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