bounds.hpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // Boost.Geometry Index
  2. //
  3. // n-dimensional bounds
  4. //
  5. // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // This file was modified by Oracle on 2019.
  8. // Modifications copyright (c) 2019 Oracle and/or its affiliates.
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. //
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_BOUNDS_HPP
  15. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_BOUNDS_HPP
  16. #include <boost/geometry/index/detail/bounded_view.hpp>
  17. namespace boost { namespace geometry { namespace index { namespace detail
  18. {
  19. namespace dispatch
  20. {
  21. template <typename Geometry,
  22. typename Bounds,
  23. typename TagGeometry = typename geometry::tag<Geometry>::type,
  24. typename TagBounds = typename geometry::tag<Bounds>::type>
  25. struct bounds
  26. {
  27. template <typename Strategy>
  28. static inline void apply(Geometry const& g, Bounds & b, Strategy const& )
  29. {
  30. geometry::convert(g, b);
  31. }
  32. };
  33. template <typename Geometry, typename Bounds>
  34. struct bounds<Geometry, Bounds, segment_tag, box_tag>
  35. {
  36. template <typename Strategy>
  37. static inline void apply(Geometry const& g, Bounds & b, Strategy const& s)
  38. {
  39. index::detail::bounded_view<Geometry, Bounds, Strategy> v(g, s);
  40. geometry::convert(v, b);
  41. }
  42. };
  43. } // namespace dispatch
  44. template <typename Geometry, typename Bounds, typename Strategy>
  45. inline void bounds(Geometry const& g, Bounds & b, Strategy const& s)
  46. {
  47. concepts::check_concepts_and_equal_dimensions<Geometry const, Bounds>();
  48. dispatch::bounds<Geometry, Bounds>::apply(g, b, s);
  49. }
  50. namespace dispatch
  51. {
  52. template <typename Bounds,
  53. typename Geometry,
  54. typename TagBounds = typename geometry::tag<Bounds>::type,
  55. typename TagGeometry = typename geometry::tag<Geometry>::type>
  56. struct expand
  57. {
  58. // STATIC ASSERT
  59. };
  60. template <typename Bounds, typename Geometry>
  61. struct expand<Bounds, Geometry, box_tag, point_tag>
  62. {
  63. static inline void apply(Bounds & b, Geometry const& g)
  64. {
  65. geometry::expand(b, g);
  66. }
  67. template <typename Strategy>
  68. static inline void apply(Bounds & b, Geometry const& g, Strategy const& )
  69. {
  70. geometry::expand(b, g, typename Strategy::expand_point_strategy_type());
  71. }
  72. };
  73. template <typename Bounds, typename Geometry>
  74. struct expand<Bounds, Geometry, box_tag, box_tag>
  75. {
  76. static inline void apply(Bounds & b, Geometry const& g)
  77. {
  78. geometry::expand(b, g);
  79. }
  80. template <typename Strategy>
  81. static inline void apply(Bounds & b, Geometry const& g, Strategy const& )
  82. {
  83. geometry::expand(b, g, typename Strategy::expand_box_strategy_type());
  84. }
  85. };
  86. template <typename Bounds, typename Geometry>
  87. struct expand<Bounds, Geometry, box_tag, segment_tag>
  88. {
  89. static inline void apply(Bounds & b, Geometry const& g)
  90. {
  91. geometry::expand(b, g);
  92. }
  93. template <typename Strategy>
  94. static inline void apply(Bounds & b, Geometry const& g, Strategy const& s)
  95. {
  96. index::detail::bounded_view<Geometry, Bounds, Strategy> v(g, s);
  97. geometry::expand(b, v, typename Strategy::expand_box_strategy_type());
  98. }
  99. };
  100. } // namespace dispatch
  101. template <typename Bounds, typename Geometry, typename Strategy>
  102. inline void expand(Bounds & b, Geometry const& g, Strategy const& s)
  103. {
  104. dispatch::expand<Bounds, Geometry>::apply(b, g, s);
  105. }
  106. template <typename Bounds, typename Geometry>
  107. inline void expand(Bounds & b, Geometry const& g, default_strategy const& )
  108. {
  109. dispatch::expand<Bounds, Geometry>::apply(b, g);
  110. }
  111. namespace dispatch
  112. {
  113. template <typename Geometry,
  114. typename Bounds,
  115. typename TagGeometry = typename geometry::tag<Geometry>::type,
  116. typename TagBounds = typename geometry::tag<Bounds>::type>
  117. struct covered_by_bounds
  118. {};
  119. template <typename Geometry, typename Bounds>
  120. struct covered_by_bounds<Geometry, Bounds, point_tag, box_tag>
  121. {
  122. static inline bool apply(Geometry const& g, Bounds & b)
  123. {
  124. return geometry::covered_by(g, b);
  125. }
  126. template <typename Strategy>
  127. static inline bool apply(Geometry const& g, Bounds & b, Strategy const&)
  128. {
  129. return geometry::covered_by(g, b, typename Strategy::covered_by_point_box_strategy_type());
  130. }
  131. };
  132. template <typename Geometry, typename Bounds>
  133. struct covered_by_bounds<Geometry, Bounds, box_tag, box_tag>
  134. {
  135. static inline bool apply(Geometry const& g, Bounds & b)
  136. {
  137. return geometry::covered_by(g, b);
  138. }
  139. template <typename Strategy>
  140. static inline bool apply(Geometry const& g, Bounds & b, Strategy const&)
  141. {
  142. return geometry::covered_by(g, b, typename Strategy::covered_by_box_box_strategy_type());
  143. }
  144. };
  145. template <typename Geometry, typename Bounds>
  146. struct covered_by_bounds<Geometry, Bounds, segment_tag, box_tag>
  147. {
  148. static inline bool apply(Geometry const& g, Bounds & b)
  149. {
  150. typedef typename point_type<Geometry>::type point_type;
  151. typedef geometry::model::box<point_type> bounds_type;
  152. typedef index::detail::bounded_view<Geometry, bounds_type, default_strategy> view_type;
  153. return geometry::covered_by(view_type(g, default_strategy()), b);
  154. }
  155. template <typename Strategy>
  156. static inline bool apply(Geometry const& g, Bounds & b, Strategy const& strategy)
  157. {
  158. typedef typename point_type<Geometry>::type point_type;
  159. typedef geometry::model::box<point_type> bounds_type;
  160. typedef index::detail::bounded_view<Geometry, bounds_type, Strategy> view_type;
  161. return geometry::covered_by(view_type(g, strategy), b,
  162. typename Strategy::covered_by_box_box_strategy_type());
  163. }
  164. };
  165. } // namespace dispatch
  166. template <typename Geometry, typename Bounds, typename Strategy>
  167. inline bool covered_by_bounds(Geometry const& g, Bounds & b, Strategy const& s)
  168. {
  169. return dispatch::covered_by_bounds<Geometry, Bounds>::apply(g, b, s);
  170. }
  171. template <typename Geometry, typename Bounds>
  172. inline bool covered_by_bounds(Geometry const& g, Bounds & b, default_strategy const& )
  173. {
  174. return dispatch::covered_by_bounds<Geometry, Bounds>::apply(g, b);
  175. }
  176. }}}} // namespace boost::geometry::index::detail
  177. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_BOUNDS_HPP