1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2014-2018, Oracle and/or its affiliates.
6 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
7 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
9 // Licensed under the Boost Software License version 1.0.
10 // http://www.boost.org/users/license.html
14 #ifndef BOOST_TEST_MODULE
15 #define BOOST_TEST_MODULE test_distance_cartesian_linear_areal
18 #include <boost/test/included/unit_test.hpp>
20 #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
;
41 typedef bg::strategy::distance::cartesian_segment_box
<> segment_box_strategy
;
43 //===========================================================================
45 template <typename Strategy
>
46 void test_distance_segment_polygon(Strategy
const& strategy
)
48 #ifdef BOOST_GEOMETRY_TEST_DEBUG
49 std::cout
<< std::endl
;
50 std::cout
<< "segment/polygon distance tests" << std::endl
;
52 typedef test_distance_of_geometries
<segment_type
, polygon_type
> tester
;
54 tester::apply("segment(-1 20,1 20)",
55 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
58 tester::apply("segment(1 20,2 40)",
59 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
62 tester::apply("segment(-1 20,-1 5)",
63 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
66 tester::apply("segment(-1 20,-1 -20)",
67 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
70 tester::apply("segment(0 0,1 1)",
72 sqrt(2.0), 2, strategy
);
75 //===========================================================================
77 template <typename Strategy
>
78 void test_distance_linestring_polygon(Strategy
const& strategy
)
80 #ifdef BOOST_GEOMETRY_TEST_DEBUG
81 std::cout
<< std::endl
;
82 std::cout
<< "linestring/polygon distance tests" << std::endl
;
84 typedef test_distance_of_geometries
<linestring_type
, polygon_type
> tester
;
86 tester::apply("linestring(-1 20,1 20,1 30)",
87 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
90 tester::apply("linestring(-5 1,-2 1)",
91 "polygon((0 0,10 0,10 10,0 10,0 0))",
94 tester::apply("linestring(-1 20,1 20,1 5)",
95 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
98 tester::apply("linestring(-1 20,1 20,1 -20)",
99 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
102 tester::apply("linestring(-2 1)",
103 "polygon((0 0,10 0,10 10,0 10,0 0))",
106 tester::apply("linestring(-5 1,-2 1)",
108 sqrt(5.0), 5, strategy
);
111 //===========================================================================
113 template <typename Strategy
>
114 void test_distance_linestring_open_polygon(Strategy
const& strategy
)
116 #ifdef BOOST_GEOMETRY_TEST_DEBUG
117 std::cout
<< std::endl
;
118 std::cout
<< "linestring/open polygon distance tests" << std::endl
;
120 typedef test_distance_of_geometries
122 linestring_type
, open_polygon_type
125 tester::apply("linestring(-5 1,-2 1)",
126 "polygon((0 0,10 0,10 10,0 10))",
130 //===========================================================================
132 template <typename Strategy
>
133 void test_distance_multilinestring_polygon(Strategy
const& strategy
)
135 #ifdef BOOST_GEOMETRY_TEST_DEBUG
136 std::cout
<< std::endl
;
137 std::cout
<< "multilinestring/polygon distance tests" << std::endl
;
139 typedef test_distance_of_geometries
141 multi_linestring_type
, polygon_type
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))",
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))",
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))",
156 tester::apply("multilinestring((-100 -100,-90 -90),(1 20))",
157 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
160 tester::apply("multilinestring((-100 -100,-90 -90),(-1 20,1 20,1 30))",
161 "polygon((-110 -110))",
162 sqrt(200.0), 200, strategy
);
165 //===========================================================================
167 template <typename Strategy
>
168 void test_distance_segment_multipolygon(Strategy
const& strategy
)
170 #ifdef BOOST_GEOMETRY_TEST_DEBUG
171 std::cout
<< std::endl
;
172 std::cout
<< "segment/multipolygon distance tests" << std::endl
;
174 typedef test_distance_of_geometries
176 segment_type
, multi_polygon_type
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)))",
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)))",
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)))",
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)))",
200 //===========================================================================
202 template <typename Strategy
>
203 void test_distance_linestring_multipolygon(Strategy
const& strategy
)
205 #ifdef BOOST_GEOMETRY_TEST_DEBUG
206 std::cout
<< std::endl
;
207 std::cout
<< "linestring/multipolygon distance tests" << std::endl
;
209 typedef test_distance_of_geometries
211 linestring_type
, multi_polygon_type
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)))",
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)))",
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)))",
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)))",
235 //===========================================================================
237 template <typename Strategy
>
238 void test_distance_linestring_open_multipolygon(Strategy
const& strategy
)
240 #ifdef BOOST_GEOMETRY_TEST_DEBUG
241 std::cout
<< std::endl
;
242 std::cout
<< "linestring/open multipolygon distance tests" << std::endl
;
244 typedef test_distance_of_geometries
246 linestring_type
, open_multipolygon_type
249 tester::apply("linestring(-5 1,-2 1)",
250 "multipolygon(((0 0,10 0,10 10,0 10)))",
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)))",
258 //===========================================================================
260 template <typename Strategy
>
261 void test_distance_multilinestring_multipolygon(Strategy
const& strategy
)
263 #ifdef BOOST_GEOMETRY_TEST_DEBUG
264 std::cout
<< std::endl
;
265 std::cout
<< "multilinestring/multipolygon distance tests" << std::endl
;
267 typedef test_distance_of_geometries
269 multi_linestring_type
, multi_polygon_type
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
);
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)))",
283 //===========================================================================
285 template <typename Strategy
>
286 void test_distance_segment_ring(Strategy
const& strategy
)
288 #ifdef BOOST_GEOMETRY_TEST_DEBUG
289 std::cout
<< std::endl
;
290 std::cout
<< "segment/ring distance tests" << std::endl
;
292 typedef test_distance_of_geometries
<segment_type
, ring_type
> tester
;
294 tester::apply("segment(-1 20,1 20)",
295 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
298 tester::apply("segment(1 20,2 40)",
299 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
302 tester::apply("segment(-1 20,-1 5)",
303 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
306 tester::apply("segment(-1 20,-1 -20)",
307 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
311 //===========================================================================
313 template <typename Strategy
>
314 void test_distance_linestring_ring(Strategy
const& strategy
)
316 #ifdef BOOST_GEOMETRY_TEST_DEBUG
317 std::cout
<< std::endl
;
318 std::cout
<< "linestring/ring distance tests" << std::endl
;
320 typedef test_distance_of_geometries
<linestring_type
, ring_type
> tester
;
322 tester::apply("linestring(-1 20,1 20,1 30)",
323 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
326 tester::apply("linestring(-1 20,1 20,1 5)",
327 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
330 tester::apply("linestring(-1 20,1 20,1 -20)",
331 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
335 //===========================================================================
337 template <typename Strategy
>
338 void test_distance_multilinestring_ring(Strategy
const& strategy
)
340 #ifdef BOOST_GEOMETRY_TEST_DEBUG
341 std::cout
<< std::endl
;
342 std::cout
<< "multilinestring/ring distance tests" << std::endl
;
344 typedef test_distance_of_geometries
346 multi_linestring_type
, ring_type
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))",
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))",
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))",
362 //===========================================================================
364 template <typename Strategy
>
365 void test_distance_segment_box(Strategy
const& strategy
)
367 #ifdef BOOST_GEOMETRY_TEST_DEBUG
368 std::cout
<< std::endl
;
369 std::cout
<< "2D segment/box distance tests" << std::endl
;
371 typedef int_box_type B
;
372 typedef segment_type S
;
373 typedef int_segment_type IS
;
375 typedef test_distance_of_geometries
<B
, S
> tester
;
376 typedef test_distance_of_geometries
<B
, IS
> itester
;
378 // 1st example by Adam Wulkiewicz
379 tester::apply("BOX(5 51,42 96)",
380 "SEGMENT(6.6799994 95.260002,35.119999 56.340004)",
383 // 2nd example by Adam Wulkiewicz
384 tester::apply("BOX(51 55,94 100)",
385 "SEGMENT(92.439995 50.130001,59.959999 80.870003)",
388 // segments that intersect the box
389 tester::apply("box(0 0,1 1)",
390 "segment(-1 0.5,0.5 0.75)",
392 tester::apply("box(0 0,1 1)",
393 "segment(-1 0.5,1.5 0.75)",
395 tester::apply("box(0 0,1 1)",
396 "segment(0.5 -1,0.5 2)",
398 tester::apply("box(0 0,1 1)",
399 "segment(1 1,1.5 0.75)",
401 tester::apply("box(0 0,1 1)",
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)",
410 // segment that has closest point on box corner
411 tester::apply("box(0 0,1 1)",
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)",
422 1.5 * sqrt(2.0), 4.5, strategy
);
423 tester::apply("box(0 0,1 1)",
425 1.5 * sqrt(2.0), 4.5, strategy
);
426 itester::apply("box(0 0,1 1)",
428 0.5 * sqrt(2.0), 0.5, strategy
);
429 itester::apply("box(0 0,1 1)",
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)",
440 tester::apply("box(0 0,1 1)",
441 "segment(-0.5 -1,0.5 -1)",
443 tester::apply("box(0 0,1 1)",
444 "segment(0.5 -1,0.75 -1)",
446 tester::apply("box(0 0,1 1)",
447 "segment(0.5 -1,1.25 -1)",
449 tester::apply("box(0 0,1 1)",
450 "segment(1 -1,2 -1)",
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)",
459 tester::apply("box(0 0,1 1)",
460 "segment(-2 0,-1 0)",
462 tester::apply("box(0 0,1 1)",
465 tester::apply("box(0 0,1 1)",
466 "segment(-0.5 0,0.5 0)",
468 tester::apply("box(0 0,1 1)",
469 "segment(0.5 0,0.75 0)",
471 tester::apply("box(0 0,1 1)",
472 "segment(0.5 0,1.25 0)",
474 tester::apply("box(0 0,1 1)",
477 tester::apply("box(0 0,1 1)",
480 tester::apply("box(0 0,1 1)",
484 tester::apply("box(0 0,1 1)",
485 "segment(-2 0.5,-1 0.5)",
487 tester::apply("box(0 0,1 1)",
488 "segment(-1 0.5,0 0.5)",
490 tester::apply("box(0 0,1 1)",
491 "segment(-0.5 0.5,0.5 0.5)",
493 tester::apply("box(0 0,1 1)",
494 "segment(0.5 0.5,0.75 0.5)",
496 tester::apply("box(0 0,1 1)",
497 "segment(0.5 0.5,1.25 0.5)",
499 tester::apply("box(0 0,1 1)",
500 "segment(1 0.5,2 0.5)",
502 tester::apply("box(0 0,1 1)",
503 "segment(2 0.5,3 0.5)",
505 tester::apply("box(0 0,1 1)",
506 "segment(-2 0.5,2 0.5)",
509 tester::apply("box(0 0,1 1)",
510 "segment(-2 1,-1 1)",
512 tester::apply("box(0 0,1 1)",
515 tester::apply("box(0 0,1 1)",
516 "segment(-0.5 1,0.5 1)",
518 tester::apply("box(0 0,1 1)",
519 "segment(0.5 1,0.75 1)",
521 tester::apply("box(0 0,1 1)",
522 "segment(0.5 1,1.25 1)",
524 tester::apply("box(0 0,1 1)",
527 tester::apply("box(0 0,1 1)",
530 tester::apply("box(0 0,1 1)",
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)",
540 tester::apply("box(0 0,1 1)",
541 "segment(-0.5 3,0.5 3)",
543 tester::apply("box(0 0,1 1)",
544 "segment(0.5 3,0.75 3)",
546 tester::apply("box(0 0,1 1)",
547 "segment(0.5 3,1.25 3)",
549 tester::apply("box(0 0,1 1)",
552 tester::apply("box(0 0,1 1)",
554 sqrt(5.0), 5, strategy
);
555 tester::apply("box(0 0,1 1)",
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)",
566 tester::apply("box(0 0,1 1)",
567 "segment(-1 -0.5,-1 0.5)",
569 tester::apply("box(0 0,1 1)",
570 "segment(-1 0.5,-1 0.75)",
572 tester::apply("box(0 0,1 1)",
573 "segment(-1 0.5,-1 1.25)",
575 tester::apply("box(0 0,1 1)",
576 "segment(-1 1,-1 2)",
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)",
585 tester::apply("box(0 0,1 1)",
586 "segment(0 -2,0 -1)",
588 tester::apply("box(0 0,1 1)",
591 tester::apply("box(0 0,1 1)",
592 "segment(0 -0.5,0 0.5)",
594 tester::apply("box(0 0,1 1)",
595 "segment(0 0.5,0 0.75)",
597 tester::apply("box(0 0,1 1)",
598 "segment(0 0.5,0 1.25)",
600 tester::apply("box(0 0,1 1)",
603 tester::apply("box(0 0,1 1)",
606 tester::apply("box(0 0,1 1)",
610 tester::apply("box(0 0,1 1)",
611 "segment(0.5 -2,0.5 -1)",
613 tester::apply("box(0 0,1 1)",
614 "segment(0.5 -1,0.5 0)",
616 tester::apply("box(0 0,1 1)",
617 "segment(0.5 -0.5,0.5 0.5)",
619 tester::apply("box(0 0,1 1)",
620 "segment(0.5 0.5,0.5 0.75)",
622 tester::apply("box(0 0,1 1)",
623 "segment(0.5 0.5,0.5 1.25)",
625 tester::apply("box(0 0,1 1)",
626 "segment(0.5 1,0.5 2)",
628 tester::apply("box(0 0,1 1)",
629 "segment(0.5 2,0.5 3)",
631 tester::apply("box(0 0,1 1)",
632 "segment(0.5 -2,0.5 2)",
635 tester::apply("box(0 0,1 1)",
636 "segment(1 -2,1 -1)",
638 tester::apply("box(0 0,1 1)",
641 tester::apply("box(0 0,1 1)",
642 "segment(1 -0.5,1 0.5)",
644 tester::apply("box(0 0,1 1)",
645 "segment(1 0.5,1 0.75)",
647 tester::apply("box(0 0,1 1)",
648 "segment(1 0.5,1 1.25)",
650 tester::apply("box(0 0,1 1)",
653 tester::apply("box(0 0,1 1)",
656 tester::apply("box(0 0,1 1)",
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)",
666 tester::apply("box(0 0,1 1)",
667 "segment(3 -0.5,3 0.5)",
669 tester::apply("box(0 0,1 1)",
670 "segment(3 0.5,3 0.75)",
672 tester::apply("box(0 0,1 1)",
673 "segment(3 0.5,3 1.25)",
675 tester::apply("box(0 0,1 1)",
678 tester::apply("box(0 0,1 1)",
680 sqrt(5.0), 5, strategy
);
681 tester::apply("box(0 0,1 1)",
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)",
722 tester::apply("box(0 0,1 1)",
723 "segment(-2 -2,2 4)",
725 tester::apply("box(0 0,1 1)",
726 "segment(-2 -2,4 3)",
728 tester::apply("box(0 0,1 1)",
729 "segment(-2 -2,3 4)",
731 tester::apply("box(0 0,1 1)",
732 "segment(-2 -2,3 3)",
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)",
757 tester::apply("box(0 0,1 1)",
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)",
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)",
774 sqrt(0.5), 0.5, strategy
);
775 tester::apply("box(0 0,1 1)",
776 "segment(0.5 -2,2 -3)",
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)",
794 // test degenerate segment
795 tester::apply("box(0 0,2 2)",
800 //===========================================================================
802 template <typename Strategy
>
803 void test_distance_linestring_box(Strategy
const& strategy
)
805 #ifdef BOOST_GEOMETRY_TEST_DEBUG
806 std::cout
<< std::endl
;
807 std::cout
<< "linestring/box distance tests" << std::endl
;
809 typedef test_distance_of_geometries
<linestring_type
, box_type
> tester
;
811 // linestrings that intersect the box
812 tester::apply("linestring(-1 0.5,0.5 0.75)",
815 tester::apply("linestring(-1 0.5,1.5 0.75)",
819 // linestring that has closest point on box boundary
820 tester::apply("linestring(4 0.5,5 0.75)",
824 // linestring that has closest point on box corner
825 tester::apply("linestring(4 0,0 4)",
827 sqrt(2.0), 2, strategy
);
830 //===========================================================================
832 template <typename Strategy
>
833 void test_distance_multilinestring_box(Strategy
const& strategy
)
835 #ifdef BOOST_GEOMETRY_TEST_DEBUG
836 std::cout
<< std::endl
;
837 std::cout
<< "multilinestring/box distance tests" << std::endl
;
839 typedef test_distance_of_geometries
<multi_linestring_type
, box_type
> tester
;
841 // multilinestring that intersects the box
842 tester::apply("multilinestring((-1 0.5,0.5 0.75),(4 0.5,5 0.75))",
846 // multilinestring that has closest point on box boundary
847 tester::apply("multilinestring((4 0.5,5 0.75))",
851 // multilinestring that has closest point on box corner
852 tester::apply("multilinestring((5 0,0 5),(4 0,0 4))",
854 sqrt(2.0), 2, strategy
);
857 //===========================================================================
859 template <typename Point
, typename Strategy
>
860 void test_more_empty_input_linear_areal(Strategy
const& strategy
)
862 #ifdef BOOST_GEOMETRY_TEST_DEBUG
863 std::cout
<< std::endl
;
864 std::cout
<< "testing on empty inputs... " << std::flush
;
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
;
872 bg::model::linestring
<Point
> line
=
873 from_wkt
<bg::model::linestring
<Point
> >("linestring(0 0,1 1)");
875 bg::model::polygon
<Point
> polygon
=
876 from_wkt
<bg::model::polygon
<Point
> >("polygon((0 0,1 0,0 1))");
878 bg::model::ring
<Point
> ring
=
879 from_wkt
<bg::model::ring
<Point
> >("polygon((0 0,1 0,0 1))");
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
);
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
);
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
);
900 #ifdef BOOST_GEOMETRY_TEST_DEBUG
901 std::cout
<< "done!" << std::endl
;
905 //===========================================================================
907 BOOST_AUTO_TEST_CASE( test_all_segment_polygon
)
909 test_distance_segment_polygon(point_segment_strategy());
912 BOOST_AUTO_TEST_CASE( test_all_linestring_polygon
)
914 test_distance_linestring_polygon(point_segment_strategy());
915 test_distance_linestring_open_polygon(point_segment_strategy());
918 BOOST_AUTO_TEST_CASE( test_all_multilinestring_polygon
)
920 test_distance_multilinestring_polygon(point_segment_strategy());
923 BOOST_AUTO_TEST_CASE( test_all_segment_multipolygon
)
925 test_distance_segment_multipolygon(point_segment_strategy());
928 BOOST_AUTO_TEST_CASE( test_all_linestring_multipolygon
)
930 test_distance_linestring_multipolygon(point_segment_strategy());
931 test_distance_linestring_open_multipolygon(point_segment_strategy());
934 BOOST_AUTO_TEST_CASE( test_all_multilinestring_multipolygon
)
936 test_distance_multilinestring_multipolygon(point_segment_strategy());
939 BOOST_AUTO_TEST_CASE( test_all_segment_ring
)
941 test_distance_segment_ring(point_segment_strategy());
944 BOOST_AUTO_TEST_CASE( test_all_linestring_ring
)
946 test_distance_linestring_ring(point_segment_strategy());
949 BOOST_AUTO_TEST_CASE( test_all_multilinestring_ring
)
951 test_distance_multilinestring_ring(point_segment_strategy());
954 BOOST_AUTO_TEST_CASE( test_all_segment_box
)
956 test_distance_segment_box(segment_box_strategy());
959 BOOST_AUTO_TEST_CASE( test_all_linestring_box
)
961 test_distance_linestring_box(point_segment_strategy());
964 BOOST_AUTO_TEST_CASE( test_all_multilinestring_box
)
966 test_distance_multilinestring_box(point_segment_strategy());
969 BOOST_AUTO_TEST_CASE( test_all_empty_input_linear_areal
)
971 test_more_empty_input_linear_areal
<point_type
>(point_segment_strategy());