bounded_view.hpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // Boost.Geometry Index
  2. //
  3. // This view makes possible to treat some simple primitives as its bounding geometry
  4. // e.g. box, nsphere, etc.
  5. //
  6. // Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland.
  7. //
  8. // This file was modified by Oracle on 2019.
  9. // Modifications copyright (c) 2019 Oracle and/or its affiliates.
  10. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  11. //
  12. // Use, modification and distribution is subject to the Boost Software License,
  13. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP
  16. #define BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP
  17. #include <boost/mpl/assert.hpp>
  18. #include <boost/geometry/algorithms/envelope.hpp>
  19. #include <boost/geometry/strategies/index.hpp>
  20. namespace boost { namespace geometry {
  21. namespace index { namespace detail {
  22. template <typename Geometry, typename BoundingGeometry, typename Strategy>
  23. struct bounded_view_base_cs_tag
  24. {
  25. typedef typename Strategy::cs_tag type;
  26. };
  27. template <typename Geometry, typename BoundingGeometry>
  28. struct bounded_view_base_cs_tag<Geometry, BoundingGeometry, default_strategy>
  29. : geometry::cs_tag<Geometry>
  30. {};
  31. template
  32. <
  33. typename Geometry,
  34. typename BoundingGeometry,
  35. typename Strategy,
  36. typename Tag = typename geometry::tag<Geometry>::type,
  37. typename BoundingTag = typename geometry::tag<BoundingGeometry>::type,
  38. typename CSTag = typename bounded_view_base_cs_tag
  39. <
  40. Geometry, BoundingGeometry, Strategy
  41. >::type
  42. >
  43. struct bounded_view_base
  44. {
  45. BOOST_MPL_ASSERT_MSG(
  46. (false),
  47. NOT_IMPLEMENTED_FOR_THOSE_GEOMETRIES,
  48. (types<Tag, BoundingTag, CSTag>));
  49. };
  50. // Segment -> Box
  51. template <typename Segment, typename Box, typename Strategy>
  52. struct bounded_view_base<Segment, Box, Strategy, segment_tag, box_tag, cartesian_tag>
  53. {
  54. public:
  55. typedef typename geometry::coordinate_type<Box>::type coordinate_type;
  56. bounded_view_base(Segment const& segment, Strategy const& )
  57. : m_segment(segment)
  58. {}
  59. template <std::size_t Dimension>
  60. inline coordinate_type get_min() const
  61. {
  62. return boost::numeric_cast<coordinate_type>(
  63. (std::min)( geometry::get<0, Dimension>(m_segment),
  64. geometry::get<1, Dimension>(m_segment) ) );
  65. }
  66. template <std::size_t Dimension>
  67. inline coordinate_type get_max() const
  68. {
  69. return boost::numeric_cast<coordinate_type>(
  70. (std::max)( geometry::get<0, Dimension>(m_segment),
  71. geometry::get<1, Dimension>(m_segment) ) );
  72. }
  73. private:
  74. Segment const& m_segment;
  75. };
  76. template <typename Segment, typename Box, typename Strategy, typename CSTag>
  77. struct bounded_view_base<Segment, Box, Strategy, segment_tag, box_tag, CSTag>
  78. {
  79. template <typename S>
  80. inline void envelope(Segment const& segment, S const& strategy)
  81. {
  82. geometry::envelope(segment, m_box,
  83. strategy.get_envelope_segment_strategy());
  84. }
  85. inline void envelope(Segment const& segment, default_strategy const& )
  86. {
  87. geometry::envelope(segment, m_box);
  88. }
  89. public:
  90. typedef typename geometry::coordinate_type<Box>::type coordinate_type;
  91. bounded_view_base(Segment const& segment, Strategy const& strategy)
  92. {
  93. envelope(segment, strategy);
  94. }
  95. template <std::size_t Dimension>
  96. inline coordinate_type get_min() const
  97. {
  98. return geometry::get<min_corner, Dimension>(m_box);
  99. }
  100. template <std::size_t Dimension>
  101. inline coordinate_type get_max() const
  102. {
  103. return geometry::get<max_corner, Dimension>(m_box);
  104. }
  105. private:
  106. Box m_box;
  107. };
  108. // Box -> Box
  109. template <typename BoxIn, typename Box, typename Strategy, typename CSTag>
  110. struct bounded_view_base<BoxIn, Box, Strategy, box_tag, box_tag, CSTag>
  111. {
  112. public:
  113. typedef typename geometry::coordinate_type<Box>::type coordinate_type;
  114. bounded_view_base(BoxIn const& box, Strategy const& )
  115. : m_box(box)
  116. {}
  117. template <std::size_t Dimension>
  118. inline coordinate_type get_min() const
  119. {
  120. return boost::numeric_cast<coordinate_type>(
  121. geometry::get<min_corner, Dimension>(m_box) );
  122. }
  123. template <std::size_t Dimension>
  124. inline coordinate_type get_max() const
  125. {
  126. return boost::numeric_cast<coordinate_type>(
  127. geometry::get<max_corner, Dimension>(m_box) );
  128. }
  129. private:
  130. BoxIn const& m_box;
  131. };
  132. // Point -> Box
  133. template <typename Point, typename Box, typename Strategy, typename CSTag>
  134. struct bounded_view_base<Point, Box, Strategy, point_tag, box_tag, CSTag>
  135. {
  136. public:
  137. typedef typename geometry::coordinate_type<Box>::type coordinate_type;
  138. bounded_view_base(Point const& point, Strategy const& )
  139. : m_point(point)
  140. {}
  141. template <std::size_t Dimension>
  142. inline coordinate_type get_min() const
  143. {
  144. return boost::numeric_cast<coordinate_type>(
  145. geometry::get<Dimension>(m_point) );
  146. }
  147. template <std::size_t Dimension>
  148. inline coordinate_type get_max() const
  149. {
  150. return boost::numeric_cast<coordinate_type>(
  151. geometry::get<Dimension>(m_point) );
  152. }
  153. private:
  154. Point const& m_point;
  155. };
  156. template <typename Geometry,
  157. typename BoundingGeometry,
  158. typename Strategy,
  159. typename Tag = typename geometry::tag<Geometry>::type,
  160. typename BoundingTag = typename geometry::tag<BoundingGeometry>::type>
  161. struct bounded_view
  162. : bounded_view_base<Geometry, BoundingGeometry, Strategy>
  163. {
  164. typedef bounded_view_base<Geometry, BoundingGeometry, Strategy> base_type;
  165. bounded_view(Geometry const& geometry, Strategy const& strategy)
  166. : base_type(geometry, strategy)
  167. {}
  168. };
  169. template <typename Geometry,
  170. typename BoundingGeometry,
  171. typename Tag,
  172. typename BoundingTag>
  173. struct bounded_view<Geometry, BoundingGeometry, default_strategy, Tag, BoundingTag>
  174. : bounded_view_base
  175. <
  176. Geometry,
  177. BoundingGeometry,
  178. typename strategy::index::services::default_strategy<Geometry>::type
  179. >
  180. {
  181. typedef typename strategy::index::services::default_strategy
  182. <
  183. Geometry
  184. >::type strategy_type;
  185. typedef bounded_view_base
  186. <
  187. Geometry,
  188. BoundingGeometry,
  189. strategy_type
  190. > base_type;
  191. explicit bounded_view(Geometry const& geometry, default_strategy const& )
  192. : base_type(geometry, strategy_type())
  193. {}
  194. };
  195. }} // namespace index::detail
  196. // XXX -> Box
  197. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  198. namespace traits
  199. {
  200. template <typename Geometry, typename Box, typename Strategy, typename Tag>
  201. struct tag< index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag> >
  202. {
  203. typedef box_tag type;
  204. };
  205. template <typename Geometry, typename Box, typename Strategy, typename Tag>
  206. struct point_type< index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag> >
  207. {
  208. typedef typename point_type<Box>::type type;
  209. };
  210. template <typename Geometry, typename Box, typename Strategy, typename Tag, std::size_t Dimension>
  211. struct indexed_access<index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag>,
  212. min_corner, Dimension>
  213. {
  214. typedef index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag> box_type;
  215. typedef typename geometry::coordinate_type<Box>::type coordinate_type;
  216. static inline coordinate_type get(box_type const& b)
  217. {
  218. return b.template get_min<Dimension>();
  219. }
  220. //static inline void set(box_type & b, coordinate_type const& value)
  221. //{
  222. // BOOST_GEOMETRY_INDEX_ASSERT(false, "unable to modify a box through view");
  223. //}
  224. };
  225. template <typename Geometry, typename Box, typename Strategy, typename Tag, std::size_t Dimension>
  226. struct indexed_access<index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag>,
  227. max_corner, Dimension>
  228. {
  229. typedef index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag> box_type;
  230. typedef typename geometry::coordinate_type<Box>::type coordinate_type;
  231. static inline coordinate_type get(box_type const& b)
  232. {
  233. return b.template get_max<Dimension>();
  234. }
  235. //static inline void set(box_type & b, coordinate_type const& value)
  236. //{
  237. // BOOST_GEOMETRY_INDEX_ASSERT(false, "unable to modify a box through view");
  238. //}
  239. };
  240. } // namespace traits
  241. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  242. }} // namespace boost::geometry
  243. #endif // BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP