]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | // | |
20effc67 TL |
8 | // This file was modified by Oracle on 2019-2020. |
9 | // Modifications copyright (c) 2019-2020 Oracle and/or its affiliates. | |
92f5a8d4 TL |
10 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle |
11 | // | |
7c673cae FG |
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 | ||
16 | #ifndef BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP | |
17 | #define BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP | |
18 | ||
92f5a8d4 | 19 | |
7c673cae | 20 | #include <boost/geometry/algorithms/envelope.hpp> |
20effc67 | 21 | #include <boost/geometry/core/static_assert.hpp> |
92f5a8d4 TL |
22 | #include <boost/geometry/strategies/index.hpp> |
23 | ||
20effc67 | 24 | |
7c673cae FG |
25 | namespace boost { namespace geometry { |
26 | ||
27 | namespace index { namespace detail { | |
28 | ||
92f5a8d4 TL |
29 | |
30 | template <typename Geometry, typename BoundingGeometry, typename Strategy> | |
31 | struct bounded_view_base_cs_tag | |
32 | { | |
33 | typedef typename Strategy::cs_tag type; | |
34 | }; | |
35 | ||
36 | template <typename Geometry, typename BoundingGeometry> | |
37 | struct bounded_view_base_cs_tag<Geometry, BoundingGeometry, default_strategy> | |
38 | : geometry::cs_tag<Geometry> | |
39 | {}; | |
40 | ||
41 | ||
42 | template | |
43 | < | |
44 | typename Geometry, | |
45 | typename BoundingGeometry, | |
46 | typename Strategy, | |
47 | typename Tag = typename geometry::tag<Geometry>::type, | |
48 | typename BoundingTag = typename geometry::tag<BoundingGeometry>::type, | |
49 | typename CSTag = typename bounded_view_base_cs_tag | |
50 | < | |
51 | Geometry, BoundingGeometry, Strategy | |
52 | >::type | |
53 | > | |
54 | struct bounded_view_base | |
7c673cae | 55 | { |
20effc67 TL |
56 | BOOST_GEOMETRY_STATIC_ASSERT_FALSE( |
57 | "Not implemented for these Geometries.", | |
58 | Geometry, BoundingGeometry, Strategy, Tag, BoundingTag, CSTag); | |
7c673cae FG |
59 | }; |
60 | ||
61 | ||
62 | // Segment -> Box | |
63 | ||
92f5a8d4 TL |
64 | template <typename Segment, typename Box, typename Strategy> |
65 | struct bounded_view_base<Segment, Box, Strategy, segment_tag, box_tag, cartesian_tag> | |
7c673cae FG |
66 | { |
67 | public: | |
68 | typedef typename geometry::coordinate_type<Box>::type coordinate_type; | |
69 | ||
92f5a8d4 | 70 | bounded_view_base(Segment const& segment, Strategy const& ) |
7c673cae FG |
71 | : m_segment(segment) |
72 | {} | |
73 | ||
74 | template <std::size_t Dimension> | |
75 | inline coordinate_type get_min() const | |
76 | { | |
77 | return boost::numeric_cast<coordinate_type>( | |
78 | (std::min)( geometry::get<0, Dimension>(m_segment), | |
79 | geometry::get<1, Dimension>(m_segment) ) ); | |
80 | } | |
81 | ||
82 | template <std::size_t Dimension> | |
83 | inline coordinate_type get_max() const | |
84 | { | |
85 | return boost::numeric_cast<coordinate_type>( | |
86 | (std::max)( geometry::get<0, Dimension>(m_segment), | |
87 | geometry::get<1, Dimension>(m_segment) ) ); | |
88 | } | |
89 | ||
90 | private: | |
91 | Segment const& m_segment; | |
92 | }; | |
93 | ||
92f5a8d4 TL |
94 | template <typename Segment, typename Box, typename Strategy, typename CSTag> |
95 | struct bounded_view_base<Segment, Box, Strategy, segment_tag, box_tag, CSTag> | |
7c673cae | 96 | { |
92f5a8d4 TL |
97 | template <typename S> |
98 | inline void envelope(Segment const& segment, S const& strategy) | |
99 | { | |
100 | geometry::envelope(segment, m_box, | |
101 | strategy.get_envelope_segment_strategy()); | |
102 | } | |
103 | ||
104 | inline void envelope(Segment const& segment, default_strategy const& ) | |
105 | { | |
106 | geometry::envelope(segment, m_box); | |
107 | } | |
108 | ||
7c673cae FG |
109 | public: |
110 | typedef typename geometry::coordinate_type<Box>::type coordinate_type; | |
111 | ||
92f5a8d4 | 112 | bounded_view_base(Segment const& segment, Strategy const& strategy) |
7c673cae | 113 | { |
92f5a8d4 | 114 | envelope(segment, strategy); |
7c673cae FG |
115 | } |
116 | ||
117 | template <std::size_t Dimension> | |
118 | inline coordinate_type get_min() const | |
119 | { | |
120 | return geometry::get<min_corner, Dimension>(m_box); | |
121 | } | |
122 | ||
123 | template <std::size_t Dimension> | |
124 | inline coordinate_type get_max() const | |
125 | { | |
126 | return geometry::get<max_corner, Dimension>(m_box); | |
127 | } | |
128 | ||
129 | private: | |
130 | Box m_box; | |
131 | }; | |
132 | ||
133 | // Box -> Box | |
134 | ||
92f5a8d4 TL |
135 | template <typename BoxIn, typename Box, typename Strategy, typename CSTag> |
136 | struct bounded_view_base<BoxIn, Box, Strategy, box_tag, box_tag, CSTag> | |
7c673cae FG |
137 | { |
138 | public: | |
139 | typedef typename geometry::coordinate_type<Box>::type coordinate_type; | |
140 | ||
92f5a8d4 | 141 | bounded_view_base(BoxIn const& box, Strategy const& ) |
7c673cae FG |
142 | : m_box(box) |
143 | {} | |
144 | ||
145 | template <std::size_t Dimension> | |
146 | inline coordinate_type get_min() const | |
147 | { | |
148 | return boost::numeric_cast<coordinate_type>( | |
149 | geometry::get<min_corner, Dimension>(m_box) ); | |
150 | } | |
151 | ||
152 | template <std::size_t Dimension> | |
153 | inline coordinate_type get_max() const | |
154 | { | |
155 | return boost::numeric_cast<coordinate_type>( | |
156 | geometry::get<max_corner, Dimension>(m_box) ); | |
157 | } | |
158 | ||
159 | private: | |
160 | BoxIn const& m_box; | |
161 | }; | |
162 | ||
163 | // Point -> Box | |
164 | ||
92f5a8d4 TL |
165 | template <typename Point, typename Box, typename Strategy, typename CSTag> |
166 | struct bounded_view_base<Point, Box, Strategy, point_tag, box_tag, CSTag> | |
7c673cae FG |
167 | { |
168 | public: | |
169 | typedef typename geometry::coordinate_type<Box>::type coordinate_type; | |
170 | ||
92f5a8d4 | 171 | bounded_view_base(Point const& point, Strategy const& ) |
7c673cae FG |
172 | : m_point(point) |
173 | {} | |
174 | ||
175 | template <std::size_t Dimension> | |
176 | inline coordinate_type get_min() const | |
177 | { | |
178 | return boost::numeric_cast<coordinate_type>( | |
179 | geometry::get<Dimension>(m_point) ); | |
180 | } | |
181 | ||
182 | template <std::size_t Dimension> | |
183 | inline coordinate_type get_max() const | |
184 | { | |
185 | return boost::numeric_cast<coordinate_type>( | |
186 | geometry::get<Dimension>(m_point) ); | |
187 | } | |
188 | ||
189 | private: | |
190 | Point const& m_point; | |
191 | }; | |
192 | ||
92f5a8d4 TL |
193 | |
194 | template <typename Geometry, | |
195 | typename BoundingGeometry, | |
196 | typename Strategy, | |
197 | typename Tag = typename geometry::tag<Geometry>::type, | |
198 | typename BoundingTag = typename geometry::tag<BoundingGeometry>::type> | |
199 | struct bounded_view | |
200 | : bounded_view_base<Geometry, BoundingGeometry, Strategy> | |
201 | { | |
202 | typedef bounded_view_base<Geometry, BoundingGeometry, Strategy> base_type; | |
203 | ||
204 | bounded_view(Geometry const& geometry, Strategy const& strategy) | |
205 | : base_type(geometry, strategy) | |
206 | {} | |
207 | }; | |
208 | ||
209 | template <typename Geometry, | |
210 | typename BoundingGeometry, | |
211 | typename Tag, | |
212 | typename BoundingTag> | |
213 | struct bounded_view<Geometry, BoundingGeometry, default_strategy, Tag, BoundingTag> | |
214 | : bounded_view_base | |
215 | < | |
216 | Geometry, | |
217 | BoundingGeometry, | |
218 | typename strategy::index::services::default_strategy<Geometry>::type | |
219 | > | |
220 | { | |
221 | typedef typename strategy::index::services::default_strategy | |
222 | < | |
223 | Geometry | |
224 | >::type strategy_type; | |
225 | ||
226 | typedef bounded_view_base | |
227 | < | |
228 | Geometry, | |
229 | BoundingGeometry, | |
230 | strategy_type | |
231 | > base_type; | |
232 | ||
233 | explicit bounded_view(Geometry const& geometry, default_strategy const& ) | |
234 | : base_type(geometry, strategy_type()) | |
235 | {} | |
236 | }; | |
237 | ||
238 | ||
7c673cae FG |
239 | }} // namespace index::detail |
240 | ||
241 | // XXX -> Box | |
242 | ||
243 | #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS | |
244 | namespace traits | |
245 | { | |
246 | ||
92f5a8d4 TL |
247 | template <typename Geometry, typename Box, typename Strategy, typename Tag> |
248 | struct tag< index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag> > | |
7c673cae FG |
249 | { |
250 | typedef box_tag type; | |
251 | }; | |
252 | ||
92f5a8d4 TL |
253 | template <typename Geometry, typename Box, typename Strategy, typename Tag> |
254 | struct point_type< index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag> > | |
7c673cae FG |
255 | { |
256 | typedef typename point_type<Box>::type type; | |
257 | }; | |
258 | ||
92f5a8d4 TL |
259 | template <typename Geometry, typename Box, typename Strategy, typename Tag, std::size_t Dimension> |
260 | struct indexed_access<index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag>, | |
7c673cae FG |
261 | min_corner, Dimension> |
262 | { | |
92f5a8d4 | 263 | typedef index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag> box_type; |
7c673cae FG |
264 | typedef typename geometry::coordinate_type<Box>::type coordinate_type; |
265 | ||
266 | static inline coordinate_type get(box_type const& b) | |
267 | { | |
268 | return b.template get_min<Dimension>(); | |
269 | } | |
270 | ||
271 | //static inline void set(box_type & b, coordinate_type const& value) | |
272 | //{ | |
273 | // BOOST_GEOMETRY_INDEX_ASSERT(false, "unable to modify a box through view"); | |
274 | //} | |
275 | }; | |
276 | ||
92f5a8d4 TL |
277 | template <typename Geometry, typename Box, typename Strategy, typename Tag, std::size_t Dimension> |
278 | struct indexed_access<index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag>, | |
7c673cae FG |
279 | max_corner, Dimension> |
280 | { | |
92f5a8d4 | 281 | typedef index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag> box_type; |
7c673cae FG |
282 | typedef typename geometry::coordinate_type<Box>::type coordinate_type; |
283 | ||
284 | static inline coordinate_type get(box_type const& b) | |
285 | { | |
286 | return b.template get_max<Dimension>(); | |
287 | } | |
288 | ||
289 | //static inline void set(box_type & b, coordinate_type const& value) | |
290 | //{ | |
291 | // BOOST_GEOMETRY_INDEX_ASSERT(false, "unable to modify a box through view"); | |
292 | //} | |
293 | }; | |
294 | ||
295 | } // namespace traits | |
296 | #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS | |
297 | ||
298 | }} // namespace boost::geometry | |
299 | ||
300 | #endif // BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP |