]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/strategies/spherical/densify.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / geometry / strategies / spherical / densify.hpp
1 // Boost.Geometry
2
3 // Copyright (c) 2017-2019, Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
10
11 #ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DENSIFY_HPP
12 #define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DENSIFY_HPP
13
14
15 #include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
16 #include <boost/geometry/algorithms/detail/signed_size_type.hpp>
17 #include <boost/geometry/arithmetic/arithmetic.hpp>
18 #include <boost/geometry/arithmetic/cross_product.hpp>
19 #include <boost/geometry/arithmetic/dot_product.hpp>
20 #include <boost/geometry/arithmetic/normalize.hpp>
21 #include <boost/geometry/core/assert.hpp>
22 #include <boost/geometry/core/coordinate_dimension.hpp>
23 #include <boost/geometry/core/coordinate_type.hpp>
24 #include <boost/geometry/core/radian_access.hpp>
25 #include <boost/geometry/formulas/spherical.hpp>
26 #include <boost/geometry/formulas/interpolate_point_spherical.hpp>
27 #include <boost/geometry/geometries/point.hpp>
28 #include <boost/geometry/srs/sphere.hpp>
29 #include <boost/geometry/strategies/densify.hpp>
30 #include <boost/geometry/strategies/spherical/get_radius.hpp>
31 #include <boost/geometry/util/math.hpp>
32 #include <boost/geometry/util/select_most_precise.hpp>
33
34
35 namespace boost { namespace geometry
36 {
37
38 namespace strategy { namespace densify
39 {
40
41
42 /*!
43 \brief Densification of spherical segment.
44 \ingroup strategies
45 \tparam RadiusTypeOrSphere \tparam_radius_or_sphere
46 \tparam CalculationType \tparam_calculation
47
48 \qbk{
49 [heading See also]
50 [link geometry.reference.algorithms.densify.densify_4_with_strategy densify (with strategy)]
51 }
52 */
53 template
54 <
55 typename RadiusTypeOrSphere = double,
56 typename CalculationType = void
57 >
58 class spherical
59 {
60 public:
61 // For consistency with area strategy the radius is set to 1
62 inline spherical()
63 : m_radius(1.0)
64 {}
65
66 template <typename RadiusOrSphere>
67 explicit inline spherical(RadiusOrSphere const& radius_or_sphere)
68 : m_radius(strategy_detail::get_radius
69 <
70 RadiusOrSphere
71 >::apply(radius_or_sphere))
72 {}
73
74 template <typename Point, typename AssignPolicy, typename T>
75 inline void apply(Point const& p0, Point const& p1, AssignPolicy & policy, T const& length_threshold) const
76 {
77 typedef typename AssignPolicy::point_type out_point_t;
78 typedef typename select_most_precise
79 <
80 typename coordinate_type<Point>::type,
81 typename coordinate_type<out_point_t>::type,
82 CalculationType
83 >::type calc_t;
84
85 calc_t angle01;
86
87 formula::interpolate_point_spherical<calc_t> formula;
88 formula.compute_angle(p0, p1, angle01);
89
90 BOOST_GEOMETRY_ASSERT(length_threshold > T(0));
91
92 signed_size_type n = signed_size_type(angle01 * m_radius / length_threshold);
93 if (n <= 0)
94 return;
95
96 formula.compute_axis(p0, angle01);
97
98 calc_t step = angle01 / (n + 1);
99
100 calc_t a = step;
101 for (signed_size_type i = 0 ; i < n ; ++i, a += step)
102 {
103 out_point_t p;
104 formula.compute_point(a, p);
105
106 geometry::detail::conversion::point_to_point
107 <
108 Point, out_point_t,
109 2, dimension<out_point_t>::value
110 >::apply(p0, p);
111
112 policy.apply(p);
113 }
114 }
115
116 private:
117 typename strategy_detail::get_radius
118 <
119 RadiusTypeOrSphere
120 >::type m_radius;
121 };
122
123
124 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
125 namespace services
126 {
127
128 template <>
129 struct default_strategy<spherical_equatorial_tag>
130 {
131 typedef strategy::densify::spherical<> type;
132 };
133
134
135 } // namespace services
136 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
137
138
139 }} // namespace strategy::densify
140
141
142 }} // namespace boost::geometry
143
144 #endif // BOOST_GEOMETRY_ALGORITHMS_DENSIFY_HPP