]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/algorithms/detail/normalize.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / detail / normalize.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2015-2017, Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Menelaos Karavelas, 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_ALGORITHMS_DETAIL_NORMALIZE_HPP
12 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_NORMALIZE_HPP
13
14 #include <cstddef>
15
16 #include <boost/numeric/conversion/cast.hpp>
17
18 #include <boost/geometry/core/access.hpp>
19 #include <boost/geometry/core/coordinate_system.hpp>
20 #include <boost/geometry/core/coordinate_type.hpp>
21 #include <boost/geometry/core/cs.hpp>
22 #include <boost/geometry/core/tag.hpp>
23 #include <boost/geometry/core/tags.hpp>
24
25 #include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
26 #include <boost/geometry/util/normalize_spheroidal_box_coordinates.hpp>
27
28 #include <boost/geometry/views/detail/indexed_point_view.hpp>
29
30
31 namespace boost { namespace geometry
32 {
33
34 #ifndef DOXYGEN_NO_DETAIL
35 namespace detail { namespace normalization
36 {
37
38
39 struct do_nothing
40 {
41 template <typename GeometryIn, typename GeometryOut>
42 static inline void apply(GeometryIn const&, GeometryOut&)
43 {
44 }
45 };
46
47
48 template <std::size_t Dimension, std::size_t DimensionCount>
49 struct assign_loop
50 {
51 template <typename CoordinateType, typename PointIn, typename PointOut>
52 static inline void apply(CoordinateType const& longitude,
53 CoordinateType const& latitude,
54 PointIn const& point_in,
55 PointOut& point_out)
56 {
57 geometry::set<Dimension>(point_out, boost::numeric_cast
58 <
59 typename coordinate_type<PointOut>::type
60 >(geometry::get<Dimension>(point_in)));
61
62 assign_loop
63 <
64 Dimension + 1, DimensionCount
65 >::apply(longitude, latitude, point_in, point_out);
66 }
67 };
68
69 template <std::size_t DimensionCount>
70 struct assign_loop<DimensionCount, DimensionCount>
71 {
72 template <typename CoordinateType, typename PointIn, typename PointOut>
73 static inline void apply(CoordinateType const&,
74 CoordinateType const&,
75 PointIn const&,
76 PointOut&)
77 {
78 }
79 };
80
81 template <std::size_t DimensionCount>
82 struct assign_loop<0, DimensionCount>
83 {
84 template <typename CoordinateType, typename PointIn, typename PointOut>
85 static inline void apply(CoordinateType const& longitude,
86 CoordinateType const& latitude,
87 PointIn const& point_in,
88 PointOut& point_out)
89 {
90 geometry::set<0>(point_out, boost::numeric_cast
91 <
92 typename coordinate_type<PointOut>::type
93 >(longitude));
94
95 assign_loop
96 <
97 1, DimensionCount
98 >::apply(longitude, latitude, point_in, point_out);
99 }
100 };
101
102 template <std::size_t DimensionCount>
103 struct assign_loop<1, DimensionCount>
104 {
105 template <typename CoordinateType, typename PointIn, typename PointOut>
106 static inline void apply(CoordinateType const& longitude,
107 CoordinateType const& latitude,
108 PointIn const& point_in,
109 PointOut& point_out)
110 {
111 geometry::set<1>(point_out, boost::numeric_cast
112 <
113 typename coordinate_type<PointOut>::type
114 >(latitude));
115
116 assign_loop
117 <
118 2, DimensionCount
119 >::apply(longitude, latitude, point_in, point_out);
120 }
121 };
122
123
124 template <typename PointIn, typename PointOut, bool IsEquatorial = true>
125 struct normalize_point
126 {
127 static inline void apply(PointIn const& point_in, PointOut& point_out)
128 {
129 typedef typename coordinate_type<PointIn>::type in_coordinate_type;
130
131 in_coordinate_type longitude = geometry::get<0>(point_in);
132 in_coordinate_type latitude = geometry::get<1>(point_in);
133
134 math::normalize_spheroidal_coordinates
135 <
136 typename coordinate_system<PointIn>::type::units,
137 IsEquatorial,
138 in_coordinate_type
139 >(longitude, latitude);
140
141 assign_loop
142 <
143 0, dimension<PointIn>::value
144 >::apply(longitude, latitude, point_in, point_out);
145 }
146 };
147
148
149 template <typename BoxIn, typename BoxOut, bool IsEquatorial = true>
150 class normalize_box
151 {
152 template <typename UnitsIn, typename UnitsOut, typename CoordinateInType>
153 static inline void apply_to_coordinates(CoordinateInType& lon_min,
154 CoordinateInType& lat_min,
155 CoordinateInType& lon_max,
156 CoordinateInType& lat_max,
157 BoxIn const& box_in,
158 BoxOut& box_out)
159 {
160 detail::indexed_point_view<BoxOut, min_corner> p_min_out(box_out);
161 assign_loop
162 <
163 0, dimension<BoxIn>::value
164 >::apply(lon_min,
165 lat_min,
166 detail::indexed_point_view
167 <
168 BoxIn const, min_corner
169 >(box_in),
170 p_min_out);
171
172 detail::indexed_point_view<BoxOut, max_corner> p_max_out(box_out);
173 assign_loop
174 <
175 0, dimension<BoxIn>::value
176 >::apply(lon_max,
177 lat_max,
178 detail::indexed_point_view
179 <
180 BoxIn const, max_corner
181 >(box_in),
182 p_max_out);
183 }
184
185 public:
186 static inline void apply(BoxIn const& box_in, BoxOut& box_out)
187 {
188 typedef typename coordinate_type<BoxIn>::type in_coordinate_type;
189
190 in_coordinate_type lon_min = geometry::get<min_corner, 0>(box_in);
191 in_coordinate_type lat_min = geometry::get<min_corner, 1>(box_in);
192 in_coordinate_type lon_max = geometry::get<max_corner, 0>(box_in);
193 in_coordinate_type lat_max = geometry::get<max_corner, 1>(box_in);
194
195 math::normalize_spheroidal_box_coordinates
196 <
197 typename coordinate_system<BoxIn>::type::units,
198 IsEquatorial,
199 in_coordinate_type
200 >(lon_min, lat_min, lon_max, lat_max);
201
202 apply_to_coordinates
203 <
204 typename coordinate_system<BoxIn>::type::units,
205 typename coordinate_system<BoxOut>::type::units
206 >(lon_min, lat_min, lon_max, lat_max, box_in, box_out);
207 }
208 };
209
210
211 }} // namespace detail::normalization
212 #endif // DOXYGEN_NO_DETAIL
213
214 #ifndef DOXYGEN_NO_DISPATCH
215 namespace dispatch
216 {
217
218 template
219 <
220 typename GeometryIn,
221 typename GeometryOut,
222 typename TagIn = typename tag<GeometryIn>::type,
223 typename TagOut = typename tag<GeometryOut>::type,
224 typename CSTagIn = typename cs_tag<GeometryIn>::type,
225 typename CSTagOut = typename cs_tag<GeometryOut>::type
226 >
227 struct normalize : detail::normalization::do_nothing
228 {};
229
230
231 template <typename PointIn, typename PointOut>
232 struct normalize
233 <
234 PointIn, PointOut, point_tag, point_tag,
235 spherical_equatorial_tag, spherical_equatorial_tag
236 > : detail::normalization::normalize_point<PointIn, PointOut>
237 {};
238
239
240 template <typename PointIn, typename PointOut>
241 struct normalize
242 <
243 PointIn, PointOut, point_tag, point_tag,
244 spherical_polar_tag, spherical_polar_tag
245 > : detail::normalization::normalize_point<PointIn, PointOut, false>
246 {};
247
248
249 template <typename PointIn, typename PointOut>
250 struct normalize
251 <
252 PointIn, PointOut, point_tag, point_tag, geographic_tag, geographic_tag
253 > : detail::normalization::normalize_point<PointIn, PointOut>
254 {};
255
256
257 template <typename BoxIn, typename BoxOut>
258 struct normalize
259 <
260 BoxIn, BoxOut, box_tag, box_tag,
261 spherical_equatorial_tag, spherical_equatorial_tag
262 > : detail::normalization::normalize_box<BoxIn, BoxOut>
263 {};
264
265
266 template <typename BoxIn, typename BoxOut>
267 struct normalize
268 <
269 BoxIn, BoxOut, box_tag, box_tag,
270 spherical_polar_tag, spherical_polar_tag
271 > : detail::normalization::normalize_box<BoxIn, BoxOut, false>
272 {};
273
274
275 template <typename BoxIn, typename BoxOut>
276 struct normalize
277 <
278 BoxIn, BoxOut, box_tag, box_tag, geographic_tag, geographic_tag
279 > : detail::normalization::normalize_box<BoxIn, BoxOut>
280 {};
281
282
283 } // namespace dispatch
284 #endif // DOXYGEN_NO_DISPATCH
285
286
287 #ifndef DOXYGEN_NO_DETAIL
288 namespace detail
289 {
290
291
292 template <typename GeometryIn, typename GeometryOut>
293 inline void normalize(GeometryIn const& geometry_in, GeometryOut& geometry_out)
294 {
295 dispatch::normalize
296 <
297 GeometryIn, GeometryOut
298 >::apply(geometry_in, geometry_out);
299 }
300
301 template <typename GeometryOut, typename GeometryIn>
302 inline GeometryOut return_normalized(GeometryIn const& geometry_in)
303 {
304 GeometryOut geometry_out;
305 detail::normalize(geometry_in, geometry_out);
306 return geometry_out;
307 }
308
309
310 } // namespace detail
311 #endif // DOXYGEN_NO_DETAIL
312
313 }} // namespace boost::geometry
314
315 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_NORMALIZE_HPP