Chris@16
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@16
|
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
|
Chris@16
|
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
|
Chris@16
|
6
|
Chris@16
|
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
Chris@16
|
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
Chris@16
|
9
|
Chris@16
|
10 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@16
|
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
12 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
13
|
Chris@16
|
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DISTANCE_HPP
|
Chris@16
|
15 #define BOOST_GEOMETRY_ALGORITHMS_DISTANCE_HPP
|
Chris@16
|
16
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/concept_check.hpp>
|
Chris@16
|
19 #include <boost/mpl/if.hpp>
|
Chris@16
|
20 #include <boost/range.hpp>
|
Chris@16
|
21 #include <boost/typeof/typeof.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 #include <boost/geometry/core/cs.hpp>
|
Chris@16
|
24 #include <boost/geometry/core/closure.hpp>
|
Chris@16
|
25 #include <boost/geometry/core/reverse_dispatch.hpp>
|
Chris@16
|
26 #include <boost/geometry/core/tag_cast.hpp>
|
Chris@16
|
27
|
Chris@16
|
28 #include <boost/geometry/algorithms/not_implemented.hpp>
|
Chris@16
|
29 #include <boost/geometry/algorithms/detail/throw_on_empty_input.hpp>
|
Chris@16
|
30
|
Chris@16
|
31 #include <boost/geometry/geometries/segment.hpp>
|
Chris@16
|
32 #include <boost/geometry/geometries/concepts/check.hpp>
|
Chris@16
|
33
|
Chris@16
|
34 #include <boost/geometry/strategies/distance.hpp>
|
Chris@16
|
35 #include <boost/geometry/strategies/default_distance_result.hpp>
|
Chris@16
|
36 #include <boost/geometry/algorithms/assign.hpp>
|
Chris@16
|
37 #include <boost/geometry/algorithms/within.hpp>
|
Chris@16
|
38
|
Chris@16
|
39 #include <boost/geometry/views/closeable_view.hpp>
|
Chris@16
|
40 #include <boost/geometry/util/math.hpp>
|
Chris@16
|
41
|
Chris@16
|
42
|
Chris@16
|
43 namespace boost { namespace geometry
|
Chris@16
|
44 {
|
Chris@16
|
45
|
Chris@16
|
46 #ifndef DOXYGEN_NO_DETAIL
|
Chris@16
|
47 namespace detail { namespace distance
|
Chris@16
|
48 {
|
Chris@16
|
49
|
Chris@16
|
50 // To avoid spurious namespaces here:
|
Chris@16
|
51 using strategy::distance::services::return_type;
|
Chris@16
|
52
|
Chris@16
|
53 template <typename P1, typename P2, typename Strategy>
|
Chris@16
|
54 struct point_to_point
|
Chris@16
|
55 {
|
Chris@16
|
56 static inline typename return_type<Strategy, P1, P2>::type
|
Chris@16
|
57 apply(P1 const& p1, P2 const& p2, Strategy const& strategy)
|
Chris@16
|
58 {
|
Chris@16
|
59 boost::ignore_unused_variable_warning(strategy);
|
Chris@16
|
60 return strategy.apply(p1, p2);
|
Chris@16
|
61 }
|
Chris@16
|
62 };
|
Chris@16
|
63
|
Chris@16
|
64
|
Chris@16
|
65 template<typename Point, typename Segment, typename Strategy>
|
Chris@16
|
66 struct point_to_segment
|
Chris@16
|
67 {
|
Chris@16
|
68 static inline typename return_type<Strategy, Point, typename point_type<Segment>::type>::type
|
Chris@16
|
69 apply(Point const& point, Segment const& segment, Strategy const& )
|
Chris@16
|
70 {
|
Chris@16
|
71 typename strategy::distance::services::default_strategy
|
Chris@16
|
72 <
|
Chris@16
|
73 segment_tag,
|
Chris@16
|
74 Point,
|
Chris@16
|
75 typename point_type<Segment>::type,
|
Chris@16
|
76 typename cs_tag<Point>::type,
|
Chris@16
|
77 typename cs_tag<typename point_type<Segment>::type>::type,
|
Chris@16
|
78 Strategy
|
Chris@16
|
79 >::type segment_strategy;
|
Chris@16
|
80
|
Chris@16
|
81 typename point_type<Segment>::type p[2];
|
Chris@16
|
82 geometry::detail::assign_point_from_index<0>(segment, p[0]);
|
Chris@16
|
83 geometry::detail::assign_point_from_index<1>(segment, p[1]);
|
Chris@16
|
84 return segment_strategy.apply(point, p[0], p[1]);
|
Chris@16
|
85 }
|
Chris@16
|
86 };
|
Chris@16
|
87
|
Chris@16
|
88
|
Chris@16
|
89 template
|
Chris@16
|
90 <
|
Chris@16
|
91 typename Point,
|
Chris@16
|
92 typename Range,
|
Chris@16
|
93 closure_selector Closure,
|
Chris@16
|
94 typename PPStrategy,
|
Chris@16
|
95 typename PSStrategy
|
Chris@16
|
96 >
|
Chris@16
|
97 struct point_to_range
|
Chris@16
|
98 {
|
Chris@16
|
99 typedef typename return_type<PSStrategy, Point, typename point_type<Range>::type>::type return_type;
|
Chris@16
|
100
|
Chris@16
|
101 static inline return_type apply(Point const& point, Range const& range,
|
Chris@16
|
102 PPStrategy const& pp_strategy, PSStrategy const& ps_strategy)
|
Chris@16
|
103 {
|
Chris@16
|
104 return_type const zero = return_type(0);
|
Chris@16
|
105
|
Chris@16
|
106 if (boost::size(range) == 0)
|
Chris@16
|
107 {
|
Chris@16
|
108 return zero;
|
Chris@16
|
109 }
|
Chris@16
|
110
|
Chris@16
|
111 typedef typename closeable_view<Range const, Closure>::type view_type;
|
Chris@16
|
112
|
Chris@16
|
113 view_type view(range);
|
Chris@16
|
114
|
Chris@16
|
115 // line of one point: return point distance
|
Chris@16
|
116 typedef typename boost::range_iterator<view_type const>::type iterator_type;
|
Chris@16
|
117 iterator_type it = boost::begin(view);
|
Chris@16
|
118 iterator_type prev = it++;
|
Chris@16
|
119 if (it == boost::end(view))
|
Chris@16
|
120 {
|
Chris@16
|
121 return pp_strategy.apply(point, *boost::begin(view));
|
Chris@16
|
122 }
|
Chris@16
|
123
|
Chris@16
|
124 // Create comparable (more efficient) strategy
|
Chris@16
|
125 typedef typename strategy::distance::services::comparable_type<PSStrategy>::type eps_strategy_type;
|
Chris@16
|
126 eps_strategy_type eps_strategy = strategy::distance::services::get_comparable<PSStrategy>::apply(ps_strategy);
|
Chris@16
|
127
|
Chris@16
|
128 // start with first segment distance
|
Chris@16
|
129 return_type d = eps_strategy.apply(point, *prev, *it);
|
Chris@16
|
130 return_type rd = ps_strategy.apply(point, *prev, *it);
|
Chris@16
|
131
|
Chris@16
|
132 // check if other segments are closer
|
Chris@16
|
133 for (++prev, ++it; it != boost::end(view); ++prev, ++it)
|
Chris@16
|
134 {
|
Chris@16
|
135 return_type const ds = eps_strategy.apply(point, *prev, *it);
|
Chris@16
|
136 if (geometry::math::equals(ds, zero))
|
Chris@16
|
137 {
|
Chris@16
|
138 return ds;
|
Chris@16
|
139 }
|
Chris@16
|
140 else if (ds < d)
|
Chris@16
|
141 {
|
Chris@16
|
142 d = ds;
|
Chris@16
|
143 rd = ps_strategy.apply(point, *prev, *it);
|
Chris@16
|
144 }
|
Chris@16
|
145 }
|
Chris@16
|
146
|
Chris@16
|
147 return rd;
|
Chris@16
|
148 }
|
Chris@16
|
149 };
|
Chris@16
|
150
|
Chris@16
|
151
|
Chris@16
|
152 template
|
Chris@16
|
153 <
|
Chris@16
|
154 typename Point,
|
Chris@16
|
155 typename Ring,
|
Chris@16
|
156 closure_selector Closure,
|
Chris@16
|
157 typename PPStrategy,
|
Chris@16
|
158 typename PSStrategy
|
Chris@16
|
159 >
|
Chris@16
|
160 struct point_to_ring
|
Chris@16
|
161 {
|
Chris@16
|
162 typedef std::pair
|
Chris@16
|
163 <
|
Chris@16
|
164 typename return_type<PPStrategy, Point, typename point_type<Ring>::type>::type, bool
|
Chris@16
|
165 > distance_containment;
|
Chris@16
|
166
|
Chris@16
|
167 static inline distance_containment apply(Point const& point,
|
Chris@16
|
168 Ring const& ring,
|
Chris@16
|
169 PPStrategy const& pp_strategy, PSStrategy const& ps_strategy)
|
Chris@16
|
170 {
|
Chris@16
|
171 return distance_containment
|
Chris@16
|
172 (
|
Chris@16
|
173 point_to_range
|
Chris@16
|
174 <
|
Chris@16
|
175 Point,
|
Chris@16
|
176 Ring,
|
Chris@16
|
177 Closure,
|
Chris@16
|
178 PPStrategy,
|
Chris@16
|
179 PSStrategy
|
Chris@16
|
180 >::apply(point, ring, pp_strategy, ps_strategy),
|
Chris@16
|
181 geometry::within(point, ring)
|
Chris@16
|
182 );
|
Chris@16
|
183 }
|
Chris@16
|
184 };
|
Chris@16
|
185
|
Chris@16
|
186
|
Chris@16
|
187
|
Chris@16
|
188 template
|
Chris@16
|
189 <
|
Chris@16
|
190 typename Point,
|
Chris@16
|
191 typename Polygon,
|
Chris@16
|
192 closure_selector Closure,
|
Chris@16
|
193 typename PPStrategy,
|
Chris@16
|
194 typename PSStrategy
|
Chris@16
|
195 >
|
Chris@16
|
196 struct point_to_polygon
|
Chris@16
|
197 {
|
Chris@16
|
198 typedef typename return_type<PPStrategy, Point, typename point_type<Polygon>::type>::type return_type;
|
Chris@16
|
199 typedef std::pair<return_type, bool> distance_containment;
|
Chris@16
|
200
|
Chris@16
|
201 static inline distance_containment apply(Point const& point,
|
Chris@16
|
202 Polygon const& polygon,
|
Chris@16
|
203 PPStrategy const& pp_strategy, PSStrategy const& ps_strategy)
|
Chris@16
|
204 {
|
Chris@16
|
205 // Check distance to all rings
|
Chris@16
|
206 typedef point_to_ring
|
Chris@16
|
207 <
|
Chris@16
|
208 Point,
|
Chris@16
|
209 typename ring_type<Polygon>::type,
|
Chris@16
|
210 Closure,
|
Chris@16
|
211 PPStrategy,
|
Chris@16
|
212 PSStrategy
|
Chris@16
|
213 > per_ring;
|
Chris@16
|
214
|
Chris@16
|
215 distance_containment dc = per_ring::apply(point,
|
Chris@16
|
216 exterior_ring(polygon), pp_strategy, ps_strategy);
|
Chris@16
|
217
|
Chris@16
|
218 typename interior_return_type<Polygon const>::type rings
|
Chris@16
|
219 = interior_rings(polygon);
|
Chris@16
|
220 for (BOOST_AUTO_TPL(it, boost::begin(rings)); it != boost::end(rings); ++it)
|
Chris@16
|
221 {
|
Chris@16
|
222 distance_containment dcr = per_ring::apply(point,
|
Chris@16
|
223 *it, pp_strategy, ps_strategy);
|
Chris@16
|
224 if (dcr.first < dc.first)
|
Chris@16
|
225 {
|
Chris@16
|
226 dc.first = dcr.first;
|
Chris@16
|
227 }
|
Chris@16
|
228 // If it was inside, and also inside inner ring,
|
Chris@16
|
229 // turn off the inside-flag, it is outside the polygon
|
Chris@16
|
230 if (dc.second && dcr.second)
|
Chris@16
|
231 {
|
Chris@16
|
232 dc.second = false;
|
Chris@16
|
233 }
|
Chris@16
|
234 }
|
Chris@16
|
235 return dc;
|
Chris@16
|
236 }
|
Chris@16
|
237 };
|
Chris@16
|
238
|
Chris@16
|
239
|
Chris@16
|
240 // Helper metafunction for default strategy retrieval
|
Chris@16
|
241 template <typename Geometry1, typename Geometry2>
|
Chris@16
|
242 struct default_strategy
|
Chris@16
|
243 : strategy::distance::services::default_strategy
|
Chris@16
|
244 <
|
Chris@16
|
245 point_tag,
|
Chris@16
|
246 typename point_type<Geometry1>::type,
|
Chris@16
|
247 typename point_type<Geometry2>::type
|
Chris@16
|
248 >
|
Chris@16
|
249 {};
|
Chris@16
|
250
|
Chris@16
|
251
|
Chris@16
|
252 }} // namespace detail::distance
|
Chris@16
|
253 #endif // DOXYGEN_NO_DETAIL
|
Chris@16
|
254
|
Chris@16
|
255
|
Chris@16
|
256 #ifndef DOXYGEN_NO_DISPATCH
|
Chris@16
|
257 namespace dispatch
|
Chris@16
|
258 {
|
Chris@16
|
259
|
Chris@16
|
260
|
Chris@16
|
261 using strategy::distance::services::return_type;
|
Chris@16
|
262
|
Chris@16
|
263
|
Chris@16
|
264 template
|
Chris@16
|
265 <
|
Chris@16
|
266 typename Geometry1, typename Geometry2,
|
Chris@16
|
267 typename Strategy = typename detail::distance::default_strategy<Geometry1, Geometry2>::type,
|
Chris@16
|
268 typename Tag1 = typename tag_cast<typename tag<Geometry1>::type, multi_tag>::type,
|
Chris@16
|
269 typename Tag2 = typename tag_cast<typename tag<Geometry2>::type, multi_tag>::type,
|
Chris@16
|
270 typename StrategyTag = typename strategy::distance::services::tag<Strategy>::type,
|
Chris@16
|
271 bool Reverse = reverse_dispatch<Geometry1, Geometry2>::type::value
|
Chris@16
|
272 >
|
Chris@16
|
273 struct distance: not_implemented<Tag1, Tag2>
|
Chris@16
|
274 {};
|
Chris@16
|
275
|
Chris@16
|
276
|
Chris@16
|
277 // If reversal is needed, perform it
|
Chris@16
|
278 template
|
Chris@16
|
279 <
|
Chris@16
|
280 typename Geometry1, typename Geometry2, typename Strategy,
|
Chris@16
|
281 typename Tag1, typename Tag2, typename StrategyTag
|
Chris@16
|
282 >
|
Chris@16
|
283 struct distance
|
Chris@16
|
284 <
|
Chris@16
|
285 Geometry1, Geometry2, Strategy,
|
Chris@16
|
286 Tag1, Tag2, StrategyTag,
|
Chris@16
|
287 true
|
Chris@16
|
288 >
|
Chris@16
|
289 : distance<Geometry2, Geometry1, Strategy, Tag2, Tag1, StrategyTag, false>
|
Chris@16
|
290 {
|
Chris@16
|
291 typedef typename strategy::distance::services::return_type
|
Chris@16
|
292 <
|
Chris@16
|
293 Strategy,
|
Chris@16
|
294 typename point_type<Geometry2>::type,
|
Chris@16
|
295 typename point_type<Geometry1>::type
|
Chris@16
|
296 >::type return_type;
|
Chris@16
|
297
|
Chris@16
|
298 static inline return_type apply(
|
Chris@16
|
299 Geometry1 const& g1,
|
Chris@16
|
300 Geometry2 const& g2,
|
Chris@16
|
301 Strategy const& strategy)
|
Chris@16
|
302 {
|
Chris@16
|
303 return distance
|
Chris@16
|
304 <
|
Chris@16
|
305 Geometry2, Geometry1, Strategy,
|
Chris@16
|
306 Tag2, Tag1, StrategyTag,
|
Chris@16
|
307 false
|
Chris@16
|
308 >::apply(g2, g1, strategy);
|
Chris@16
|
309 }
|
Chris@16
|
310 };
|
Chris@16
|
311
|
Chris@16
|
312
|
Chris@16
|
313 // Point-point
|
Chris@16
|
314 template <typename P1, typename P2, typename Strategy>
|
Chris@16
|
315 struct distance
|
Chris@16
|
316 <
|
Chris@16
|
317 P1, P2, Strategy,
|
Chris@16
|
318 point_tag, point_tag, strategy_tag_distance_point_point,
|
Chris@16
|
319 false
|
Chris@16
|
320 >
|
Chris@16
|
321 : detail::distance::point_to_point<P1, P2, Strategy>
|
Chris@16
|
322 {};
|
Chris@16
|
323
|
Chris@16
|
324
|
Chris@16
|
325 // Point-line version 1, where point-point strategy is specified
|
Chris@16
|
326 template <typename Point, typename Linestring, typename Strategy>
|
Chris@16
|
327 struct distance
|
Chris@16
|
328 <
|
Chris@16
|
329 Point, Linestring, Strategy,
|
Chris@16
|
330 point_tag, linestring_tag, strategy_tag_distance_point_point,
|
Chris@16
|
331 false
|
Chris@16
|
332 >
|
Chris@16
|
333 {
|
Chris@16
|
334
|
Chris@16
|
335 static inline typename return_type<Strategy, Point, typename point_type<Linestring>::type>::type
|
Chris@16
|
336 apply(Point const& point,
|
Chris@16
|
337 Linestring const& linestring,
|
Chris@16
|
338 Strategy const& strategy)
|
Chris@16
|
339 {
|
Chris@16
|
340 typedef typename strategy::distance::services::default_strategy
|
Chris@16
|
341 <
|
Chris@16
|
342 segment_tag,
|
Chris@16
|
343 Point,
|
Chris@16
|
344 typename point_type<Linestring>::type,
|
Chris@16
|
345 typename cs_tag<Point>::type,
|
Chris@16
|
346 typename cs_tag<typename point_type<Linestring>::type>::type,
|
Chris@16
|
347 Strategy
|
Chris@16
|
348 >::type ps_strategy_type;
|
Chris@16
|
349
|
Chris@16
|
350 return detail::distance::point_to_range
|
Chris@16
|
351 <
|
Chris@16
|
352 Point, Linestring, closed, Strategy, ps_strategy_type
|
Chris@16
|
353 >::apply(point, linestring, strategy, ps_strategy_type());
|
Chris@16
|
354 }
|
Chris@16
|
355 };
|
Chris@16
|
356
|
Chris@16
|
357
|
Chris@16
|
358 // Point-line version 2, where point-segment strategy is specified
|
Chris@16
|
359 template <typename Point, typename Linestring, typename Strategy>
|
Chris@16
|
360 struct distance
|
Chris@16
|
361 <
|
Chris@16
|
362 Point, Linestring, Strategy,
|
Chris@16
|
363 point_tag, linestring_tag, strategy_tag_distance_point_segment,
|
Chris@16
|
364 false
|
Chris@16
|
365 >
|
Chris@16
|
366 {
|
Chris@16
|
367 static inline typename return_type<Strategy, Point, typename point_type<Linestring>::type>::type
|
Chris@16
|
368 apply(Point const& point,
|
Chris@16
|
369 Linestring const& linestring,
|
Chris@16
|
370 Strategy const& strategy)
|
Chris@16
|
371 {
|
Chris@16
|
372 typedef typename Strategy::point_strategy_type pp_strategy_type;
|
Chris@16
|
373 return detail::distance::point_to_range
|
Chris@16
|
374 <
|
Chris@16
|
375 Point, Linestring, closed, pp_strategy_type, Strategy
|
Chris@16
|
376 >::apply(point, linestring, pp_strategy_type(), strategy);
|
Chris@16
|
377 }
|
Chris@16
|
378 };
|
Chris@16
|
379
|
Chris@16
|
380 // Point-ring , where point-segment strategy is specified
|
Chris@16
|
381 template <typename Point, typename Ring, typename Strategy>
|
Chris@16
|
382 struct distance
|
Chris@16
|
383 <
|
Chris@16
|
384 Point, Ring, Strategy,
|
Chris@16
|
385 point_tag, ring_tag, strategy_tag_distance_point_point,
|
Chris@16
|
386 false
|
Chris@16
|
387 >
|
Chris@16
|
388 {
|
Chris@16
|
389 typedef typename return_type<Strategy, Point, typename point_type<Ring>::type>::type return_type;
|
Chris@16
|
390
|
Chris@16
|
391 static inline return_type apply(Point const& point,
|
Chris@16
|
392 Ring const& ring,
|
Chris@16
|
393 Strategy const& strategy)
|
Chris@16
|
394 {
|
Chris@16
|
395 typedef typename strategy::distance::services::default_strategy
|
Chris@16
|
396 <
|
Chris@16
|
397 segment_tag,
|
Chris@16
|
398 Point,
|
Chris@16
|
399 typename point_type<Ring>::type
|
Chris@16
|
400 >::type ps_strategy_type;
|
Chris@16
|
401
|
Chris@16
|
402 std::pair<return_type, bool>
|
Chris@16
|
403 dc = detail::distance::point_to_ring
|
Chris@16
|
404 <
|
Chris@16
|
405 Point, Ring,
|
Chris@16
|
406 geometry::closure<Ring>::value,
|
Chris@16
|
407 Strategy, ps_strategy_type
|
Chris@16
|
408 >::apply(point, ring, strategy, ps_strategy_type());
|
Chris@16
|
409
|
Chris@16
|
410 return dc.second ? return_type(0) : dc.first;
|
Chris@16
|
411 }
|
Chris@16
|
412 };
|
Chris@16
|
413
|
Chris@16
|
414
|
Chris@16
|
415 // Point-polygon , where point-segment strategy is specified
|
Chris@16
|
416 template <typename Point, typename Polygon, typename Strategy>
|
Chris@16
|
417 struct distance
|
Chris@16
|
418 <
|
Chris@16
|
419 Point, Polygon, Strategy,
|
Chris@16
|
420 point_tag, polygon_tag, strategy_tag_distance_point_point,
|
Chris@16
|
421 false
|
Chris@16
|
422 >
|
Chris@16
|
423 {
|
Chris@16
|
424 typedef typename return_type<Strategy, Point, typename point_type<Polygon>::type>::type return_type;
|
Chris@16
|
425
|
Chris@16
|
426 static inline return_type apply(Point const& point,
|
Chris@16
|
427 Polygon const& polygon,
|
Chris@16
|
428 Strategy const& strategy)
|
Chris@16
|
429 {
|
Chris@16
|
430 typedef typename strategy::distance::services::default_strategy
|
Chris@16
|
431 <
|
Chris@16
|
432 segment_tag,
|
Chris@16
|
433 Point,
|
Chris@16
|
434 typename point_type<Polygon>::type
|
Chris@16
|
435 >::type ps_strategy_type;
|
Chris@16
|
436
|
Chris@16
|
437 std::pair<return_type, bool>
|
Chris@16
|
438 dc = detail::distance::point_to_polygon
|
Chris@16
|
439 <
|
Chris@16
|
440 Point, Polygon,
|
Chris@16
|
441 geometry::closure<Polygon>::value,
|
Chris@16
|
442 Strategy, ps_strategy_type
|
Chris@16
|
443 >::apply(point, polygon, strategy, ps_strategy_type());
|
Chris@16
|
444
|
Chris@16
|
445 return dc.second ? return_type(0) : dc.first;
|
Chris@16
|
446 }
|
Chris@16
|
447 };
|
Chris@16
|
448
|
Chris@16
|
449
|
Chris@16
|
450
|
Chris@16
|
451 // Point-segment version 1, with point-point strategy
|
Chris@16
|
452 template <typename Point, typename Segment, typename Strategy>
|
Chris@16
|
453 struct distance
|
Chris@16
|
454 <
|
Chris@16
|
455 Point, Segment, Strategy,
|
Chris@16
|
456 point_tag, segment_tag, strategy_tag_distance_point_point,
|
Chris@16
|
457 false
|
Chris@16
|
458 > : detail::distance::point_to_segment<Point, Segment, Strategy>
|
Chris@16
|
459 {};
|
Chris@16
|
460
|
Chris@16
|
461 // Point-segment version 2, with point-segment strategy
|
Chris@16
|
462 template <typename Point, typename Segment, typename Strategy>
|
Chris@16
|
463 struct distance
|
Chris@16
|
464 <
|
Chris@16
|
465 Point, Segment, Strategy,
|
Chris@16
|
466 point_tag, segment_tag, strategy_tag_distance_point_segment,
|
Chris@16
|
467 false
|
Chris@16
|
468 >
|
Chris@16
|
469 {
|
Chris@16
|
470 static inline typename return_type<Strategy, Point, typename point_type<Segment>::type>::type
|
Chris@16
|
471 apply(Point const& point,
|
Chris@16
|
472 Segment const& segment,
|
Chris@16
|
473 Strategy const& strategy)
|
Chris@16
|
474 {
|
Chris@16
|
475
|
Chris@16
|
476 typename point_type<Segment>::type p[2];
|
Chris@16
|
477 geometry::detail::assign_point_from_index<0>(segment, p[0]);
|
Chris@16
|
478 geometry::detail::assign_point_from_index<1>(segment, p[1]);
|
Chris@16
|
479 return strategy.apply(point, p[0], p[1]);
|
Chris@16
|
480 }
|
Chris@16
|
481 };
|
Chris@16
|
482
|
Chris@16
|
483
|
Chris@16
|
484
|
Chris@16
|
485 } // namespace dispatch
|
Chris@16
|
486 #endif // DOXYGEN_NO_DISPATCH
|
Chris@16
|
487
|
Chris@16
|
488 /*!
|
Chris@16
|
489 \brief \brief_calc2{distance} \brief_strategy
|
Chris@16
|
490 \ingroup distance
|
Chris@16
|
491 \details
|
Chris@16
|
492 \details \details_calc{area}. \brief_strategy. \details_strategy_reasons
|
Chris@16
|
493
|
Chris@16
|
494 \tparam Geometry1 \tparam_geometry
|
Chris@16
|
495 \tparam Geometry2 \tparam_geometry
|
Chris@16
|
496 \tparam Strategy \tparam_strategy{Distance}
|
Chris@16
|
497 \param geometry1 \param_geometry
|
Chris@16
|
498 \param geometry2 \param_geometry
|
Chris@16
|
499 \param strategy \param_strategy{distance}
|
Chris@16
|
500 \return \return_calc{distance}
|
Chris@16
|
501 \note The strategy can be a point-point strategy. In case of distance point-line/point-polygon
|
Chris@16
|
502 it may also be a point-segment strategy.
|
Chris@16
|
503
|
Chris@16
|
504 \qbk{distinguish,with strategy}
|
Chris@16
|
505
|
Chris@16
|
506 \qbk{
|
Chris@16
|
507 [heading Available Strategies]
|
Chris@16
|
508 \* [link geometry.reference.strategies.strategy_distance_pythagoras Pythagoras (cartesian)]
|
Chris@16
|
509 \* [link geometry.reference.strategies.strategy_distance_haversine Haversine (spherical)]
|
Chris@16
|
510 \* [link geometry.reference.strategies.strategy_distance_cross_track Cross track (spherical\, point-to-segment)]
|
Chris@16
|
511 \* [link geometry.reference.strategies.strategy_distance_projected_point Projected point (cartesian\, point-to-segment)]
|
Chris@16
|
512 \* more (currently extensions): Vincenty\, Andoyer (geographic)
|
Chris@16
|
513 }
|
Chris@16
|
514 */
|
Chris@16
|
515
|
Chris@16
|
516 /*
|
Chris@16
|
517 Note, in case of a Compilation Error:
|
Chris@16
|
518 if you get:
|
Chris@16
|
519 - "Failed to specialize function template ..."
|
Chris@16
|
520 - "error: no matching function for call to ..."
|
Chris@16
|
521 for distance, it is probably so that there is no specialization
|
Chris@16
|
522 for return_type<...> for your strategy.
|
Chris@16
|
523 */
|
Chris@16
|
524 template <typename Geometry1, typename Geometry2, typename Strategy>
|
Chris@16
|
525 inline typename strategy::distance::services::return_type
|
Chris@16
|
526 <
|
Chris@16
|
527 Strategy,
|
Chris@16
|
528 typename point_type<Geometry1>::type,
|
Chris@16
|
529 typename point_type<Geometry2>::type
|
Chris@16
|
530 >::type
|
Chris@16
|
531 distance(Geometry1 const& geometry1,
|
Chris@16
|
532 Geometry2 const& geometry2,
|
Chris@16
|
533 Strategy const& strategy)
|
Chris@16
|
534 {
|
Chris@16
|
535 concept::check<Geometry1 const>();
|
Chris@16
|
536 concept::check<Geometry2 const>();
|
Chris@16
|
537
|
Chris@16
|
538 detail::throw_on_empty_input(geometry1);
|
Chris@16
|
539 detail::throw_on_empty_input(geometry2);
|
Chris@16
|
540
|
Chris@16
|
541 return dispatch::distance
|
Chris@16
|
542 <
|
Chris@16
|
543 Geometry1,
|
Chris@16
|
544 Geometry2,
|
Chris@16
|
545 Strategy
|
Chris@16
|
546 >::apply(geometry1, geometry2, strategy);
|
Chris@16
|
547 }
|
Chris@16
|
548
|
Chris@16
|
549
|
Chris@16
|
550 /*!
|
Chris@16
|
551 \brief \brief_calc2{distance}
|
Chris@16
|
552 \ingroup distance
|
Chris@16
|
553 \details The default strategy is used, corresponding to the coordinate system of the geometries
|
Chris@16
|
554 \tparam Geometry1 \tparam_geometry
|
Chris@16
|
555 \tparam Geometry2 \tparam_geometry
|
Chris@16
|
556 \param geometry1 \param_geometry
|
Chris@16
|
557 \param geometry2 \param_geometry
|
Chris@16
|
558 \return \return_calc{distance}
|
Chris@16
|
559
|
Chris@16
|
560 \qbk{[include reference/algorithms/distance.qbk]}
|
Chris@16
|
561 */
|
Chris@16
|
562 template <typename Geometry1, typename Geometry2>
|
Chris@16
|
563 inline typename default_distance_result<Geometry1, Geometry2>::type distance(
|
Chris@16
|
564 Geometry1 const& geometry1, Geometry2 const& geometry2)
|
Chris@16
|
565 {
|
Chris@16
|
566 concept::check<Geometry1 const>();
|
Chris@16
|
567 concept::check<Geometry2 const>();
|
Chris@16
|
568
|
Chris@16
|
569 return distance(geometry1, geometry2,
|
Chris@16
|
570 typename detail::distance::default_strategy<Geometry1, Geometry2>::type());
|
Chris@16
|
571 }
|
Chris@16
|
572
|
Chris@16
|
573 }} // namespace boost::geometry
|
Chris@16
|
574
|
Chris@16
|
575 #endif // BOOST_GEOMETRY_ALGORITHMS_DISTANCE_HPP
|