annotate DEPENDENCIES/generic/include/boost/geometry/index/detail/distance_predicates.hpp @ 133:4acb5d8d80b6 tip

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