]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/strategies/geographic/distance.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / geometry / strategies / geographic / distance.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2016 Barend Gehrels, Amsterdam, the Netherlands.
4
5 // This file was modified by Oracle on 2014-2017.
6 // Modifications copyright (c) 2014-2017 Oracle and/or its affiliates.
7
8 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14
15
16 #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISTANCE_HPP
17 #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISTANCE_HPP
18
19
20 #include <boost/geometry/core/coordinate_type.hpp>
21 #include <boost/geometry/core/radian_access.hpp>
22 #include <boost/geometry/core/radius.hpp>
23 #include <boost/geometry/core/srs.hpp>
24
25 #include <boost/geometry/formulas/andoyer_inverse.hpp>
26 #include <boost/geometry/formulas/elliptic_arc_length.hpp>
27 #include <boost/geometry/formulas/flattening.hpp>
28
29 #include <boost/geometry/strategies/distance.hpp>
30 #include <boost/geometry/strategies/geographic/parameters.hpp>
31
32 #include <boost/geometry/util/math.hpp>
33 #include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
34 #include <boost/geometry/util/promote_floating_point.hpp>
35 #include <boost/geometry/util/select_calculation_type.hpp>
36
37
38 namespace boost { namespace geometry
39 {
40
41 namespace strategy { namespace distance
42 {
43
44 template
45 <
46 typename FormulaPolicy = strategy::andoyer,
47 typename Spheroid = srs::spheroid<double>,
48 typename CalculationType = void
49 >
50 class geographic
51 {
52 public :
53 template <typename Point1, typename Point2>
54 struct calculation_type
55 : promote_floating_point
56 <
57 typename select_calculation_type
58 <
59 Point1,
60 Point2,
61 CalculationType
62 >::type
63 >
64 {};
65
66 typedef Spheroid model_type;
67
68 inline geographic()
69 : m_spheroid()
70 {}
71
72 explicit inline geographic(Spheroid const& spheroid)
73 : m_spheroid(spheroid)
74 {}
75
76 template <typename CT>
77 static inline CT apply(CT lon1, CT lat1, CT lon2, CT lat2,
78 Spheroid const& spheroid)
79 {
80 typedef typename formula::elliptic_arc_length
81 <
82 CT, strategy::default_order<FormulaPolicy>::value
83 > elliptic_arc_length;
84
85 typename elliptic_arc_length::result res =
86 elliptic_arc_length::apply(lon1, lat1, lon2, lat2, spheroid);
87
88 if (res.meridian)
89 {
90 return res.distance;
91 }
92
93 return FormulaPolicy::template inverse
94 <
95 CT, true, false, false, false, false
96 >::apply(lon1, lat1, lon2, lat2, spheroid).distance;
97 }
98
99 template <typename Point1, typename Point2>
100 inline typename calculation_type<Point1, Point2>::type
101 apply(Point1 const& point1, Point2 const& point2) const
102 {
103 typedef typename calculation_type<Point1, Point2>::type CT;
104
105 CT lon1 = get_as_radian<0>(point1);
106 CT lat1 = get_as_radian<1>(point1);
107 CT lon2 = get_as_radian<0>(point2);
108 CT lat2 = get_as_radian<1>(point2);
109
110 return apply(lon1, lat1, lon2, lat2, m_spheroid);
111 }
112
113 inline Spheroid const& model() const
114 {
115 return m_spheroid;
116 }
117
118 private :
119 Spheroid m_spheroid;
120 };
121
122
123 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
124 namespace services
125 {
126
127 template
128 <
129 typename FormulaPolicy,
130 typename Spheroid,
131 typename CalculationType
132 >
133 struct tag<geographic<FormulaPolicy, Spheroid, CalculationType> >
134 {
135 typedef strategy_tag_distance_point_point type;
136 };
137
138
139 template
140 <
141 typename FormulaPolicy,
142 typename Spheroid,
143 typename CalculationType,
144 typename P1,
145 typename P2
146 >
147 struct return_type<geographic<FormulaPolicy, Spheroid, CalculationType>, P1, P2>
148 : geographic<FormulaPolicy, Spheroid, CalculationType>::template calculation_type<P1, P2>
149 {};
150
151
152 template
153 <
154 typename FormulaPolicy,
155 typename Spheroid,
156 typename CalculationType
157 >
158 struct comparable_type<geographic<FormulaPolicy, Spheroid, CalculationType> >
159 {
160 typedef geographic<FormulaPolicy, Spheroid, CalculationType> type;
161 };
162
163
164 template
165 <
166 typename FormulaPolicy,
167 typename Spheroid,
168 typename CalculationType
169 >
170 struct get_comparable<geographic<FormulaPolicy, Spheroid, CalculationType> >
171 {
172 static inline geographic<FormulaPolicy, Spheroid, CalculationType>
173 apply(geographic<FormulaPolicy, Spheroid, CalculationType> const& input)
174 {
175 return input;
176 }
177 };
178
179 template
180 <
181 typename FormulaPolicy,
182 typename Spheroid,
183 typename CalculationType,
184 typename P1,
185 typename P2
186 >
187 struct result_from_distance<geographic<FormulaPolicy, Spheroid, CalculationType>, P1, P2>
188 {
189 template <typename T>
190 static inline typename return_type<geographic<FormulaPolicy, Spheroid, CalculationType>, P1, P2>::type
191 apply(geographic<FormulaPolicy, Spheroid, CalculationType> const& , T const& value)
192 {
193 return value;
194 }
195 };
196
197
198 template <typename Point1, typename Point2>
199 struct default_strategy<point_tag, point_tag, Point1, Point2, geographic_tag, geographic_tag>
200 {
201 typedef strategy::distance::geographic
202 <
203 strategy::andoyer,
204 srs::spheroid
205 <
206 typename select_coordinate_type<Point1, Point2>::type
207 >
208 > type;
209 };
210
211
212 } // namespace services
213 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
214
215
216 }} // namespace strategy::distance
217
218
219 }} // namespace boost::geometry
220
221
222 #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISTANCE_HPP