spherical.hpp 11 KB

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