areal_areal.hpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. // Boost.Geometry
  2. // Copyright (c) 2020, 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 detail::intersection::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. detail::intersection::expect_output_pla
  76. <
  77. Areal1, Areal2, single_out
  78. >
  79. >();
  80. typedef geometry::detail::output_geometry_access
  81. <
  82. single_out, polygon_tag, polygon_tag
  83. > areal;
  84. typedef geometry::detail::output_geometry_access
  85. <
  86. single_out, linestring_tag, linestring_tag
  87. > linear;
  88. typedef geometry::detail::output_geometry_access
  89. <
  90. single_out, point_tag, point_tag
  91. > pointlike;
  92. typedef typename geometry::tuples::element
  93. <
  94. areal::index, TupledOut
  95. >::type areal_out_type;
  96. typedef typename geometry::tuples::element
  97. <
  98. pointlike::index, TupledOut
  99. >::type pointlike_out_type;
  100. // NOTE: The same robust_policy is used in each call of
  101. // intersection_insert. Is that correct?
  102. // A * A -> A
  103. call_intersection(areal1, areal2, robust_policy,
  104. areal::get(geometry_out),
  105. strategy);
  106. bool const is_areal_empty = boost::empty(areal::get(geometry_out));
  107. TupledOut temp_out;
  108. // L * L -> (L, P)
  109. call_intersection(geometry::detail::boundary_view<Areal1 const>(areal1),
  110. geometry::detail::boundary_view<Areal2 const>(areal2),
  111. robust_policy,
  112. ! is_areal_empty
  113. ? temp_out
  114. : geometry_out,
  115. strategy);
  116. if (! is_areal_empty)
  117. {
  118. // NOTE: the original areal geometry could be used instead of boundary here
  119. // however this results in static assert failure related to rescale policy
  120. typedef geometry::detail::boundary_view
  121. <
  122. areal_out_type const
  123. > areal_out_boundary_type;
  124. areal_out_boundary_type areal_out_boundary(areal::get(geometry_out));
  125. // L - L -> L
  126. call_difference(linear::get(temp_out),
  127. areal_out_boundary,
  128. robust_policy,
  129. linear::get(geometry_out),
  130. strategy);
  131. // P - L -> P
  132. call_difference(pointlike::get(temp_out),
  133. areal_out_boundary,
  134. robust_policy,
  135. pointlike::get(geometry_out),
  136. strategy.template get_point_in_geometry_strategy
  137. <
  138. pointlike_out_type,
  139. areal_out_boundary_type
  140. >());
  141. }
  142. return;
  143. }
  144. private:
  145. template
  146. <
  147. typename Geometry1,
  148. typename Geometry2,
  149. typename RobustPolicy,
  150. typename GeometryOut,
  151. typename Strategy
  152. >
  153. static inline void call_intersection(Geometry1 const& geometry1,
  154. Geometry2 const& geometry2,
  155. RobustPolicy const& robust_policy,
  156. GeometryOut& geometry_out,
  157. Strategy const& strategy)
  158. {
  159. geometry::dispatch::intersection_insert
  160. <
  161. Geometry1,
  162. Geometry2,
  163. typename geometry::detail::output_geometry_value
  164. <
  165. GeometryOut
  166. >::type,
  167. overlay_intersection
  168. >::apply(geometry1,
  169. geometry2,
  170. robust_policy,
  171. geometry::detail::output_geometry_back_inserter(geometry_out),
  172. strategy);
  173. }
  174. template
  175. <
  176. typename Geometry1,
  177. typename Geometry2,
  178. typename RobustPolicy,
  179. typename GeometryOut,
  180. typename Strategy
  181. >
  182. static inline void call_difference(Geometry1 const& geometry1,
  183. Geometry2 const& geometry2,
  184. RobustPolicy const& robust_policy,
  185. GeometryOut& geometry_out,
  186. Strategy const& strategy)
  187. {
  188. geometry::dispatch::intersection_insert
  189. <
  190. Geometry1,
  191. Geometry2,
  192. typename boost::range_value<GeometryOut>::type,
  193. overlay_difference
  194. >::apply(geometry1,
  195. geometry2,
  196. robust_policy,
  197. geometry::range::back_inserter(geometry_out),
  198. strategy);
  199. }
  200. };
  201. struct intersection_areal_areal
  202. {
  203. template
  204. <
  205. typename Areal1,
  206. typename Areal2,
  207. typename RobustPolicy,
  208. typename GeometryOut,
  209. typename Strategy
  210. >
  211. static inline bool apply(Areal1 const& areal1,
  212. Areal2 const& areal2,
  213. RobustPolicy const& robust_policy,
  214. GeometryOut& geometry_out,
  215. Strategy const& strategy)
  216. {
  217. intersection_areal_areal_
  218. <
  219. GeometryOut
  220. >::apply(areal1, areal2, robust_policy, geometry_out, strategy);
  221. return true;
  222. }
  223. };
  224. }} // namespace detail::intersection
  225. #endif // DOXYGEN_NO_DETAIL
  226. #ifndef DOXYGEN_NO_DISPATCH
  227. namespace dispatch
  228. {
  229. template
  230. <
  231. typename Polygon1, typename Polygon2
  232. >
  233. struct intersection
  234. <
  235. Polygon1, Polygon2,
  236. polygon_tag, polygon_tag,
  237. false
  238. >
  239. : detail::intersection::intersection_areal_areal
  240. {};
  241. template
  242. <
  243. typename Polygon, typename Ring
  244. >
  245. struct intersection
  246. <
  247. Polygon, Ring,
  248. polygon_tag, ring_tag,
  249. false
  250. >
  251. : detail::intersection::intersection_areal_areal
  252. {};
  253. template
  254. <
  255. typename Ring1, typename Ring2
  256. >
  257. struct intersection
  258. <
  259. Ring1, Ring2,
  260. ring_tag, ring_tag,
  261. false
  262. >
  263. : detail::intersection::intersection_areal_areal
  264. {};
  265. template
  266. <
  267. typename Polygon, typename MultiPolygon
  268. >
  269. struct intersection
  270. <
  271. Polygon, MultiPolygon,
  272. polygon_tag, multi_polygon_tag,
  273. false
  274. >
  275. : detail::intersection::intersection_areal_areal
  276. {};
  277. template
  278. <
  279. typename MultiPolygon, typename Ring
  280. >
  281. struct intersection
  282. <
  283. MultiPolygon, Ring,
  284. multi_polygon_tag, ring_tag,
  285. false
  286. >
  287. : detail::intersection::intersection_areal_areal
  288. {};
  289. template
  290. <
  291. typename MultiPolygon1, typename MultiPolygon2
  292. >
  293. struct intersection
  294. <
  295. MultiPolygon1, MultiPolygon2,
  296. multi_polygon_tag, multi_polygon_tag,
  297. false
  298. >
  299. : detail::intersection::intersection_areal_areal
  300. {};
  301. } // namespace dispatch
  302. #endif // DOXYGEN_NO_DISPATCH
  303. }} // namespace boost::geometry
  304. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_AREAL_AREAL_HPP