File indexing completed on 2025-01-18 09:35:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_DISTANCE_PREDICATES_HPP
0018 #define BOOST_GEOMETRY_INDEX_DETAIL_DISTANCE_PREDICATES_HPP
0019
0020 #include <boost/geometry/core/static_assert.hpp>
0021
0022 #include <boost/geometry/algorithms/detail/covered_by/interface.hpp>
0023 #include <boost/geometry/algorithms/detail/disjoint/interface.hpp>
0024 #include <boost/geometry/algorithms/detail/intersects/interface.hpp>
0025 #include <boost/geometry/algorithms/detail/overlaps/interface.hpp>
0026 #include <boost/geometry/algorithms/detail/touches/interface.hpp>
0027 #include <boost/geometry/algorithms/detail/within/interface.hpp>
0028
0029 #include <boost/geometry/index/detail/algorithms/comparable_distance_near.hpp>
0030 #include <boost/geometry/index/detail/algorithms/comparable_distance_far.hpp>
0031 #include <boost/geometry/index/detail/algorithms/comparable_distance_centroid.hpp>
0032 #include <boost/geometry/index/detail/algorithms/path_intersection.hpp>
0033 #include <boost/geometry/index/detail/predicates.hpp>
0034 #include <boost/geometry/index/detail/tags.hpp>
0035
0036 namespace boost { namespace geometry { namespace index { namespace detail {
0037
0038
0039
0040
0041
0042 template <typename T>
0043 struct to_nearest
0044 {
0045 to_nearest(T const& v) : value(v) {}
0046 T value;
0047 };
0048
0049 template <typename T>
0050 struct to_centroid
0051 {
0052 to_centroid(T const& v) : value(v) {}
0053 T value;
0054 };
0055
0056 template <typename T>
0057 struct to_furthest
0058 {
0059 to_furthest(T const& v) : value(v) {}
0060 T value;
0061 };
0062
0063
0064
0065 struct to_nearest_tag {};
0066 struct to_centroid_tag {};
0067 struct to_furthest_tag {};
0068
0069
0070
0071
0072
0073 template <typename T>
0074 struct relation
0075 {
0076 typedef T value_type;
0077 typedef to_nearest_tag tag;
0078 static inline T const& value(T const& v) { return v; }
0079 static inline T & value(T & v) { return v; }
0080 };
0081
0082 template <typename T>
0083 struct relation< to_nearest<T> >
0084 {
0085 typedef T value_type;
0086 typedef to_nearest_tag tag;
0087 static inline T const& value(to_nearest<T> const& r) { return r.value; }
0088 static inline T & value(to_nearest<T> & r) { return r.value; }
0089 };
0090
0091 template <typename T>
0092 struct relation< to_centroid<T> >
0093 {
0094 typedef T value_type;
0095 typedef to_centroid_tag tag;
0096 static inline T const& value(to_centroid<T> const& r) { return r.value; }
0097 static inline T & value(to_centroid<T> & r) { return r.value; }
0098 };
0099
0100 template <typename T>
0101 struct relation< to_furthest<T> >
0102 {
0103 typedef T value_type;
0104 typedef to_furthest_tag tag;
0105 static inline T const& value(to_furthest<T> const& r) { return r.value; }
0106 static inline T & value(to_furthest<T> & r) { return r.value; }
0107 };
0108
0109
0110
0111 template
0112 <
0113 typename G1, typename G2, typename Strategy
0114 >
0115 struct comparable_distance_call
0116 {
0117 typedef typename geometry::comparable_distance_result
0118 <
0119 G1, G2, Strategy
0120 >::type result_type;
0121
0122 static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const& s)
0123 {
0124 return geometry::comparable_distance(g1, g2, s);
0125 }
0126 };
0127
0128 template
0129 <
0130 typename G1, typename G2
0131 >
0132 struct comparable_distance_call<G1, G2, default_strategy>
0133 {
0134 typedef typename geometry::default_comparable_distance_result
0135 <
0136 G1, G2
0137 >::type result_type;
0138
0139 static inline result_type apply(G1 const& g1, G2 const& g2, default_strategy const&)
0140 {
0141 return geometry::comparable_distance(g1, g2);
0142 }
0143 };
0144
0145
0146
0147
0148
0149 template <typename Predicate, typename Indexable, typename Strategy, typename Tag>
0150 struct calculate_distance
0151 {
0152 BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
0153 "Invalid Predicate or Tag.",
0154 Predicate, Indexable, Strategy, Tag);
0155 };
0156
0157
0158 template <typename PointRelation, typename Indexable, typename Strategy, typename Tag>
0159 struct calculate_distance< predicates::nearest<PointRelation>, Indexable, Strategy, Tag>
0160 {
0161 typedef detail::relation<PointRelation> relation;
0162 typedef comparable_distance_call
0163 <
0164 typename relation::value_type,
0165 Indexable,
0166 Strategy
0167 > call_type;
0168 typedef typename call_type::result_type result_type;
0169
0170 static inline bool apply(predicates::nearest<PointRelation> const& p, Indexable const& i,
0171 Strategy const& s, result_type & result)
0172 {
0173 result = call_type::apply(relation::value(p.point_or_relation), i, s);
0174 return true;
0175 }
0176 };
0177
0178 template <typename Point, typename Indexable, typename Strategy>
0179 struct calculate_distance< predicates::nearest< to_centroid<Point> >, Indexable, Strategy, value_tag>
0180 {
0181 typedef Point point_type;
0182 typedef typename geometry::default_comparable_distance_result
0183 <
0184 point_type, Indexable
0185 >::type result_type;
0186
0187 static inline bool apply(predicates::nearest< to_centroid<Point> > const& p, Indexable const& i,
0188 Strategy const& , result_type & result)
0189 {
0190 result = index::detail::comparable_distance_centroid(p.point_or_relation.value, i);
0191 return true;
0192 }
0193 };
0194
0195 template <typename Point, typename Indexable, typename Strategy>
0196 struct calculate_distance< predicates::nearest< to_furthest<Point> >, Indexable, Strategy, value_tag>
0197 {
0198 typedef Point point_type;
0199 typedef typename geometry::default_comparable_distance_result
0200 <
0201 point_type, Indexable
0202 >::type result_type;
0203
0204 static inline bool apply(predicates::nearest< to_furthest<Point> > const& p, Indexable const& i,
0205 Strategy const& , result_type & result)
0206 {
0207 result = index::detail::comparable_distance_far(p.point_or_relation.value, i);
0208 return true;
0209 }
0210 };
0211
0212 template <typename SegmentOrLinestring, typename Indexable, typename Strategy, typename Tag>
0213 struct calculate_distance< predicates::path<SegmentOrLinestring>, Indexable, Strategy, Tag>
0214 {
0215 typedef typename index::detail::default_path_intersection_distance_type<
0216 Indexable, SegmentOrLinestring
0217 >::type result_type;
0218
0219 static inline bool apply(predicates::path<SegmentOrLinestring> const& p, Indexable const& i,
0220 Strategy const& , result_type & result)
0221 {
0222 return index::detail::path_intersection(i, p.geometry, result);
0223 }
0224 };
0225
0226 }}}}
0227
0228 #endif