implementation.hpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2013-2022.
  6. // Modifications copyright (c) 2013-2022 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_IMPLEMENTATION_HPP
  14. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_IMPLEMENTATION_HPP
  15. #include <cstddef>
  16. #include <deque>
  17. #include <boost/core/ignore_unused.hpp>
  18. #include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>
  19. #include <boost/geometry/algorithms/detail/overlay/do_reverse.hpp>
  20. #include <boost/geometry/algorithms/detail/within/interface.hpp>
  21. #include <boost/geometry/algorithms/detail/within/multi_point.hpp>
  22. #include <boost/geometry/algorithms/detail/within/point_in_geometry.hpp>
  23. #include <boost/geometry/algorithms/detail/relate/implementation.hpp>
  24. #include <boost/geometry/algorithms/detail/relate/relate_impl.hpp>
  25. #include <boost/geometry/core/access.hpp>
  26. #include <boost/geometry/core/closure.hpp>
  27. #include <boost/geometry/core/cs.hpp>
  28. #include <boost/geometry/core/exterior_ring.hpp>
  29. #include <boost/geometry/core/interior_rings.hpp>
  30. #include <boost/geometry/core/point_order.hpp>
  31. #include <boost/geometry/core/ring_type.hpp>
  32. #include <boost/geometry/core/interior_rings.hpp>
  33. #include <boost/geometry/core/tags.hpp>
  34. #include <boost/geometry/strategies/relate/cartesian.hpp>
  35. #include <boost/geometry/strategies/relate/geographic.hpp>
  36. #include <boost/geometry/strategies/relate/spherical.hpp>
  37. #include <boost/geometry/util/math.hpp>
  38. #include <boost/geometry/util/order_as_direction.hpp>
  39. namespace boost { namespace geometry
  40. {
  41. #ifndef DOXYGEN_NO_DETAIL
  42. namespace detail { namespace within {
  43. struct use_point_in_geometry
  44. {
  45. template <typename Geometry1, typename Geometry2, typename Strategy>
  46. static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
  47. {
  48. return detail::within::within_point_geometry(geometry1, geometry2, strategy);
  49. }
  50. };
  51. struct use_relate
  52. {
  53. template <typename Geometry1, typename Geometry2, typename Strategy>
  54. static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
  55. {
  56. return detail::relate::relate_impl
  57. <
  58. detail::de9im::static_mask_within_type,
  59. Geometry1,
  60. Geometry2
  61. >::apply(geometry1, geometry2, strategy);
  62. }
  63. };
  64. }} // namespace detail::within
  65. #endif // DOXYGEN_NO_DETAIL
  66. #ifndef DOXYGEN_NO_DISPATCH
  67. namespace dispatch
  68. {
  69. template <typename Point, typename Box>
  70. struct within<Point, Box, point_tag, box_tag>
  71. {
  72. template <typename Strategy>
  73. static inline bool apply(Point const& point, Box const& box, Strategy const& strategy)
  74. {
  75. return strategy.within(point, box).apply(point, box);
  76. }
  77. };
  78. template <typename Box1, typename Box2>
  79. struct within<Box1, Box2, box_tag, box_tag>
  80. {
  81. template <typename Strategy>
  82. static inline bool apply(Box1 const& box1, Box2 const& box2, Strategy const& strategy)
  83. {
  84. assert_dimension_equal<Box1, Box2>();
  85. return strategy.within(box1, box2).apply(box1, box2);
  86. }
  87. };
  88. // P/P
  89. template <typename Point1, typename Point2>
  90. struct within<Point1, Point2, point_tag, point_tag>
  91. : public detail::within::use_point_in_geometry
  92. {};
  93. template <typename Point, typename MultiPoint>
  94. struct within<Point, MultiPoint, point_tag, multi_point_tag>
  95. : public detail::within::use_point_in_geometry
  96. {};
  97. template <typename MultiPoint, typename Point>
  98. struct within<MultiPoint, Point, multi_point_tag, point_tag>
  99. : public detail::within::multi_point_point
  100. {};
  101. template <typename MultiPoint1, typename MultiPoint2>
  102. struct within<MultiPoint1, MultiPoint2, multi_point_tag, multi_point_tag>
  103. : public detail::within::multi_point_multi_point
  104. {};
  105. // P/L
  106. template <typename Point, typename Segment>
  107. struct within<Point, Segment, point_tag, segment_tag>
  108. : public detail::within::use_point_in_geometry
  109. {};
  110. template <typename Point, typename Linestring>
  111. struct within<Point, Linestring, point_tag, linestring_tag>
  112. : public detail::within::use_point_in_geometry
  113. {};
  114. template <typename Point, typename MultiLinestring>
  115. struct within<Point, MultiLinestring, point_tag, multi_linestring_tag>
  116. : public detail::within::use_point_in_geometry
  117. {};
  118. template <typename MultiPoint, typename Segment>
  119. struct within<MultiPoint, Segment, multi_point_tag, segment_tag>
  120. : public detail::within::multi_point_single_geometry<true>
  121. {};
  122. template <typename MultiPoint, typename Linestring>
  123. struct within<MultiPoint, Linestring, multi_point_tag, linestring_tag>
  124. : public detail::within::multi_point_single_geometry<true>
  125. {};
  126. template <typename MultiPoint, typename MultiLinestring>
  127. struct within<MultiPoint, MultiLinestring, multi_point_tag, multi_linestring_tag>
  128. : public detail::within::multi_point_multi_geometry<true>
  129. {};
  130. // P/A
  131. template <typename Point, typename Ring>
  132. struct within<Point, Ring, point_tag, ring_tag>
  133. : public detail::within::use_point_in_geometry
  134. {};
  135. template <typename Point, typename Polygon>
  136. struct within<Point, Polygon, point_tag, polygon_tag>
  137. : public detail::within::use_point_in_geometry
  138. {};
  139. template <typename Point, typename MultiPolygon>
  140. struct within<Point, MultiPolygon, point_tag, multi_polygon_tag>
  141. : public detail::within::use_point_in_geometry
  142. {};
  143. template <typename MultiPoint, typename Ring>
  144. struct within<MultiPoint, Ring, multi_point_tag, ring_tag>
  145. : public detail::within::multi_point_single_geometry<true>
  146. {};
  147. template <typename MultiPoint, typename Polygon>
  148. struct within<MultiPoint, Polygon, multi_point_tag, polygon_tag>
  149. : public detail::within::multi_point_single_geometry<true>
  150. {};
  151. template <typename MultiPoint, typename MultiPolygon>
  152. struct within<MultiPoint, MultiPolygon, multi_point_tag, multi_polygon_tag>
  153. : public detail::within::multi_point_multi_geometry<true>
  154. {};
  155. // L/L
  156. template <typename Linestring1, typename Linestring2>
  157. struct within<Linestring1, Linestring2, linestring_tag, linestring_tag>
  158. : public detail::within::use_relate
  159. {};
  160. template <typename Linestring, typename MultiLinestring>
  161. struct within<Linestring, MultiLinestring, linestring_tag, multi_linestring_tag>
  162. : public detail::within::use_relate
  163. {};
  164. template <typename MultiLinestring, typename Linestring>
  165. struct within<MultiLinestring, Linestring, multi_linestring_tag, linestring_tag>
  166. : public detail::within::use_relate
  167. {};
  168. template <typename MultiLinestring1, typename MultiLinestring2>
  169. struct within<MultiLinestring1, MultiLinestring2, multi_linestring_tag, multi_linestring_tag>
  170. : public detail::within::use_relate
  171. {};
  172. // L/A
  173. template <typename Linestring, typename Ring>
  174. struct within<Linestring, Ring, linestring_tag, ring_tag>
  175. : public detail::within::use_relate
  176. {};
  177. template <typename MultiLinestring, typename Ring>
  178. struct within<MultiLinestring, Ring, multi_linestring_tag, ring_tag>
  179. : public detail::within::use_relate
  180. {};
  181. template <typename Linestring, typename Polygon>
  182. struct within<Linestring, Polygon, linestring_tag, polygon_tag>
  183. : public detail::within::use_relate
  184. {};
  185. template <typename MultiLinestring, typename Polygon>
  186. struct within<MultiLinestring, Polygon, multi_linestring_tag, polygon_tag>
  187. : public detail::within::use_relate
  188. {};
  189. template <typename Linestring, typename MultiPolygon>
  190. struct within<Linestring, MultiPolygon, linestring_tag, multi_polygon_tag>
  191. : public detail::within::use_relate
  192. {};
  193. template <typename MultiLinestring, typename MultiPolygon>
  194. struct within<MultiLinestring, MultiPolygon, multi_linestring_tag, multi_polygon_tag>
  195. : public detail::within::use_relate
  196. {};
  197. // A/A
  198. template <typename Ring1, typename Ring2>
  199. struct within<Ring1, Ring2, ring_tag, ring_tag>
  200. : public detail::within::use_relate
  201. {};
  202. template <typename Ring, typename Polygon>
  203. struct within<Ring, Polygon, ring_tag, polygon_tag>
  204. : public detail::within::use_relate
  205. {};
  206. template <typename Polygon, typename Ring>
  207. struct within<Polygon, Ring, polygon_tag, ring_tag>
  208. : public detail::within::use_relate
  209. {};
  210. template <typename Polygon1, typename Polygon2>
  211. struct within<Polygon1, Polygon2, polygon_tag, polygon_tag>
  212. : public detail::within::use_relate
  213. {};
  214. template <typename Ring, typename MultiPolygon>
  215. struct within<Ring, MultiPolygon, ring_tag, multi_polygon_tag>
  216. : public detail::within::use_relate
  217. {};
  218. template <typename MultiPolygon, typename Ring>
  219. struct within<MultiPolygon, Ring, multi_polygon_tag, ring_tag>
  220. : public detail::within::use_relate
  221. {};
  222. template <typename Polygon, typename MultiPolygon>
  223. struct within<Polygon, MultiPolygon, polygon_tag, multi_polygon_tag>
  224. : public detail::within::use_relate
  225. {};
  226. template <typename MultiPolygon, typename Polygon>
  227. struct within<MultiPolygon, Polygon, multi_polygon_tag, polygon_tag>
  228. : public detail::within::use_relate
  229. {};
  230. template <typename MultiPolygon1, typename MultiPolygon2>
  231. struct within<MultiPolygon1, MultiPolygon2, multi_polygon_tag, multi_polygon_tag>
  232. : public detail::within::use_relate
  233. {};
  234. } // namespace dispatch
  235. #endif // DOXYGEN_NO_DISPATCH
  236. }} // namespace boost::geometry
  237. #include <boost/geometry/index/rtree.hpp>
  238. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_IMPLEMENTATION_HPP