implementation.hpp 9.5 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, 2014, 2017, 2019.
  6. // Modifications copyright (c) 2013-2019 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 <boost/core/ignore_unused.hpp>
  17. #include <boost/range.hpp>
  18. #include <boost/geometry/algorithms/detail/within/interface.hpp>
  19. #include <boost/geometry/core/access.hpp>
  20. #include <boost/geometry/core/closure.hpp>
  21. #include <boost/geometry/core/cs.hpp>
  22. #include <boost/geometry/core/exterior_ring.hpp>
  23. #include <boost/geometry/core/interior_rings.hpp>
  24. #include <boost/geometry/core/point_order.hpp>
  25. #include <boost/geometry/core/ring_type.hpp>
  26. #include <boost/geometry/core/interior_rings.hpp>
  27. #include <boost/geometry/core/tags.hpp>
  28. #include <boost/geometry/util/math.hpp>
  29. #include <boost/geometry/util/order_as_direction.hpp>
  30. #include <boost/geometry/algorithms/detail/within/multi_point.hpp>
  31. #include <boost/geometry/algorithms/detail/within/point_in_geometry.hpp>
  32. #include <boost/geometry/algorithms/relate.hpp>
  33. #include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>
  34. #include <boost/geometry/algorithms/detail/overlay/do_reverse.hpp>
  35. #include <deque>
  36. namespace boost { namespace geometry
  37. {
  38. #ifndef DOXYGEN_NO_DETAIL
  39. namespace detail { namespace within {
  40. struct use_point_in_geometry
  41. {
  42. template <typename Geometry1, typename Geometry2, typename Strategy>
  43. static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
  44. {
  45. return detail::within::within_point_geometry(geometry1, geometry2, strategy);
  46. }
  47. };
  48. struct use_relate
  49. {
  50. template <typename Geometry1, typename Geometry2, typename Strategy>
  51. static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
  52. {
  53. typedef typename detail::de9im::static_mask_within_type
  54. <
  55. Geometry1, Geometry2
  56. >::type within_mask;
  57. return geometry::relate(geometry1, geometry2, within_mask(), strategy);
  58. }
  59. };
  60. }} // namespace detail::within
  61. #endif // DOXYGEN_NO_DETAIL
  62. #ifndef DOXYGEN_NO_DISPATCH
  63. namespace dispatch
  64. {
  65. template <typename Point, typename Box>
  66. struct within<Point, Box, point_tag, box_tag>
  67. {
  68. template <typename Strategy>
  69. static inline bool apply(Point const& point, Box const& box, Strategy const& strategy)
  70. {
  71. boost::ignore_unused(strategy);
  72. return strategy.apply(point, box);
  73. }
  74. };
  75. template <typename Box1, typename Box2>
  76. struct within<Box1, Box2, box_tag, box_tag>
  77. {
  78. template <typename Strategy>
  79. static inline bool apply(Box1 const& box1, Box2 const& box2, Strategy const& strategy)
  80. {
  81. assert_dimension_equal<Box1, Box2>();
  82. boost::ignore_unused(strategy);
  83. return strategy.apply(box1, box2);
  84. }
  85. };
  86. // P/P
  87. template <typename Point1, typename Point2>
  88. struct within<Point1, Point2, point_tag, point_tag>
  89. : public detail::within::use_point_in_geometry
  90. {};
  91. template <typename Point, typename MultiPoint>
  92. struct within<Point, MultiPoint, point_tag, multi_point_tag>
  93. : public detail::within::use_point_in_geometry
  94. {};
  95. template <typename MultiPoint, typename Point>
  96. struct within<MultiPoint, Point, multi_point_tag, point_tag>
  97. : public detail::within::multi_point_point
  98. {};
  99. template <typename MultiPoint1, typename MultiPoint2>
  100. struct within<MultiPoint1, MultiPoint2, multi_point_tag, multi_point_tag>
  101. : public detail::within::multi_point_multi_point
  102. {};
  103. // P/L
  104. template <typename Point, typename Segment>
  105. struct within<Point, Segment, point_tag, segment_tag>
  106. : public detail::within::use_point_in_geometry
  107. {};
  108. template <typename Point, typename Linestring>
  109. struct within<Point, Linestring, point_tag, linestring_tag>
  110. : public detail::within::use_point_in_geometry
  111. {};
  112. template <typename Point, typename MultiLinestring>
  113. struct within<Point, MultiLinestring, point_tag, multi_linestring_tag>
  114. : public detail::within::use_point_in_geometry
  115. {};
  116. template <typename MultiPoint, typename Segment>
  117. struct within<MultiPoint, Segment, multi_point_tag, segment_tag>
  118. : public detail::within::multi_point_single_geometry<true>
  119. {};
  120. template <typename MultiPoint, typename Linestring>
  121. struct within<MultiPoint, Linestring, multi_point_tag, linestring_tag>
  122. : public detail::within::multi_point_single_geometry<true>
  123. {};
  124. template <typename MultiPoint, typename MultiLinestring>
  125. struct within<MultiPoint, MultiLinestring, multi_point_tag, multi_linestring_tag>
  126. : public detail::within::multi_point_multi_geometry<true>
  127. {};
  128. // P/A
  129. template <typename Point, typename Ring>
  130. struct within<Point, Ring, point_tag, ring_tag>
  131. : public detail::within::use_point_in_geometry
  132. {};
  133. template <typename Point, typename Polygon>
  134. struct within<Point, Polygon, point_tag, polygon_tag>
  135. : public detail::within::use_point_in_geometry
  136. {};
  137. template <typename Point, typename MultiPolygon>
  138. struct within<Point, MultiPolygon, point_tag, multi_polygon_tag>
  139. : public detail::within::use_point_in_geometry
  140. {};
  141. template <typename MultiPoint, typename Ring>
  142. struct within<MultiPoint, Ring, multi_point_tag, ring_tag>
  143. : public detail::within::multi_point_single_geometry<true>
  144. {};
  145. template <typename MultiPoint, typename Polygon>
  146. struct within<MultiPoint, Polygon, multi_point_tag, polygon_tag>
  147. : public detail::within::multi_point_single_geometry<true>
  148. {};
  149. template <typename MultiPoint, typename MultiPolygon>
  150. struct within<MultiPoint, MultiPolygon, multi_point_tag, multi_polygon_tag>
  151. : public detail::within::multi_point_multi_geometry<true>
  152. {};
  153. // L/L
  154. template <typename Linestring1, typename Linestring2>
  155. struct within<Linestring1, Linestring2, linestring_tag, linestring_tag>
  156. : public detail::within::use_relate
  157. {};
  158. template <typename Linestring, typename MultiLinestring>
  159. struct within<Linestring, MultiLinestring, linestring_tag, multi_linestring_tag>
  160. : public detail::within::use_relate
  161. {};
  162. template <typename MultiLinestring, typename Linestring>
  163. struct within<MultiLinestring, Linestring, multi_linestring_tag, linestring_tag>
  164. : public detail::within::use_relate
  165. {};
  166. template <typename MultiLinestring1, typename MultiLinestring2>
  167. struct within<MultiLinestring1, MultiLinestring2, multi_linestring_tag, multi_linestring_tag>
  168. : public detail::within::use_relate
  169. {};
  170. // L/A
  171. template <typename Linestring, typename Ring>
  172. struct within<Linestring, Ring, linestring_tag, ring_tag>
  173. : public detail::within::use_relate
  174. {};
  175. template <typename MultiLinestring, typename Ring>
  176. struct within<MultiLinestring, Ring, multi_linestring_tag, ring_tag>
  177. : public detail::within::use_relate
  178. {};
  179. template <typename Linestring, typename Polygon>
  180. struct within<Linestring, Polygon, linestring_tag, polygon_tag>
  181. : public detail::within::use_relate
  182. {};
  183. template <typename MultiLinestring, typename Polygon>
  184. struct within<MultiLinestring, Polygon, multi_linestring_tag, polygon_tag>
  185. : public detail::within::use_relate
  186. {};
  187. template <typename Linestring, typename MultiPolygon>
  188. struct within<Linestring, MultiPolygon, linestring_tag, multi_polygon_tag>
  189. : public detail::within::use_relate
  190. {};
  191. template <typename MultiLinestring, typename MultiPolygon>
  192. struct within<MultiLinestring, MultiPolygon, multi_linestring_tag, multi_polygon_tag>
  193. : public detail::within::use_relate
  194. {};
  195. // A/A
  196. template <typename Ring1, typename Ring2>
  197. struct within<Ring1, Ring2, ring_tag, ring_tag>
  198. : public detail::within::use_relate
  199. {};
  200. template <typename Ring, typename Polygon>
  201. struct within<Ring, Polygon, ring_tag, polygon_tag>
  202. : public detail::within::use_relate
  203. {};
  204. template <typename Polygon, typename Ring>
  205. struct within<Polygon, Ring, polygon_tag, ring_tag>
  206. : public detail::within::use_relate
  207. {};
  208. template <typename Polygon1, typename Polygon2>
  209. struct within<Polygon1, Polygon2, polygon_tag, polygon_tag>
  210. : public detail::within::use_relate
  211. {};
  212. template <typename Ring, typename MultiPolygon>
  213. struct within<Ring, MultiPolygon, ring_tag, multi_polygon_tag>
  214. : public detail::within::use_relate
  215. {};
  216. template <typename MultiPolygon, typename Ring>
  217. struct within<MultiPolygon, Ring, multi_polygon_tag, ring_tag>
  218. : public detail::within::use_relate
  219. {};
  220. template <typename Polygon, typename MultiPolygon>
  221. struct within<Polygon, MultiPolygon, polygon_tag, multi_polygon_tag>
  222. : public detail::within::use_relate
  223. {};
  224. template <typename MultiPolygon, typename Polygon>
  225. struct within<MultiPolygon, Polygon, multi_polygon_tag, polygon_tag>
  226. : public detail::within::use_relate
  227. {};
  228. template <typename MultiPolygon1, typename MultiPolygon2>
  229. struct within<MultiPolygon1, MultiPolygon2, multi_polygon_tag, multi_polygon_tag>
  230. : public detail::within::use_relate
  231. {};
  232. } // namespace dispatch
  233. #endif // DOXYGEN_NO_DISPATCH
  234. }} // namespace boost::geometry
  235. #include <boost/geometry/index/rtree.hpp>
  236. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_WITHIN_IMPLEMENTATION_HPP