annotate DEPENDENCIES/generic/include/boost/geometry/policies/compare.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Boost.Geometry (aka GGL, Generic Geometry Library)
Chris@16 2
Chris@16 3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
Chris@16 4
Chris@16 5 // Use, modification and distribution is subject to the Boost Software License,
Chris@16 6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8
Chris@16 9 #ifndef BOOST_GEOMETRY_POLICIES_COMPARE_HPP
Chris@16 10 #define BOOST_GEOMETRY_POLICIES_COMPARE_HPP
Chris@16 11
Chris@16 12
Chris@16 13 #include <cstddef>
Chris@16 14
Chris@16 15 #include <boost/geometry/strategies/compare.hpp>
Chris@16 16 #include <boost/geometry/util/math.hpp>
Chris@16 17
Chris@16 18
Chris@16 19 namespace boost { namespace geometry
Chris@16 20 {
Chris@16 21
Chris@16 22
Chris@16 23 #ifndef DOXYGEN_NO_DETAIL
Chris@16 24 namespace detail { namespace compare
Chris@16 25 {
Chris@16 26
Chris@16 27
Chris@16 28 template
Chris@16 29 <
Chris@16 30 int Direction,
Chris@16 31 typename Point,
Chris@16 32 typename Strategy,
Chris@16 33 std::size_t Dimension,
Chris@16 34 std::size_t DimensionCount
Chris@16 35 >
Chris@16 36 struct compare_loop
Chris@16 37 {
Chris@16 38 typedef typename strategy::compare::detail::select_strategy
Chris@16 39 <
Chris@16 40 Strategy, Direction, Point, Dimension
Chris@16 41 >::type compare_type;
Chris@16 42
Chris@16 43 typedef typename geometry::coordinate_type<Point>::type coordinate_type;
Chris@16 44
Chris@16 45 static inline bool apply(Point const& left, Point const& right)
Chris@16 46 {
Chris@16 47 coordinate_type const& cleft = geometry::get<Dimension>(left);
Chris@16 48 coordinate_type const& cright = geometry::get<Dimension>(right);
Chris@16 49
Chris@16 50 if (geometry::math::equals(cleft, cright))
Chris@16 51 {
Chris@16 52 return compare_loop
Chris@16 53 <
Chris@16 54 Direction, Point, Strategy,
Chris@16 55 Dimension + 1, DimensionCount
Chris@16 56 >::apply(left, right);
Chris@16 57 }
Chris@16 58 else
Chris@16 59 {
Chris@16 60 compare_type compare;
Chris@16 61 return compare(cleft, cright);
Chris@16 62 }
Chris@16 63 }
Chris@16 64 };
Chris@16 65
Chris@16 66 template
Chris@16 67 <
Chris@16 68 int Direction,
Chris@16 69 typename Point,
Chris@16 70 typename Strategy,
Chris@16 71 std::size_t DimensionCount
Chris@16 72 >
Chris@16 73 struct compare_loop<Direction, Point, Strategy, DimensionCount, DimensionCount>
Chris@16 74 {
Chris@16 75 static inline bool apply(Point const&, Point const&)
Chris@16 76 {
Chris@16 77 // On coming here, points are equal. Return true if
Chris@16 78 // direction = 0 (equal), false if -1/1 (greater/less)
Chris@16 79 return Direction == 0;
Chris@16 80 }
Chris@16 81 };
Chris@16 82
Chris@16 83
Chris@16 84 template <int Direction, typename Point, typename Strategy>
Chris@16 85 struct compare_in_all_dimensions
Chris@16 86 {
Chris@16 87 inline bool operator()(Point const& left, Point const& right) const
Chris@16 88 {
Chris@16 89 return detail::compare::compare_loop
Chris@16 90 <
Chris@16 91 Direction, Point, Strategy,
Chris@16 92 0, geometry::dimension<Point>::type::value
Chris@16 93 >::apply(left, right);
Chris@16 94 }
Chris@16 95 };
Chris@16 96
Chris@16 97
Chris@16 98 template <typename Point, typename Strategy, std::size_t Dimension>
Chris@16 99 class compare_in_one_dimension
Chris@16 100 {
Chris@16 101 Strategy compare;
Chris@16 102
Chris@16 103 public :
Chris@16 104 inline bool operator()(Point const& left, Point const& right) const
Chris@16 105 {
Chris@16 106 typedef typename geometry::coordinate_type<Point>::type coordinate_type;
Chris@16 107
Chris@16 108 coordinate_type const& cleft = get<Dimension>(left);
Chris@16 109 coordinate_type const& cright = get<Dimension>(right);
Chris@16 110 return compare(cleft, cright);
Chris@16 111 }
Chris@16 112 };
Chris@16 113
Chris@16 114 }} // namespace detail::compare
Chris@16 115
Chris@16 116 #endif
Chris@16 117
Chris@16 118 #ifndef DOXYGEN_NO_DISPATCH
Chris@16 119 namespace dispatch
Chris@16 120 {
Chris@16 121
Chris@16 122 template
Chris@16 123 <
Chris@16 124 int Direction,
Chris@16 125 typename Point,
Chris@16 126 typename Strategy,
Chris@16 127 int Dimension
Chris@16 128 >
Chris@16 129 struct compare_geometries
Chris@16 130 : detail::compare::compare_in_one_dimension
Chris@16 131 <
Chris@16 132 Point,
Chris@16 133 typename strategy::compare::detail::select_strategy
Chris@16 134 <
Chris@16 135 Strategy, Direction, Point, Dimension
Chris@16 136 >::type,
Chris@16 137 Dimension
Chris@16 138 >
Chris@16 139 {};
Chris@16 140
Chris@16 141
Chris@16 142 // Specialization with -1: compare in all dimensions
Chris@16 143 template <int Direction, typename Point, typename Strategy>
Chris@16 144 struct compare_geometries<Direction, Point, Strategy, -1>
Chris@16 145 : detail::compare::compare_in_all_dimensions<Direction, Point, Strategy>
Chris@16 146 {};
Chris@16 147
Chris@16 148
Chris@16 149
Chris@16 150 } // namespace dispatch
Chris@16 151 #endif // DOXYGEN_NO_DISPATCH
Chris@16 152
Chris@16 153
Chris@16 154 /*!
Chris@16 155 \brief Less functor, to sort points in ascending order.
Chris@16 156 \ingroup compare
Chris@16 157 \details This functor compares points and orders them on x,
Chris@16 158 then on y, then on z coordinate.
Chris@16 159 \tparam Geometry the geometry
Chris@16 160 \tparam Dimension the dimension to sort on, defaults to -1,
Chris@16 161 indicating ALL dimensions. That's to say, first on x,
Chris@16 162 on equal x-es then on y, etc.
Chris@16 163 If a dimension is specified, only that dimension is considered
Chris@16 164 \tparam Strategy underlying coordinate comparing functor,
Chris@16 165 defaults to the default comparison strategies
Chris@16 166 related to the point coordinate system. If specified, the specified
Chris@16 167 strategy is used. This can e.g. be std::less<double>.
Chris@16 168 */
Chris@16 169 template
Chris@16 170 <
Chris@16 171 typename Point,
Chris@16 172 int Dimension = -1,
Chris@16 173 typename Strategy = strategy::compare::default_strategy
Chris@16 174 >
Chris@16 175 struct less
Chris@16 176 : dispatch::compare_geometries
Chris@16 177 <
Chris@16 178 1, // indicates ascending
Chris@16 179 Point,
Chris@16 180 Strategy,
Chris@16 181 Dimension
Chris@16 182 >
Chris@16 183 {
Chris@16 184 typedef Point first_argument_type;
Chris@16 185 typedef Point second_argument_type;
Chris@16 186 typedef bool result_type;
Chris@16 187 };
Chris@16 188
Chris@16 189
Chris@16 190 /*!
Chris@16 191 \brief Greater functor
Chris@16 192 \ingroup compare
Chris@16 193 \details Can be used to sort points in reverse order
Chris@16 194 \see Less functor
Chris@16 195 */
Chris@16 196 template
Chris@16 197 <
Chris@16 198 typename Point,
Chris@16 199 int Dimension = -1,
Chris@16 200 typename Strategy = strategy::compare::default_strategy
Chris@16 201 >
Chris@16 202 struct greater
Chris@16 203 : dispatch::compare_geometries
Chris@16 204 <
Chris@16 205 -1, // indicates descending
Chris@16 206 Point,
Chris@16 207 Strategy,
Chris@16 208 Dimension
Chris@16 209 >
Chris@16 210 {};
Chris@16 211
Chris@16 212
Chris@16 213 /*!
Chris@16 214 \brief Equal To functor, to compare if points are equal
Chris@16 215 \ingroup compare
Chris@16 216 \tparam Geometry the geometry
Chris@16 217 \tparam Dimension the dimension to compare on, defaults to -1,
Chris@16 218 indicating ALL dimensions.
Chris@16 219 If a dimension is specified, only that dimension is considered
Chris@16 220 \tparam Strategy underlying coordinate comparing functor
Chris@16 221 */
Chris@16 222 template
Chris@16 223 <
Chris@16 224 typename Point,
Chris@16 225 int Dimension = -1,
Chris@16 226 typename Strategy = strategy::compare::default_strategy
Chris@16 227 >
Chris@16 228 struct equal_to
Chris@16 229 : dispatch::compare_geometries
Chris@16 230 <
Chris@16 231 0,
Chris@16 232 Point,
Chris@16 233 Strategy,
Chris@16 234 Dimension
Chris@16 235 >
Chris@16 236 {};
Chris@16 237
Chris@16 238
Chris@16 239 }} // namespace boost::geometry
Chris@16 240
Chris@16 241
Chris@16 242 #endif // BOOST_GEOMETRY_POLICIES_COMPARE_HPP