1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2014-2015, Oracle and/or its affiliates.
6 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
13 #ifndef BOOST_TEST_MODULE
14 #define BOOST_TEST_MODULE test_distance_linear_areal
17 #include <boost/test/included/unit_test.hpp>
19 #include "test_distance_common.hpp"
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
;
36 namespace services
= bg::strategy::distance::services
;
37 typedef bg::default_distance_result
<point_type
>::type return_type
;
39 typedef bg::strategy::distance::pythagoras
<> point_point_strategy
;
40 typedef bg::strategy::distance::projected_point
<> point_segment_strategy
;
42 //===========================================================================
44 template <typename Strategy
>
45 void test_distance_segment_polygon(Strategy
const& strategy
)
47 #ifdef BOOST_GEOMETRY_TEST_DEBUG
48 std::cout
<< std::endl
;
49 std::cout
<< "segment/polygon distance tests" << std::endl
;
51 typedef test_distance_of_geometries
<segment_type
, polygon_type
> tester
;
53 tester::apply("segment(-1 20,1 20)",
54 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
57 tester::apply("segment(1 20,2 40)",
58 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
61 tester::apply("segment(-1 20,-1 5)",
62 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
65 tester::apply("segment(-1 20,-1 -20)",
66 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
69 tester::apply("segment(0 0,1 1)",
71 sqrt(2.0), 2, strategy
);
74 //===========================================================================
76 template <typename Strategy
>
77 void test_distance_linestring_polygon(Strategy
const& strategy
)
79 #ifdef BOOST_GEOMETRY_TEST_DEBUG
80 std::cout
<< std::endl
;
81 std::cout
<< "linestring/polygon distance tests" << std::endl
;
83 typedef test_distance_of_geometries
<linestring_type
, polygon_type
> tester
;
85 tester::apply("linestring(-1 20,1 20,1 30)",
86 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
89 tester::apply("linestring(-5 1,-2 1)",
90 "polygon((0 0,10 0,10 10,0 10,0 0))",
93 tester::apply("linestring(-1 20,1 20,1 5)",
94 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
97 tester::apply("linestring(-1 20,1 20,1 -20)",
98 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
101 tester::apply("linestring(-2 1)",
102 "polygon((0 0,10 0,10 10,0 10,0 0))",
105 tester::apply("linestring(-5 1,-2 1)",
107 sqrt(5.0), 5, strategy
);
110 //===========================================================================
112 template <typename Strategy
>
113 void test_distance_linestring_open_polygon(Strategy
const& strategy
)
115 #ifdef BOOST_GEOMETRY_TEST_DEBUG
116 std::cout
<< std::endl
;
117 std::cout
<< "linestring/open polygon distance tests" << std::endl
;
119 typedef test_distance_of_geometries
121 linestring_type
, open_polygon_type
124 tester::apply("linestring(-5 1,-2 1)",
125 "polygon((0 0,10 0,10 10,0 10))",
129 //===========================================================================
131 template <typename Strategy
>
132 void test_distance_multilinestring_polygon(Strategy
const& strategy
)
134 #ifdef BOOST_GEOMETRY_TEST_DEBUG
135 std::cout
<< std::endl
;
136 std::cout
<< "multilinestring/polygon distance tests" << std::endl
;
138 typedef test_distance_of_geometries
140 multi_linestring_type
, polygon_type
143 tester::apply("multilinestring((-100 -100,-90 -90),(-1 20,1 20,1 30))",
144 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
147 tester::apply("multilinestring((-1 20,1 20,1 30),(-1 20,1 20,1 5))",
148 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
151 tester::apply("multilinestring((-1 20,1 20,1 30),(-1 20,1 20,1 -20))",
152 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
155 tester::apply("multilinestring((-100 -100,-90 -90),(1 20))",
156 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
159 tester::apply("multilinestring((-100 -100,-90 -90),(-1 20,1 20,1 30))",
160 "polygon((-110 -110))",
161 sqrt(200.0), 200, strategy
);
164 //===========================================================================
166 template <typename Strategy
>
167 void test_distance_segment_multipolygon(Strategy
const& strategy
)
169 #ifdef BOOST_GEOMETRY_TEST_DEBUG
170 std::cout
<< std::endl
;
171 std::cout
<< "segment/multipolygon distance tests" << std::endl
;
173 typedef test_distance_of_geometries
175 segment_type
, multi_polygon_type
178 tester::apply("segment(-1 20,1 20)",
179 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
180 ((0 22,-1 30, 2 40,0 22)))",
183 tester::apply("segment(12 0,14 0)",
184 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
185 ((20 -1,21 2,30 -10,20 -1)))",
188 tester::apply("segment(12 0,20.5 0.5)",
189 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
190 ((20 -1,21 2,30 -10,20 -1)))",
193 tester::apply("segment(12 0,50 0)",
194 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
195 ((20 -1,21 2,30 -10,20 -1)))",
199 //===========================================================================
201 template <typename Strategy
>
202 void test_distance_linestring_multipolygon(Strategy
const& strategy
)
204 #ifdef BOOST_GEOMETRY_TEST_DEBUG
205 std::cout
<< std::endl
;
206 std::cout
<< "linestring/multipolygon distance tests" << std::endl
;
208 typedef test_distance_of_geometries
210 linestring_type
, multi_polygon_type
213 tester::apply("linestring(-1 20,1 20)",
214 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
215 ((0 22,-1 30, 2 40,0 22)))",
218 tester::apply("linestring(12 0,14 0)",
219 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
220 ((20 -1,21 2,30 -10,20 -1)))",
223 tester::apply("linestring(12 0,20.5 0.5)",
224 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
225 ((20 -1,21 2,30 -10,20 -1)))",
228 tester::apply("linestring(12 0,50 0)",
229 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
230 ((20 -1,21 2,30 -10,20 -1)))",
234 //===========================================================================
236 template <typename Strategy
>
237 void test_distance_linestring_open_multipolygon(Strategy
const& strategy
)
239 #ifdef BOOST_GEOMETRY_TEST_DEBUG
240 std::cout
<< std::endl
;
241 std::cout
<< "linestring/open multipolygon distance tests" << std::endl
;
243 typedef test_distance_of_geometries
245 linestring_type
, open_multipolygon_type
248 tester::apply("linestring(-5 1,-2 1)",
249 "multipolygon(((0 0,10 0,10 10,0 10)))",
252 tester::apply("linestring(-5 1,-3 1)",
253 "multipolygon(((20 20,21 20,21 21,20 21)),((0 0,10 0,10 10,0 10)))",
257 //===========================================================================
259 template <typename Strategy
>
260 void test_distance_multilinestring_multipolygon(Strategy
const& strategy
)
262 #ifdef BOOST_GEOMETRY_TEST_DEBUG
263 std::cout
<< std::endl
;
264 std::cout
<< "multilinestring/multipolygon distance tests" << std::endl
;
266 typedef test_distance_of_geometries
268 multi_linestring_type
, multi_polygon_type
271 tester::apply("multilinestring((12 0,14 0),(19 0,19.9 -1))",
272 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
273 ((20 -1,21 2,30 -10)))",
274 0.1, 0.01, strategy
);
276 tester::apply("multilinestring((19 0,19.9 -1),(12 0,20.5 0.5))",
277 "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
278 ((20 -1,21 2,30 -10,20 -1)))",
282 //===========================================================================
284 template <typename Strategy
>
285 void test_distance_segment_ring(Strategy
const& strategy
)
287 #ifdef BOOST_GEOMETRY_TEST_DEBUG
288 std::cout
<< std::endl
;
289 std::cout
<< "segment/ring distance tests" << std::endl
;
291 typedef test_distance_of_geometries
<segment_type
, ring_type
> tester
;
293 tester::apply("segment(-1 20,1 20)",
294 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
297 tester::apply("segment(1 20,2 40)",
298 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
301 tester::apply("segment(-1 20,-1 5)",
302 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
305 tester::apply("segment(-1 20,-1 -20)",
306 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
310 //===========================================================================
312 template <typename Strategy
>
313 void test_distance_linestring_ring(Strategy
const& strategy
)
315 #ifdef BOOST_GEOMETRY_TEST_DEBUG
316 std::cout
<< std::endl
;
317 std::cout
<< "linestring/ring distance tests" << std::endl
;
319 typedef test_distance_of_geometries
<linestring_type
, ring_type
> tester
;
321 tester::apply("linestring(-1 20,1 20,1 30)",
322 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
325 tester::apply("linestring(-1 20,1 20,1 5)",
326 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
329 tester::apply("linestring(-1 20,1 20,1 -20)",
330 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
334 //===========================================================================
336 template <typename Strategy
>
337 void test_distance_multilinestring_ring(Strategy
const& strategy
)
339 #ifdef BOOST_GEOMETRY_TEST_DEBUG
340 std::cout
<< std::endl
;
341 std::cout
<< "multilinestring/ring distance tests" << std::endl
;
343 typedef test_distance_of_geometries
345 multi_linestring_type
, ring_type
348 tester::apply("multilinestring((-100 -100,-90 -90),(-1 20,1 20,1 30))",
349 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
352 tester::apply("multilinestring((-1 20,1 20,1 30),(-1 20,1 20,1 5))",
353 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
356 tester::apply("multilinestring((-1 20,1 20,1 30),(-1 20,1 20,1 -20))",
357 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
361 //===========================================================================
363 template <typename Strategy
>
364 void test_distance_segment_box(Strategy
const& strategy
)
366 #ifdef BOOST_GEOMETRY_TEST_DEBUG
367 std::cout
<< std::endl
;
368 std::cout
<< "2D segment/box distance tests" << std::endl
;
370 typedef int_box_type B
;
371 typedef segment_type S
;
372 typedef int_segment_type IS
;
374 typedef test_distance_of_geometries
<B
, S
> tester
;
375 typedef test_distance_of_geometries
<B
, IS
> itester
;
377 // 1st example by Adam Wulkiewicz
378 tester::apply("BOX(5 51,42 96)",
379 "SEGMENT(6.6799994 95.260002,35.119999 56.340004)",
382 // 2nd example by Adam Wulkiewicz
383 tester::apply("BOX(51 55,94 100)",
384 "SEGMENT(92.439995 50.130001,59.959999 80.870003)",
387 // segments that intersect the box
388 tester::apply("box(0 0,1 1)",
389 "segment(-1 0.5,0.5 0.75)",
391 tester::apply("box(0 0,1 1)",
392 "segment(-1 0.5,1.5 0.75)",
394 tester::apply("box(0 0,1 1)",
395 "segment(0.5 -1,0.5 2)",
397 tester::apply("box(0 0,1 1)",
398 "segment(1 1,1.5 0.75)",
400 tester::apply("box(0 0,1 1)",
404 // segment that has closest point on box boundary
405 tester::apply("box(0 0,1 1)",
406 "segment(4 0.5,5 0.75)",
409 // segment that has closest point on box corner
410 tester::apply("box(0 0,1 1)",
412 sqrt(2.0), 2, strategy
);
413 itester::apply("box(0 0,1 1)",
414 "segment(-4 0,0 -4)",
415 sqrt(8.0), 8, strategy
);
416 itester::apply("box(0 0,1 1)",
417 "segment(-8 4,4 -8)",
418 sqrt(8.0), 8, strategy
);
419 tester::apply("box(0 0,1 1)",
421 1.5 * sqrt(2.0), 4.5, strategy
);
422 tester::apply("box(0 0,1 1)",
424 1.5 * sqrt(2.0), 4.5, strategy
);
425 itester::apply("box(0 0,1 1)",
427 0.5 * sqrt(2.0), 0.5, strategy
);
428 itester::apply("box(0 0,1 1)",
432 // horizontal segments
433 itester::apply("box(0 0,1 1)",
434 "segment(-2 -1,-1 -1)",
435 sqrt(2.0), 2, strategy
);
436 itester::apply("box(0 0,1 1)",
437 "segment(-1 -1,0 -1)",
439 tester::apply("box(0 0,1 1)",
440 "segment(-0.5 -1,0.5 -1)",
442 tester::apply("box(0 0,1 1)",
443 "segment(0.5 -1,0.75 -1)",
445 tester::apply("box(0 0,1 1)",
446 "segment(0.5 -1,1.25 -1)",
448 tester::apply("box(0 0,1 1)",
449 "segment(1 -1,2 -1)",
451 tester::apply("box(0 0,1 1)",
452 "segment(2 -1,3 -1)",
453 sqrt(2.0), 2, strategy
);
454 tester::apply("box(0 0,1 1)",
455 "segment(-2 -1,2 -1)",
458 tester::apply("box(0 0,1 1)",
459 "segment(-2 0,-1 0)",
461 tester::apply("box(0 0,1 1)",
464 tester::apply("box(0 0,1 1)",
465 "segment(-0.5 0,0.5 0)",
467 tester::apply("box(0 0,1 1)",
468 "segment(0.5 0,0.75 0)",
470 tester::apply("box(0 0,1 1)",
471 "segment(0.5 0,1.25 0)",
473 tester::apply("box(0 0,1 1)",
476 tester::apply("box(0 0,1 1)",
479 tester::apply("box(0 0,1 1)",
483 tester::apply("box(0 0,1 1)",
484 "segment(-2 0.5,-1 0.5)",
486 tester::apply("box(0 0,1 1)",
487 "segment(-1 0.5,0 0.5)",
489 tester::apply("box(0 0,1 1)",
490 "segment(-0.5 0.5,0.5 0.5)",
492 tester::apply("box(0 0,1 1)",
493 "segment(0.5 0.5,0.75 0.5)",
495 tester::apply("box(0 0,1 1)",
496 "segment(0.5 0.5,1.25 0.5)",
498 tester::apply("box(0 0,1 1)",
499 "segment(1 0.5,2 0.5)",
501 tester::apply("box(0 0,1 1)",
502 "segment(2 0.5,3 0.5)",
504 tester::apply("box(0 0,1 1)",
505 "segment(-2 0.5,2 0.5)",
508 tester::apply("box(0 0,1 1)",
509 "segment(-2 1,-1 1)",
511 tester::apply("box(0 0,1 1)",
514 tester::apply("box(0 0,1 1)",
515 "segment(-0.5 1,0.5 1)",
517 tester::apply("box(0 0,1 1)",
518 "segment(0.5 1,0.75 1)",
520 tester::apply("box(0 0,1 1)",
521 "segment(0.5 1,1.25 1)",
523 tester::apply("box(0 0,1 1)",
526 tester::apply("box(0 0,1 1)",
529 tester::apply("box(0 0,1 1)",
533 tester::apply("box(0 0,1 1)",
534 "segment(-2 3,-1 3)",
535 sqrt(5.0), 5, strategy
);
536 itester::apply("box(0 0,1 1)",
539 tester::apply("box(0 0,1 1)",
540 "segment(-0.5 3,0.5 3)",
542 tester::apply("box(0 0,1 1)",
543 "segment(0.5 3,0.75 3)",
545 tester::apply("box(0 0,1 1)",
546 "segment(0.5 3,1.25 3)",
548 tester::apply("box(0 0,1 1)",
551 tester::apply("box(0 0,1 1)",
553 sqrt(5.0), 5, strategy
);
554 tester::apply("box(0 0,1 1)",
559 tester::apply("box(0 0,1 1)",
560 "segment(-1 -2,-1 -1)",
561 sqrt(2.0), 2, strategy
);
562 tester::apply("box(0 0,1 1)",
563 "segment(-1 -1,-1 0)",
565 tester::apply("box(0 0,1 1)",
566 "segment(-1 -0.5,-1 0.5)",
568 tester::apply("box(0 0,1 1)",
569 "segment(-1 0.5,-1 0.75)",
571 tester::apply("box(0 0,1 1)",
572 "segment(-1 0.5,-1 1.25)",
574 tester::apply("box(0 0,1 1)",
575 "segment(-1 1,-1 2)",
577 tester::apply("box(0 0,1 1)",
578 "segment(-1 2,-1 3)",
579 sqrt(2.0), 2, strategy
);
580 tester::apply("box(0 0,1 1)",
581 "segment(-1 -2,-1 2)",
584 tester::apply("box(0 0,1 1)",
585 "segment(0 -2,0 -1)",
587 tester::apply("box(0 0,1 1)",
590 tester::apply("box(0 0,1 1)",
591 "segment(0 -0.5,0 0.5)",
593 tester::apply("box(0 0,1 1)",
594 "segment(0 0.5,0 0.75)",
596 tester::apply("box(0 0,1 1)",
597 "segment(0 0.5,0 1.25)",
599 tester::apply("box(0 0,1 1)",
602 tester::apply("box(0 0,1 1)",
605 tester::apply("box(0 0,1 1)",
609 tester::apply("box(0 0,1 1)",
610 "segment(0.5 -2,0.5 -1)",
612 tester::apply("box(0 0,1 1)",
613 "segment(0.5 -1,0.5 0)",
615 tester::apply("box(0 0,1 1)",
616 "segment(0.5 -0.5,0.5 0.5)",
618 tester::apply("box(0 0,1 1)",
619 "segment(0.5 0.5,0.5 0.75)",
621 tester::apply("box(0 0,1 1)",
622 "segment(0.5 0.5,0.5 1.25)",
624 tester::apply("box(0 0,1 1)",
625 "segment(0.5 1,0.5 2)",
627 tester::apply("box(0 0,1 1)",
628 "segment(0.5 2,0.5 3)",
630 tester::apply("box(0 0,1 1)",
631 "segment(0.5 -2,0.5 2)",
634 tester::apply("box(0 0,1 1)",
635 "segment(1 -2,1 -1)",
637 tester::apply("box(0 0,1 1)",
640 tester::apply("box(0 0,1 1)",
641 "segment(1 -0.5,1 0.5)",
643 tester::apply("box(0 0,1 1)",
644 "segment(1 0.5,1 0.75)",
646 tester::apply("box(0 0,1 1)",
647 "segment(1 0.5,1 1.25)",
649 tester::apply("box(0 0,1 1)",
652 tester::apply("box(0 0,1 1)",
655 tester::apply("box(0 0,1 1)",
659 tester::apply("box(0 0,1 1)",
660 "segment(3 -2,3 -1)",
661 sqrt(5.0), 5, strategy
);
662 tester::apply("box(0 0,1 1)",
665 tester::apply("box(0 0,1 1)",
666 "segment(3 -0.5,3 0.5)",
668 tester::apply("box(0 0,1 1)",
669 "segment(3 0.5,3 0.75)",
671 tester::apply("box(0 0,1 1)",
672 "segment(3 0.5,3 1.25)",
674 tester::apply("box(0 0,1 1)",
677 tester::apply("box(0 0,1 1)",
679 sqrt(5.0), 5, strategy
);
680 tester::apply("box(0 0,1 1)",
685 itester::apply("box(0 0,1 1)",
686 "segment(-2 -2,-1 -1)",
687 sqrt(2.0), 2, strategy
);
688 tester::apply("box(0 0,1 1)",
689 "segment(-2 -2,0 -0.5)",
690 0.5, 0.25, strategy
);
691 tester::apply("box(0 0,1 1)",
692 "segment(-2 -2,0.5 -0.5)",
693 0.5, 0.25, strategy
);
694 tester::apply("box(0 0,1 1)",
695 "segment(-2 -2,1 -0.5)",
696 0.5, 0.25, strategy
);
697 tester::apply("box(0 0,1 1)",
698 "segment(-2 -2,2 0)",
699 sqrt(0.2), 0.2, strategy
);
700 tester::apply("box(0 0,1 1)",
701 "segment(-2 -2,4 1)",
702 sqrt(0.2), 0.2, strategy
);
703 tester::apply("box(0 0,1 1)",
704 "segment(-2 -2,-1.5 0)",
705 1.5, 2.25, strategy
);
706 tester::apply("box(0 0,1 1)",
707 "segment(-2 -2,-1.5 0.5)",
708 1.5, 2.25, strategy
);
709 tester::apply("box(0 0,1 1)",
710 "segment(-2 -2,-1.5 1)",
711 1.5, 2.25, strategy
);
712 tester::apply("box(0 0,1 1)",
713 "segment(-2 -2,0 2)",
714 sqrt(0.2), 0.2, strategy
);
715 tester::apply("box(0 0,1 1)",
716 "segment(-2 -2,1 4)",
717 sqrt(0.2), 0.2, strategy
);
718 tester::apply("box(0 0,1 1)",
719 "segment(-2 -2,4 2)",
721 tester::apply("box(0 0,1 1)",
722 "segment(-2 -2,2 4)",
724 tester::apply("box(0 0,1 1)",
725 "segment(-2 -2,4 3)",
727 tester::apply("box(0 0,1 1)",
728 "segment(-2 -2,3 4)",
730 tester::apply("box(0 0,1 1)",
731 "segment(-2 -2,3 3)",
735 tester::apply("box(0 0,1 1)",
736 "segment(-2 -2,-1 -3)",
737 sqrt(8.0), 8, strategy
);
738 tester::apply("box(0 0,1 1)",
739 "segment(-3 -1,0 -4)",
740 sqrt(8.0), 8, strategy
);
741 tester::apply("box(0 0,1 1)",
742 "segment(-2 0.75,-1.5 0.5)",
743 1.5, 2.25, strategy
);
744 tester::apply("box(0 0,1 1)",
745 "segment(-2 1.5,-1.5 0.5)",
746 1.5, 2.25, strategy
);
747 tester::apply("box(0 0,1 1)",
748 "segment(0.5 2,0.75 1.5)",
749 0.5, 0.25, strategy
);
750 tester::apply("box(0 0,1 1)",
751 "segment(-1 2,0.75 1.5)",
752 0.5, 0.25, strategy
);
753 tester::apply("box(0 0,1 1)",
756 tester::apply("box(0 0,1 1)",
758 sqrt(0.5), 0.5, strategy
);
759 tester::apply("box(0 0,1 1)",
760 "segment(-1 4,4 -1)",
761 sqrt(0.5), 0.5, strategy
);
762 tester::apply("box(0 0,1 1)",
765 tester::apply("box(0 0,1 1)",
766 "segment(-2 5,-1 4)",
767 sqrt(10.0), 10, strategy
);
768 tester::apply("box(0 0,1 1)",
769 "segment(3 -1,4 -4)",
770 sqrt(5.0), 5, strategy
);
771 tester::apply("box(0 0,1 1)",
773 sqrt(0.5), 0.5, strategy
);
774 tester::apply("box(0 0,1 1)",
775 "segment(0.5 -2,2 -3)",
777 tester::apply("box(0 0,1 1)",
778 "segment(-1 -2,0 -3)",
779 sqrt(5.0), 5, strategy
);
780 tester::apply("box(0 0,1 1)",
781 "segment(-1 -2,0.5 -3.5)",
782 sqrt(5.0), 5, strategy
);
783 tester::apply("box(0 0,1 1)",
784 "segment(-1 -2,0.5 -3.5)",
785 sqrt(5.0), 5, strategy
);
786 tester::apply("box(0 0,1 1)",
787 "segment(0.5 3,2.5 2)",
788 sqrt(2.45), 2.45, strategy
);
789 tester::apply("box(0 0,1 1)",
790 "segment(0.5 1.5,1.5 -1.5)",
793 // test degenerate segment
794 tester::apply("box(0 0,2 2)",
799 //===========================================================================
801 template <typename Strategy
>
802 void test_distance_linestring_box(Strategy
const& strategy
)
804 #ifdef BOOST_GEOMETRY_TEST_DEBUG
805 std::cout
<< std::endl
;
806 std::cout
<< "linestring/box distance tests" << std::endl
;
808 typedef test_distance_of_geometries
<linestring_type
, box_type
> tester
;
810 // linestrings that intersect the box
811 tester::apply("linestring(-1 0.5,0.5 0.75)",
814 tester::apply("linestring(-1 0.5,1.5 0.75)",
818 // linestring that has closest point on box boundary
819 tester::apply("linestring(4 0.5,5 0.75)",
823 // linestring that has closest point on box corner
824 tester::apply("linestring(4 0,0 4)",
826 sqrt(2.0), 2, strategy
);
829 //===========================================================================
831 template <typename Strategy
>
832 void test_distance_multilinestring_box(Strategy
const& strategy
)
834 #ifdef BOOST_GEOMETRY_TEST_DEBUG
835 std::cout
<< std::endl
;
836 std::cout
<< "multilinestring/box distance tests" << std::endl
;
838 typedef test_distance_of_geometries
<multi_linestring_type
, box_type
> tester
;
840 // multilinestring that intersects the box
841 tester::apply("multilinestring((-1 0.5,0.5 0.75),(4 0.5,5 0.75))",
845 // multilinestring that has closest point on box boundary
846 tester::apply("multilinestring((4 0.5,5 0.75))",
850 // multilinestring that has closest point on box corner
851 tester::apply("multilinestring((5 0,0 5),(4 0,0 4))",
853 sqrt(2.0), 2, strategy
);
856 //===========================================================================
858 template <typename Point
, typename Strategy
>
859 void test_more_empty_input_linear_areal(Strategy
const& strategy
)
861 #ifdef BOOST_GEOMETRY_TEST_DEBUG
862 std::cout
<< std::endl
;
863 std::cout
<< "testing on empty inputs... " << std::flush
;
865 bg::model::linestring
<Point
> line_empty
;
866 bg::model::polygon
<Point
> polygon_empty
;
867 bg::model::multi_linestring
<bg::model::linestring
<Point
> > multiline_empty
;
868 bg::model::multi_polygon
<bg::model::polygon
<Point
> > multipolygon_empty
;
869 bg::model::ring
<Point
> ring_empty
;
871 bg::model::linestring
<Point
> line
=
872 from_wkt
<bg::model::linestring
<Point
> >("linestring(0 0,1 1)");
874 bg::model::polygon
<Point
> polygon
=
875 from_wkt
<bg::model::polygon
<Point
> >("polygon((0 0,1 0,0 1))");
877 bg::model::ring
<Point
> ring
=
878 from_wkt
<bg::model::ring
<Point
> >("polygon((0 0,1 0,0 1))");
880 // 1st geometry is empty
881 test_empty_input(line_empty
, polygon
, strategy
);
882 test_empty_input(line_empty
, ring
, strategy
);
883 test_empty_input(multiline_empty
, polygon
, strategy
);
884 test_empty_input(multiline_empty
, ring
, strategy
);
886 // 2nd geometry is empty
887 test_empty_input(line
, polygon_empty
, strategy
);
888 test_empty_input(line
, multipolygon_empty
, strategy
);
889 test_empty_input(line
, ring_empty
, strategy
);
891 // both geometries are empty
892 test_empty_input(line_empty
, polygon_empty
, strategy
);
893 test_empty_input(line_empty
, multipolygon_empty
, strategy
);
894 test_empty_input(line_empty
, ring_empty
, strategy
);
895 test_empty_input(multiline_empty
, polygon_empty
, strategy
);
896 test_empty_input(multiline_empty
, multipolygon_empty
, strategy
);
897 test_empty_input(multiline_empty
, ring_empty
, strategy
);
899 #ifdef BOOST_GEOMETRY_TEST_DEBUG
900 std::cout
<< "done!" << std::endl
;
904 //===========================================================================
906 BOOST_AUTO_TEST_CASE( test_all_segment_polygon
)
908 test_distance_segment_polygon(point_segment_strategy());
911 BOOST_AUTO_TEST_CASE( test_all_linestring_polygon
)
913 test_distance_linestring_polygon(point_segment_strategy());
914 test_distance_linestring_open_polygon(point_segment_strategy());
917 BOOST_AUTO_TEST_CASE( test_all_multilinestring_polygon
)
919 test_distance_multilinestring_polygon(point_segment_strategy());
922 BOOST_AUTO_TEST_CASE( test_all_segment_multipolygon
)
924 test_distance_segment_multipolygon(point_segment_strategy());
927 BOOST_AUTO_TEST_CASE( test_all_linestring_multipolygon
)
929 test_distance_linestring_multipolygon(point_segment_strategy());
930 test_distance_linestring_open_multipolygon(point_segment_strategy());
933 BOOST_AUTO_TEST_CASE( test_all_multilinestring_multipolygon
)
935 test_distance_multilinestring_multipolygon(point_segment_strategy());
938 BOOST_AUTO_TEST_CASE( test_all_segment_ring
)
940 test_distance_segment_ring(point_segment_strategy());
943 BOOST_AUTO_TEST_CASE( test_all_linestring_ring
)
945 test_distance_linestring_ring(point_segment_strategy());
948 BOOST_AUTO_TEST_CASE( test_all_multilinestring_ring
)
950 test_distance_multilinestring_ring(point_segment_strategy());
953 BOOST_AUTO_TEST_CASE( test_all_segment_box
)
955 test_distance_segment_box(point_segment_strategy());
958 BOOST_AUTO_TEST_CASE( test_all_linestring_box
)
960 test_distance_linestring_box(point_segment_strategy());
963 BOOST_AUTO_TEST_CASE( test_all_multilinestring_box
)
965 test_distance_multilinestring_box(point_segment_strategy());
968 BOOST_AUTO_TEST_CASE( test_all_empty_input_linear_areal
)
970 test_more_empty_input_linear_areal
<point_type
>(point_segment_strategy());