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