1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2017, 2019.
6 // Modifications copyright (c) 2017, 2019, Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 #ifndef BOOST_GEOMETRY_POLICIES_COMPARE_HPP
15 #define BOOST_GEOMETRY_POLICIES_COMPARE_HPP
20 #include <boost/geometry/strategies/compare.hpp>
21 #include <boost/geometry/util/math.hpp>
24 namespace boost { namespace geometry
29 \brief Less functor, to sort points in ascending order.
31 \details This functor compares points and orders them on x,
32 then on y, then on z coordinate.
33 \tparam Point the geometry
34 \tparam Dimension the dimension to sort on, defaults to -1,
35 indicating ALL dimensions. That's to say, first on x,
36 on equal x-es then on y, etc.
37 If a dimension is specified, only that dimension is considered
41 typename Point = void,
47 typedef Point first_argument_type;
48 typedef Point second_argument_type;
49 typedef bool result_type;
51 inline bool operator()(Point const& left, Point const& right) const
53 typedef typename strategy::compare::services::default_strategy
55 strategy::compare::less,
59 >::type strategy_type;
61 return strategy_type::apply(left, right);
65 template <int Dimension, typename CSTag>
66 struct less<void, Dimension, CSTag>
68 typedef bool result_type;
70 template <typename Point1, typename Point2>
71 inline bool operator()(Point1 const& left, Point2 const& right) const
73 typedef typename strategy::compare::services::default_strategy
75 strategy::compare::less,
79 >::type strategy_type;
81 return strategy_type::apply(left, right);
85 template <typename Point, int Dimension>
86 struct less<Point, Dimension, void>
88 typedef Point first_argument_type;
89 typedef Point second_argument_type;
90 typedef bool result_type;
92 inline bool operator()(Point const& left, Point const& right) const
94 typedef typename strategy::compare::services::default_strategy
96 strategy::compare::less,
99 >::type strategy_type;
101 return strategy_type::apply(left, right);
105 template <int Dimension>
106 struct less<void, Dimension, void>
108 typedef bool result_type;
110 template <typename Point1, typename Point2>
111 inline bool operator()(Point1 const& left, Point2 const& right) const
113 typedef typename strategy::compare::services::default_strategy
115 strategy::compare::less,
118 >::type strategy_type;
120 return strategy_type::apply(left, right);
126 \brief Greater functor
128 \details Can be used to sort points in reverse order
133 typename Point = void,
135 typename CSTag = void
139 typedef Point first_argument_type;
140 typedef Point second_argument_type;
141 typedef bool result_type;
143 bool operator()(Point const& left, Point const& right) const
145 typedef typename strategy::compare::services::default_strategy
147 strategy::compare::greater,
151 >::type strategy_type;
153 return strategy_type::apply(left, right);
157 template <int Dimension, typename CSTag>
158 struct greater<void, Dimension, CSTag>
160 typedef bool result_type;
162 template <typename Point1, typename Point2>
163 bool operator()(Point1 const& left, Point2 const& right) const
165 typedef typename strategy::compare::services::default_strategy
167 strategy::compare::greater,
171 >::type strategy_type;
173 return strategy_type::apply(left, right);
177 template <typename Point, int Dimension>
178 struct greater<Point, Dimension, void>
180 typedef Point first_argument_type;
181 typedef Point second_argument_type;
182 typedef bool result_type;
184 bool operator()(Point const& left, Point const& right) const
186 typedef typename strategy::compare::services::default_strategy
188 strategy::compare::greater,
191 >::type strategy_type;
193 return strategy_type::apply(left, right);
197 template <int Dimension>
198 struct greater<void, Dimension, void>
200 typedef bool result_type;
202 template <typename Point1, typename Point2>
203 bool operator()(Point1 const& left, Point2 const& right) const
205 typedef typename strategy::compare::services::default_strategy
207 strategy::compare::greater,
210 >::type strategy_type;
212 return strategy_type::apply(left, right);
218 \brief Equal To functor, to compare if points are equal
220 \tparam Geometry the geometry
221 \tparam Dimension the dimension to compare on, defaults to -1,
222 indicating ALL dimensions.
223 If a dimension is specified, only that dimension is considered
229 typename CSTag = void
233 typedef Point first_argument_type;
234 typedef Point second_argument_type;
235 typedef bool result_type;
237 bool operator()(Point const& left, Point const& right) const
239 typedef typename strategy::compare::services::default_strategy
241 strategy::compare::equal_to,
245 >::type strategy_type;
247 return strategy_type::apply(left, right);
251 template <int Dimension, typename CSTag>
252 struct equal_to<void, Dimension, CSTag>
254 typedef bool result_type;
256 template <typename Point1, typename Point2>
257 bool operator()(Point1 const& left, Point2 const& right) const
259 typedef typename strategy::compare::services::default_strategy
261 strategy::compare::equal_to,
265 >::type strategy_type;
267 return strategy_type::apply(left, right);
271 template <typename Point, int Dimension>
272 struct equal_to<Point, Dimension, void>
274 typedef Point first_argument_type;
275 typedef Point second_argument_type;
276 typedef bool result_type;
278 bool operator()(Point const& left, Point const& right) const
280 typedef typename strategy::compare::services::default_strategy
282 strategy::compare::equal_to,
285 >::type strategy_type;
287 return strategy_type::apply(left, right);
291 template <int Dimension>
292 struct equal_to<void, Dimension, void>
294 typedef bool result_type;
296 template <typename Point1, typename Point2>
297 bool operator()(Point1 const& left, Point2 const& right) const
299 typedef typename strategy::compare::services::default_strategy
301 strategy::compare::equal_to,
304 >::type strategy_type;
306 return strategy_type::apply(left, right);
311 }} // namespace boost::geometry
314 #endif // BOOST_GEOMETRY_POLICIES_COMPARE_HPP