densify.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Boost.Geometry
  2. // Copyright (c) 2017-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_DENSIFY_HPP
  8. #define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DENSIFY_HPP
  9. #include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
  10. #include <boost/geometry/algorithms/detail/signed_size_type.hpp>
  11. #include <boost/geometry/arithmetic/arithmetic.hpp>
  12. #include <boost/geometry/arithmetic/cross_product.hpp>
  13. #include <boost/geometry/arithmetic/dot_product.hpp>
  14. #include <boost/geometry/arithmetic/normalize.hpp>
  15. #include <boost/geometry/core/assert.hpp>
  16. #include <boost/geometry/core/coordinate_dimension.hpp>
  17. #include <boost/geometry/core/coordinate_type.hpp>
  18. #include <boost/geometry/core/radian_access.hpp>
  19. #include <boost/geometry/formulas/spherical.hpp>
  20. #include <boost/geometry/formulas/interpolate_point_spherical.hpp>
  21. #include <boost/geometry/geometries/point.hpp>
  22. #include <boost/geometry/srs/sphere.hpp>
  23. #include <boost/geometry/strategies/densify.hpp>
  24. #include <boost/geometry/strategies/spherical/get_radius.hpp>
  25. #include <boost/geometry/util/math.hpp>
  26. #include <boost/geometry/util/select_most_precise.hpp>
  27. namespace boost { namespace geometry
  28. {
  29. namespace strategy { namespace densify
  30. {
  31. /*!
  32. \brief Densification of spherical segment.
  33. \ingroup strategies
  34. \tparam RadiusTypeOrSphere \tparam_radius_or_sphere
  35. \tparam CalculationType \tparam_calculation
  36. \qbk{
  37. [heading See also]
  38. [link geometry.reference.algorithms.densify.densify_4_with_strategy densify (with strategy)]
  39. }
  40. */
  41. template
  42. <
  43. typename RadiusTypeOrSphere = double,
  44. typename CalculationType = void
  45. >
  46. class spherical
  47. {
  48. public:
  49. typedef typename strategy_detail::get_radius
  50. <
  51. RadiusTypeOrSphere
  52. >::type radius_type;
  53. // For consistency with area strategy the radius is set to 1
  54. inline spherical()
  55. : m_radius(1.0)
  56. {}
  57. template <typename RadiusOrSphere>
  58. explicit inline spherical(RadiusOrSphere const& radius_or_sphere)
  59. : m_radius(strategy_detail::get_radius
  60. <
  61. RadiusOrSphere
  62. >::apply(radius_or_sphere))
  63. {}
  64. template <typename Point, typename AssignPolicy, typename T>
  65. inline void apply(Point const& p0, Point const& p1, AssignPolicy & policy, T const& length_threshold) const
  66. {
  67. typedef typename AssignPolicy::point_type out_point_t;
  68. typedef typename select_most_precise
  69. <
  70. typename coordinate_type<Point>::type,
  71. typename coordinate_type<out_point_t>::type,
  72. CalculationType
  73. >::type calc_t;
  74. calc_t angle01;
  75. formula::interpolate_point_spherical<calc_t> formula;
  76. formula.compute_angle(p0, p1, angle01);
  77. BOOST_GEOMETRY_ASSERT(length_threshold > T(0));
  78. signed_size_type n = signed_size_type(angle01 * m_radius / length_threshold);
  79. if (n <= 0)
  80. return;
  81. formula.compute_axis(p0, angle01);
  82. calc_t step = angle01 / (n + 1);
  83. calc_t a = step;
  84. for (signed_size_type i = 0 ; i < n ; ++i, a += step)
  85. {
  86. out_point_t p;
  87. formula.compute_point(a, p);
  88. geometry::detail::conversion::point_to_point
  89. <
  90. Point, out_point_t,
  91. 2, dimension<out_point_t>::value
  92. >::apply(p0, p);
  93. policy.apply(p);
  94. }
  95. }
  96. inline radius_type radius() const
  97. {
  98. return m_radius;
  99. }
  100. private:
  101. radius_type m_radius;
  102. };
  103. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  104. namespace services
  105. {
  106. template <>
  107. struct default_strategy<spherical_equatorial_tag>
  108. {
  109. typedef strategy::densify::spherical<> type;
  110. };
  111. } // namespace services
  112. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  113. }} // namespace strategy::densify
  114. }} // namespace boost::geometry
  115. #endif // BOOST_GEOMETRY_ALGORITHMS_DENSIFY_HPP