]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/relational_operations/disjoint/disjoint_coverage_p_l.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / relational_operations / disjoint / disjoint_coverage_p_l.cpp
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>
47 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 // pointlike-linear geometries
80 template <typename P>
81 inline void test_point_segment()
82 {
83 typedef test_disjoint tester;
84 typedef bg::model::segment<P> S;
85
86 tester::apply("p-s-01",
87 from_wkt<P>("POINT(0 0)"),
88 from_wkt<S>("SEGMENT(0 0,2 0)"),
89 false);
90
91 tester::apply("p-s-02",
92 from_wkt<P>("POINT(2 0)"),
93 from_wkt<S>("SEGMENT(0 0,2 0)"),
94 false);
95
96 tester::apply("p-s-03",
97 from_wkt<P>("POINT(1 0)"),
98 from_wkt<S>("SEGMENT(0 0,2 0)"),
99 false);
100
101 tester::apply("p-s-04",
102 from_wkt<P>("POINT(1 1)"),
103 from_wkt<S>("SEGMENT(0 0,2 0)"),
104 true);
105
106 tester::apply("p-s-05",
107 from_wkt<P>("POINT(3 0)"),
108 from_wkt<S>("SEGMENT(0 0,2 0)"),
109 true);
110
111 tester::apply("p-s-06",
112 from_wkt<P>("POINT(-1 0)"),
113 from_wkt<S>("SEGMENT(0 0,2 0)"),
114 true);
115
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)"),
120 true);
121
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)"),
126 false);
127
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)"),
132 true);
133
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)"),
138 true);
139 }
140
141 template <typename P>
142 inline void test_point_linestring()
143 {
144 typedef bg::model::linestring<P> L;
145
146 typedef test_disjoint tester;
147
148 tester::apply("p-l-01",
149 from_wkt<P>("POINT(0 0)"),
150 from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
151 false);
152
153 tester::apply("p-l-02",
154 from_wkt<P>("POINT(1 1)"),
155 from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
156 false);
157
158 tester::apply("p-l-03",
159 from_wkt<P>("POINT(3 3)"),
160 from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
161 false);
162
163 tester::apply("p-l-04",
164 from_wkt<P>("POINT(1 0)"),
165 from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
166 true);
167
168 tester::apply("p-l-05",
169 from_wkt<P>("POINT(5 5)"),
170 from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
171 true);
172
173 tester::apply("p-l-06",
174 from_wkt<P>("POINT(5 5)"),
175 from_wkt<L>("LINESTRING(0 0,2 2)"),
176 true);
177 }
178
179 template <typename P>
180 inline void test_point_multilinestring()
181 {
182 typedef bg::model::linestring<P> L;
183 typedef bg::model::multi_linestring<L> ML;
184
185 typedef test_disjoint tester;
186
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))"),
190 true);
191
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))"),
195 false);
196
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))"),
200 false);
201
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))"),
205 false);
206
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))"),
210 true);
211
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))"),
215 false);
216
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))"),
220 false);
221 }
222
223 template <typename P>
224 inline void test_multipoint_segment()
225 {
226 typedef test_disjoint tester;
227 typedef bg::model::multi_point<P> MP;
228 typedef bg::model::segment<P> S;
229
230 tester::apply("mp-s-01",
231 from_wkt<MP>("MULTIPOINT(0 0,1 1)"),
232 from_wkt<S>("SEGMENT(0 0,2 0)"),
233 false);
234
235 tester::apply("mp-s-02",
236 from_wkt<MP>("MULTIPOINT(1 0,1 1)"),
237 from_wkt<S>("SEGMENT(0 0,2 0)"),
238 false);
239
240 tester::apply("mp-s-03",
241 from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
242 from_wkt<S>("SEGMENT(0 0,2 0)"),
243 true);
244
245 tester::apply("mp-s-04",
246 from_wkt<MP>("MULTIPOINT()"),
247 from_wkt<S>("SEGMENT(0 0,2 0)"),
248 true);
249
250 tester::apply("mp-s-05",
251 from_wkt<MP>("MULTIPOINT(3 0,4 0)"),
252 from_wkt<S>("SEGMENT(0 0,2 0)"),
253 true);
254
255 tester::apply("mp-s-06",
256 from_wkt<MP>("MULTIPOINT(1 0,4 0)"),
257 from_wkt<S>("SEGMENT(0 0,2 0)"),
258 false);
259
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)"),
264 true);
265
266 tester::apply("mp-s-08",
267 from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
268 from_wkt<S>("SEGMENT(1 1,1 1)"),
269 false);
270 }
271
272 template <typename P>
273 inline void test_multipoint_linestring()
274 {
275 typedef bg::model::multi_point<P> MP;
276 typedef bg::model::linestring<P> L;
277
278 typedef test_disjoint tester;
279
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)"),
283 false);
284
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)"),
288 false);
289
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)"),
293 false);
294
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)"),
298 true);
299
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)"),
303 true);
304
305 tester::apply("mp-l-06",
306 from_wkt<MP>("MULTIPOINT(-1 -1,2 0)"),
307 from_wkt<L>("LINESTRING(1 0,3 0)"),
308 false);
309
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)"),
313 false);
314
315 tester::apply("mp-l-08",
316 from_wkt<MP>("MULTIPOINT(2 0)"),
317 from_wkt<L>("LINESTRING(1 0)"),
318 true);
319
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)"),
323 true);
324 }
325
326 template <typename P>
327 inline void test_multipoint_multilinestring()
328 {
329 typedef bg::model::multi_point<P> MP;
330 typedef bg::model::linestring<P> L;
331 typedef bg::model::multi_linestring<L> ML;
332
333 typedef test_disjoint tester;
334
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))"),
338 true);
339
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))"),
343 false);
344
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))"),
348 false);
349
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))"),
353 false);
354
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))"),
358 false);
359
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))"),
363 false);
364 }
365
366 //============================================================================
367
368 template <typename CoordinateType>
369 inline void test_pointlike_linear()
370 {
371 typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type;
372
373 test_point_linestring<point_type>();
374 test_point_multilinestring<point_type>();
375 test_point_segment<point_type>();
376
377 test_multipoint_linestring<point_type>();
378 test_multipoint_multilinestring<point_type>();
379 test_multipoint_segment<point_type>();
380 }
381
382 //============================================================================
383
384 BOOST_AUTO_TEST_CASE( test_pointlike_linear_all )
385 {
386 test_pointlike_linear<double>();
387 test_pointlike_linear<int>();
388 #ifdef HAVE_TTMATH
389 test_pointlike_linear<ttmath_big>();
390 #endif
391 }