]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/strategies/distance/spherical.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / geometry / strategies / distance / spherical.hpp
1 // Boost.Geometry
2
3 // Copyright (c) 2021, Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
9
10 #ifndef BOOST_GEOMETRY_STRATEGIES_DISTANCE_SPHERICAL_HPP
11 #define BOOST_GEOMETRY_STRATEGIES_DISTANCE_SPHERICAL_HPP
12
13
14 #include <boost/geometry/strategies/distance/comparable.hpp>
15 #include <boost/geometry/strategies/distance/detail.hpp>
16 #include <boost/geometry/strategies/distance/services.hpp>
17 #include <boost/geometry/strategies/detail.hpp>
18
19 #include <boost/geometry/strategies/normalize.hpp>
20 #include <boost/geometry/strategies/relate/spherical.hpp>
21
22 #include <boost/geometry/strategies/spherical/azimuth.hpp>
23
24 #include <boost/geometry/strategies/spherical/distance_cross_track.hpp>
25 #include <boost/geometry/strategies/spherical/distance_cross_track_box_box.hpp>
26 #include <boost/geometry/strategies/spherical/distance_cross_track_point_box.hpp>
27 #include <boost/geometry/strategies/spherical/distance_haversine.hpp>
28 #include <boost/geometry/strategies/spherical/distance_segment_box.hpp>
29
30
31 namespace boost { namespace geometry
32 {
33
34 namespace strategies { namespace distance
35 {
36
37 #ifndef DOXYGEN_NO_DETAIL
38 namespace detail
39 {
40
41 // TODO: azimuth and normalize getters would not be needed if distance_segment_box was implemented differently
42 // right now it calls disjoint algorithm details.
43
44 template <typename RadiusTypeOrSphere, typename CalculationType>
45 class spherical
46 : public strategies::relate::detail::spherical<RadiusTypeOrSphere, CalculationType>
47 {
48 using base_t = strategies::relate::detail::spherical<RadiusTypeOrSphere, CalculationType>;
49
50 public:
51 spherical() = default;
52
53 template <typename RadiusOrSphere>
54 explicit spherical(RadiusOrSphere const& radius_or_sphere)
55 : base_t(radius_or_sphere)
56 {}
57
58 // azimuth
59
60 static auto azimuth()
61 {
62 return strategy::azimuth::spherical<CalculationType>();
63 }
64
65 // distance
66
67 template <typename Geometry1, typename Geometry2>
68 auto distance(Geometry1 const&, Geometry2 const&,
69 detail::enable_if_pp_t<Geometry1, Geometry2> * = nullptr) const
70 {
71 return strategy::distance::haversine
72 <
73 typename base_t::radius_type, CalculationType
74 >(base_t::radius());
75 }
76
77 template <typename Geometry1, typename Geometry2>
78 auto distance(Geometry1 const&, Geometry2 const&,
79 detail::enable_if_ps_t<Geometry1, Geometry2> * = nullptr) const
80 {
81 return strategy::distance::cross_track
82 <
83 CalculationType,
84 strategy::distance::haversine<typename base_t::radius_type, CalculationType>
85 >(base_t::radius());
86 }
87
88 template <typename Geometry1, typename Geometry2>
89 auto distance(Geometry1 const&, Geometry2 const&,
90 detail::enable_if_pb_t<Geometry1, Geometry2> * = nullptr) const
91 {
92 return strategy::distance::cross_track_point_box
93 <
94 CalculationType,
95 strategy::distance::haversine<typename base_t::radius_type, CalculationType>
96 >(base_t::radius());
97 }
98
99 template <typename Geometry1, typename Geometry2>
100 auto distance(Geometry1 const&, Geometry2 const&,
101 detail::enable_if_sb_t<Geometry1, Geometry2> * = nullptr) const
102 {
103 return strategy::distance::spherical_segment_box
104 <
105 CalculationType,
106 strategy::distance::haversine<typename base_t::radius_type, CalculationType>
107 >(base_t::radius());
108 }
109
110 template <typename Geometry1, typename Geometry2>
111 auto distance(Geometry1 const&, Geometry2 const&,
112 detail::enable_if_bb_t<Geometry1, Geometry2> * = nullptr) const
113 {
114 return strategy::distance::cross_track_box_box
115 <
116 CalculationType,
117 strategy::distance::haversine<typename base_t::radius_type, CalculationType>
118 >(base_t::radius());
119 }
120
121 // normalize
122
123 template <typename Geometry>
124 static auto normalize(Geometry const&,
125 std::enable_if_t
126 <
127 util::is_point<Geometry>::value
128 > * = nullptr)
129 {
130 return strategy::normalize::spherical_point();
131 }
132 };
133
134
135 } // namespace detail
136 #endif // DOXYGEN_NO_DETAIL
137
138
139 template
140 <
141 typename RadiusTypeOrSphere = double,
142 typename CalculationType = void
143 >
144 class spherical
145 : public strategies::distance::detail::spherical<RadiusTypeOrSphere, CalculationType>
146 {
147 using base_t = strategies::distance::detail::spherical<RadiusTypeOrSphere, CalculationType>;
148
149 public:
150 spherical() = default;
151
152 template <typename RadiusOrSphere>
153 explicit spherical(RadiusOrSphere const& radius_or_sphere)
154 : base_t(radius_or_sphere)
155 {}
156 };
157
158
159 namespace services
160 {
161
162 template <typename Geometry1, typename Geometry2>
163 struct default_strategy
164 <
165 Geometry1, Geometry2,
166 spherical_equatorial_tag, spherical_equatorial_tag
167 >
168 {
169 using type = strategies::distance::spherical<>;
170 };
171
172
173 template <typename R, typename CT>
174 struct strategy_converter<strategy::distance::haversine<R, CT> >
175 {
176 template <typename S>
177 static auto get(S const& s)
178 {
179 return strategies::distance::spherical<R, CT>(s.radius());
180 }
181 };
182
183 template <typename CT, typename PPS>
184 struct strategy_converter<strategy::distance::cross_track<CT, PPS> >
185 : strategy_converter<PPS>
186 {};
187
188 template <typename CT, typename PPS>
189 struct strategy_converter<strategy::distance::cross_track_point_box<CT, PPS> >
190 : strategy_converter<PPS>
191 {};
192
193 template <typename CT, typename PPS>
194 struct strategy_converter<strategy::distance::spherical_segment_box<CT, PPS> >
195 : strategy_converter<PPS>
196 {};
197
198 template <typename CT, typename PPS>
199 struct strategy_converter<strategy::distance::cross_track_box_box<CT, PPS> >
200 : strategy_converter<PPS>
201 {};
202
203
204 template <typename R, typename CT>
205 struct strategy_converter<strategy::distance::comparable::haversine<R, CT> >
206 {
207 template <typename S>
208 static auto get(S const& s)
209 {
210 return strategies::distance::detail::make_comparable(
211 strategies::distance::spherical<R, CT>(s.radius()));
212 }
213 };
214
215 template <typename CT, typename PPS>
216 struct strategy_converter<strategy::distance::comparable::cross_track<CT, PPS> >
217 : strategy_converter<PPS>
218 {};
219
220
221 } // namespace services
222
223 }} // namespace strategies::distance
224
225 }} // namespace boost::geometry
226
227 #endif // BOOST_GEOMETRY_STRATEGIES_DISTANCE_SPHERICAL_HPP