bounds.hpp 6.3 KB

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