]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/algorithms/detail/closest_points/multipoint_to_geometry.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / detail / closest_points / multipoint_to_geometry.hpp
1 // Boost.Geometry
2
3 // Copyright (c) 2021, Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Vissarion Fysikopoulos, 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_CLOSEST_POINTS_MULTIPOINT_TO_GEOMETRY_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_POINTS_MULTIPOINT_TO_GEOMETRY_HPP
12
13 #include <iterator>
14
15 #include <boost/geometry/algorithms/covered_by.hpp>
16 #include <boost/geometry/algorithms/detail/closest_points/range_to_geometry_rtree.hpp>
17 #include <boost/geometry/algorithms/detail/closest_points/utilities.hpp>
18 #include <boost/geometry/algorithms/dispatch/closest_points.hpp>
19
20 #include <boost/geometry/core/point_type.hpp>
21 #include <boost/geometry/core/tags.hpp>
22
23 #include <boost/geometry/geometries/linestring.hpp>
24
25
26 namespace boost { namespace geometry
27 {
28
29 #ifndef DOXYGEN_NO_DETAIL
30 namespace detail { namespace closest_points
31 {
32
33
34 struct multipoint_to_multipoint
35 {
36 template
37 <
38 typename MultiPoint1,
39 typename MultiPoint2,
40 typename Segment,
41 typename Strategies
42 >
43 static inline void apply(MultiPoint1 const& multipoint1,
44 MultiPoint2 const& multipoint2,
45 Segment& shortest_seg,
46 Strategies const& strategies)
47 {
48 if (boost::size(multipoint1) < boost::size(multipoint2))
49 {
50 point_or_segment_range_to_geometry_rtree::apply(
51 boost::begin(multipoint2),
52 boost::end(multipoint2),
53 multipoint1,
54 shortest_seg,
55 strategies);
56 detail::closest_points::swap_segment_points::apply(shortest_seg);
57 return;
58 }
59 point_or_segment_range_to_geometry_rtree::apply(
60 boost::begin(multipoint1),
61 boost::end(multipoint1),
62 multipoint2,
63 shortest_seg,
64 strategies);
65 }
66 };
67
68 struct multipoint_to_linear
69 {
70 template
71 <
72 typename MultiPoint,
73 typename Linear,
74 typename Segment,
75 typename Strategies
76 >
77 static inline void apply(MultiPoint const& multipoint,
78 Linear const& linear,
79 Segment& shortest_seg,
80 Strategies const& strategies)
81 {
82 point_or_segment_range_to_geometry_rtree::apply(
83 boost::begin(multipoint),
84 boost::end(multipoint),
85 linear,
86 shortest_seg,
87 strategies);
88 }
89 };
90
91 struct linear_to_multipoint
92 {
93 template
94 <
95 typename Linear,
96 typename MultiPoint,
97 typename Segment,
98 typename Strategies
99 >
100 static inline void apply(Linear const& linear,
101 MultiPoint const& multipoint,
102 Segment& shortest_seg,
103 Strategies const& strategies)
104 {
105 multipoint_to_linear::apply(multipoint, linear, shortest_seg, strategies);
106 detail::closest_points::swap_segment_points::apply(shortest_seg);
107 }
108 };
109
110 struct segment_to_multipoint
111 {
112 template
113 <
114 typename Segment,
115 typename MultiPoint,
116 typename OutSegment,
117 typename Strategies
118 >
119 static inline void apply(Segment const& segment,
120 MultiPoint const& multipoint,
121 OutSegment& shortest_seg,
122 Strategies const& strategies)
123 {
124 using linestring_type = geometry::model::linestring
125 <
126 typename point_type<Segment>::type
127 >;
128 linestring_type linestring;
129 convert(segment, linestring);
130 multipoint_to_linear::apply(multipoint, linestring, shortest_seg, strategies);
131 detail::closest_points::swap_segment_points::apply(shortest_seg);
132 }
133 };
134
135 struct multipoint_to_segment
136 {
137 template
138 <
139 typename MultiPoint,
140 typename Segment,
141 typename OutSegment,
142 typename Strategies
143 >
144 static inline void apply(MultiPoint const& multipoint,
145 Segment const& segment,
146 OutSegment& shortest_seg,
147 Strategies const& strategies)
148 {
149 using linestring_type = geometry::model::linestring
150 <
151 typename point_type<Segment>::type
152 >;
153 linestring_type linestring;
154 convert(segment, linestring);
155 multipoint_to_linear::apply(multipoint, linestring, shortest_seg,
156 strategies);
157 }
158 };
159
160
161 struct multipoint_to_areal
162 {
163
164 private:
165
166 template <typename Areal, typename Strategies>
167 struct covered_by_areal
168 {
169 covered_by_areal(Areal const& areal, Strategies const& strategy)
170 : m_areal(areal), m_strategy(strategy)
171 {}
172
173 template <typename Point>
174 inline bool operator()(Point const& point) const
175 {
176 return geometry::covered_by(point, m_areal, m_strategy);
177 }
178
179 Areal const& m_areal;
180 Strategies const& m_strategy;
181 };
182
183 public:
184
185 template
186 <
187 typename MultiPoint,
188 typename Areal,
189 typename Segment,
190 typename Strategies
191 >
192 static inline void apply(MultiPoint const& multipoint,
193 Areal const& areal,
194 Segment& shortest_seg,
195 Strategies const& strategies)
196 {
197 covered_by_areal<Areal, Strategies> predicate(areal, strategies);
198
199 auto it = std::find_if(
200 boost::begin(multipoint),
201 boost::end(multipoint),
202 predicate);
203
204 if (it != boost::end(multipoint))
205 {
206 return set_segment_from_points::apply(*it, *it, shortest_seg);
207
208 }
209
210 point_or_segment_range_to_geometry_rtree::apply(
211 boost::begin(multipoint),
212 boost::end(multipoint),
213 areal,
214 shortest_seg,
215 strategies);
216 }
217 };
218
219 struct areal_to_multipoint
220 {
221 template
222 <
223 typename Areal,
224 typename MultiPoint,
225 typename Segment,
226 typename Strategies
227 >
228 static inline void apply(Areal const& areal,
229 MultiPoint const& multipoint,
230 Segment& shortest_seg,
231 Strategies const& strategies)
232 {
233 multipoint_to_areal::apply(multipoint, areal, shortest_seg, strategies);
234 detail::closest_points::swap_segment_points::apply(shortest_seg);
235 }
236 };
237
238 }} // namespace detail::closest_points
239 #endif // DOXYGEN_NO_DETAIL
240
241
242
243 #ifndef DOXYGEN_NO_DISPATCH
244 namespace dispatch
245 {
246
247
248 template <typename MultiPoint1, typename MultiPoint2>
249 struct closest_points
250 <
251 MultiPoint1, MultiPoint2,
252 multi_point_tag, multi_point_tag,
253 false
254 > : detail::closest_points::multipoint_to_multipoint
255 {};
256
257
258 template <typename MultiPoint, typename Linear>
259 struct closest_points
260 <
261 MultiPoint, Linear,
262 multi_point_tag, linear_tag,
263 false
264 > : detail::closest_points::multipoint_to_linear
265 {};
266
267
268 template <typename Linear, typename MultiPoint>
269 struct closest_points
270 <
271 Linear, MultiPoint,
272 linear_tag, multi_point_tag,
273 false
274 > : detail::closest_points::linear_to_multipoint
275 {};
276
277
278 template <typename MultiPoint, typename Segment>
279 struct closest_points
280 <
281 MultiPoint, Segment,
282 multi_point_tag, segment_tag,
283 false
284 > : detail::closest_points::multipoint_to_segment
285 {};
286
287
288 template <typename Segment, typename MultiPoint>
289 struct closest_points
290 <
291 Segment, MultiPoint,
292 segment_tag, multi_point_tag,
293 false
294 > : detail::closest_points::segment_to_multipoint
295 {};
296
297
298 template <typename MultiPoint, typename Areal>
299 struct closest_points
300 <
301 MultiPoint, Areal,
302 multi_point_tag, areal_tag,
303 false
304 > : detail::closest_points::multipoint_to_areal
305 {};
306
307
308 template <typename Areal, typename MultiPoint>
309 struct closest_points
310 <
311 Areal, MultiPoint,
312 areal_tag, multi_point_tag,
313 false
314 > : detail::closest_points::areal_to_multipoint
315 {};
316
317
318 } // namespace dispatch
319 #endif // DOXYGEN_NO_DISPATCH
320
321
322 }} // namespace boost::geometry
323
324
325 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_POINTS_MULTIPOINT_TO_GEOMETRY_HPP