]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/envelope_expand/test_envelope_expand_on_spheroid.hpp
14066cd472543364ca9b0055b406937a792d36fb
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / envelope_expand / test_envelope_expand_on_spheroid.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2015, Oracle and/or its affiliates.
5
6 // Contributed and/or modified by Menelaos Karavelas, 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_TEST_ENVELOPE_EXPAND_ON_SPHEROID_HPP
12 #define BOOST_GEOMETRY_TEST_ENVELOPE_EXPAND_ON_SPHEROID_HPP
13
14 #include <cmath>
15 #include <cstddef>
16 #include <algorithm>
17
18 #include <boost/type_traits/is_same.hpp>
19
20 #include <boost/geometry/core/access.hpp>
21 #include <boost/geometry/core/coordinate_dimension.hpp>
22 #include <boost/geometry/core/cs.hpp>
23
24 #include <boost/geometry/util/condition.hpp>
25 #include <boost/geometry/util/math.hpp>
26
27 #include <boost/geometry/views/detail/indexed_point_view.hpp>
28
29 #include <boost/geometry/algorithms/assign.hpp>
30
31
32 template <typename Units>
33 char const* units2string()
34 {
35 if (BOOST_GEOMETRY_CONDITION((boost::is_same<Units, bg::degree>::value)))
36 {
37 return "degrees";
38 }
39 return "radians";
40 }
41
42 template <typename CoordinateSystem>
43 struct other_system_info
44 {};
45
46 template <>
47 struct other_system_info<bg::cs::spherical_equatorial<bg::radian> >
48 {
49 typedef bg::degree units;
50 typedef bg::cs::spherical_equatorial<units> type;
51
52 template <typename T>
53 static inline T convert(T const& value)
54 {
55 return value * bg::math::r2d<T>();
56 }
57 };
58
59 template <>
60 struct other_system_info<bg::cs::spherical_equatorial<bg::degree> >
61 {
62 typedef bg::radian units;
63 typedef bg::cs::spherical_equatorial<units> type;
64
65 template <typename T>
66 static inline T convert(T const& value)
67 {
68 return value * bg::math::d2r<T>();
69 }
70 };
71
72 template <>
73 struct other_system_info<bg::cs::geographic<bg::radian> >
74 {
75 typedef bg::degree units;
76 typedef bg::cs::geographic<units> type;
77
78 template <typename T>
79 static inline T convert(T const& value)
80 {
81 return value * bg::math::r2d<T>();
82 }
83 };
84
85 template <>
86 struct other_system_info<bg::cs::geographic<bg::degree> >
87 {
88 typedef bg::radian units;
89 typedef bg::cs::geographic<units> type;
90
91 template <typename T>
92 static inline T convert(T const& value)
93 {
94 return value * bg::math::d2r<T>();
95 }
96 };
97
98
99
100 class equals_with_tolerance
101 {
102 private:
103 double m_tolerence;
104
105 template <typename T>
106 static inline T const& get_max(T const& a, T const& b, T const& c)
107 {
108 return (std::max)((std::max)(a, b), c);
109 }
110
111 template <typename T>
112 static inline bool check_close(T const& a, T const& b, double tol)
113 {
114 return (a == b)
115 || (std::abs(a - b) <= tol * get_max(std::abs(a), std::abs(b), 1.0));
116 }
117
118 public:
119 equals_with_tolerance(double tolerence) : m_tolerence(tolerence) {}
120
121 template <typename T>
122 inline bool operator()(T const& value1, T const& value2) const
123 {
124 return check_close(value1, value2, m_tolerence);
125 }
126 };
127
128
129 template
130 <
131 typename Box1,
132 typename Box2 = Box1,
133 std::size_t DimensionCount = bg::dimension<Box1>::value
134 >
135 struct box_equals
136 {
137 static inline bool apply(Box1 const& box1, Box2 const& box2, double tol)
138 {
139 equals_with_tolerance equals(tol);
140
141 #ifndef BOOST_GEOMETRY_TEST_ENABLE_FAILING
142 // check latitude with tolerance when necessary
143 return bg::math::equals(bg::get<0, 0>(box1), bg::get<0, 0>(box2))
144 && (bg::get<0, 1>(box1) < 0
145 ? equals(bg::get<0, 1>(box1), bg::get<0, 1>(box2))
146 : bg::math::equals(bg::get<0, 1>(box1), bg::get<0, 1>(box2)))
147 && bg::math::equals(bg::get<1, 0>(box1), bg::get<1, 0>(box2))
148 && (bg::get<1, 1>(box1) > 0
149 ? equals(bg::get<1, 1>(box1), bg::get<1, 1>(box2))
150 : bg::math::equals(bg::get<1, 1>(box1), bg::get<1, 1>(box2)));
151 #else
152 // check latitude with tolerance when necessary
153 return bg::get<0, 0>(box1) == bg::get<0, 0>(box2)
154 && (bg::get<0, 1>(box1) < 0
155 ? equals(bg::get<0, 1>(box1), bg::get<0, 1>(box2))
156 : bg::get<0, 1>(box1) == bg::get<0, 1>(box2))
157 && bg::get<1, 0>(box1) == bg::get<1, 0>(box2)
158 && (bg::get<1, 1>(box1) > 0
159 ? equals(bg::get<1, 1>(box1), bg::get<1, 1>(box2))
160 : bg::get<1, 1>(box1) == bg::get<1, 1>(box2));
161 #endif
162 }
163 };
164
165 template <typename Box1, typename Box2>
166 struct box_equals<Box1, Box2, 3>
167 {
168 static inline bool apply(Box1 const& box1, Box2 const& box2, double tol)
169 {
170 #ifndef BOOST_GEOMETRY_TEST_ENABLE_FAILING
171 equals_with_tolerance equals(tol);
172
173 return box_equals<Box1, Box2, 2>::apply(box1, box2, tol)
174 && equals(bg::get<0, 2>(box1), bg::get<0, 2>(box2))
175 && equals(bg::get<1, 2>(box1), bg::get<1, 2>(box2));
176 #else
177 return box_equals<Box1, Box2, 2>::apply(box1, box2, tol)
178 && bg::get<0, 2>(box1) == bg::get<0, 2>(box2)
179 && bg::get<1, 2>(box1) == bg::get<1, 2>(box2);
180 #endif
181 }
182 };
183
184
185 template <typename Box, std::size_t Dimension = bg::dimension<Box>::value>
186 struct initialize_box
187 {
188 static inline void apply(Box& box,
189 double lon_min, double lat_min, double,
190 double lon_max, double lat_max, double)
191 {
192 bg::detail::indexed_point_view<Box, bg::min_corner> p_min(box);
193 bg::detail::indexed_point_view<Box, bg::max_corner> p_max(box);
194
195 bg::assign_values(p_min, lon_min, lat_min);
196 bg::assign_values(p_max, lon_max, lat_max);
197 }
198 };
199
200 template <typename Box>
201 struct initialize_box<Box, 3>
202 {
203 static inline void apply(Box& box,
204 double lon_min, double lat_min, double height_min,
205 double lon_max, double lat_max, double height_max)
206 {
207 bg::detail::indexed_point_view<Box, bg::min_corner> p_min(box);
208 bg::detail::indexed_point_view<Box, bg::max_corner> p_max(box);
209
210 bg::assign_values(p_min, lon_min, lat_min, height_min);
211 bg::assign_values(p_max, lon_max, lat_max, height_max);
212 }
213 };
214
215 #endif // BOOST_GEOMETRY_TEST_ENVELOPE_EXPAND_ON_SPHEROID_HPP