]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/strategies/compare.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / geometry / strategies / compare.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6
7 // This file was modified by Oracle on 2017.
8 // Modifications copyright (c) 2017, Oracle and/or its affiliates.
9
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18
19
20 #ifndef BOOST_GEOMETRY_STRATEGIES_COMPARE_HPP
21 #define BOOST_GEOMETRY_STRATEGIES_COMPARE_HPP
22
23
24 #include <cstddef>
25 #include <functional>
26
27 #include <boost/mpl/assert.hpp>
28 #include <boost/mpl/min.hpp>
29
30 #include <boost/geometry/core/access.hpp>
31 #include <boost/geometry/core/cs.hpp>
32 #include <boost/geometry/core/coordinate_type.hpp>
33 #include <boost/geometry/core/coordinate_dimension.hpp>
34
35 #include <boost/geometry/util/math.hpp>
36
37
38 namespace boost { namespace geometry
39 {
40
41
42 namespace strategy { namespace compare
43 {
44
45
46 struct less
47 {
48 template <typename T1, typename T2>
49 static inline bool apply(T1 const& l, T2 const& r)
50 {
51 return l < r;
52 }
53 };
54
55 struct greater
56 {
57 template <typename T1, typename T2>
58 static inline bool apply(T1 const& l, T2 const& r)
59 {
60 return l > r;
61 }
62 };
63
64 struct equal_to
65 {
66 template <typename T1, typename T2>
67 static inline bool apply(T1 const& , T2 const& )
68 {
69 return false;
70 }
71 };
72
73
74 #ifndef DOXYGEN_NO_DETAIL
75 namespace detail
76 {
77
78
79 template
80 <
81 typename ComparePolicy,
82 std::size_t Dimension,
83 std::size_t DimensionCount
84 >
85 struct compare_loop
86 {
87 template <typename Point1, typename Point2>
88 static inline bool apply(Point1 const& left, Point2 const& right)
89 {
90 typename geometry::coordinate_type<Point1>::type const&
91 cleft = geometry::get<Dimension>(left);
92 typename geometry::coordinate_type<Point2>::type const&
93 cright = geometry::get<Dimension>(right);
94
95 if (math::equals(cleft, cright))
96 {
97 return compare_loop
98 <
99 ComparePolicy,
100 Dimension + 1, DimensionCount
101 >::apply(left, right);
102 }
103 else
104 {
105 return ComparePolicy::apply(cleft, cright);
106 }
107 }
108 };
109
110 template
111 <
112 typename ComparePolicy,
113 std::size_t DimensionCount
114 >
115 struct compare_loop<ComparePolicy, DimensionCount, DimensionCount>
116 {
117 template <typename Point1, typename Point2>
118 static inline bool apply(Point1 const& , Point2 const& )
119 {
120 // On coming here, points are equal.
121 // Return false for less/greater.
122 return false;
123 }
124 };
125
126 template
127 <
128 std::size_t DimensionCount
129 >
130 struct compare_loop<strategy::compare::equal_to, DimensionCount, DimensionCount>
131 {
132 template <typename Point1, typename Point2>
133 static inline bool apply(Point1 const& , Point2 const& )
134 {
135 // On coming here, points are equal.
136 // Return true for equal_to.
137 return true;
138 }
139 };
140
141 } // namespace detail
142 #endif // DOXYGEN_NO_DETAIL
143
144
145 template
146 <
147 typename ComparePolicy,
148 int Dimension = -1
149 >
150 struct cartesian
151 {
152 template <typename Point1, typename Point2>
153 static inline bool apply(Point1 const& left, Point2 const& right)
154 {
155 return compare::detail::compare_loop
156 <
157 ComparePolicy, Dimension, Dimension + 1
158 >::apply(left, right);
159 }
160 };
161
162 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
163 template
164 <
165 typename ComparePolicy
166 >
167 struct cartesian<ComparePolicy, -1>
168 {
169 template <typename Point1, typename Point2>
170 static inline bool apply(Point1 const& left, Point2 const& right)
171 {
172 return compare::detail::compare_loop
173 <
174 ComparePolicy,
175 0,
176 boost::mpl::min
177 <
178 geometry::dimension<Point1>,
179 geometry::dimension<Point2>
180 >::type::value
181 >::apply(left, right);
182 }
183 };
184 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
185
186 namespace services
187 {
188
189
190 template
191 <
192 typename ComparePolicy,
193 typename Point1,
194 typename Point2 = Point1,
195 int Dimension = -1,
196 typename CSTag1 = typename cs_tag<Point1>::type,
197 typename CSTag2 = typename cs_tag<Point2>::type
198 >
199 struct default_strategy
200 {
201 BOOST_MPL_ASSERT_MSG
202 (
203 false,
204 NOT_IMPLEMENTED_FOR_THESE_TYPES,
205 (types<CSTag1, CSTag2>)
206 );
207 };
208
209
210 template <typename ComparePolicy, typename Point1, typename Point2, int Dimension>
211 struct default_strategy<ComparePolicy, Point1, Point2, Dimension, cartesian_tag, cartesian_tag>
212 {
213 typedef compare::cartesian<ComparePolicy, Dimension> type;
214 };
215
216
217 } // namespace services
218
219
220 }} // namespace strategy compare
221
222
223 }} // namespace boost::geometry
224
225
226 #endif // BOOST_GEOMETRY_STRATEGIES_COMPARE_HPP