1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2015, Oracle and/or its affiliates.
6 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
11 #ifndef BOOST_GEOMETRY_TEST_ENVELOPE_EXPAND_ON_SPHEROID_HPP
12 #define BOOST_GEOMETRY_TEST_ENVELOPE_EXPAND_ON_SPHEROID_HPP
18 #include <boost/type_traits/is_same.hpp>
20 #include <boost/geometry/core/access.hpp>
21 #include <boost/geometry/core/coordinate_dimension.hpp>
22 #include <boost/geometry/core/cs.hpp>
24 #include <boost/geometry/util/condition.hpp>
25 #include <boost/geometry/util/math.hpp>
27 #include <boost/geometry/views/detail/indexed_point_view.hpp>
29 #include <boost/geometry/algorithms/assign.hpp>
32 template <typename Units>
33 char const* units2string()
35 if (BOOST_GEOMETRY_CONDITION((boost::is_same<Units, bg::degree>::value)))
42 template <typename CoordinateSystem>
43 struct other_system_info
47 struct other_system_info<bg::cs::spherical_equatorial<bg::radian> >
49 typedef bg::degree units;
50 typedef bg::cs::spherical_equatorial<units> type;
53 static inline T convert(T const& value)
55 return value * bg::math::r2d<T>();
60 struct other_system_info<bg::cs::spherical_equatorial<bg::degree> >
62 typedef bg::radian units;
63 typedef bg::cs::spherical_equatorial<units> type;
66 static inline T convert(T const& value)
68 return value * bg::math::d2r<T>();
73 struct other_system_info<bg::cs::geographic<bg::radian> >
75 typedef bg::degree units;
76 typedef bg::cs::geographic<units> type;
79 static inline T convert(T const& value)
81 return value * bg::math::r2d<T>();
86 struct other_system_info<bg::cs::geographic<bg::degree> >
88 typedef bg::radian units;
89 typedef bg::cs::geographic<units> type;
92 static inline T convert(T const& value)
94 return value * bg::math::d2r<T>();
100 class equals_with_tolerance
105 template <typename T>
106 static inline T const& get_max(T const& a, T const& b, T const& c)
108 return (std::max)((std::max)(a, b), c);
111 template <typename T>
112 static inline bool check_close(T const& a, T const& b, double tol)
115 || (std::abs(a - b) <= tol * get_max(std::abs(a), std::abs(b), 1.0));
119 equals_with_tolerance(double tolerence) : m_tolerence(tolerence) {}
121 template <typename T>
122 inline bool operator()(T const& value1, T const& value2) const
124 return check_close(value1, value2, m_tolerence);
132 typename Box2 = Box1,
133 std::size_t DimensionCount = bg::dimension<Box1>::value
137 static inline bool apply(Box1 const& box1, Box2 const& box2, double tol)
139 equals_with_tolerance equals(tol);
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)));
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));
165 template <typename Box1, typename Box2>
166 struct box_equals<Box1, Box2, 3>
168 static inline bool apply(Box1 const& box1, Box2 const& box2, double tol)
170 #ifndef BOOST_GEOMETRY_TEST_ENABLE_FAILING
171 equals_with_tolerance equals(tol);
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));
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);
185 template <typename Box, std::size_t Dimension = bg::dimension<Box>::value>
186 struct initialize_box
188 static inline void apply(Box& box,
189 double lon_min, double lat_min, double,
190 double lon_max, double lat_max, double)
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);
195 bg::assign_values(p_min, lon_min, lat_min);
196 bg::assign_values(p_max, lon_max, lat_max);
200 template <typename Box>
201 struct initialize_box<Box, 3>
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)
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);
210 bg::assign_values(p_min, lon_min, lat_min, height_min);
211 bg::assign_values(p_max, lon_max, lat_max, height_max);
215 #endif // BOOST_GEOMETRY_TEST_ENVELOPE_EXPAND_ON_SPHEROID_HPP