point_in_point.hpp 5.7 KB

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