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 // pointlike-linear geometries
81 inline void test_point_segment()
83 typedef test_disjoint tester
;
84 typedef bg::model::segment
<P
> S
;
86 tester::apply("p-s-01",
87 from_wkt
<P
>("POINT(0 0)"),
88 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
91 tester::apply("p-s-02",
92 from_wkt
<P
>("POINT(2 0)"),
93 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
96 tester::apply("p-s-03",
97 from_wkt
<P
>("POINT(1 0)"),
98 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
101 tester::apply("p-s-04",
102 from_wkt
<P
>("POINT(1 1)"),
103 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
106 tester::apply("p-s-05",
107 from_wkt
<P
>("POINT(3 0)"),
108 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
111 tester::apply("p-s-06",
112 from_wkt
<P
>("POINT(-1 0)"),
113 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
116 // degenerate segment
117 tester::apply("p-s-07",
118 from_wkt
<P
>("POINT(-1 0)"),
119 from_wkt
<S
>("SEGMENT(2 0,2 0)"),
122 // degenerate segment
123 tester::apply("p-s-08",
124 from_wkt
<P
>("POINT(2 0)"),
125 from_wkt
<S
>("SEGMENT(2 0,2 0)"),
128 // degenerate segment
129 tester::apply("p-s-09",
130 from_wkt
<P
>("POINT(3 0)"),
131 from_wkt
<S
>("SEGMENT(2 0,2 0)"),
134 // degenerate segment
135 tester::apply("p-s-10",
136 from_wkt
<P
>("POINT(1 1)"),
137 from_wkt
<S
>("SEGMENT(2 0,2 0)"),
141 template <typename P
>
142 inline void test_point_linestring()
144 typedef bg::model::linestring
<P
> L
;
146 typedef test_disjoint tester
;
148 tester::apply("p-l-01",
149 from_wkt
<P
>("POINT(0 0)"),
150 from_wkt
<L
>("LINESTRING(0 0,2 2,4 4)"),
153 tester::apply("p-l-02",
154 from_wkt
<P
>("POINT(1 1)"),
155 from_wkt
<L
>("LINESTRING(0 0,2 2,4 4)"),
158 tester::apply("p-l-03",
159 from_wkt
<P
>("POINT(3 3)"),
160 from_wkt
<L
>("LINESTRING(0 0,2 2,4 4)"),
163 tester::apply("p-l-04",
164 from_wkt
<P
>("POINT(1 0)"),
165 from_wkt
<L
>("LINESTRING(0 0,2 2,4 4)"),
168 tester::apply("p-l-05",
169 from_wkt
<P
>("POINT(5 5)"),
170 from_wkt
<L
>("LINESTRING(0 0,2 2,4 4)"),
173 tester::apply("p-l-06",
174 from_wkt
<P
>("POINT(5 5)"),
175 from_wkt
<L
>("LINESTRING(0 0,2 2)"),
179 template <typename P
>
180 inline void test_point_multilinestring()
182 typedef bg::model::linestring
<P
> L
;
183 typedef bg::model::multi_linestring
<L
> ML
;
185 typedef test_disjoint tester
;
187 tester::apply("p-ml-01",
188 from_wkt
<P
>("POINT(0 1)"),
189 from_wkt
<ML
>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
192 tester::apply("p-ml-02",
193 from_wkt
<P
>("POINT(0 0)"),
194 from_wkt
<ML
>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
197 tester::apply("p-ml-03",
198 from_wkt
<P
>("POINT(1 1)"),
199 from_wkt
<ML
>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
202 tester::apply("p-ml-04",
203 from_wkt
<P
>("POINT(1 0)"),
204 from_wkt
<ML
>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
207 tester::apply("p-ml-05",
208 from_wkt
<P
>("POINT(0 0)"),
209 from_wkt
<ML
>("MULTILINESTRING((1 1,2 2,4 4),(3 0,4 0))"),
212 tester::apply("p-ml-06",
213 from_wkt
<P
>("POINT(0 0)"),
214 from_wkt
<ML
>("MULTILINESTRING((1 1,2 2,4 4),(0 0,4 0))"),
217 tester::apply("p-ml-07",
218 from_wkt
<P
>("POINT(0 0)"),
219 from_wkt
<ML
>("MULTILINESTRING((1 1,2 2,4 4),(-1 0,4 0))"),
223 template <typename P
>
224 inline void test_multipoint_segment()
226 typedef test_disjoint tester
;
227 typedef bg::model::multi_point
<P
> MP
;
228 typedef bg::model::segment
<P
> S
;
230 tester::apply("mp-s-01",
231 from_wkt
<MP
>("MULTIPOINT(0 0,1 1)"),
232 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
235 tester::apply("mp-s-02",
236 from_wkt
<MP
>("MULTIPOINT(1 0,1 1)"),
237 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
240 tester::apply("mp-s-03",
241 from_wkt
<MP
>("MULTIPOINT(1 1,2 2)"),
242 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
245 tester::apply("mp-s-04",
246 from_wkt
<MP
>("MULTIPOINT()"),
247 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
250 tester::apply("mp-s-05",
251 from_wkt
<MP
>("MULTIPOINT(3 0,4 0)"),
252 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
255 tester::apply("mp-s-06",
256 from_wkt
<MP
>("MULTIPOINT(1 0,4 0)"),
257 from_wkt
<S
>("SEGMENT(0 0,2 0)"),
260 // segments that degenerate to a point
261 tester::apply("mp-s-07",
262 from_wkt
<MP
>("MULTIPOINT(1 1,2 2)"),
263 from_wkt
<S
>("SEGMENT(0 0,0 0)"),
266 tester::apply("mp-s-08",
267 from_wkt
<MP
>("MULTIPOINT(1 1,2 2)"),
268 from_wkt
<S
>("SEGMENT(1 1,1 1)"),
272 template <typename P
>
273 inline void test_multipoint_linestring()
275 typedef bg::model::multi_point
<P
> MP
;
276 typedef bg::model::linestring
<P
> L
;
278 typedef test_disjoint tester
;
280 tester::apply("mp-l-01",
281 from_wkt
<MP
>("MULTIPOINT(0 0,1 0)"),
282 from_wkt
<L
>("LINESTRING(0 0,2 2,4 4)"),
285 tester::apply("mp-l-02",
286 from_wkt
<MP
>("MULTIPOINT(1 0,1 1)"),
287 from_wkt
<L
>("LINESTRING(0 0,2 2,4 4)"),
290 tester::apply("mp-l-03",
291 from_wkt
<MP
>("MULTIPOINT(1 0,3 3)"),
292 from_wkt
<L
>("LINESTRING(0 0,2 2,4 4)"),
295 tester::apply("mp-l-04",
296 from_wkt
<MP
>("MULTIPOINT(1 0,2 0)"),
297 from_wkt
<L
>("LINESTRING(0 0,2 2,4 4)"),
300 tester::apply("mp-l-05",
301 from_wkt
<MP
>("MULTIPOINT(-1 -1,2 0)"),
302 from_wkt
<L
>("LINESTRING(0 0,2 2,4 4)"),
305 tester::apply("mp-l-06",
306 from_wkt
<MP
>("MULTIPOINT(-1 -1,2 0)"),
307 from_wkt
<L
>("LINESTRING(1 0,3 0)"),
310 tester::apply("mp-l-07",
311 from_wkt
<MP
>("MULTIPOINT(-1 -1,2 0,-1 -1,2 0)"),
312 from_wkt
<L
>("LINESTRING(1 0,3 0)"),
315 tester::apply("mp-l-08",
316 from_wkt
<MP
>("MULTIPOINT(2 0)"),
317 from_wkt
<L
>("LINESTRING(1 0)"),
320 tester::apply("mp-l-09",
321 from_wkt
<MP
>("MULTIPOINT(3 0,0 0,3 0)"),
322 from_wkt
<L
>("LINESTRING(1 0,2 0)"),
326 template <typename P
>
327 inline void test_multipoint_multilinestring()
329 typedef bg::model::multi_point
<P
> MP
;
330 typedef bg::model::linestring
<P
> L
;
331 typedef bg::model::multi_linestring
<L
> ML
;
333 typedef test_disjoint tester
;
335 tester::apply("mp-ml-01",
336 from_wkt
<MP
>("MULTIPOINT(0 1,0 2)"),
337 from_wkt
<ML
>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
340 tester::apply("mp-ml-02",
341 from_wkt
<MP
>("MULTIPOINT(0 0,1 0)"),
342 from_wkt
<ML
>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
345 tester::apply("mp-ml-03",
346 from_wkt
<MP
>("MULTIPOINT(0 1,1 1)"),
347 from_wkt
<ML
>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
350 tester::apply("mp-ml-04",
351 from_wkt
<MP
>("MULTIPOINT(0 1,1 0)"),
352 from_wkt
<ML
>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
355 tester::apply("mp-ml-05",
356 from_wkt
<MP
>("MULTIPOINT(0 0,10 0)"),
357 from_wkt
<ML
>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
360 tester::apply("mp-ml-06",
361 from_wkt
<MP
>("MULTIPOINT(-1 0,3 0)"),
362 from_wkt
<ML
>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
366 //============================================================================
368 template <typename CoordinateType
>
369 inline void test_pointlike_linear()
371 typedef bg::model::point
<CoordinateType
, 2, bg::cs::cartesian
> point_type
;
373 test_point_linestring
<point_type
>();
374 test_point_multilinestring
<point_type
>();
375 test_point_segment
<point_type
>();
377 test_multipoint_linestring
<point_type
>();
378 test_multipoint_multilinestring
<point_type
>();
379 test_multipoint_segment
<point_type
>();
382 //============================================================================
384 BOOST_AUTO_TEST_CASE( test_pointlike_linear_all
)
386 test_pointlike_linear
<double>();
387 test_pointlike_linear
<int>();
389 test_pointlike_linear
<ttmath_big
>();