box_in_box.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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_BOX_IN_BOX_HPP
  11. #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BOX_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 box_within_range
  21. {
  22. template <typename BoxContainedValue, typename BoxContainingValue>
  23. static inline bool apply(BoxContainedValue const& bed_min
  24. , BoxContainedValue const& bed_max
  25. , BoxContainingValue const& bing_min
  26. , BoxContainingValue const& bing_max)
  27. {
  28. return bed_min > bing_min && bed_max < bing_max;
  29. }
  30. };
  31. struct box_covered_by_range
  32. {
  33. template <typename BoxContainedValue, typename BoxContainingValue>
  34. static inline bool apply(BoxContainedValue const& bed_min
  35. , BoxContainedValue const& bed_max
  36. , BoxContainingValue const& bing_min
  37. , BoxContainingValue const& bing_max)
  38. {
  39. return bed_min >= bing_min && bed_max <= bing_max;
  40. }
  41. };
  42. template
  43. <
  44. typename SubStrategy,
  45. typename Box1,
  46. typename Box2,
  47. std::size_t Dimension,
  48. std::size_t DimensionCount
  49. >
  50. struct relate_box_box_loop
  51. {
  52. static inline bool apply(Box1 const& b_contained, Box2 const& b_containing)
  53. {
  54. assert_dimension_equal<Box1, Box2>();
  55. if (! SubStrategy::apply(
  56. get<min_corner, Dimension>(b_contained),
  57. get<max_corner, Dimension>(b_contained),
  58. get<min_corner, Dimension>(b_containing),
  59. get<max_corner, Dimension>(b_containing)
  60. )
  61. )
  62. {
  63. return false;
  64. }
  65. return relate_box_box_loop
  66. <
  67. SubStrategy,
  68. Box1, Box2,
  69. Dimension + 1, DimensionCount
  70. >::apply(b_contained, b_containing);
  71. }
  72. };
  73. template
  74. <
  75. typename SubStrategy,
  76. typename Box1,
  77. typename Box2,
  78. std::size_t DimensionCount
  79. >
  80. struct relate_box_box_loop<SubStrategy, Box1, Box2, DimensionCount, DimensionCount>
  81. {
  82. static inline bool apply(Box1 const& , Box2 const& )
  83. {
  84. return true;
  85. }
  86. };
  87. template
  88. <
  89. typename Box1,
  90. typename Box2,
  91. typename SubStrategy = box_within_range
  92. >
  93. struct box_in_box
  94. {
  95. static inline bool apply(Box1 const& box1, Box2 const& box2)
  96. {
  97. return relate_box_box_loop
  98. <
  99. SubStrategy,
  100. Box1, Box2, 0, dimension<Box1>::type::value
  101. >::apply(box1, box2);
  102. }
  103. };
  104. } // namespace within
  105. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  106. namespace within { namespace services
  107. {
  108. template <typename BoxContained, typename BoxContaining>
  109. struct default_strategy
  110. <
  111. box_tag, box_tag,
  112. box_tag, areal_tag,
  113. cartesian_tag, cartesian_tag,
  114. BoxContained, BoxContaining
  115. >
  116. {
  117. typedef within::box_in_box<BoxContained, BoxContaining> type;
  118. };
  119. }} // namespace within::services
  120. namespace covered_by { namespace services
  121. {
  122. template <typename BoxContained, typename BoxContaining>
  123. struct default_strategy
  124. <
  125. box_tag, box_tag,
  126. box_tag, areal_tag,
  127. cartesian_tag, cartesian_tag,
  128. BoxContained, BoxContaining
  129. >
  130. {
  131. typedef within::box_in_box
  132. <
  133. BoxContained, BoxContaining,
  134. within::box_covered_by_range
  135. > type;
  136. };
  137. }} // namespace covered_by::services
  138. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  139. }}} // namespace boost::geometry::strategy
  140. #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BOX_IN_BOX_HPP