1 // Boost.Geometry 2 3 // Copyright (c) 2018, Oracle and/or its affiliates. 4 5 // Contributed and/or modified by Vissarion Fysikopoulos, 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_SPHERICAL_LINE_INTERPOLATE_HPP 11 #define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_LINE_INTERPOLATE_HPP 12 13 #include <boost/geometry/core/assert.hpp> 14 #include <boost/geometry/core/coordinate_dimension.hpp> 15 #include <boost/geometry/core/coordinate_type.hpp> 16 #include <boost/geometry/core/radian_access.hpp> 17 #include <boost/geometry/formulas/interpolate_point_spherical.hpp> 18 #include <boost/geometry/srs/spheroid.hpp> 19 #include <boost/geometry/strategies/line_interpolate.hpp> 20 #include <boost/geometry/strategies/spherical/distance_haversine.hpp> 21 #include <boost/geometry/util/select_calculation_type.hpp> 22 23 24 namespace boost { namespace geometry 25 { 26 27 namespace strategy { namespace line_interpolate 28 { 29 30 31 /*! 32 \brief Interpolate point on a spherical segment. 33 \ingroup strategies 34 \tparam CalculationType \tparam_calculation 35 \tparam DistanceStrategy The underlying point-point distance strategy 36 37 \qbk{ 38 [heading See also] 39 \* [link geometry.reference.algorithms.line_interpolate.line_interpolate_4_with_strategy line_interpolate (with strategy)] 40 } 41 42 */ 43 template 44 < 45 typename CalculationType = void, 46 typename DistanceStrategy = distance::haversine<double, CalculationType> 47 > 48 class spherical 49 { 50 public: 51 52 typedef typename DistanceStrategy::radius_type radius_type; 53 spherical()54 inline spherical() 55 {} 56 spherical(typename DistanceStrategy::radius_type const & r)57 explicit inline spherical(typename DistanceStrategy::radius_type const& r) 58 : m_strategy(r) 59 {} 60 spherical(DistanceStrategy const & s)61 inline spherical(DistanceStrategy const& s) 62 : m_strategy(s) 63 {} 64 65 // point-point strategy getters 66 struct distance_pp_strategy 67 { 68 typedef DistanceStrategy type; 69 }; 70 get_distance_pp_strategy() const71 inline typename distance_pp_strategy::type get_distance_pp_strategy() const 72 { 73 return m_strategy; 74 } 75 76 template <typename Point, typename Fraction, typename Distance> apply(Point const & p0,Point const & p1,Fraction const & fraction,Point & p,Distance const &) const77 inline void apply(Point const& p0, 78 Point const& p1, 79 Fraction const& fraction, 80 Point & p, 81 Distance const&) const 82 { 83 typedef typename select_calculation_type_alt 84 < 85 CalculationType, 86 Point 87 >::type calc_t; 88 89 formula::interpolate_point_spherical<calc_t> formula; 90 91 calc_t angle01; 92 formula.compute_angle(p0, p1, angle01); 93 formula.compute_axis(p0, angle01); 94 95 calc_t a = angle01 * fraction; 96 formula.compute_point(a, p); 97 } 98 private : 99 DistanceStrategy m_strategy; 100 }; 101 102 103 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS 104 namespace services 105 { 106 107 template <> 108 struct default_strategy<spherical_equatorial_tag> 109 { 110 typedef strategy::line_interpolate::spherical<> type; 111 }; 112 113 114 } // namespace services 115 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS 116 117 118 }} // namespace strategy::line_interpolate 119 120 121 }} // namespace boost::geometry 122 123 #endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_LINE_INTERPOLATE_HPP 124