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>
35 namespace bg
= ::boost::geometry
;
37 //============================================================================
41 template <typename Geometry1
, typename Geometry2
>
42 static inline void apply(std::string
const& case_id
,
43 Geometry1
const& geometry1
,
44 Geometry2
const& geometry2
,
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
);
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
);
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
;
72 //============================================================================
74 // areal-areal geometries
76 inline void test_box_box()
78 typedef bg::model::box
<P
> B
;
80 typedef test_disjoint tester
;
82 tester::apply("b-b-01",
83 from_wkt
<B
>("BOX(2 2,3 3)"),
84 from_wkt
<B
>("BOX(0 0,2 2)"),
87 tester::apply("b-b-02",
88 from_wkt
<B
>("BOX(1 1,3 3)"),
89 from_wkt
<B
>("BOX(0 0,2 2)"),
92 tester::apply("b-b-03",
93 from_wkt
<B
>("BOX(3 3,4 4)"),
94 from_wkt
<B
>("BOX(0 0,2 2)"),
99 inline void test_ring_box()
101 typedef bg::model::box
<P
> B
;
102 typedef bg::model::ring
<P
, false, false> R
; // ccw, open
104 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
122 template <typename P
>
123 inline void test_polygon_box()
125 typedef bg::model::box
<P
> B
;
126 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
128 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
146 template <typename P
>
147 inline void test_multipolygon_box()
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
;
153 typedef test_disjoint tester
;
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)))"),
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)))"),
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)))"),
171 template <typename P
>
172 inline void test_ring_ring()
174 typedef bg::model::ring
<P
, false, false> R
; // ccw, open
176 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
194 template <typename P
>
195 inline void test_polygon_ring()
197 typedef bg::model::ring
<P
, false, false> R
; // ccw, open
198 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
200 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
218 template <typename P
>
219 inline void test_multipolygon_ring()
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
;
225 typedef test_disjoint tester
;
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)))"),
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)))"),
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)))"),
243 template <typename P
>
244 inline void test_polygon_polygon()
246 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
248 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
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))"),
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))"),
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))"),
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))"),
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))"),
293 typedef bg::model::polygon
<P
> PL
; // cw, closed
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))"),
303 template <typename P
>
304 inline void test_polygon_multipolygon()
306 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
307 typedef bg::model::multi_polygon
<PL
> MPL
;
309 typedef test_disjoint tester
;
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)))"),
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)))"),
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)))"),
327 template <typename P
>
328 inline void test_multipolygon_multipolygon()
330 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
331 typedef bg::model::multi_polygon
<PL
> MPL
;
333 typedef test_disjoint tester
;
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)))"),
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)))"),
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)))"),
351 //============================================================================
353 template <typename CoordinateType
>
354 inline void test_areal_areal()
356 typedef bg::model::point
<CoordinateType
, 2, bg::cs::cartesian
> point_type
;
358 test_polygon_polygon
<point_type
>();
359 test_polygon_multipolygon
<point_type
>();
360 test_polygon_ring
<point_type
>();
361 test_polygon_box
<point_type
>();
363 test_multipolygon_multipolygon
<point_type
>();
364 test_multipolygon_ring
<point_type
>();
365 test_multipolygon_box
<point_type
>();
367 test_ring_ring
<point_type
>();
368 test_ring_box
<point_type
>();
370 test_box_box
<point_type
>();
373 //============================================================================
375 BOOST_AUTO_TEST_CASE( test_areal_areal_all
)
377 test_areal_areal
<double>();
378 test_areal_areal
<int>();