spherical.hpp 2.0 KB

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