]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2014-2015, Oracle and/or its affiliates. | |
4 | ||
5 | // Licensed under the Boost Software License version 1.0. | |
6 | // http://www.boost.org/users/license.html | |
7 | ||
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 | #ifndef BOOST_TEST_MODULE | |
12 | #define BOOST_TEST_MODULE test_disjoint_coverage | |
13 | #endif | |
14 | ||
15 | // unit test to test disjoint for all geometry combinations | |
16 | ||
17 | #include <iostream> | |
18 | ||
19 | #include <boost/test/included/unit_test.hpp> | |
20 | ||
21 | #include <boost/geometry/core/tag.hpp> | |
22 | #include <boost/geometry/core/tags.hpp> | |
23 | ||
24 | #include <boost/geometry/strategies/strategies.hpp> | |
25 | ||
26 | #include <boost/geometry/io/wkt/wkt.hpp> | |
27 | #include <boost/geometry/io/dsv/write.hpp> | |
28 | ||
29 | #include <boost/geometry/geometries/geometries.hpp> | |
30 | ||
31 | #include <boost/geometry/algorithms/disjoint.hpp> | |
32 | ||
33 | #include <from_wkt.hpp> | |
34 | ||
7c673cae FG |
35 | namespace bg = ::boost::geometry; |
36 | ||
37 | //============================================================================ | |
38 | ||
39 | struct test_disjoint | |
40 | { | |
41 | template <typename Geometry1, typename Geometry2> | |
42 | static inline void apply(std::string const& case_id, | |
43 | Geometry1 const& geometry1, | |
44 | Geometry2 const& geometry2, | |
45 | bool expected_result) | |
46 | { | |
47 | bool result = bg::disjoint(geometry1, geometry2); | |
48 | BOOST_CHECK_MESSAGE(result == expected_result, | |
49 | "case ID: " << case_id << ", G1: " << bg::wkt(geometry1) | |
50 | << ", G2: " << bg::wkt(geometry2) << " -> Expected: " | |
51 | << expected_result << ", detected: " << result); | |
52 | ||
53 | result = bg::disjoint(geometry2, geometry1); | |
54 | BOOST_CHECK_MESSAGE(result == expected_result, | |
55 | "case ID: " << case_id << ", G1: " << bg::wkt(geometry2) | |
56 | << ", G2: " << bg::wkt(geometry1) << " -> Expected: " | |
57 | << expected_result << ", detected: " << result); | |
58 | ||
59 | #ifdef BOOST_GEOMETRY_TEST_DEBUG | |
60 | std::cout << "case ID: " << case_id << "; G1 - G2: "; | |
61 | std::cout << bg::wkt(geometry1) << " - "; | |
62 | std::cout << bg::wkt(geometry2) << std::endl; | |
63 | std::cout << std::boolalpha; | |
64 | std::cout << "expected/computed result: " | |
65 | << expected_result << " / " << result << std::endl; | |
66 | std::cout << std::endl; | |
67 | std::cout << std::noboolalpha; | |
68 | #endif | |
69 | } | |
70 | }; | |
71 | ||
72 | //============================================================================ | |
73 | ||
74 | // areal-areal geometries | |
75 | template <typename P> | |
76 | inline void test_box_box() | |
77 | { | |
78 | typedef bg::model::box<P> B; | |
79 | ||
80 | typedef test_disjoint tester; | |
81 | ||
82 | tester::apply("b-b-01", | |
83 | from_wkt<B>("BOX(2 2,3 3)"), | |
84 | from_wkt<B>("BOX(0 0,2 2)"), | |
85 | false); | |
86 | ||
87 | tester::apply("b-b-02", | |
88 | from_wkt<B>("BOX(1 1,3 3)"), | |
89 | from_wkt<B>("BOX(0 0,2 2)"), | |
90 | false); | |
91 | ||
92 | tester::apply("b-b-03", | |
93 | from_wkt<B>("BOX(3 3,4 4)"), | |
94 | from_wkt<B>("BOX(0 0,2 2)"), | |
95 | true); | |
96 | } | |
97 | ||
98 | template <typename P> | |
99 | inline void test_ring_box() | |
100 | { | |
101 | typedef bg::model::box<P> B; | |
102 | typedef bg::model::ring<P, false, false> R; // ccw, open | |
103 | ||
104 | typedef test_disjoint tester; | |
105 | ||
106 | tester::apply("r-b-01", | |
107 | from_wkt<B>("BOX(2 2,3 3)"), | |
108 | from_wkt<R>("POLYGON((0 0,2 0,2 2,0 2))"), | |
109 | false); | |
110 | ||
111 | tester::apply("r-b-02", | |
112 | from_wkt<B>("BOX(1 1,3 3)"), | |
113 | from_wkt<R>("POLYGON((0 0,2 0,2 2,0 2))"), | |
114 | false); | |
115 | ||
116 | tester::apply("r-b-03", | |
117 | from_wkt<B>("BOX(3 3,4 4)"), | |
118 | from_wkt<R>("POLYGON((0 0,2 0,2 2,0 2))"), | |
119 | true); | |
120 | } | |
121 | ||
122 | template <typename P> | |
123 | inline void test_polygon_box() | |
124 | { | |
125 | typedef bg::model::box<P> B; | |
126 | typedef bg::model::polygon<P, false, false> PL; // ccw, open | |
127 | ||
128 | typedef test_disjoint tester; | |
129 | ||
130 | tester::apply("pg-b-01", | |
131 | from_wkt<B>("BOX(2 2,3 3)"), | |
132 | from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), | |
133 | false); | |
134 | ||
135 | tester::apply("pg-b-02", | |
136 | from_wkt<B>("BOX(1 1,3 3)"), | |
137 | from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), | |
138 | false); | |
139 | ||
140 | tester::apply("pg-b-03", | |
141 | from_wkt<B>("BOX(3 3,4 4)"), | |
142 | from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), | |
143 | true); | |
144 | } | |
145 | ||
146 | template <typename P> | |
147 | inline void test_multipolygon_box() | |
148 | { | |
149 | typedef bg::model::box<P> B; | |
150 | typedef bg::model::polygon<P, false, false> PL; // ccw, open | |
151 | typedef bg::model::multi_polygon<PL> MPL; | |
152 | ||
153 | typedef test_disjoint tester; | |
154 | ||
155 | tester::apply("mpg-b-01", | |
156 | from_wkt<B>("BOX(2 2,3 3)"), | |
157 | from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), | |
158 | false); | |
159 | ||
160 | tester::apply("mpg-b-02", | |
161 | from_wkt<B>("BOX(1 1,3 3)"), | |
162 | from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), | |
163 | false); | |
164 | ||
165 | tester::apply("mpg-b-03", | |
166 | from_wkt<B>("BOX(3 3,4 4)"), | |
167 | from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), | |
168 | true); | |
169 | } | |
170 | ||
171 | template <typename P> | |
172 | inline void test_ring_ring() | |
173 | { | |
174 | typedef bg::model::ring<P, false, false> R; // ccw, open | |
175 | ||
176 | typedef test_disjoint tester; | |
177 | ||
178 | tester::apply("r-r-01", | |
179 | from_wkt<R>("POLYGON((2 2,2 3,3 3,3 2))"), | |
180 | from_wkt<R>("POLYGON((0 0,2 0,2 2,0 2))"), | |
181 | false); | |
182 | ||
183 | tester::apply("r-r-02", | |
184 | from_wkt<R>("POLYGON((1 1,1 3,3 3,3 1))"), | |
185 | from_wkt<R>("POLYGON((0 0,2 0,2 2,0 2))"), | |
186 | false); | |
187 | ||
188 | tester::apply("r-r-03", | |
189 | from_wkt<R>("POLYGON((3 3,3 4,4 4,4 3))"), | |
190 | from_wkt<R>("POLYGON((0 0,2 0,2 2,0 2))"), | |
191 | true); | |
192 | } | |
193 | ||
194 | template <typename P> | |
195 | inline void test_polygon_ring() | |
196 | { | |
197 | typedef bg::model::ring<P, false, false> R; // ccw, open | |
198 | typedef bg::model::polygon<P, false, false> PL; // ccw, open | |
199 | ||
200 | typedef test_disjoint tester; | |
201 | ||
202 | tester::apply("pg-r-01", | |
203 | from_wkt<R>("POLYGON((2 2,2 3,3 3,3 2))"), | |
204 | from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), | |
205 | false); | |
206 | ||
207 | tester::apply("pg-r-02", | |
208 | from_wkt<R>("POLYGON((1 1,1 3,3 3,3 1))"), | |
209 | from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), | |
210 | false); | |
211 | ||
212 | tester::apply("pg-r-03", | |
213 | from_wkt<R>("POLYGON((3 3,3 4,4 4,4 3))"), | |
214 | from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), | |
215 | true); | |
216 | } | |
217 | ||
218 | template <typename P> | |
219 | inline void test_multipolygon_ring() | |
220 | { | |
221 | typedef bg::model::ring<P, false, false> R; // ccw, open | |
222 | typedef bg::model::polygon<P, false, false> PL; // ccw, open | |
223 | typedef bg::model::multi_polygon<PL> MPL; | |
224 | ||
225 | typedef test_disjoint tester; | |
226 | ||
227 | tester::apply("mpg-r-01", | |
228 | from_wkt<R>("POLYGON((2 2,2 3,3 3,3 2))"), | |
229 | from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), | |
230 | false); | |
231 | ||
232 | tester::apply("mpg-r-02", | |
233 | from_wkt<R>("POLYGON((1 1,1 3,3 3,3 1))"), | |
234 | from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), | |
235 | false); | |
236 | ||
237 | tester::apply("mpg-r-03", | |
238 | from_wkt<R>("POLYGON((3 3,3 4,4 4,4 3))"), | |
239 | from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), | |
240 | true); | |
241 | } | |
242 | ||
243 | template <typename P> | |
244 | inline void test_polygon_polygon() | |
245 | { | |
246 | typedef bg::model::polygon<P, false, false> PL; // ccw, open | |
247 | ||
248 | typedef test_disjoint tester; | |
249 | ||
250 | tester::apply("pg-pg-01", | |
251 | from_wkt<PL>("POLYGON((2 2,2 3,3 3,3 2))"), | |
252 | from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), | |
253 | false); | |
254 | ||
255 | tester::apply("pg-pg-02", | |
256 | from_wkt<PL>("POLYGON((1 1,1 3,3 3,3 1))"), | |
257 | from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), | |
258 | false); | |
259 | ||
260 | tester::apply("pg-pg-03", | |
261 | from_wkt<PL>("POLYGON((3 3,3 4,4 4,4 3))"), | |
262 | from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), | |
263 | true); | |
264 | ||
265 | tester::apply("pg-pg-04", | |
266 | from_wkt<PL>("POLYGON((0 0,9 0,9 9,0 9))"), | |
267 | from_wkt<PL>("POLYGON((3 3,6 3,6 6,3 6))"), | |
268 | false); | |
269 | // polygon with a hole which entirely contains the other polygon | |
270 | tester::apply("pg-pg-05", | |
271 | from_wkt<PL>("POLYGON((0 0,9 0,9 9,0 9),(2 2,2 7,7 7,7 2))"), | |
272 | from_wkt<PL>("POLYGON((3 3,6 3,6 6,3 6))"), | |
273 | true); | |
274 | // polygon with a hole, but the inner ring intersects the other polygon | |
275 | tester::apply("pg-pg-06", | |
276 | from_wkt<PL>("POLYGON((0 0,9 0,9 9,0 9),(3 2,3 7,7 7,7 2))"), | |
277 | from_wkt<PL>("POLYGON((2 3,6 3,6 6,2 6))"), | |
278 | false); | |
279 | // polygon with a hole, but the other polygon is entirely contained | |
280 | // between the inner and outer rings. | |
281 | tester::apply("pg-pg-07", | |
282 | from_wkt<PL>("POLYGON((0 0,9 0,9 9,0 9),(6 2,6 7,7 7,7 2))"), | |
283 | from_wkt<PL>("POLYGON((3 3,5 3,5 6,3 6))"), | |
284 | false); | |
285 | // polygon with a hole and the outer ring of the other polygon lies | |
286 | // between the inner and outer, but without touching either. | |
287 | tester::apply("pg-pg-08", | |
288 | from_wkt<PL>("POLYGON((0 0,9 0,9 9,0 9),(3 3,3 6,6 6,6 3))"), | |
289 | from_wkt<PL>("POLYGON((2 2,7 2,7 7,2 7))"), | |
290 | false); | |
291 | ||
292 | { | |
293 | typedef bg::model::polygon<P> PL; // cw, closed | |
294 | ||
295 | // https://svn.boost.org/trac/boost/ticket/10647 | |
296 | tester::apply("ticket-10647", | |
297 | from_wkt<PL>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0)(1 1, 4 1, 4 4, 1 4, 1 1))"), | |
298 | from_wkt<PL>("POLYGON((2 2, 2 3, 3 3, 3 2, 2 2))"), | |
299 | true); | |
300 | } | |
301 | } | |
302 | ||
303 | template <typename P> | |
304 | inline void test_polygon_multipolygon() | |
305 | { | |
306 | typedef bg::model::polygon<P, false, false> PL; // ccw, open | |
307 | typedef bg::model::multi_polygon<PL> MPL; | |
308 | ||
309 | typedef test_disjoint tester; | |
310 | ||
311 | tester::apply("pg-mpg-01", | |
312 | from_wkt<PL>("POLYGON((2 2,2 3,3 3,3 2))"), | |
313 | from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), | |
314 | false); | |
315 | ||
316 | tester::apply("pg-mpg-02", | |
317 | from_wkt<PL>("POLYGON((1 1,1 3,3 3,3 1))"), | |
318 | from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), | |
319 | false); | |
320 | ||
321 | tester::apply("pg-mpg-03", | |
322 | from_wkt<PL>("POLYGON((3 3,3 4,4 4,4 3))"), | |
323 | from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), | |
324 | true); | |
325 | } | |
326 | ||
327 | template <typename P> | |
328 | inline void test_multipolygon_multipolygon() | |
329 | { | |
330 | typedef bg::model::polygon<P, false, false> PL; // ccw, open | |
331 | typedef bg::model::multi_polygon<PL> MPL; | |
332 | ||
333 | typedef test_disjoint tester; | |
334 | ||
335 | tester::apply("mpg-mpg-01", | |
336 | from_wkt<MPL>("MULTIPOLYGON(((2 2,2 3,3 3,3 2)))"), | |
337 | from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), | |
338 | false); | |
339 | ||
340 | tester::apply("mpg-mpg-02", | |
341 | from_wkt<MPL>("MULTIPOLYGON(((1 1,1 3,3 3,3 1)))"), | |
342 | from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), | |
343 | false); | |
344 | ||
345 | tester::apply("mpg-mpg-03", | |
346 | from_wkt<MPL>("MULTIPOLYGON(((3 3,3 4,4 4,4 3)))"), | |
347 | from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), | |
348 | true); | |
349 | } | |
350 | ||
351 | //============================================================================ | |
352 | ||
353 | template <typename CoordinateType> | |
354 | inline void test_areal_areal() | |
355 | { | |
356 | typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type; | |
357 | ||
358 | test_polygon_polygon<point_type>(); | |
359 | test_polygon_multipolygon<point_type>(); | |
360 | test_polygon_ring<point_type>(); | |
361 | test_polygon_box<point_type>(); | |
362 | ||
363 | test_multipolygon_multipolygon<point_type>(); | |
364 | test_multipolygon_ring<point_type>(); | |
365 | test_multipolygon_box<point_type>(); | |
366 | ||
367 | test_ring_ring<point_type>(); | |
368 | test_ring_box<point_type>(); | |
369 | ||
370 | test_box_box<point_type>(); | |
371 | } | |
372 | ||
373 | //============================================================================ | |
374 | ||
375 | BOOST_AUTO_TEST_CASE( test_areal_areal_all ) | |
376 | { | |
377 | test_areal_areal<double>(); | |
378 | test_areal_areal<int>(); | |
7c673cae | 379 | } |