spherical.hpp 12 KB

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