1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2014-2015, Oracle and/or its affiliates.
5 // Licensed under the Boost Software License version 1.0.
6 // http://www.boost.org/users/license.html
8 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11 #ifndef BOOST_TEST_MODULE
12 #define BOOST_TEST_MODULE test_disjoint_coverage
15 // unit test to test disjoint for all geometry combinations
19 #include <boost/test/included/unit_test.hpp>
21 #include <boost/geometry/core/tag.hpp>
22 #include <boost/geometry/core/tags.hpp>
24 #include <boost/geometry/strategies/strategies.hpp>
26 #include <boost/geometry/io/wkt/wkt.hpp>
27 #include <boost/geometry/io/dsv/write.hpp>
29 #include <boost/geometry/geometries/geometries.hpp>
31 #include <boost/geometry/algorithms/disjoint.hpp>
33 #include <from_wkt.hpp>
37 #include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
40 namespace bg
= ::boost::geometry
;
42 //============================================================================
46 template <typename Geometry1
, typename Geometry2
>
47 static inline void apply(std::string
const& case_id
,
48 Geometry1
const& geometry1
,
49 Geometry2
const& geometry2
,
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
);
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
);
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
;
77 //============================================================================
79 // linear-areal geometries
81 inline void test_segment_box()
83 typedef bg::model::segment
<P
> S
;
84 typedef bg::model::box
<P
> B
;
86 typedef test_disjoint tester
;
88 tester::apply("s-b-01",
89 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
90 from_wkt
<B
>("BOX(0 0,2 2)"),
93 tester::apply("s-b-02",
94 from_wkt
<S
>("SEGMENT(1 1,3 3)"),
95 from_wkt
<B
>("BOX(0 0,2 2)"),
98 tester::apply("s-b-03",
99 from_wkt
<S
>("SEGMENT(2 2,3 3)"),
100 from_wkt
<B
>("BOX(0 0,2 2)"),
103 tester::apply("s-b-04",
104 from_wkt
<S
>("SEGMENT(4 4,3 3)"),
105 from_wkt
<B
>("BOX(0 0,2 2)"),
108 tester::apply("s-b-05",
109 from_wkt
<S
>("SEGMENT(0 4,4 4)"),
110 from_wkt
<B
>("BOX(0 0,2 2)"),
113 tester::apply("s-b-06",
114 from_wkt
<S
>("SEGMENT(4 0,4 4)"),
115 from_wkt
<B
>("BOX(0 0,2 2)"),
118 tester::apply("s-b-07",
119 from_wkt
<S
>("SEGMENT(0 -2,0 -1)"),
120 from_wkt
<B
>("BOX(0 0,1 1)"),
123 tester::apply("s-b-08",
124 from_wkt
<S
>("SEGMENT(-2 -2,-2 -1)"),
125 from_wkt
<B
>("BOX(0 0,1 1)"),
128 tester::apply("s-b-09",
129 from_wkt
<S
>("SEGMENT(-2 -2,-2 -2)"),
130 from_wkt
<B
>("BOX(0 0,1 1)"),
133 tester::apply("s-b-10",
134 from_wkt
<S
>("SEGMENT(-2 0,-2 0)"),
135 from_wkt
<B
>("BOX(0 0,1 1)"),
138 tester::apply("s-b-11",
139 from_wkt
<S
>("SEGMENT(0 -2,0 -2)"),
140 from_wkt
<B
>("BOX(0 0,1 1)"),
143 tester::apply("s-b-12",
144 from_wkt
<S
>("SEGMENT(-2 0,-1 0)"),
145 from_wkt
<B
>("BOX(0 0,1 1)"),
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)"),
154 tester::apply("s-b-14",
155 from_wkt
<S
>("SEGMENT(1 1,1 1)"),
156 from_wkt
<B
>("BOX(0 0,2 2)"),
159 tester::apply("s-b-15",
160 from_wkt
<S
>("SEGMENT(2 2,2 2)"),
161 from_wkt
<B
>("BOX(0 0,2 2)"),
164 tester::apply("s-b-16",
165 from_wkt
<S
>("SEGMENT(2 0,2 0)"),
166 from_wkt
<B
>("BOX(0 0,2 2)"),
169 tester::apply("s-b-17",
170 from_wkt
<S
>("SEGMENT(0 2,0 2)"),
171 from_wkt
<B
>("BOX(0 0,2 2)"),
174 tester::apply("s-b-18",
175 from_wkt
<S
>("SEGMENT(2 2,2 2)"),
176 from_wkt
<B
>("BOX(0 0,1 1)"),
180 template <typename P
>
181 inline void test_segment_ring()
183 typedef bg::model::segment
<P
> S
;
184 typedef bg::model::ring
<P
, false, false> R
; // ccw, open
186 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
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))"),
209 template <typename P
>
210 inline void test_segment_polygon()
212 typedef bg::model::segment
<P
> S
;
213 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
215 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
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))"),
238 template <typename P
>
239 inline void test_segment_multipolygon()
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
;
245 typedef test_disjoint tester
;
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)))"),
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)))"),
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)))"),
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)))"),
268 template <typename P
>
269 inline void test_linestring_box()
271 typedef bg::model::linestring
<P
> L
;
272 typedef bg::model::box
<P
> B
;
274 typedef test_disjoint tester
;
276 tester::apply("l-b-01",
277 from_wkt
<L
>("LINESTRING(0 0,2 0)"),
278 from_wkt
<B
>("BOX(0 0,2 2)"),
281 tester::apply("l-b-02",
282 from_wkt
<L
>("LINESTRING(1 1,3 3)"),
283 from_wkt
<B
>("BOX(0 0,2 2)"),
286 tester::apply("l-b-03",
287 from_wkt
<L
>("LINESTRING(2 2,3 3)"),
288 from_wkt
<B
>("BOX(0 0,2 2)"),
291 tester::apply("l-b-04",
292 from_wkt
<L
>("LINESTRING(4 4,3 3)"),
293 from_wkt
<B
>("BOX(0 0,2 2)"),
297 template <typename P
>
298 inline void test_linestring_ring()
300 typedef bg::model::linestring
<P
> L
;
301 typedef bg::model::ring
<P
, false, false> R
; // ccw, open
303 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
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))"),
326 template <typename P
>
327 inline void test_linestring_polygon()
329 typedef bg::model::linestring
<P
> L
;
330 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
332 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
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))"),
355 template <typename P
>
356 inline void test_linestring_multipolygon()
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
;
362 typedef test_disjoint tester
;
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)))"),
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)))"),
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)))"),
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)))"),
385 template <typename P
>
386 inline void test_multilinestring_box()
388 typedef bg::model::linestring
<P
> L
;
389 typedef bg::model::multi_linestring
<L
> ML
;
390 typedef bg::model::box
<P
> B
;
392 typedef test_disjoint tester
;
394 tester::apply("ml-b-01",
395 from_wkt
<ML
>("MULTILINESTRING((0 0,2 0))"),
396 from_wkt
<B
>("BOX(0 0,2 2)"),
399 tester::apply("ml-b-02",
400 from_wkt
<ML
>("MULTILINESTRING((1 1,3 3))"),
401 from_wkt
<B
>("BOX(0 0,2 2)"),
404 tester::apply("ml-b-03",
405 from_wkt
<ML
>("MULTILINESTRING((2 2,3 3))"),
406 from_wkt
<B
>("BOX(0 0,2 2)"),
409 tester::apply("ml-b-04",
410 from_wkt
<ML
>("MULTILINESTRING((4 4,3 3))"),
411 from_wkt
<B
>("BOX(0 0,2 2)"),
415 template <typename P
>
416 inline void test_multilinestring_ring()
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
422 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
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))"),
445 template <typename P
>
446 inline void test_multilinestring_polygon()
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
452 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
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))"),
475 template <typename P
>
476 inline void test_multilinestring_multipolygon()
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
;
483 typedef test_disjoint tester
;
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)))"),
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)))"),
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)))"),
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)))"),
506 //============================================================================
508 template <typename CoordinateType
>
509 inline void test_linear_areal()
511 typedef bg::model::point
<CoordinateType
, 2, bg::cs::cartesian
> point_type
;
513 test_segment_polygon
<point_type
>();
514 test_segment_multipolygon
<point_type
>();
515 test_segment_ring
<point_type
>();
516 test_segment_box
<point_type
>();
518 test_linestring_polygon
<point_type
>();
519 test_linestring_multipolygon
<point_type
>();
520 test_linestring_ring
<point_type
>();
521 test_linestring_box
<point_type
>();
523 test_multilinestring_polygon
<point_type
>();
524 test_multilinestring_multipolygon
<point_type
>();
525 test_multilinestring_ring
<point_type
>();
526 test_multilinestring_box
<point_type
>();
529 //============================================================================
531 BOOST_AUTO_TEST_CASE( test_linear_areal_all
)
533 test_linear_areal
<double>();
534 test_linear_areal
<int>();
536 test_linear_areal
<ttmath_big
>();