• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
5 
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 
11 //#define BOOST_GEOMETRY_DEBUG_ENRICH
12 //#define BOOST_GEOMETRY_DEBUG_RELATIVE_ORDER
13 
14 // Include the single-geometry version
15 #define BOOST_GEOMETRY_TEST_MULTI
16 #include <algorithms/overlay/traverse.cpp>
17 
18 #include <boost/geometry/core/closure.hpp>
19 #include <boost/geometry/core/geometry_id.hpp>
20 #include <boost/geometry/core/point_order.hpp>
21 #include <boost/geometry/core/ring_type.hpp>
22 
23 #include <boost/geometry/algorithms/envelope.hpp>
24 #include <boost/geometry/algorithms/num_points.hpp>
25 #include <boost/geometry/algorithms/detail/overlay/copy_segments.hpp>
26 #include <boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp>
27 #include <boost/geometry/algorithms/detail/sections/range_by_section.hpp>
28 #include <boost/geometry/algorithms/detail/sections/sectionalize.hpp>
29 
30 #include <boost/geometry/views/detail/range_type.hpp>
31 
32 
33 #include "multi_overlay_cases.hpp"
34 
35 
36 
37 template <typename MultiPolygon, bool Reverse>
test_geometries()38 void test_geometries()
39 {
40     typedef test_traverse
41         <
42             MultiPolygon, MultiPolygon,
43             bg::overlay_intersection, Reverse, Reverse
44         > test_traverse_intersection;
45     typedef test_traverse
46         <
47             MultiPolygon, MultiPolygon,
48             bg::overlay_union, Reverse, Reverse
49         > test_traverse_union;
50 
51     // Intersections:
52     test_traverse_intersection::apply
53         (
54             "simplex", 2, 6.42,
55             case_multi_simplex[0], case_multi_simplex[1]
56         );
57 
58     test_traverse_intersection::apply
59         (
60             "case_58_multi_b4", 1, 12.666666667,
61             case_58_multi[4], case_58_multi[2]
62         );
63 
64 #ifdef BOOST_GEOMETRY_TEST_FAILURES
65     test_traverse_intersection::apply
66         (
67             "case_58_multi_b5", 1, 1,
68             case_58_multi[5], case_58_multi[2]
69         );
70 #endif
71     test_traverse_intersection::apply
72         (
73             "case_58_multi_b6", 1, 13.25,
74             case_58_multi[6], case_58_multi[2]
75         );
76 
77     test_traverse_intersection::apply
78         (
79             "case_65_multi", 1, 1,
80             case_65_multi[0], case_65_multi[1]
81         );
82     test_traverse_intersection::apply
83         (
84             "case_66_multi", 1, 1,
85             case_66_multi[0], case_66_multi[1]
86         );
87 
88     test_traverse_intersection::apply
89         (
90             "case_67_multi", 1, 1,
91             case_67_multi[0], case_67_multi[1]
92         );
93     test_traverse_intersection::apply
94         (
95             "case_69_multi", 1, 1,
96             case_69_multi[0], case_69_multi[1]
97         );
98 
99     test_traverse_intersection::apply
100         (
101             "case_71_multi", 2, 2,
102             case_71_multi[0], case_71_multi[1]
103         );
104 
105     // #72, note that it intersects into 2 shapes,
106     // the third one is done by assemble (see intersection #72)
107     test_traverse_intersection::apply
108         (
109             "case_72_multi", 2, 1.35,
110             case_72_multi[0], case_72_multi[1]
111         );
112 
113     test_traverse_intersection::apply
114         (
115             "case_73_multi", 2, 2,
116             case_73_multi[0], case_73_multi[1]
117         );
118     test_traverse_intersection::apply
119         (
120             "case_74_multi", 2, 3,
121             case_74_multi[0], case_74_multi[1]
122         );
123     test_traverse_intersection::apply
124         (
125             "case_75_multi", 1, 1,
126             case_75_multi[0], case_75_multi[1]
127         );
128     test_traverse_intersection::apply
129         (
130             "case_77_multi", 5, 9,
131             case_77_multi[0], case_77_multi[1]
132         );
133     test_traverse_intersection::apply
134         (
135             "case_78_multi", 2, 22, // Went from 3 to 2 by get_turns / partition
136             case_78_multi[0], case_78_multi[1]
137         );
138 
139     test_traverse_intersection::apply
140         (
141             "case_80_multi", 1, 0.5,
142             case_80_multi[0], case_80_multi[1]
143         );
144     test_traverse_intersection::apply
145         (
146             "case_81_multi", 1, 0.25,
147             case_81_multi[0], case_81_multi[1]
148         );
149     test_traverse_intersection::apply
150         (
151             "case_83_multi", 3, 1.25,
152             case_83_multi[0], case_83_multi[1]
153         );
154 
155     test_traverse_intersection::apply
156         (
157             "case_91_multi", 2, 1.0,
158             case_91_multi[0], case_91_multi[1]
159         );
160     test_traverse_intersection::apply
161         (
162             "case_92_multi", 3, 1.5,
163             case_92_multi[0], case_92_multi[1]
164         );
165     test_traverse_intersection::apply
166         (
167             "case_93_multi", 2, 1.25,
168             case_93_multi[0], case_93_multi[1]
169         );
170     test_traverse_intersection::apply
171         (
172             "case_96_multi", 1, 0.5,
173             case_96_multi[0], case_96_multi[1]
174         );
175     test_traverse_intersection::apply
176         (
177             "case_98_multi", 4, 3.0,
178             case_98_multi[0], case_98_multi[1]
179         );
180 
181     test_traverse_intersection::apply
182         (
183             "case_99_multi", 3, 1.75,
184             case_99_multi[0], case_99_multi[1]
185         );
186     test_traverse_intersection::apply
187         (
188             "case_100_multi", 2, 1.5,
189             case_100_multi[0], case_100_multi[1]
190         );
191 
192     test_traverse_intersection::apply
193         (
194             "case_108_multi", 7, 7.5,
195             case_108_multi[0], case_108_multi[1]
196         );
197 
198     test_traverse_intersection::apply
199         (
200             "case_recursive_boxes_2", 1, 91,
201             case_recursive_boxes_2[0], case_recursive_boxes_2[1]
202         );
203     test_traverse_intersection::apply
204         (
205             "case_107_multi", 2, 1.5,
206             case_107_multi[0], case_107_multi[1]
207         );
208     test_traverse_intersection::apply
209         (
210             "case_recursive_boxes_3", 19, 12.5,
211             case_recursive_boxes_3[0], case_recursive_boxes_3[1]
212         );
213 
214     // Unions
215 
216 
217     test_traverse_union::apply
218         (
219             "simplex", 1, 14.58,
220             case_multi_simplex[0], case_multi_simplex[1]
221         );
222 
223     test_traverse_union::apply
224         (
225             "case_61_multi", 1, 4,
226             case_61_multi[0], case_61_multi[1]
227         );
228     test_traverse_union::apply
229         (
230             "case_62_multi", 1, 1 /*UU 2, 2 */,
231             case_62_multi[0], case_62_multi[1]
232         );
233     test_traverse_union::apply
234         (
235             "case_63_multi", 1, 1 /*UU 2, 2 */,
236             case_63_multi[0], case_63_multi[1]
237         );
238     test_traverse_union::apply
239         (
240             "case_64_multi", 1, 3,
241             case_64_multi[0], case_64_multi[1]
242         );
243 
244     test_traverse_union::apply
245         (
246             "case_66_multi", 1, 4 /*UU 3, 7 */,
247             case_66_multi[0], case_66_multi[1]
248         );
249     test_traverse_union::apply
250         (
251             "case_68_multi", 1, 4 /*UU 2, 5 */,
252             case_68_multi[0], case_68_multi[1]
253         );
254     // 71: single-polygon generates 2 shapes, multi-polygon
255     //     generates 1 shape, both are self-tangent and OK
256     test_traverse_union::apply
257         (
258             "case_71_multi", 1, 9,
259             case_71_multi[0], case_71_multi[1]
260         );
261 
262     test_traverse_union::apply
263         (
264             "case_72_multi", 1, 10.65,
265             case_72_multi[0], case_72_multi[1]
266         );
267 
268     test_traverse_union::apply
269         (
270             "case_73_multi", 1, 3,
271             case_73_multi[0], case_73_multi[1]
272         );
273     test_traverse_union::apply
274         (
275             "case_74_multi", 2, 17,
276             case_74_multi[0], case_74_multi[1]
277         );
278     test_traverse_union::apply
279         (
280             "case_75_multi", 1, 1 /*UU 5, 5 */,
281             case_75_multi[0], case_75_multi[1]
282         );
283     test_traverse_union::apply
284         (
285             "case_76_multi", 2, 5 /*UU 6, 6 */,
286             case_76_multi[0], case_76_multi[1]
287         );
288 
289     test_traverse_union::apply
290         (
291             "case_80_multi", 1, 9.25,
292             case_80_multi[0], case_80_multi[1]
293         );
294     test_traverse_union::apply
295         (
296             "case_81_multi", 1, 3.25,
297             case_81_multi[0], case_81_multi[1]
298         );
299     test_traverse_union::apply
300         (
301             "case_82_multi", 3, 4,
302             case_82_multi[0], case_82_multi[1]
303         );
304     test_traverse_union::apply
305         (
306             "case_84_multi", 1, 4,
307             case_84_multi[0], case_84_multi[1]
308         );
309     test_traverse_union::apply
310         (
311             "case_85_multi", 1, 3.5,
312             case_85_multi[0], case_85_multi[1]
313         );
314     test_traverse_union::apply
315         (
316             "case_86_multi", 1, 4,
317             case_86_multi[0], case_86_multi[1]
318         );
319     test_traverse_union::apply
320         (
321             "case_87_multi", 1, 6,
322             case_87_multi[0], case_87_multi[1]
323         );
324     test_traverse_union::apply
325         (
326             "case_88_multi", 2, 4,
327             case_88_multi[0], case_88_multi[1]
328         );
329     test_traverse_union::apply
330         (
331             "case_89_multi", 1, 6,
332             case_89_multi[0], case_89_multi[1]
333         );
334     test_traverse_union::apply
335         (
336             "case_90_multi", 1, 7.5,
337             case_90_multi[0], case_90_multi[1]
338         );
339     test_traverse_union::apply
340         (
341             "case_92_multi", 2, 6.25,
342             case_92_multi[0], case_92_multi[1]
343         );
344     test_traverse_union::apply
345         (
346             "case_94_multi", 1, 10.0,
347             case_94_multi[0], case_94_multi[1]
348         );
349     test_traverse_union::apply
350         (
351             "case_95_multi", 2, 6.5,
352             case_95_multi[0], case_95_multi[1]
353         );
354     test_traverse_union::apply
355         (
356             "case_96_multi", 1, 3.5,
357             case_96_multi[0], case_96_multi[1]
358         );
359     test_traverse_union::apply
360         (
361             "case_97_multi", 1, 3.75,
362             case_97_multi[0], case_97_multi[1]
363         );
364     test_traverse_union::apply
365         (
366             "case_101_multi", 1, 22.25,
367             case_101_multi[0], case_101_multi[1]
368         );
369     test_traverse_union::apply
370         (
371             "case_102_multi", 3, 24.25,
372             case_102_multi[0], case_102_multi[1]
373         );
374     test_traverse_union::apply
375         (
376             "case_103_multi", 1, 25,
377             case_103_multi[0], case_103_multi[1]
378         );
379     test_traverse_union::apply
380         (
381             "case_104_multi", 1, 25,
382             case_104_multi[0], case_104_multi[1]
383         );
384     test_traverse_union::apply
385         (
386             "case_105_multi", 1, 25,
387             case_105_multi[0], case_105_multi[1]
388         );
389     test_traverse_union::apply
390         (
391             "case_106_multi", 1, 25,
392             case_106_multi[0], case_106_multi[1]
393         );
394 
395 
396     test_traverse_union::apply
397         (
398             "case_recursive_boxes_1", 2, 97,
399             case_recursive_boxes_1[0], case_recursive_boxes_1[1]
400         );
401 
402     test_traverse_union::apply
403         (
404             "case_recursive_boxes_3", 7, 49.5,
405             case_recursive_boxes_3[0], case_recursive_boxes_3[1]
406         );
407 
408     test_traverse_intersection::apply
409         (
410             "pie_21_7_21_0_3", 2, 818824.56678,
411             pie_21_7_21_0_3[0], pie_21_7_21_0_3[1]
412         );
413 
414     test_traverse_intersection::apply
415         (
416             "pie_23_19_5_0_2", 2, 2948602.3911823,
417             pie_23_19_5_0_2[0], pie_23_19_5_0_2[1]
418         );
419     test_traverse_intersection::apply
420         (
421             "pie_7_14_5_0_7", 2, 490804.56678,
422             pie_7_14_5_0_7[0], pie_7_14_5_0_7[1]
423         );
424     test_traverse_intersection::apply
425         (
426             "pie_16_16_9_0_2", 2, 1146795,
427             pie_16_16_9_0_2[0], pie_16_16_9_0_2[1]
428         );
429     test_traverse_intersection::apply
430         (
431             "pie_7_2_1_0_15", 2, 490585.5,
432             pie_7_2_1_0_15[0], pie_7_2_1_0_15[1]
433         );
434 
435 }
436 
437 template <typename T>
test_all()438 void test_all()
439 {
440     typedef bg::model::point<T, 2, bg::cs::cartesian> point_type;
441 
442     typedef bg::model::multi_polygon
443         <
444             bg::model::polygon<point_type>
445         > multi_polygon;
446 
447     typedef bg::model::multi_polygon
448         <
449             bg::model::polygon<point_type, false>
450         > multi_polygon_ccw;
451 
452     test_geometries<multi_polygon, false>();
453     test_geometries<multi_polygon_ccw, true>();
454 }
455 
456 
test_main(int,char * [])457 int test_main(int, char* [])
458 {
459     test_all<double>();
460 
461     return 0;
462 }
463