• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 2015, 2016.
7 // Modifications copyright (c) 2015-2016, Oracle and/or its affiliates.
8 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14 
15 #include <iomanip>
16 #include <iostream>
17 #include <sstream>
18 #include <string>
19 
20 #include <boost/geometry/algorithms/correct.hpp>
21 #include <boost/geometry/algorithms/is_valid.hpp>
22 
23 #include <boost/geometry/io/wkt/wkt.hpp>
24 
25 #include <boost/geometry/geometries/point_xy.hpp>
26 
27 #include "test_difference.hpp"
28 #include <algorithms/test_overlay.hpp>
29 #include <algorithms/overlay/overlay_cases.hpp>
30 #include <algorithms/overlay/multi_overlay_cases.hpp>
31 
32 
33 #ifdef HAVE_TTMATH
34 #  include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
35 #endif
36 
37 
38 // Convenience macros (points are not checked)
39 #define TEST_DIFFERENCE(caseid, clips1, area1, clips2, area2, clips3) \
40     (test_one<polygon, polygon, polygon>) \
41     ( #caseid, caseid[0], caseid[1], clips1, -1, area1, clips2, -1, area2, \
42                 clips3, -1, area1 + area2)
43 
44 #define TEST_DIFFERENCE_WITH(caseid, clips1, area1, clips2, area2, clips3) \
45     (test_one<polygon, polygon, polygon>) \
46     ( #caseid, caseid[0], caseid[1], clips1, -1, area1, clips2, -1, area2, \
47                 clips3, -1, area1 + area2, settings)
48 
49 template <typename P>
test_all()50 void test_all()
51 {
52     typedef bg::model::polygon<P> polygon;
53 
54     typedef typename bg::coordinate_type<P>::type ct;
55 
56     ut_settings sym_settings;
57 #if ! defined(BOOST_GEOMETRY_USE_RESCALING)
58     sym_settings.sym_difference = false;
59 #endif
60 
61     ut_settings ignore_validity_settings;
62     ignore_validity_settings.set_test_validity(false);
63 
64     test_one<polygon, polygon, polygon>("simplex_normal",
65         simplex_normal[0], simplex_normal[1],
66         3, 12, 2.52636706856656,
67         3, 12, 3.52636706856656,
68         sym_settings);
69 
70     test_one<polygon, polygon, polygon>("simplex_with_empty",
71         simplex_normal[0], polygon_empty,
72         1, 4, 8.0,
73         0, 0, 0.0);
74 
75     test_one<polygon, polygon, polygon>(
76             "star_ring", example_star, example_ring,
77             5, 22, 1.1901714,
78             5, 27, 1.6701714,
79             sym_settings);
80 
81     test_one<polygon, polygon, polygon>("two_bends",
82         two_bends[0], two_bends[1],
83         1, 5, 8.0,
84         1, 5, 8.0);
85 
86     test_one<polygon, polygon, polygon>("star_comb_15",
87         star_comb_15[0], star_comb_15[1],
88         30, -1, 227.658275102812,
89         30, -1, 480.485775259312,
90         sym_settings);
91 
92     test_one<polygon, polygon, polygon>("new_hole",
93         new_hole[0], new_hole[1],
94         1, 9, 7.0,
95         1, 13, 14.0);
96 
97 
98     test_one<polygon, polygon, polygon>("crossed",
99         crossed[0], crossed[1],
100         1, 18, 19.5,
101         1, 7, 2.5);
102 
103     test_one<polygon, polygon, polygon>("disjoint",
104         disjoint[0], disjoint[1],
105         1, 5, 1.0,
106         1, 5, 1.0);
107 
108     // Two outputs, but the small one might be discarded
109     // (depending on point-type / compiler)
110     test_one<polygon, polygon, polygon>("distance_zero",
111         distance_zero[0], distance_zero[1],
112         count_set(1, 2), -1, 8.7048386,
113         count_set(1, 2), -1, 0.0098387,
114         tolerance(0.001));
115 
116     test_one<polygon, polygon, polygon>("equal_holes_disjoint",
117         equal_holes_disjoint[0], equal_holes_disjoint[1],
118         1, 5, 9.0,
119         1, 5, 9.0);
120 
121     test_one<polygon, polygon, polygon>("only_hole_intersections1",
122         only_hole_intersections[0], only_hole_intersections[1],
123         2, 10,  1.9090909,
124         4, 16, 10.9090909,
125         sym_settings);
126 
127     test_one<polygon, polygon, polygon>("only_hole_intersection2",
128         only_hole_intersections[0], only_hole_intersections[2],
129         3, 20, 30.9090909,
130         4, 16, 10.9090909,
131         sym_settings);
132 
133     test_one<polygon, polygon, polygon>("first_within_second",
134         first_within_second[1], first_within_second[0],
135         1, 10, 24,
136         0, 0, 0);
137 
138     test_one<polygon, polygon, polygon>("fitting",
139         fitting[0], fitting[1],
140         1, 9, 21.0,
141         1, 4, 4.0,
142         1, 5, 25.0);
143 
144     test_one<polygon, polygon, polygon>("identical",
145         identical[0], identical[1],
146         0, 0, 0.0,
147         0, 0, 0.0);
148 
149     test_one<polygon, polygon, polygon>("intersect_exterior_and_interiors_winded",
150         intersect_exterior_and_interiors_winded[0], intersect_exterior_and_interiors_winded[1],
151         4, 20, 11.533333,
152         5, 26, 29.783333);
153 
154     test_one<polygon, polygon, polygon>("intersect_holes_intersect_and_disjoint",
155         intersect_holes_intersect_and_disjoint[0], intersect_holes_intersect_and_disjoint[1],
156         2, 16, 15.75,
157         3, 17, 6.75,
158         ignore_validity_settings);
159 
160     test_one<polygon, polygon, polygon>("intersect_holes_intersect_and_touch",
161         intersect_holes_intersect_and_touch[0], intersect_holes_intersect_and_touch[1],
162         3, 21, 16.25,
163         3, 17, 6.25,
164         ignore_validity_settings);
165 
166     {
167         ut_settings settings = sym_settings;
168         settings.percentage = 0.01;
169         test_one<polygon, polygon, polygon>("intersect_holes_new_ring",
170             intersect_holes_new_ring[0], intersect_holes_new_ring[1],
171             3, 15, 9.8961,
172             4, 25, 121.8961,
173             settings);
174     }
175 
176     test_one<polygon, polygon, polygon>("first_within_hole_of_second",
177         first_within_hole_of_second[0], first_within_hole_of_second[1],
178         1, 5, 1,
179         1, 10, 16);
180 
181     test_one<polygon, polygon, polygon>("intersect_holes_disjoint",
182         intersect_holes_disjoint[0], intersect_holes_disjoint[1],
183         2, 14, 16.0,
184         2, 10, 6.0);
185 
186     test_one<polygon, polygon, polygon>("intersect_holes_intersect",
187         intersect_holes_intersect[0], intersect_holes_intersect[1],
188         2, 16, 15.75,
189         2, 12, 5.75,
190         ignore_validity_settings);
191 
192     test_one<polygon, polygon, polygon>(
193             "case4", case_4[0], case_4[1],
194             6, 28, 2.77878787878788,
195             4, 22, 4.77878787878788,
196             sym_settings);
197 
198     test_one<polygon, polygon, polygon>(
199             "case5", case_5[0], case_5[1],
200             8, 36, 2.43452380952381,
201             7, 33, 3.18452380952381);
202 
203     test_one<polygon, polygon, polygon>("case_58_iet",
204         case_58[0], case_58[2],
205         3, 12, 0.6666666667,
206         1, -1, 11.1666666667,
207         2, -1, 0.6666666667 + 11.1666666667);
208 
209     test_one<polygon, polygon, polygon>("case_80",
210         case_80[0], case_80[1],
211         1, 9, 44.5,
212         1, 10, 84.5);
213 
214     // Fails without rescaling, holes are not subtracted
215     test_one<polygon, polygon, polygon>("case_81",
216         case_81[0], case_81[1],
217         1, 8, 80.5,
218         1, 8, 83.0,
219         1, 12, 80.5 + 83.0);
220 
221     test_one<polygon, polygon, polygon>("case_100",
222         case_100[0], case_100[1],
223         1, 7, 3.125,
224         1, 7, 16.0,
225         1, 13, 16.0 + 3.125);
226 
227     test_one<polygon, polygon, polygon>("case_101",
228         case_101[0], case_101[1],
229         3, 17, 13.75,
230         1, 4, 1.0);
231 
232     test_one<polygon, polygon, polygon>("case_102",
233         case_102[0], case_102[1],
234         4, 18, 1.5,
235         3, 15, 4.0625);
236 
237     TEST_DIFFERENCE(case_105, 4, 8.0, 1, 16.0, 5);
238     TEST_DIFFERENCE(case_106, 1, 17.5, 2, 32.5, 3);
239     TEST_DIFFERENCE(case_107, 2, 18.0, 2, 29.0, 4);
240 
241     TEST_DIFFERENCE(case_precision_1, 1, 14.0, 1, BG_IF_KRAMER(8.00001, 8.0), 1);
242     TEST_DIFFERENCE(case_precision_2, 1, 14.0, 1, 8.0, 1);
243     TEST_DIFFERENCE(case_precision_3, 1, 14.0, 1, 8.0, 1);
244     TEST_DIFFERENCE(case_precision_4, 1, 14.0, 1, 8.0, 1);
245     TEST_DIFFERENCE(case_precision_5, 1, 14.0, 1, 8.0, count_set(1, 2));
246     // Small optional sliver allowed, here and below
247     TEST_DIFFERENCE(case_precision_6, optional(), 0.0, 1, 57.0, count_set(1, 2));
248     TEST_DIFFERENCE(case_precision_7, 1, 14.0, 1, 8.0, 1);
249     TEST_DIFFERENCE(case_precision_8, 0, 0.0, 1, 59.0, 1);
250     TEST_DIFFERENCE(case_precision_9, optional(), 0.0, 1, 59.0, count_set(1, 2));
251     TEST_DIFFERENCE(case_precision_10, optional(), 0.0, 1, 59.0, count_set(1, 2));
252 #if ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) || defined(BOOST_GEOMETRY_TEST_FAILURES)
253     TEST_DIFFERENCE(case_precision_11, optional(), 0.0, 1, 59.0, 1);
254 #endif
255     TEST_DIFFERENCE(case_precision_12, 1, 12.0, 0, 0.0, 1);
256     TEST_DIFFERENCE(case_precision_13, 1, BG_IF_KRAMER(12.00002, 12.0), 0, 0.0, 1);
257     TEST_DIFFERENCE(case_precision_14, 1, 14.0, 1, 8.0, 1);
258     TEST_DIFFERENCE(case_precision_15, 0, 0.0, 1, 59.0, 1);
259     TEST_DIFFERENCE(case_precision_16, optional(), 0.0, 1, 59.0, 1);
260     TEST_DIFFERENCE(case_precision_17, 0, 0.0, 1, 59.0, 1);
261     TEST_DIFFERENCE(case_precision_18, 0, 0.0, 1, 59.0, 1);
262     TEST_DIFFERENCE(case_precision_19, 1, 0.0, 1, 59.0, 2);
263     TEST_DIFFERENCE(case_precision_20, 1, 14.0, 1, 8.0, 1);
264     TEST_DIFFERENCE(case_precision_21, 1, 14.0, 1, 7.99999, 1);
265     TEST_DIFFERENCE(case_precision_22, optional(), 0.0, 1, 59.0, count_set(1, 2));
266     TEST_DIFFERENCE(case_precision_23, optional(), 0.0, 1, 59.0, count_set(1, 2));
267     TEST_DIFFERENCE(case_precision_24, 1, 14.0, 1, 8.0, 1);
268     TEST_DIFFERENCE(case_precision_25, 1, 14.0, 1, 7.99999, 1);
269     TEST_DIFFERENCE(case_precision_26, optional(), 0.0, 1, 59.0, count_set(1, 2));
270 
271     test_one<polygon, polygon, polygon>("winded",
272         winded[0], winded[1],
273         3, 37, 61,
274         1, 15, 13);
275 
276     test_one<polygon, polygon, polygon>("within_holes_disjoint",
277         within_holes_disjoint[0], within_holes_disjoint[1],
278         2, 15, 25,
279         1, 5, 1);
280 
281     test_one<polygon, polygon, polygon>("side_side",
282         side_side[0], side_side[1],
283         1, 5, 1,
284         1, 5, 1,
285         1, 7, 2);
286 
287     test_one<polygon, polygon, polygon>("buffer_mp1",
288         buffer_mp1[0], buffer_mp1[1],
289         1, 61, 10.2717,
290         1, 61, 10.2717);
291 
292     if ( BOOST_GEOMETRY_CONDITION((boost::is_same<ct, double>::value)) )
293     {
294         test_one<polygon, polygon, polygon>("buffer_mp2",
295             buffer_mp2[0], buffer_mp2[1],
296             1, 91, 12.09857,
297             1, 155, 24.19714,
298             BG_IF_RESCALED(2, 1), -1, 12.09857 + 24.19714);
299     }
300 
301     /*** TODO: self-tangencies for difference
302     test_one<polygon, polygon, polygon>("wrapped_a",
303         wrapped[0], wrapped[1],
304         3, 1, 61,
305         1, 0, 13);
306 
307     test_one<polygon, polygon, polygon>("wrapped_b",
308         wrapped[0], wrapped[2],
309         3, 1, 61,
310         1, 0, 13);
311     ***/
312 
313     {
314         ut_settings settings;
315         settings.percentage = BG_IF_RESCALED(0.001, 0.1);
316         settings.set_test_validity(BG_IF_RESCALED(true, false));
317         settings.sym_difference = BG_IF_RESCALED(true, false);
318 
319         // Isovist - the # output polygons differ per compiler/pointtype, (very) small
320         // rings might be discarded. We check area only
321 
322         // SQL Server gives:    0.279121891701124 and 224.889211358929
323         // PostGIS gives:       0.279121991127244 and 224.889205853156
324         // No robustness gives: 0.279121991127106 and 224.825363749290
325 
326         test_one<polygon, polygon, polygon>("isovist",
327             isovist1[0], isovist1[1],
328             ignore_count(), -1, 0.279132,
329             ignore_count(), -1, 224.8892,
330             settings);
331     }
332 
333 #if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
334     {
335         ut_settings settings;
336         settings.percentage = 0.1;
337         settings.set_test_validity(false);
338 
339         // SQL Server gives: 0.28937764436705 and 0.000786406897532288 with 44/35 rings
340         // PostGIS gives:    0.30859375       and 0.033203125 with 35/35 rings
341         TEST_DIFFERENCE_WITH(geos_1,
342             ignore_count(), BG_IF_KRAMER(0.29171, 0.20705),
343             ignore_count(), BG_IF_KRAMER(0.00076855, 0.00060440758),
344             ignore_count());
345     }
346 #endif
347 
348     {
349         // MSVC 14 expects 138.69214 and 211.85913: increase percentage
350 
351         ut_settings settings = sym_settings;
352         settings.percentage = 0.01;
353         settings.set_test_validity(false);
354 
355         // Output polygons for sym difference might be combined
356         test_one<polygon, polygon, polygon>("geos_2",
357             geos_2[0], geos_2[1],
358             1, -1, 138.6923828,
359             1, -1, 211.859375,
360             BG_IF_RESCALED(2, 1), -1, 138.6923828 + 211.859375,
361             settings);
362     }
363 
364     // Output polygons for sym difference might be combined
365     test_one<polygon, polygon, polygon>("geos_3",
366         geos_3[0], geos_3[1],
367         1, -1, 16211128.5,
368         1, -1, 13180420.0,
369         BG_IF_RESCALED(1, 2), -1, 16211128.5 + 13180420.0,
370         sym_settings);
371 
372     test_one<polygon, polygon, polygon>("geos_4",
373         geos_4[0], geos_4[1],
374         1, -1, 971.9163115,
375         1, -1, 1332.4163115,
376         sym_settings);
377 
378     test_one<polygon, polygon, polygon>("ggl_list_20110306_javier",
379         ggl_list_20110306_javier[0], ggl_list_20110306_javier[1],
380         1, -1, 71495.3331,
381         2, -1, 8960.49049,
382         2, -1, 71495.3331 + 8960.49049);
383 
384     test_one<polygon, polygon, polygon>("ggl_list_20110307_javier",
385         ggl_list_20110307_javier[0], ggl_list_20110307_javier[1],
386         1, if_typed<ct, float>(14, 13), 16815.6,
387         1, 4, 3200.4,
388         tolerance(0.01));
389 
390     if ( BOOST_GEOMETRY_CONDITION((! boost::is_same<ct, float>::value)) )
391     {
392         TEST_DIFFERENCE(ggl_list_20110716_enrico,
393             3, 35723.8506317139, // TODO FOR GENERIC, misses one of three outputs
394             1, 58456.4964294434,
395             1);
396     }
397 
398 #if defined(BOOST_GEOMETRY_USE_RESCALING) \
399     || ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) \
400     || defined(BOOST_GEOMETRY_TEST_FAILURES)
401     {
402         // Symmetric difference should output one polygon
403         // Using rescaling, it currently outputs two.
404         ut_settings settings;
405         settings.set_test_validity(false);
406 
407         TEST_DIFFERENCE_WITH(ggl_list_20110820_christophe,
408             1, 2.8570121719168924,
409             1, 64.498061986388564,
410             BG_IF_RESCALED(2, 1));
411     }
412 #endif
413 
414     test_one<polygon, polygon, polygon>("ggl_list_20120717_volker",
415         ggl_list_20120717_volker[0], ggl_list_20120717_volker[1],
416         1, 11, 3370866.2295081965,
417         1, 5, 384.2295081964694,
418         tolerance(0.01));
419 
420     // 2011-07-02 / 2014-06-19
421     // Interesting FP-precision case.
422     // sql server gives: 6.62295817619452E-05
423     // PostGIS gives: 0.0 (no output)
424     // Boost.Geometry gave results depending on FP-type, and compiler, and operating system.
425     // With rescaling results are equal w.r.t. compiler/FP type,
426     // however, some long spikes are still generated in the resulting difference
427     // Without rescaling there is no output, like PostGIS
428     test_one<polygon, polygon, polygon>("ggl_list_20110627_phillip",
429         ggl_list_20110627_phillip[0], ggl_list_20110627_phillip[1],
430         BG_IF_RESCALED(1, 0), -1,
431         BG_IF_RESCALED(if_typed_tt<ct>(0.0000000000001105367, 0.000125137888971949), 0),
432         1, -1, 3577.40960816756,
433         tolerance(0.01)
434         );
435 
436     {
437         // With rescaling, difference of output a-b and a sym b is invalid
438         ut_settings settings;
439         settings.set_test_validity(BG_IF_RESCALED(false, true));
440         TEST_DIFFERENCE_WITH(ggl_list_20190307_matthieu_1,
441                 count_set(1, 2), 0.18461532,
442                 count_set(1, 2), 0.617978,
443                 count_set(3, 4));
444         TEST_DIFFERENCE_WITH(ggl_list_20190307_matthieu_2, 2, 12.357152, 0, 0.0, 2);
445     }
446 
447     // Ticket 8310, one should be completely subtracted from the other.
448     test_one<polygon, polygon, polygon>("ticket_8310a",
449         ticket_8310a[0], ticket_8310a[1],
450         1, 10, 10.11562724,
451         0, 0, 0);
452     test_one<polygon, polygon, polygon>("ticket_8310b",
453         ticket_8310b[0], ticket_8310b[1],
454         1, 10, 10.12655608,
455         0, 0, 0);
456     test_one<polygon, polygon, polygon>("ticket_8310c",
457         ticket_8310c[0], ticket_8310c[1],
458         1, 10, 10.03103292,
459         0, 0, 0);
460 
461     test_one<polygon, polygon, polygon>("ticket_9081_15",
462             ticket_9081_15[0], ticket_9081_15[1],
463             2, -1, 0.0334529710902111,
464             BG_IF_RESCALED(1, 0), -1, BG_IF_RESCALED(5.3469555172380723e-010, 0));
465 
466     test_one<polygon, polygon, polygon>("ticket_9081_314",
467             ticket_9081_314[0], ticket_9081_314[1],
468             2, 12, 0.0451236449624935,
469             0, 0, 0);
470 
471     {
472         ut_settings settings;
473         settings.set_test_validity(BG_IF_RESCALED(true, false));
474 #if ! defined(BOOST_GEOMETRY_USE_RESCALING) && defined(BOOST_GEOMETRY_USE_KRAMER_RULE)
475         const int expected_count = 1; // Wrong, considers all consecutive polygons as one
476 #else
477         const int expected_count = 6;
478 #endif
479         TEST_DIFFERENCE_WITH(ticket_9563,
480                 0, 0,
481                 expected_count, 20.096189,
482                 expected_count);
483     }
484 
485     test_one<polygon, polygon, polygon>("ticket_10108_a",
486             ticket_10108_a[0], ticket_10108_a[1],
487             1, 4,  0.0145037,
488             1, 4,  0.029019232,
489             sym_settings);
490 
491     test_one<polygon, polygon, polygon>("ticket_10108_b",
492             ticket_10108_b[0], ticket_10108_b[1],
493             1, -1, 1081.68697,
494             1, -1, 1342.65795,
495             BG_IF_RESCALED(2, 1), -1, 1081.68697 + 1342.65795);
496 
497     test_one<polygon, polygon, polygon>("ticket_11725",
498         ticket_11725[0], ticket_11725[1],
499         1, -1, 3.0,
500         1, -1, 4.5,
501         1, -1, 7.5);
502 
503     // From assemble-test, with a u/u case
504     test_one<polygon, polygon, polygon>("assemble_0210",
505             "POLYGON((0 0,0 10,10 10,10 0,0 0),(8.5 1,9.5 1,9.5 2,8.5 2,8.5 1))",
506             "POLYGON((2 0.5,0.5 2,0.5 8,2 9.5,6 9.5,8.5 8,8.5 2,7 0.5,2 0.5),(2 2,7 2,7 8,2 8,2 2))",
507             2, 23, 62.25,
508             0, 0, 0.0);
509 
510 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
511     typedef bg::model::box<P> box;
512     typedef bg::model::ring<P> ring;
513 
514     // Other combinations
515     {
516         test_one<polygon, polygon, ring>(
517                 "star_ring_ring", example_star, example_ring,
518                 5, 22, 1.1901714,
519                 5, 27, 1.6701714,
520                 sym_settings);
521 
522         test_one<polygon, ring, polygon>(
523                 "ring_star_ring", example_ring, example_star,
524                 5, 27, 1.6701714,
525                 5, 22, 1.1901714,
526                 sym_settings);
527 
528         static std::string const clip = "POLYGON((2.5 0.5,5.5 2.5))";
529 
530         test_one<polygon, box, ring>("star_box",
531             clip, example_star,
532             4, 20, 2.833333, 4, 16, 0.833333);
533 
534         test_one<polygon, ring, box>("box_star",
535             example_star, clip,
536             4, 16, 0.833333, 4, 20, 2.833333);
537     }
538 
539     // Counter clockwise
540     {
541         typedef bg::model::polygon<P, false> polygon_ccw;
542         test_one<polygon, polygon_ccw, polygon_ccw>(
543                 "star_ring_ccw", example_star, example_ring,
544                 5, 22, 1.1901714,
545                 5, 27, 1.6701714,
546                 sym_settings);
547         test_one<polygon, polygon, polygon_ccw>(
548                 "star_ring_ccw1", example_star, example_ring,
549                 5, 22, 1.1901714,
550                 5, 27, 1.6701714,
551                 sym_settings);
552         test_one<polygon, polygon_ccw, polygon>(
553                 "star_ring_ccw2", example_star, example_ring,
554                 5, 22, 1.1901714,
555                 5, 27, 1.6701714,
556                 sym_settings);
557     }
558 
559     // Multi/box (should be moved to multi)
560     {
561         typedef bg::model::multi_polygon<polygon> mp;
562 
563         static std::string const clip = "POLYGON((2 2,4 4))";
564 
565         test_one<polygon, box, mp>("simplex_multi_box_mp",
566             clip, case_multi_simplex[0],
567             2, -1, 0.53333333333, 3, -1, 8.53333333333);
568         test_one<polygon, mp, box>("simplex_multi_mp_box",
569             case_multi_simplex[0], clip,
570             3, -1, 8.53333333333, 2, -1, 0.53333333333);
571 
572     }
573 #endif
574 
575     // Rescaling generates a very small false polygon
576     {
577         ut_settings settings;
578 #if defined(BOOST_GEOMETRY_USE_KRAMER_RULE)
579         settings.set_test_validity(BG_IF_RESCALED(true, false));
580 #endif
581         TEST_DIFFERENCE_WITH(issue_566_a, 1, 143.662, BG_IF_RESCALED(1, 0),
582                              BG_IF_RESCALED(1.605078e-6, 0.0),
583                              BG_IF_RESCALED(2, 1));
584     }
585     TEST_DIFFERENCE(issue_566_b, 1, 143.662, BG_IF_RESCALED(1, 0),
586                     BG_IF_RESCALED(1.605078e-6, 0.0),
587                     BG_IF_RESCALED(2, 1));
588 
589     TEST_DIFFERENCE(mysql_21977775, 2, 160.856568913, 2, 92.3565689126, 4);
590     TEST_DIFFERENCE(mysql_21965285, 1, 92.0, 1, 14.0, 1);
591     TEST_DIFFERENCE(mysql_23023665_1, 1, 92.0, 1, 142.5, 2);
592     TEST_DIFFERENCE(mysql_23023665_2, 1, 96.0, 1, 16.0, 2);
593     TEST_DIFFERENCE(mysql_23023665_3, 1, 225.0, 1, 66.0, 2);
594     TEST_DIFFERENCE(mysql_23023665_5, 2, 165.23735, 2, 105.73735, 4);
595 #if defined(BOOST_GEOMETRY_USE_RESCALING) \
596     || ! defined(BOOST_GEOMETRY_USE_KRAMER_RULE) \
597     || defined(BOOST_GEOMETRY_TEST_FAILURES)
598     // Testcases going wrong with Kramer's rule and no rescaling
599     TEST_DIFFERENCE(mysql_23023665_6, 2, 105.68756, 3, 10.18756, 5);
600     TEST_DIFFERENCE(mysql_23023665_13, 3, 99.74526, 3, 37.74526, 6);
601 #endif
602 }
603 
604 
605 // Test cases for integer coordinates / ccw / open
606 template <typename Point, bool ClockWise, bool Closed>
test_specific()607 void test_specific()
608 {
609     typedef bg::model::polygon<Point, ClockWise, Closed> polygon;
610 
611     test_one<polygon, polygon, polygon>("ggl_list_20120717_volker",
612         ggl_list_20120717_volker[0], ggl_list_20120717_volker[1],
613         1, 11, 3371540,
614         1, 4, 385,
615         1, 16, 3371540 + 385);
616 
617     test_one<polygon, polygon, polygon>("ticket_10658",
618         ticket_10658[0], ticket_10658[1],
619         1, 6, 1510434,
620         0, 0, 0);
621 
622     test_one<polygon, polygon, polygon>("ticket_11121",
623         ticket_11121[0], ticket_11121[1],
624         2, 8, 489763.5,
625         1, 4, 6731652.0);
626 
627     // Generates spikes, both a-b and b-a
628     TEST_DIFFERENCE(ticket_11676, 2, 2537992.5, 2, 294963.5, 3);
629 }
630 
test_main(int,char * [])631 int test_main(int, char* [])
632 {
633     BoostGeometryWriteTestConfiguration();
634     test_all<bg::model::d2::point_xy<default_test_type> >();
635 
636     test_specific<bg::model::d2::point_xy<int>, false, false>();
637 
638 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
639     test_all<bg::model::d2::point_xy<float> >();
640 
641 #ifdef HAVE_TTMATH
642     std::cout << "Testing TTMATH" << std::endl;
643     test_all<bg::model::d2::point_xy<ttmath_big> >();
644 #endif
645 #endif
646 
647 #if defined(BOOST_GEOMETRY_TEST_FAILURES)
648     BoostGeometryWriteExpectedFailures(12, 9);
649 #endif
650 
651     return 0;
652 }
653