implementation.hpp 9.6 KB

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