areal_areal.hpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. // Boost.Geometry
  2. // Copyright (c) 2020-2021, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_AREAL_AREAL_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_AREAL_AREAL_HPP
  8. #include <boost/core/ignore_unused.hpp>
  9. #include <boost/geometry/algorithms/detail/intersection/interface.hpp>
  10. namespace boost { namespace geometry
  11. {
  12. #ifndef DOXYGEN_NO_DETAIL
  13. namespace detail { namespace intersection
  14. {
  15. template
  16. <
  17. typename GeometryOut,
  18. typename OutTag = typename geometry::detail::setop_insert_output_tag
  19. <
  20. typename geometry::detail::output_geometry_value
  21. <
  22. GeometryOut
  23. >::type
  24. >::type
  25. >
  26. struct intersection_areal_areal_
  27. {
  28. template
  29. <
  30. typename Areal1,
  31. typename Areal2,
  32. typename RobustPolicy,
  33. typename Strategy
  34. >
  35. static inline void apply(Areal1 const& areal1,
  36. Areal2 const& areal2,
  37. RobustPolicy const& robust_policy,
  38. GeometryOut& geometry_out,
  39. Strategy const& strategy)
  40. {
  41. geometry::dispatch::intersection_insert
  42. <
  43. Areal1, Areal2,
  44. typename boost::range_value<GeometryOut>::type,
  45. overlay_intersection
  46. >::apply(areal1, areal2, robust_policy,
  47. geometry::range::back_inserter(geometry_out),
  48. strategy);
  49. }
  50. };
  51. // TODO: Ideally this should be done in one call of intersection_insert
  52. // just like it's done for all other combinations
  53. template <typename TupledOut>
  54. struct intersection_areal_areal_<TupledOut, tupled_output_tag>
  55. {
  56. template
  57. <
  58. typename Areal1,
  59. typename Areal2,
  60. typename RobustPolicy,
  61. typename Strategy
  62. >
  63. static inline void apply(Areal1 const& areal1,
  64. Areal2 const& areal2,
  65. RobustPolicy const& robust_policy,
  66. TupledOut& geometry_out,
  67. Strategy const& strategy)
  68. {
  69. typedef typename geometry::detail::output_geometry_value
  70. <
  71. TupledOut
  72. >::type single_out;
  73. boost::ignore_unused
  74. <
  75. geometry::detail::expect_output
  76. <
  77. Areal1, Areal2, single_out,
  78. point_tag, linestring_tag, polygon_tag
  79. >
  80. >();
  81. typedef geometry::detail::output_geometry_access
  82. <
  83. single_out, polygon_tag, polygon_tag
  84. > areal;
  85. typedef geometry::detail::output_geometry_access
  86. <
  87. single_out, linestring_tag, linestring_tag
  88. > linear;
  89. typedef geometry::detail::output_geometry_access
  90. <
  91. single_out, point_tag, point_tag
  92. > pointlike;
  93. typedef typename geometry::tuples::element
  94. <
  95. areal::index, TupledOut
  96. >::type areal_out_type;
  97. // NOTE: The same robust_policy is used in each call of
  98. // intersection_insert. Is that correct?
  99. // A * A -> A
  100. call_intersection(areal1, areal2, robust_policy,
  101. areal::get(geometry_out),
  102. strategy);
  103. bool const is_areal_empty = boost::empty(areal::get(geometry_out));
  104. TupledOut temp_out;
  105. // L * L -> (L, P)
  106. call_intersection(geometry::detail::boundary_view<Areal1 const>(areal1),
  107. geometry::detail::boundary_view<Areal2 const>(areal2),
  108. robust_policy,
  109. ! is_areal_empty
  110. ? temp_out
  111. : geometry_out,
  112. strategy);
  113. if (! is_areal_empty)
  114. {
  115. // NOTE: the original areal geometry could be used instead of boundary here
  116. // however this results in static assert failure related to rescale policy
  117. typedef geometry::detail::boundary_view
  118. <
  119. areal_out_type const
  120. > areal_out_boundary_type;
  121. areal_out_boundary_type areal_out_boundary(areal::get(geometry_out));
  122. // L - L -> L
  123. call_difference(linear::get(temp_out),
  124. areal_out_boundary,
  125. robust_policy,
  126. linear::get(geometry_out),
  127. strategy);
  128. // P - L -> P
  129. call_difference(pointlike::get(temp_out),
  130. areal_out_boundary,
  131. robust_policy,
  132. pointlike::get(geometry_out),
  133. strategy);
  134. }
  135. return;
  136. }
  137. private:
  138. template
  139. <
  140. typename Geometry1,
  141. typename Geometry2,
  142. typename RobustPolicy,
  143. typename GeometryOut,
  144. typename Strategy
  145. >
  146. static inline void call_intersection(Geometry1 const& geometry1,
  147. Geometry2 const& geometry2,
  148. RobustPolicy const& robust_policy,
  149. GeometryOut& geometry_out,
  150. Strategy const& strategy)
  151. {
  152. geometry::dispatch::intersection_insert
  153. <
  154. Geometry1,
  155. Geometry2,
  156. typename geometry::detail::output_geometry_value
  157. <
  158. GeometryOut
  159. >::type,
  160. overlay_intersection
  161. >::apply(geometry1,
  162. geometry2,
  163. robust_policy,
  164. geometry::detail::output_geometry_back_inserter(geometry_out),
  165. strategy);
  166. }
  167. template
  168. <
  169. typename Geometry1,
  170. typename Geometry2,
  171. typename RobustPolicy,
  172. typename GeometryOut,
  173. typename Strategy
  174. >
  175. static inline void call_difference(Geometry1 const& geometry1,
  176. Geometry2 const& geometry2,
  177. RobustPolicy const& robust_policy,
  178. GeometryOut& geometry_out,
  179. Strategy const& strategy)
  180. {
  181. geometry::dispatch::intersection_insert
  182. <
  183. Geometry1,
  184. Geometry2,
  185. typename boost::range_value<GeometryOut>::type,
  186. overlay_difference
  187. >::apply(geometry1,
  188. geometry2,
  189. robust_policy,
  190. geometry::range::back_inserter(geometry_out),
  191. strategy);
  192. }
  193. };
  194. struct intersection_areal_areal
  195. {
  196. template
  197. <
  198. typename Areal1,
  199. typename Areal2,
  200. typename RobustPolicy,
  201. typename GeometryOut,
  202. typename Strategy
  203. >
  204. static inline bool apply(Areal1 const& areal1,
  205. Areal2 const& areal2,
  206. RobustPolicy const& robust_policy,
  207. GeometryOut& geometry_out,
  208. Strategy const& strategy)
  209. {
  210. intersection_areal_areal_
  211. <
  212. GeometryOut
  213. >::apply(areal1, areal2, robust_policy, geometry_out, strategy);
  214. return true;
  215. }
  216. };
  217. }} // namespace detail::intersection
  218. #endif // DOXYGEN_NO_DETAIL
  219. #ifndef DOXYGEN_NO_DISPATCH
  220. namespace dispatch
  221. {
  222. template
  223. <
  224. typename Polygon1, typename Polygon2
  225. >
  226. struct intersection
  227. <
  228. Polygon1, Polygon2,
  229. polygon_tag, polygon_tag,
  230. false
  231. >
  232. : detail::intersection::intersection_areal_areal
  233. {};
  234. template
  235. <
  236. typename Polygon, typename Ring
  237. >
  238. struct intersection
  239. <
  240. Polygon, Ring,
  241. polygon_tag, ring_tag,
  242. false
  243. >
  244. : detail::intersection::intersection_areal_areal
  245. {};
  246. template
  247. <
  248. typename Ring1, typename Ring2
  249. >
  250. struct intersection
  251. <
  252. Ring1, Ring2,
  253. ring_tag, ring_tag,
  254. false
  255. >
  256. : detail::intersection::intersection_areal_areal
  257. {};
  258. template
  259. <
  260. typename Polygon, typename MultiPolygon
  261. >
  262. struct intersection
  263. <
  264. Polygon, MultiPolygon,
  265. polygon_tag, multi_polygon_tag,
  266. false
  267. >
  268. : detail::intersection::intersection_areal_areal
  269. {};
  270. template
  271. <
  272. typename MultiPolygon, typename Ring
  273. >
  274. struct intersection
  275. <
  276. MultiPolygon, Ring,
  277. multi_polygon_tag, ring_tag,
  278. false
  279. >
  280. : detail::intersection::intersection_areal_areal
  281. {};
  282. template
  283. <
  284. typename MultiPolygon1, typename MultiPolygon2
  285. >
  286. struct intersection
  287. <
  288. MultiPolygon1, MultiPolygon2,
  289. multi_polygon_tag, multi_polygon_tag,
  290. false
  291. >
  292. : detail::intersection::intersection_areal_areal
  293. {};
  294. } // namespace dispatch
  295. #endif // DOXYGEN_NO_DISPATCH
  296. }} // namespace boost::geometry
  297. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_AREAL_AREAL_HPP