]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/algorithms/detail/intersection/interface.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / detail / intersection / interface.hpp
CommitLineData
b32b8144
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2
3// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4
1e59de90
TL
5// This file was modified by Oracle on 2014-2020.
6// Modifications copyright (c) 2014-2020, Oracle and/or its affiliates.
b32b8144
FG
7// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8
9// Use, modification and distribution is subject to the Boost Software License,
10// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11// http://www.boost.org/LICENSE_1_0.txt)
12
13#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP
14#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP
15
16
17#include <boost/variant/apply_visitor.hpp>
18#include <boost/variant/static_visitor.hpp>
19#include <boost/variant/variant_fwd.hpp>
20
21#include <boost/geometry/algorithms/detail/overlay/intersection_insert.hpp>
f67539c2 22#include <boost/geometry/algorithms/detail/tupled_output.hpp>
b32b8144
FG
23#include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
24#include <boost/geometry/strategies/default_strategy.hpp>
1e59de90
TL
25#include <boost/geometry/strategies/detail.hpp>
26#include <boost/geometry/strategies/relate/services.hpp>
b32b8144
FG
27#include <boost/geometry/util/range.hpp>
28
29
30namespace boost { namespace geometry
31{
32
33
34#ifndef DOXYGEN_NO_DISPATCH
35namespace dispatch
36{
37
38// By default, all is forwarded to the intersection_insert-dispatcher
39template
40<
41 typename Geometry1, typename Geometry2,
42 typename Tag1 = typename geometry::tag<Geometry1>::type,
43 typename Tag2 = typename geometry::tag<Geometry2>::type,
44 bool Reverse = reverse_dispatch<Geometry1, Geometry2>::type::value
45>
46struct intersection
47{
48 template <typename RobustPolicy, typename GeometryOut, typename Strategy>
49 static inline bool apply(Geometry1 const& geometry1,
50 Geometry2 const& geometry2,
51 RobustPolicy const& robust_policy,
52 GeometryOut& geometry_out,
53 Strategy const& strategy)
54 {
f67539c2
TL
55 typedef typename geometry::detail::output_geometry_value
56 <
57 GeometryOut
58 >::type SingleOut;
b32b8144
FG
59
60 intersection_insert
61 <
f67539c2 62 Geometry1, Geometry2, SingleOut,
b32b8144
FG
63 overlay_intersection
64 >::apply(geometry1, geometry2, robust_policy,
f67539c2
TL
65 geometry::detail::output_geometry_back_inserter(geometry_out),
66 strategy);
b32b8144
FG
67
68 return true;
69 }
70
71};
72
73
74// If reversal is needed, perform it
75template
76<
77 typename Geometry1, typename Geometry2,
78 typename Tag1, typename Tag2
79>
80struct intersection
81<
82 Geometry1, Geometry2,
83 Tag1, Tag2,
84 true
85>
86 : intersection<Geometry2, Geometry1, Tag2, Tag1, false>
87{
88 template <typename RobustPolicy, typename GeometryOut, typename Strategy>
89 static inline bool apply(
90 Geometry1 const& g1,
91 Geometry2 const& g2,
92 RobustPolicy const& robust_policy,
93 GeometryOut& out,
94 Strategy const& strategy)
95 {
96 return intersection
97 <
98 Geometry2, Geometry1,
99 Tag2, Tag1,
100 false
101 >::apply(g2, g1, robust_policy, out, strategy);
102 }
103};
104
105
106} // namespace dispatch
107#endif // DOXYGEN_NO_DISPATCH
108
109
110namespace resolve_strategy {
111
1e59de90
TL
112template
113<
114 typename Strategy,
115 bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
116>
b32b8144
FG
117struct intersection
118{
119 template
120 <
121 typename Geometry1,
122 typename Geometry2,
1e59de90 123 typename GeometryOut
b32b8144
FG
124 >
125 static inline bool apply(Geometry1 const& geometry1,
126 Geometry2 const& geometry2,
b32b8144
FG
127 GeometryOut & geometry_out,
128 Strategy const& strategy)
129 {
92f5a8d4
TL
130 typedef typename geometry::rescale_overlay_policy_type
131 <
132 Geometry1,
133 Geometry2,
134 typename Strategy::cs_tag
135 >::type rescale_policy_type;
136
137 rescale_policy_type robust_policy
138 = geometry::get_rescale_policy<rescale_policy_type>(
139 geometry1, geometry2, strategy);
140
b32b8144
FG
141 return dispatch::intersection
142 <
143 Geometry1,
144 Geometry2
145 >::apply(geometry1, geometry2, robust_policy, geometry_out,
146 strategy);
147 }
1e59de90 148};
b32b8144 149
1e59de90
TL
150template <typename Strategy>
151struct intersection<Strategy, false>
152{
b32b8144
FG
153 template
154 <
155 typename Geometry1,
156 typename Geometry2,
b32b8144
FG
157 typename GeometryOut
158 >
159 static inline bool apply(Geometry1 const& geometry1,
160 Geometry2 const& geometry2,
b32b8144 161 GeometryOut & geometry_out,
1e59de90 162 Strategy const& strategy)
b32b8144 163 {
1e59de90
TL
164 using strategies::relate::services::strategy_converter;
165 return intersection
b32b8144 166 <
1e59de90
TL
167 decltype(strategy_converter<Strategy>::get(strategy))
168 >::apply(geometry1, geometry2, geometry_out,
169 strategy_converter<Strategy>::get(strategy));
170 }
171};
172
173template <>
174struct intersection<default_strategy, false>
175{
176 template
177 <
178 typename Geometry1,
179 typename Geometry2,
180 typename GeometryOut
181 >
182 static inline bool apply(Geometry1 const& geometry1,
183 Geometry2 const& geometry2,
184 GeometryOut & geometry_out,
185 default_strategy)
186 {
187 typedef typename strategies::relate::services::default_strategy
92f5a8d4
TL
188 <
189 Geometry1, Geometry2
1e59de90 190 >::type strategy_type;
92f5a8d4 191
1e59de90 192 return intersection
b32b8144 193 <
1e59de90
TL
194 strategy_type
195 >::apply(geometry1, geometry2, geometry_out, strategy_type());
b32b8144
FG
196 }
197};
198
199} // resolve_strategy
200
201
202namespace resolve_variant
203{
204
205template <typename Geometry1, typename Geometry2>
206struct intersection
207{
208 template <typename GeometryOut, typename Strategy>
209 static inline bool apply(Geometry1 const& geometry1,
210 Geometry2 const& geometry2,
211 GeometryOut& geometry_out,
212 Strategy const& strategy)
213 {
214 concepts::check<Geometry1 const>();
215 concepts::check<Geometry2 const>();
216
1e59de90
TL
217 return resolve_strategy::intersection
218 <
219 Strategy
220 >::apply(geometry1, geometry2, geometry_out, strategy);
b32b8144
FG
221 }
222};
223
224
225template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
226struct intersection<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
227{
228 template <typename GeometryOut, typename Strategy>
229 struct visitor: static_visitor<bool>
230 {
231 Geometry2 const& m_geometry2;
232 GeometryOut& m_geometry_out;
233 Strategy const& m_strategy;
234
235 visitor(Geometry2 const& geometry2,
236 GeometryOut& geometry_out,
237 Strategy const& strategy)
238 : m_geometry2(geometry2)
239 , m_geometry_out(geometry_out)
240 , m_strategy(strategy)
241 {}
242
243 template <typename Geometry1>
244 bool operator()(Geometry1 const& geometry1) const
245 {
246 return intersection
247 <
248 Geometry1,
249 Geometry2
250 >::apply(geometry1, m_geometry2, m_geometry_out, m_strategy);
251 }
252 };
253
254 template <typename GeometryOut, typename Strategy>
255 static inline bool
256 apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
257 Geometry2 const& geometry2,
258 GeometryOut& geometry_out,
259 Strategy const& strategy)
260 {
261 return boost::apply_visitor(visitor<GeometryOut, Strategy>(geometry2,
262 geometry_out,
263 strategy),
264 geometry1);
265 }
266};
267
268
269template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
270struct intersection<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
271{
272 template <typename GeometryOut, typename Strategy>
273 struct visitor: static_visitor<bool>
274 {
275 Geometry1 const& m_geometry1;
276 GeometryOut& m_geometry_out;
277 Strategy const& m_strategy;
278
279 visitor(Geometry1 const& geometry1,
280 GeometryOut& geometry_out,
281 Strategy const& strategy)
282 : m_geometry1(geometry1)
283 , m_geometry_out(geometry_out)
284 , m_strategy(strategy)
285 {}
286
287 template <typename Geometry2>
288 bool operator()(Geometry2 const& geometry2) const
289 {
290 return intersection
291 <
292 Geometry1,
293 Geometry2
294 >::apply(m_geometry1, geometry2, m_geometry_out, m_strategy);
295 }
296 };
297
298 template <typename GeometryOut, typename Strategy>
299 static inline bool
300 apply(Geometry1 const& geometry1,
301 variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
302 GeometryOut& geometry_out,
303 Strategy const& strategy)
304 {
305 return boost::apply_visitor(visitor<GeometryOut, Strategy>(geometry1,
306 geometry_out,
307 strategy),
308 geometry2);
309 }
310};
311
312
313template <BOOST_VARIANT_ENUM_PARAMS(typename T1), BOOST_VARIANT_ENUM_PARAMS(typename T2)>
314struct intersection<variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
315{
316 template <typename GeometryOut, typename Strategy>
317 struct visitor: static_visitor<bool>
318 {
319 GeometryOut& m_geometry_out;
320 Strategy const& m_strategy;
321
322 visitor(GeometryOut& geometry_out, Strategy const& strategy)
323 : m_geometry_out(geometry_out)
324 , m_strategy(strategy)
325 {}
326
327 template <typename Geometry1, typename Geometry2>
328 bool operator()(Geometry1 const& geometry1,
329 Geometry2 const& geometry2) const
330 {
331 return intersection
332 <
333 Geometry1,
334 Geometry2
335 >::apply(geometry1, geometry2, m_geometry_out, m_strategy);
336 }
337 };
338
339 template <typename GeometryOut, typename Strategy>
340 static inline bool
341 apply(variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
342 variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
343 GeometryOut& geometry_out,
344 Strategy const& strategy)
345 {
346 return boost::apply_visitor(visitor<GeometryOut, Strategy>(geometry_out,
347 strategy),
348 geometry1, geometry2);
349 }
350};
351
352} // namespace resolve_variant
353
354
355/*!
356\brief \brief_calc2{intersection}
357\ingroup intersection
358\details \details_calc2{intersection, spatial set theoretic intersection}.
359\tparam Geometry1 \tparam_geometry
360\tparam Geometry2 \tparam_geometry
361\tparam GeometryOut Collection of geometries (e.g. std::vector, std::deque, boost::geometry::multi*) of which
362 the value_type fulfills a \p_l_or_c concept, or it is the output geometry (e.g. for a box)
363\tparam Strategy \tparam_strategy{Intersection}
364\param geometry1 \param_geometry
365\param geometry2 \param_geometry
366\param geometry_out The output geometry, either a multi_point, multi_polygon,
367 multi_linestring, or a box (for intersection of two boxes)
368\param strategy \param_strategy{intersection}
369
370\qbk{distinguish,with strategy}
371\qbk{[include reference/algorithms/intersection.qbk]}
372*/
373template
374<
375 typename Geometry1,
376 typename Geometry2,
377 typename GeometryOut,
378 typename Strategy
379>
380inline bool intersection(Geometry1 const& geometry1,
381 Geometry2 const& geometry2,
382 GeometryOut& geometry_out,
383 Strategy const& strategy)
384{
385 return resolve_variant::intersection
386 <
387 Geometry1,
388 Geometry2
389 >::apply(geometry1, geometry2, geometry_out, strategy);
390}
391
392
393/*!
394\brief \brief_calc2{intersection}
395\ingroup intersection
396\details \details_calc2{intersection, spatial set theoretic intersection}.
397\tparam Geometry1 \tparam_geometry
398\tparam Geometry2 \tparam_geometry
399\tparam GeometryOut Collection of geometries (e.g. std::vector, std::deque, boost::geometry::multi*) of which
400 the value_type fulfills a \p_l_or_c concept, or it is the output geometry (e.g. for a box)
401\param geometry1 \param_geometry
402\param geometry2 \param_geometry
403\param geometry_out The output geometry, either a multi_point, multi_polygon,
404 multi_linestring, or a box (for intersection of two boxes)
405
406\qbk{[include reference/algorithms/intersection.qbk]}
407*/
408template
409<
410 typename Geometry1,
411 typename Geometry2,
412 typename GeometryOut
413>
414inline bool intersection(Geometry1 const& geometry1,
415 Geometry2 const& geometry2,
416 GeometryOut& geometry_out)
417{
418 return resolve_variant::intersection
419 <
420 Geometry1,
421 Geometry2
422 >::apply(geometry1, geometry2, geometry_out, default_strategy());
423}
424
425
426}} // namespace boost::geometry
427
428
429#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_INTERFACE_HPP