1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2017, 2018 Oracle and/or its affiliates.
6 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
11 #ifndef BOOST_TEST_MODULE
12 #define BOOST_TEST_MODULE test_distance_geographic_areal_areal
15 #include <boost/range.hpp>
16 #include <boost/type_traits/is_same.hpp>
18 #include <boost/test/included/unit_test.hpp>
19 #include <boost/geometry/util/condition.hpp>
20 #include <boost/geometry/strategies/strategies.hpp>
22 #include "test_distance_geo_common.hpp"
23 #include "test_empty_geometry.hpp"
25 template <typename Point
, typename Strategy_pp
, typename Strategy_ps
>
26 void test_distance_ring_ring(Strategy_pp
const& strategy_pp
,
27 Strategy_ps
const& strategy_ps
)
30 #ifdef BOOST_GEOMETRY_TEST_DEBUG
31 std::cout
<< std::endl
;
32 std::cout
<< "ring/ring distance tests" << std::endl
;
34 typedef bg::model::ring
<Point
> ring_type
;
36 typedef test_distance_of_geometries
<ring_type
, ring_type
> tester
;
38 std::string
const ring
= "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
40 tester::apply("rr1", ring
, "POLYGON((16 0,13 0,15 1,16 0))",
41 ps_distance
<Point
>("POINT(13 1)",
42 "SEGMENT(13 0,15 1)", strategy_ps
),
43 strategy_ps
, true, false, false);
45 tester::apply("rr2", ring
, "POLYGON((16 0,14 1,15 1,16 0))",
46 pp_distance
<Point
>("POINT(13 1)", "POINT(14 1)", strategy_pp
),
47 strategy_ps
, true, false, false);
49 tester::apply("rr3", ring
, ring
,
50 0, strategy_ps
, true, false, false);
54 //============================================================================
56 template <typename Point
, typename Strategy_pp
, typename Strategy_ps
>
57 void test_distance_ring_polygon(Strategy_pp
const& strategy_pp
,
58 Strategy_ps
const& strategy_ps
)
61 #ifdef BOOST_GEOMETRY_TEST_DEBUG
62 std::cout
<< std::endl
;
63 std::cout
<< "ring/polygon distance tests" << std::endl
;
65 typedef bg::model::ring
<Point
> ring_type
;
66 typedef bg::model::polygon
<Point
> polygon_type
;
68 typedef test_distance_of_geometries
<ring_type
, polygon_type
> tester
;
70 std::string
const ring
= "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
72 tester::apply("rp1", ring
, "POLYGON((16 0,13 0,15 1,16 0))",
73 ps_distance
<Point
>("POINT(13 1)",
74 "SEGMENT(13 0,15 1)", strategy_ps
),
75 strategy_ps
, true, false, false);
77 tester::apply("rp2", ring
, "POLYGON((16 0,14 1,15 1,16 0))",
78 pp_distance
<Point
>("POINT(13 1)", "POINT(14 1)", strategy_pp
),
79 strategy_ps
, true, false, false);
81 tester::apply("rp3", ring
, "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))",
82 0, strategy_ps
, true, false, false);
85 template <typename Point
, typename Strategy_pp
, typename Strategy_ps
>
86 void test_distance_polygon_polygon(Strategy_pp
const& strategy_pp
,
87 Strategy_ps
const& strategy_ps
)
90 #ifdef BOOST_GEOMETRY_TEST_DEBUG
91 std::cout
<< std::endl
;
92 std::cout
<< "polygon/polygon distance tests" << std::endl
;
94 typedef bg::model::polygon
<Point
> polygon_type
;
96 typedef test_distance_of_geometries
<polygon_type
, polygon_type
> tester
;
98 std::string
const poly
= "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
100 tester::apply("pp1", poly
, "POLYGON((16 0,13 0,15 1,16 0))",
101 ps_distance
<Point
>("POINT(13 1)",
102 "SEGMENT(13 0,15 1)", strategy_ps
),
103 strategy_ps
, true, false, false);
105 tester::apply("pp2", poly
, "POLYGON((16 0,14 1,15 1,16 0))",
106 pp_distance
<Point
>("POINT(13 1)", "POINT(14 1)", strategy_pp
),
107 strategy_ps
, true, false, false);
109 tester::apply("pp3", poly
, "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))",
110 0, strategy_ps
, true, false, false);
114 //============================================================================
116 template <typename Point
, typename Strategy_pp
, typename Strategy_ps
>
117 void test_distance_ring_multi_polygon(Strategy_pp
const& strategy_pp
,
118 Strategy_ps
const& strategy_ps
)
121 #ifdef BOOST_GEOMETRY_TEST_DEBUG
122 std::cout
<< std::endl
;
123 std::cout
<< "ring/multi_polygon distance tests" << std::endl
;
125 typedef bg::model::ring
<Point
> ring_type
;
126 typedef bg::model::polygon
<Point
> polygon_type
;
127 typedef bg::model::multi_polygon
<polygon_type
> multi_polygon_type
;
129 typedef test_distance_of_geometries
<ring_type
, multi_polygon_type
> tester
;
131 std::string
const ring
= "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
133 tester::apply("rmp1", ring
, "MULTIPOLYGON(((16 0,13 0,15 1,16 0)),\
134 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
135 ps_distance
<Point
>("POINT(12.5 2.5)", "SEGMENT(12 3,13 1)",
137 strategy_ps
, true, false, false);
139 tester::apply("rmp2", ring
, "MULTIPOLYGON(((16 0,13.1 1,15 1,16 0)),\
140 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
141 pp_distance
<Point
>("POINT(13 1)", "POINT(13.1 1)", strategy_pp
),
142 strategy_ps
, true, false, false);
144 tester::apply("rmp3", ring
, "MULTIPOLYGON(((16 0,13 1,15 1,16 0)),\
145 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
146 0, strategy_ps
, true, false, false);
148 tester::apply("rmp4", ring
, "MULTIPOLYGON(((16 0,12 1,15 1,16 0)),\
149 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
150 0, strategy_ps
, true, false, false);
153 template <typename Point
, typename Strategy_pp
, typename Strategy_ps
>
154 void test_distance_polygon_multi_polygon(Strategy_pp
const& strategy_pp
,
155 Strategy_ps
const& strategy_ps
)
158 #ifdef BOOST_GEOMETRY_TEST_DEBUG
159 std::cout
<< std::endl
;
160 std::cout
<< "polygon/multi_polygon distance tests" << std::endl
;
162 typedef bg::model::polygon
<Point
> polygon_type
;
163 typedef bg::model::multi_polygon
<polygon_type
> multi_polygon_type
;
165 typedef test_distance_of_geometries
<polygon_type
, multi_polygon_type
> tester
;
167 std::string
const poly
= "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
169 tester::apply("pmp1", poly
, "MULTIPOLYGON(((16 0,13 0,15 1,16 0)),\
170 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
171 ps_distance
<Point
>("POINT(12.5 2.5)", "SEGMENT(12 3,13 1)",
173 strategy_ps
, true, false, false);
175 tester::apply("pmp2", poly
, "MULTIPOLYGON(((16 0,13.1 1,15 1,16 0)),\
176 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
177 pp_distance
<Point
>("POINT(13 1)", "POINT(13.1 1)", strategy_pp
),
178 strategy_ps
, true, false, false);
180 tester::apply("pmp3", poly
, "MULTIPOLYGON(((16 0,13 1,15 1,16 0)),\
181 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
182 0, strategy_ps
, true, false, false);
184 tester::apply("pmp4", poly
, "MULTIPOLYGON(((16 0,12 1,15 1,16 0)),\
185 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
186 0, strategy_ps
, true, false, false);
189 std::string
const poly_interior
= "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0),\
190 (12 1,11 1,12 2,12 1))";
192 tester::apply("pmp1", poly_interior
, "MULTIPOLYGON(((16 0,13 0,15 1,16 0)),\
193 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
194 ps_distance
<Point
>("POINT(12.5 2.5)", "SEGMENT(12 3,13 1)",
196 strategy_ps
, true, false, false);
198 tester::apply("pmp2", poly_interior
, "MULTIPOLYGON(((16 0,13.1 1,15 1,16 0)),\
199 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
200 pp_distance
<Point
>("POINT(13 1)", "POINT(13.1 1)", strategy_pp
),
201 strategy_ps
, true, false, false);
203 tester::apply("pmp3", poly_interior
, "MULTIPOLYGON(((16 0,13 1,15 1,16 0)),\
204 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
205 0, strategy_ps
, true, false, false);
207 tester::apply("pmp4", poly_interior
, "MULTIPOLYGON(((16 0,12 1,15 1,16 0)),\
208 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
209 0, strategy_ps
, true, false, false);
214 template <typename Point
, typename Strategy_pp
, typename Strategy_ps
>
215 void test_distance_multi_polygon_multi_polygon(Strategy_pp
const& strategy_pp
,
216 Strategy_ps
const& strategy_ps
)
219 #ifdef BOOST_GEOMETRY_TEST_DEBUG
220 std::cout
<< std::endl
;
221 std::cout
<< "multi_polygon/multi_polygon distance tests" << std::endl
;
223 typedef bg::model::polygon
<Point
> polygon_type
;
224 typedef bg::model::multi_polygon
<polygon_type
> multi_polygon_type
;
226 typedef test_distance_of_geometries
<multi_polygon_type
, multi_polygon_type
>
229 std::string
const mpoly
= "MULTIPOLYGON(((11 0,10 1,11 2,12 3,13 1,11 0)),\
230 ((0 0,0 1,1 1,1 0,0 0)))";
232 tester::apply("mpmp1", mpoly
, "MULTIPOLYGON(((16 0,13 0,15 1,16 0)),\
233 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
234 ps_distance
<Point
>("POINT(12.5 2.5)", "SEGMENT(12 3,13 1)",
236 strategy_ps
, true, false, false);
238 tester::apply("mpmp2", mpoly
, "MULTIPOLYGON(((16 0,13.1 1,15 1,16 0)),\
239 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
240 pp_distance
<Point
>("POINT(13 1)", "POINT(13.1 1)", strategy_pp
),
241 strategy_ps
, true, false, false);
243 tester::apply("mpmp3", mpoly
, "MULTIPOLYGON(((16 0,13 1,15 1,16 0)),\
244 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
245 0, strategy_ps
, true, false, false);
247 tester::apply("mpmp4", mpoly
, "MULTIPOLYGON(((16 0,12 1,15 1,16 0)),\
248 ((12.5 2.5,12.5 4,14 2.5,12.5 2.5)))",
249 0, strategy_ps
, true, false, false);
253 //============================================================================
258 typename Strategy_pp
,
259 typename Strategy_ps
,
262 void test_distance_ring_box(Strategy_pp
const& strategy_pp
,
263 Strategy_ps
const& strategy_ps
,
264 Strategy_sb
const& strategy_sb
)
267 #ifdef BOOST_GEOMETRY_TEST_DEBUG
268 std::cout
<< std::endl
;
269 std::cout
<< "ring/box distance tests" << std::endl
;
271 typedef bg::model::box
<Point
> box_type
;
272 typedef bg::model::ring
<Point
> ring_type
;
274 typedef test_distance_of_geometries
<ring_type
, box_type
> tester
;
276 std::string
const ring
= "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
278 tester::apply("rb1", ring
, "BOX(10 10,20 20)",
279 sb_distance
<Point
>("SEGMENT(11 2,12 3)",
280 "BOX(10 10,20 20)", strategy_sb
),
281 strategy_sb
, true, false, false);
283 tester::apply("rb2", ring
, "BOX(17 0,20 3)",
284 ps_distance
<Point
>("POINT(13 1)",
285 "SEGMENT(17 0,17 3)", strategy_ps
),
286 strategy_sb
, true, false, false);
288 tester::apply("rb3", ring
, "BOX(17 0,20 1)",
289 pp_distance
<Point
>("POINT(17 1)", "POINT(13 1)", strategy_pp
),
290 strategy_sb
, true, false, false);
292 tester::apply("rb4", ring
, "BOX(12 0,20 1)",
293 0, strategy_sb
, true, false, false);
299 typename Strategy_pp
,
300 typename Strategy_ps
,
303 void test_distance_polygon_box(Strategy_pp
const& strategy_pp
,
304 Strategy_ps
const& strategy_ps
,
305 Strategy_sb
const& strategy_sb
)
308 #ifdef BOOST_GEOMETRY_TEST_DEBUG
309 std::cout
<< std::endl
;
310 std::cout
<< "polygon/box distance tests" << std::endl
;
312 typedef bg::model::box
<Point
> box_type
;
313 typedef bg::model::polygon
<Point
> polygon_type
;
315 typedef test_distance_of_geometries
<polygon_type
, box_type
> tester
;
317 std::string
const polygon
= "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
319 tester::apply("pb1", polygon
, "BOX(10 10,20 20)",
320 sb_distance
<Point
>("SEGMENT(11 2,12 3)",
321 "BOX(10 10,20 20)", strategy_sb
),
322 strategy_sb
, true, false, false);
324 tester::apply("pb2", polygon
, "BOX(17 0,20 3)",
325 ps_distance
<Point
>("POINT(13 1)",
326 "SEGMENT(17 0,17 3)", strategy_ps
),
327 strategy_sb
, true, false, false);
329 tester::apply("pb3", polygon
, "BOX(17 0,20 1)",
330 pp_distance
<Point
>("POINT(17 1)", "POINT(13 1)", strategy_pp
),
331 strategy_sb
, true, false, false);
333 tester::apply("pb4", polygon
, "BOX(12 0,20 1)",
334 0, strategy_sb
, true, false, false);
337 std::string
const poly_interior
= "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0),\
338 (12 1,11 1,12 2,12 1))";
340 tester::apply("pb5", poly_interior
, "BOX(10 10,20 20)",
341 sb_distance
<Point
>("SEGMENT(11 2,12 3)",
342 "BOX(10 10,20 20)", strategy_sb
),
343 strategy_sb
, true, false, false);
349 typename Strategy_pp
,
350 typename Strategy_ps
,
353 void test_distance_multi_polygon_box(Strategy_pp
const& strategy_pp
,
354 Strategy_ps
const& strategy_ps
,
355 Strategy_sb
const& strategy_sb
)
358 #ifdef BOOST_GEOMETRY_TEST_DEBUG
359 std::cout
<< std::endl
;
360 std::cout
<< "multi_polygon/box distance tests" << std::endl
;
362 typedef bg::model::box
<Point
> box_type
;
363 typedef bg::model::polygon
<Point
> polygon_type
;
364 typedef bg::model::multi_polygon
<polygon_type
> multi_polygon_type
;
366 typedef test_distance_of_geometries
<multi_polygon_type
, box_type
> tester
;
368 std::string
const multi_polygon
= "MULTIPOLYGON(((20 20,20 30,30 40,20 20)),\
369 ((10 10,0 20,15 30,20 15,15 10,10 10)))";
371 tester::apply("mpb1", multi_polygon
, "BOX(0 0,5 5)",
372 sb_distance
<Point
>("SEGMENT(10 10,0 20)",
373 "BOX(0 0,5 5)", strategy_sb
),
374 strategy_sb
, true, false, false);
376 tester::apply("mpb2", multi_polygon
, "BOX(27 0,30 16)",
377 ps_distance
<Point
>("POINT(20 15)",
378 "SEGMENT(27 0,27 16)", strategy_ps
),
379 strategy_sb
, true, false, false);
381 tester::apply("mpb3", multi_polygon
, "BOX(27 0,30 15)",
382 pp_distance
<Point
>("POINT(20 15)",
383 "POINT(27 15)", strategy_pp
),
384 strategy_sb
, true, false, false);
386 tester::apply("mpb4", multi_polygon
, "BOX(17 0,20 14)",
387 0, strategy_sb
, true, false, false);
391 //===========================================================================
392 // Cases for relative location of box2 wrt to box1
397 // --10---+---------+---3---
401 // -------+---------+-------
406 // case 6 includes all possible intersections
407 // The picture assumes northern hemisphere location
408 // southern hemisphere picture is mirrored wrt the equator
414 typename Strategy_pp
,
415 typename Strategy_ps
,
418 void test_distance_box_box(Strategy_pp
const& strategy_pp
,
419 Strategy_ps
const& strategy_ps
,
420 Strategy_bb
const& strategy_bb
)
423 #ifdef BOOST_GEOMETRY_TEST_DEBUG
424 std::cout
<< std::endl
;
425 std::cout
<< "box/box distance tests" << std::endl
;
427 typedef bg::model::box
<Point
> box_type
;
429 typedef test_distance_of_geometries
<box_type
, box_type
> tester
;
431 std::string
const box1
= "BOX(10 10,20 20)";
434 tester::apply("bb1", box1
, "BOX(30 0,40 5)",
435 pp_distance
<Point
>("POINT(20 10)", "POINT(30 5)", strategy_pp
),
439 tester::apply("bb2-a", box1
, "BOX(30 12, 40 17)",
440 ps_distance
<Point
>("POINT(30 17)",
441 "SEGMENT(20 10,20 20)", strategy_ps
),
444 tester::apply("bb2-b", box1
, "BOX(30 10, 40 17)",
445 ps_distance
<Point
>("POINT(30 17)",
446 "SEGMENT(20 10,20 20)", strategy_ps
),
449 tester::apply("bb2-c", box1
, "BOX(30 8, 40 17)",
450 ps_distance
<Point
>("POINT(30 17)",
451 "SEGMENT(20 10,20 20)", strategy_ps
),
456 tester::apply("bb3-a", box1
, "BOX(30 15, 40 25)",
457 ps_distance
<Point
>("POINT(20 20)",
458 "SEGMENT(30 15,30 25)", strategy_ps
),
461 tester::apply("bb3-b", box1
, "BOX(30 20, 40 40)",
462 ps_distance
<Point
>("POINT(20 20)",
463 "SEGMENT(30 20,30 40)", strategy_ps
),
467 tester::apply("bb4", box1
, "BOX(30 25, 40 40)",
468 pp_distance
<Point
>("POINT(20 20)",
469 "POINT(30 25)", strategy_pp
),
473 tester::apply("bb5", box1
, "BOX(12 2, 17 7)",
474 pp_distance
<Point
>("POINT(17 7)", "POINT(17 10)", strategy_pp
),
477 // case 6, boxes intersect thus distance is 0
478 tester::apply("bb6-a", box1
, "BOX(12 2, 17 10)",
479 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
482 tester::apply("bb6-b", box1
, "BOX(12 2, 17 17)",
483 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
486 tester::apply("bb6-c", box1
, "BOX(20 2, 30 10)",
487 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
490 tester::apply("bb6-d", box1
, "BOX(20 11, 30 15)",
491 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
494 tester::apply("bb6-e", box1
, "BOX(20 20, 30 30)",
495 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
498 tester::apply("bb6-f", box1
, "BOX(15 20, 17 30)",
499 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
502 tester::apply("bb6-g", box1
, "BOX(8 20, 10 25)",
503 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
506 tester::apply("bb6-h", box1
, "BOX(8 15 , 10 17)",
507 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
510 tester::apply("bb6-i", box1
, "BOX(8 8, 10 10)",
511 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
514 tester::apply("bb6-j", box1
, "BOX(15 8, 17 10)",
515 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
519 tester::apply("bb7", box1
, "BOX(12 22, 17 27)",
520 pp_distance
<Point
>("POINT(17 20)",
521 "POINT(17 22)", strategy_pp
),
525 tester::apply("bb8", box1
, "BOX(4 4, 8 8)",
526 pp_distance
<Point
>("POINT(8 8)", "POINT(10 10)", strategy_pp
),
530 tester::apply("bb9-a", box1
, "BOX(4 14, 8 18)",
531 ps_distance
<Point
>("POINT(8 18)",
532 "SEGMENT(10 10, 10 20)", strategy_ps
),
535 tester::apply("bb9-b", box1
, "BOX(4 10, 8 18)",
536 ps_distance
<Point
>("POINT(8 18)",
537 "SEGMENT(10 10, 10 20)", strategy_ps
),
540 tester::apply("bb9-c", box1
, "BOX(4 8, 8 18)",
541 ps_distance
<Point
>("POINT(8 18)",
542 "SEGMENT(10 10, 10 20)", strategy_ps
),
546 tester::apply("bb10a", box1
, "BOX(4 18, 8 22)",
547 ps_distance
<Point
>("POINT(10 20)",
548 "SEGMENT(8 18, 8 22)", strategy_ps
),
551 std::string
const box1m
= "BOX(10 -20,20 -10)";
552 tester::apply("bb10am", box1m
, "BOX(4 -22, 8 -18)",
553 ps_distance
<Point
>("POINT(10 20)",
554 "SEGMENT(8 18, 8 22)", strategy_ps
),
557 tester::apply("bb10b", box1
, "BOX(4 20, 8 22)",
558 ps_distance
<Point
>("POINT(10 20)",
559 "SEGMENT(8 20, 8 22)", strategy_ps
),
562 tester::apply("bb10bm", box1m
, "BOX(4 -22, 8 -20)",
563 ps_distance
<Point
>("POINT(10 20)",
564 "SEGMENT(8 22, 8 20)", strategy_ps
),
568 tester::apply("bb11", box1
, "BOX(4 22, 8 24)",
569 pp_distance
<Point
>("POINT(8 22)", "POINT(10 20)", strategy_pp
),
573 tester::apply("bb-far", "BOX(150 15, 170 25)", box1
,
574 ps_distance
<Point
>("POINT(20 20)",
575 "SEGMENT(150 15, 150 25)", strategy_ps
),
578 // crosses antimeridian
579 tester::apply("bb-anti1", "BOX(170 15, -160 25)", box1
,
580 ps_distance
<Point
>("POINT(20 20)",
581 "SEGMENT(170 15, 170 25)", strategy_ps
),
584 tester::apply("bb-anti2", "BOX(170 15, -160 25)", "BOX(160 10, -170 20)",
585 pp_distance
<Point
>("POINT(20 20)",
586 "POINT(20 20)", strategy_pp
),
589 tester::apply("bb-anti3", "BOX(170 15, -160 25)", "BOX(160 10, 170 20)",
590 pp_distance
<Point
>("POINT(20 20)",
591 "POINT(20 20)", strategy_pp
),
594 tester::apply("bb-anti4", "BOX(170 10, -160 20)", "BOX(160 30, -170 40)",
595 pp_distance
<Point
>("POINT(180 20)",
596 "POINT(180 30)", strategy_pp
),
601 tester::apply("bb-south1", "BOX(10 -20, 20 -10)", "BOX(30 -15, 40 -12)",
602 ps_distance
<Point
>("POINT(30 -15)",
603 "SEGMENT(20 -10, 20 -20)", strategy_ps
),
606 tester::apply("bb-south2", "BOX(10 -20, 20 -10)", "BOX(30 -30, 40 -25)",
607 pp_distance
<Point
>("POINT(30 -25)",
608 "POINT(20 -20)", strategy_pp
),
611 tester::apply("bb-south3", "BOX(10 -20, 20 -10)", "BOX(30 -25, 40 -15)",
612 ps_distance
<Point
>("POINT(20 -20)",
613 "SEGMENT(30 -15, 30 -25)", strategy_ps
),
616 tester::apply("bb-south4", "BOX(10 -20, 20 -10)", "BOX(5 -30, 30 -25)",
617 pp_distance
<Point
>("POINT(10 -25)",
618 "POINT(10 -20)", strategy_pp
),
621 tester::apply("bb-south4", "BOX(10 -20, 20 -10)", "BOX(5 -7, 30 -5)",
622 pp_distance
<Point
>("POINT(10 -7)",
623 "POINT(10 -10)", strategy_pp
),
629 tester::apply("bb-eq1", "BOX(30 -15, 40 30)", "BOX(10 -20, 20 25)",
630 ps_distance
<Point
>("POINT(20 25)",
631 "SEGMENT(30 -15, 30 30)", strategy_ps
),
634 tester::apply("bb-eq1b", "BOX(30 -15, 40 30)", "BOX(10 -20, 20 10)",
635 ps_distance
<Point
>("POINT(30 -15)",
636 "SEGMENT(20 10, 20 -20)", strategy_ps
),
639 tester::apply("bb-eq1bm", "BOX(30 -30, 40 15)", "BOX(10 -10, 20 20)",
640 ps_distance
<Point
>("POINT(30 15)",
641 "SEGMENT(20 -10, 20 20)", strategy_ps
),
644 tester::apply("bb-eq2", "BOX(30 -15, 40 20)", "BOX(10 -20, 20 25)",
645 ps_distance
<Point
>("POINT(30 20)",
646 "SEGMENT(20 -20, 20 25)", strategy_ps
),
649 tester::apply("bb-eq3", "BOX(30 5, 40 20)", "BOX(10 -20, 20 25)",
650 ps_distance
<Point
>("POINT(30 20)",
651 "SEGMENT(20 -20, 20 25)", strategy_ps
),
654 tester::apply("bb-eq4", "BOX(5 -30, 40 -25)", "BOX(10 -20, 20 25)",
655 pp_distance
<Point
>("POINT(10 -25)",
656 "POINT(10 -20)", strategy_pp
),
659 tester::apply("bb-eq5", "BOX(30 5, 40 20)", "BOX(10 -20, 50 25)",
660 pp_distance
<Point
>("POINT(30 20)",
661 "POINT(30 20)", strategy_pp
),
664 tester::apply("bb-eq6", "BOX(30 5, 40 20)", "BOX(10 -20, 35 25)",
665 pp_distance
<Point
>("POINT(30 20)",
666 "POINT(30 20)", strategy_pp
),
669 // One box in the north and one in the south hemisphere
671 tester::apply("bb-ns1", "BOX(30 15, 40 20)", "BOX(10 -20, 20 -15)",
672 pp_distance
<Point
>("POINT(30 15)",
673 "POINT(20 -15)", strategy_pp
),
676 tester::apply("bb-ns2", "BOX(30 15, 40 20)", "BOX(25 -20, 50 -15)",
677 pp_distance
<Point
>("POINT(30 15)",
678 "POINT(30 -15)", strategy_pp
),
681 //negative coordinates
683 std::string
const box1neg
= "BOX(-20 10,-10 20)";
686 tester::apply("bb1", box1neg
, "BOX(-40 0,-30 5)",
687 pp_distance
<Point
>("POINT(-20 10)",
688 "POINT(-30 5)", strategy_pp
),
692 tester::apply("bb2-a", box1neg
, "BOX(-40 12, -30 17)",
693 ps_distance
<Point
>("POINT(-30 17)",
694 "SEGMENT(-20 10,-20 20)", strategy_ps
),
697 tester::apply("bb2-b", box1neg
, "BOX(-40 10, -30 17)",
698 ps_distance
<Point
>("POINT(-30 17)",
699 "SEGMENT(-20 10,-20 20)", strategy_ps
),
702 tester::apply("bb2-c", box1neg
, "BOX(-40 8, -30 17)",
703 ps_distance
<Point
>("POINT(-30 17)",
704 "SEGMENT(-20 10,-20 20)", strategy_ps
),
709 tester::apply("bb3-a", box1neg
, "BOX(-40 15, -30 25)",
710 ps_distance
<Point
>("POINT(-20 20)",
711 "SEGMENT(-30 15,-30 25)", strategy_ps
),
714 tester::apply("bb3-b", box1neg
, "BOX(-40 20, -30 40)",
715 ps_distance
<Point
>("POINT(-20 20)",
716 "SEGMENT(-30 20,-30 40)", strategy_ps
),
720 tester::apply("bb4", box1neg
, "BOX(-40 25, -30 40)",
721 pp_distance
<Point
>("POINT(-20 20)",
722 "POINT(-30 25)", strategy_pp
),
726 tester::apply("bb5", box1neg
, "BOX(-17 2,-12 7)",
727 pp_distance
<Point
>("POINT(-17 7)",
728 "POINT(-17 10)", strategy_pp
),
731 // case 6, boxes intersect thus distance is 0
732 tester::apply("bb6-a", box1neg
, "BOX(-17 2, -12 10)",
733 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
736 tester::apply("bb6-b", box1neg
, "BOX(-17 2, -12 17)",
737 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
740 tester::apply("bb6-c", box1neg
, "BOX(-30 2, -20 10)",
741 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
744 tester::apply("bb6-d", box1neg
, "BOX(-30 11, -20 15)",
745 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
748 tester::apply("bb6-e", box1neg
, "BOX(-30 20, -20 30)",
749 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
752 tester::apply("bb6-f", box1neg
, "BOX(-17 20, -15 30)",
753 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
756 tester::apply("bb6-g", box1neg
, "BOX(-10 20, -8 25)",
757 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
760 tester::apply("bb6-h", box1neg
, "BOX(-10 15 , -8 17)",
761 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
764 tester::apply("bb6-i", box1neg
, "BOX(-10 8, -8 10)",
765 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
768 tester::apply("bb6-j", box1neg
, "BOX(-17 8, -15 10)",
769 pp_distance
<Point
>("POINT(0 0)", "POINT(0 0)", strategy_pp
),
773 tester::apply("bb7", box1neg
, "BOX(-17 22, -12 27)",
774 pp_distance
<Point
>("POINT(-17 20)",
775 "POINT(-17 22)", strategy_pp
),
779 tester::apply("bb8", box1neg
, "BOX(-8 4, -4 8)",
780 pp_distance
<Point
>("POINT(-8 8)",
781 "POINT(-10 10)", strategy_pp
),
785 tester::apply("bb9-a", box1neg
, "BOX(-8 14, -4 18)",
786 ps_distance
<Point
>("POINT(-8 18)",
787 "SEGMENT(-10 10, -10 20)", strategy_ps
),
790 tester::apply("bb9-b", box1neg
, "BOX(-8 10, -4 18)",
791 ps_distance
<Point
>("POINT(-8 18)",
792 "SEGMENT(-10 10, -10 20)", strategy_ps
),
795 tester::apply("bb9-c", box1neg
, "BOX(-8 8, -4 18)",
796 ps_distance
<Point
>("POINT(-8 18)",
797 "SEGMENT(-10 10, -10 20)", strategy_ps
),
801 tester::apply("bb10", box1neg
, "BOX(-8 18, -4 22)",
802 ps_distance
<Point
>("POINT(-10 20)",
803 "SEGMENT(-8 18, -8 22)", strategy_ps
),
806 tester::apply("bb10", box1neg
, "BOX(-8 20, -4 22)",
807 ps_distance
<Point
>("POINT(-10 20)",
808 "SEGMENT(-8 20, -8 22)", strategy_ps
),
812 tester::apply("bb11", box1neg
, "BOX(-8 22, -4 24)",
813 pp_distance
<Point
>("POINT(-8 22)",
814 "POINT(-10 20)", strategy_pp
),
820 //1st box degenerates to a meridian segment
821 std::string
const box1deg
= "BOX(0 10,0 20)";
824 tester::apply("pbd1", box1deg
, "BOX(1 15, 2 25)",
825 ps_distance
<Point
>("POINT(0 20)",
826 "SEGMENT(1 15, 1 25)", strategy_ps
),
829 //2nd box degenerates to a meridian segment
830 tester::apply("pbd2", box1deg
, "BOX(1 15, 1 25)",
831 ps_distance
<Point
>("POINT(0 20)",
832 "SEGMENT(1 15, 1 25)", strategy_ps
),
835 //2nd box degenerates to a horizontal line
836 //test fails for thomas strategy; test only for andoyer
837 tester::apply("pbd3", box1deg
, "BOX(1 15, 2 15)",
838 pp_distance
<Point
>("POINT(1 15)",
839 "POINT(0 15)", andoyer_pp()),
842 //2nd box degenerates to a point
843 tester::apply("pbd4", box1deg
, "BOX(1 15, 1 15)",
844 ps_distance
<Point
>("POINT(1 15)",
845 "SEGMENT(0 10, 0 20)", strategy_ps
),
849 //1st box degenerates to a horizontal line; that is not a geodesic segment
850 std::string
const box2deg
= "BOX(10 10,20 10)";
853 tester::apply("pbd5", box2deg
, "BOX(15 15, 25 20)",
854 pp_distance
<Point
>("POINT(15 15)",
855 "POINT(15 10)", strategy_pp
),
858 //2nd box degenerates to a horizontal line
859 tester::apply("pbd6", box2deg
, "BOX(15 15, 25 15)",
860 pp_distance
<Point
>("POINT(15 15)",
861 "POINT(15 10)", strategy_pp
),
864 //2nd box degenerates to a point
865 tester::apply("pbd7", box2deg
, "BOX(15 15, 15 15)",
866 pp_distance
<Point
>("POINT(15 15)",
867 "POINT(15 10)", strategy_pp
),
871 //1st box degenerates to a point
872 std::string
const box3deg
= "BOX(0 6,0 6)";
875 tester::apply("pbd8", box3deg
, "BOX(15 15, 25 20)",
876 ps_distance
<Point
>("POINT(0 6)",
877 "SEGMENT(15 15, 15 20)", strategy_ps
),
880 //2nd box degenerates to a point
881 tester::apply("pbd9", box3deg
, "BOX(15 15, 15 15)",
882 pp_distance
<Point
>("POINT(0 6)",
883 "POINT(15 15)", strategy_pp
),
887 //===========================================================================
892 typename Strategy_pp
,
893 typename Strategy_ps
,
894 typename Strategy_bb
,
897 void test_all_ar_ar(Strategy_pp pp_strategy
,
898 Strategy_ps ps_strategy
,
899 Strategy_bb bb_strategy
,
900 Strategy_sb sb_strategy
)
902 test_distance_ring_ring
<Point
>(pp_strategy
, ps_strategy
);
904 test_distance_ring_polygon
<Point
>(pp_strategy
, ps_strategy
);
905 test_distance_polygon_polygon
<Point
>(pp_strategy
, ps_strategy
);
907 test_distance_ring_multi_polygon
<Point
>(pp_strategy
, ps_strategy
);
908 test_distance_polygon_multi_polygon
<Point
>(pp_strategy
, ps_strategy
);
909 test_distance_multi_polygon_multi_polygon
<Point
>(pp_strategy
, ps_strategy
);
911 test_distance_polygon_box
<Point
>(pp_strategy
, ps_strategy
, sb_strategy
);
912 test_distance_multi_polygon_box
<Point
>(pp_strategy
, ps_strategy
, sb_strategy
);
913 test_distance_ring_box
<Point
>(pp_strategy
, ps_strategy
, sb_strategy
);
914 test_distance_box_box
<Point
>(pp_strategy
, ps_strategy
, bb_strategy
);
916 test_more_empty_input_areal_areal
<Point
>(ps_strategy
);
919 BOOST_AUTO_TEST_CASE( test_all_areal_areal
)
921 typedef bg::model::point
924 bg::cs::spherical_equatorial
<bg::degree
>
927 test_all_ar_ar
<sph_point
>(spherical_pp(), spherical_ps(), spherical_bb(), spherical_sb());
929 typedef bg::model::point
932 bg::cs::geographic
<bg::degree
>
935 test_all_ar_ar
<geo_point
>(vincenty_pp(), vincenty_ps(), vincenty_bb(), vincenty_sb());
936 test_all_ar_ar
<geo_point
>(thomas_pp(), thomas_ps(), thomas_bb(), thomas_sb());
937 test_all_ar_ar
<geo_point
>(andoyer_pp(), andoyer_ps(), andoyer_bb(), andoyer_sb());
939 // test with different spheroid
940 stype
spheroid(6372000, 6370000);
941 test_all_ar_ar
<geo_point
>(andoyer_pp(spheroid
), andoyer_ps(spheroid
),
942 andoyer_bb(spheroid
), andoyer_sb(spheroid
));