• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry
2 
3 // Copyright (c) 2016, 2019 Oracle and/or its affiliates.
4 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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 #include "test_disjoint.hpp"
11 
12 #include <algorithms/overlay/overlay_cases.hpp>
13 #include <algorithms/overlay/multi_overlay_cases.hpp>
14 
15 #include <boost/geometry/geometries/geometries.hpp>
16 
17 #include <boost/geometry/strategies/strategies.hpp>
18 
19 
20 template <typename P>
test_polygon_polygon()21 void test_polygon_polygon()
22 {
23     typedef bg::model::polygon<P> poly;
24     typedef bg::model::ring<P> ring;
25 
26     test_geometry<ring, ring>(case_1[0], case_1[1],
27                               false);
28     test_geometry<ring, poly>(case_1[0], case_1[1],
29                               false);
30 
31     test_geometry<poly, poly>(case_1[0], case_1[1],
32                               false);
33     test_geometry<poly, poly>(case_2[0], case_2[1],
34                               false);
35     test_geometry<poly, poly>(case_3_sph[0], case_3_sph[1],
36                               false);
37     test_geometry<poly, poly>(case_3_2_sph[0], case_3_2_sph[1],
38                               false);
39     test_geometry<poly, poly>(case_4[0], case_4[1],
40                               false);
41     test_geometry<poly, poly>(case_5[0], case_5[1],
42                               false);
43     test_geometry<poly, poly>(case_6_sph[0], case_6_sph[1],
44                               false);
45 
46     test_geometry<poly, poly>(case_7[0], case_7[1],
47                               false);
48     test_geometry<poly, poly>(case_8_sph[0], case_8_sph[1],
49                               false);
50     test_geometry<poly, poly>(case_9_sph[0], case_9_sph[1],
51                               false);
52     test_geometry<poly, poly>(case_10_sph[0], case_10_sph[1],
53                               false);
54     test_geometry<poly, poly>(case_11_sph[0], case_11_sph[1],
55                               false);
56     test_geometry<poly, poly>(case_12[0], case_12[1],
57                               false);
58 
59     test_geometry<poly, poly>(case_13_sph[0], case_13_sph[1],
60                               false);
61     test_geometry<poly, poly>(case_14_sph[0], case_14_sph[1],
62                               false);
63     test_geometry<poly, poly>(case_15_sph[0], case_15_sph[1],
64                               false);
65     test_geometry<poly, poly>(case_16_sph[0], case_16_sph[1],
66                               false);
67     test_geometry<poly, poly>(case_17_sph[0], case_17_sph[1],
68                               false);
69     test_geometry<poly, poly>(case_17_sph[1], case_17_sph[0],
70                               false);
71     test_geometry<poly, poly>(case_18_sph[0], case_18_sph[1],
72                               false);
73     test_geometry<poly, poly>(case_18_sph[1], case_18_sph[0],
74                               false);
75 }
76 
77 template <typename P>
test_polygon_multi_polygon()78 void test_polygon_multi_polygon()
79 {
80     typedef bg::model::polygon<P> poly;
81     typedef bg::model::ring<P> ring;
82     typedef bg::model::multi_polygon<poly> mpoly;
83 
84     test_geometry<ring, mpoly>(case_1[0], case_multi_2[0],
85                                false);
86     test_geometry<poly, mpoly>(case_2[0], case_multi_2[0],
87                                false);
88 }
89 
90 template <typename P>
test_multi_polygon_multi_polygon()91 void test_multi_polygon_multi_polygon()
92 {
93     typedef bg::model::polygon<P> poly;
94     typedef bg::model::multi_polygon<poly> mpoly;
95 
96     test_geometry<mpoly, mpoly>(case_multi_2[0], case_multi_2[1],
97                                 false);
98 }
99 
100 template <typename P>
test_linestring_polygon()101 void test_linestring_polygon()
102 {
103     typedef bg::model::linestring<P> ls;
104     typedef bg::model::polygon<P> poly;
105     typedef bg::model::polygon<P> ring;
106 
107     test_geometry<ls, poly>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
108     test_geometry<ls, ring>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
109     test_geometry<ls, poly>("LINESTRING(0 0,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
110     test_geometry<ls, poly>("LINESTRING(5 0,5 5,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
111     test_geometry<ls, poly>("LINESTRING(5 1,5 5,9 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
112     test_geometry<ls, poly>("LINESTRING(11 1,11 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
113 
114     test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)",
115                             "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
116                             false);
117 
118     test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9,1 9,1 1,9 1)",
119                             "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
120                             false);
121 
122     test_geometry<ls, poly>("LINESTRING(0 0,10 0,10 10,0 10,0 0)",
123                             "POLYGON((0 0,0 10,10 10,10 0,0 0))",
124                             false);
125 }
126 
127 template <typename P>
test_linestring_multi_polygon()128 void test_linestring_multi_polygon()
129 {
130     typedef bg::model::linestring<P> ls;
131     typedef bg::model::polygon<P> poly;
132     typedef bg::model::multi_polygon<poly> mpoly;
133 
134     test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,10 9)",
135                              "MULTIPOLYGON(((0 20,0 30,10 30,10 20,0 20)),((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)))",
136                              false);
137 }
138 
139 template <typename P>
test_multi_linestring_polygon()140 void test_multi_linestring_polygon()
141 {
142     typedef bg::model::linestring<P> ls;
143     typedef bg::model::polygon<P> poly;
144     typedef bg::model::ring<P> ring;
145     typedef bg::model::multi_linestring<ls> mls;
146 
147     test_geometry<mls, poly>("MULTILINESTRING((11 11, 20 20),(5 7, 4 1))",
148                              "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))",
149                              false);
150 
151     test_geometry<mls, ring>("MULTILINESTRING((6 6,15 15),(0 0, 7 7))",
152                              "POLYGON((5 5,5 15,15 15,15 5,5 5))",
153                              false);
154 
155     test_geometry<mls, poly>("MULTILINESTRING((3 10.031432746397092, 1 5, 1 10.013467818052765, 3 4, 7 8, 6 10.035925377760330, 10 2))",
156                              "POLYGON((0 0,0 10,10 10,10 0,0 0))",
157                              false);
158 }
159 
160 template <typename P>
test_multi_linestring_multi_polygon()161 void test_multi_linestring_multi_polygon()
162 {
163     typedef bg::model::linestring<P> ls;
164     typedef bg::model::polygon<P> poly;
165     typedef bg::model::multi_linestring<ls> mls;
166     typedef bg::model::multi_polygon<poly> mpoly;
167 
168     test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10,0 10,0 0),(2 2,5 5,2 8,2 2))",
169                               "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(2 2,5 5,2 8,2 2)))",
170                               false);
171 
172     test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10),(10 10,0 10,0 0),(20 20,50 50,20 80,20 20))",
173                               "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
174                               false);
175 
176     test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,4 -2,5 0),(5 -2,6 -2,5 0))",
177                               "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
178                               false);
179 }
180 
181 template <typename P>
test_linestring_linestring()182 void test_linestring_linestring()
183 {
184     typedef bg::model::linestring<P> ls;
185 
186     test_geometry<ls, ls>("LINESTRING(0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", false);
187 
188     test_geometry<ls, ls>("LINESTRING(1 0,2 2,2 3)", "LINESTRING(0 0, 2 2, 3 2)", false);
189 }
190 
191 //https://svn.boost.org/trac10/ticket/13057
192 template <typename P>
test_linestring_linestring_radians()193 void test_linestring_linestring_radians()
194 {
195     typedef bg::model::linestring<P> ls;
196 
197     test_geometry<ls, ls>("LINESTRING(0 -0.31415926535897897853,\
198                                       0.26179938779914918578 0,\
199                                      -0.034906585039886556254 0.13962634015954622502,\
200                                      -0.12217304763960294689 0.12217304763960294689)",\
201                           "LINESTRING(-0.034906585039886556254 0.13962634015954622502,\
202                                       -0.26179938779914918578 0)", false);
203 
204 }
205 
206 template <typename P>
test_linestring_multi_linestring()207 void test_linestring_multi_linestring()
208 {
209     typedef bg::model::linestring<P> ls;
210     typedef bg::model::multi_linestring<ls> mls;
211 
212     test_geometry<ls, mls>("LINESTRING(0 0,10 0)",
213                            "MULTILINESTRING((1 0,2 0),(1 1,2 1))",
214                            false);
215 
216     test_geometry<ls, mls>("LINESTRING(0 0,5 0,5 5,0 5,0 0)",
217                            "MULTILINESTRING((5 5,0 5,0 0),(0 0,5 0,5 5))",
218                            false);
219 }
220 
221 template <typename P>
test_multi_linestring_multi_linestring()222 void test_multi_linestring_multi_linestring()
223 {
224     typedef bg::model::linestring<P> ls;
225     typedef bg::model::multi_linestring<ls> mls;
226 
227     test_geometry<mls, mls>("MULTILINESTRING((0 0,0 0,18 0,18 0,19 0,19 0,19 0,30 0,30 0))",
228                             "MULTILINESTRING((0 10,5 0,20 0,20 0,30 0))",
229                             false);
230 }
231 
232 template <typename P>
test_point_polygon()233 void test_point_polygon()
234 {
235     typedef bg::model::polygon<P> poly;
236 
237     // https://svn.boost.org/trac/boost/ticket/9162
238     test_geometry<P, poly>("POINT(0 90)",
239                            "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
240                            false);
241     test_geometry<P, poly>("POINT(-120 21)",
242                            "POLYGON((30 0,30 30,90 30, 90 0, 30 0))",
243                            true);
244     // extended
245     test_geometry<P, poly>("POINT(0 -90)",
246                            "POLYGON((0 -80,90 -80, -180 -80, -90 -80, 0 -80))",
247                            false);
248     test_geometry<P, poly>("POINT(0 89)",
249                            "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
250                            false);
251     test_geometry<P, poly>("POINT(-180 89)",
252                            "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
253                            false);
254 }
255 
256 template <typename P>
test_box_polygon()257 void test_box_polygon()
258 {
259     typedef bg::model::box<P> box;
260     typedef bg::model::polygon<P> poly;
261 
262     // https://github.com/boostorg/geometry/issues/466
263     test_geometry<box, poly>("BOX(2.2 48.88, 2.5 48.9021)",
264                              "POLYGON((2.4 48.90205, 2.4 48.89, 2.3 48.89, 2.3 48.90205, 2.4 48.90205))",
265                              false);
266     test_geometry<box, poly>("BOX(2.2 48.88, 2.5 48.9021)",
267                              "POLYGON((2.4 48.9021, 2.4 48.89, 2.3 48.89, 2.3 48.9021, 2.4 48.9021))",
268                              false);
269     test_geometry<box, poly>("BOX(2.2 48.88, 2.5 48.9021)",
270                              "POLYGON((2.4 48.90215, 2.4 48.89, 2.3 48.89, 2.3 48.90215, 2.4 48.90215))",
271                              false);
272     // extended
273     test_geometry<box, poly>("BOX(2.2 48.88, 2.5 48.9021)",
274                              "POLYGON((2.4 48.9022, 2.4 48.89, 2.3 48.89, 2.3 48.9022, 2.4 48.9022))",
275                              false);
276     // box within poly
277     test_geometry<box, poly>("BOX(2.2 48.88, 2.5 48.9021)",
278                              "POLYGON((2.6 48.9021, 2.6 48.8, 2.1 48.8, 2.1 48.9021, 2.6 48.9021))",
279                              false);
280     test_geometry<box, poly>("BOX(2.2 48.88, 2.5 48.9021)",
281                              "POLYGON((2.6 48.9022, 2.6 48.8, 2.1 48.8, 2.1 48.9022, 2.6 48.9022))",
282                              false);
283 
284     // related to https://github.com/boostorg/geometry/issues/579
285     test_geometry<box, poly>("BOX(10 10,20 20)",
286                              "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0),"
287                                      "(12 1,11 1,12 2,12 1))",
288                              true);
289 }
290 
291 
292 template <typename P>
test_all()293 void test_all()
294 {
295     test_polygon_polygon<P>();
296     test_polygon_multi_polygon<P>();
297     test_multi_polygon_multi_polygon<P>();
298 
299     test_linestring_polygon<P>();
300     test_linestring_multi_polygon<P>();
301     test_multi_linestring_polygon<P>();
302     test_multi_linestring_multi_polygon<P>();
303 
304     test_linestring_linestring<P>();
305     test_linestring_multi_linestring<P>();
306     test_multi_linestring_multi_linestring<P>();
307 
308     test_point_polygon<P>();
309     test_box_polygon<P>();
310 }
311 
312 
test_main(int,char * [])313 int test_main( int , char* [] )
314 {
315     typedef bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > point_deg;
316     typedef bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::radian> > point_rad;
317 
318     test_all<point_deg>();
319 
320     test_linestring_linestring_radians<point_rad>();
321 
322 #if defined(HAVE_TTMATH)
323     test_cs<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
324 #endif
325 
326     return 0;
327 }
328