]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/disjoint/disjoint_coverage_l_a.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / disjoint / disjoint_coverage_l_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 // linear-areal geometries
80 template <typename P>
81 inline void test_segment_box()
82 {
83 typedef bg::model::segment<P> S;
84 typedef bg::model::box<P> B;
85
86 typedef test_disjoint tester;
87
88 tester::apply("s-b-01",
89 from_wkt<S>("SEGMENT(0 0,2 0)"),
90 from_wkt<B>("BOX(0 0,2 2)"),
91 false);
92
93 tester::apply("s-b-02",
94 from_wkt<S>("SEGMENT(1 1,3 3)"),
95 from_wkt<B>("BOX(0 0,2 2)"),
96 false);
97
98 tester::apply("s-b-03",
99 from_wkt<S>("SEGMENT(2 2,3 3)"),
100 from_wkt<B>("BOX(0 0,2 2)"),
101 false);
102
103 tester::apply("s-b-04",
104 from_wkt<S>("SEGMENT(4 4,3 3)"),
105 from_wkt<B>("BOX(0 0,2 2)"),
106 true);
107
108 tester::apply("s-b-05",
109 from_wkt<S>("SEGMENT(0 4,4 4)"),
110 from_wkt<B>("BOX(0 0,2 2)"),
111 true);
112
113 tester::apply("s-b-06",
114 from_wkt<S>("SEGMENT(4 0,4 4)"),
115 from_wkt<B>("BOX(0 0,2 2)"),
116 true);
117
118 tester::apply("s-b-07",
119 from_wkt<S>("SEGMENT(0 -2,0 -1)"),
120 from_wkt<B>("BOX(0 0,1 1)"),
121 true);
122
123 tester::apply("s-b-08",
124 from_wkt<S>("SEGMENT(-2 -2,-2 -1)"),
125 from_wkt<B>("BOX(0 0,1 1)"),
126 true);
127
128 tester::apply("s-b-09",
129 from_wkt<S>("SEGMENT(-2 -2,-2 -2)"),
130 from_wkt<B>("BOX(0 0,1 1)"),
131 true);
132
133 tester::apply("s-b-10",
134 from_wkt<S>("SEGMENT(-2 0,-2 0)"),
135 from_wkt<B>("BOX(0 0,1 1)"),
136 true);
137
138 tester::apply("s-b-11",
139 from_wkt<S>("SEGMENT(0 -2,0 -2)"),
140 from_wkt<B>("BOX(0 0,1 1)"),
141 true);
142
143 tester::apply("s-b-12",
144 from_wkt<S>("SEGMENT(-2 0,-1 0)"),
145 from_wkt<B>("BOX(0 0,1 1)"),
146 true);
147
148 // segment degenerates to a point
149 tester::apply("s-b-13",
150 from_wkt<S>("SEGMENT(0 0,0 0)"),
151 from_wkt<B>("BOX(0 0,1 1)"),
152 false);
153
154 tester::apply("s-b-14",
155 from_wkt<S>("SEGMENT(1 1,1 1)"),
156 from_wkt<B>("BOX(0 0,2 2)"),
157 false);
158
159 tester::apply("s-b-15",
160 from_wkt<S>("SEGMENT(2 2,2 2)"),
161 from_wkt<B>("BOX(0 0,2 2)"),
162 false);
163
164 tester::apply("s-b-16",
165 from_wkt<S>("SEGMENT(2 0,2 0)"),
166 from_wkt<B>("BOX(0 0,2 2)"),
167 false);
168
169 tester::apply("s-b-17",
170 from_wkt<S>("SEGMENT(0 2,0 2)"),
171 from_wkt<B>("BOX(0 0,2 2)"),
172 false);
173
174 tester::apply("s-b-18",
175 from_wkt<S>("SEGMENT(2 2,2 2)"),
176 from_wkt<B>("BOX(0 0,1 1)"),
177 true);
178 }
179
180 template <typename P>
181 inline void test_segment_ring()
182 {
183 typedef bg::model::segment<P> S;
184 typedef bg::model::ring<P, false, false> R; // ccw, open
185
186 typedef test_disjoint tester;
187
188 tester::apply("s-r-01",
189 from_wkt<S>("SEGMENT(0 0,2 0)"),
190 from_wkt<R>("POLYGON((0 0,2 0,0 2))"),
191 false);
192
193 tester::apply("s-r-02",
194 from_wkt<S>("SEGMENT(1 0,3 3)"),
195 from_wkt<R>("POLYGON((0 0,2 0,0 2))"),
196 false);
197
198 tester::apply("s-r-03",
199 from_wkt<S>("SEGMENT(1 1,3 3)"),
200 from_wkt<R>("POLYGON((0 0,2 0,0 2))"),
201 false);
202
203 tester::apply("s-r-04",
204 from_wkt<S>("SEGMENT(2 2,3 3)"),
205 from_wkt<R>("POLYGON((0 0,2 0,0 2))"),
206 true);
207 }
208
209 template <typename P>
210 inline void test_segment_polygon()
211 {
212 typedef bg::model::segment<P> S;
213 typedef bg::model::polygon<P, false, false> PL; // ccw, open
214
215 typedef test_disjoint tester;
216
217 tester::apply("s-pg-01",
218 from_wkt<S>("SEGMENT(0 0,2 0)"),
219 from_wkt<PL>("POLYGON((0 0,2 0,0 2))"),
220 false);
221
222 tester::apply("s-pg-02",
223 from_wkt<S>("SEGMENT(1 0,3 3)"),
224 from_wkt<PL>("POLYGON((0 0,2 0,0 2))"),
225 false);
226
227 tester::apply("s-pg-03",
228 from_wkt<S>("SEGMENT(1 1,3 3)"),
229 from_wkt<PL>("POLYGON((0 0,2 0,0 2))"),
230 false);
231
232 tester::apply("s-pg-04",
233 from_wkt<S>("SEGMENT(2 2,3 3)"),
234 from_wkt<PL>("POLYGON((0 0,2 0,0 2))"),
235 true);
236 }
237
238 template <typename P>
239 inline void test_segment_multipolygon()
240 {
241 typedef bg::model::segment<P> S;
242 typedef bg::model::polygon<P, false, false> PL; // ccw, open
243 typedef bg::model::multi_polygon<PL> MPL;
244
245 typedef test_disjoint tester;
246
247 tester::apply("s-mpg-01",
248 from_wkt<S>("SEGMENT(0 0,2 0)"),
249 from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"),
250 false);
251
252 tester::apply("s-mpg-02",
253 from_wkt<S>("SEGMENT(1 0,3 3)"),
254 from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"),
255 false);
256
257 tester::apply("s-mpg-03",
258 from_wkt<S>("SEGMENT(1 1,3 3)"),
259 from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"),
260 false);
261
262 tester::apply("s-mpg-04",
263 from_wkt<S>("SEGMENT(2 2,3 3)"),
264 from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"),
265 true);
266 }
267
268 template <typename P>
269 inline void test_linestring_box()
270 {
271 typedef bg::model::linestring<P> L;
272 typedef bg::model::box<P> B;
273
274 typedef test_disjoint tester;
275
276 tester::apply("l-b-01",
277 from_wkt<L>("LINESTRING(0 0,2 0)"),
278 from_wkt<B>("BOX(0 0,2 2)"),
279 false);
280
281 tester::apply("l-b-02",
282 from_wkt<L>("LINESTRING(1 1,3 3)"),
283 from_wkt<B>("BOX(0 0,2 2)"),
284 false);
285
286 tester::apply("l-b-03",
287 from_wkt<L>("LINESTRING(2 2,3 3)"),
288 from_wkt<B>("BOX(0 0,2 2)"),
289 false);
290
291 tester::apply("l-b-04",
292 from_wkt<L>("LINESTRING(4 4,3 3)"),
293 from_wkt<B>("BOX(0 0,2 2)"),
294 true);
295 }
296
297 template <typename P>
298 inline void test_linestring_ring()
299 {
300 typedef bg::model::linestring<P> L;
301 typedef bg::model::ring<P, false, false> R; // ccw, open
302
303 typedef test_disjoint tester;
304
305 tester::apply("l-r-01",
306 from_wkt<L>("LINESTRING(0 0,2 0)"),
307 from_wkt<R>("POLYGON((0 0,2 0,0 2))"),
308 false);
309
310 tester::apply("l-r-02",
311 from_wkt<L>("LINESTRING(1 0,3 3)"),
312 from_wkt<R>("POLYGON((0 0,2 0,0 2))"),
313 false);
314
315 tester::apply("l-r-03",
316 from_wkt<L>("LINESTRING(1 1,3 3)"),
317 from_wkt<R>("POLYGON((0 0,2 0,0 2))"),
318 false);
319
320 tester::apply("l-r-04",
321 from_wkt<L>("LINESTRING(2 2,3 3)"),
322 from_wkt<R>("POLYGON((0 0,2 0,0 2))"),
323 true);
324 }
325
326 template <typename P>
327 inline void test_linestring_polygon()
328 {
329 typedef bg::model::linestring<P> L;
330 typedef bg::model::polygon<P, false, false> PL; // ccw, open
331
332 typedef test_disjoint tester;
333
334 tester::apply("l-pg-01",
335 from_wkt<L>("LINESTRING(0 0,2 0)"),
336 from_wkt<PL>("POLYGON((0 0,2 0,0 2))"),
337 false);
338
339 tester::apply("l-pg-02",
340 from_wkt<L>("LINESTRING(1 0,3 3)"),
341 from_wkt<PL>("POLYGON((0 0,2 0,0 2))"),
342 false);
343
344 tester::apply("l-pg-03",
345 from_wkt<L>("LINESTRING(1 1,3 3)"),
346 from_wkt<PL>("POLYGON((0 0,2 0,0 2))"),
347 false);
348
349 tester::apply("l-pg-04",
350 from_wkt<L>("LINESTRING(2 2,3 3)"),
351 from_wkt<PL>("POLYGON((0 0,2 0,0 2))"),
352 true);
353 }
354
355 template <typename P>
356 inline void test_linestring_multipolygon()
357 {
358 typedef bg::model::linestring<P> L;
359 typedef bg::model::polygon<P, false, false> PL; // ccw, open
360 typedef bg::model::multi_polygon<PL> MPL;
361
362 typedef test_disjoint tester;
363
364 tester::apply("l-mpg-01",
365 from_wkt<L>("LINESTRING(0 0,2 0)"),
366 from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"),
367 false);
368
369 tester::apply("l-mpg-02",
370 from_wkt<L>("LINESTRING(1 0,3 3)"),
371 from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"),
372 false);
373
374 tester::apply("l-mpg-03",
375 from_wkt<L>("LINESTRING(1 1,3 3)"),
376 from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"),
377 false);
378
379 tester::apply("l-mpg-04",
380 from_wkt<L>("LINESTRING(2 2,3 3)"),
381 from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"),
382 true);
383 }
384
385 template <typename P>
386 inline void test_multilinestring_box()
387 {
388 typedef bg::model::linestring<P> L;
389 typedef bg::model::multi_linestring<L> ML;
390 typedef bg::model::box<P> B;
391
392 typedef test_disjoint tester;
393
394 tester::apply("ml-b-01",
395 from_wkt<ML>("MULTILINESTRING((0 0,2 0))"),
396 from_wkt<B>("BOX(0 0,2 2)"),
397 false);
398
399 tester::apply("ml-b-02",
400 from_wkt<ML>("MULTILINESTRING((1 1,3 3))"),
401 from_wkt<B>("BOX(0 0,2 2)"),
402 false);
403
404 tester::apply("ml-b-03",
405 from_wkt<ML>("MULTILINESTRING((2 2,3 3))"),
406 from_wkt<B>("BOX(0 0,2 2)"),
407 false);
408
409 tester::apply("ml-b-04",
410 from_wkt<ML>("MULTILINESTRING((4 4,3 3))"),
411 from_wkt<B>("BOX(0 0,2 2)"),
412 true);
413 }
414
415 template <typename P>
416 inline void test_multilinestring_ring()
417 {
418 typedef bg::model::linestring<P> L;
419 typedef bg::model::multi_linestring<L> ML;
420 typedef bg::model::ring<P, false, false> R; // ccw, open
421
422 typedef test_disjoint tester;
423
424 tester::apply("ml-r-01",
425 from_wkt<ML>("MULTILINESTRING((0 0,2 0))"),
426 from_wkt<R>("POLYGON((0 0,2 0,0 2))"),
427 false);
428
429 tester::apply("ml-r-02",
430 from_wkt<ML>("MULTILINESTRING((1 0,3 3))"),
431 from_wkt<R>("POLYGON((0 0,2 0,0 2))"),
432 false);
433
434 tester::apply("ml-r-03",
435 from_wkt<ML>("MULTILINESTRING((1 1,3 3))"),
436 from_wkt<R>("POLYGON((0 0,2 0,0 2))"),
437 false);
438
439 tester::apply("ml-r-04",
440 from_wkt<ML>("MULTILINESTRING((2 2,3 3))"),
441 from_wkt<R>("POLYGON((0 0,2 0,0 2))"),
442 true);
443 }
444
445 template <typename P>
446 inline void test_multilinestring_polygon()
447 {
448 typedef bg::model::linestring<P> L;
449 typedef bg::model::multi_linestring<L> ML;
450 typedef bg::model::polygon<P, false, false> PL; // ccw, open
451
452 typedef test_disjoint tester;
453
454 tester::apply("ml-pg-01",
455 from_wkt<ML>("MULTILINESTRING((0 0,2 0))"),
456 from_wkt<PL>("POLYGON((0 0,2 0,0 2))"),
457 false);
458
459 tester::apply("ml-pg-02",
460 from_wkt<ML>("MULTILINESTRING((1 0,3 3))"),
461 from_wkt<PL>("POLYGON((0 0,2 0,0 2))"),
462 false);
463
464 tester::apply("ml-pg-03",
465 from_wkt<ML>("MULTILINESTRING((1 1,3 3))"),
466 from_wkt<PL>("POLYGON((0 0,2 0,0 2))"),
467 false);
468
469 tester::apply("ml-pg-04",
470 from_wkt<ML>("MULTILINESTRING((2 2,3 3))"),
471 from_wkt<PL>("POLYGON((0 0,2 0,0 2))"),
472 true);
473 }
474
475 template <typename P>
476 inline void test_multilinestring_multipolygon()
477 {
478 typedef bg::model::linestring<P> L;
479 typedef bg::model::multi_linestring<L> ML;
480 typedef bg::model::polygon<P, false, false> PL; // ccw, open
481 typedef bg::model::multi_polygon<PL> MPL;
482
483 typedef test_disjoint tester;
484
485 tester::apply("ml-mpg-01",
486 from_wkt<ML>("MULTILINESTRING((0 0,2 0))"),
487 from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"),
488 false);
489
490 tester::apply("ml-mpg-02",
491 from_wkt<ML>("MULTILINESTRING((1 0,3 3))"),
492 from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"),
493 false);
494
495 tester::apply("ml-mpg-03",
496 from_wkt<ML>("MULTILINESTRING((1 1,3 3))"),
497 from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"),
498 false);
499
500 tester::apply("ml-mpg-04",
501 from_wkt<ML>("MULTILINESTRING((2 2,3 3))"),
502 from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"),
503 true);
504 }
505
506 //============================================================================
507
508 template <typename CoordinateType>
509 inline void test_linear_areal()
510 {
511 typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type;
512
513 test_segment_polygon<point_type>();
514 test_segment_multipolygon<point_type>();
515 test_segment_ring<point_type>();
516 test_segment_box<point_type>();
517
518 test_linestring_polygon<point_type>();
519 test_linestring_multipolygon<point_type>();
520 test_linestring_ring<point_type>();
521 test_linestring_box<point_type>();
522
523 test_multilinestring_polygon<point_type>();
524 test_multilinestring_multipolygon<point_type>();
525 test_multilinestring_ring<point_type>();
526 test_multilinestring_box<point_type>();
527 }
528
529 //============================================================================
530
531 BOOST_AUTO_TEST_CASE( test_linear_areal_all )
532 {
533 test_linear_areal<double>();
534 test_linear_areal<int>();
535 #ifdef HAVE_TTMATH
536 test_linear_areal<ttmath_big>();
537 #endif
538 }