densify.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Boost.Geometry
  2. // Copyright (c) 2017-2019, 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. // For consistency with area strategy the radius is set to 1
  50. inline spherical()
  51. : m_radius(1.0)
  52. {}
  53. template <typename RadiusOrSphere>
  54. explicit inline spherical(RadiusOrSphere const& radius_or_sphere)
  55. : m_radius(strategy_detail::get_radius
  56. <
  57. RadiusOrSphere
  58. >::apply(radius_or_sphere))
  59. {}
  60. template <typename Point, typename AssignPolicy, typename T>
  61. inline void apply(Point const& p0, Point const& p1, AssignPolicy & policy, T const& length_threshold) const
  62. {
  63. typedef typename AssignPolicy::point_type out_point_t;
  64. typedef typename select_most_precise
  65. <
  66. typename coordinate_type<Point>::type,
  67. typename coordinate_type<out_point_t>::type,
  68. CalculationType
  69. >::type calc_t;
  70. calc_t angle01;
  71. formula::interpolate_point_spherical<calc_t> formula;
  72. formula.compute_angle(p0, p1, angle01);
  73. BOOST_GEOMETRY_ASSERT(length_threshold > T(0));
  74. signed_size_type n = signed_size_type(angle01 * m_radius / length_threshold);
  75. if (n <= 0)
  76. return;
  77. formula.compute_axis(p0, angle01);
  78. calc_t step = angle01 / (n + 1);
  79. calc_t a = step;
  80. for (signed_size_type i = 0 ; i < n ; ++i, a += step)
  81. {
  82. out_point_t p;
  83. formula.compute_point(a, p);
  84. geometry::detail::conversion::point_to_point
  85. <
  86. Point, out_point_t,
  87. 2, dimension<out_point_t>::value
  88. >::apply(p0, p);
  89. policy.apply(p);
  90. }
  91. }
  92. private:
  93. typename strategy_detail::get_radius
  94. <
  95. RadiusTypeOrSphere
  96. >::type m_radius;
  97. };
  98. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  99. namespace services
  100. {
  101. template <>
  102. struct default_strategy<spherical_equatorial_tag>
  103. {
  104. typedef strategy::densify::spherical<> type;
  105. };
  106. } // namespace services
  107. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  108. }} // namespace strategy::densify
  109. }} // namespace boost::geometry
  110. #endif // BOOST_GEOMETRY_ALGORITHMS_DENSIFY_HPP