side_rounded_input.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2021 Tinko Bartels, Berlin, Germany.
  3. // This file was modified by Oracle on 2023.
  4. // Modifications copyright (c) 2023 Oracle and/or its affiliates.
  5. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_STRATEGY_CARTESIAN_SIDE_ROUNDED_INPUT_HPP
  10. #define BOOST_GEOMETRY_STRATEGY_CARTESIAN_SIDE_ROUNDED_INPUT_HPP
  11. #include <limits>
  12. #include <boost/geometry/core/access.hpp>
  13. #include <boost/geometry/core/config.hpp>
  14. #include <boost/geometry/util/math.hpp>
  15. #include <boost/geometry/strategies/side.hpp>
  16. #include <boost/geometry/util/select_calculation_type.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. namespace strategy { namespace side
  20. {
  21. template <typename CalculationType = void, int Coeff1 = 5, int Coeff2 = 32>
  22. struct side_rounded_input
  23. {
  24. using cs_tag = cartesian_tag;
  25. template <typename P1, typename P2, typename P>
  26. static inline int apply(P1 const& p1, P2 const& p2, P const& p)
  27. {
  28. using coor_t = typename select_calculation_type_alt<CalculationType, P1, P2, P>::type;
  29. coor_t const p1_x = geometry::get<0>(p1);
  30. coor_t const p1_y = geometry::get<1>(p1);
  31. coor_t const p2_x = geometry::get<0>(p2);
  32. coor_t const p2_y = geometry::get<1>(p2);
  33. coor_t const p_x = geometry::get<0>(p);
  34. coor_t const p_y = geometry::get<1>(p);
  35. static coor_t const eps = std::numeric_limits<coor_t>::epsilon() / 2;
  36. coor_t const det = (p1_x - p_x) * (p2_y - p_y) - (p1_y - p_y) * (p2_x - p_x);
  37. coor_t const err_bound = (Coeff1 * eps + Coeff2 * eps * eps) *
  38. ( (geometry::math::abs(p1_x) + geometry::math::abs(p_x))
  39. * (geometry::math::abs(p2_y) + geometry::math::abs(p_y))
  40. + (geometry::math::abs(p2_x) + geometry::math::abs(p_x))
  41. * (geometry::math::abs(p1_y) + geometry::math::abs(p_y)));
  42. return (det > err_bound) - (det < -err_bound);
  43. }
  44. };
  45. }} // namespace strategy::side
  46. }} // namespace boost::geometry
  47. #endif // BOOST_GEOMETRY_STRATEGY_CARTESIAN_SIDE_ROUNDED_INPUT_HPP