1 // Boost.Geometry Index
3 // Spatial index distance predicates, calculators and checkers
4 // used in nearest query - specialized for envelopes
6 // Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland.
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)
12 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_DISTANCE_PREDICATES_HPP
13 #define BOOST_GEOMETRY_INDEX_DETAIL_DISTANCE_PREDICATES_HPP
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>
20 #include <boost/geometry/index/detail/tags.hpp>
22 namespace boost { namespace geometry { namespace index { namespace detail {
24 // ------------------------------------------------------------------ //
26 // ------------------------------------------------------------------ //
31 to_nearest(T const& v) : value(v) {}
38 to_centroid(T const& v) : value(v) {}
45 to_furthest(T const& v) : value(v) {}
51 struct to_nearest_tag {};
52 struct to_centroid_tag {};
53 struct to_furthest_tag {};
55 // ------------------------------------------------------------------ //
56 // relation traits and access
57 // ------------------------------------------------------------------ //
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; }
69 struct relation< to_nearest<T> >
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; }
78 struct relation< to_centroid<T> >
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; }
87 struct relation< to_furthest<T> >
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; }
95 // ------------------------------------------------------------------ //
97 // ------------------------------------------------------------------ //
99 template <typename Predicate, typename Indexable, typename Tag>
100 struct calculate_distance
102 BOOST_MPL_ASSERT_MSG((false), INVALID_PREDICATE_OR_TAG, (calculate_distance));
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 >
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;
113 static inline bool apply(predicates::nearest<PointRelation> const& p, Indexable const& i, result_type & result)
115 result = geometry::comparable_distance(relation::value(p.point_or_relation), i);
120 template <typename Point, typename Indexable>
121 struct calculate_distance< predicates::nearest< to_centroid<Point> >, Indexable, value_tag>
123 typedef Point point_type;
124 typedef typename geometry::default_comparable_distance_result<point_type, Indexable>::type result_type;
126 static inline bool apply(predicates::nearest< to_centroid<Point> > const& p, Indexable const& i, result_type & result)
128 result = index::detail::comparable_distance_centroid(p.point_or_relation.value, i);
133 template <typename Point, typename Indexable>
134 struct calculate_distance< predicates::nearest< to_furthest<Point> >, Indexable, value_tag>
136 typedef Point point_type;
137 typedef typename geometry::default_comparable_distance_result<point_type, Indexable>::type result_type;
139 static inline bool apply(predicates::nearest< to_furthest<Point> > const& p, Indexable const& i, result_type & result)
141 result = index::detail::comparable_distance_far(p.point_or_relation.value, i);
146 template <typename SegmentOrLinestring, typename Indexable, typename Tag>
147 struct calculate_distance< predicates::path<SegmentOrLinestring>, Indexable, Tag>
149 typedef typename index::detail::default_path_intersection_distance_type<
150 Indexable, SegmentOrLinestring
153 static inline bool apply(predicates::path<SegmentOrLinestring> const& p, Indexable const& i, result_type & result)
155 return index::detail::path_intersection(i, p.geometry, result);
159 }}}} // namespace boost::geometry::index::detail
161 #endif // BOOST_GEOMETRY_INDEX_RTREE_DISTANCE_PREDICATES_HPP