]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/set_operations/intersection/intersection_areal_areal_linear.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / set_operations / intersection / intersection_areal_areal_linear.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit test
3
4 // Copyright (c) 2015, Oracle and/or its affiliates.
5
6 // Licensed under the Boost Software License version 1.0.
7 // http://www.boost.org/users/license.html
8
9 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
10
11 #ifndef BOOST_TEST_MODULE
12 #define BOOST_TEST_MODULE test_intersection_linear_linear_areal
13 #endif
14
15 #ifdef BOOST_GEOMETRY_TEST_DEBUG
16 #define BOOST_GEOMETRY_DEBUG_TURNS
17 #define BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER
18 #endif
19
20 #include <boost/test/included/unit_test.hpp>
21
22 #include <boost/range.hpp>
23
24 #include <boost/geometry/geometries/linestring.hpp>
25 #include <boost/geometry/geometries/multi_linestring.hpp>
26 #include <boost/geometry/geometries/ring.hpp>
27 #include <boost/geometry/geometries/polygon.hpp>
28 #include <boost/geometry/geometries/multi_polygon.hpp>
29
30 #include "test_intersection_linear_linear.hpp"
31
32 typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
33 typedef bg::model::multi_linestring
34 <
35 bg::model::linestring<point_type>
36 > multi_linestring_type;
37
38 typedef bg::model::ring<point_type, true, false> open_ring_type;
39 typedef bg::model::polygon<point_type, true, false> open_polygon_type;
40 typedef bg::model::multi_polygon<open_polygon_type> open_multipolygon_type;
41
42 typedef bg::model::ring<point_type> closed_ring_type;
43 typedef bg::model::polygon<point_type> closed_polygon_type;
44 typedef bg::model::multi_polygon<closed_polygon_type> closed_multipolygon_type;
45
46
47 template
48 <
49 typename OpenAreal1,
50 typename OpenAreal2,
51 typename ClosedAreal1,
52 typename ClosedAreal2,
53 typename MultiLinestring
54 >
55 struct test_intersection_aal
56 {
57 static inline void apply(std::string const& case_id,
58 OpenAreal1 const& open_areal1,
59 OpenAreal2 const& open_areal2,
60 MultiLinestring const& expected1,
61 MultiLinestring const& expected2)
62 {
63 typedef test_intersection_of_geometries
64 <
65 OpenAreal1, OpenAreal2, MultiLinestring
66 > tester;
67
68 tester::apply(open_areal1, open_areal2, expected1, expected2, case_id);
69
70 ClosedAreal1 closed_areal1;
71 ClosedAreal2 closed_areal2;
72 bg::convert(open_areal1, closed_areal1);
73 bg::convert(open_areal2, closed_areal2);
74
75 typedef test_intersection_of_geometries
76 <
77 ClosedAreal1, ClosedAreal2, MultiLinestring
78 > tester_of_closed;
79
80 std::string case_id_closed = case_id + "-closed";
81
82 #ifdef BOOST_GEOMETRY_TEST_DEBUG
83 std::cout << "testing closed areal geometries..." << std::endl;
84 #endif
85 tester_of_closed::apply(closed_areal1, closed_areal2,
86 expected1, expected2, case_id_closed);
87 }
88
89 static inline void apply(std::string const& case_id,
90 OpenAreal1 const& open_areal1,
91 OpenAreal2 const& open_areal2,
92 MultiLinestring const& expected)
93 {
94 apply(case_id, open_areal1, open_areal2, expected, expected);
95 }
96 };
97
98
99 BOOST_AUTO_TEST_CASE( test_intersection_ring_ring_linestring )
100 {
101 #ifdef BOOST_GEOMETRY_TEST_DEBUG
102 std::cout << std::endl << std::endl << std::endl;
103 std::cout << "*** RING / RING / LINEAR INTERSECTION ***" << std::endl;
104 std::cout << std::endl;
105 #endif
106 typedef open_ring_type OG;
107 typedef closed_ring_type CG;
108 typedef multi_linestring_type ML;
109
110 typedef test_intersection_aal<OG, OG, CG, CG, ML> tester;
111
112 tester::apply
113 ("r-r-01",
114 from_wkt<OG>("POLYGON((0 0,0 2,2 2,2 0))"),
115 from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
116 from_wkt<ML>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
117 from_wkt<ML>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
118 );
119
120 tester::apply
121 ("r-r-02",
122 from_wkt<OG>("POLYGON(())"),
123 from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
124 from_wkt<ML>("MULTILINESTRING()")
125 );
126
127 tester::apply
128 ("r-r-03",
129 from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
130 from_wkt<OG>("POLYGON(())"),
131 from_wkt<ML>("MULTILINESTRING()")
132 );
133
134 tester::apply
135 ("r-r-04",
136 from_wkt<OG>("POLYGON(())"),
137 from_wkt<OG>("POLYGON(())"),
138 from_wkt<ML>("MULTILINESTRING()")
139 );
140 }
141
142
143 BOOST_AUTO_TEST_CASE( test_intersection_ring_polygon_linestring )
144 {
145 #ifdef BOOST_GEOMETRY_TEST_DEBUG
146 std::cout << std::endl << std::endl << std::endl;
147 std::cout << "*** RING / POLYGON / LINEAR INTERSECTION ***" << std::endl;
148 std::cout << std::endl;
149 #endif
150 typedef open_ring_type OG1;
151 typedef open_polygon_type OG2;
152 typedef closed_ring_type CG1;
153 typedef closed_polygon_type CG2;
154 typedef multi_linestring_type ML;
155
156 typedef test_intersection_aal<OG1, OG2, CG1, CG2, ML> tester;
157
158 tester::apply
159 ("r-pg-01",
160 from_wkt<OG1>("POLYGON((0 0,0 2,2 2,2 0))"),
161 from_wkt<OG2>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
162 from_wkt<ML>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
163 from_wkt<ML>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
164 );
165 }
166
167
168 BOOST_AUTO_TEST_CASE( test_intersection_ring_multipolygon_linestring )
169 {
170 #ifdef BOOST_GEOMETRY_TEST_DEBUG
171 std::cout << std::endl << std::endl << std::endl;
172 std::cout << "*** RING / MULTIPOLYGON / LINEAR INTERSECTION ***"
173 << std::endl;
174 std::cout << std::endl;
175 #endif
176 typedef open_ring_type OG1;
177 typedef open_multipolygon_type OG2;
178 typedef closed_ring_type CG1;
179 typedef closed_multipolygon_type CG2;
180 typedef multi_linestring_type ML;
181
182 typedef test_intersection_aal<OG1, OG2, CG1, CG2, ML> tester;
183
184 tester::apply
185 ("r-mpg-01",
186 from_wkt<OG1>("POLYGON((0 0,0 2,2 2,2 0))"),
187 from_wkt<OG2>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
188 from_wkt<ML>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
189 from_wkt<ML>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
190 );
191 }
192
193
194 BOOST_AUTO_TEST_CASE( test_intersection_polygon_polygon_linestring )
195 {
196 #ifdef BOOST_GEOMETRY_TEST_DEBUG
197 std::cout << std::endl << std::endl << std::endl;
198 std::cout << "*** POLYGON / POLYGON / LINEAR INTERSECTION ***" << std::endl;
199 std::cout << std::endl;
200 #endif
201 typedef open_polygon_type OG;
202 typedef closed_polygon_type CG;
203 typedef multi_linestring_type ML;
204
205 typedef test_intersection_aal<OG, OG, CG, CG, ML> tester;
206
207 tester::apply
208 ("pg-pg-01",
209 from_wkt<OG>("POLYGON((0 0,0 2,2 2,2 0))"),
210 from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
211 from_wkt<ML>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
212 from_wkt<ML>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
213 );
214
215 tester::apply
216 ("pg-pg-02",
217 from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
218 from_wkt<OG>("POLYGON((2 2,2 7,7 7,7 2))"),
219 from_wkt<ML>("MULTILINESTRING((2 2,2 2),(2 2,2 7,7 7,7 2,2 2),(2 2,2 2))"),
220 from_wkt<ML>("MULTILINESTRING((2 2,2 2),(2 2,7 2,7 7,2 7,2 2),(2 2,2 2))")
221 );
222
223 tester::apply
224 ("pg-pg-03",
225 from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
226 from_wkt<OG>("POLYGON((2 3,2 6,6 6,6 3))"),
227 from_wkt<ML>("MULTILINESTRING((2 3,2 6),(2 3,2 3))")
228 );
229
230 tester::apply
231 ("pg-pg-04",
232 from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
233 from_wkt<OG>("POLYGON((2 3,2 7,6 7,6 3))"),
234 from_wkt<ML>("MULTILINESTRING((2 3,2 7,6 7),(2 3,2 3))")
235 );
236
237 tester::apply
238 ("pg-pg-05",
239 from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
240 from_wkt<OG>("POLYGON((2 3,2 7,7 7,7 3))"),
241 from_wkt<ML>("MULTILINESTRING((2 3,2 7,7 7,7 3),(2 3,2 3))")
242 );
243
244 tester::apply
245 ("pg-pg-06",
246 from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
247 from_wkt<OG>("POLYGON((2 3,2 7,7 7,7 3))"),
248 from_wkt<ML>("MULTILINESTRING((2 3,2 7,7 7,7 3),(2 3,2 3))")
249 );
250
251 tester::apply
252 ("pg-pg-07",
253 from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
254 from_wkt<OG>("POLYGON((2 5,5 7,7 5,5 2))"),
255 from_wkt<ML>("MULTILINESTRING((2 5,2 5),(5 7,5 7),(7 5,7 5),(5 2,5 2))")
256 );
257
258 tester::apply
259 ("pg-pg-08",
260 from_wkt<OG>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
261 from_wkt<OG>("POLYGON((2 5,4 7,6 7,7 5,5 2))"),
262 from_wkt<ML>("MULTILINESTRING((2 5,2 5),(4 7,6 7),(7 5,7 5),(5 2,5 2))")
263 );
264
265 tester::apply
266 ("pg-pg-09",
267 from_wkt<OG>("POLYGON(())"),
268 from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
269 from_wkt<ML>("MULTILINESTRING()")
270 );
271
272 tester::apply
273 ("pg-pg-10",
274 from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
275 from_wkt<OG>("POLYGON(())"),
276 from_wkt<ML>("MULTILINESTRING()")
277 );
278
279 tester::apply
280 ("pg-pg-11",
281 from_wkt<OG>("POLYGON(())"),
282 from_wkt<OG>("POLYGON(())"),
283 from_wkt<ML>("MULTILINESTRING()")
284 );
285
286 tester::apply
287 ("pg-pg-12",
288 from_wkt<OG>("POLYGON((),())"),
289 from_wkt<OG>("POLYGON((),(),())"),
290 from_wkt<ML>("MULTILINESTRING()")
291 );
292
293 tester::apply
294 ("pg-pg-13",
295 from_wkt<OG>("POLYGON((2 1,2 4,4 4,4 0,1 0),())"),
296 from_wkt<OG>("POLYGON(())"),
297 from_wkt<ML>("MULTILINESTRING()")
298 );
299 }
300
301
302 BOOST_AUTO_TEST_CASE( test_intersection_polygon_multipolygon_linestring )
303 {
304 #ifdef BOOST_GEOMETRY_TEST_DEBUG
305 std::cout << std::endl << std::endl << std::endl;
306 std::cout << "*** POLYGON / MULTIPOLYGON / LINEAR INTERSECTION ***"
307 << std::endl;
308 std::cout << std::endl;
309 #endif
310 typedef open_polygon_type OG1;
311 typedef open_multipolygon_type OG2;
312 typedef closed_polygon_type CG1;
313 typedef closed_multipolygon_type CG2;
314 typedef multi_linestring_type ML;
315
316 typedef test_intersection_aal<OG1, OG2, CG1, CG2, ML> tester;
317
318 tester::apply
319 ("pg-mpg-01",
320 from_wkt<OG1>("POLYGON((0 0,0 2,2 2,2 0))"),
321 from_wkt<OG2>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
322 from_wkt<ML>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
323 from_wkt<ML>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
324 );
325 }
326
327
328 BOOST_AUTO_TEST_CASE( test_intersection_multipolygon_multipolygon_linestring )
329 {
330 #ifdef BOOST_GEOMETRY_TEST_DEBUG
331 std::cout << std::endl << std::endl << std::endl;
332 std::cout << "*** MULTIPOLYGON / MULTIPOLYGON / LINEAR INTERSECTION ***"
333 << std::endl;
334 std::cout << std::endl;
335 #endif
336 typedef open_multipolygon_type OG;
337 typedef closed_multipolygon_type CG;
338 typedef multi_linestring_type ML;
339
340 typedef test_intersection_aal<OG, OG, CG, CG, ML> tester;
341
342 tester::apply
343 ("mpg-mpg-01",
344 from_wkt<OG>("MULTIPOLYGON(((0 0,0 2,2 2,2 0)))"),
345 from_wkt<OG>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
346 from_wkt<ML>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
347 from_wkt<ML>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
348 );
349
350 tester::apply
351 ("mpg-mpg-02",
352 from_wkt<OG>("MULTIPOLYGON(((0 0,0 10,10 10,10 0),(2 2,8 2,8 8,2 8)))"),
353 from_wkt<OG>("MULTIPOLYGON(((2 4,2 6,8 6,8 4)))"),
354 from_wkt<ML>("MULTILINESTRING((2 4,2 4),(2 4,2 6),(8 6,8 4))")
355 );
356
357 tester::apply
358 ("mpg-mpg-03",
359 from_wkt<OG>("MULTIPOLYGON()"),
360 from_wkt<OG>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
361 from_wkt<ML>("MULTILINESTRING()")
362 );
363
364 tester::apply
365 ("mpg-mpg-04",
366 from_wkt<OG>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
367 from_wkt<OG>("MULTIPOLYGON()"),
368 from_wkt<ML>("MULTILINESTRING()")
369 );
370
371 tester::apply
372 ("mpg-mpg-05",
373 from_wkt<OG>("MULTIPOLYGON()"),
374 from_wkt<OG>("MULTIPOLYGON()"),
375 from_wkt<ML>("MULTILINESTRING()")
376 );
377
378 tester::apply
379 ("mpg-mpg-06",
380 from_wkt<OG>("MULTIPOLYGON((()),((),()))"),
381 from_wkt<OG>("MULTIPOLYGON()"),
382 from_wkt<ML>("MULTILINESTRING()")
383 );
384
385 tester::apply
386 ("mpg-mpg-07",
387 from_wkt<OG>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0),(),()))"),
388 from_wkt<OG>("MULTIPOLYGON()"),
389 from_wkt<ML>("MULTILINESTRING()")
390 );
391 }