1 // Boost.Geometry 2 3 // Copyright (c) 2021, Oracle and/or its affiliates. 4 5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle 6 7 // Licensed under the Boost Software License version 1.0. 8 // http://www.boost.org/users/license.html 9 10 #ifndef BOOST_GEOMETRY_STRATEGIES_DISCRETE_DISTANCE_SPHERICAL_HPP 11 #define BOOST_GEOMETRY_STRATEGIES_DISCRETE_DISTANCE_SPHERICAL_HPP 12 13 14 #include <boost/geometry/strategies/detail.hpp> 15 #include <boost/geometry/strategies/discrete_distance/services.hpp> 16 #include <boost/geometry/strategies/distance/comparable.hpp> 17 #include <boost/geometry/strategies/distance/detail.hpp> 18 19 #include <boost/geometry/strategies/spherical/distance_haversine.hpp> 20 21 22 namespace boost { namespace geometry 23 { 24 25 namespace strategies { namespace discrete_distance 26 { 27 28 template 29 < 30 typename RadiusTypeOrSphere = double, 31 typename CalculationType = void 32 > 33 class spherical 34 : public strategies::detail::spherical_base<RadiusTypeOrSphere> 35 { 36 using base_t = strategies::detail::spherical_base<RadiusTypeOrSphere>; 37 38 public: 39 spherical() = default; 40 41 template <typename RadiusOrSphere> spherical(RadiusOrSphere const & radius_or_sphere)42 explicit spherical(RadiusOrSphere const& radius_or_sphere) 43 : base_t(radius_or_sphere) 44 {} 45 46 template <typename Geometry1, typename Geometry2> distance(Geometry1 const &,Geometry2 const &,distance::detail::enable_if_pp_t<Geometry1,Geometry2> * =nullptr) const47 auto distance(Geometry1 const&, Geometry2 const&, 48 distance::detail::enable_if_pp_t<Geometry1, Geometry2> * = nullptr) const 49 { 50 return strategy::distance::haversine 51 < 52 typename base_t::radius_type, CalculationType 53 >(base_t::radius()); 54 } 55 }; 56 57 58 namespace services 59 { 60 61 template <typename Geometry1, typename Geometry2> 62 struct default_strategy<Geometry1, Geometry2, spherical_equatorial_tag, spherical_equatorial_tag> 63 { 64 using type = strategies::discrete_distance::spherical<>; 65 }; 66 67 68 template <typename R, typename CT> 69 struct strategy_converter<strategy::distance::haversine<R, CT> > 70 { getboost::geometry::strategies::discrete_distance::services::strategy_converter71 static auto get(strategy::distance::haversine<R, CT> const& s) 72 { 73 return strategies::discrete_distance::spherical<R, CT>(s.radius()); 74 } 75 }; 76 77 template <typename R, typename CT> 78 struct strategy_converter<strategy::distance::comparable::haversine<R, CT> > 79 { getboost::geometry::strategies::discrete_distance::services::strategy_converter80 static auto get(strategy::distance::comparable::haversine<R, CT> const& s) 81 { 82 return strategies::distance::detail::make_comparable( 83 strategies::discrete_distance::spherical<R, CT>(s.radius())); 84 } 85 }; 86 87 } // namespace services 88 89 }} // namespace strategies::discrete_distance 90 91 }} // namespace boost::geometry 92 93 #endif // BOOST_GEOMETRY_STRATEGIES_DISCRETE_DISTANCE_SPHERICAL_HPP 94