1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2010-2015 Barend Gehrels, Amsterdam, the Netherlands.
5 
6 // This file was modified by Oracle on 2016.
7 // Modifications copyright (c) 2016, Oracle and/or its affiliates.
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 #include <iostream>
15 #include <string>
16 
17 #include "test_intersection.hpp"
18 #include <algorithms/test_overlay.hpp>
19 #include <algorithms/overlay/multi_overlay_cases.hpp>
20 
21 #include <boost/geometry/algorithms/correct.hpp>
22 #include <boost/geometry/algorithms/intersection.hpp>
23 
24 #include <boost/geometry/geometries/point_xy.hpp>
25 #include <boost/geometry/geometries/multi_point.hpp>
26 #include <boost/geometry/geometries/multi_linestring.hpp>
27 #include <boost/geometry/geometries/multi_polygon.hpp>
28 
29 #include <boost/geometry/io/wkt/read.hpp>
30 
31 #define TEST_INTERSECTION(caseid, clips, points, area) \
32     (test_one<Polygon, MultiPolygon, MultiPolygon>) \
33     ( #caseid, caseid[0], caseid[1], clips, points, area)
34 
35 #define TEST_INTERSECTION_REV(caseid, clips, points, area) \
36     (test_one<Polygon, MultiPolygon, MultiPolygon>) \
37     ( #caseid "_rev", caseid[1], caseid[0], clips, points, area)
38 
39 #define TEST_INTERSECTION_IGNORE(caseid, clips, points, area) \
40     { ut_settings ignore_validity; ignore_validity.test_validity = false; \
41     (test_one<Polygon, MultiPolygon, MultiPolygon>) \
42     ( #caseid, caseid[0], caseid[1], clips, points, area, ignore_validity); }
43 
44 template <typename Ring, typename Polygon, typename MultiPolygon>
test_areal()45 void test_areal()
46 {
47     test_one<Polygon, MultiPolygon, MultiPolygon>("simplex_multi",
48         case_multi_simplex[0], case_multi_simplex[1],
49         2, 12, 6.42);
50 
51     test_one<Polygon, MultiPolygon, MultiPolygon>("case_multi_no_ip",
52         case_multi_no_ip[0], case_multi_no_ip[1],
53         2, 8, 8.5);
54     test_one<Polygon, MultiPolygon, MultiPolygon>("case_multi_2",
55         case_multi_2[0], case_multi_2[1],
56         3, 12, 5.9);
57 
58     test_one<Polygon, MultiPolygon, Polygon>("simplex_multi_mp_p",
59         case_multi_simplex[0], case_single_simplex,
60         2, 12, 6.42);
61 
62     test_one<Polygon, Ring, MultiPolygon>("simplex_multi_r_mp",
63         case_single_simplex, case_multi_simplex[0],
64         2, 12, 6.42);
65     test_one<Ring, MultiPolygon, Polygon>("simplex_multi_mp_r",
66         case_multi_simplex[0], case_single_simplex,
67         2, 12, 6.42);
68 
69     test_one<Polygon, MultiPolygon, MultiPolygon>("case_58_multi_a",
70         case_58_multi[0], case_58_multi[3],
71         3, 12, 0.666666667);
72     test_one<Polygon, MultiPolygon, MultiPolygon>("case_58_multi_b",
73         case_58_multi[1], case_58_multi[2],
74         1, 19, 11.16666666667);
75     test_one<Polygon, MultiPolygon, MultiPolygon>("case_58_multi_b4",
76         case_58_multi[4], case_58_multi[2],
77         1, 13, 12.66666666);
78     test_one<Polygon, MultiPolygon, MultiPolygon>("case_58_multi_b5",
79         case_58_multi[5], case_58_multi[2],
80         1, 13, 13.25);
81     test_one<Polygon, MultiPolygon, MultiPolygon>("case_58_multi_b6",
82         case_58_multi[6], case_58_multi[2],
83         1, 13, 13.25);
84     test_one<Polygon, MultiPolygon, MultiPolygon>("case_58_multi_b7",
85         case_58_multi[7], case_58_multi[2],
86         1, 16, 12.5);
87 
88     // Constructed cases for multi/touch/equal/etc
89     test_one<Polygon, MultiPolygon, MultiPolygon>("case_61_multi",
90         case_61_multi[0], case_61_multi[1],
91         0, 0, 0.0);
92     test_one<Polygon, MultiPolygon, MultiPolygon>("case_62_multi",
93         case_62_multi[0], case_62_multi[1],
94         1, 5, 1.0);
95     test_one<Polygon, MultiPolygon, MultiPolygon>("case_63_multi",
96         case_63_multi[0], case_63_multi[1],
97         1, 5, 1.0);
98     test_one<Polygon, MultiPolygon, MultiPolygon>("case_64_multi",
99         case_64_multi[0], case_64_multi[1],
100         1, 5, 1.0);
101     test_one<Polygon, MultiPolygon, MultiPolygon>("case_65_multi",
102         case_65_multi[0], case_65_multi[1],
103         1, 5, 1.0);
104     test_one<Polygon, MultiPolygon, MultiPolygon>("case_65_multi_inv_a",
105         case_65_multi[0], case_65_multi[3],
106         0, 0, 0.0);
107     test_one<Polygon, MultiPolygon, MultiPolygon>("case_65_multi_inv_b",
108         case_65_multi[1], case_65_multi[2],
109         2, 10, 3.0);
110     test_one<Polygon, MultiPolygon, MultiPolygon>("case_72_multi",
111         case_72_multi[0], case_72_multi[1],
112         3, 14, 2.85);
113     test_one<Polygon, MultiPolygon, MultiPolygon>("case_72_multi_inv_b",
114         case_72_multi[1], case_72_multi[2],
115         3, 16, 6.15);
116     test_one<Polygon, MultiPolygon, MultiPolygon>("case_77_multi",
117         case_77_multi[0], case_77_multi[1],
118         5, 27, 9.0);
119     test_one<Polygon, MultiPolygon, MultiPolygon>("case_78_multi",
120         case_78_multi[0], case_78_multi[1],
121         1, 16, 22.0);
122     test_one<Polygon, MultiPolygon, MultiPolygon>("case_101_multi",
123         case_101_multi[0], case_101_multi[1],
124         4, 22, 4.75);
125     test_one<Polygon, MultiPolygon, MultiPolygon>("case_102_multi",
126         case_102_multi[0], case_102_multi[1],
127         3, 26, 19.75);
128     test_one<Polygon, MultiPolygon, MultiPolygon>("case_102_multi_inv_b",
129         case_102_multi[1], case_102_multi[2],
130         6, 25, 3.75);
131     test_one<Polygon, MultiPolygon, MultiPolygon>("case_107_multi",
132         case_107_multi[0], case_107_multi[1],
133         2, 10, 1.5);
134     test_one<Polygon, MultiPolygon, MultiPolygon>("case_107_multi_inv_b",
135         case_107_multi[1], case_107_multi[2],
136         3, 13, 3.0);
137 
138 #if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
139     {
140         // Rescaling misses one intersection
141         test_one<Polygon, MultiPolygon, MultiPolygon>("case_108_multi",
142             case_108_multi[0], case_108_multi[1],
143             7, -1, 7.5);
144     }
145 #endif
146 
147     TEST_INTERSECTION(case_123_multi, 3, 13, 1.875);
148     TEST_INTERSECTION(case_124_multi, 2, 13, 2.0625);
149     TEST_INTERSECTION(case_125_multi, 3, 17, 2.1);
150     TEST_INTERSECTION(case_126_multi, 5, 27, 9.0);
151     TEST_INTERSECTION(case_127_multi, 3, 19, 24.0);
152     TEST_INTERSECTION(case_128_multi, 2, 26, 75.5);
153     TEST_INTERSECTION(case_129_multi, 1, 20, 20.5);
154     TEST_INTERSECTION(case_130_multi, 2, 30, 39.0);
155 
156     TEST_INTERSECTION(case_133_multi, 2, 23, 40.625);
157     TEST_INTERSECTION(case_134_multi, 1, 23, 42.0);
158     TEST_INTERSECTION(case_135_multi, 1, 12, 7.0);
159     TEST_INTERSECTION(case_136_multi, 1, 12, 6.5);
160     TEST_INTERSECTION(case_137_multi, 1, 12, 6.5);
161 
162     TEST_INTERSECTION(case_138_multi, 2, 23, 40.4);
163     TEST_INTERSECTION(case_139_multi, 2, 23, 40.546875);
164     TEST_INTERSECTION(case_140_multi, 2, 23, 40.546875);
165     TEST_INTERSECTION(case_141_multi, 3, -1, 74.5);
166 
167     TEST_INTERSECTION(case_recursive_boxes_1, 10, 89, 47.0);
168 
169     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_2",
170         case_recursive_boxes_2[0], case_recursive_boxes_2[1],
171         1, 50, 90.0); // Area from SQL Server
172     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_3",
173         case_recursive_boxes_3[0], case_recursive_boxes_3[1],
174         19, 84, 12.5); // Area from SQL Server
175 
176     TEST_INTERSECTION_IGNORE(case_recursive_boxes_4, 13, 158, 67.0);
177 
178     // Fixed by replacing handle_tangencies in less_by_segment_ratio sort order
179     // Should contain 6 output polygons
180     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_6",
181         case_recursive_boxes_6[0], case_recursive_boxes_6[1],
182         6, 42, 19.0);
183 
184     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_7",
185         case_recursive_boxes_7[0], case_recursive_boxes_7[1],
186         2, 9, 1.5);
187 
188     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_8",
189         case_recursive_boxes_8[0], case_recursive_boxes_8[1],
190         3, 19, 3.75);
191 
192     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_9",
193         case_recursive_boxes_9[0], case_recursive_boxes_9[1],
194         5, 27, 4.25);
195     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_10",
196         case_recursive_boxes_10[0], case_recursive_boxes_10[1],
197         2, 8, 0.75);
198     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_11",
199         case_recursive_boxes_11[0], case_recursive_boxes_11[1],
200         2, 8, 1.0);
201     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_12",
202         case_recursive_boxes_12[0], case_recursive_boxes_12[1],
203         1, 4, 0.5);
204     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_13",
205         case_recursive_boxes_13[0], case_recursive_boxes_13[1],
206         0, 0, 0.0);
207     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_14",
208         case_recursive_boxes_14[0], case_recursive_boxes_14[1],
209         0, 0, 0.0);
210     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_15",
211         case_recursive_boxes_15[0], case_recursive_boxes_15[1],
212         1, 4, 0.5);
213     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_16",
214         case_recursive_boxes_16[0], case_recursive_boxes_16[1],
215         9, 43, 10.0);
216     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_17",
217         case_recursive_boxes_17[0], case_recursive_boxes_17[1],
218         7, -1, 7.75);
219     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_18",
220         case_recursive_boxes_18[0], case_recursive_boxes_18[1],
221         0, 0, 0.0);
222     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_19",
223         case_recursive_boxes_19[0], case_recursive_boxes_19[1],
224         0, 0, 0.0);
225     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_20",
226         case_recursive_boxes_20[0], case_recursive_boxes_20[1],
227         2, 0, 1.0);
228     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_21",
229         case_recursive_boxes_21[0], case_recursive_boxes_21[1],
230         1, 0, 0.5);
231     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_22",
232         case_recursive_boxes_22[0], case_recursive_boxes_22[1],
233         0, 0, 0.0);
234     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_23",
235         case_recursive_boxes_23[0], case_recursive_boxes_23[1],
236         1, 0, 0.5);
237     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_24",
238         case_recursive_boxes_24[0], case_recursive_boxes_24[1],
239         1, 0, 0.5);
240     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_25",
241         case_recursive_boxes_25[0], case_recursive_boxes_25[1],
242         1, 0, 0.5);
243     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_26",
244         case_recursive_boxes_26[0], case_recursive_boxes_26[1],
245         1, 0, 2.5);
246     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_27",
247         case_recursive_boxes_27[0], case_recursive_boxes_27[1],
248         1, 0, 0.5);
249     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_28",
250         case_recursive_boxes_28[0], case_recursive_boxes_28[1],
251         2, 0, 1.0);
252     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_29",
253         case_recursive_boxes_29[0], case_recursive_boxes_29[1],
254         5, 0, 3.75);
255     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_30",
256         case_recursive_boxes_30[0], case_recursive_boxes_30[1],
257         4, 0, 6.0);
258     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_31",
259         case_recursive_boxes_31[0], case_recursive_boxes_31[1],
260         2, 0, 2.5);
261     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_32",
262         case_recursive_boxes_32[0], case_recursive_boxes_32[1],
263         2, 0, 1.75);
264     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_33",
265         case_recursive_boxes_33[0], case_recursive_boxes_33[1],
266         3, 0, 2.0);
267     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_34",
268         case_recursive_boxes_34[0], case_recursive_boxes_34[1],
269         2, 0, 17.25);
270     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_35",
271         case_recursive_boxes_35[0], case_recursive_boxes_35[1],
272         2, 0, 20.0);
273     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_36",
274         case_recursive_boxes_36[0], case_recursive_boxes_36[1],
275         1, 0, 0.5);
276     test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_37",
277         case_recursive_boxes_37[0], case_recursive_boxes_37[1],
278         2, 0, 1.0);
279 
280     TEST_INTERSECTION(case_recursive_boxes_39, 3, 0, 3.0);
281     TEST_INTERSECTION(case_recursive_boxes_40, 1, 0, 1.0);
282     TEST_INTERSECTION(case_recursive_boxes_41, 1, 0, 23.5);
283     TEST_INTERSECTION(case_recursive_boxes_42, 1, 29, 95.0);
284     TEST_INTERSECTION(case_recursive_boxes_43, 2, 0, 22.5);
285     TEST_INTERSECTION(case_recursive_boxes_44, 2, 0, 3.0);
286     TEST_INTERSECTION(case_recursive_boxes_45, 7, 0, 12.0);
287     TEST_INTERSECTION(case_recursive_boxes_46, 6, -1, 7.0);
288     TEST_INTERSECTION(case_recursive_boxes_47, 1, 5, 1.0);
289     TEST_INTERSECTION(case_recursive_boxes_48, 1, 5, 1.0);
290     TEST_INTERSECTION(case_recursive_boxes_49, 7, 57, 20.0);
291     TEST_INTERSECTION(case_recursive_boxes_50, 9, 62, 26.0);
292     TEST_INTERSECTION(case_recursive_boxes_51, 14, 74, 19.0);
293     TEST_INTERSECTION(case_recursive_boxes_52, 8, -1, 22.0);
294     TEST_INTERSECTION(case_recursive_boxes_53, 1, -1, 19.75);
295     TEST_INTERSECTION(case_recursive_boxes_54, 3, -1, 10.0);
296     TEST_INTERSECTION(case_recursive_boxes_55, 5, -1, 2.25);
297     TEST_INTERSECTION(case_recursive_boxes_56, 1, -1, 0.5);
298     TEST_INTERSECTION(case_recursive_boxes_57, 10, -1, 9.5);
299     TEST_INTERSECTION(case_recursive_boxes_58, 1, -1, 0.25);
300     TEST_INTERSECTION(case_recursive_boxes_59, 8, -1, 8.25);
301     TEST_INTERSECTION(case_recursive_boxes_60, 8, -1, 10.0);
302     TEST_INTERSECTION(case_recursive_boxes_61, 2, -1, 20.0);
303     TEST_INTERSECTION(case_recursive_boxes_62, 9, -1, 10.5);
304     TEST_INTERSECTION(case_recursive_boxes_63, 11, -1, 5.75);
305     TEST_INTERSECTION(case_recursive_boxes_64, 5, -1, 17.25);
306     TEST_INTERSECTION(case_recursive_boxes_65, 3, -1, 17.25);
307     TEST_INTERSECTION(case_recursive_boxes_66, 4, -1, 16.0);
308     TEST_INTERSECTION(case_recursive_boxes_67, 5, -1, 2.5);
309     TEST_INTERSECTION(case_recursive_boxes_68, 8, -1, 9.5);
310     TEST_INTERSECTION(case_recursive_boxes_69, 6, -1, 3.25);
311     TEST_INTERSECTION(case_recursive_boxes_70, 6, -1, 18.5);
312     TEST_INTERSECTION(case_recursive_boxes_71, 3, -1, 1.75);
313     TEST_INTERSECTION(case_recursive_boxes_72, 8, -1, 4.5);
314     TEST_INTERSECTION(case_recursive_boxes_73, 3, -1, 18.5);
315     TEST_INTERSECTION(case_recursive_boxes_74, 3, -1, 20.25);
316     TEST_INTERSECTION(case_recursive_boxes_75, 5, -1, 16.75);
317     TEST_INTERSECTION(case_recursive_boxes_76, 2, -1, 18.25);
318     TEST_INTERSECTION(case_recursive_boxes_77, 5, -1, 3.5);
319     TEST_INTERSECTION(case_recursive_boxes_78, 9, -1, 8.0);
320     TEST_INTERSECTION(case_recursive_boxes_79, 5, -1, 9.0);
321     TEST_INTERSECTION(case_recursive_boxes_80, 1, -1, 0.25);
322     TEST_INTERSECTION(case_recursive_boxes_81, 5, -1, 3.75);
323     TEST_INTERSECTION(case_recursive_boxes_82, 5, -1, 8.5);
324     TEST_INTERSECTION(case_recursive_boxes_83, 5, -1, 10.25);
325     TEST_INTERSECTION(case_recursive_boxes_84, 1, -1, 0.5);
326 #if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
327     TEST_INTERSECTION(case_recursive_boxes_85, 1, -1, 0.25);
328 #endif
329     TEST_INTERSECTION(case_recursive_boxes_86, 0, -1, 0.0);
330     TEST_INTERSECTION(case_recursive_boxes_87, 0, -1, 0.0);
331     TEST_INTERSECTION(case_recursive_boxes_88, 4, -1, 3.5);
332 
333 #if ! defined(BOOST_GEOMETRY_USE_RESCALING)
334     TEST_INTERSECTION(case_precision_m1, 1, -1, 14.0);
335     TEST_INTERSECTION(case_precision_m2, 2, -1, 15.25);
336     TEST_INTERSECTION_REV(case_precision_m1, 1, -1, 14.0);
337     TEST_INTERSECTION_REV(case_precision_m2, 2, -1, 15.25);
338 #else
339     // Validity: false positives (very small triangles looking like a line)
340     TEST_INTERSECTION_IGNORE(case_precision_m1, 1, -1, 14.0);
341     TEST_INTERSECTION_IGNORE(case_precision_m2, 2, -1, 15.25);
342 #endif
343 
344     test_one<Polygon, MultiPolygon, MultiPolygon>("ggl_list_20120915_h2_a",
345         ggl_list_20120915_h2[0], ggl_list_20120915_h2[1],
346         2, 10, 6.0); // Area from SQL Server
347     test_one<Polygon, MultiPolygon, MultiPolygon>("ggl_list_20120915_h2_b",
348         ggl_list_20120915_h2[0], ggl_list_20120915_h2[2],
349         2, 10, 6.0); // Area from SQL Server
350 
351     test_one<Polygon, MultiPolygon, MultiPolygon>("ticket_9081",
352         ticket_9081[0], ticket_9081[1],
353         2, 10, 0.0019812556);
354 
355     // Should generate output, even for <float>
356     test_one<Polygon, MultiPolygon, MultiPolygon>("mail_2019_01_21_johan",
357         mail_2019_01_21_johan[2], mail_2019_01_21_johan[3],
358         2, -1, 0.0005889587);
359 
360     // Very small slice is generated.
361     // qcc-arm reports 1.7791215549400884e-14
362     // With rescaling, generates very small triangle
363     test_one<Polygon, MultiPolygon, MultiPolygon>("ticket_11018",
364         ticket_11018[0], ticket_11018[1],
365         BG_IF_RESCALED(1, 0), 0,
366         1.0e-8, ut_settings(-1)
367     );
368 
369     TEST_INTERSECTION(ticket_12503, 2, 13, 17.375);
370 
371 #if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
372     // Result is wrong with rescaling
373     TEST_INTERSECTION(issue_630_a, 1, -1, 0.1770);
374 #endif
375 #if ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) || defined(BOOST_GEOMETRY_TEST_FAILURES)
376     // Two cases produce either too large, or no output if Kramer rule is used
377     TEST_INTERSECTION(issue_630_b, 1, -1, BG_IF_KRAMER(0.1714, 0.1713911));
378     TEST_INTERSECTION(issue_630_c, 1, -1, 0.1770);
379 #endif
380 
381 #if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
382     // Result is missing with rescaling
383     TEST_INTERSECTION(issue_643, 1, -1, 3.4615);
384 #endif
385 
386     test_one<Polygon, MultiPolygon, MultiPolygon>("mysql_23023665_7",
387         mysql_23023665_7[0], mysql_23023665_7[1],
388         2, 11, 9.80505786783);
389 
390     TEST_INTERSECTION(mysql_23023665_12, 2, 0, 11.812440191387557);
391     TEST_INTERSECTION(mysql_regression_1_65_2017_08_31, 2, -1, 29.9022122);
392 }
393 
394 template <typename Polygon, typename MultiPolygon, typename Box>
test_areal_clip()395 void test_areal_clip()
396 {
397     static std::string const clip = "POLYGON((1 1,4 4))";
398     test_one<Polygon, Box, MultiPolygon>("simplex_multi_mp_b", clip, case_multi_simplex[0],
399         2, 11, 6.791666);
400     test_one<Polygon, MultiPolygon, Box>("simplex_multi_b_mp", case_multi_simplex[0], clip,
401         2, 11, 6.791666);
402 }
403 
404 template <typename LineString, typename MultiLineString, typename Box>
test_linear()405 void test_linear()
406 {
407     typedef typename bg::point_type<MultiLineString>::type point;
408     test_one<point, MultiLineString, MultiLineString>("case_multi_ml_ml_1",
409         "MULTILINESTRING((0 0,1 1))", "MULTILINESTRING((0 1,1 0))",
410         1, 1, 0.0);
411     test_one<point, MultiLineString, MultiLineString>("case_multi_ml_ml_2",
412         "MULTILINESTRING((0 0,1 1),(0.5 0,1.5 1))", "MULTILINESTRING((0 1,1 0),(0.5 1,1.5 0))",
413         4, 4, 0.0);
414 
415     test_one<point, LineString, MultiLineString>("case_multi_l_ml",
416         "LINESTRING(0 0,1 1)", "MULTILINESTRING((0 1,1 0),(0.5 1,1.5 0))",
417         2, 2, 0.0);
418     test_one<point, MultiLineString, LineString>("case_multi_ml_l",
419         "MULTILINESTRING((0 1,1 0),(0.5 1,1.5 0))", "LINESTRING(0 0,1 1)",
420         2, 2, 0.0);
421 
422     test_one<LineString, MultiLineString, Box>("case_multi_ml_b",
423         "MULTILINESTRING((0 0,3 3)(1 0,4 3))", "POLYGON((1 1,3 2))",
424         2, 4, 2.0 * std::sqrt(2.0));
425     test_one<LineString, Box, MultiLineString>("case_multi_b_ml",
426         "POLYGON((1 1,3 2))", "MULTILINESTRING((0 0,3 3)(1 0,4 3))",
427         2, 4, 2.0 * std::sqrt(2.0));
428 }
429 
430 template <typename P>
test_point_output()431 void test_point_output()
432 {
433     typedef bg::model::box<P> box;
434     typedef bg::model::linestring<P> linestring;
435     typedef bg::model::polygon<P> polygon;
436     typedef bg::model::multi_polygon<polygon> multi_polygon;
437 
438     test_point_output<multi_polygon, multi_polygon>(case_multi_simplex[0], case_multi_simplex[1], 10);
439     test_point_output<linestring, multi_polygon>("linestring(4 0,0 4)", case_multi_simplex[0], 4);
440     test_point_output<box, multi_polygon>("box(3 0,4 6)", case_multi_simplex[0], 8);
441 }
442 
443 template <typename MultiPolygon, typename MultiLineString>
test_areal_linear()444 void test_areal_linear()
445 {
446     typedef typename boost::range_value<MultiPolygon>::type Polygon;
447     typedef typename boost::range_value<MultiLineString>::type LineString;
448     typedef typename bg::point_type<Polygon>::type Point;
449     typedef bg::model::ring<Point> Ring;
450 
451     test_one_lp<LineString, MultiPolygon, LineString>("case_mp_ls_1", case_multi_simplex[0], "LINESTRING(2 0,2 5)", 2, 4, 3.70);
452     test_one_lp<LineString, Polygon, MultiLineString>("case_p_mls_1", case_single_simplex, "MULTILINESTRING((2 0,2 5),(3 0,3 5))", 2, 4, 7.5);
453     test_one_lp<LineString, MultiPolygon, MultiLineString>("case_mp_mls_1", case_multi_simplex[0], "MULTILINESTRING((2 0,2 5),(3 0,3 5))", 4, 8, 6.8333333);
454     test_one_lp<LineString, Ring, MultiLineString>("case_r_mls_1", case_single_simplex, "MULTILINESTRING((2 0,2 5),(3 0,3 5))", 2, 4, 7.5);
455 }
456 
457 template <typename P>
test_all()458 void test_all()
459 {
460     typedef bg::model::ring<P> ring;
461     typedef bg::model::polygon<P> polygon;
462     typedef bg::model::multi_polygon<polygon> multi_polygon;
463     test_areal<ring, polygon, multi_polygon>();
464 
465 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
466 
467     typedef bg::model::ring<P, false> ring_ccw;
468     typedef bg::model::polygon<P, false> polygon_ccw;
469     typedef bg::model::multi_polygon<polygon_ccw> multi_polygon_ccw;
470     test_areal<ring_ccw, polygon_ccw, multi_polygon_ccw>();
471 
472     typedef bg::model::ring<P, true, false> ring_open;
473     typedef bg::model::polygon<P, true, false> polygon_open;
474     typedef bg::model::multi_polygon<polygon_open> multi_polygon_open;
475     test_areal<ring_open, polygon_open, multi_polygon_open>();
476 
477     typedef bg::model::ring<P, false, false> ring_open_ccw;
478     typedef bg::model::polygon<P, false, false> polygon_open_ccw;
479     typedef bg::model::multi_polygon<polygon_open_ccw> multi_polygon_open_ccw;
480     test_areal<ring_open_ccw, polygon_open_ccw, multi_polygon_open_ccw>();
481 
482     typedef bg::model::box<P> box;
483     test_areal_clip<polygon, multi_polygon, box>();
484     test_areal_clip<polygon_ccw, multi_polygon_ccw, box>();
485 
486     typedef bg::model::linestring<P> linestring;
487     typedef bg::model::multi_linestring<linestring> multi_linestring;
488 
489     test_linear<linestring, multi_linestring, box>();
490     test_areal_linear<multi_polygon, multi_linestring>();
491 #endif
492 
493     test_point_output<P>();
494     // linear
495 
496 }
497 
498 
test_main(int,char * [])499 int test_main(int, char* [])
500 {
501     BoostGeometryWriteTestConfiguration();
502     test_all<bg::model::d2::point_xy<default_test_type> >();
503 
504 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
505     test_all<bg::model::d2::point_xy<float> >();
506 
507 #if defined(HAVE_TTMATH)
508     std::cout << "Testing TTMATH" << std::endl;
509     test_all<bg::model::d2::point_xy<ttmath_big> >();
510 #endif
511 
512 #endif
513 
514     return 0;
515 }
516