]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry Index |
2 | // | |
3 | // Spatial index distance predicates, calculators and checkers | |
4 | // used in nearest query - specialized for envelopes | |
5 | // | |
6 | // Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland. | |
7 | // | |
92f5a8d4 TL |
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 | // | |
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_DISTANCE_PREDICATES_HPP | |
17 | #define BOOST_GEOMETRY_INDEX_DETAIL_DISTANCE_PREDICATES_HPP | |
18 | ||
19 | #include <boost/geometry/index/detail/algorithms/comparable_distance_near.hpp> | |
20 | #include <boost/geometry/index/detail/algorithms/comparable_distance_far.hpp> | |
21 | #include <boost/geometry/index/detail/algorithms/comparable_distance_centroid.hpp> | |
22 | #include <boost/geometry/index/detail/algorithms/path_intersection.hpp> | |
23 | ||
24 | #include <boost/geometry/index/detail/tags.hpp> | |
25 | ||
26 | namespace boost { namespace geometry { namespace index { namespace detail { | |
27 | ||
28 | // ------------------------------------------------------------------ // | |
29 | // relations | |
30 | // ------------------------------------------------------------------ // | |
31 | ||
32 | template <typename T> | |
33 | struct to_nearest | |
34 | { | |
35 | to_nearest(T const& v) : value(v) {} | |
36 | T value; | |
37 | }; | |
38 | ||
39 | template <typename T> | |
40 | struct to_centroid | |
41 | { | |
42 | to_centroid(T const& v) : value(v) {} | |
43 | T value; | |
44 | }; | |
45 | ||
46 | template <typename T> | |
47 | struct to_furthest | |
48 | { | |
49 | to_furthest(T const& v) : value(v) {} | |
50 | T value; | |
51 | }; | |
52 | ||
53 | // tags | |
54 | ||
55 | struct to_nearest_tag {}; | |
56 | struct to_centroid_tag {}; | |
57 | struct to_furthest_tag {}; | |
58 | ||
59 | // ------------------------------------------------------------------ // | |
60 | // relation traits and access | |
61 | // ------------------------------------------------------------------ // | |
62 | ||
63 | template <typename T> | |
64 | struct relation | |
65 | { | |
66 | typedef T value_type; | |
67 | typedef to_nearest_tag tag; | |
68 | static inline T const& value(T const& v) { return v; } | |
69 | static inline T & value(T & v) { return v; } | |
70 | }; | |
71 | ||
72 | template <typename T> | |
73 | struct relation< to_nearest<T> > | |
74 | { | |
75 | typedef T value_type; | |
76 | typedef to_nearest_tag tag; | |
77 | static inline T const& value(to_nearest<T> const& r) { return r.value; } | |
78 | static inline T & value(to_nearest<T> & r) { return r.value; } | |
79 | }; | |
80 | ||
81 | template <typename T> | |
82 | struct relation< to_centroid<T> > | |
83 | { | |
84 | typedef T value_type; | |
85 | typedef to_centroid_tag tag; | |
86 | static inline T const& value(to_centroid<T> const& r) { return r.value; } | |
87 | static inline T & value(to_centroid<T> & r) { return r.value; } | |
88 | }; | |
89 | ||
90 | template <typename T> | |
91 | struct relation< to_furthest<T> > | |
92 | { | |
93 | typedef T value_type; | |
94 | typedef to_furthest_tag tag; | |
95 | static inline T const& value(to_furthest<T> const& r) { return r.value; } | |
96 | static inline T & value(to_furthest<T> & r) { return r.value; } | |
97 | }; | |
98 | ||
92f5a8d4 TL |
99 | // ------------------------------------------------------------------ // |
100 | ||
101 | template | |
102 | < | |
103 | typename G1, typename G2, typename Strategy, | |
104 | typename Tag1 = typename geometry::tag<G1>::type, | |
105 | typename Tag2 = typename geometry::tag<G2>::type | |
106 | > | |
107 | struct comparable_distance_call_base | |
108 | { | |
109 | typedef typename geometry::default_comparable_distance_result | |
110 | < | |
111 | G1, G2 | |
112 | >::type result_type; | |
113 | ||
114 | static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const&) | |
115 | { | |
116 | return geometry::comparable_distance(g1, g2); | |
117 | } | |
118 | }; | |
119 | ||
120 | template | |
121 | < | |
122 | typename G1, typename G2, typename Strategy | |
123 | > | |
124 | struct comparable_distance_call_base<G1, G2, Strategy, point_tag, point_tag> | |
125 | { | |
126 | typedef typename geometry::comparable_distance_result | |
127 | < | |
128 | G1, G2, | |
129 | typename Strategy::comparable_distance_point_point_strategy_type | |
130 | >::type result_type; | |
131 | ||
132 | static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const& s) | |
133 | { | |
134 | return geometry::comparable_distance(g1, g2, | |
135 | s.get_comparable_distance_point_point_strategy()); | |
136 | } | |
137 | }; | |
138 | ||
139 | template | |
140 | < | |
141 | typename G1, typename G2, typename Strategy | |
142 | > | |
143 | struct comparable_distance_call_base<G1, G2, Strategy, point_tag, box_tag> | |
144 | { | |
145 | typedef typename geometry::comparable_distance_result | |
146 | < | |
147 | G1, G2, | |
148 | typename Strategy::comparable_distance_point_box_strategy_type | |
149 | >::type result_type; | |
150 | ||
151 | static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const& s) | |
152 | { | |
153 | return geometry::comparable_distance(g1, g2, | |
154 | s.get_comparable_distance_point_box_strategy()); | |
155 | } | |
156 | }; | |
157 | ||
158 | template | |
159 | < | |
160 | typename G1, typename G2, typename Strategy | |
161 | > | |
162 | struct comparable_distance_call_base<G1, G2, Strategy, segment_tag, point_tag> | |
163 | { | |
164 | typedef typename geometry::comparable_distance_result | |
165 | < | |
166 | G1, G2, | |
167 | typename Strategy::comparable_distance_point_segment_strategy_type | |
168 | >::type result_type; | |
169 | ||
170 | static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const& s) | |
171 | { | |
172 | return geometry::comparable_distance(g1, g2, | |
173 | s.get_comparable_distance_point_segment_strategy()); | |
174 | } | |
175 | }; | |
176 | ||
177 | template | |
178 | < | |
179 | typename G1, typename G2, typename Strategy | |
180 | > | |
181 | struct comparable_distance_call_base<G1, G2, Strategy, segment_tag, box_tag> | |
182 | { | |
183 | typedef typename geometry::comparable_distance_result | |
184 | < | |
185 | G1, G2, | |
186 | typename Strategy::comparable_distance_segment_box_strategy_type | |
187 | >::type result_type; | |
188 | ||
189 | static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const& s) | |
190 | { | |
191 | return geometry::comparable_distance(g1, g2, | |
192 | s.get_comparable_distance_segment_box_strategy()); | |
193 | } | |
194 | }; | |
195 | ||
196 | template | |
197 | < | |
198 | typename G1, typename G2, typename Strategy | |
199 | > | |
200 | struct comparable_distance_call_base<G1, G2, Strategy, segment_tag, segment_tag> | |
201 | { | |
202 | typedef typename geometry::comparable_distance_result | |
203 | < | |
204 | G1, G2, | |
205 | typename Strategy::comparable_distance_point_segment_strategy_type | |
206 | >::type result_type; | |
207 | ||
208 | static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const& s) | |
209 | { | |
210 | return geometry::comparable_distance(g1, g2, | |
211 | s.get_comparable_distance_point_segment_strategy()); | |
212 | } | |
213 | }; | |
214 | ||
215 | template | |
216 | < | |
217 | typename G1, typename G2, typename Strategy | |
218 | > | |
219 | struct comparable_distance_call | |
220 | : comparable_distance_call_base<G1, G2, Strategy> | |
221 | {}; | |
222 | ||
223 | template | |
224 | < | |
225 | typename G1, typename G2 | |
226 | > | |
227 | struct comparable_distance_call<G1, G2, default_strategy> | |
228 | : comparable_distance_call_base<G1, G2, default_strategy, void, void> | |
229 | {}; | |
230 | ||
7c673cae FG |
231 | // ------------------------------------------------------------------ // |
232 | // calculate_distance | |
233 | // ------------------------------------------------------------------ // | |
234 | ||
92f5a8d4 | 235 | template <typename Predicate, typename Indexable, typename Strategy, typename Tag> |
7c673cae FG |
236 | struct calculate_distance |
237 | { | |
238 | BOOST_MPL_ASSERT_MSG((false), INVALID_PREDICATE_OR_TAG, (calculate_distance)); | |
239 | }; | |
240 | ||
241 | // this handles nearest() with default Point parameter, to_nearest() and bounds | |
92f5a8d4 TL |
242 | template <typename PointRelation, typename Indexable, typename Strategy, typename Tag> |
243 | struct calculate_distance< predicates::nearest<PointRelation>, Indexable, Strategy, Tag> | |
7c673cae FG |
244 | { |
245 | typedef detail::relation<PointRelation> relation; | |
92f5a8d4 TL |
246 | typedef comparable_distance_call |
247 | < | |
248 | typename relation::value_type, | |
249 | Indexable, | |
250 | Strategy | |
251 | > call_type; | |
252 | typedef typename call_type::result_type result_type; | |
7c673cae | 253 | |
92f5a8d4 TL |
254 | static inline bool apply(predicates::nearest<PointRelation> const& p, Indexable const& i, |
255 | Strategy const& s, result_type & result) | |
7c673cae | 256 | { |
92f5a8d4 | 257 | result = call_type::apply(relation::value(p.point_or_relation), i, s); |
7c673cae FG |
258 | return true; |
259 | } | |
260 | }; | |
261 | ||
92f5a8d4 TL |
262 | template <typename Point, typename Indexable, typename Strategy> |
263 | struct calculate_distance< predicates::nearest< to_centroid<Point> >, Indexable, Strategy, value_tag> | |
7c673cae FG |
264 | { |
265 | typedef Point point_type; | |
92f5a8d4 TL |
266 | typedef typename geometry::default_comparable_distance_result |
267 | < | |
268 | point_type, Indexable | |
269 | >::type result_type; | |
7c673cae | 270 | |
92f5a8d4 TL |
271 | static inline bool apply(predicates::nearest< to_centroid<Point> > const& p, Indexable const& i, |
272 | Strategy const& , result_type & result) | |
7c673cae FG |
273 | { |
274 | result = index::detail::comparable_distance_centroid(p.point_or_relation.value, i); | |
275 | return true; | |
276 | } | |
277 | }; | |
278 | ||
92f5a8d4 TL |
279 | template <typename Point, typename Indexable, typename Strategy> |
280 | struct calculate_distance< predicates::nearest< to_furthest<Point> >, Indexable, Strategy, value_tag> | |
7c673cae FG |
281 | { |
282 | typedef Point point_type; | |
92f5a8d4 TL |
283 | typedef typename geometry::default_comparable_distance_result |
284 | < | |
285 | point_type, Indexable | |
286 | >::type result_type; | |
7c673cae | 287 | |
92f5a8d4 TL |
288 | static inline bool apply(predicates::nearest< to_furthest<Point> > const& p, Indexable const& i, |
289 | Strategy const& , result_type & result) | |
7c673cae FG |
290 | { |
291 | result = index::detail::comparable_distance_far(p.point_or_relation.value, i); | |
292 | return true; | |
293 | } | |
294 | }; | |
295 | ||
92f5a8d4 TL |
296 | template <typename SegmentOrLinestring, typename Indexable, typename Strategy, typename Tag> |
297 | struct calculate_distance< predicates::path<SegmentOrLinestring>, Indexable, Strategy, Tag> | |
7c673cae FG |
298 | { |
299 | typedef typename index::detail::default_path_intersection_distance_type< | |
300 | Indexable, SegmentOrLinestring | |
301 | >::type result_type; | |
302 | ||
92f5a8d4 TL |
303 | static inline bool apply(predicates::path<SegmentOrLinestring> const& p, Indexable const& i, |
304 | Strategy const& , result_type & result) | |
7c673cae FG |
305 | { |
306 | return index::detail::path_intersection(i, p.geometry, result); | |
307 | } | |
308 | }; | |
309 | ||
310 | }}}} // namespace boost::geometry::index::detail | |
311 | ||
312 | #endif // BOOST_GEOMETRY_INDEX_RTREE_DISTANCE_PREDICATES_HPP |