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