]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2014-2015, Oracle and/or its affiliates. | |
4 | ||
5 | // Licensed under the Boost Software License version 1.0. | |
6 | // http://www.boost.org/users/license.html | |
7 | ||
8 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle | |
9 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
10 | ||
11 | #ifndef BOOST_TEST_MODULE | |
12 | #define BOOST_TEST_MODULE test_disjoint_coverage | |
13 | #endif | |
14 | ||
15 | // unit test to test disjoint for all geometry combinations | |
16 | ||
17 | #include <iostream> | |
18 | ||
19 | #include <boost/test/included/unit_test.hpp> | |
20 | ||
21 | #include <boost/geometry/core/tag.hpp> | |
22 | #include <boost/geometry/core/tags.hpp> | |
23 | ||
24 | #include <boost/geometry/strategies/strategies.hpp> | |
25 | ||
26 | #include <boost/geometry/io/wkt/wkt.hpp> | |
27 | #include <boost/geometry/io/dsv/write.hpp> | |
28 | ||
29 | #include <boost/geometry/geometries/geometries.hpp> | |
30 | ||
31 | #include <boost/geometry/algorithms/disjoint.hpp> | |
32 | ||
33 | #include <from_wkt.hpp> | |
34 | ||
35 | ||
7c673cae FG |
36 | namespace bg = ::boost::geometry; |
37 | ||
38 | //============================================================================ | |
39 | ||
40 | struct test_disjoint | |
41 | { | |
42 | template <typename Geometry1, typename Geometry2> | |
43 | static inline void apply(std::string const& case_id, | |
44 | Geometry1 const& geometry1, | |
45 | Geometry2 const& geometry2, | |
46 | bool expected_result) | |
47 | { | |
48 | bool result = bg::disjoint(geometry1, geometry2); | |
49 | BOOST_CHECK_MESSAGE(result == expected_result, | |
50 | "case ID: " << case_id << ", G1: " << bg::wkt(geometry1) | |
51 | << ", G2: " << bg::wkt(geometry2) << " -> Expected: " | |
52 | << expected_result << ", detected: " << result); | |
53 | ||
54 | result = bg::disjoint(geometry2, geometry1); | |
55 | BOOST_CHECK_MESSAGE(result == expected_result, | |
56 | "case ID: " << case_id << ", G1: " << bg::wkt(geometry2) | |
57 | << ", G2: " << bg::wkt(geometry1) << " -> Expected: " | |
58 | << expected_result << ", detected: " << result); | |
59 | ||
60 | #ifdef BOOST_GEOMETRY_TEST_DEBUG | |
61 | std::cout << "case ID: " << case_id << "; G1 - G2: "; | |
62 | std::cout << bg::wkt(geometry1) << " - "; | |
63 | std::cout << bg::wkt(geometry2) << std::endl; | |
64 | std::cout << std::boolalpha; | |
65 | std::cout << "expected/computed result: " | |
66 | << expected_result << " / " << result << std::endl; | |
67 | std::cout << std::endl; | |
68 | std::cout << std::noboolalpha; | |
69 | #endif | |
70 | } | |
71 | }; | |
72 | ||
73 | //============================================================================ | |
74 | ||
75 | // pointlike-linear geometries | |
76 | template <typename P> | |
77 | inline void test_point_segment() | |
78 | { | |
79 | typedef test_disjoint tester; | |
80 | typedef bg::model::segment<P> S; | |
81 | ||
82 | tester::apply("p-s-01", | |
83 | from_wkt<P>("POINT(0 0)"), | |
84 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
85 | false); | |
86 | ||
87 | tester::apply("p-s-02", | |
88 | from_wkt<P>("POINT(2 0)"), | |
89 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
90 | false); | |
91 | ||
92 | tester::apply("p-s-03", | |
93 | from_wkt<P>("POINT(1 0)"), | |
94 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
95 | false); | |
96 | ||
97 | tester::apply("p-s-04", | |
98 | from_wkt<P>("POINT(1 1)"), | |
99 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
100 | true); | |
101 | ||
102 | tester::apply("p-s-05", | |
103 | from_wkt<P>("POINT(3 0)"), | |
104 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
105 | true); | |
106 | ||
107 | tester::apply("p-s-06", | |
108 | from_wkt<P>("POINT(-1 0)"), | |
109 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
110 | true); | |
111 | ||
112 | // degenerate segment | |
113 | tester::apply("p-s-07", | |
114 | from_wkt<P>("POINT(-1 0)"), | |
115 | from_wkt<S>("SEGMENT(2 0,2 0)"), | |
116 | true); | |
117 | ||
118 | // degenerate segment | |
119 | tester::apply("p-s-08", | |
120 | from_wkt<P>("POINT(2 0)"), | |
121 | from_wkt<S>("SEGMENT(2 0,2 0)"), | |
122 | false); | |
123 | ||
124 | // degenerate segment | |
125 | tester::apply("p-s-09", | |
126 | from_wkt<P>("POINT(3 0)"), | |
127 | from_wkt<S>("SEGMENT(2 0,2 0)"), | |
128 | true); | |
129 | ||
130 | // degenerate segment | |
131 | tester::apply("p-s-10", | |
132 | from_wkt<P>("POINT(1 1)"), | |
133 | from_wkt<S>("SEGMENT(2 0,2 0)"), | |
134 | true); | |
135 | } | |
136 | ||
137 | template <typename P> | |
138 | inline void test_point_linestring() | |
139 | { | |
140 | typedef bg::model::linestring<P> L; | |
141 | ||
142 | typedef test_disjoint tester; | |
143 | ||
144 | tester::apply("p-l-01", | |
145 | from_wkt<P>("POINT(0 0)"), | |
146 | from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), | |
147 | false); | |
148 | ||
149 | tester::apply("p-l-02", | |
150 | from_wkt<P>("POINT(1 1)"), | |
151 | from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), | |
152 | false); | |
153 | ||
154 | tester::apply("p-l-03", | |
155 | from_wkt<P>("POINT(3 3)"), | |
156 | from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), | |
157 | false); | |
158 | ||
159 | tester::apply("p-l-04", | |
160 | from_wkt<P>("POINT(1 0)"), | |
161 | from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), | |
162 | true); | |
163 | ||
164 | tester::apply("p-l-05", | |
165 | from_wkt<P>("POINT(5 5)"), | |
166 | from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), | |
167 | true); | |
168 | ||
169 | tester::apply("p-l-06", | |
170 | from_wkt<P>("POINT(5 5)"), | |
171 | from_wkt<L>("LINESTRING(0 0,2 2)"), | |
172 | true); | |
173 | } | |
174 | ||
175 | template <typename P> | |
176 | inline void test_point_multilinestring() | |
177 | { | |
178 | typedef bg::model::linestring<P> L; | |
179 | typedef bg::model::multi_linestring<L> ML; | |
180 | ||
181 | typedef test_disjoint tester; | |
182 | ||
183 | tester::apply("p-ml-01", | |
184 | from_wkt<P>("POINT(0 1)"), | |
185 | from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), | |
186 | true); | |
187 | ||
188 | tester::apply("p-ml-02", | |
189 | from_wkt<P>("POINT(0 0)"), | |
190 | from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), | |
191 | false); | |
192 | ||
193 | tester::apply("p-ml-03", | |
194 | from_wkt<P>("POINT(1 1)"), | |
195 | from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), | |
196 | false); | |
197 | ||
198 | tester::apply("p-ml-04", | |
199 | from_wkt<P>("POINT(1 0)"), | |
200 | from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), | |
201 | false); | |
202 | ||
203 | tester::apply("p-ml-05", | |
204 | from_wkt<P>("POINT(0 0)"), | |
205 | from_wkt<ML>("MULTILINESTRING((1 1,2 2,4 4),(3 0,4 0))"), | |
206 | true); | |
207 | ||
208 | tester::apply("p-ml-06", | |
209 | from_wkt<P>("POINT(0 0)"), | |
210 | from_wkt<ML>("MULTILINESTRING((1 1,2 2,4 4),(0 0,4 0))"), | |
211 | false); | |
212 | ||
213 | tester::apply("p-ml-07", | |
214 | from_wkt<P>("POINT(0 0)"), | |
215 | from_wkt<ML>("MULTILINESTRING((1 1,2 2,4 4),(-1 0,4 0))"), | |
216 | false); | |
217 | } | |
218 | ||
219 | template <typename P> | |
220 | inline void test_multipoint_segment() | |
221 | { | |
222 | typedef test_disjoint tester; | |
223 | typedef bg::model::multi_point<P> MP; | |
224 | typedef bg::model::segment<P> S; | |
225 | ||
226 | tester::apply("mp-s-01", | |
227 | from_wkt<MP>("MULTIPOINT(0 0,1 1)"), | |
228 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
229 | false); | |
230 | ||
231 | tester::apply("mp-s-02", | |
232 | from_wkt<MP>("MULTIPOINT(1 0,1 1)"), | |
233 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
234 | false); | |
235 | ||
236 | tester::apply("mp-s-03", | |
237 | from_wkt<MP>("MULTIPOINT(1 1,2 2)"), | |
238 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
239 | true); | |
240 | ||
241 | tester::apply("mp-s-04", | |
242 | from_wkt<MP>("MULTIPOINT()"), | |
243 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
244 | true); | |
245 | ||
246 | tester::apply("mp-s-05", | |
247 | from_wkt<MP>("MULTIPOINT(3 0,4 0)"), | |
248 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
249 | true); | |
250 | ||
251 | tester::apply("mp-s-06", | |
252 | from_wkt<MP>("MULTIPOINT(1 0,4 0)"), | |
253 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
254 | false); | |
255 | ||
256 | // segments that degenerate to a point | |
257 | tester::apply("mp-s-07", | |
258 | from_wkt<MP>("MULTIPOINT(1 1,2 2)"), | |
259 | from_wkt<S>("SEGMENT(0 0,0 0)"), | |
260 | true); | |
261 | ||
262 | tester::apply("mp-s-08", | |
263 | from_wkt<MP>("MULTIPOINT(1 1,2 2)"), | |
264 | from_wkt<S>("SEGMENT(1 1,1 1)"), | |
265 | false); | |
266 | } | |
267 | ||
268 | template <typename P> | |
269 | inline void test_multipoint_linestring() | |
270 | { | |
271 | typedef bg::model::multi_point<P> MP; | |
272 | typedef bg::model::linestring<P> L; | |
273 | ||
274 | typedef test_disjoint tester; | |
275 | ||
276 | tester::apply("mp-l-01", | |
277 | from_wkt<MP>("MULTIPOINT(0 0,1 0)"), | |
278 | from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), | |
279 | false); | |
280 | ||
281 | tester::apply("mp-l-02", | |
282 | from_wkt<MP>("MULTIPOINT(1 0,1 1)"), | |
283 | from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), | |
284 | false); | |
285 | ||
286 | tester::apply("mp-l-03", | |
287 | from_wkt<MP>("MULTIPOINT(1 0,3 3)"), | |
288 | from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), | |
289 | false); | |
290 | ||
291 | tester::apply("mp-l-04", | |
292 | from_wkt<MP>("MULTIPOINT(1 0,2 0)"), | |
293 | from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), | |
294 | true); | |
295 | ||
296 | tester::apply("mp-l-05", | |
297 | from_wkt<MP>("MULTIPOINT(-1 -1,2 0)"), | |
298 | from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), | |
299 | true); | |
300 | ||
301 | tester::apply("mp-l-06", | |
302 | from_wkt<MP>("MULTIPOINT(-1 -1,2 0)"), | |
303 | from_wkt<L>("LINESTRING(1 0,3 0)"), | |
304 | false); | |
305 | ||
306 | tester::apply("mp-l-07", | |
307 | from_wkt<MP>("MULTIPOINT(-1 -1,2 0,-1 -1,2 0)"), | |
308 | from_wkt<L>("LINESTRING(1 0,3 0)"), | |
309 | false); | |
310 | ||
311 | tester::apply("mp-l-08", | |
312 | from_wkt<MP>("MULTIPOINT(2 0)"), | |
313 | from_wkt<L>("LINESTRING(1 0)"), | |
314 | true); | |
315 | ||
316 | tester::apply("mp-l-09", | |
317 | from_wkt<MP>("MULTIPOINT(3 0,0 0,3 0)"), | |
318 | from_wkt<L>("LINESTRING(1 0,2 0)"), | |
319 | true); | |
320 | } | |
321 | ||
322 | template <typename P> | |
323 | inline void test_multipoint_multilinestring() | |
324 | { | |
325 | typedef bg::model::multi_point<P> MP; | |
326 | typedef bg::model::linestring<P> L; | |
327 | typedef bg::model::multi_linestring<L> ML; | |
328 | ||
329 | typedef test_disjoint tester; | |
330 | ||
331 | tester::apply("mp-ml-01", | |
332 | from_wkt<MP>("MULTIPOINT(0 1,0 2)"), | |
333 | from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), | |
334 | true); | |
335 | ||
336 | tester::apply("mp-ml-02", | |
337 | from_wkt<MP>("MULTIPOINT(0 0,1 0)"), | |
338 | from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), | |
339 | false); | |
340 | ||
341 | tester::apply("mp-ml-03", | |
342 | from_wkt<MP>("MULTIPOINT(0 1,1 1)"), | |
343 | from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), | |
344 | false); | |
345 | ||
346 | tester::apply("mp-ml-04", | |
347 | from_wkt<MP>("MULTIPOINT(0 1,1 0)"), | |
348 | from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), | |
349 | false); | |
350 | ||
351 | tester::apply("mp-ml-05", | |
352 | from_wkt<MP>("MULTIPOINT(0 0,10 0)"), | |
353 | from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), | |
354 | false); | |
355 | ||
356 | tester::apply("mp-ml-06", | |
357 | from_wkt<MP>("MULTIPOINT(-1 0,3 0)"), | |
358 | from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), | |
359 | false); | |
360 | } | |
361 | ||
362 | //============================================================================ | |
363 | ||
364 | template <typename CoordinateType> | |
365 | inline void test_pointlike_linear() | |
366 | { | |
367 | typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type; | |
368 | ||
369 | test_point_linestring<point_type>(); | |
370 | test_point_multilinestring<point_type>(); | |
371 | test_point_segment<point_type>(); | |
372 | ||
373 | test_multipoint_linestring<point_type>(); | |
374 | test_multipoint_multilinestring<point_type>(); | |
375 | test_multipoint_segment<point_type>(); | |
376 | } | |
377 | ||
378 | //============================================================================ | |
379 | ||
380 | BOOST_AUTO_TEST_CASE( test_pointlike_linear_all ) | |
381 | { | |
382 | test_pointlike_linear<double>(); | |
383 | test_pointlike_linear<int>(); | |
7c673cae | 384 | } |