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