bounds.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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-2021.
  8. // Modifications copyright (c) 2019-2021 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/algorithms/convert.hpp>
  17. #include <boost/geometry/algorithms/detail/covered_by/interface.hpp>
  18. #include <boost/geometry/algorithms/detail/envelope/interface.hpp>
  19. #include <boost/geometry/algorithms/detail/expand/interface.hpp>
  20. #include <boost/geometry/index/detail/bounded_view.hpp>
  21. namespace boost { namespace geometry { namespace index { namespace detail
  22. {
  23. namespace dispatch
  24. {
  25. template
  26. <
  27. typename Geometry,
  28. typename Bounds,
  29. typename TagGeometry = geometry::tag_t<Geometry>,
  30. typename TagBounds = geometry::tag_t<Bounds>
  31. >
  32. struct bounds
  33. {
  34. template <typename Strategy>
  35. static inline void apply(Geometry const& g, Bounds & b, Strategy const& )
  36. {
  37. geometry::convert(g, b);
  38. }
  39. };
  40. template <typename Geometry, typename Bounds>
  41. struct bounds<Geometry, Bounds, segment_tag, box_tag>
  42. {
  43. template <typename Strategy>
  44. static inline void apply(Geometry const& g, Bounds & b, Strategy const& s)
  45. {
  46. index::detail::bounded_view<Geometry, Bounds, Strategy> v(g, s);
  47. geometry::convert(v, b);
  48. }
  49. };
  50. } // namespace dispatch
  51. template <typename Geometry, typename Bounds, typename Strategy>
  52. inline void bounds(Geometry const& g, Bounds & b, Strategy const& s)
  53. {
  54. concepts::check_concepts_and_equal_dimensions<Geometry const, Bounds>();
  55. dispatch::bounds<Geometry, Bounds>::apply(g, b, s);
  56. }
  57. namespace dispatch
  58. {
  59. template
  60. <
  61. typename Bounds,
  62. typename Geometry,
  63. typename TagBounds = geometry::tag_t<Bounds>,
  64. typename TagGeometry = geometry::tag_t<Geometry>
  65. >
  66. struct expand
  67. {
  68. // STATIC ASSERT
  69. };
  70. template <typename Bounds, typename Geometry>
  71. struct expand<Bounds, Geometry, box_tag, point_tag>
  72. {
  73. static inline void apply(Bounds & b, Geometry const& g)
  74. {
  75. geometry::expand(b, g);
  76. }
  77. template <typename Strategy>
  78. static inline void apply(Bounds & b, Geometry const& g, Strategy const& s)
  79. {
  80. geometry::expand(b, g, s);
  81. }
  82. };
  83. template <typename Bounds, typename Geometry>
  84. struct expand<Bounds, Geometry, box_tag, box_tag>
  85. {
  86. static inline void apply(Bounds & b, Geometry const& g)
  87. {
  88. geometry::expand(b, g);
  89. }
  90. template <typename Strategy>
  91. static inline void apply(Bounds & b, Geometry const& g, Strategy const& s)
  92. {
  93. geometry::expand(b, g, s);
  94. }
  95. };
  96. template <typename Bounds, typename Geometry>
  97. struct expand<Bounds, Geometry, box_tag, segment_tag>
  98. {
  99. static inline void apply(Bounds & b, Geometry const& g)
  100. {
  101. geometry::expand(b, g);
  102. }
  103. template <typename Strategy>
  104. static inline void apply(Bounds & b, Geometry const& g, Strategy const& s)
  105. {
  106. geometry::expand(b, geometry::return_envelope<Bounds>(g, s), s);
  107. // requires additional strategy
  108. //geometry::expand(b, g, s);
  109. }
  110. };
  111. } // namespace dispatch
  112. template <typename Bounds, typename Geometry, typename Strategy>
  113. inline void expand(Bounds & b, Geometry const& g, Strategy const& s)
  114. {
  115. dispatch::expand<Bounds, Geometry>::apply(b, g, s);
  116. }
  117. template <typename Bounds, typename Geometry>
  118. inline void expand(Bounds & b, Geometry const& g, default_strategy const& )
  119. {
  120. dispatch::expand<Bounds, Geometry>::apply(b, g);
  121. }
  122. namespace dispatch
  123. {
  124. template
  125. <
  126. typename Geometry,
  127. typename Bounds,
  128. typename TagGeometry = geometry::tag_t<Geometry>,
  129. typename TagBounds = geometry::tag_t<Bounds>
  130. >
  131. struct covered_by_bounds
  132. {};
  133. template <typename Geometry, typename Bounds>
  134. struct covered_by_bounds<Geometry, Bounds, point_tag, box_tag>
  135. {
  136. static inline bool apply(Geometry const& g, Bounds & b)
  137. {
  138. return geometry::covered_by(g, b);
  139. }
  140. template <typename Strategy>
  141. static inline bool apply(Geometry const& g, Bounds & b, Strategy const& s)
  142. {
  143. return geometry::covered_by(g, b, s);
  144. }
  145. };
  146. template <typename Geometry, typename Bounds>
  147. struct covered_by_bounds<Geometry, Bounds, box_tag, box_tag>
  148. {
  149. static inline bool apply(Geometry const& g, Bounds & b)
  150. {
  151. return geometry::covered_by(g, b);
  152. }
  153. template <typename Strategy>
  154. static inline bool apply(Geometry const& g, Bounds & b, Strategy const& s)
  155. {
  156. return geometry::covered_by(g, b, s);
  157. }
  158. };
  159. template <typename Geometry, typename Bounds>
  160. struct covered_by_bounds<Geometry, Bounds, segment_tag, box_tag>
  161. {
  162. static inline bool apply(Geometry const& g, Bounds & b)
  163. {
  164. using point_type = point_type_t<Geometry>;
  165. using bounds_type = geometry::model::box<point_type>;
  166. using view_type = index::detail::bounded_view<Geometry, bounds_type, default_strategy>;
  167. return geometry::covered_by(view_type(g, default_strategy()), b);
  168. }
  169. template <typename Strategy>
  170. static inline bool apply(Geometry const& g, Bounds & b, Strategy const& strategy)
  171. {
  172. using point_type = point_type_t<Geometry>;
  173. using bounds_type = geometry::model::box<point_type>;
  174. using view_type = index::detail::bounded_view<Geometry, bounds_type, Strategy>;
  175. return geometry::covered_by(view_type(g, strategy), b, strategy);
  176. }
  177. };
  178. } // namespace dispatch
  179. template <typename Geometry, typename Bounds, typename Strategy>
  180. inline bool covered_by_bounds(Geometry const& g, Bounds & b, Strategy const& s)
  181. {
  182. return dispatch::covered_by_bounds<Geometry, Bounds>::apply(g, b, s);
  183. }
  184. template <typename Geometry, typename Bounds>
  185. inline bool covered_by_bounds(Geometry const& g, Bounds & b, default_strategy const& )
  186. {
  187. return dispatch::covered_by_bounds<Geometry, Bounds>::apply(g, b);
  188. }
  189. }}}} // namespace boost::geometry::index::detail
  190. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_BOUNDS_HPP