cartesian.hpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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_STRATEGIES_RELATE_CARTESIAN_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_RELATE_CARTESIAN_HPP
  8. // TEMP - move to strategy
  9. #include <boost/geometry/strategies/agnostic/point_in_box_by_side.hpp>
  10. #include <boost/geometry/strategies/cartesian/intersection.hpp>
  11. #include <boost/geometry/strategies/cartesian/box_in_box.hpp>
  12. #include <boost/geometry/strategies/cartesian/point_in_point.hpp>
  13. #include <boost/geometry/strategies/cartesian/point_in_poly_crossings_multiply.hpp>
  14. #include <boost/geometry/strategies/cartesian/point_in_poly_franklin.hpp>
  15. #include <boost/geometry/strategies/cartesian/point_in_poly_winding.hpp>
  16. #include <boost/geometry/strategies/cartesian/disjoint_box_box.hpp>
  17. #include <boost/geometry/strategies/envelope/cartesian.hpp>
  18. #include <boost/geometry/strategies/relate/services.hpp>
  19. #include <boost/geometry/strategies/detail.hpp>
  20. #include <boost/geometry/strategy/cartesian/area.hpp>
  21. #include <boost/geometry/util/type_traits.hpp>
  22. namespace boost { namespace geometry
  23. {
  24. namespace strategies { namespace relate
  25. {
  26. template <typename CalculationType = void>
  27. class cartesian
  28. : public strategies::envelope::cartesian<CalculationType>
  29. {
  30. public:
  31. //area
  32. template <typename Geometry>
  33. static auto area(Geometry const&)
  34. {
  35. return strategy::area::cartesian<CalculationType>();
  36. }
  37. // covered_by
  38. template <typename Geometry1, typename Geometry2>
  39. static auto covered_by(Geometry1 const&, Geometry2 const&,
  40. std::enable_if_t
  41. <
  42. util::is_pointlike<Geometry1>::value
  43. && util::is_box<Geometry2>::value
  44. > * = nullptr)
  45. {
  46. return strategy::covered_by::cartesian_point_box();
  47. }
  48. template <typename Geometry1, typename Geometry2>
  49. static auto covered_by(Geometry1 const&, Geometry2 const&,
  50. std::enable_if_t
  51. <
  52. util::is_box<Geometry1>::value
  53. && util::is_box<Geometry2>::value
  54. > * = nullptr)
  55. {
  56. return strategy::covered_by::cartesian_box_box();
  57. }
  58. // disjoint
  59. template <typename Geometry1, typename Geometry2>
  60. static auto disjoint(Geometry1 const&, Geometry2 const&,
  61. std::enable_if_t
  62. <
  63. util::is_box<Geometry1>::value
  64. && util::is_box<Geometry2>::value
  65. > * = nullptr)
  66. {
  67. return strategy::disjoint::cartesian_box_box();
  68. }
  69. template <typename Geometry1, typename Geometry2>
  70. static auto disjoint(Geometry1 const&, Geometry2 const&,
  71. std::enable_if_t
  72. <
  73. util::is_segment<Geometry1>::value
  74. && util::is_box<Geometry2>::value
  75. > * = nullptr)
  76. {
  77. // NOTE: Inconsistent name.
  78. return strategy::disjoint::segment_box();
  79. }
  80. // relate
  81. template <typename Geometry1, typename Geometry2>
  82. static auto relate(Geometry1 const&, Geometry2 const&,
  83. std::enable_if_t
  84. <
  85. util::is_pointlike<Geometry1>::value
  86. && util::is_pointlike<Geometry2>::value
  87. > * = nullptr)
  88. {
  89. return strategy::within::cartesian_point_point();
  90. }
  91. template <typename Geometry1, typename Geometry2>
  92. static auto relate(Geometry1 const&, Geometry2 const&,
  93. std::enable_if_t
  94. <
  95. util::is_pointlike<Geometry1>::value
  96. && ( util::is_linear<Geometry2>::value
  97. || util::is_polygonal<Geometry2>::value )
  98. > * = nullptr)
  99. {
  100. return strategy::within::cartesian_winding<void, void, CalculationType>();
  101. }
  102. // The problem is that this strategy is often used with non-geometry ranges.
  103. // So dispatching only by geometry categories is impossible.
  104. // In the past it was taking two segments, now it takes 3-point sub-ranges.
  105. // So dispatching by segments is impossible.
  106. // It could be dispatched by (linear || polygonal || non-geometry point range).
  107. // For now implement as 0-parameter, special case relate.
  108. //template <typename Geometry1, typename Geometry2>
  109. static auto relate(/*Geometry1 const&, Geometry2 const&,
  110. std::enable_if_t
  111. <
  112. ( util::is_linear<Geometry1>::value
  113. || util::is_polygonal<Geometry1>::value )
  114. && ( util::is_linear<Geometry2>::value
  115. || util::is_polygonal<Geometry2>::value )
  116. > * = nullptr*/)
  117. {
  118. return strategy::intersection::cartesian_segments<CalculationType>();
  119. }
  120. // side
  121. static auto side()
  122. {
  123. return strategy::side::side_by_triangle<CalculationType>();
  124. }
  125. // within
  126. template <typename Geometry1, typename Geometry2>
  127. static auto within(Geometry1 const&, Geometry2 const&,
  128. std::enable_if_t
  129. <
  130. util::is_pointlike<Geometry1>::value
  131. && util::is_box<Geometry2>::value
  132. > * = nullptr)
  133. {
  134. return strategy::within::cartesian_point_box();
  135. }
  136. template <typename Geometry1, typename Geometry2>
  137. static auto within(Geometry1 const&, Geometry2 const&,
  138. std::enable_if_t
  139. <
  140. util::is_box<Geometry1>::value
  141. && util::is_box<Geometry2>::value
  142. > * = nullptr)
  143. {
  144. return strategy::within::cartesian_box_box();
  145. }
  146. };
  147. namespace services
  148. {
  149. template <typename Geometry1, typename Geometry2>
  150. struct default_strategy<Geometry1, Geometry2, cartesian_tag, cartesian_tag>
  151. {
  152. using type = strategies::relate::cartesian<>;
  153. };
  154. template <>
  155. struct strategy_converter<strategy::within::cartesian_point_point>
  156. {
  157. static auto get(strategy::within::cartesian_point_point const& )
  158. {
  159. return strategies::relate::cartesian<>();
  160. }
  161. };
  162. template <>
  163. struct strategy_converter<strategy::within::cartesian_point_box>
  164. {
  165. static auto get(strategy::within::cartesian_point_box const&)
  166. {
  167. return strategies::relate::cartesian<>();
  168. }
  169. };
  170. template <>
  171. struct strategy_converter<strategy::covered_by::cartesian_point_box>
  172. {
  173. static auto get(strategy::covered_by::cartesian_point_box const&)
  174. {
  175. return strategies::relate::cartesian<>();
  176. }
  177. };
  178. template <>
  179. struct strategy_converter<strategy::covered_by::cartesian_box_box>
  180. {
  181. static auto get(strategy::covered_by::cartesian_box_box const&)
  182. {
  183. return strategies::relate::cartesian<>();
  184. }
  185. };
  186. template <>
  187. struct strategy_converter<strategy::disjoint::cartesian_box_box>
  188. {
  189. static auto get(strategy::disjoint::cartesian_box_box const&)
  190. {
  191. return strategies::relate::cartesian<>();
  192. }
  193. };
  194. template <>
  195. struct strategy_converter<strategy::disjoint::segment_box>
  196. {
  197. static auto get(strategy::disjoint::segment_box const&)
  198. {
  199. return strategies::relate::cartesian<>();
  200. }
  201. };
  202. template <>
  203. struct strategy_converter<strategy::within::cartesian_box_box>
  204. {
  205. static auto get(strategy::within::cartesian_box_box const&)
  206. {
  207. return strategies::relate::cartesian<>();
  208. }
  209. };
  210. template <typename P1, typename P2, typename CalculationType>
  211. struct strategy_converter<strategy::within::cartesian_winding<P1, P2, CalculationType>>
  212. {
  213. static auto get(strategy::within::cartesian_winding<P1, P2, CalculationType> const& )
  214. {
  215. return strategies::relate::cartesian<CalculationType>();
  216. }
  217. };
  218. template <typename CalculationType>
  219. struct strategy_converter<strategy::intersection::cartesian_segments<CalculationType>>
  220. {
  221. static auto get(strategy::intersection::cartesian_segments<CalculationType> const& )
  222. {
  223. return strategies::relate::cartesian<CalculationType>();
  224. }
  225. };
  226. template <typename CalculationType>
  227. struct strategy_converter<strategy::within::cartesian_point_box_by_side<CalculationType>>
  228. {
  229. struct altered_strategy
  230. : strategies::relate::cartesian<CalculationType>
  231. {
  232. template <typename Geometry1, typename Geometry2>
  233. static auto covered_by(Geometry1 const&, Geometry2 const&,
  234. std::enable_if_t
  235. <
  236. util::is_pointlike<Geometry1>::value
  237. && util::is_box<Geometry2>::value
  238. > * = nullptr)
  239. {
  240. return strategy::covered_by::cartesian_point_box_by_side<CalculationType>();
  241. }
  242. template <typename Geometry1, typename Geometry2>
  243. static auto within(Geometry1 const&, Geometry2 const&,
  244. std::enable_if_t
  245. <
  246. util::is_pointlike<Geometry1>::value
  247. && util::is_box<Geometry2>::value
  248. > * = nullptr)
  249. {
  250. return strategy::within::cartesian_point_box_by_side<CalculationType>();
  251. }
  252. };
  253. static auto get(strategy::covered_by::cartesian_point_box_by_side<CalculationType> const&)
  254. {
  255. return altered_strategy();
  256. }
  257. static auto get(strategy::within::cartesian_point_box_by_side<CalculationType> const&)
  258. {
  259. return altered_strategy();
  260. }
  261. };
  262. template <typename CalculationType>
  263. struct strategy_converter<strategy::covered_by::cartesian_point_box_by_side<CalculationType>>
  264. : strategy_converter<strategy::within::cartesian_point_box_by_side<CalculationType>>
  265. {};
  266. template <typename P1, typename P2, typename CalculationType>
  267. struct strategy_converter<strategy::within::franklin<P1, P2, CalculationType>>
  268. {
  269. struct altered_strategy
  270. : strategies::relate::cartesian<CalculationType>
  271. {
  272. template <typename Geometry1, typename Geometry2>
  273. static auto relate(Geometry1 const&, Geometry2 const&,
  274. std::enable_if_t
  275. <
  276. util::is_pointlike<Geometry1>::value
  277. && ( util::is_linear<Geometry2>::value
  278. || util::is_polygonal<Geometry2>::value )
  279. > * = nullptr)
  280. {
  281. return strategy::within::franklin<void, void, CalculationType>();
  282. }
  283. };
  284. static auto get(strategy::within::franklin<P1, P2, CalculationType> const&)
  285. {
  286. return altered_strategy();
  287. }
  288. };
  289. template <typename P1, typename P2, typename CalculationType>
  290. struct strategy_converter<strategy::within::crossings_multiply<P1, P2, CalculationType>>
  291. {
  292. struct altered_strategy
  293. : strategies::relate::cartesian<CalculationType>
  294. {
  295. template <typename Geometry1, typename Geometry2>
  296. static auto relate(Geometry1 const&, Geometry2 const&,
  297. std::enable_if_t
  298. <
  299. util::is_pointlike<Geometry1>::value
  300. && ( util::is_linear<Geometry2>::value
  301. || util::is_polygonal<Geometry2>::value )
  302. > * = nullptr)
  303. {
  304. return strategy::within::crossings_multiply<void, void, CalculationType>();
  305. }
  306. };
  307. static auto get(strategy::within::crossings_multiply<P1, P2, CalculationType> const&)
  308. {
  309. return altered_strategy();
  310. }
  311. };
  312. // TEMP used in distance segment/box
  313. template <typename CalculationType>
  314. struct strategy_converter<strategy::side::side_by_triangle<CalculationType>>
  315. {
  316. static auto get(strategy::side::side_by_triangle<CalculationType> const&)
  317. {
  318. return strategies::relate::cartesian<CalculationType>();
  319. }
  320. };
  321. } // namespace services
  322. }} // namespace strategies::relate
  323. }} // namespace boost::geometry
  324. #endif // BOOST_GEOMETRY_STRATEGIES_RELATE_CARTESIAN_HPP