]>
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 | // linear-linear geometries | |
76 | template <typename P> | |
77 | inline void test_segment_segment() | |
78 | { | |
79 | typedef bg::model::segment<P> S; | |
80 | ||
81 | typedef test_disjoint tester; | |
82 | ||
83 | tester::apply("s-s-01", | |
84 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
85 | from_wkt<S>("SEGMENT(0 0,0 2)"), | |
86 | false); | |
87 | ||
88 | tester::apply("s-s-02", | |
89 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
90 | from_wkt<S>("SEGMENT(2 0,3 0)"), | |
91 | false); | |
92 | ||
93 | tester::apply("s-s-03", | |
94 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
95 | from_wkt<S>("SEGMENT(1 0,3 0)"), | |
96 | false); | |
97 | ||
98 | tester::apply("s-s-04", | |
99 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
100 | from_wkt<S>("SEGMENT(1 0,1 1)"), | |
101 | false); | |
102 | ||
103 | tester::apply("s-s-05", | |
104 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
105 | from_wkt<S>("SEGMENT(1 1,2 2)"), | |
106 | true); | |
107 | ||
108 | tester::apply("s-s-06", | |
109 | from_wkt<S>("SEGMENT(0 0,1 1)"), | |
110 | from_wkt<S>("SEGMENT(1 1,1 1)"), | |
111 | false); | |
112 | ||
113 | tester::apply("s-s-07", | |
114 | from_wkt<S>("SEGMENT(0 0,1 1)"), | |
115 | from_wkt<S>("SEGMENT(2 2,2 2)"), | |
116 | true); | |
117 | ||
118 | tester::apply("s-s-08", | |
119 | from_wkt<S>("SEGMENT(0 0,1 1)"), | |
120 | from_wkt<S>("SEGMENT(2 2,3 3)"), | |
121 | true); | |
122 | } | |
123 | ||
124 | template <typename P> | |
125 | inline void test_linestring_segment() | |
126 | { | |
127 | typedef bg::model::segment<P> S; | |
128 | typedef bg::model::linestring<P> L; | |
129 | ||
130 | typedef test_disjoint tester; | |
131 | ||
132 | tester::apply("l-s-01", | |
133 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
134 | from_wkt<L>("LINESTRING(0 0,0 2)"), | |
135 | false); | |
136 | ||
137 | tester::apply("l-s-02", | |
138 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
139 | from_wkt<L>("LINESTRING(2 0,3 0)"), | |
140 | false); | |
141 | ||
142 | tester::apply("l-s-03", | |
143 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
144 | from_wkt<L>("LINESTRING(1 0,3 0)"), | |
145 | false); | |
146 | ||
147 | tester::apply("l-s-04", | |
148 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
149 | from_wkt<L>("LINESTRING(1 0,1 1)"), | |
150 | false); | |
151 | ||
152 | tester::apply("l-s-05", | |
153 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
154 | from_wkt<L>("LINESTRING(1 1,2 2)"), | |
155 | true); | |
156 | ||
157 | tester::apply("l-s-06", | |
158 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
159 | from_wkt<L>("LINESTRING(1 1,1 1,2 2)"), | |
160 | true); | |
161 | ||
162 | tester::apply("l-s-07", | |
163 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
164 | from_wkt<L>("LINESTRING(1 0,1 0,1 1,2 2)"), | |
165 | false); | |
166 | ||
167 | tester::apply("l-s-08", | |
168 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
169 | from_wkt<L>("LINESTRING(1 0,1 0,3 0)"), | |
170 | false); | |
171 | ||
172 | tester::apply("l-s-09", | |
173 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
174 | from_wkt<L>("LINESTRING(3 0,3 0,4 0)"), | |
175 | true); | |
176 | ||
177 | tester::apply("l-s-10", | |
178 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
179 | from_wkt<L>("LINESTRING(3 0,3 0)"), | |
180 | true); | |
181 | ||
182 | tester::apply("l-s-11", | |
183 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
184 | from_wkt<L>("LINESTRING(-1 0,-1 0)"), | |
185 | true); | |
186 | ||
187 | tester::apply("l-s-12", | |
188 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
189 | from_wkt<L>("LINESTRING(1 0,1 0)"), | |
190 | false); | |
191 | ||
192 | tester::apply("l-s-13", | |
193 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
194 | from_wkt<L>("LINESTRING(1 1,1 1)"), | |
195 | true); | |
196 | } | |
197 | ||
198 | template <typename P> | |
199 | inline void test_multilinestring_segment() | |
200 | { | |
201 | typedef bg::model::segment<P> S; | |
202 | typedef bg::model::linestring<P> L; | |
203 | typedef bg::model::multi_linestring<L> ML; | |
204 | ||
205 | typedef test_disjoint tester; | |
206 | ||
207 | tester::apply("s-ml-01", | |
208 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
209 | from_wkt<ML>("MULTILINESTRING((0 0,0 2))"), | |
210 | false); | |
211 | ||
212 | tester::apply("s-ml-02", | |
213 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
214 | from_wkt<ML>("MULTILINESTRING((2 0,3 0))"), | |
215 | false); | |
216 | ||
217 | tester::apply("s-ml-03", | |
218 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
219 | from_wkt<ML>("MULTILINESTRING((1 0,3 0))"), | |
220 | false); | |
221 | ||
222 | tester::apply("s-ml-04", | |
223 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
224 | from_wkt<ML>("MULTILINESTRING((1 0,1 1))"), | |
225 | false); | |
226 | ||
227 | tester::apply("s-ml-05", | |
228 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
229 | from_wkt<ML>("MULTILINESTRING((1 1,2 2))"), | |
230 | true); | |
231 | ||
232 | tester::apply("s-ml-06", | |
233 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
234 | from_wkt<ML>("MULTILINESTRING((1 1,2 2),(3 3,3 3))"), | |
235 | true); | |
236 | ||
237 | tester::apply("s-ml-07", | |
238 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
239 | from_wkt<ML>("MULTILINESTRING((1 1,2 2),(1 0,1 0))"), | |
240 | false); | |
241 | ||
242 | tester::apply("s-ml-08", | |
243 | from_wkt<S>("SEGMENT(0 0,2 0)"), | |
244 | from_wkt<ML>("MULTILINESTRING((1 1,2 2),(3 0,3 0))"), | |
245 | true); | |
246 | } | |
247 | ||
248 | template <typename P> | |
249 | inline void test_linestring_linestring() | |
250 | { | |
251 | typedef bg::model::linestring<P> L; | |
252 | ||
253 | typedef test_disjoint tester; | |
254 | ||
255 | tester::apply("l-l-01", | |
256 | from_wkt<L>("LINESTRING(0 0,2 0)"), | |
257 | from_wkt<L>("LINESTRING(0 0,0 2)"), | |
258 | false); | |
259 | ||
260 | tester::apply("l-l-02", | |
261 | from_wkt<L>("LINESTRING(0 0,2 0)"), | |
262 | from_wkt<L>("LINESTRING(2 0,3 0)"), | |
263 | false); | |
264 | ||
265 | tester::apply("l-l-03", | |
266 | from_wkt<L>("LINESTRING(0 0,2 0)"), | |
267 | from_wkt<L>("LINESTRING(1 0,3 0)"), | |
268 | false); | |
269 | ||
270 | tester::apply("l-l-04", | |
271 | from_wkt<L>("LINESTRING(0 0,2 0)"), | |
272 | from_wkt<L>("LINESTRING(1 0,1 1)"), | |
273 | false); | |
274 | ||
275 | tester::apply("l-l-05", | |
276 | from_wkt<L>("LINESTRING(0 0,2 0)"), | |
277 | from_wkt<L>("LINESTRING(1 1,2 2)"), | |
278 | true); | |
279 | } | |
280 | ||
281 | template <typename P> | |
282 | inline void test_linestring_multilinestring() | |
283 | { | |
284 | typedef bg::model::linestring<P> L; | |
285 | typedef bg::model::multi_linestring<L> ML; | |
286 | ||
287 | typedef test_disjoint tester; | |
288 | ||
289 | tester::apply("l-ml-01", | |
290 | from_wkt<L>("LINESTRING(0 0,2 0)"), | |
291 | from_wkt<ML>("MULTILINESTRING((0 0,0 2))"), | |
292 | false); | |
293 | ||
294 | tester::apply("l-ml-02", | |
295 | from_wkt<L>("LINESTRING(0 0,2 0)"), | |
296 | from_wkt<ML>("MULTILINESTRING((2 0,3 0))"), | |
297 | false); | |
298 | ||
299 | tester::apply("l-ml-03", | |
300 | from_wkt<L>("LINESTRING(0 0,2 0)"), | |
301 | from_wkt<ML>("MULTILINESTRING((1 0,3 0))"), | |
302 | false); | |
303 | ||
304 | tester::apply("l-ml-04", | |
305 | from_wkt<L>("LINESTRING(0 0,2 0)"), | |
306 | from_wkt<ML>("MULTILINESTRING((1 0,1 1))"), | |
307 | false); | |
308 | ||
309 | tester::apply("l-ml-05", | |
310 | from_wkt<L>("LINESTRING(0 0,2 0)"), | |
311 | from_wkt<ML>("MULTILINESTRING((1 1,2 2))"), | |
312 | true); | |
313 | } | |
314 | ||
315 | template <typename P> | |
316 | inline void test_multilinestring_multilinestring() | |
317 | { | |
318 | typedef bg::model::linestring<P> L; | |
319 | typedef bg::model::multi_linestring<L> ML; | |
320 | ||
321 | typedef test_disjoint tester; | |
322 | ||
323 | tester::apply("ml-ml-01", | |
324 | from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), | |
325 | from_wkt<ML>("MULTILINESTRING((0 0,0 2))"), | |
326 | false); | |
327 | ||
328 | tester::apply("ml-ml-02", | |
329 | from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), | |
330 | from_wkt<ML>("MULTILINESTRING((2 0,3 0))"), | |
331 | false); | |
332 | ||
333 | tester::apply("ml-ml-03", | |
334 | from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), | |
335 | from_wkt<ML>("MULTILINESTRING((1 0,3 0))"), | |
336 | false); | |
337 | ||
338 | tester::apply("ml-ml-04", | |
339 | from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), | |
340 | from_wkt<ML>("MULTILINESTRING((1 0,1 1))"), | |
341 | false); | |
342 | ||
343 | tester::apply("ml-ml-05", | |
344 | from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), | |
345 | from_wkt<ML>("MULTILINESTRING((1 1,2 2))"), | |
346 | true); | |
347 | } | |
348 | ||
349 | //============================================================================ | |
350 | ||
351 | template <typename CoordinateType> | |
352 | inline void test_linear_linear() | |
353 | { | |
354 | typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type; | |
355 | ||
356 | test_linestring_linestring<point_type>(); | |
357 | test_linestring_multilinestring<point_type>(); | |
358 | test_linestring_segment<point_type>(); | |
359 | ||
360 | test_multilinestring_multilinestring<point_type>(); | |
361 | test_multilinestring_segment<point_type>(); | |
362 | ||
363 | test_segment_segment<point_type>(); | |
364 | } | |
365 | ||
366 | //============================================================================ | |
367 | ||
368 | BOOST_AUTO_TEST_CASE( test_linear_linear_all ) | |
369 | { | |
370 | test_linear_linear<double>(); | |
371 | test_linear_linear<int>(); | |
7c673cae | 372 | } |