compare.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2017.
  4. // Modifications copyright (c) 2017, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_POLICIES_COMPARE_HPP
  10. #define BOOST_GEOMETRY_POLICIES_COMPARE_HPP
  11. #include <cstddef>
  12. #include <boost/geometry/strategies/compare.hpp>
  13. #include <boost/geometry/util/math.hpp>
  14. namespace boost { namespace geometry
  15. {
  16. /*!
  17. \brief Less functor, to sort points in ascending order.
  18. \ingroup compare
  19. \details This functor compares points and orders them on x,
  20. then on y, then on z coordinate.
  21. \tparam Point the geometry
  22. \tparam Dimension the dimension to sort on, defaults to -1,
  23. indicating ALL dimensions. That's to say, first on x,
  24. on equal x-es then on y, etc.
  25. If a dimension is specified, only that dimension is considered
  26. */
  27. template
  28. <
  29. typename Point = void,
  30. int Dimension = -1
  31. >
  32. struct less
  33. {
  34. typedef Point first_argument_type;
  35. typedef Point second_argument_type;
  36. typedef bool result_type;
  37. inline bool operator()(Point const& left, Point const& right) const
  38. {
  39. typedef typename strategy::compare::services::default_strategy
  40. <
  41. strategy::compare::less,
  42. Point, Point,
  43. Dimension
  44. >::type strategy_type;
  45. return strategy_type::apply(left, right);
  46. }
  47. };
  48. template <int Dimension>
  49. struct less<void, Dimension>
  50. {
  51. template <typename Point1, typename Point2>
  52. inline bool operator()(Point1 const& left, Point2 const& right) const
  53. {
  54. typedef typename strategy::compare::services::default_strategy
  55. <
  56. strategy::compare::less,
  57. Point1, Point2,
  58. Dimension
  59. >::type strategy_type;
  60. return strategy_type::apply(left, right);
  61. }
  62. };
  63. /*!
  64. \brief Greater functor
  65. \ingroup compare
  66. \details Can be used to sort points in reverse order
  67. \see Less functor
  68. */
  69. template
  70. <
  71. typename Point = void,
  72. int Dimension = -1
  73. >
  74. struct greater
  75. {
  76. typedef Point first_argument_type;
  77. typedef Point second_argument_type;
  78. typedef bool result_type;
  79. bool operator()(Point const& left, Point const& right) const
  80. {
  81. typedef typename strategy::compare::services::default_strategy
  82. <
  83. strategy::compare::greater,
  84. Point, Point,
  85. Dimension
  86. >::type strategy_type;
  87. return strategy_type::apply(left, right);
  88. }
  89. };
  90. template <int Dimension>
  91. struct greater<void, Dimension>
  92. {
  93. template <typename Point1, typename Point2>
  94. bool operator()(Point1 const& left, Point2 const& right) const
  95. {
  96. typedef typename strategy::compare::services::default_strategy
  97. <
  98. strategy::compare::greater,
  99. Point1, Point2,
  100. Dimension
  101. >::type strategy_type;
  102. return strategy_type::apply(left, right);
  103. }
  104. };
  105. /*!
  106. \brief Equal To functor, to compare if points are equal
  107. \ingroup compare
  108. \tparam Geometry the geometry
  109. \tparam Dimension the dimension to compare on, defaults to -1,
  110. indicating ALL dimensions.
  111. If a dimension is specified, only that dimension is considered
  112. */
  113. template
  114. <
  115. typename Point,
  116. int Dimension = -1
  117. >
  118. struct equal_to
  119. {
  120. typedef Point first_argument_type;
  121. typedef Point second_argument_type;
  122. typedef bool result_type;
  123. bool operator()(Point const& left, Point const& right) const
  124. {
  125. typedef typename strategy::compare::services::default_strategy
  126. <
  127. strategy::compare::equal_to,
  128. Point, Point,
  129. Dimension
  130. >::type strategy_type;
  131. return strategy_type::apply(left, right);
  132. }
  133. };
  134. template <int Dimension>
  135. struct equal_to<void, Dimension>
  136. {
  137. template <typename Point1, typename Point2>
  138. bool operator()(Point1 const& left, Point2 const& right) const
  139. {
  140. typedef typename strategy::compare::services::default_strategy
  141. <
  142. strategy::compare::equal_to,
  143. Point1, Point2,
  144. Dimension
  145. >::type strategy_type;
  146. return strategy_type::apply(left, right);
  147. }
  148. };
  149. }} // namespace boost::geometry
  150. #endif // BOOST_GEOMETRY_POLICIES_COMPARE_HPP