line_interpolate.hpp 3.0 KB

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