point_in_point.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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, 2014, 2015, 2017, 2018, 2019.
  7. // Modifications copyright (c) 2013-2019, 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 <boost/geometry/core/access.hpp>
  19. #include <boost/geometry/core/radian_access.hpp>
  20. #include <boost/geometry/core/coordinate_dimension.hpp>
  21. #include <boost/geometry/core/coordinate_system.hpp>
  22. #include <boost/geometry/core/coordinate_type.hpp>
  23. #include <boost/geometry/core/cs.hpp>
  24. #include <boost/geometry/core/tags.hpp>
  25. #include <boost/geometry/algorithms/detail/normalize.hpp>
  26. #include <boost/geometry/algorithms/dispatch/disjoint.hpp>
  27. #include <boost/geometry/algorithms/transform.hpp>
  28. #include <boost/geometry/geometries/helper_geometry.hpp>
  29. #include <boost/geometry/strategies/cartesian/point_in_point.hpp>
  30. #include <boost/geometry/strategies/covered_by.hpp>
  31. #include <boost/geometry/strategies/strategy_transform.hpp>
  32. #include <boost/geometry/strategies/within.hpp>
  33. #include <boost/geometry/util/math.hpp>
  34. #include <boost/geometry/util/select_most_precise.hpp>
  35. namespace boost { namespace geometry
  36. {
  37. #ifndef DOXYGEN_NO_DETAIL
  38. namespace detail { namespace within
  39. {
  40. class point_point_on_spheroid
  41. {
  42. public:
  43. typedef spherical_tag cs_tag;
  44. private:
  45. template <typename Point1, typename Point2, bool SameUnits>
  46. struct are_same_points
  47. {
  48. static inline bool apply(Point1 const& point1, Point2 const& point2)
  49. {
  50. typedef typename helper_geometry<Point1>::type helper_point_type1;
  51. typedef typename helper_geometry<Point2>::type helper_point_type2;
  52. helper_point_type1 point1_normalized;
  53. strategy::normalize::spherical_point::apply(point1, point1_normalized);
  54. helper_point_type2 point2_normalized;
  55. strategy::normalize::spherical_point::apply(point2, point2_normalized);
  56. return point_point_generic
  57. <
  58. 0, dimension<Point1>::value
  59. >::apply(point1_normalized, point2_normalized);
  60. }
  61. };
  62. template <typename Point1, typename Point2>
  63. struct are_same_points<Point1, Point2, false> // points have different units
  64. {
  65. static inline bool apply(Point1 const& point1, Point2 const& point2)
  66. {
  67. typedef typename geometry::select_most_precise
  68. <
  69. typename fp_coordinate_type<Point1>::type,
  70. typename fp_coordinate_type<Point2>::type
  71. >::type calculation_type;
  72. typename helper_geometry
  73. <
  74. Point1, calculation_type, radian
  75. >::type helper_point1, helper_point2;
  76. Point1 point1_normalized;
  77. strategy::normalize::spherical_point::apply(point1, point1_normalized);
  78. Point2 point2_normalized;
  79. strategy::normalize::spherical_point::apply(point2, point2_normalized);
  80. geometry::transform(point1_normalized, helper_point1);
  81. geometry::transform(point2_normalized, helper_point2);
  82. return point_point_generic
  83. <
  84. 0, dimension<Point1>::value
  85. >::apply(helper_point1, helper_point2);
  86. }
  87. };
  88. public:
  89. template <typename Point1, typename Point2>
  90. static inline bool apply(Point1 const& point1, Point2 const& point2)
  91. {
  92. return are_same_points
  93. <
  94. Point1,
  95. Point2,
  96. boost::is_same
  97. <
  98. typename detail::cs_angular_units<Point1>::type,
  99. typename detail::cs_angular_units<Point2>::type
  100. >::value
  101. >::apply(point1, point2);
  102. }
  103. };
  104. }} // namespace detail::within
  105. #endif // DOXYGEN_NO_DETAIL
  106. namespace strategy { namespace within
  107. {
  108. struct spherical_point_point
  109. : geometry::detail::within::point_point_on_spheroid
  110. {};
  111. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  112. namespace services
  113. {
  114. template <typename PointLike1, typename PointLike2, typename Tag1, typename Tag2>
  115. struct default_strategy<PointLike1, PointLike2, Tag1, Tag2, pointlike_tag, pointlike_tag, spherical_tag, spherical_tag>
  116. {
  117. typedef strategy::within::spherical_point_point type;
  118. };
  119. } // namespace services
  120. #endif
  121. }} // namespace strategy::within
  122. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  123. namespace strategy { namespace covered_by { namespace services
  124. {
  125. template <typename PointLike1, typename PointLike2, typename Tag1, typename Tag2>
  126. struct default_strategy<PointLike1, PointLike2, Tag1, Tag2, pointlike_tag, pointlike_tag, spherical_tag, spherical_tag>
  127. {
  128. typedef strategy::within::spherical_point_point type;
  129. };
  130. }}} // namespace strategy::covered_by::services
  131. #endif
  132. }} // namespace boost::geometry
  133. #endif // BOOST_GEOMETRY_STRATEGY_SPHERICAL_POINT_IN_POINT_HPP