1 // Boost.Geometry
2
3 // Copyright (c) 2016 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_intersects.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
18 template <typename P>
test_polygon_polygon()19 void test_polygon_polygon()
20 {
21 typedef bg::model::polygon<P> poly;
22 typedef bg::model::ring<P> ring;
23
24 test_geometry<ring, ring>(case_1[0], case_1[1],
25 true);
26 test_geometry<ring, poly>(case_1[0], case_1[1],
27 true);
28
29 test_geometry<poly, poly>(case_1[0], case_1[1],
30 true);
31 test_geometry<poly, poly>(case_2[0], case_2[1],
32 true);
33 test_geometry<poly, poly>(case_3_sph[0], case_3_sph[1],
34 true);
35 test_geometry<poly, poly>(case_3_2_sph[0], case_3_2_sph[1],
36 true);
37 test_geometry<poly, poly>(case_4[0], case_4[1],
38 true);
39 test_geometry<poly, poly>(case_5[0], case_5[1],
40 true);
41 test_geometry<poly, poly>(case_6_sph[0], case_6_sph[1],
42 true);
43
44 test_geometry<poly, poly>(case_7[0], case_7[1],
45 true);
46 test_geometry<poly, poly>(case_8_sph[0], case_8_sph[1],
47 true);
48 test_geometry<poly, poly>(case_9_sph[0], case_9_sph[1],
49 true);
50 test_geometry<poly, poly>(case_10_sph[0], case_10_sph[1],
51 true);
52 test_geometry<poly, poly>(case_11_sph[0], case_11_sph[1],
53 true);
54 test_geometry<poly, poly>(case_12[0], case_12[1],
55 true);
56
57 test_geometry<poly, poly>(case_13_sph[0], case_13_sph[1],
58 true);
59 test_geometry<poly, poly>(case_14_sph[0], case_14_sph[1],
60 true);
61 test_geometry<poly, poly>(case_15_sph[0], case_15_sph[1],
62 true);
63 test_geometry<poly, poly>(case_16_sph[0], case_16_sph[1],
64 true);
65 test_geometry<poly, poly>(case_17_sph[0], case_17_sph[1],
66 true);
67 test_geometry<poly, poly>(case_17_sph[1], case_17_sph[0],
68 true);
69 test_geometry<poly, poly>(case_18_sph[0], case_18_sph[1],
70 true);
71 test_geometry<poly, poly>(case_18_sph[1], case_18_sph[0],
72 true);
73 }
74
75 template <typename P>
test_polygon_multi_polygon()76 void test_polygon_multi_polygon()
77 {
78 typedef bg::model::polygon<P> poly;
79 typedef bg::model::ring<P> ring;
80 typedef bg::model::multi_polygon<poly> mpoly;
81
82 test_geometry<ring, mpoly>(case_1[0], case_multi_2[0],
83 true);
84 test_geometry<poly, mpoly>(case_2[0], case_multi_2[0],
85 true);
86 }
87
88 template <typename P>
test_multi_polygon_multi_polygon()89 void test_multi_polygon_multi_polygon()
90 {
91 typedef bg::model::polygon<P> poly;
92 typedef bg::model::multi_polygon<poly> mpoly;
93
94 test_geometry<mpoly, mpoly>(case_multi_2[0], case_multi_2[1],
95 true);
96 }
97
98 template <typename P>
test_linestring_polygon()99 void test_linestring_polygon()
100 {
101 typedef bg::model::linestring<P> ls;
102 typedef bg::model::polygon<P> poly;
103 typedef bg::model::polygon<P> ring;
104
105 test_geometry<ls, poly>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
106 test_geometry<ls, ring>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
107 test_geometry<ls, poly>("LINESTRING(0 0,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
108 test_geometry<ls, poly>("LINESTRING(5 0,5 5,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
109 test_geometry<ls, poly>("LINESTRING(5 1,5 5,9 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
110 test_geometry<ls, poly>("LINESTRING(11 1,11 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
111
112 test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)",
113 "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
114 true);
115
116 test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9,1 9,1 1,9 1)",
117 "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
118 true);
119
120 test_geometry<ls, poly>("LINESTRING(0 0,10 0,10 10,0 10,0 0)",
121 "POLYGON((0 0,0 10,10 10,10 0,0 0))",
122 true);
123 }
124
125 template <typename P>
test_linestring_multi_polygon()126 void test_linestring_multi_polygon()
127 {
128 typedef bg::model::linestring<P> ls;
129 typedef bg::model::polygon<P> poly;
130 typedef bg::model::multi_polygon<poly> mpoly;
131
132 test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,10 9)",
133 "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)))",
134 true);
135 }
136
137 template <typename P>
test_multi_linestring_polygon()138 void test_multi_linestring_polygon()
139 {
140 typedef bg::model::linestring<P> ls;
141 typedef bg::model::polygon<P> poly;
142 typedef bg::model::ring<P> ring;
143 typedef bg::model::multi_linestring<ls> mls;
144
145 test_geometry<mls, poly>("MULTILINESTRING((11 11, 20 20),(5 7, 4 1))",
146 "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))",
147 true);
148
149 test_geometry<mls, ring>("MULTILINESTRING((6 6,15 15),(0 0, 7 7))",
150 "POLYGON((5 5,5 15,15 15,15 5,5 5))",
151 true);
152
153 test_geometry<mls, poly>("MULTILINESTRING((3 10.031432746397092, 1 5, 1 10.013467818052765, 3 4, 7 8, 6 10.035925377760330, 10 2))",
154 "POLYGON((0 0,0 10,10 10,10 0,0 0))",
155 true);
156 }
157
158 template <typename P>
test_multi_linestring_multi_polygon()159 void test_multi_linestring_multi_polygon()
160 {
161 typedef bg::model::linestring<P> ls;
162 typedef bg::model::polygon<P> poly;
163 typedef bg::model::multi_linestring<ls> mls;
164 typedef bg::model::multi_polygon<poly> mpoly;
165
166 test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10,0 10,0 0),(2 2,5 5,2 8,2 2))",
167 "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(2 2,5 5,2 8,2 2)))",
168 true);
169
170 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))",
171 "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
172 true);
173
174 test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,4 -2,5 0),(5 -2,6 -2,5 0))",
175 "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
176 true);
177 }
178
179 template <typename P>
test_linestring_linestring()180 void test_linestring_linestring()
181 {
182 typedef bg::model::linestring<P> ls;
183
184 test_geometry<ls, ls>("LINESTRING(0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", true);
185
186 test_geometry<ls, ls>("LINESTRING(1 0,2 2,2 3)", "LINESTRING(0 0, 2 2, 3 2)", true);
187 }
188
189 template <typename P>
test_linestring_multi_linestring()190 void test_linestring_multi_linestring()
191 {
192 typedef bg::model::linestring<P> ls;
193 typedef bg::model::multi_linestring<ls> mls;
194
195 test_geometry<ls, mls>("LINESTRING(0 0,10 0)",
196 "MULTILINESTRING((1 0,2 0),(1 1,2 1))",
197 true);
198
199 test_geometry<ls, mls>("LINESTRING(0 0,5 0,5 5,0 5,0 0)",
200 "MULTILINESTRING((5 5,0 5,0 0),(0 0,5 0,5 5))",
201 true);
202 }
203
204 template <typename P>
test_multi_linestring_multi_linestring()205 void test_multi_linestring_multi_linestring()
206 {
207 typedef bg::model::linestring<P> ls;
208 typedef bg::model::multi_linestring<ls> mls;
209
210 test_geometry<mls, mls>("MULTILINESTRING((0 0,0 0,18 0,18 0,19 0,19 0,19 0,30 0,30 0))",
211 "MULTILINESTRING((0 10,5 0,20 0,20 0,30 0))",
212 true);
213 }
214
215 template <typename P>
test_point_polygon()216 void test_point_polygon()
217 {
218 typedef bg::model::polygon<P> poly;
219
220 // https://svn.boost.org/trac/boost/ticket/9162
221 test_geometry<P, poly>("POINT(0 90)",
222 "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
223 true);
224 test_geometry<P, poly>("POINT(-120 21)",
225 "POLYGON((30 0,30 30,90 30, 90 0, 30 0))",
226 false);
227 // extended
228 test_geometry<P, poly>("POINT(0 -90)",
229 "POLYGON((0 -80,90 -80, -180 -80, -90 -80, 0 -80))",
230 true);
231 test_geometry<P, poly>("POINT(0 89)",
232 "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
233 true);
234 test_geometry<P, poly>("POINT(-180 89)",
235 "POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
236 true);
237 }
238
239
240 template <typename P>
test_all()241 void test_all()
242 {
243 test_polygon_polygon<P>();
244 test_polygon_multi_polygon<P>();
245 test_multi_polygon_multi_polygon<P>();
246
247 test_linestring_polygon<P>();
248 test_linestring_multi_polygon<P>();
249 test_multi_linestring_polygon<P>();
250 test_multi_linestring_multi_polygon<P>();
251
252 test_linestring_linestring<P>();
253 test_linestring_multi_linestring<P>();
254 test_multi_linestring_multi_linestring<P>();
255
256 test_point_polygon<P>();
257 }
258
259
test_main(int,char * [])260 int test_main( int , char* [] )
261 {
262 test_all<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
263
264 #if defined(HAVE_TTMATH)
265 test_cs<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
266 #endif
267
268 return 0;
269 }
270