spherical.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_DISCRETE_DISTANCE_SPHERICAL_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_DISCRETE_DISTANCE_SPHERICAL_HPP
  8. #include <boost/geometry/strategies/detail.hpp>
  9. #include <boost/geometry/strategies/discrete_distance/services.hpp>
  10. #include <boost/geometry/strategies/distance/comparable.hpp>
  11. #include <boost/geometry/strategies/distance/detail.hpp>
  12. #include <boost/geometry/strategies/spherical/distance_haversine.hpp>
  13. namespace boost { namespace geometry
  14. {
  15. namespace strategies { namespace discrete_distance
  16. {
  17. template
  18. <
  19. typename RadiusTypeOrSphere = double,
  20. typename CalculationType = void
  21. >
  22. class spherical
  23. : public strategies::detail::spherical_base<RadiusTypeOrSphere>
  24. {
  25. using base_t = strategies::detail::spherical_base<RadiusTypeOrSphere>;
  26. public:
  27. spherical() = default;
  28. template <typename RadiusOrSphere>
  29. explicit spherical(RadiusOrSphere const& radius_or_sphere)
  30. : base_t(radius_or_sphere)
  31. {}
  32. template <typename Geometry1, typename Geometry2>
  33. auto distance(Geometry1 const&, Geometry2 const&,
  34. distance::detail::enable_if_pp_t<Geometry1, Geometry2> * = nullptr) const
  35. {
  36. return strategy::distance::haversine
  37. <
  38. typename base_t::radius_type, CalculationType
  39. >(base_t::radius());
  40. }
  41. };
  42. namespace services
  43. {
  44. template <typename Geometry1, typename Geometry2>
  45. struct default_strategy<Geometry1, Geometry2, spherical_equatorial_tag, spherical_equatorial_tag>
  46. {
  47. using type = strategies::discrete_distance::spherical<>;
  48. };
  49. template <typename R, typename CT>
  50. struct strategy_converter<strategy::distance::haversine<R, CT> >
  51. {
  52. static auto get(strategy::distance::haversine<R, CT> const& s)
  53. {
  54. return strategies::discrete_distance::spherical<R, CT>(s.radius());
  55. }
  56. };
  57. template <typename R, typename CT>
  58. struct strategy_converter<strategy::distance::comparable::haversine<R, CT> >
  59. {
  60. static auto get(strategy::distance::comparable::haversine<R, CT> const& s)
  61. {
  62. return strategies::distance::detail::make_comparable(
  63. strategies::discrete_distance::spherical<R, CT>(s.radius()));
  64. }
  65. };
  66. } // namespace services
  67. }} // namespace strategies::discrete_distance
  68. }} // namespace boost::geometry
  69. #endif // BOOST_GEOMETRY_STRATEGIES_DISCRETE_DISTANCE_SPHERICAL_HPP