]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/distance/distance_ca_l_ar.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / distance / distance_ca_l_ar.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2014-2018, Oracle and/or its affiliates.
5
6 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
7 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
8
9 // Licensed under the Boost Software License version 1.0.
10 // http://www.boost.org/users/license.html
11
12 #include <iostream>
13
14 #ifndef BOOST_TEST_MODULE
15 #define BOOST_TEST_MODULE test_distance_cartesian_linear_areal
16 #endif
17
18 #include <boost/test/included/unit_test.hpp>
19
20 #include "test_distance_common.hpp"
21
22 typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
23 typedef bg::model::point<int,2,bg::cs::cartesian> int_point_type;
24 typedef bg::model::segment<point_type> segment_type;
25 typedef bg::model::segment<int_point_type> int_segment_type;
26 typedef bg::model::linestring<point_type> linestring_type;
27 typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
28 typedef bg::model::polygon<point_type, false> polygon_type;
29 typedef bg::model::polygon<point_type, false, false> open_polygon_type;
30 typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
31 typedef bg::model::multi_polygon<open_polygon_type> open_multipolygon_type;
32 typedef bg::model::ring<point_type, false> ring_type;
33 typedef bg::model::box<point_type> box_type;
34 typedef bg::model::box<int_point_type> int_box_type;
35
36 namespace services = bg::strategy::distance::services;
37 typedef bg::default_distance_result<point_type>::type return_type;
38
39 typedef bg::strategy::distance::pythagoras<> point_point_strategy;
40 typedef bg::strategy::distance::projected_point<> point_segment_strategy;
41 typedef bg::strategy::distance::cartesian_segment_box<> segment_box_strategy;
42
43 //===========================================================================
44
45 template <typename Strategy>
46 void test_distance_segment_polygon(Strategy const& strategy)
47 {
48 #ifdef BOOST_GEOMETRY_TEST_DEBUG
49 std::cout << std::endl;
50 std::cout << "segment/polygon distance tests" << std::endl;
51 #endif
52 typedef test_distance_of_geometries<segment_type, polygon_type> tester;
53
54 tester::apply("segment(-1 20,1 20)",
55 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
56 10, 100, strategy);
57
58 tester::apply("segment(1 20,2 40)",
59 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
60 10, 100, strategy);
61
62 tester::apply("segment(-1 20,-1 5)",
63 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
64 0, 0, strategy);
65
66 tester::apply("segment(-1 20,-1 -20)",
67 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
68 0, 0, strategy);
69
70 tester::apply("segment(0 0,1 1)",
71 "polygon((2 2))",
72 sqrt(2.0), 2, strategy);
73 }
74
75 //===========================================================================
76
77 template <typename Strategy>
78 void test_distance_linestring_polygon(Strategy const& strategy)
79 {
80 #ifdef BOOST_GEOMETRY_TEST_DEBUG
81 std::cout << std::endl;
82 std::cout << "linestring/polygon distance tests" << std::endl;
83 #endif
84 typedef test_distance_of_geometries<linestring_type, polygon_type> tester;
85
86 tester::apply("linestring(-1 20,1 20,1 30)",
87 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
88 10, 100, strategy);
89
90 tester::apply("linestring(-5 1,-2 1)",
91 "polygon((0 0,10 0,10 10,0 10,0 0))",
92 2, 4, strategy);
93
94 tester::apply("linestring(-1 20,1 20,1 5)",
95 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
96 0, 0, strategy);
97
98 tester::apply("linestring(-1 20,1 20,1 -20)",
99 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
100 0, 0, strategy);
101
102 tester::apply("linestring(-2 1)",
103 "polygon((0 0,10 0,10 10,0 10,0 0))",
104 2, 4, strategy);
105
106 tester::apply("linestring(-5 1,-2 1)",
107 "polygon((0 0))",
108 sqrt(5.0), 5, strategy);
109 }
110
111 //===========================================================================
112
113 template <typename Strategy>
114 void test_distance_linestring_open_polygon(Strategy const& strategy)
115 {
116 #ifdef BOOST_GEOMETRY_TEST_DEBUG
117 std::cout << std::endl;
118 std::cout << "linestring/open polygon distance tests" << std::endl;
119 #endif
120 typedef test_distance_of_geometries
121 <
122 linestring_type, open_polygon_type
123 > tester;
124
125 tester::apply("linestring(-5 1,-2 1)",
126 "polygon((0 0,10 0,10 10,0 10))",
127 2, 4, strategy);
128 }
129
130 //===========================================================================
131
132 template <typename Strategy>
133 void test_distance_multilinestring_polygon(Strategy const& strategy)
134 {
135 #ifdef BOOST_GEOMETRY_TEST_DEBUG
136 std::cout << std::endl;
137 std::cout << "multilinestring/polygon distance tests" << std::endl;
138 #endif
139 typedef test_distance_of_geometries
140 <
141 multi_linestring_type, polygon_type
142 > tester;
143
144 tester::apply("multilinestring((-100 -100,-90 -90),(-1 20,1 20,1 30))",
145 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
146 10, 100, strategy);
147
148 tester::apply("multilinestring((-1 20,1 20,1 30),(-1 20,1 20,1 5))",
149 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
150 0, 0, strategy);
151
152 tester::apply("multilinestring((-1 20,1 20,1 30),(-1 20,1 20,1 -20))",
153 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
154 0, 0, strategy);
155
156 tester::apply("multilinestring((-100 -100,-90 -90),(1 20))",
157 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
158 10, 100, strategy);
159
160 tester::apply("multilinestring((-100 -100,-90 -90),(-1 20,1 20,1 30))",
161 "polygon((-110 -110))",
162 sqrt(200.0), 200, strategy);
163 }
164
165 //===========================================================================
166
167 template <typename Strategy>
168 void test_distance_segment_multipolygon(Strategy const& strategy)
169 {
170 #ifdef BOOST_GEOMETRY_TEST_DEBUG
171 std::cout << std::endl;
172 std::cout << "segment/multipolygon distance tests" << std::endl;
173 #endif
174 typedef test_distance_of_geometries
175 <
176 segment_type, multi_polygon_type
177 > tester;
178
179 tester::apply("segment(-1 20,1 20)",
180 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
181 ((0 22,-1 30, 2 40,0 22)))",
182 2, 4, strategy);
183
184 tester::apply("segment(12 0,14 0)",
185 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
186 ((20 -1,21 2,30 -10,20 -1)))",
187 2, 4, strategy);
188
189 tester::apply("segment(12 0,20.5 0.5)",
190 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
191 ((20 -1,21 2,30 -10,20 -1)))",
192 0, 0, strategy);
193
194 tester::apply("segment(12 0,50 0)",
195 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
196 ((20 -1,21 2,30 -10,20 -1)))",
197 0, 0, strategy);
198 }
199
200 //===========================================================================
201
202 template <typename Strategy>
203 void test_distance_linestring_multipolygon(Strategy const& strategy)
204 {
205 #ifdef BOOST_GEOMETRY_TEST_DEBUG
206 std::cout << std::endl;
207 std::cout << "linestring/multipolygon distance tests" << std::endl;
208 #endif
209 typedef test_distance_of_geometries
210 <
211 linestring_type, multi_polygon_type
212 > tester;
213
214 tester::apply("linestring(-1 20,1 20)",
215 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
216 ((0 22,-1 30, 2 40,0 22)))",
217 2, 4, strategy);
218
219 tester::apply("linestring(12 0,14 0)",
220 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
221 ((20 -1,21 2,30 -10,20 -1)))",
222 2, 4, strategy);
223
224 tester::apply("linestring(12 0,20.5 0.5)",
225 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
226 ((20 -1,21 2,30 -10,20 -1)))",
227 0, 0, strategy);
228
229 tester::apply("linestring(12 0,50 0)",
230 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
231 ((20 -1,21 2,30 -10,20 -1)))",
232 0, 0, strategy);
233 }
234
235 //===========================================================================
236
237 template <typename Strategy>
238 void test_distance_linestring_open_multipolygon(Strategy const& strategy)
239 {
240 #ifdef BOOST_GEOMETRY_TEST_DEBUG
241 std::cout << std::endl;
242 std::cout << "linestring/open multipolygon distance tests" << std::endl;
243 #endif
244 typedef test_distance_of_geometries
245 <
246 linestring_type, open_multipolygon_type
247 > tester;
248
249 tester::apply("linestring(-5 1,-2 1)",
250 "multipolygon(((0 0,10 0,10 10,0 10)))",
251 2, 4, strategy);
252
253 tester::apply("linestring(-5 1,-3 1)",
254 "multipolygon(((20 20,21 20,21 21,20 21)),((0 0,10 0,10 10,0 10)))",
255 3, 9, strategy);
256 }
257
258 //===========================================================================
259
260 template <typename Strategy>
261 void test_distance_multilinestring_multipolygon(Strategy const& strategy)
262 {
263 #ifdef BOOST_GEOMETRY_TEST_DEBUG
264 std::cout << std::endl;
265 std::cout << "multilinestring/multipolygon distance tests" << std::endl;
266 #endif
267 typedef test_distance_of_geometries
268 <
269 multi_linestring_type, multi_polygon_type
270 > tester;
271
272 tester::apply("multilinestring((12 0,14 0),(19 0,19.9 -1))",
273 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
274 ((20 -1,21 2,30 -10)))",
275 0.1, 0.01, strategy);
276
277 tester::apply("multilinestring((19 0,19.9 -1),(12 0,20.5 0.5))",
278 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
279 ((20 -1,21 2,30 -10,20 -1)))",
280 0, 0, strategy);
281 }
282
283 //===========================================================================
284
285 template <typename Strategy>
286 void test_distance_segment_ring(Strategy const& strategy)
287 {
288 #ifdef BOOST_GEOMETRY_TEST_DEBUG
289 std::cout << std::endl;
290 std::cout << "segment/ring distance tests" << std::endl;
291 #endif
292 typedef test_distance_of_geometries<segment_type, ring_type> tester;
293
294 tester::apply("segment(-1 20,1 20)",
295 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
296 10, 100, strategy);
297
298 tester::apply("segment(1 20,2 40)",
299 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
300 10, 100, strategy);
301
302 tester::apply("segment(-1 20,-1 5)",
303 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
304 0, 0, strategy);
305
306 tester::apply("segment(-1 20,-1 -20)",
307 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
308 0, 0, strategy);
309 }
310
311 //===========================================================================
312
313 template <typename Strategy>
314 void test_distance_linestring_ring(Strategy const& strategy)
315 {
316 #ifdef BOOST_GEOMETRY_TEST_DEBUG
317 std::cout << std::endl;
318 std::cout << "linestring/ring distance tests" << std::endl;
319 #endif
320 typedef test_distance_of_geometries<linestring_type, ring_type> tester;
321
322 tester::apply("linestring(-1 20,1 20,1 30)",
323 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
324 10, 100, strategy);
325
326 tester::apply("linestring(-1 20,1 20,1 5)",
327 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
328 0, 0, strategy);
329
330 tester::apply("linestring(-1 20,1 20,1 -20)",
331 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
332 0, 0, strategy);
333 }
334
335 //===========================================================================
336
337 template <typename Strategy>
338 void test_distance_multilinestring_ring(Strategy const& strategy)
339 {
340 #ifdef BOOST_GEOMETRY_TEST_DEBUG
341 std::cout << std::endl;
342 std::cout << "multilinestring/ring distance tests" << std::endl;
343 #endif
344 typedef test_distance_of_geometries
345 <
346 multi_linestring_type, ring_type
347 > tester;
348
349 tester::apply("multilinestring((-100 -100,-90 -90),(-1 20,1 20,1 30))",
350 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
351 10, 100, strategy);
352
353 tester::apply("multilinestring((-1 20,1 20,1 30),(-1 20,1 20,1 5))",
354 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
355 0, 0, strategy);
356
357 tester::apply("multilinestring((-1 20,1 20,1 30),(-1 20,1 20,1 -20))",
358 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
359 0, 0, strategy);
360 }
361
362 //===========================================================================
363
364 template <typename Strategy>
365 void test_distance_segment_box(Strategy const& strategy)
366 {
367 #ifdef BOOST_GEOMETRY_TEST_DEBUG
368 std::cout << std::endl;
369 std::cout << "2D segment/box distance tests" << std::endl;
370 #endif
371 typedef int_box_type B;
372 typedef segment_type S;
373 typedef int_segment_type IS;
374
375 typedef test_distance_of_geometries<B, S> tester;
376 typedef test_distance_of_geometries<B, IS> itester;
377
378 // 1st example by Adam Wulkiewicz
379 tester::apply("BOX(5 51,42 96)",
380 "SEGMENT(6.6799994 95.260002,35.119999 56.340004)",
381 0, 0, strategy);
382
383 // 2nd example by Adam Wulkiewicz
384 tester::apply("BOX(51 55,94 100)",
385 "SEGMENT(92.439995 50.130001,59.959999 80.870003)",
386 0, 0, strategy);
387
388 // segments that intersect the box
389 tester::apply("box(0 0,1 1)",
390 "segment(-1 0.5,0.5 0.75)",
391 0, 0, strategy);
392 tester::apply("box(0 0,1 1)",
393 "segment(-1 0.5,1.5 0.75)",
394 0, 0, strategy);
395 tester::apply("box(0 0,1 1)",
396 "segment(0.5 -1,0.5 2)",
397 0, 0, strategy);
398 tester::apply("box(0 0,1 1)",
399 "segment(1 1,1.5 0.75)",
400 0, 0, strategy);
401 tester::apply("box(0 0,1 1)",
402 "segment(2 0,0 2)",
403 0, 0, strategy);
404
405 // segment that has closest point on box boundary
406 tester::apply("box(0 0,1 1)",
407 "segment(4 0.5,5 0.75)",
408 3, 9, strategy);
409
410 // segment that has closest point on box corner
411 tester::apply("box(0 0,1 1)",
412 "segment(4 0,0 4)",
413 sqrt(2.0), 2, strategy);
414 itester::apply("box(0 0,1 1)",
415 "segment(-4 0,0 -4)",
416 sqrt(8.0), 8, strategy);
417 itester::apply("box(0 0,1 1)",
418 "segment(-8 4,4 -8)",
419 sqrt(8.0), 8, strategy);
420 tester::apply("box(0 0,1 1)",
421 "segment(-4 0,0 4)",
422 1.5 * sqrt(2.0), 4.5, strategy);
423 tester::apply("box(0 0,1 1)",
424 "segment(-4 0,1 5)",
425 1.5 * sqrt(2.0), 4.5, strategy);
426 itester::apply("box(0 0,1 1)",
427 "segment(0 -2,3 1)",
428 0.5 * sqrt(2.0), 0.5, strategy);
429 itester::apply("box(0 0,1 1)",
430 "segment(0 -2,2 2)",
431 0, 0, strategy);
432
433 // horizontal segments
434 itester::apply("box(0 0,1 1)",
435 "segment(-2 -1,-1 -1)",
436 sqrt(2.0), 2, strategy);
437 itester::apply("box(0 0,1 1)",
438 "segment(-1 -1,0 -1)",
439 1, 1, strategy);
440 tester::apply("box(0 0,1 1)",
441 "segment(-0.5 -1,0.5 -1)",
442 1, 1, strategy);
443 tester::apply("box(0 0,1 1)",
444 "segment(0.5 -1,0.75 -1)",
445 1, 1, strategy);
446 tester::apply("box(0 0,1 1)",
447 "segment(0.5 -1,1.25 -1)",
448 1, 1, strategy);
449 tester::apply("box(0 0,1 1)",
450 "segment(1 -1,2 -1)",
451 1, 1, strategy);
452 tester::apply("box(0 0,1 1)",
453 "segment(2 -1,3 -1)",
454 sqrt(2.0), 2, strategy);
455 tester::apply("box(0 0,1 1)",
456 "segment(-2 -1,2 -1)",
457 1, 1, strategy);
458
459 tester::apply("box(0 0,1 1)",
460 "segment(-2 0,-1 0)",
461 1, 1, strategy);
462 tester::apply("box(0 0,1 1)",
463 "segment(-1 0,0 0)",
464 0, 0, strategy);
465 tester::apply("box(0 0,1 1)",
466 "segment(-0.5 0,0.5 0)",
467 0, 0, strategy);
468 tester::apply("box(0 0,1 1)",
469 "segment(0.5 0,0.75 0)",
470 0, 0, strategy);
471 tester::apply("box(0 0,1 1)",
472 "segment(0.5 0,1.25 0)",
473 0, 0, strategy);
474 tester::apply("box(0 0,1 1)",
475 "segment(1 0,2 0)",
476 0, 0, strategy);
477 tester::apply("box(0 0,1 1)",
478 "segment(2 0,3 0)",
479 1, 1, strategy);
480 tester::apply("box(0 0,1 1)",
481 "segment(-2 0,2 0)",
482 0, 0, strategy);
483
484 tester::apply("box(0 0,1 1)",
485 "segment(-2 0.5,-1 0.5)",
486 1, 1, strategy);
487 tester::apply("box(0 0,1 1)",
488 "segment(-1 0.5,0 0.5)",
489 0, 0, strategy);
490 tester::apply("box(0 0,1 1)",
491 "segment(-0.5 0.5,0.5 0.5)",
492 0, 0, strategy);
493 tester::apply("box(0 0,1 1)",
494 "segment(0.5 0.5,0.75 0.5)",
495 0, 0, strategy);
496 tester::apply("box(0 0,1 1)",
497 "segment(0.5 0.5,1.25 0.5)",
498 0, 0, strategy);
499 tester::apply("box(0 0,1 1)",
500 "segment(1 0.5,2 0.5)",
501 0, 0, strategy);
502 tester::apply("box(0 0,1 1)",
503 "segment(2 0.5,3 0.5)",
504 1, 1, strategy);
505 tester::apply("box(0 0,1 1)",
506 "segment(-2 0.5,2 0.5)",
507 0, 0, strategy);
508
509 tester::apply("box(0 0,1 1)",
510 "segment(-2 1,-1 1)",
511 1, 1, strategy);
512 tester::apply("box(0 0,1 1)",
513 "segment(-1 1,0 1)",
514 0, 0, strategy);
515 tester::apply("box(0 0,1 1)",
516 "segment(-0.5 1,0.5 1)",
517 0, 0, strategy);
518 tester::apply("box(0 0,1 1)",
519 "segment(0.5 1,0.75 1)",
520 0, 0, strategy);
521 tester::apply("box(0 0,1 1)",
522 "segment(0.5 1,1.25 1)",
523 0, 0, strategy);
524 tester::apply("box(0 0,1 1)",
525 "segment(1 1,2 1)",
526 0, 0, strategy);
527 tester::apply("box(0 0,1 1)",
528 "segment(2 1,3 1)",
529 1, 1, strategy);
530 tester::apply("box(0 0,1 1)",
531 "segment(-2 1,2 1)",
532 0, 0, strategy);
533
534 tester::apply("box(0 0,1 1)",
535 "segment(-2 3,-1 3)",
536 sqrt(5.0), 5, strategy);
537 itester::apply("box(0 0,1 1)",
538 "segment(-1 3,0 3)",
539 2, 4, strategy);
540 tester::apply("box(0 0,1 1)",
541 "segment(-0.5 3,0.5 3)",
542 2, 4, strategy);
543 tester::apply("box(0 0,1 1)",
544 "segment(0.5 3,0.75 3)",
545 2, 4, strategy);
546 tester::apply("box(0 0,1 1)",
547 "segment(0.5 3,1.25 3)",
548 2, 4, strategy);
549 tester::apply("box(0 0,1 1)",
550 "segment(1 3,2 3)",
551 2, 4, strategy);
552 tester::apply("box(0 0,1 1)",
553 "segment(2 3,3 3)",
554 sqrt(5.0), 5, strategy);
555 tester::apply("box(0 0,1 1)",
556 "segment(-2 3,2 3)",
557 2, 4, strategy);
558
559 // vertical segments
560 tester::apply("box(0 0,1 1)",
561 "segment(-1 -2,-1 -1)",
562 sqrt(2.0), 2, strategy);
563 tester::apply("box(0 0,1 1)",
564 "segment(-1 -1,-1 0)",
565 1, 1, strategy);
566 tester::apply("box(0 0,1 1)",
567 "segment(-1 -0.5,-1 0.5)",
568 1, 1, strategy);
569 tester::apply("box(0 0,1 1)",
570 "segment(-1 0.5,-1 0.75)",
571 1, 1, strategy);
572 tester::apply("box(0 0,1 1)",
573 "segment(-1 0.5,-1 1.25)",
574 1, 1, strategy);
575 tester::apply("box(0 0,1 1)",
576 "segment(-1 1,-1 2)",
577 1, 1, strategy);
578 tester::apply("box(0 0,1 1)",
579 "segment(-1 2,-1 3)",
580 sqrt(2.0), 2, strategy);
581 tester::apply("box(0 0,1 1)",
582 "segment(-1 -2,-1 2)",
583 1, 1, strategy);
584
585 tester::apply("box(0 0,1 1)",
586 "segment(0 -2,0 -1)",
587 1, 1, strategy);
588 tester::apply("box(0 0,1 1)",
589 "segment(0 -1,0 0)",
590 0, 0, strategy);
591 tester::apply("box(0 0,1 1)",
592 "segment(0 -0.5,0 0.5)",
593 0, 0, strategy);
594 tester::apply("box(0 0,1 1)",
595 "segment(0 0.5,0 0.75)",
596 0, 0, strategy);
597 tester::apply("box(0 0,1 1)",
598 "segment(0 0.5,0 1.25)",
599 0, 0, strategy);
600 tester::apply("box(0 0,1 1)",
601 "segment(0 1,0 2)",
602 0, 0, strategy);
603 tester::apply("box(0 0,1 1)",
604 "segment(0 2,0 3)",
605 1, 1, strategy);
606 tester::apply("box(0 0,1 1)",
607 "segment(0 -2,0 2)",
608 0, 0, strategy);
609
610 tester::apply("box(0 0,1 1)",
611 "segment(0.5 -2,0.5 -1)",
612 1, 1, strategy);
613 tester::apply("box(0 0,1 1)",
614 "segment(0.5 -1,0.5 0)",
615 0, 0, strategy);
616 tester::apply("box(0 0,1 1)",
617 "segment(0.5 -0.5,0.5 0.5)",
618 0, 0, strategy);
619 tester::apply("box(0 0,1 1)",
620 "segment(0.5 0.5,0.5 0.75)",
621 0, 0, strategy);
622 tester::apply("box(0 0,1 1)",
623 "segment(0.5 0.5,0.5 1.25)",
624 0, 0, strategy);
625 tester::apply("box(0 0,1 1)",
626 "segment(0.5 1,0.5 2)",
627 0, 0, strategy);
628 tester::apply("box(0 0,1 1)",
629 "segment(0.5 2,0.5 3)",
630 1, 1, strategy);
631 tester::apply("box(0 0,1 1)",
632 "segment(0.5 -2,0.5 2)",
633 0, 0, strategy);
634
635 tester::apply("box(0 0,1 1)",
636 "segment(1 -2,1 -1)",
637 1, 1, strategy);
638 tester::apply("box(0 0,1 1)",
639 "segment(1 -1,1 0)",
640 0, 0, strategy);
641 tester::apply("box(0 0,1 1)",
642 "segment(1 -0.5,1 0.5)",
643 0, 0, strategy);
644 tester::apply("box(0 0,1 1)",
645 "segment(1 0.5,1 0.75)",
646 0, 0, strategy);
647 tester::apply("box(0 0,1 1)",
648 "segment(1 0.5,1 1.25)",
649 0, 0, strategy);
650 tester::apply("box(0 0,1 1)",
651 "segment(1 1,1 2)",
652 0, 0, strategy);
653 tester::apply("box(0 0,1 1)",
654 "segment(1 2,1 3)",
655 1, 1, strategy);
656 tester::apply("box(0 0,1 1)",
657 "segment(1 -2,1 2)",
658 0, 0, strategy);
659
660 tester::apply("box(0 0,1 1)",
661 "segment(3 -2,3 -1)",
662 sqrt(5.0), 5, strategy);
663 tester::apply("box(0 0,1 1)",
664 "segment(3 -1,3 0)",
665 2, 4, strategy);
666 tester::apply("box(0 0,1 1)",
667 "segment(3 -0.5,3 0.5)",
668 2, 4, strategy);
669 tester::apply("box(0 0,1 1)",
670 "segment(3 0.5,3 0.75)",
671 2, 4, strategy);
672 tester::apply("box(0 0,1 1)",
673 "segment(3 0.5,3 1.25)",
674 2, 4, strategy);
675 tester::apply("box(0 0,1 1)",
676 "segment(3 1,3 2)",
677 2, 4, strategy);
678 tester::apply("box(0 0,1 1)",
679 "segment(3 2,3 3)",
680 sqrt(5.0), 5, strategy);
681 tester::apply("box(0 0,1 1)",
682 "segment(3 -2,3 2)",
683 2, 4, strategy);
684
685 // positive slope
686 itester::apply("box(0 0,1 1)",
687 "segment(-2 -2,-1 -1)",
688 sqrt(2.0), 2, strategy);
689 tester::apply("box(0 0,1 1)",
690 "segment(-2 -2,0 -0.5)",
691 0.5, 0.25, strategy);
692 tester::apply("box(0 0,1 1)",
693 "segment(-2 -2,0.5 -0.5)",
694 0.5, 0.25, strategy);
695 tester::apply("box(0 0,1 1)",
696 "segment(-2 -2,1 -0.5)",
697 0.5, 0.25, strategy);
698 tester::apply("box(0 0,1 1)",
699 "segment(-2 -2,2 0)",
700 sqrt(0.2), 0.2, strategy);
701 tester::apply("box(0 0,1 1)",
702 "segment(-2 -2,4 1)",
703 sqrt(0.2), 0.2, strategy);
704 tester::apply("box(0 0,1 1)",
705 "segment(-2 -2,-1.5 0)",
706 1.5, 2.25, strategy);
707 tester::apply("box(0 0,1 1)",
708 "segment(-2 -2,-1.5 0.5)",
709 1.5, 2.25, strategy);
710 tester::apply("box(0 0,1 1)",
711 "segment(-2 -2,-1.5 1)",
712 1.5, 2.25, strategy);
713 tester::apply("box(0 0,1 1)",
714 "segment(-2 -2,0 2)",
715 sqrt(0.2), 0.2, strategy);
716 tester::apply("box(0 0,1 1)",
717 "segment(-2 -2,1 4)",
718 sqrt(0.2), 0.2, strategy);
719 tester::apply("box(0 0,1 1)",
720 "segment(-2 -2,4 2)",
721 0, 0, strategy);
722 tester::apply("box(0 0,1 1)",
723 "segment(-2 -2,2 4)",
724 0, 0, strategy);
725 tester::apply("box(0 0,1 1)",
726 "segment(-2 -2,4 3)",
727 0, 0, strategy);
728 tester::apply("box(0 0,1 1)",
729 "segment(-2 -2,3 4)",
730 0, 0, strategy);
731 tester::apply("box(0 0,1 1)",
732 "segment(-2 -2,3 3)",
733 0, 0, strategy);
734
735 // negative slope
736 tester::apply("box(0 0,1 1)",
737 "segment(-2 -2,-1 -3)",
738 sqrt(8.0), 8, strategy);
739 tester::apply("box(0 0,1 1)",
740 "segment(-3 -1,0 -4)",
741 sqrt(8.0), 8, strategy);
742 tester::apply("box(0 0,1 1)",
743 "segment(-2 0.75,-1.5 0.5)",
744 1.5, 2.25, strategy);
745 tester::apply("box(0 0,1 1)",
746 "segment(-2 1.5,-1.5 0.5)",
747 1.5, 2.25, strategy);
748 tester::apply("box(0 0,1 1)",
749 "segment(0.5 2,0.75 1.5)",
750 0.5, 0.25, strategy);
751 tester::apply("box(0 0,1 1)",
752 "segment(-1 2,0.75 1.5)",
753 0.5, 0.25, strategy);
754 tester::apply("box(0 0,1 1)",
755 "segment(0 2,2 0)",
756 0, 0, strategy);
757 tester::apply("box(0 0,1 1)",
758 "segment(0 3,3 0)",
759 sqrt(0.5), 0.5, strategy);
760 tester::apply("box(0 0,1 1)",
761 "segment(-1 4,4 -1)",
762 sqrt(0.5), 0.5, strategy);
763 tester::apply("box(0 0,1 1)",
764 "segment(-1 4,0 3)",
765 2, 4, strategy);
766 tester::apply("box(0 0,1 1)",
767 "segment(-2 5,-1 4)",
768 sqrt(10.0), 10, strategy);
769 tester::apply("box(0 0,1 1)",
770 "segment(3 -1,4 -4)",
771 sqrt(5.0), 5, strategy);
772 tester::apply("box(0 0,1 1)",
773 "segment(1 2,2 1)",
774 sqrt(0.5), 0.5, strategy);
775 tester::apply("box(0 0,1 1)",
776 "segment(0.5 -2,2 -3)",
777 2, 4, strategy);
778 tester::apply("box(0 0,1 1)",
779 "segment(-1 -2,0 -3)",
780 sqrt(5.0), 5, strategy);
781 tester::apply("box(0 0,1 1)",
782 "segment(-1 -2,0.5 -3.5)",
783 sqrt(5.0), 5, strategy);
784 tester::apply("box(0 0,1 1)",
785 "segment(-1 -2,0.5 -3.5)",
786 sqrt(5.0), 5, strategy);
787 tester::apply("box(0 0,1 1)",
788 "segment(0.5 3,2.5 2)",
789 sqrt(2.45), 2.45, strategy);
790 tester::apply("box(0 0,1 1)",
791 "segment(0.5 1.5,1.5 -1.5)",
792 0, 0, strategy);
793
794 // test degenerate segment
795 tester::apply("box(0 0,2 2)",
796 "segment(4 1,4 1)",
797 2, 4, strategy);
798 }
799
800 //===========================================================================
801
802 template <typename Strategy>
803 void test_distance_linestring_box(Strategy const& strategy)
804 {
805 #ifdef BOOST_GEOMETRY_TEST_DEBUG
806 std::cout << std::endl;
807 std::cout << "linestring/box distance tests" << std::endl;
808 #endif
809 typedef test_distance_of_geometries<linestring_type, box_type> tester;
810
811 // linestrings that intersect the box
812 tester::apply("linestring(-1 0.5,0.5 0.75)",
813 "box(0 0,1 1)",
814 0, 0, strategy);
815 tester::apply("linestring(-1 0.5,1.5 0.75)",
816 "box(0 0,1 1)",
817 0, 0, strategy);
818
819 // linestring that has closest point on box boundary
820 tester::apply("linestring(4 0.5,5 0.75)",
821 "box(0 0,1 1)",
822 3, 9, strategy);
823
824 // linestring that has closest point on box corner
825 tester::apply("linestring(4 0,0 4)",
826 "box(0 0,1 1)",
827 sqrt(2.0), 2, strategy);
828 }
829
830 //===========================================================================
831
832 template <typename Strategy>
833 void test_distance_multilinestring_box(Strategy const& strategy)
834 {
835 #ifdef BOOST_GEOMETRY_TEST_DEBUG
836 std::cout << std::endl;
837 std::cout << "multilinestring/box distance tests" << std::endl;
838 #endif
839 typedef test_distance_of_geometries<multi_linestring_type, box_type> tester;
840
841 // multilinestring that intersects the box
842 tester::apply("multilinestring((-1 0.5,0.5 0.75),(4 0.5,5 0.75))",
843 "box(0 0,1 1)",
844 0, 0, strategy);
845
846 // multilinestring that has closest point on box boundary
847 tester::apply("multilinestring((4 0.5,5 0.75))",
848 "box(0 0,1 1)",
849 3, 9, strategy);
850
851 // multilinestring that has closest point on box corner
852 tester::apply("multilinestring((5 0,0 5),(4 0,0 4))",
853 "box(0 0,1 1)",
854 sqrt(2.0), 2, strategy);
855 }
856
857 //===========================================================================
858
859 template <typename Point, typename Strategy>
860 void test_more_empty_input_linear_areal(Strategy const& strategy)
861 {
862 #ifdef BOOST_GEOMETRY_TEST_DEBUG
863 std::cout << std::endl;
864 std::cout << "testing on empty inputs... " << std::flush;
865 #endif
866 bg::model::linestring<Point> line_empty;
867 bg::model::polygon<Point> polygon_empty;
868 bg::model::multi_linestring<bg::model::linestring<Point> > multiline_empty;
869 bg::model::multi_polygon<bg::model::polygon<Point> > multipolygon_empty;
870 bg::model::ring<Point> ring_empty;
871
872 bg::model::linestring<Point> line =
873 from_wkt<bg::model::linestring<Point> >("linestring(0 0,1 1)");
874
875 bg::model::polygon<Point> polygon =
876 from_wkt<bg::model::polygon<Point> >("polygon((0 0,1 0,0 1))");
877
878 bg::model::ring<Point> ring =
879 from_wkt<bg::model::ring<Point> >("polygon((0 0,1 0,0 1))");
880
881 // 1st geometry is empty
882 test_empty_input(line_empty, polygon, strategy);
883 test_empty_input(line_empty, ring, strategy);
884 test_empty_input(multiline_empty, polygon, strategy);
885 test_empty_input(multiline_empty, ring, strategy);
886
887 // 2nd geometry is empty
888 test_empty_input(line, polygon_empty, strategy);
889 test_empty_input(line, multipolygon_empty, strategy);
890 test_empty_input(line, ring_empty, strategy);
891
892 // both geometries are empty
893 test_empty_input(line_empty, polygon_empty, strategy);
894 test_empty_input(line_empty, multipolygon_empty, strategy);
895 test_empty_input(line_empty, ring_empty, strategy);
896 test_empty_input(multiline_empty, polygon_empty, strategy);
897 test_empty_input(multiline_empty, multipolygon_empty, strategy);
898 test_empty_input(multiline_empty, ring_empty, strategy);
899
900 #ifdef BOOST_GEOMETRY_TEST_DEBUG
901 std::cout << "done!" << std::endl;
902 #endif
903 }
904
905 //===========================================================================
906
907 BOOST_AUTO_TEST_CASE( test_all_segment_polygon )
908 {
909 test_distance_segment_polygon(point_segment_strategy());
910 }
911
912 BOOST_AUTO_TEST_CASE( test_all_linestring_polygon )
913 {
914 test_distance_linestring_polygon(point_segment_strategy());
915 test_distance_linestring_open_polygon(point_segment_strategy());
916 }
917
918 BOOST_AUTO_TEST_CASE( test_all_multilinestring_polygon )
919 {
920 test_distance_multilinestring_polygon(point_segment_strategy());
921 }
922
923 BOOST_AUTO_TEST_CASE( test_all_segment_multipolygon )
924 {
925 test_distance_segment_multipolygon(point_segment_strategy());
926 }
927
928 BOOST_AUTO_TEST_CASE( test_all_linestring_multipolygon )
929 {
930 test_distance_linestring_multipolygon(point_segment_strategy());
931 test_distance_linestring_open_multipolygon(point_segment_strategy());
932 }
933
934 BOOST_AUTO_TEST_CASE( test_all_multilinestring_multipolygon )
935 {
936 test_distance_multilinestring_multipolygon(point_segment_strategy());
937 }
938
939 BOOST_AUTO_TEST_CASE( test_all_segment_ring )
940 {
941 test_distance_segment_ring(point_segment_strategy());
942 }
943
944 BOOST_AUTO_TEST_CASE( test_all_linestring_ring )
945 {
946 test_distance_linestring_ring(point_segment_strategy());
947 }
948
949 BOOST_AUTO_TEST_CASE( test_all_multilinestring_ring )
950 {
951 test_distance_multilinestring_ring(point_segment_strategy());
952 }
953
954 BOOST_AUTO_TEST_CASE( test_all_segment_box )
955 {
956 test_distance_segment_box(segment_box_strategy());
957 }
958
959 BOOST_AUTO_TEST_CASE( test_all_linestring_box )
960 {
961 test_distance_linestring_box(point_segment_strategy());
962 }
963
964 BOOST_AUTO_TEST_CASE( test_all_multilinestring_box )
965 {
966 test_distance_multilinestring_box(point_segment_strategy());
967 }
968
969 BOOST_AUTO_TEST_CASE( test_all_empty_input_linear_areal )
970 {
971 test_more_empty_input_linear_areal<point_type>(point_segment_strategy());
972 }