implementation.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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 Vissarion Fysikopoulos, on behalf of Oracle
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_COVERED_BY_IMPLEMENTATION_HPP
  15. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_COVERED_BY_IMPLEMENTATION_HPP
  16. #include <cstddef>
  17. #include <boost/core/ignore_unused.hpp>
  18. #include <boost/geometry/algorithms/detail/covered_by/interface.hpp>
  19. #include <boost/geometry/algorithms/detail/within/implementation.hpp>
  20. #include <boost/geometry/strategies/relate/cartesian.hpp>
  21. #include <boost/geometry/strategies/relate/geographic.hpp>
  22. #include <boost/geometry/strategies/relate/spherical.hpp>
  23. namespace boost { namespace geometry
  24. {
  25. #ifndef DOXYGEN_NO_DETAIL
  26. namespace detail { namespace covered_by {
  27. struct use_point_in_geometry
  28. {
  29. template <typename Geometry1, typename Geometry2, typename Strategy>
  30. static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
  31. Strategy const& strategy)
  32. {
  33. return detail::within::covered_by_point_geometry(geometry1, geometry2, strategy);
  34. }
  35. };
  36. struct use_relate
  37. {
  38. template <typename Geometry1, typename Geometry2, typename Strategy>
  39. static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
  40. Strategy const& strategy)
  41. {
  42. return detail::relate::relate_impl
  43. <
  44. detail::de9im::static_mask_covered_by_type,
  45. Geometry1,
  46. Geometry2
  47. >::apply(geometry1, geometry2, strategy);
  48. }
  49. };
  50. struct geometry_covered_by_box
  51. {
  52. template <typename Geometry, typename Box, typename Strategy>
  53. static inline bool apply(Geometry const& geometry, Box const& box, Strategy const& strategy)
  54. {
  55. using point_type = typename point_type<Geometry>::type;
  56. using mutable_point_type = typename helper_geometry<point_type>::type;
  57. using box_type = model::box<mutable_point_type>;
  58. // TODO: this is not optimal since the process should be able to terminate if a point is found
  59. // outside of the box without computing the whole envelope
  60. box_type box_areal;
  61. geometry::envelope(geometry, box_areal, strategy);
  62. return strategy.covered_by(box_areal, box).apply(box_areal, box);
  63. }
  64. };
  65. }} // namespace detail::covered_by
  66. #endif // DOXYGEN_NO_DETAIL
  67. #ifndef DOXYGEN_NO_DISPATCH
  68. namespace dispatch
  69. {
  70. // P/P
  71. template <typename Point1, typename Point2>
  72. struct covered_by<Point1, Point2, point_tag, point_tag>
  73. : public detail::covered_by::use_point_in_geometry
  74. {};
  75. template <typename Point, typename MultiPoint>
  76. struct covered_by<Point, MultiPoint, point_tag, multi_point_tag>
  77. : public detail::covered_by::use_point_in_geometry
  78. {};
  79. template <typename MultiPoint, typename Point>
  80. struct covered_by<MultiPoint, Point, multi_point_tag, point_tag>
  81. : public detail::within::multi_point_point
  82. {};
  83. template <typename MultiPoint1, typename MultiPoint2>
  84. struct covered_by<MultiPoint1, MultiPoint2, multi_point_tag, multi_point_tag>
  85. : public detail::within::multi_point_multi_point
  86. {};
  87. // P/L
  88. template <typename Point, typename Segment>
  89. struct covered_by<Point, Segment, point_tag, segment_tag>
  90. : public detail::covered_by::use_point_in_geometry
  91. {};
  92. template <typename Point, typename Linestring>
  93. struct covered_by<Point, Linestring, point_tag, linestring_tag>
  94. : public detail::covered_by::use_point_in_geometry
  95. {};
  96. template <typename Point, typename MultiLinestring>
  97. struct covered_by<Point, MultiLinestring, point_tag, multi_linestring_tag>
  98. : public detail::covered_by::use_point_in_geometry
  99. {};
  100. template <typename MultiPoint, typename Segment>
  101. struct covered_by<MultiPoint, Segment, multi_point_tag, segment_tag>
  102. : public detail::within::multi_point_single_geometry<false>
  103. {};
  104. template <typename MultiPoint, typename Linestring>
  105. struct covered_by<MultiPoint, Linestring, multi_point_tag, linestring_tag>
  106. : public detail::within::multi_point_single_geometry<false>
  107. {};
  108. template <typename MultiPoint, typename MultiLinestring>
  109. struct covered_by<MultiPoint, MultiLinestring, multi_point_tag, multi_linestring_tag>
  110. : public detail::within::multi_point_multi_geometry<false>
  111. {};
  112. // P/A
  113. template <typename Point, typename Ring>
  114. struct covered_by<Point, Ring, point_tag, ring_tag>
  115. : public detail::covered_by::use_point_in_geometry
  116. {};
  117. template <typename Point, typename Polygon>
  118. struct covered_by<Point, Polygon, point_tag, polygon_tag>
  119. : public detail::covered_by::use_point_in_geometry
  120. {};
  121. template <typename Point, typename MultiPolygon>
  122. struct covered_by<Point, MultiPolygon, point_tag, multi_polygon_tag>
  123. : public detail::covered_by::use_point_in_geometry
  124. {};
  125. template <typename MultiPoint, typename Ring>
  126. struct covered_by<MultiPoint, Ring, multi_point_tag, ring_tag>
  127. : public detail::within::multi_point_single_geometry<false>
  128. {};
  129. template <typename MultiPoint, typename Polygon>
  130. struct covered_by<MultiPoint, Polygon, multi_point_tag, polygon_tag>
  131. : public detail::within::multi_point_single_geometry<false>
  132. {};
  133. template <typename MultiPoint, typename MultiPolygon>
  134. struct covered_by<MultiPoint, MultiPolygon, multi_point_tag, multi_polygon_tag>
  135. : public detail::within::multi_point_multi_geometry<false>
  136. {};
  137. // L/L
  138. template <typename Linestring1, typename Linestring2>
  139. struct covered_by<Linestring1, Linestring2, linestring_tag, linestring_tag>
  140. : public detail::covered_by::use_relate
  141. {};
  142. template <typename Linestring, typename MultiLinestring>
  143. struct covered_by<Linestring, MultiLinestring, linestring_tag, multi_linestring_tag>
  144. : public detail::covered_by::use_relate
  145. {};
  146. template <typename MultiLinestring, typename Linestring>
  147. struct covered_by<MultiLinestring, Linestring, multi_linestring_tag, linestring_tag>
  148. : public detail::covered_by::use_relate
  149. {};
  150. template <typename MultiLinestring1, typename MultiLinestring2>
  151. struct covered_by<MultiLinestring1, MultiLinestring2, multi_linestring_tag, multi_linestring_tag>
  152. : public detail::covered_by::use_relate
  153. {};
  154. // L/A
  155. template <typename Linestring, typename Ring>
  156. struct covered_by<Linestring, Ring, linestring_tag, ring_tag>
  157. : public detail::covered_by::use_relate
  158. {};
  159. template <typename MultiLinestring, typename Ring>
  160. struct covered_by<MultiLinestring, Ring, multi_linestring_tag, ring_tag>
  161. : public detail::covered_by::use_relate
  162. {};
  163. template <typename Linestring, typename Polygon>
  164. struct covered_by<Linestring, Polygon, linestring_tag, polygon_tag>
  165. : public detail::covered_by::use_relate
  166. {};
  167. template <typename MultiLinestring, typename Polygon>
  168. struct covered_by<MultiLinestring, Polygon, multi_linestring_tag, polygon_tag>
  169. : public detail::covered_by::use_relate
  170. {};
  171. template <typename Linestring, typename MultiPolygon>
  172. struct covered_by<Linestring, MultiPolygon, linestring_tag, multi_polygon_tag>
  173. : public detail::covered_by::use_relate
  174. {};
  175. template <typename MultiLinestring, typename MultiPolygon>
  176. struct covered_by<MultiLinestring, MultiPolygon, multi_linestring_tag, multi_polygon_tag>
  177. : public detail::covered_by::use_relate
  178. {};
  179. // A/A
  180. template <typename Ring1, typename Ring2>
  181. struct covered_by<Ring1, Ring2, ring_tag, ring_tag>
  182. : public detail::covered_by::use_relate
  183. {};
  184. template <typename Ring, typename Polygon>
  185. struct covered_by<Ring, Polygon, ring_tag, polygon_tag>
  186. : public detail::covered_by::use_relate
  187. {};
  188. template <typename Polygon, typename Ring>
  189. struct covered_by<Polygon, Ring, polygon_tag, ring_tag>
  190. : public detail::covered_by::use_relate
  191. {};
  192. template <typename Polygon1, typename Polygon2>
  193. struct covered_by<Polygon1, Polygon2, polygon_tag, polygon_tag>
  194. : public detail::covered_by::use_relate
  195. {};
  196. template <typename Ring, typename MultiPolygon>
  197. struct covered_by<Ring, MultiPolygon, ring_tag, multi_polygon_tag>
  198. : public detail::covered_by::use_relate
  199. {};
  200. template <typename MultiPolygon, typename Ring>
  201. struct covered_by<MultiPolygon, Ring, multi_polygon_tag, ring_tag>
  202. : public detail::covered_by::use_relate
  203. {};
  204. template <typename Polygon, typename MultiPolygon>
  205. struct covered_by<Polygon, MultiPolygon, polygon_tag, multi_polygon_tag>
  206. : public detail::covered_by::use_relate
  207. {};
  208. template <typename MultiPolygon, typename Polygon>
  209. struct covered_by<MultiPolygon, Polygon, multi_polygon_tag, polygon_tag>
  210. : public detail::covered_by::use_relate
  211. {};
  212. template <typename MultiPolygon1, typename MultiPolygon2>
  213. struct covered_by<MultiPolygon1, MultiPolygon2, multi_polygon_tag, multi_polygon_tag>
  214. : public detail::covered_by::use_relate
  215. {};
  216. // B/A
  217. template <typename Box, typename Polygon>
  218. struct covered_by<Box, Polygon, box_tag, ring_tag>
  219. : public detail::covered_by::use_relate
  220. {};
  221. template <typename Box, typename Polygon>
  222. struct covered_by<Box, Polygon, box_tag, polygon_tag>
  223. : public detail::covered_by::use_relate
  224. {};
  225. template <typename Box, typename Polygon>
  226. struct covered_by<Box, Polygon, box_tag, multi_polygon_tag>
  227. : public detail::covered_by::use_relate
  228. {};
  229. // Geometry/Box
  230. template <typename Point, typename Box>
  231. struct covered_by<Point, Box, point_tag, box_tag>
  232. {
  233. template <typename Strategy>
  234. static inline bool apply(Point const& point, Box const& box, Strategy const& strategy)
  235. {
  236. return strategy.covered_by(point, box).apply(point, box);
  237. }
  238. };
  239. template <typename MultiPoint, typename Box>
  240. struct covered_by<MultiPoint, Box, multi_point_tag, box_tag>
  241. : public detail::covered_by::geometry_covered_by_box
  242. {};
  243. template <typename Linestring, typename Box>
  244. struct covered_by<Linestring, Box, linestring_tag, box_tag>
  245. : public detail::covered_by::geometry_covered_by_box
  246. {};
  247. template <typename MultiLinestring, typename Box>
  248. struct covered_by<MultiLinestring, Box, multi_linestring_tag, box_tag>
  249. : public detail::covered_by::geometry_covered_by_box
  250. {};
  251. template <typename Ring, typename Box>
  252. struct covered_by<Ring, Box, ring_tag, box_tag>
  253. : public detail::covered_by::geometry_covered_by_box
  254. {};
  255. template <typename Polygon, typename Box>
  256. struct covered_by<Polygon, Box, polygon_tag, box_tag>
  257. : public detail::covered_by::geometry_covered_by_box
  258. {};
  259. template <typename MultiPolygon, typename Box>
  260. struct covered_by<MultiPolygon, Box, multi_polygon_tag, box_tag>
  261. : public detail::covered_by::geometry_covered_by_box
  262. {};
  263. template <typename Box1, typename Box2>
  264. struct covered_by<Box1, Box2, box_tag, box_tag>
  265. {
  266. template <typename Strategy>
  267. static inline bool apply(Box1 const& box1, Box2 const& box2, Strategy const& strategy)
  268. {
  269. assert_dimension_equal<Box1, Box2>();
  270. return strategy.covered_by(box1, box2).apply(box1, box2);
  271. }
  272. };
  273. } // namespace dispatch
  274. #endif // DOXYGEN_NO_DISPATCH
  275. }} // namespace boost::geometry
  276. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_COVERED_BY_IMPLEMENTATION_HPP