1 // Boost.Geometry (aka GGL, Generic Geometry Library) 2 3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. 4 5 // This file was modified by Oracle on 2017, 2019. 6 // Modifications copyright (c) 2017, 2019, Oracle and/or its affiliates. 7 8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle 9 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) 13 14 #ifndef BOOST_GEOMETRY_POLICIES_COMPARE_HPP 15 #define BOOST_GEOMETRY_POLICIES_COMPARE_HPP 16 17 18 #include <cstddef> 19 20 #include <boost/geometry/strategies/compare.hpp> 21 #include <boost/geometry/util/math.hpp> 22 23 24 namespace boost { namespace geometry 25 { 26 27 28 /*! 29 \brief Less functor, to sort points in ascending order. 30 \ingroup compare 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 38 */ 39 template 40 < 41 typename Point = void, 42 int Dimension = -1, 43 typename CSTag = void 44 > 45 struct less 46 { 47 typedef Point first_argument_type; 48 typedef Point second_argument_type; 49 typedef bool result_type; 50 operator ()boost::geometry::less51 inline bool operator()(Point const& left, Point const& right) const 52 { 53 typedef typename strategy::compare::services::default_strategy 54 < 55 strategy::compare::less, 56 Point, Point, 57 Dimension, 58 CSTag, CSTag 59 >::type strategy_type; 60 61 return strategy_type::apply(left, right); 62 } 63 }; 64 65 template <int Dimension, typename CSTag> 66 struct less<void, Dimension, CSTag> 67 { 68 typedef bool result_type; 69 70 template <typename Point1, typename Point2> operator ()boost::geometry::less71 inline bool operator()(Point1 const& left, Point2 const& right) const 72 { 73 typedef typename strategy::compare::services::default_strategy 74 < 75 strategy::compare::less, 76 Point1, Point2, 77 Dimension, 78 CSTag, CSTag 79 >::type strategy_type; 80 81 return strategy_type::apply(left, right); 82 } 83 }; 84 85 template <typename Point, int Dimension> 86 struct less<Point, Dimension, void> 87 { 88 typedef Point first_argument_type; 89 typedef Point second_argument_type; 90 typedef bool result_type; 91 operator ()boost::geometry::less92 inline bool operator()(Point const& left, Point const& right) const 93 { 94 typedef typename strategy::compare::services::default_strategy 95 < 96 strategy::compare::less, 97 Point, Point, 98 Dimension 99 >::type strategy_type; 100 101 return strategy_type::apply(left, right); 102 } 103 }; 104 105 template <int Dimension> 106 struct less<void, Dimension, void> 107 { 108 typedef bool result_type; 109 110 template <typename Point1, typename Point2> operator ()boost::geometry::less111 inline bool operator()(Point1 const& left, Point2 const& right) const 112 { 113 typedef typename strategy::compare::services::default_strategy 114 < 115 strategy::compare::less, 116 Point1, Point2, 117 Dimension 118 >::type strategy_type; 119 120 return strategy_type::apply(left, right); 121 } 122 }; 123 124 125 /*! 126 \brief Greater functor 127 \ingroup compare 128 \details Can be used to sort points in reverse order 129 \see Less functor 130 */ 131 template 132 < 133 typename Point = void, 134 int Dimension = -1, 135 typename CSTag = void 136 > 137 struct greater 138 { 139 typedef Point first_argument_type; 140 typedef Point second_argument_type; 141 typedef bool result_type; 142 operator ()boost::geometry::greater143 bool operator()(Point const& left, Point const& right) const 144 { 145 typedef typename strategy::compare::services::default_strategy 146 < 147 strategy::compare::greater, 148 Point, Point, 149 Dimension, 150 CSTag, CSTag 151 >::type strategy_type; 152 153 return strategy_type::apply(left, right); 154 } 155 }; 156 157 template <int Dimension, typename CSTag> 158 struct greater<void, Dimension, CSTag> 159 { 160 typedef bool result_type; 161 162 template <typename Point1, typename Point2> operator ()boost::geometry::greater163 bool operator()(Point1 const& left, Point2 const& right) const 164 { 165 typedef typename strategy::compare::services::default_strategy 166 < 167 strategy::compare::greater, 168 Point1, Point2, 169 Dimension, 170 CSTag, CSTag 171 >::type strategy_type; 172 173 return strategy_type::apply(left, right); 174 } 175 }; 176 177 template <typename Point, int Dimension> 178 struct greater<Point, Dimension, void> 179 { 180 typedef Point first_argument_type; 181 typedef Point second_argument_type; 182 typedef bool result_type; 183 operator ()boost::geometry::greater184 bool operator()(Point const& left, Point const& right) const 185 { 186 typedef typename strategy::compare::services::default_strategy 187 < 188 strategy::compare::greater, 189 Point, Point, 190 Dimension 191 >::type strategy_type; 192 193 return strategy_type::apply(left, right); 194 } 195 }; 196 197 template <int Dimension> 198 struct greater<void, Dimension, void> 199 { 200 typedef bool result_type; 201 202 template <typename Point1, typename Point2> operator ()boost::geometry::greater203 bool operator()(Point1 const& left, Point2 const& right) const 204 { 205 typedef typename strategy::compare::services::default_strategy 206 < 207 strategy::compare::greater, 208 Point1, Point2, 209 Dimension 210 >::type strategy_type; 211 212 return strategy_type::apply(left, right); 213 } 214 }; 215 216 217 /*! 218 \brief Equal To functor, to compare if points are equal 219 \ingroup compare 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 224 */ 225 template 226 < 227 typename Point, 228 int Dimension = -1, 229 typename CSTag = void 230 > 231 struct equal_to 232 { 233 typedef Point first_argument_type; 234 typedef Point second_argument_type; 235 typedef bool result_type; 236 operator ()boost::geometry::equal_to237 bool operator()(Point const& left, Point const& right) const 238 { 239 typedef typename strategy::compare::services::default_strategy 240 < 241 strategy::compare::equal_to, 242 Point, Point, 243 Dimension, 244 CSTag, CSTag 245 >::type strategy_type; 246 247 return strategy_type::apply(left, right); 248 } 249 }; 250 251 template <int Dimension, typename CSTag> 252 struct equal_to<void, Dimension, CSTag> 253 { 254 typedef bool result_type; 255 256 template <typename Point1, typename Point2> operator ()boost::geometry::equal_to257 bool operator()(Point1 const& left, Point2 const& right) const 258 { 259 typedef typename strategy::compare::services::default_strategy 260 < 261 strategy::compare::equal_to, 262 Point1, Point2, 263 Dimension, 264 CSTag, CSTag 265 >::type strategy_type; 266 267 return strategy_type::apply(left, right); 268 } 269 }; 270 271 template <typename Point, int Dimension> 272 struct equal_to<Point, Dimension, void> 273 { 274 typedef Point first_argument_type; 275 typedef Point second_argument_type; 276 typedef bool result_type; 277 operator ()boost::geometry::equal_to278 bool operator()(Point const& left, Point const& right) const 279 { 280 typedef typename strategy::compare::services::default_strategy 281 < 282 strategy::compare::equal_to, 283 Point, Point, 284 Dimension 285 >::type strategy_type; 286 287 return strategy_type::apply(left, right); 288 } 289 }; 290 291 template <int Dimension> 292 struct equal_to<void, Dimension, void> 293 { 294 typedef bool result_type; 295 296 template <typename Point1, typename Point2> operator ()boost::geometry::equal_to297 bool operator()(Point1 const& left, Point2 const& right) const 298 { 299 typedef typename strategy::compare::services::default_strategy 300 < 301 strategy::compare::equal_to, 302 Point1, Point2, 303 Dimension 304 >::type strategy_type; 305 306 return strategy_type::apply(left, right); 307 } 308 }; 309 310 311 }} // namespace boost::geometry 312 313 314 #endif // BOOST_GEOMETRY_POLICIES_COMPARE_HPP 315