point_in_point.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland
  6. // This file was modified by Oracle on 2013-2025.
  7. // Modifications copyright (c) 2013-2025, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  9. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  10. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  11. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  12. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  13. // Use, modification and distribution is subject to the Boost Software License,
  14. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  15. // http://www.boost.org/LICENSE_1_0.txt)
  16. #ifndef BOOST_GEOMETRY_STRATEGY_SPHERICAL_POINT_IN_POINT_HPP
  17. #define BOOST_GEOMETRY_STRATEGY_SPHERICAL_POINT_IN_POINT_HPP
  18. #include <cstddef>
  19. #include <type_traits>
  20. #include <boost/geometry/core/access.hpp>
  21. #include <boost/geometry/core/radian_access.hpp>
  22. #include <boost/geometry/core/coordinate_dimension.hpp>
  23. #include <boost/geometry/core/coordinate_promotion.hpp>
  24. #include <boost/geometry/core/coordinate_system.hpp>
  25. #include <boost/geometry/core/coordinate_type.hpp>
  26. #include <boost/geometry/core/cs.hpp>
  27. #include <boost/geometry/core/tags.hpp>
  28. #include <boost/geometry/algorithms/detail/normalize.hpp>
  29. #include <boost/geometry/algorithms/dispatch/disjoint.hpp>
  30. #include <boost/geometry/algorithms/transform.hpp>
  31. #include <boost/geometry/geometries/helper_geometry.hpp>
  32. #include <boost/geometry/strategies/cartesian/point_in_point.hpp>
  33. #include <boost/geometry/strategies/covered_by.hpp>
  34. #include <boost/geometry/strategies/strategy_transform.hpp>
  35. #include <boost/geometry/strategies/within.hpp>
  36. #include <boost/geometry/util/math.hpp>
  37. #include <boost/geometry/util/select_most_precise.hpp>
  38. namespace boost { namespace geometry
  39. {
  40. #ifndef DOXYGEN_NO_DETAIL
  41. namespace detail { namespace within
  42. {
  43. class point_point_on_spheroid
  44. {
  45. public:
  46. using cs_tag = spherical_tag;
  47. private:
  48. template <typename Point1, typename Point2, bool SameUnits>
  49. struct are_same_points
  50. {
  51. static inline bool apply(Point1 const& point1, Point2 const& point2)
  52. {
  53. using helper_point_type1 = typename helper_geometry<Point1>::type;
  54. using helper_point_type2 = typename helper_geometry<Point2>::type;
  55. helper_point_type1 point1_normalized;
  56. bool const exact_normalized = false;
  57. strategy::normalize::spherical_point::apply(point1, point1_normalized, exact_normalized);
  58. helper_point_type2 point2_normalized;
  59. strategy::normalize::spherical_point::apply(point2, point2_normalized, exact_normalized);
  60. return point_point_generic
  61. <
  62. 0, dimension<Point1>::value
  63. >::apply(point1_normalized, point2_normalized);
  64. }
  65. };
  66. template <typename Point1, typename Point2>
  67. struct are_same_points<Point1, Point2, false> // points have different units
  68. {
  69. static inline bool apply(Point1 const& point1, Point2 const& point2)
  70. {
  71. using calculation_type = typename geometry::select_most_precise
  72. <
  73. typename fp_coordinate_type<Point1>::type,
  74. typename fp_coordinate_type<Point2>::type
  75. >::type;
  76. typename helper_geometry
  77. <
  78. Point1, calculation_type, radian
  79. >::type helper_point1, helper_point2;
  80. Point1 point1_normalized;
  81. strategy::normalize::spherical_point::apply(point1, point1_normalized);
  82. Point2 point2_normalized;
  83. strategy::normalize::spherical_point::apply(point2, point2_normalized);
  84. geometry::transform(point1_normalized, helper_point1);
  85. geometry::transform(point2_normalized, helper_point2);
  86. return point_point_generic
  87. <
  88. 0, dimension<Point1>::value
  89. >::apply(helper_point1, helper_point2);
  90. }
  91. };
  92. public:
  93. template <typename Point1, typename Point2>
  94. static inline bool apply(Point1 const& point1, Point2 const& point2)
  95. {
  96. return are_same_points
  97. <
  98. Point1,
  99. Point2,
  100. std::is_same
  101. <
  102. typename detail::cs_angular_units<Point1>::type,
  103. typename detail::cs_angular_units<Point2>::type
  104. >::value
  105. >::apply(point1, point2);
  106. }
  107. };
  108. }} // namespace detail::within
  109. #endif // DOXYGEN_NO_DETAIL
  110. namespace strategy { namespace within
  111. {
  112. struct spherical_point_point
  113. : geometry::detail::within::point_point_on_spheroid
  114. {};
  115. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  116. namespace services
  117. {
  118. template <typename PointLike1, typename PointLike2, typename Tag1, typename Tag2>
  119. struct default_strategy<PointLike1, PointLike2, Tag1, Tag2, pointlike_tag, pointlike_tag, spherical_tag, spherical_tag>
  120. {
  121. using type = strategy::within::spherical_point_point;
  122. };
  123. } // namespace services
  124. #endif
  125. }} // namespace strategy::within
  126. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  127. namespace strategy { namespace covered_by { namespace services
  128. {
  129. template <typename PointLike1, typename PointLike2, typename Tag1, typename Tag2>
  130. struct default_strategy<PointLike1, PointLike2, Tag1, Tag2, pointlike_tag, pointlike_tag, spherical_tag, spherical_tag>
  131. {
  132. using type = strategy::within::spherical_point_point;
  133. };
  134. }}} // namespace strategy::covered_by::services
  135. #endif
  136. }} // namespace boost::geometry
  137. #endif // BOOST_GEOMETRY_STRATEGY_SPHERICAL_POINT_IN_POINT_HPP