Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / geometry / test / multi / algorithms / multi_difference_spike.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2013 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 #include <boost/geometry.hpp>
12 #include <boost/geometry/geometries/geometries.hpp>
13 #include <boost/geometry/geometries/point_xy.hpp>
14 #include <boost/geometry/multi/geometries/multi_geometries.hpp>
15
16 #include <algorithms/test_difference.hpp>
17
18
19 template <typename P, bool ClockWise, bool Closed>
20 void test_spikes_in_ticket_8364()
21 {
22     // See: https://svn.boost.org/trac/boost/ticket/8364
23     //_TPolygon<T> polygon( "MULTIPOLYGON(((1031 1056,3232 1056,3232 2856,1031 2856)))" );
24     //polygon -= _TPolygon<T>( "MULTIPOLYGON(((1032 1458,1032 1212,2136 2328,3234 2220,3234 2412,2136 2646)))" );
25     //polygon -= _TPolygon<T>( "MULTIPOLYGON(((1032 1764,1032 1458,2136 2646,3234 2412,3234 2532,2136 2790)))" );
26     // RESULTS OF ABOVE IS USED IN STEP 3 BELOW
27     //polygon -= _TPolygon<T>( "MULTIPOLYGON(((1032 2130,1032 1764,2052 2712)),((3234 2580,2558 2690,3234 2532)),((2558 2690,2136 2790,2052 2712,2136 2760)))" ); USED IN STEP 3
28     //polygon -= _TPolygon<T>( "MULTIPOLYGON(((1032 2556,1032 2130,1778 2556)),((3234 2580,2136 2760,1778 2556,3234 2556)))" ); USED IN STEP 4
29     // NOTE: polygons below are closed and clockwise
30
31     typedef typename bg::coordinate_type<P>::type ct;
32     typedef bg::model::polygon<P, ClockWise, Closed> polygon;
33     typedef bg::model::multi_polygon<polygon> multi_polygon;
34
35     // The difference of polygons below result in a spike. The spike should be there, it is also generated in ttmath,
36     // and (e.g.) in SQL Server. However, using int-coordinates, the spike makes the polygon invalid. Therefore it is now (since August 2013) checked and removed.
37
38     // So using int's, the spike is removed automatically. Therefore there is one polygon less, and less points. Also area differs
39     test_one<polygon, multi_polygon, multi_polygon>("ticket_8364_step3",
40         "MULTIPOLYGON(((3232 2532,2136 2790,1032 1764,1032 1458,1032 1212,2136 2328,3232 2220,3232 1056,1031 1056,1031 2856,3232 2856,3232 2532)))",
41         "MULTIPOLYGON(((1032 2130,2052 2712,1032 1764,1032 2130)),((3234 2580,3234 2532,2558 2690,3234 2580)),((2558 2690,2136 2760,2052 2712,2136 2790,2558 2690)))",
42         2,
43         if_typed<ct, int>(19, 22),
44         if_typed<ct, int>(2775595.5, 2775256.487954), // SQL Server: 2775256.47588724
45         3,
46         -1, // don't check point-count
47         if_typed<ct, int>(7907.0, 7810.487954)); // SQL Server: 7810.48711165739
48
49     test_one<polygon, multi_polygon, multi_polygon>("ticket_8364_step4",
50         "MULTIPOLYGON(((2567 2688,2136 2790,2052 2712,1032 2130,1032 1764,1032 1458,1032 1212,2136 2328,3232 2220,3232 1056,1031 1056,1031 2856,3232 2856,3232 2580,2567 2688)))",
51         "MULTIPOLYGON(((1032 2556,1778 2556,1032 2130,1032 2556)),((3234 2580,3234 2556,1778 2556,2136 2760,3234 2580)))",
52         1,
53         if_typed<ct, int>(17, 20),
54         if_typed<ct, int>(2616125.0, 2616029.559567), // SQL Server: 2616029.55616044
55         1,
56         if_typed<ct, int>(9, 11),
57         if_typed<ct, int>(161211.5, 161054.559567)); // SQL Server: 161054.560110092
58 }
59
60 template <typename P, bool ClockWise, bool Closed>
61 void test_spikes_in_ticket_8365()
62 {
63     // See: https://svn.boost.org/trac/boost/ticket/8365
64     // NOTE: polygons below are closed and clockwise
65
66     typedef typename bg::coordinate_type<P>::type ct;
67     typedef bg::model::polygon<P, ClockWise, Closed> polygon;
68     typedef bg::model::multi_polygon<polygon> multi_polygon;
69
70     test_one<polygon, multi_polygon, multi_polygon>("ticket_8365_step2",
71         "MULTIPOLYGON(((971 2704,971 1402,4640 1402,3912 1722,3180 2376,3912 1884,4643 1402,5395 1402,5395 3353,971 3353,971 2865,1704 3348)))",
72         "MULTIPOLYGON(((5388 1560,4650 1722,3912 1884,4650 1398)),((2442 3186,1704 3348,966 2700,1704 3024)))",
73         if_typed<ct, int>(1, 2),
74         if_typed<ct, int>(17, 21),
75         if_typed<ct, int>(7974930.5, 7975207.6047877), // SQL Server:
76         2,
77         -1,
78         if_typed<ct, int>(196.5, 197.1047877)); // SQL Server:
79 }
80
81
82
83
84
85 int test_main(int, char* [])
86 {
87     test_spikes_in_ticket_8364<bg::model::d2::point_xy<double>, true, true>();
88     test_spikes_in_ticket_8364<bg::model::d2::point_xy<double>, false, false>();
89     test_spikes_in_ticket_8365<bg::model::d2::point_xy<double>, true, true>();
90     test_spikes_in_ticket_8365<bg::model::d2::point_xy<double>, false, false>();
91
92     test_spikes_in_ticket_8364<bg::model::d2::point_xy<int>, true, true>();
93     test_spikes_in_ticket_8364<bg::model::d2::point_xy<int>, false, false>();
94     test_spikes_in_ticket_8365<bg::model::d2::point_xy<int>, true, true >();
95     test_spikes_in_ticket_8365<bg::model::d2::point_xy<int>, false, false >();
96
97 #ifdef HAVE_TTMATH
98     std::cout << "Testing TTMATH" << std::endl;
99     test_spikes_in_ticket_8364<bg::model::d2::point_xy<ttmath_big>, true, true>();
100     test_spikes_in_ticket_8365<bg::model::d2::point_xy<ttmath_big>, true, true>();
101 #endif
102
103     return 0;
104 }
105