spherical.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. // Boost.Geometry
  2. // Copyright (c) 2020-2023, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_STRATEGIES_RELATE_SPHERICAL_HPP
  8. #define BOOST_GEOMETRY_STRATEGIES_RELATE_SPHERICAL_HPP
  9. // TEMP - move to strategy
  10. #include <boost/geometry/strategies/agnostic/point_in_box_by_side.hpp>
  11. #include <boost/geometry/strategies/cartesian/box_in_box.hpp>
  12. #include <boost/geometry/strategies/spherical/intersection.hpp>
  13. #include <boost/geometry/strategies/spherical/point_in_point.hpp>
  14. #include <boost/geometry/strategies/spherical/point_in_poly_winding.hpp>
  15. #include <boost/geometry/strategies/spherical/disjoint_box_box.hpp>
  16. #include <boost/geometry/strategies/distance/detail.hpp>
  17. #include <boost/geometry/strategies/distance/services.hpp>
  18. #include <boost/geometry/strategies/envelope/spherical.hpp>
  19. #include <boost/geometry/strategies/relate/services.hpp>
  20. #include <boost/geometry/strategies/detail.hpp>
  21. #include <boost/geometry/strategy/spherical/area.hpp>
  22. #include <boost/geometry/strategy/spherical/area_box.hpp>
  23. #include <boost/geometry/util/type_traits.hpp>
  24. namespace boost { namespace geometry
  25. {
  26. namespace strategies { namespace relate
  27. {
  28. #ifndef DOXYGEN_NO_DETAIL
  29. namespace detail
  30. {
  31. template <typename RadiusTypeOrSphere, typename CalculationType>
  32. class spherical
  33. : public strategies::envelope::detail::spherical<RadiusTypeOrSphere, CalculationType>
  34. {
  35. using base_t = strategies::envelope::detail::spherical<RadiusTypeOrSphere, CalculationType>;
  36. public:
  37. spherical() = default;
  38. template <typename RadiusOrSphere>
  39. explicit spherical(RadiusOrSphere const& radius_or_sphere)
  40. : strategies::envelope::detail::spherical<RadiusTypeOrSphere, CalculationType>(radius_or_sphere)
  41. {}
  42. // area
  43. template <typename Geometry>
  44. auto area(Geometry const&,
  45. std::enable_if_t<! util::is_box<Geometry>::value> * = nullptr) const
  46. {
  47. return strategy::area::spherical
  48. <
  49. typename base_t::radius_type, CalculationType
  50. >(base_t::radius());
  51. }
  52. template <typename Geometry>
  53. auto area(Geometry const&,
  54. std::enable_if_t<util::is_box<Geometry>::value> * = nullptr) const
  55. {
  56. return strategy::area::spherical_box
  57. <
  58. typename base_t::radius_type, CalculationType
  59. >(base_t::radius());
  60. }
  61. template <typename Geometry1, typename Geometry2>
  62. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  63. distance::detail::enable_if_pp_t<Geometry1, Geometry2> * = nullptr) const
  64. {
  65. return strategy::distance::comparable::haversine
  66. <
  67. typename base_t::radius_type, CalculationType
  68. >(base_t::radius());
  69. }
  70. // covered_by
  71. template <typename Geometry1, typename Geometry2>
  72. static auto covered_by(Geometry1 const&, Geometry2 const&,
  73. std::enable_if_t
  74. <
  75. util::is_pointlike<Geometry1>::value
  76. && util::is_box<Geometry2>::value
  77. > * = nullptr)
  78. {
  79. return strategy::covered_by::spherical_point_box();
  80. }
  81. template <typename Geometry1, typename Geometry2>
  82. static auto covered_by(Geometry1 const&, Geometry2 const&,
  83. std::enable_if_t
  84. <
  85. util::is_box<Geometry1>::value
  86. && util::is_box<Geometry2>::value
  87. > * = nullptr)
  88. {
  89. return strategy::covered_by::spherical_box_box();
  90. }
  91. // disjoint
  92. template <typename Geometry1, typename Geometry2>
  93. static auto disjoint(Geometry1 const&, Geometry2 const&,
  94. std::enable_if_t
  95. <
  96. util::is_box<Geometry1>::value
  97. && util::is_box<Geometry2>::value
  98. > * = nullptr)
  99. {
  100. return strategy::disjoint::spherical_box_box();
  101. }
  102. template <typename Geometry1, typename Geometry2>
  103. static auto disjoint(Geometry1 const&, Geometry2 const&,
  104. std::enable_if_t
  105. <
  106. util::is_segment<Geometry1>::value
  107. && util::is_box<Geometry2>::value
  108. > * = nullptr)
  109. {
  110. // NOTE: Inconsistent name.
  111. return strategy::disjoint::segment_box_spherical();
  112. }
  113. // relate
  114. template <typename Geometry1, typename Geometry2>
  115. static auto relate(Geometry1 const&, Geometry2 const&,
  116. std::enable_if_t
  117. <
  118. util::is_pointlike<Geometry1>::value
  119. && util::is_pointlike<Geometry2>::value
  120. > * = nullptr)
  121. {
  122. return strategy::within::spherical_point_point();
  123. }
  124. template <typename Geometry1, typename Geometry2>
  125. static auto relate(Geometry1 const&, Geometry2 const&,
  126. std::enable_if_t
  127. <
  128. util::is_pointlike<Geometry1>::value
  129. && ( util::is_linear<Geometry2>::value
  130. || util::is_polygonal<Geometry2>::value )
  131. > * = nullptr)
  132. {
  133. return strategy::within::spherical_winding<void, void, CalculationType>();
  134. }
  135. //template <typename Geometry1, typename Geometry2>
  136. static auto relate(/*Geometry1 const&, Geometry2 const&,
  137. std::enable_if_t
  138. <
  139. ( util::is_linear<Geometry1>::value
  140. || util::is_polygonal<Geometry1>::value )
  141. && ( util::is_linear<Geometry2>::value
  142. || util::is_polygonal<Geometry2>::value )
  143. > * = nullptr*/)
  144. {
  145. return strategy::intersection::spherical_segments<CalculationType>();
  146. }
  147. // side
  148. static auto side()
  149. {
  150. return strategy::side::spherical_side_formula<CalculationType>();
  151. }
  152. // within
  153. template <typename Geometry1, typename Geometry2>
  154. static auto within(Geometry1 const&, Geometry2 const&,
  155. std::enable_if_t
  156. <
  157. util::is_pointlike<Geometry1>::value
  158. && util::is_box<Geometry2>::value
  159. > * = nullptr)
  160. {
  161. return strategy::within::spherical_point_box();
  162. }
  163. template <typename Geometry1, typename Geometry2>
  164. static auto within(Geometry1 const&, Geometry2 const&,
  165. std::enable_if_t
  166. <
  167. util::is_box<Geometry1>::value
  168. && util::is_box<Geometry2>::value
  169. > * = nullptr)
  170. {
  171. return strategy::within::spherical_box_box();
  172. }
  173. template <typename ComparePolicy, typename EqualsPolicy>
  174. using compare_type = typename strategy::compare::spherical
  175. <
  176. ComparePolicy,
  177. EqualsPolicy,
  178. -1
  179. >;
  180. };
  181. } // namespace detail
  182. #endif // DOXYGEN_NO_DETAIL
  183. template <typename CalculationType = void>
  184. class spherical
  185. : public strategies::relate::detail::spherical<void, CalculationType>
  186. {};
  187. namespace services
  188. {
  189. template <typename Geometry1, typename Geometry2>
  190. struct default_strategy<Geometry1, Geometry2, spherical_tag, spherical_tag>
  191. {
  192. using type = strategies::relate::spherical<>;
  193. };
  194. template <typename Geometry1, typename Geometry2>
  195. struct default_strategy<Geometry1, Geometry2, spherical_equatorial_tag, spherical_equatorial_tag>
  196. {
  197. using type = strategies::relate::spherical<>;
  198. };
  199. template <typename Geometry1, typename Geometry2>
  200. struct default_strategy<Geometry1, Geometry2, spherical_polar_tag, spherical_polar_tag>
  201. {
  202. using type = strategies::relate::spherical<>;
  203. };
  204. template <>
  205. struct strategy_converter<strategy::within::spherical_point_point>
  206. {
  207. static auto get(strategy::within::spherical_point_point const& )
  208. {
  209. return strategies::relate::spherical<>();
  210. }
  211. };
  212. template <>
  213. struct strategy_converter<strategy::within::spherical_point_box>
  214. {
  215. static auto get(strategy::within::spherical_point_box const&)
  216. {
  217. return strategies::relate::spherical<>();
  218. }
  219. };
  220. template <>
  221. struct strategy_converter<strategy::covered_by::spherical_point_box>
  222. {
  223. static auto get(strategy::covered_by::spherical_point_box const&)
  224. {
  225. return strategies::relate::spherical<>();
  226. }
  227. };
  228. template <>
  229. struct strategy_converter<strategy::covered_by::spherical_box_box>
  230. {
  231. static auto get(strategy::covered_by::spherical_box_box const&)
  232. {
  233. return strategies::relate::spherical<>();
  234. }
  235. };
  236. template <>
  237. struct strategy_converter<strategy::disjoint::spherical_box_box>
  238. {
  239. static auto get(strategy::disjoint::spherical_box_box const&)
  240. {
  241. return strategies::relate::spherical<>();
  242. }
  243. };
  244. template <>
  245. struct strategy_converter<strategy::disjoint::segment_box_spherical>
  246. {
  247. static auto get(strategy::disjoint::segment_box_spherical const&)
  248. {
  249. return strategies::relate::spherical<>();
  250. }
  251. };
  252. template <>
  253. struct strategy_converter<strategy::within::spherical_box_box>
  254. {
  255. static auto get(strategy::within::spherical_box_box const&)
  256. {
  257. return strategies::relate::spherical<>();
  258. }
  259. };
  260. template <typename P1, typename P2, typename CalculationType>
  261. struct strategy_converter<strategy::within::spherical_winding<P1, P2, CalculationType>>
  262. {
  263. static auto get(strategy::within::spherical_winding<P1, P2, CalculationType> const& )
  264. {
  265. return strategies::relate::spherical<CalculationType>();
  266. }
  267. };
  268. template <typename CalculationType>
  269. struct strategy_converter<strategy::intersection::spherical_segments<CalculationType>>
  270. {
  271. static auto get(strategy::intersection::spherical_segments<CalculationType> const& )
  272. {
  273. return strategies::relate::spherical<CalculationType>();
  274. }
  275. };
  276. template <typename CalculationType>
  277. struct strategy_converter<strategy::within::spherical_point_box_by_side<CalculationType>>
  278. {
  279. struct altered_strategy
  280. : strategies::relate::spherical<CalculationType>
  281. {
  282. template <typename Geometry1, typename Geometry2>
  283. static auto covered_by(Geometry1 const&, Geometry2 const&,
  284. std::enable_if_t
  285. <
  286. util::is_pointlike<Geometry1>::value
  287. && util::is_box<Geometry2>::value
  288. > * = nullptr)
  289. {
  290. return strategy::covered_by::spherical_point_box_by_side<CalculationType>();
  291. }
  292. template <typename Geometry1, typename Geometry2>
  293. static auto within(Geometry1 const&, Geometry2 const&,
  294. std::enable_if_t
  295. <
  296. util::is_pointlike<Geometry1>::value
  297. && util::is_box<Geometry2>::value
  298. > * = nullptr)
  299. {
  300. return strategy::within::spherical_point_box_by_side<CalculationType>();
  301. }
  302. };
  303. static auto get(strategy::covered_by::spherical_point_box_by_side<CalculationType> const&)
  304. {
  305. return altered_strategy();
  306. }
  307. static auto get(strategy::within::spherical_point_box_by_side<CalculationType> const&)
  308. {
  309. return altered_strategy();
  310. }
  311. };
  312. template <typename CalculationType>
  313. struct strategy_converter<strategy::covered_by::spherical_point_box_by_side<CalculationType>>
  314. : strategy_converter<strategy::within::spherical_point_box_by_side<CalculationType>>
  315. {};
  316. // TEMP used in distance segment/box
  317. template <typename CalculationType>
  318. struct strategy_converter<strategy::side::spherical_side_formula<CalculationType>>
  319. {
  320. static auto get(strategy::side::spherical_side_formula<CalculationType> const& )
  321. {
  322. return strategies::relate::spherical<CalculationType>();
  323. }
  324. };
  325. } // namespace services
  326. }} // namespace strategies::relate
  327. }} // namespace boost::geometry
  328. #endif // BOOST_GEOMETRY_STRATEGIES_RELATE_SPHERICAL_HPP