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-linear geometries
81 inline void test_segment_segment()
83 typedef bg::model::segment
<P
> S
;
85 typedef test_disjoint tester
;
87 tester::apply("s-s-01",
88 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
89 from_wkt
<S
>("SEGMENT(0 0,0 2)"),
92 tester::apply("s-s-02",
93 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
94 from_wkt
<S
>("SEGMENT(2 0,3 0)"),
97 tester::apply("s-s-03",
98 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
99 from_wkt
<S
>("SEGMENT(1 0,3 0)"),
102 tester::apply("s-s-04",
103 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
104 from_wkt
<S
>("SEGMENT(1 0,1 1)"),
107 tester::apply("s-s-05",
108 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
109 from_wkt
<S
>("SEGMENT(1 1,2 2)"),
112 tester::apply("s-s-06",
113 from_wkt
<S
>("SEGMENT(0 0,1 1)"),
114 from_wkt
<S
>("SEGMENT(1 1,1 1)"),
117 tester::apply("s-s-07",
118 from_wkt
<S
>("SEGMENT(0 0,1 1)"),
119 from_wkt
<S
>("SEGMENT(2 2,2 2)"),
122 tester::apply("s-s-08",
123 from_wkt
<S
>("SEGMENT(0 0,1 1)"),
124 from_wkt
<S
>("SEGMENT(2 2,3 3)"),
128 template <typename P
>
129 inline void test_linestring_segment()
131 typedef bg::model::segment
<P
> S
;
132 typedef bg::model::linestring
<P
> L
;
134 typedef test_disjoint tester
;
136 tester::apply("l-s-01",
137 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
138 from_wkt
<L
>("LINESTRING(0 0,0 2)"),
141 tester::apply("l-s-02",
142 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
143 from_wkt
<L
>("LINESTRING(2 0,3 0)"),
146 tester::apply("l-s-03",
147 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
148 from_wkt
<L
>("LINESTRING(1 0,3 0)"),
151 tester::apply("l-s-04",
152 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
153 from_wkt
<L
>("LINESTRING(1 0,1 1)"),
156 tester::apply("l-s-05",
157 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
158 from_wkt
<L
>("LINESTRING(1 1,2 2)"),
161 tester::apply("l-s-06",
162 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
163 from_wkt
<L
>("LINESTRING(1 1,1 1,2 2)"),
166 tester::apply("l-s-07",
167 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
168 from_wkt
<L
>("LINESTRING(1 0,1 0,1 1,2 2)"),
171 tester::apply("l-s-08",
172 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
173 from_wkt
<L
>("LINESTRING(1 0,1 0,3 0)"),
176 tester::apply("l-s-09",
177 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
178 from_wkt
<L
>("LINESTRING(3 0,3 0,4 0)"),
181 tester::apply("l-s-10",
182 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
183 from_wkt
<L
>("LINESTRING(3 0,3 0)"),
186 tester::apply("l-s-11",
187 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
188 from_wkt
<L
>("LINESTRING(-1 0,-1 0)"),
191 tester::apply("l-s-12",
192 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
193 from_wkt
<L
>("LINESTRING(1 0,1 0)"),
196 tester::apply("l-s-13",
197 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
198 from_wkt
<L
>("LINESTRING(1 1,1 1)"),
202 template <typename P
>
203 inline void test_multilinestring_segment()
205 typedef bg::model::segment
<P
> S
;
206 typedef bg::model::linestring
<P
> L
;
207 typedef bg::model::multi_linestring
<L
> ML
;
209 typedef test_disjoint tester
;
211 tester::apply("s-ml-01",
212 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
213 from_wkt
<ML
>("MULTILINESTRING((0 0,0 2))"),
216 tester::apply("s-ml-02",
217 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
218 from_wkt
<ML
>("MULTILINESTRING((2 0,3 0))"),
221 tester::apply("s-ml-03",
222 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
223 from_wkt
<ML
>("MULTILINESTRING((1 0,3 0))"),
226 tester::apply("s-ml-04",
227 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
228 from_wkt
<ML
>("MULTILINESTRING((1 0,1 1))"),
231 tester::apply("s-ml-05",
232 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
233 from_wkt
<ML
>("MULTILINESTRING((1 1,2 2))"),
236 tester::apply("s-ml-06",
237 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
238 from_wkt
<ML
>("MULTILINESTRING((1 1,2 2),(3 3,3 3))"),
241 tester::apply("s-ml-07",
242 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
243 from_wkt
<ML
>("MULTILINESTRING((1 1,2 2),(1 0,1 0))"),
246 tester::apply("s-ml-08",
247 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
248 from_wkt
<ML
>("MULTILINESTRING((1 1,2 2),(3 0,3 0))"),
252 template <typename P
>
253 inline void test_linestring_linestring()
255 typedef bg::model::linestring
<P
> L
;
257 typedef test_disjoint tester
;
259 tester::apply("l-l-01",
260 from_wkt
<L
>("LINESTRING(0 0,2 0)"),
261 from_wkt
<L
>("LINESTRING(0 0,0 2)"),
264 tester::apply("l-l-02",
265 from_wkt
<L
>("LINESTRING(0 0,2 0)"),
266 from_wkt
<L
>("LINESTRING(2 0,3 0)"),
269 tester::apply("l-l-03",
270 from_wkt
<L
>("LINESTRING(0 0,2 0)"),
271 from_wkt
<L
>("LINESTRING(1 0,3 0)"),
274 tester::apply("l-l-04",
275 from_wkt
<L
>("LINESTRING(0 0,2 0)"),
276 from_wkt
<L
>("LINESTRING(1 0,1 1)"),
279 tester::apply("l-l-05",
280 from_wkt
<L
>("LINESTRING(0 0,2 0)"),
281 from_wkt
<L
>("LINESTRING(1 1,2 2)"),
285 template <typename P
>
286 inline void test_linestring_multilinestring()
288 typedef bg::model::linestring
<P
> L
;
289 typedef bg::model::multi_linestring
<L
> ML
;
291 typedef test_disjoint tester
;
293 tester::apply("l-ml-01",
294 from_wkt
<L
>("LINESTRING(0 0,2 0)"),
295 from_wkt
<ML
>("MULTILINESTRING((0 0,0 2))"),
298 tester::apply("l-ml-02",
299 from_wkt
<L
>("LINESTRING(0 0,2 0)"),
300 from_wkt
<ML
>("MULTILINESTRING((2 0,3 0))"),
303 tester::apply("l-ml-03",
304 from_wkt
<L
>("LINESTRING(0 0,2 0)"),
305 from_wkt
<ML
>("MULTILINESTRING((1 0,3 0))"),
308 tester::apply("l-ml-04",
309 from_wkt
<L
>("LINESTRING(0 0,2 0)"),
310 from_wkt
<ML
>("MULTILINESTRING((1 0,1 1))"),
313 tester::apply("l-ml-05",
314 from_wkt
<L
>("LINESTRING(0 0,2 0)"),
315 from_wkt
<ML
>("MULTILINESTRING((1 1,2 2))"),
319 template <typename P
>
320 inline void test_multilinestring_multilinestring()
322 typedef bg::model::linestring
<P
> L
;
323 typedef bg::model::multi_linestring
<L
> ML
;
325 typedef test_disjoint tester
;
327 tester::apply("ml-ml-01",
328 from_wkt
<ML
>("MULTILINESTRING((0 0,2 0))"),
329 from_wkt
<ML
>("MULTILINESTRING((0 0,0 2))"),
332 tester::apply("ml-ml-02",
333 from_wkt
<ML
>("MULTILINESTRING((0 0,2 0))"),
334 from_wkt
<ML
>("MULTILINESTRING((2 0,3 0))"),
337 tester::apply("ml-ml-03",
338 from_wkt
<ML
>("MULTILINESTRING((0 0,2 0))"),
339 from_wkt
<ML
>("MULTILINESTRING((1 0,3 0))"),
342 tester::apply("ml-ml-04",
343 from_wkt
<ML
>("MULTILINESTRING((0 0,2 0))"),
344 from_wkt
<ML
>("MULTILINESTRING((1 0,1 1))"),
347 tester::apply("ml-ml-05",
348 from_wkt
<ML
>("MULTILINESTRING((0 0,2 0))"),
349 from_wkt
<ML
>("MULTILINESTRING((1 1,2 2))"),
353 //============================================================================
355 template <typename CoordinateType
>
356 inline void test_linear_linear()
358 typedef bg::model::point
<CoordinateType
, 2, bg::cs::cartesian
> point_type
;
360 test_linestring_linestring
<point_type
>();
361 test_linestring_multilinestring
<point_type
>();
362 test_linestring_segment
<point_type
>();
364 test_multilinestring_multilinestring
<point_type
>();
365 test_multilinestring_segment
<point_type
>();
367 test_segment_segment
<point_type
>();
370 //============================================================================
372 BOOST_AUTO_TEST_CASE( test_linear_linear_all
)
374 test_linear_linear
<double>();
375 test_linear_linear
<int>();
377 test_linear_linear
<ttmath_big
>();