point_in_box.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_BOX_HPP
  11. #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_BOX_HPP
  12. #include <boost/geometry/core/access.hpp>
  13. #include <boost/geometry/core/coordinate_dimension.hpp>
  14. #include <boost/geometry/strategies/covered_by.hpp>
  15. #include <boost/geometry/strategies/within.hpp>
  16. namespace boost { namespace geometry { namespace strategy
  17. {
  18. namespace within
  19. {
  20. struct within_range
  21. {
  22. template <typename Value1, typename Value2>
  23. static inline bool apply(Value1 const& value, Value2 const& min_value, Value2 const& max_value)
  24. {
  25. return value > min_value && value < max_value;
  26. }
  27. };
  28. struct covered_by_range
  29. {
  30. template <typename Value1, typename Value2>
  31. static inline bool apply(Value1 const& value, Value2 const& min_value, Value2 const& max_value)
  32. {
  33. return value >= min_value && value <= max_value;
  34. }
  35. };
  36. template
  37. <
  38. typename SubStrategy,
  39. typename Point,
  40. typename Box,
  41. std::size_t Dimension,
  42. std::size_t DimensionCount
  43. >
  44. struct relate_point_box_loop
  45. {
  46. static inline bool apply(Point const& point, Box const& box)
  47. {
  48. if (! SubStrategy::apply(get<Dimension>(point),
  49. get<min_corner, Dimension>(box),
  50. get<max_corner, Dimension>(box))
  51. )
  52. {
  53. return false;
  54. }
  55. return relate_point_box_loop
  56. <
  57. SubStrategy,
  58. Point, Box,
  59. Dimension + 1, DimensionCount
  60. >::apply(point, box);
  61. }
  62. };
  63. template
  64. <
  65. typename SubStrategy,
  66. typename Point,
  67. typename Box,
  68. std::size_t DimensionCount
  69. >
  70. struct relate_point_box_loop<SubStrategy, Point, Box, DimensionCount, DimensionCount>
  71. {
  72. static inline bool apply(Point const& , Box const& )
  73. {
  74. return true;
  75. }
  76. };
  77. template
  78. <
  79. typename Point,
  80. typename Box,
  81. typename SubStrategy = within_range
  82. >
  83. struct point_in_box
  84. {
  85. static inline bool apply(Point const& point, Box const& box)
  86. {
  87. return relate_point_box_loop
  88. <
  89. SubStrategy,
  90. Point, Box,
  91. 0, dimension<Point>::type::value
  92. >::apply(point, box);
  93. }
  94. };
  95. } // namespace within
  96. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  97. namespace within { namespace services
  98. {
  99. template <typename Point, typename Box>
  100. struct default_strategy
  101. <
  102. point_tag, box_tag,
  103. point_tag, areal_tag,
  104. cartesian_tag, cartesian_tag,
  105. Point, Box
  106. >
  107. {
  108. typedef within::point_in_box<Point, Box> type;
  109. };
  110. }} // namespace within::services
  111. namespace covered_by { namespace services
  112. {
  113. template <typename Point, typename Box>
  114. struct default_strategy
  115. <
  116. point_tag, box_tag,
  117. point_tag, areal_tag,
  118. cartesian_tag, cartesian_tag,
  119. Point, Box
  120. >
  121. {
  122. typedef within::point_in_box
  123. <
  124. Point, Box,
  125. within::covered_by_range
  126. > type;
  127. };
  128. }} // namespace covered_by::services
  129. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  130. }}} // namespace boost::geometry::strategy
  131. #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_BOX_HPP