geographic.hpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. // Boost.Geometry
  2. // Copyright (c) 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_DISTANCE_GEOGRAPHIC_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_DISTANCE_GEOGRAPHIC_HPP
  8. #include <boost/geometry/strategies/distance/comparable.hpp>
  9. #include <boost/geometry/strategies/distance/detail.hpp>
  10. #include <boost/geometry/strategies/distance/services.hpp>
  11. #include <boost/geometry/strategies/detail.hpp>
  12. #include <boost/geometry/strategies/geographic/azimuth.hpp>
  13. #include <boost/geometry/strategies/geographic/distance.hpp>
  14. #include <boost/geometry/strategies/geographic/distance_cross_track.hpp>
  15. #include <boost/geometry/strategies/geographic/distance_cross_track_box_box.hpp>
  16. #include <boost/geometry/strategies/geographic/distance_cross_track_point_box.hpp>
  17. #include <boost/geometry/strategies/geographic/distance_segment_box.hpp>
  18. // TODO - for backwards compatibility, remove?
  19. #include <boost/geometry/strategies/geographic/distance_andoyer.hpp>
  20. #include <boost/geometry/strategies/geographic/distance_thomas.hpp>
  21. #include <boost/geometry/strategies/geographic/distance_vincenty.hpp>
  22. #include <boost/geometry/strategies/normalize.hpp>
  23. #include <boost/geometry/strategies/relate/geographic.hpp>
  24. namespace boost { namespace geometry
  25. {
  26. namespace strategies { namespace distance
  27. {
  28. // TODO: azimuth and normalize getters would not be needed if distance_segment_box was implemented differently
  29. // right now it calls disjoint algorithm details.
  30. template
  31. <
  32. typename FormulaPolicy = strategy::andoyer,
  33. typename Spheroid = srs::spheroid<double>,
  34. typename CalculationType = void
  35. >
  36. class geographic
  37. : public strategies::relate::geographic<FormulaPolicy, Spheroid, CalculationType>
  38. {
  39. using base_t = strategies::relate::geographic<FormulaPolicy, Spheroid, CalculationType>;
  40. public:
  41. geographic() = default;
  42. explicit geographic(Spheroid const& spheroid)
  43. : base_t(spheroid)
  44. {}
  45. // azimuth
  46. auto azimuth() const
  47. {
  48. return strategy::azimuth::geographic
  49. <
  50. FormulaPolicy, Spheroid, CalculationType
  51. >(base_t::m_spheroid);
  52. }
  53. // distance
  54. template <typename Geometry1, typename Geometry2>
  55. auto distance(Geometry1 const&, Geometry2 const&,
  56. detail::enable_if_pp_t<Geometry1, Geometry2> * = nullptr) const
  57. {
  58. return strategy::distance::geographic
  59. <
  60. FormulaPolicy, Spheroid, CalculationType
  61. >(base_t::m_spheroid);
  62. }
  63. template <typename Geometry1, typename Geometry2>
  64. auto distance(Geometry1 const&, Geometry2 const&,
  65. detail::enable_if_ps_t<Geometry1, Geometry2> * = nullptr) const
  66. {
  67. return strategy::distance::geographic_cross_track
  68. <
  69. FormulaPolicy, Spheroid, CalculationType
  70. >(base_t::m_spheroid);
  71. }
  72. template <typename Geometry1, typename Geometry2>
  73. auto distance(Geometry1 const&, Geometry2 const&,
  74. detail::enable_if_pb_t<Geometry1, Geometry2> * = nullptr) const
  75. {
  76. return strategy::distance::geographic_cross_track_point_box
  77. <
  78. FormulaPolicy, Spheroid, CalculationType
  79. >(base_t::m_spheroid);
  80. }
  81. template <typename Geometry1, typename Geometry2>
  82. auto distance(Geometry1 const&, Geometry2 const&,
  83. detail::enable_if_sb_t<Geometry1, Geometry2> * = nullptr) const
  84. {
  85. return strategy::distance::geographic_segment_box
  86. <
  87. FormulaPolicy, Spheroid, CalculationType
  88. >(base_t::m_spheroid);
  89. }
  90. template <typename Geometry1, typename Geometry2>
  91. auto distance(Geometry1 const&, Geometry2 const&,
  92. detail::enable_if_bb_t<Geometry1, Geometry2> * = nullptr) const
  93. {
  94. return strategy::distance::geographic_cross_track_box_box
  95. <
  96. FormulaPolicy, Spheroid, CalculationType
  97. >(base_t::m_spheroid);
  98. }
  99. // normalize
  100. template <typename Geometry>
  101. static auto normalize(Geometry const&,
  102. std::enable_if_t
  103. <
  104. util::is_point<Geometry>::value
  105. > * = nullptr)
  106. {
  107. return strategy::normalize::spherical_point();
  108. }
  109. };
  110. namespace services
  111. {
  112. template <typename Geometry1, typename Geometry2>
  113. struct default_strategy<Geometry1, Geometry2, geographic_tag, geographic_tag>
  114. {
  115. using type = strategies::distance::geographic<>;
  116. };
  117. template <typename FP, typename S, typename CT>
  118. struct strategy_converter<strategy::distance::geographic<FP, S, CT> >
  119. {
  120. static auto get(strategy::distance::geographic<FP, S, CT> const& s)
  121. {
  122. return strategies::distance::geographic<FP, S, CT>(s.model());
  123. }
  124. };
  125. // TODO - for backwards compatibility, remove?
  126. template <typename S, typename CT>
  127. struct strategy_converter<strategy::distance::andoyer<S, CT> >
  128. {
  129. static auto get(strategy::distance::andoyer<S, CT> const& s)
  130. {
  131. return strategies::distance::geographic<strategy::andoyer, S, CT>(s.model());
  132. }
  133. };
  134. // TODO - for backwards compatibility, remove?
  135. template <typename S, typename CT>
  136. struct strategy_converter<strategy::distance::thomas<S, CT> >
  137. {
  138. static auto get(strategy::distance::thomas<S, CT> const& s)
  139. {
  140. return strategies::distance::geographic<strategy::thomas, S, CT>(s.model());
  141. }
  142. };
  143. // TODO - for backwards compatibility, remove?
  144. template <typename S, typename CT>
  145. struct strategy_converter<strategy::distance::vincenty<S, CT> >
  146. {
  147. static auto get(strategy::distance::vincenty<S, CT> const& s)
  148. {
  149. return strategies::distance::geographic<strategy::vincenty, S, CT>(s.model());
  150. }
  151. };
  152. template <typename FP, typename S, typename CT>
  153. struct strategy_converter<strategy::distance::geographic_cross_track<FP, S, CT> >
  154. {
  155. static auto get(strategy::distance::geographic_cross_track<FP, S, CT> const& s)
  156. {
  157. return strategies::distance::geographic<FP, S, CT>(s.model());
  158. }
  159. };
  160. template <typename FP, typename S, typename CT>
  161. struct strategy_converter<strategy::distance::geographic_cross_track_point_box<FP, S, CT> >
  162. {
  163. static auto get(strategy::distance::geographic_cross_track_point_box<FP, S, CT> const& s)
  164. {
  165. return strategies::distance::geographic<FP, S, CT>(s.model());
  166. }
  167. };
  168. template <typename FP, typename S, typename CT>
  169. struct strategy_converter<strategy::distance::geographic_segment_box<FP, S, CT> >
  170. {
  171. static auto get(strategy::distance::geographic_segment_box<FP, S, CT> const& s)
  172. {
  173. return strategies::distance::geographic<FP, S, CT>(s.model());
  174. }
  175. };
  176. template <typename FP, typename S, typename CT>
  177. struct strategy_converter<strategy::distance::geographic_cross_track_box_box<FP, S, CT> >
  178. {
  179. static auto get(strategy::distance::geographic_cross_track_box_box<FP, S, CT> const& s)
  180. {
  181. return strategies::distance::geographic<FP, S, CT>(s.model());
  182. }
  183. };
  184. // details
  185. // TODO: This specialization wouldn't be needed if strategy::distance::geographic_cross_track was implemented as an alias
  186. template <typename FP, typename S, typename CT, bool B, bool ECP>
  187. struct strategy_converter<strategy::distance::detail::geographic_cross_track<FP, S, CT, B, ECP> >
  188. {
  189. struct altered_strategy
  190. : strategies::distance::geographic<FP, S, CT>
  191. {
  192. typedef strategies::distance::geographic<FP, S, CT> base_t;
  193. explicit altered_strategy(S const& s) : base_t(s) {}
  194. using base_t::distance;
  195. template <typename Geometry1, typename Geometry2>
  196. auto distance(Geometry1 const&, Geometry2 const&,
  197. detail::enable_if_ps_t<Geometry1, Geometry2> * = nullptr) const
  198. {
  199. return strategy::distance::detail::geographic_cross_track
  200. <
  201. FP, S, CT, B, ECP
  202. >(base_t::m_spheroid);
  203. }
  204. };
  205. static auto get(strategy::distance::detail::geographic_cross_track<FP, S, CT, B, ECP> const& s)
  206. {
  207. return altered_strategy(s.model());
  208. }
  209. };
  210. } // namespace services
  211. }} // namespace strategies::distance
  212. }} // namespace boost::geometry
  213. #endif // BOOST_GEOMETRY_STRATEGIES_DISTANCE_GEOGRAPHIC_HPP