line_interpolate.hpp 3.1 KB

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