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 // areal-areal geometries
81 inline void test_box_box()
83 typedef bg::model::box
<P
> B
;
85 typedef test_disjoint tester
;
87 tester::apply("b-b-01",
88 from_wkt
<B
>("BOX(2 2,3 3)"),
89 from_wkt
<B
>("BOX(0 0,2 2)"),
92 tester::apply("b-b-02",
93 from_wkt
<B
>("BOX(1 1,3 3)"),
94 from_wkt
<B
>("BOX(0 0,2 2)"),
97 tester::apply("b-b-03",
98 from_wkt
<B
>("BOX(3 3,4 4)"),
99 from_wkt
<B
>("BOX(0 0,2 2)"),
103 template <typename P
>
104 inline void test_ring_box()
106 typedef bg::model::box
<P
> B
;
107 typedef bg::model::ring
<P
, false, false> R
; // ccw, open
109 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
127 template <typename P
>
128 inline void test_polygon_box()
130 typedef bg::model::box
<P
> B
;
131 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
133 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
151 template <typename P
>
152 inline void test_multipolygon_box()
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
;
158 typedef test_disjoint tester
;
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)))"),
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)))"),
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)))"),
176 template <typename P
>
177 inline void test_ring_ring()
179 typedef bg::model::ring
<P
, false, false> R
; // ccw, open
181 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
199 template <typename P
>
200 inline void test_polygon_ring()
202 typedef bg::model::ring
<P
, false, false> R
; // ccw, open
203 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
205 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
223 template <typename P
>
224 inline void test_multipolygon_ring()
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
;
230 typedef test_disjoint tester
;
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)))"),
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)))"),
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)))"),
248 template <typename P
>
249 inline void test_polygon_polygon()
251 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
253 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
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))"),
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))"),
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))"),
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))"),
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))"),
298 typedef bg::model::polygon
<P
> PL
; // cw, closed
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))"),
308 template <typename P
>
309 inline void test_polygon_multipolygon()
311 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
312 typedef bg::model::multi_polygon
<PL
> MPL
;
314 typedef test_disjoint tester
;
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)))"),
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)))"),
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)))"),
332 template <typename P
>
333 inline void test_multipolygon_multipolygon()
335 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
336 typedef bg::model::multi_polygon
<PL
> MPL
;
338 typedef test_disjoint tester
;
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)))"),
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)))"),
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)))"),
356 //============================================================================
358 template <typename CoordinateType
>
359 inline void test_areal_areal()
361 typedef bg::model::point
<CoordinateType
, 2, bg::cs::cartesian
> point_type
;
363 test_polygon_polygon
<point_type
>();
364 test_polygon_multipolygon
<point_type
>();
365 test_polygon_ring
<point_type
>();
366 test_polygon_box
<point_type
>();
368 test_multipolygon_multipolygon
<point_type
>();
369 test_multipolygon_ring
<point_type
>();
370 test_multipolygon_box
<point_type
>();
372 test_ring_ring
<point_type
>();
373 test_ring_box
<point_type
>();
375 test_box_box
<point_type
>();
378 //============================================================================
380 BOOST_AUTO_TEST_CASE( test_areal_areal_all
)
382 test_areal_areal
<double>();
383 test_areal_areal
<int>();
385 test_areal_areal
<ttmath_big
>();