line_interpolate.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_GEOGRAPHIC_LINE_INTERPOLATE_HPP
  8. #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_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/srs/spheroid.hpp>
  14. #include <boost/geometry/strategies/line_interpolate.hpp>
  15. #include <boost/geometry/strategies/geographic/parameters.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 geographic segment.
  23. \ingroup strategies
  24. \tparam FormulaPolicy The geodesic formulas used internally.
  25. \tparam Spheroid The spheroid model.
  26. \tparam CalculationType \tparam_calculation
  27. \qbk{
  28. [heading See also]
  29. \* [link geometry.reference.algorithms.line_interpolate.line_interpolate_4_with_strategy line_interpolate (with strategy)]
  30. \* [link geometry.reference.srs.srs_spheroid srs::spheroid]
  31. }
  32. */
  33. template
  34. <
  35. typename FormulaPolicy = strategy::andoyer,
  36. typename Spheroid = srs::spheroid<double>,
  37. typename CalculationType = void
  38. >
  39. class geographic
  40. {
  41. public:
  42. geographic() = default;
  43. explicit geographic(Spheroid const& spheroid)
  44. : m_spheroid(spheroid)
  45. {}
  46. template <typename Point, typename Fraction, typename Distance>
  47. inline void apply(Point const& p0,
  48. Point const& p1,
  49. Fraction const& fraction, //fraction of segment
  50. Point & p,
  51. Distance const& distance) const
  52. {
  53. typedef typename select_calculation_type_alt
  54. <
  55. CalculationType,
  56. Point
  57. >::type calc_t;
  58. typedef typename FormulaPolicy::template inverse
  59. <calc_t, false, true, false, false, false> inverse_t;
  60. calc_t azimuth = inverse_t::apply(get_as_radian<0>(p0), get_as_radian<1>(p0),
  61. get_as_radian<0>(p1), get_as_radian<1>(p1),
  62. m_spheroid).azimuth;
  63. typedef typename FormulaPolicy::template direct
  64. <calc_t, true, false, false, false> direct_t;
  65. typename direct_t::result_type
  66. dir_r = direct_t::apply(get_as_radian<0>(p0), get_as_radian<1>(p0),
  67. distance * fraction, azimuth,
  68. m_spheroid);
  69. set_from_radian<0>(p, dir_r.lon2);
  70. set_from_radian<1>(p, dir_r.lat2);
  71. }
  72. inline Spheroid model() const
  73. {
  74. return m_spheroid;
  75. }
  76. private:
  77. Spheroid m_spheroid;
  78. };
  79. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  80. namespace services
  81. {
  82. template <>
  83. struct default_strategy<geographic_tag>
  84. {
  85. typedef strategy::line_interpolate::geographic<> 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_GEOGRAPHIC_LINE_INTERPOLATE_HPP