spherical.hpp 12 KB

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