spherical.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_LINE_INTERPOLATE_SPHERICAL_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_LINE_INTERPOLATE_SPHERICAL_HPP
  8. #include <boost/geometry/strategies/detail.hpp>
  9. #include <boost/geometry/strategies/distance/detail.hpp>
  10. #include <boost/geometry/strategies/line_interpolate/services.hpp>
  11. #include <boost/geometry/strategies/spherical/distance_haversine.hpp>
  12. #include <boost/geometry/strategies/spherical/line_interpolate.hpp>
  13. namespace boost { namespace geometry
  14. {
  15. namespace strategies { namespace line_interpolate
  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. template <typename Geometry>
  42. auto line_interpolate(Geometry const&) const
  43. {
  44. // NOTE: radius is ignored, but pass it just in case
  45. return strategy::line_interpolate::spherical<CalculationType>(base_t::radius());
  46. }
  47. };
  48. namespace services
  49. {
  50. template <typename Geometry>
  51. struct default_strategy<Geometry, spherical_equatorial_tag>
  52. {
  53. using type = strategies::line_interpolate::spherical<>;
  54. };
  55. template <typename CT, typename DS>
  56. struct strategy_converter<strategy::line_interpolate::spherical<CT, DS> >
  57. {
  58. static auto get(strategy::line_interpolate::spherical<CT, DS> const& s)
  59. {
  60. typedef typename strategy::line_interpolate::spherical<CT, DS>::radius_type radius_type;
  61. return strategies::line_interpolate::spherical<radius_type, CT>(s.radius());
  62. }
  63. };
  64. } // namespace services
  65. }} // namespace strategies::line_interpolate
  66. }} // namespace boost::geometry
  67. #endif // BOOST_GEOMETRY_STRATEGIES_LINE_INTERPOLATE_SPHERICAL_HPP