spherical.hpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_INDEX_SPHERICAL_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_INDEX_SPHERICAL_HPP
  8. // TEMP - move to strategy
  9. #include <boost/geometry/strategies/spherical/distance_cross_track.hpp>
  10. #include <boost/geometry/strategies/spherical/distance_cross_track_point_box.hpp>
  11. #include <boost/geometry/strategies/spherical/distance_haversine.hpp>
  12. #include <boost/geometry/strategies/spherical/distance_segment_box.hpp>
  13. #include <boost/geometry/strategies/index/services.hpp>
  14. #include <boost/geometry/strategies/relate/spherical.hpp>
  15. namespace boost { namespace geometry
  16. {
  17. namespace strategies { namespace index
  18. {
  19. #ifndef DOXYGEN_NO_DETAIL
  20. namespace detail
  21. {
  22. template <typename RadiusTypeOrSphere, typename CalculationType>
  23. class spherical
  24. : public strategies::relate::detail::spherical<RadiusTypeOrSphere, CalculationType>
  25. {
  26. using base_t = strategies::relate::detail::spherical<RadiusTypeOrSphere, CalculationType>;
  27. public:
  28. template <typename Geometry1, typename Geometry2>
  29. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  30. std::enable_if_t
  31. <
  32. util::is_pointlike<Geometry1>::value
  33. && util::is_pointlike<Geometry2>::value
  34. > * = nullptr) const
  35. {
  36. //return geometry::strategy::distance::comparable::haversine
  37. return geometry::strategy::distance::haversine
  38. <
  39. typename base_t::radius_type, CalculationType
  40. >(base_t::radius());
  41. }
  42. template <typename Geometry1, typename Geometry2>
  43. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  44. std::enable_if_t
  45. <
  46. (util::is_pointlike<Geometry1>::value
  47. && util::is_segment<Geometry2>::value)
  48. || (util::is_segment<Geometry1>::value
  49. && util::is_pointlike<Geometry2>::value)
  50. > * = nullptr) const
  51. {
  52. //return geometry::strategy::distance::comparable::cross_track
  53. return geometry::strategy::distance::cross_track
  54. <
  55. CalculationType,
  56. //geometry::strategy::distance::comparable::haversine
  57. geometry::strategy::distance::haversine
  58. <
  59. typename base_t::radius_type, CalculationType
  60. >
  61. >(base_t::radius());
  62. }
  63. template <typename Geometry1, typename Geometry2>
  64. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  65. std::enable_if_t
  66. <
  67. (util::is_pointlike<Geometry1>::value
  68. && util::is_box<Geometry2>::value)
  69. || (util::is_box<Geometry1>::value
  70. && util::is_pointlike<Geometry2>::value)
  71. > * = nullptr) const
  72. {
  73. //return geometry::strategy::distance::comparable::cross_track_point_box
  74. return geometry::strategy::distance::cross_track_point_box
  75. <
  76. CalculationType,
  77. //geometry::strategy::distance::comparable::haversine
  78. geometry::strategy::distance::haversine
  79. <
  80. typename base_t::radius_type, CalculationType
  81. >
  82. >(base_t::radius());
  83. }
  84. template <typename Geometry1, typename Geometry2>
  85. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  86. std::enable_if_t
  87. <
  88. (util::is_segment<Geometry1>::value
  89. && util::is_box<Geometry2>::value)
  90. || (util::is_box<Geometry1>::value
  91. && util::is_segment<Geometry2>::value)
  92. > * = nullptr) const
  93. {
  94. return geometry::strategy::distance::spherical_segment_box
  95. <
  96. CalculationType,
  97. //geometry::strategy::distance::comparable::haversine
  98. geometry::strategy::distance::haversine
  99. <
  100. typename base_t::radius_type, CalculationType
  101. >
  102. // TODO:
  103. >(/*base_t::radius()*/);
  104. }
  105. template <typename Geometry1, typename Geometry2>
  106. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  107. std::enable_if_t
  108. <
  109. util::is_segment<Geometry1>::value
  110. && util::is_segment<Geometry2>::value
  111. > * = nullptr) const
  112. {
  113. //return geometry::strategy::distance::comparable::cross_track
  114. return geometry::strategy::distance::cross_track
  115. <
  116. CalculationType,
  117. //geometry::strategy::distance::comparable::haversine
  118. geometry::strategy::distance::haversine
  119. <
  120. typename base_t::radius_type, CalculationType
  121. >
  122. >(base_t::radius());
  123. }
  124. };
  125. } // namespace detail
  126. #endif // DOXYGEN_NO_DETAIL
  127. template <typename CalculationType = void>
  128. class spherical
  129. : public strategies::index::detail::spherical<void, CalculationType>
  130. {};
  131. namespace services
  132. {
  133. template <typename Geometry>
  134. struct default_strategy<Geometry, spherical_tag>
  135. {
  136. using type = strategies::index::spherical<>;
  137. };
  138. template <typename Geometry>
  139. struct default_strategy<Geometry, spherical_equatorial_tag>
  140. {
  141. using type = strategies::index::spherical<>;
  142. };
  143. template <typename Geometry>
  144. struct default_strategy<Geometry, spherical_polar_tag>
  145. {
  146. using type = strategies::index::spherical<>;
  147. };
  148. // TEMP - needed in distance until umbrella strategies are supported
  149. template <typename CalculationType, typename SubStrategy>
  150. struct strategy_converter<strategy::distance::comparable::cross_track<CalculationType, SubStrategy>>
  151. {
  152. static auto get(strategy::distance::comparable::cross_track<CalculationType, SubStrategy> const& )
  153. {
  154. return strategies::index::spherical<CalculationType>();
  155. }
  156. };
  157. // TEMP - needed in distance until umbrella strategies are supported
  158. template <typename RadiusOrSphere, typename CalculationType>
  159. struct strategy_converter<strategy::distance::comparable::haversine<RadiusOrSphere, CalculationType>>
  160. {
  161. static auto get(strategy::distance::comparable::haversine<RadiusOrSphere, CalculationType> const&)
  162. {
  163. return strategies::index::spherical<CalculationType>();
  164. }
  165. };
  166. } // namespace services
  167. }}}} // namespace boost::geometry::strategy::index
  168. #endif // BOOST_GEOMETRY_STRATEGIES_INDEX_SPHERICAL_HPP