]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/algorithms/detail/distance/multipoint_to_geometry.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / detail / distance / multipoint_to_geometry.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2014, Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
6
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
9
10 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_MULTIPOINT_TO_GEOMETRY_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_MULTIPOINT_TO_GEOMETRY_HPP
12
13 #include <boost/range.hpp>
14
15 #include <boost/geometry/core/point_type.hpp>
16 #include <boost/geometry/core/tags.hpp>
17
18 #include <boost/geometry/strategies/distance.hpp>
19 #include <boost/geometry/strategies/tags.hpp>
20
21 #include <boost/geometry/algorithms/covered_by.hpp>
22
23 #include <boost/geometry/algorithms/dispatch/distance.hpp>
24
25 #include <boost/geometry/algorithms/detail/check_iterator_range.hpp>
26 #include <boost/geometry/algorithms/detail/distance/range_to_geometry_rtree.hpp>
27
28
29 namespace boost { namespace geometry
30 {
31
32 #ifndef DOXYGEN_NO_DETAIL
33 namespace detail { namespace distance
34 {
35
36
37 template <typename MultiPoint1, typename MultiPoint2, typename Strategy>
38 struct multipoint_to_multipoint
39 {
40 typedef typename strategy::distance::services::return_type
41 <
42 Strategy,
43 typename point_type<MultiPoint1>::type,
44 typename point_type<MultiPoint2>::type
45 >::type return_type;
46
47 static inline return_type apply(MultiPoint1 const& multipoint1,
48 MultiPoint2 const& multipoint2,
49 Strategy const& strategy)
50 {
51 if (boost::size(multipoint2) < boost::size(multipoint1))
52
53 {
54 return point_or_segment_range_to_geometry_rtree
55 <
56 typename boost::range_iterator<MultiPoint2 const>::type,
57 MultiPoint1,
58 Strategy
59 >::apply(boost::begin(multipoint2),
60 boost::end(multipoint2),
61 multipoint1,
62 strategy);
63 }
64
65 return point_or_segment_range_to_geometry_rtree
66 <
67 typename boost::range_iterator<MultiPoint1 const>::type,
68 MultiPoint2,
69 Strategy
70 >::apply(boost::begin(multipoint1),
71 boost::end(multipoint1),
72 multipoint2,
73 strategy);
74 }
75 };
76
77
78 template <typename MultiPoint, typename Linear, typename Strategy>
79 struct multipoint_to_linear
80 {
81 typedef typename strategy::distance::services::return_type
82 <
83 Strategy,
84 typename point_type<MultiPoint>::type,
85 typename point_type<Linear>::type
86 >::type return_type;
87
88 static inline return_type apply(MultiPoint const& multipoint,
89 Linear const& linear,
90 Strategy const& strategy)
91 {
92 return detail::distance::point_or_segment_range_to_geometry_rtree
93 <
94 typename boost::range_iterator<MultiPoint const>::type,
95 Linear,
96 Strategy
97 >::apply(boost::begin(multipoint),
98 boost::end(multipoint),
99 linear,
100 strategy);
101 }
102
103 static inline return_type apply(Linear const& linear,
104 MultiPoint const& multipoint,
105 Strategy const& strategy)
106 {
107 return apply(multipoint, linear, strategy);
108 }
109 };
110
111
112 template <typename MultiPoint, typename Areal, typename Strategy>
113 class multipoint_to_areal
114 {
115 private:
116 struct not_covered_by_areal
117 {
118 not_covered_by_areal(Areal const& areal)
119 : m_areal(areal)
120 {}
121
122 template <typename Point>
123 inline bool apply(Point const& point) const
124 {
125 return !geometry::covered_by(point, m_areal);
126 }
127
128 Areal const& m_areal;
129 };
130
131 public:
132 typedef typename strategy::distance::services::return_type
133 <
134 Strategy,
135 typename point_type<MultiPoint>::type,
136 typename point_type<Areal>::type
137 >::type return_type;
138
139 static inline return_type apply(MultiPoint const& multipoint,
140 Areal const& areal,
141 Strategy const& strategy)
142 {
143 not_covered_by_areal predicate(areal);
144
145 if (check_iterator_range
146 <
147 not_covered_by_areal, false
148 >::apply(boost::begin(multipoint),
149 boost::end(multipoint),
150 predicate))
151 {
152 return detail::distance::point_or_segment_range_to_geometry_rtree
153 <
154 typename boost::range_iterator<MultiPoint const>::type,
155 Areal,
156 Strategy
157 >::apply(boost::begin(multipoint),
158 boost::end(multipoint),
159 areal,
160 strategy);
161 }
162 return 0;
163 }
164
165 static inline return_type apply(Areal const& areal,
166 MultiPoint const& multipoint,
167 Strategy const& strategy)
168 {
169 return apply(multipoint, areal, strategy);
170 }
171 };
172
173
174 }} // namespace detail::distance
175 #endif // DOXYGEN_NO_DETAIL
176
177
178
179 #ifndef DOXYGEN_NO_DISPATCH
180 namespace dispatch
181 {
182
183
184 template <typename MultiPoint1, typename MultiPoint2, typename Strategy>
185 struct distance
186 <
187 MultiPoint1, MultiPoint2, Strategy,
188 multi_point_tag, multi_point_tag,
189 strategy_tag_distance_point_point, false
190 > : detail::distance::multipoint_to_multipoint
191 <
192 MultiPoint1, MultiPoint2, Strategy
193 >
194 {};
195
196 template <typename MultiPoint, typename Linear, typename Strategy>
197 struct distance
198 <
199 MultiPoint, Linear, Strategy, multi_point_tag, linear_tag,
200 strategy_tag_distance_point_segment, false
201 > : detail::distance::multipoint_to_linear<MultiPoint, Linear, Strategy>
202 {};
203
204
205 template <typename Linear, typename MultiPoint, typename Strategy>
206 struct distance
207 <
208 Linear, MultiPoint, Strategy, linear_tag, multi_point_tag,
209 strategy_tag_distance_point_segment, false
210 > : detail::distance::multipoint_to_linear<MultiPoint, Linear, Strategy>
211 {};
212
213
214 template <typename MultiPoint, typename Areal, typename Strategy>
215 struct distance
216 <
217 MultiPoint, Areal, Strategy, multi_point_tag, areal_tag,
218 strategy_tag_distance_point_segment, false
219 > : detail::distance::multipoint_to_areal<MultiPoint, Areal, Strategy>
220 {};
221
222
223 template <typename Areal, typename MultiPoint, typename Strategy>
224 struct distance
225 <
226 Areal, MultiPoint, Strategy, areal_tag, multi_point_tag,
227 strategy_tag_distance_point_segment, false
228 > : detail::distance::multipoint_to_areal<MultiPoint, Areal, Strategy>
229 {};
230
231
232 } // namespace dispatch
233 #endif // DOXYGEN_NO_DISPATCH
234
235
236 }} // namespace boost::geometry
237
238
239 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_MULTIPOINT_TO_GEOMETRY_HPP