]>
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 | // | |
8 | // Use, modification and distribution is subject to the Boost Software License, | |
9 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
10 | // http://www.boost.org/LICENSE_1_0.txt) | |
11 | ||
12 | #ifndef BOOST_GEOMETRY_INDEX_DETAIL_DISTANCE_PREDICATES_HPP | |
13 | #define BOOST_GEOMETRY_INDEX_DETAIL_DISTANCE_PREDICATES_HPP | |
14 | ||
15 | #include <boost/geometry/index/detail/algorithms/comparable_distance_near.hpp> | |
16 | #include <boost/geometry/index/detail/algorithms/comparable_distance_far.hpp> | |
17 | #include <boost/geometry/index/detail/algorithms/comparable_distance_centroid.hpp> | |
18 | #include <boost/geometry/index/detail/algorithms/path_intersection.hpp> | |
19 | ||
20 | #include <boost/geometry/index/detail/tags.hpp> | |
21 | ||
22 | namespace boost { namespace geometry { namespace index { namespace detail { | |
23 | ||
24 | // ------------------------------------------------------------------ // | |
25 | // relations | |
26 | // ------------------------------------------------------------------ // | |
27 | ||
28 | template <typename T> | |
29 | struct to_nearest | |
30 | { | |
31 | to_nearest(T const& v) : value(v) {} | |
32 | T value; | |
33 | }; | |
34 | ||
35 | template <typename T> | |
36 | struct to_centroid | |
37 | { | |
38 | to_centroid(T const& v) : value(v) {} | |
39 | T value; | |
40 | }; | |
41 | ||
42 | template <typename T> | |
43 | struct to_furthest | |
44 | { | |
45 | to_furthest(T const& v) : value(v) {} | |
46 | T value; | |
47 | }; | |
48 | ||
49 | // tags | |
50 | ||
51 | struct to_nearest_tag {}; | |
52 | struct to_centroid_tag {}; | |
53 | struct to_furthest_tag {}; | |
54 | ||
55 | // ------------------------------------------------------------------ // | |
56 | // relation traits and access | |
57 | // ------------------------------------------------------------------ // | |
58 | ||
59 | template <typename T> | |
60 | struct relation | |
61 | { | |
62 | typedef T value_type; | |
63 | typedef to_nearest_tag tag; | |
64 | static inline T const& value(T const& v) { return v; } | |
65 | static inline T & value(T & v) { return v; } | |
66 | }; | |
67 | ||
68 | template <typename T> | |
69 | struct relation< to_nearest<T> > | |
70 | { | |
71 | typedef T value_type; | |
72 | typedef to_nearest_tag tag; | |
73 | static inline T const& value(to_nearest<T> const& r) { return r.value; } | |
74 | static inline T & value(to_nearest<T> & r) { return r.value; } | |
75 | }; | |
76 | ||
77 | template <typename T> | |
78 | struct relation< to_centroid<T> > | |
79 | { | |
80 | typedef T value_type; | |
81 | typedef to_centroid_tag tag; | |
82 | static inline T const& value(to_centroid<T> const& r) { return r.value; } | |
83 | static inline T & value(to_centroid<T> & r) { return r.value; } | |
84 | }; | |
85 | ||
86 | template <typename T> | |
87 | struct relation< to_furthest<T> > | |
88 | { | |
89 | typedef T value_type; | |
90 | typedef to_furthest_tag tag; | |
91 | static inline T const& value(to_furthest<T> const& r) { return r.value; } | |
92 | static inline T & value(to_furthest<T> & r) { return r.value; } | |
93 | }; | |
94 | ||
95 | // ------------------------------------------------------------------ // | |
96 | // calculate_distance | |
97 | // ------------------------------------------------------------------ // | |
98 | ||
99 | template <typename Predicate, typename Indexable, typename Tag> | |
100 | struct calculate_distance | |
101 | { | |
102 | BOOST_MPL_ASSERT_MSG((false), INVALID_PREDICATE_OR_TAG, (calculate_distance)); | |
103 | }; | |
104 | ||
105 | // this handles nearest() with default Point parameter, to_nearest() and bounds | |
106 | template <typename PointRelation, typename Indexable, typename Tag> | |
107 | struct calculate_distance< predicates::nearest<PointRelation>, Indexable, Tag > | |
108 | { | |
109 | typedef detail::relation<PointRelation> relation; | |
110 | typedef typename relation::value_type point_type; | |
111 | typedef typename geometry::default_comparable_distance_result<point_type, Indexable>::type result_type; | |
112 | ||
113 | static inline bool apply(predicates::nearest<PointRelation> const& p, Indexable const& i, result_type & result) | |
114 | { | |
115 | result = geometry::comparable_distance(relation::value(p.point_or_relation), i); | |
116 | return true; | |
117 | } | |
118 | }; | |
119 | ||
120 | template <typename Point, typename Indexable> | |
121 | struct calculate_distance< predicates::nearest< to_centroid<Point> >, Indexable, value_tag> | |
122 | { | |
123 | typedef Point point_type; | |
124 | typedef typename geometry::default_comparable_distance_result<point_type, Indexable>::type result_type; | |
125 | ||
126 | static inline bool apply(predicates::nearest< to_centroid<Point> > const& p, Indexable const& i, result_type & result) | |
127 | { | |
128 | result = index::detail::comparable_distance_centroid(p.point_or_relation.value, i); | |
129 | return true; | |
130 | } | |
131 | }; | |
132 | ||
133 | template <typename Point, typename Indexable> | |
134 | struct calculate_distance< predicates::nearest< to_furthest<Point> >, Indexable, value_tag> | |
135 | { | |
136 | typedef Point point_type; | |
137 | typedef typename geometry::default_comparable_distance_result<point_type, Indexable>::type result_type; | |
138 | ||
139 | static inline bool apply(predicates::nearest< to_furthest<Point> > const& p, Indexable const& i, result_type & result) | |
140 | { | |
141 | result = index::detail::comparable_distance_far(p.point_or_relation.value, i); | |
142 | return true; | |
143 | } | |
144 | }; | |
145 | ||
146 | template <typename SegmentOrLinestring, typename Indexable, typename Tag> | |
147 | struct calculate_distance< predicates::path<SegmentOrLinestring>, Indexable, Tag> | |
148 | { | |
149 | typedef typename index::detail::default_path_intersection_distance_type< | |
150 | Indexable, SegmentOrLinestring | |
151 | >::type result_type; | |
152 | ||
153 | static inline bool apply(predicates::path<SegmentOrLinestring> const& p, Indexable const& i, result_type & result) | |
154 | { | |
155 | return index::detail::path_intersection(i, p.geometry, result); | |
156 | } | |
157 | }; | |
158 | ||
159 | }}}} // namespace boost::geometry::index::detail | |
160 | ||
161 | #endif // BOOST_GEOMETRY_INDEX_RTREE_DISTANCE_PREDICATES_HPP |