]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/test/algorithms/set_operations/sym_difference/sym_difference_tupled.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / set_operations / sym_difference / sym_difference_tupled.cpp
CommitLineData
20effc67
TL
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2
3// Copyright (c) 2020, Oracle and/or its affiliates.
4
5// Contributed and/or modified by Adam Wulkiewicz, 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#include <geometry_test_common.hpp>
11
12#include <boost/geometry/algorithms/correct.hpp>
13#include <boost/geometry/algorithms/equals.hpp>
14#include <boost/geometry/algorithms/sym_difference.hpp>
15#include <boost/geometry/geometries/geometries.hpp>
16#include <boost/geometry/io/wkt/wkt.hpp>
20effc67
TL
17#include <boost/geometry/strategies/cartesian/intersection.hpp>
18#include <boost/geometry/strategies/cartesian/point_in_poly_winding.hpp>
19#include <boost/geometry/strategies/cartesian/point_in_point.hpp>
20
21#include <boost/tuple/tuple.hpp>
22
23// TEST
24#include <boost/geometry/strategies/cartesian.hpp>
25#include <boost/geometry/strategies/geographic.hpp>
26#include <boost/geometry/strategies/spherical.hpp>
27
28
29typedef bg::model::point<double, 2, bg::cs::cartesian> Pt;
30typedef bg::model::linestring<Pt> Ls;
31typedef bg::model::polygon<Pt> Po;
32typedef bg::model::ring<Pt> R;
33typedef bg::model::multi_point<Pt> MPt;
34typedef bg::model::multi_linestring<Ls> MLs;
35typedef bg::model::multi_polygon<Po> MPo;
36
37#ifdef BOOST_GEOMETRY_CXX11_TUPLE
38
39#include <tuple>
40
41#endif
42
43template <typename G>
44inline void check(std::string const& wkt1,
45 std::string const& wkt2,
46 G const& g,
47 std::string const& expected)
48{
49 G expect;
50 bg::read_wkt(expected, expect);
51 bg::correct(expect);
52 if (! boost::empty(g) || ! boost::empty(expect))
53 {
54 BOOST_CHECK_MESSAGE(
55 // Commented out becasue the output in reversed case may be slightly different
56 // e.g. different number of duplicated points in MultiPoint
57 //boost::size(g) == boost::size(expect) &&
58 bg::equals(g, expect),
59 wkt1 << " ^ " << wkt2 << " -> " << bg::wkt(g)
60 << " different than expected: " << expected
61 );
62 }
63}
64
65inline void check(std::string const& wkt1,
66 std::string const& wkt2,
67 boost::tuple<MPt, MLs, MPo> const& tup,
68 std::string const& out_p_str,
69 std::string const& out_l_str,
70 std::string const& out_a_str)
71{
72 check(wkt1, wkt2, boost::get<0>(tup), out_p_str);
73 check(wkt1, wkt2, boost::get<1>(tup), out_l_str);
74 check(wkt1, wkt2, boost::get<2>(tup), out_a_str);
75}
76
77inline void check(std::string const& wkt1,
78 std::string const& wkt2,
79 std::pair<MPt, MLs> const& pair,
80 std::string const& out_p_str,
81 std::string const& out_l_str,
82 std::string const& )
83{
84 check(wkt1, wkt2, pair.first, out_p_str);
85 check(wkt1, wkt2, pair.second, out_l_str);
86}
87
88#ifdef BOOST_GEOMETRY_CXX11_TUPLE
89
90inline void check(std::string const& wkt1,
91 std::string const& wkt2,
92 std::tuple<MPt, MLs, MPo> const& tup,
93 std::string const& out_p_str,
94 std::string const& out_l_str,
95 std::string const& out_a_str)
96{
97 check(wkt1, wkt2, std::get<0>(tup), out_p_str);
98 check(wkt1, wkt2, std::get<1>(tup), out_l_str);
99 check(wkt1, wkt2, std::get<2>(tup), out_a_str);
100}
101
102#endif
103
104template <typename In1, typename In2, typename Tup>
105inline void test_one(std::string const& in1_str,
106 std::string const& in2_str,
107 std::string const& out_p_str = "MULTIPOINT()",
108 std::string const& out_l_str = "MULTILINESTRING()",
109 std::string const& out_a_str = "MULTIPOLYGON()")
110{
111 In1 in1;
112 bg::read_wkt(in1_str, in1);
113 bg::correct(in1);
114
115 In2 in2;
116 bg::read_wkt(in2_str, in2);
117 bg::correct(in2);
118
119 {
120 Tup result;
121 bg::sym_difference(in1, in2, result);
122 check(in1_str, in2_str, result, out_p_str, out_l_str, out_a_str);
123 }
124 {
125 Tup result;
126 bg::sym_difference(in2, in1, result);
127 check(in1_str, in2_str, result, out_p_str, out_l_str, out_a_str);
128 }
129}
130
131template <typename Tup>
132inline void test_pp()
133{
134 test_one<Pt, Pt, Tup>(
135 "POINT(0 0)",
136 "POINT(0 0)",
137 "MULTIPOINT()");
138
139 test_one<Pt, MPt, Tup>(
140 "POINT(0 0)",
141 "MULTIPOINT(0 0, 1 1)",
142 "MULTIPOINT(1 1)");
143
144 test_one<MPt, MPt, Tup>(
145 "MULTIPOINT(0 0, 1 1, 2 2)",
146 "MULTIPOINT(1 1, 2 2, 3 3)",
147 "MULTIPOINT(0 0, 3 3)");
148}
149
150template <typename Tup>
151inline void test_pl()
152{
153 test_one<Pt, Ls, Tup>(
154 "POINT(0 0)",
155 "LINESTRING(0 0, 1 1)",
156 "MULTIPOINT()",
157 "MULTILINESTRING((0 0, 1 1))");
158
159 test_one<Pt, MLs, Tup>(
160 "POINT(1 1)",
161 "MULTILINESTRING((0 0, 1 1),(1 1, 2 2),(4 4, 5 5))",
162 "MULTIPOINT()",
163 "MULTILINESTRING((0 0, 1 1),(1 1, 2 2),(4 4, 5 5))");
164
165 test_one<MPt, Ls, Tup>(
166 "MULTIPOINT(0 0, 1 1, 2 2, 3 3)",
167 "LINESTRING(0 0, 1 1)",
168 "MULTIPOINT(2 2, 3 3)",
169 "MULTILINESTRING((0 0, 1 1))");
170
171 test_one<MPt, MLs, Tup>(
172 "MULTIPOINT(0 0, 1 1, 2 2, 3 3)",
173 "MULTILINESTRING((0 0, 1 1),(1 1, 2 2),(4 4, 5 5))",
174 "MULTIPOINT(3 3)",
175 "MULTILINESTRING((0 0, 1 1),(1 1, 2 2),(4 4, 5 5))");
176}
177
178template <typename Tup>
179inline void test_pa()
180{
181 test_one<Pt, R, Tup>(
182 "POINT(0 0)",
183 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))",
184 "MULTIPOINT()",
185 "MULTILINESTRING()",
186 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0)))");
187
188 test_one<Pt, Po, Tup>(
189 "POINT(0 0)",
190 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))",
191 "MULTIPOINT()",
192 "MULTILINESTRING()",
193 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)))");
194
195 test_one<Pt, MPo, Tup>(
196 "POINT(0 0)",
197 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),((0 0, 1 2, 2 2, 2 1, 0 0)))",
198 "MULTIPOINT()",
199 "MULTILINESTRING()",
200 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),((0 0, 1 2, 2 2, 2 1, 0 0)))");
201
202 test_one<MPt, R, Tup>(
203 "MULTIPOINT(0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6)",
204 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))",
205 "MULTIPOINT(6 6)",
206 "MULTILINESTRING()",
207 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0)))");
208
209 test_one<MPt, Po, Tup>(
210 "MULTIPOINT(0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6)",
211 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))",
212 "MULTIPOINT(1 1, 2 2, 3 3, 6 6)",
213 "MULTILINESTRING()",
214 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)))");
215
216 test_one<MPt, MPo, Tup>(
217 "MULTIPOINT(0 0, 0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6)",
218 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),((0 0, 1 2, 2 2, 2 1, 0 0)))",
219 "MULTIPOINT(3 3, 6 6)",
220 "MULTILINESTRING()",
221 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),((0 0, 1 2, 2 2, 2 1, 0 0)))");
222}
223
224template <typename Tup>
225inline void test_ll()
226{
227 test_one<Ls, Ls, Tup>(
228 "LINESTRING(0 0, 1 0, 2 1, 3 0)",
229 "LINESTRING(0 0, 1 0, 3 0, 4 0)",
230 "MULTIPOINT()",
231 "MULTILINESTRING((1 0, 2 1, 3 0),(1 0, 3 0, 4 0))");
232
233 test_one<Ls, MLs, Tup>(
234 "LINESTRING(0 0, 1 0, 2 1, 3 0)",
235 "MULTILINESTRING((0 0, 1 0, 3 0),(2 1, 2 2))",
236 "MULTIPOINT()",
237 "MULTILINESTRING((1 0, 2 1, 3 0),(1 0, 3 0),(2 1, 2 2))");
238
239 test_one<MLs, MLs, Tup>(
240 "MULTILINESTRING((0 0, 1 0, 2 1),(2 1, 3 0))",
241 "MULTILINESTRING((0 0, 1 0, 3 0),(2 1, 2 2))",
242 "MULTIPOINT()",
243 "MULTILINESTRING((1 0, 2 1),(2 1, 3 0),(1 0, 3 0),(2 1, 2 2))");
244
245 test_one<Ls, Ls, Tup>(
246 "LINESTRING(0 0, 0 5, 5 5, 5 0, 0 0)",
247 "LINESTRING(0 0, 0 1, 6 1, 5 2, 5 5, 5 6, 4 5, 4 7, 7 7, 7 0, 0 0)",
248 "MULTIPOINT()",
249 "MULTILINESTRING((0 1, 0 5, 5 5),(5 2, 5 0),(0 1, 6 1, 5 2), (5 5, 5 6, 4 5, 4 7, 7 7, 7 0, 5 0))");
250
251 test_one<MLs, MLs, Tup>(
252 "MULTILINESTRING((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))",
253 "MULTILINESTRING((0 0, 1 4, 5 4, 5 1, 4 1, 0 0),(0 0, 2 1, 2 2, 1 2, 0 0))",
254 "MULTIPOINT()",
255 "MULTILINESTRING((0 0, 0 5, 5 5, 5 4),(5 1, 5 0, 0 0),(4 1, 4 4),(4 4, 5 4),(5 1, 4 1),(0 0, 2 1, 2 2, 1 2, 0 0))");
256}
257
258template <typename Tup>
259inline void test_la()
260{
261 test_one<Ls, R, Tup>(
262 "LINESTRING(0 2, -4 1, 0 0, 5 0, 9 1, 5 2, 9 3, 5 5, 4 9, 4 5, 3 3, 2 5, 2 9, 0 5)",
263 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))",
264 "MULTIPOINT()",
265 "MULTILINESTRING((0 2, -4 1, 0 0),(5 0, 9 1, 5 2, 9 3, 5 5, 4 9, 4 5),(2 5, 2 9, 0 5))",
266 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0)))");
267
268 test_one<Ls, Po, Tup>(
269 "LINESTRING(1 4, -4 1, 0 0, 5 0, 9 1, 5 2, 9 3, 5 5, 4 9, 4 5, 3 3, 2 5, 2 9, 0 5)",
270 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))",
271 "MULTIPOINT()",
272 "MULTILINESTRING((0 3.4, -4 1, 0 0),(5 0, 9 1, 5 2, 9 3, 5 5, 4 9, 4 5),(3.5 4, 3 3, 2.5 4),(2 5, 2 9, 0 5))",
273 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)))");
274
275 test_one<MLs, R, Tup>(
276 "MULTILINESTRING((0 2, -4 1, 0 0, 5 0, 9 1, 5 2, 9 3, 5 5, 4 9), (4 9, 4 5, 3 3, 2 5, 2 9, 0 5))",
277 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))",
278 "MULTIPOINT()",
279 "MULTILINESTRING((0 2, -4 1, 0 0),(5 0, 9 1, 5 2, 9 3, 5 5, 4 9),(4 9, 4 5),(2 5, 2 9, 0 5))",
280 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0)))");
281
282 test_one<MLs, Po, Tup>(
283 "MULTILINESTRING((1 4, -4 1, 0 0, 5 0, 9 1, 5 2, 9 3, 5 5, 4 9), (4 9, 4 5, 3 3, 2 5, 2 9, 0 5))",
284 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))",
285 "MULTIPOINT()",
286 "MULTILINESTRING((0 3.4, -4 1, 0 0),(5 0, 9 1, 5 2, 9 3, 5 5, 4 9),(4 9, 4 5),(3.5 4, 3 3, 2.5 4),(2 5, 2 9, 0 5))",
287 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)))");
288
289 test_one<MLs, MPo, Tup>(
290 "MULTILINESTRING((1 4, -4 1, 0 0, 5 0, 9 1, 5 2, 9 3, 5 5, 4 9), (4 9, 4 5, 4 4, 2 2, 2 5, 1 9, 0 5))",
291 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),((0 0, 1 2, 2 2, 2 1, 0 0)))",
292 "MULTIPOINT()",
293 "MULTILINESTRING((0 3.4, -4 1, 0 0),(5 0, 9 1, 5 2, 9 3, 5 5, 4 9),(4 9, 4 5),(4 4, 2 2, 2 4),(2 5, 1 9, 0 5))",
294 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),((0 0, 1 2, 2 2, 2 1, 0 0)))");
295
296 test_one<Ls, R, Tup>(
297 "LINESTRING(0 0, 0 5, 5 5, 5 0, 0 0)",
298 "POLYGON((0 0, 0 1, 6 1, 5 2, 5 5, 5 6, 4 5, 4 7, 7 7, 7 0, 0 0))",
299 "MULTIPOINT()",
300 "MULTILINESTRING((0 1, 0 5, 5 5),(5 2, 5 1))",
301 "MULTIPOLYGON(((0 0, 0 1, 6 1, 5 2, 5 5, 5 6, 4 5, 4 7, 7 7, 7 0, 0 0)))");
302
303 test_one<MLs, Po, Tup>(
304 "MULTILINESTRING((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))",
305 "POLYGON((0 0, 1 4, 5 4, 5 1, 4 1, 0 0),(0 0, 2 1, 2 2, 1 2, 0 0))",
306 "MULTIPOINT()",
307 "MULTILINESTRING((0 0, 0 5, 5 5, 5 4),(5 1, 5 0, 0 0))",
308 "MULTIPOLYGON(((0 0, 1 4, 5 4, 5 1, 4 1, 0 0),(0 0, 2 1, 2 2, 1 2, 0 0)))");
309}
310
311template <typename Tup>
312inline void test_aa()
313{
314 test_one<R, R, Tup>(
315 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))",
316 "POLYGON((0 0, 0 1, 6 1, 5 2, 5 5, 5 6, 4 5, 4 7, 7 7, 7 0, 0 0))",
317 "MULTIPOINT()",
318 "MULTILINESTRING()",
319 "MULTIPOLYGON(((4 5,4 7,7 7,7 0,5 0,5 1,0 1,0 5,4 5),(5 5,5 6,4 5,5 5),(5 2,5 1,6 1,5 2)))");
320
321 test_one<R, MPo, Tup>(
322 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))",
323 "MULTIPOLYGON(((0 0, 0 1, 6 1, 6 0, 0 0)),"
324 "((6 1, 5 2, 5 5, 5 6, 4 5, 4 7, 7 7, 7 1, 6 1)))",
325 "MULTIPOINT()",
326 "MULTILINESTRING()",
327 "MULTIPOLYGON(((4 5,4 7,7 7,7 1,6 1,5 2,5 1,0 1,0 5,4 5),(5 5,5 6,4 5,5 5)),"
328 "((5 1,6 1,6 0,5 0,5 1)))");
329
330 test_one<Po, Po, Tup>(
331 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))",
332 "POLYGON((0 0, 1 4, 5 4, 5 1, 4 1, 0 0),(0 0, 2 1, 2 2, 1 2, 0 0))",
333 "MULTIPOINT()",
334 "MULTILINESTRING()",
335 "MULTIPOLYGON(((4 1,5 1,5 0,0 0,0 5,5 5,5 4,4 4,4 1),(0 0,2 1,2 2,1 2,0 0)))");
336
337 test_one<Po, MPo, Tup>(
338 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))",
339 "MULTIPOLYGON(((0 0, 1 4, 5 4, 5 1, 4 1, 0 0),(0 0, 2 1, 2 2, 1 2, 0 0)),"
340 "((5 0, 5 1, 6 1, 6 4, 5 4, 3 6, 2 5, 2 7, 7 7, 7 0 5 0)))",
341 "MULTIPOINT()",
342 "MULTILINESTRING()",
343 "MULTIPOLYGON(((0 0,0 5,2 5,2 7,7 7,7 0,0 0),"
344 "(4 4,4 1,5 1,6 1,6 4,4 4),(5 4,5 5,4 5,5 4),"
345 "(0 0,2 1,2 2,1 2,0 0),(4 5,3 6,2 5,4 5)))");
346
347 test_one<MPo, MPo, Tup>(
348 "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),"
349 "((2 6, 2 8, 8 8, 8 5, 7 5, 7 6, 2 6)))",
350 "MULTIPOLYGON(((0 0, 1 4, 5 4, 5 1, 4 1, 0 0),(0 0, 2 1, 2 2, 1 2, 0 0)),"
1e59de90 351 "((5 0, 5 1, 6 1, 6 4, 5 4, 3 6, 2 5, 2 7, 7 7, 7 0, 5 0)))",
20effc67
TL
352 "MULTIPOINT()",
353 "MULTILINESTRING()",
354 "MULTIPOLYGON(((0 0,0 5,4 5,3 6,7 6,7 7,2 7,2 8,8 8,8 5,7 5,7 0,0 0),"
355 "(4 4,4 1,5 1,6 1,6 4,4 4),(5 4,5 5,4 5,5 4),(0 0,2 1,2 2,1 2,0 0)),"
356 "((2 5,2 6,3 6,2 5)))");
357}
358
359template <typename Tup>
360inline void test_pair()
361{
362 test_pp<Tup>();
363 test_pl<Tup>();
364 test_ll<Tup>();
365}
366
367template <typename Tup>
368inline void test_tuple()
369{
370 test_pp<Tup>();
371 test_pl<Tup>();
372 test_pa<Tup>();
373 test_ll<Tup>();
374 test_la<Tup>();
375 test_aa<Tup>();
376}
377
378int test_main(int, char* [])
379{
380 test_pair<std::pair<MPt, MLs> >();
381 test_tuple<boost::tuple<MPt, MLs, MPo> >();
382
383#ifdef BOOST_GEOMETRY_CXX11_TUPLE
384 test_tuple<std::tuple<MPt, MLs, MPo> >();
385#endif
386
387 return 0;
388}