]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/util/normalize_spheroidal_box_coordinates.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / geometry / util / normalize_spheroidal_box_coordinates.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2015-2022, 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_UTIL_NORMALIZE_SPHEROIDAL_BOX_COORDINATES_HPP
12 #define BOOST_GEOMETRY_UTIL_NORMALIZE_SPHEROIDAL_BOX_COORDINATES_HPP
13
14 #include <boost/geometry/core/assert.hpp>
15 #include <boost/geometry/util/math.hpp>
16 #include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
17
18
19 namespace boost { namespace geometry
20 {
21
22 namespace math
23 {
24
25 #ifndef DOXYGEN_NO_DETAIL
26 namespace detail
27 {
28
29
30 template <typename Units, typename CoordinateType, bool IsEquatorial = true>
31 class normalize_spheroidal_box_coordinates
32 {
33 private:
34 typedef normalize_spheroidal_coordinates<Units, CoordinateType> normalize;
35 typedef constants_on_spheroid<CoordinateType, Units> constants;
36
37 static inline bool is_band(CoordinateType const& longitude1,
38 CoordinateType const& longitude2)
39 {
40 return math::larger_or_equals(math::abs(longitude1 - longitude2),
41 constants::period());
42 }
43
44 public:
45 static inline void apply(CoordinateType& longitude1,
46 CoordinateType& latitude1,
47 CoordinateType& longitude2,
48 CoordinateType& latitude2,
49 bool band)
50 {
51 normalize::apply(longitude1, latitude1, false);
52 normalize::apply(longitude2, latitude2, false);
53
54 latitude_convert_if_polar<Units, IsEquatorial>::apply(latitude1);
55 latitude_convert_if_polar<Units, IsEquatorial>::apply(latitude2);
56
57 if (math::equals(latitude1, constants::min_latitude())
58 && math::equals(latitude2, constants::min_latitude()))
59 {
60 // box degenerates to the south pole
61 longitude1 = longitude2 = CoordinateType(0);
62 }
63 else if (math::equals(latitude1, constants::max_latitude())
64 && math::equals(latitude2, constants::max_latitude()))
65 {
66 // box degenerates to the north pole
67 longitude1 = longitude2 = CoordinateType(0);
68 }
69 else if (band)
70 {
71 // the box is a band between two small circles (parallel
72 // to the equator) on the spheroid
73 longitude1 = constants::min_longitude();
74 longitude2 = constants::max_longitude();
75 }
76 else if (longitude1 > longitude2)
77 {
78 // the box crosses the antimeridian, so we need to adjust
79 // the longitudes
80 longitude2 += constants::period();
81 }
82
83 latitude_convert_if_polar<Units, IsEquatorial>::apply(latitude1);
84 latitude_convert_if_polar<Units, IsEquatorial>::apply(latitude2);
85
86 #ifdef BOOST_GEOMETRY_NORMALIZE_LATITUDE
87 BOOST_GEOMETRY_ASSERT(! math::larger(latitude1, latitude2));
88 BOOST_GEOMETRY_ASSERT(! math::smaller(latitude1, constants::min_latitude()));
89 BOOST_GEOMETRY_ASSERT(! math::larger(latitude2, constants::max_latitude()));
90 #endif
91
92 BOOST_GEOMETRY_ASSERT(! math::larger(longitude1, longitude2));
93 BOOST_GEOMETRY_ASSERT(! math::smaller(longitude1, constants::min_longitude()));
94 BOOST_GEOMETRY_ASSERT(! math::larger(longitude2 - longitude1, constants::period()));
95 }
96
97 static inline void apply(CoordinateType& longitude1,
98 CoordinateType& latitude1,
99 CoordinateType& longitude2,
100 CoordinateType& latitude2)
101 {
102 bool const band = is_band(longitude1, longitude2);
103
104 apply(longitude1, latitude1, longitude2, latitude2, band);
105 }
106 };
107
108
109 } // namespace detail
110 #endif // DOXYGEN_NO_DETAIL
111
112
113 /*!
114 \brief Short utility to normalize the coordinates of a box on a spheroid
115 \tparam Units The units of the coordindate system in the spheroid
116 \tparam CoordinateType The type of the coordinates
117 \param longitude1 Minimum longitude of the box
118 \param latitude1 Minimum latitude of the box
119 \param longitude2 Maximum longitude of the box
120 \param latitude2 Maximum latitude of the box
121 \ingroup utility
122 */
123 template <typename Units, typename CoordinateType>
124 inline void normalize_spheroidal_box_coordinates(CoordinateType& longitude1,
125 CoordinateType& latitude1,
126 CoordinateType& longitude2,
127 CoordinateType& latitude2)
128 {
129 detail::normalize_spheroidal_box_coordinates
130 <
131 Units, CoordinateType
132 >::apply(longitude1, latitude1, longitude2, latitude2);
133 }
134
135 template <typename Units, bool IsEquatorial, typename CoordinateType>
136 inline void normalize_spheroidal_box_coordinates(CoordinateType& longitude1,
137 CoordinateType& latitude1,
138 CoordinateType& longitude2,
139 CoordinateType& latitude2)
140 {
141 detail::normalize_spheroidal_box_coordinates
142 <
143 Units, CoordinateType, IsEquatorial
144 >::apply(longitude1, latitude1, longitude2, latitude2);
145 }
146
147 /*!
148 \brief Short utility to normalize the coordinates of a box on a spheroid
149 \tparam Units The units of the coordindate system in the spheroid
150 \tparam CoordinateType The type of the coordinates
151 \param longitude1 Minimum longitude of the box
152 \param latitude1 Minimum latitude of the box
153 \param longitude2 Maximum longitude of the box
154 \param latitude2 Maximum latitude of the box
155 \param band Indicates whether the box should be treated as a band or
156 not and avoid the computation done in the other version of the function
157 \ingroup utility
158 */
159 template <typename Units, typename CoordinateType>
160 inline void normalize_spheroidal_box_coordinates(CoordinateType& longitude1,
161 CoordinateType& latitude1,
162 CoordinateType& longitude2,
163 CoordinateType& latitude2,
164 bool band)
165 {
166 detail::normalize_spheroidal_box_coordinates
167 <
168 Units, CoordinateType
169 >::apply(longitude1, latitude1, longitude2, latitude2, band);
170 }
171
172 template <typename Units, bool IsEquatorial, typename CoordinateType>
173 inline void normalize_spheroidal_box_coordinates(CoordinateType& longitude1,
174 CoordinateType& latitude1,
175 CoordinateType& longitude2,
176 CoordinateType& latitude2,
177 bool band)
178 {
179 detail::normalize_spheroidal_box_coordinates
180 <
181 Units, CoordinateType, IsEquatorial
182 >::apply(longitude1, latitude1, longitude2, latitude2, band);
183 }
184
185
186 } // namespace math
187
188
189 }} // namespace boost::geometry
190
191 #endif // BOOST_GEOMETRY_UTIL_NORMALIZE_SPHEROIDAL_BOX_COORDINATES_HPP