]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/distance/distance_se_geo_ar_ar.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / distance / distance_se_geo_ar_ar.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2017, 2018 Oracle and/or its affiliates.
5
6 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
7
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
10
11 #ifndef BOOST_TEST_MODULE
12 #define BOOST_TEST_MODULE test_distance_geographic_areal_areal
13 #endif
14
15 #include <boost/range.hpp>
16 #include <boost/type_traits/is_same.hpp>
17
18 #include <boost/test/included/unit_test.hpp>
19 #include <boost/geometry/util/condition.hpp>
20 #include <boost/geometry/strategies/strategies.hpp>
21
22 #include "test_distance_geo_common.hpp"
23 #include "test_empty_geometry.hpp"
24
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)
28 {
29
30 #ifdef BOOST_GEOMETRY_TEST_DEBUG
31 std::cout << std::endl;
32 std::cout << "ring/ring distance tests" << std::endl;
33 #endif
34 typedef bg::model::ring<Point> ring_type;
35
36 typedef test_distance_of_geometries<ring_type, ring_type> tester;
37
38 std::string const ring = "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
39
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);
44
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);
48
49 tester::apply("rr3", ring, ring,
50 0, strategy_ps, true, false, false);
51
52 }
53
54 //============================================================================
55
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)
59 {
60
61 #ifdef BOOST_GEOMETRY_TEST_DEBUG
62 std::cout << std::endl;
63 std::cout << "ring/polygon distance tests" << std::endl;
64 #endif
65 typedef bg::model::ring<Point> ring_type;
66 typedef bg::model::polygon<Point> polygon_type;
67
68 typedef test_distance_of_geometries<ring_type, polygon_type> tester;
69
70 std::string const ring = "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
71
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);
76
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);
80
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);
83 }
84
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)
88 {
89
90 #ifdef BOOST_GEOMETRY_TEST_DEBUG
91 std::cout << std::endl;
92 std::cout << "polygon/polygon distance tests" << std::endl;
93 #endif
94 typedef bg::model::polygon<Point> polygon_type;
95
96 typedef test_distance_of_geometries<polygon_type, polygon_type> tester;
97
98 std::string const poly = "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
99
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);
104
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);
108
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);
111
112 }
113
114 //============================================================================
115
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)
119 {
120
121 #ifdef BOOST_GEOMETRY_TEST_DEBUG
122 std::cout << std::endl;
123 std::cout << "ring/multi_polygon distance tests" << std::endl;
124 #endif
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;
128
129 typedef test_distance_of_geometries<ring_type, multi_polygon_type> tester;
130
131 std::string const ring = "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
132
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)",
136 strategy_ps),
137 strategy_ps, true, false, false);
138
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);
143
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);
147
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);
151 }
152
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)
156 {
157
158 #ifdef BOOST_GEOMETRY_TEST_DEBUG
159 std::cout << std::endl;
160 std::cout << "polygon/multi_polygon distance tests" << std::endl;
161 #endif
162 typedef bg::model::polygon<Point> polygon_type;
163 typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
164
165 typedef test_distance_of_geometries<polygon_type, multi_polygon_type> tester;
166
167 std::string const poly = "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
168
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)",
172 strategy_ps),
173 strategy_ps, true, false, false);
174
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);
179
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);
183
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);
187
188 // w/ interior ring
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))";
191
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)",
195 strategy_ps),
196 strategy_ps, true, false, false);
197
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);
202
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);
206
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);
210
211 }
212
213
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)
217 {
218
219 #ifdef BOOST_GEOMETRY_TEST_DEBUG
220 std::cout << std::endl;
221 std::cout << "multi_polygon/multi_polygon distance tests" << std::endl;
222 #endif
223 typedef bg::model::polygon<Point> polygon_type;
224 typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
225
226 typedef test_distance_of_geometries<multi_polygon_type, multi_polygon_type>
227 tester;
228
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)))";
231
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)",
235 strategy_ps),
236 strategy_ps, true, false, false);
237
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);
242
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);
246
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);
250
251 }
252
253 //============================================================================
254
255 template
256 <
257 typename Point,
258 typename Strategy_pp,
259 typename Strategy_ps,
260 typename Strategy_sb
261 >
262 void test_distance_ring_box(Strategy_pp const& strategy_pp,
263 Strategy_ps const& strategy_ps,
264 Strategy_sb const& strategy_sb)
265 {
266
267 #ifdef BOOST_GEOMETRY_TEST_DEBUG
268 std::cout << std::endl;
269 std::cout << "ring/box distance tests" << std::endl;
270 #endif
271 typedef bg::model::box<Point> box_type;
272 typedef bg::model::ring<Point> ring_type;
273
274 typedef test_distance_of_geometries<ring_type, box_type> tester;
275
276 std::string const ring = "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
277
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);
282
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);
287
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);
291
292 tester::apply("rb4", ring, "BOX(12 0,20 1)",
293 0, strategy_sb, true, false, false);
294 }
295
296 template
297 <
298 typename Point,
299 typename Strategy_pp,
300 typename Strategy_ps,
301 typename Strategy_sb
302 >
303 void test_distance_polygon_box(Strategy_pp const& strategy_pp,
304 Strategy_ps const& strategy_ps,
305 Strategy_sb const& strategy_sb)
306 {
307
308 #ifdef BOOST_GEOMETRY_TEST_DEBUG
309 std::cout << std::endl;
310 std::cout << "polygon/box distance tests" << std::endl;
311 #endif
312 typedef bg::model::box<Point> box_type;
313 typedef bg::model::polygon<Point> polygon_type;
314
315 typedef test_distance_of_geometries<polygon_type, box_type> tester;
316
317 std::string const polygon = "POLYGON((11 0,10 1,11 2,12 3,13 1,11 0))";
318
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);
323
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);
328
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);
332
333 tester::apply("pb4", polygon, "BOX(12 0,20 1)",
334 0, strategy_sb, true, false, false);
335
336 // w/ interior ring
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))";
339
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);
344 }
345
346 template
347 <
348 typename Point,
349 typename Strategy_pp,
350 typename Strategy_ps,
351 typename Strategy_sb
352 >
353 void test_distance_multi_polygon_box(Strategy_pp const& strategy_pp,
354 Strategy_ps const& strategy_ps,
355 Strategy_sb const& strategy_sb)
356 {
357
358 #ifdef BOOST_GEOMETRY_TEST_DEBUG
359 std::cout << std::endl;
360 std::cout << "multi_polygon/box distance tests" << std::endl;
361 #endif
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;
365
366 typedef test_distance_of_geometries<multi_polygon_type, box_type> tester;
367
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)))";
370
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);
375
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);
380
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);
385
386 tester::apply("mpb4", multi_polygon, "BOX(17 0,20 14)",
387 0, strategy_sb, true, false, false);
388 }
389
390
391 //===========================================================================
392 // Cases for relative location of box2 wrt to box1
393 //
394 // | |
395 // 11 | 7 | 4
396 // | |
397 // --10---+---------+---3---
398 // | |
399 // 9 | 6 | 2
400 // | |
401 // -------+---------+-------
402 // | |
403 // 8 | 5 | 1
404 // | |
405 //
406 // case 6 includes all possible intersections
407 // The picture assumes northern hemisphere location
408 // southern hemisphere picture is mirrored wrt the equator
409
410
411 template
412 <
413 typename Point,
414 typename Strategy_pp,
415 typename Strategy_ps,
416 typename Strategy_bb
417 >
418 void test_distance_box_box(Strategy_pp const& strategy_pp,
419 Strategy_ps const& strategy_ps,
420 Strategy_bb const& strategy_bb)
421 {
422
423 #ifdef BOOST_GEOMETRY_TEST_DEBUG
424 std::cout << std::endl;
425 std::cout << "box/box distance tests" << std::endl;
426 #endif
427 typedef bg::model::box<Point> box_type;
428
429 typedef test_distance_of_geometries<box_type, box_type> tester;
430
431 std::string const box1 = "BOX(10 10,20 20)";
432
433 // case 1
434 tester::apply("bb1", box1, "BOX(30 0,40 5)",
435 pp_distance<Point>("POINT(20 10)", "POINT(30 5)", strategy_pp),
436 strategy_bb);
437
438 // case 2
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),
442 strategy_bb);
443
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),
447 strategy_bb);
448
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),
452 strategy_bb);
453
454
455 // case 3
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),
459 strategy_bb);
460
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),
464 strategy_bb);
465
466 // case 4
467 tester::apply("bb4", box1, "BOX(30 25, 40 40)",
468 pp_distance<Point>("POINT(20 20)",
469 "POINT(30 25)", strategy_pp),
470 strategy_bb);
471
472 // case 5
473 tester::apply("bb5", box1, "BOX(12 2, 17 7)",
474 pp_distance<Point>("POINT(17 7)", "POINT(17 10)", strategy_pp),
475 strategy_bb);
476
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),
480 strategy_bb);
481
482 tester::apply("bb6-b", box1, "BOX(12 2, 17 17)",
483 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
484 strategy_bb);
485
486 tester::apply("bb6-c", box1, "BOX(20 2, 30 10)",
487 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
488 strategy_bb);
489
490 tester::apply("bb6-d", box1, "BOX(20 11, 30 15)",
491 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
492 strategy_bb);
493
494 tester::apply("bb6-e", box1, "BOX(20 20, 30 30)",
495 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
496 strategy_bb);
497
498 tester::apply("bb6-f", box1, "BOX(15 20, 17 30)",
499 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
500 strategy_bb);
501
502 tester::apply("bb6-g", box1, "BOX(8 20, 10 25)",
503 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
504 strategy_bb);
505
506 tester::apply("bb6-h", box1, "BOX(8 15 , 10 17)",
507 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
508 strategy_bb);
509
510 tester::apply("bb6-i", box1, "BOX(8 8, 10 10)",
511 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
512 strategy_bb);
513
514 tester::apply("bb6-j", box1, "BOX(15 8, 17 10)",
515 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
516 strategy_bb);
517
518 // case 7
519 tester::apply("bb7", box1, "BOX(12 22, 17 27)",
520 pp_distance<Point>("POINT(17 20)",
521 "POINT(17 22)", strategy_pp),
522 strategy_bb);
523
524 // case 8
525 tester::apply("bb8", box1, "BOX(4 4, 8 8)",
526 pp_distance<Point>("POINT(8 8)", "POINT(10 10)", strategy_pp),
527 strategy_bb);
528
529 // case 9
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),
533 strategy_bb);
534
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),
538 strategy_bb);
539
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),
543 strategy_bb);
544
545 // case 10
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),
549 strategy_bb);
550
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),
555 strategy_bb);
556
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),
560 strategy_bb);
561
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),
565 strategy_bb);
566
567 // case 11
568 tester::apply("bb11", box1, "BOX(4 22, 8 24)",
569 pp_distance<Point>("POINT(8 22)", "POINT(10 20)", strategy_pp),
570 strategy_bb);
571
572 // far away boxes
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),
576 strategy_bb);
577
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),
582 strategy_bb);
583
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),
587 strategy_bb);
588
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),
592 strategy_bb);
593
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),
597 strategy_bb);
598
599 // South hemisphere
600
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),
604 strategy_bb);
605
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),
609 strategy_bb);
610
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),
614 strategy_bb);
615
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),
619 strategy_bb);
620
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),
624 strategy_bb);
625
626
627 // Crosses equator
628
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),
632 strategy_bb);
633
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),
637 strategy_bb);
638
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),
642 strategy_bb);
643
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),
647 strategy_bb);
648
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),
652 strategy_bb);
653
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),
657 strategy_bb);
658
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),
662 strategy_bb);
663
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),
667 strategy_bb);
668
669 // One box in the north and one in the south hemisphere
670
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),
674 strategy_bb);
675
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),
679 strategy_bb);
680
681 //negative coordinates
682
683 std::string const box1neg = "BOX(-20 10,-10 20)";
684
685 // case 1
686 tester::apply("bb1", box1neg, "BOX(-40 0,-30 5)",
687 pp_distance<Point>("POINT(-20 10)",
688 "POINT(-30 5)", strategy_pp),
689 strategy_bb);
690
691 // case 2
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),
695 strategy_bb);
696
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),
700 strategy_bb);
701
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),
705 strategy_bb);
706
707
708 // case 3
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),
712 strategy_bb);
713
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),
717 strategy_bb);
718
719 // case 4
720 tester::apply("bb4", box1neg, "BOX(-40 25, -30 40)",
721 pp_distance<Point>("POINT(-20 20)",
722 "POINT(-30 25)", strategy_pp),
723 strategy_bb);
724
725 // case 5
726 tester::apply("bb5", box1neg, "BOX(-17 2,-12 7)",
727 pp_distance<Point>("POINT(-17 7)",
728 "POINT(-17 10)", strategy_pp),
729 strategy_bb);
730
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),
734 strategy_bb);
735
736 tester::apply("bb6-b", box1neg, "BOX(-17 2, -12 17)",
737 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
738 strategy_bb);
739
740 tester::apply("bb6-c", box1neg, "BOX(-30 2, -20 10)",
741 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
742 strategy_bb);
743
744 tester::apply("bb6-d", box1neg, "BOX(-30 11, -20 15)",
745 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
746 strategy_bb);
747
748 tester::apply("bb6-e", box1neg, "BOX(-30 20, -20 30)",
749 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
750 strategy_bb);
751
752 tester::apply("bb6-f", box1neg, "BOX(-17 20, -15 30)",
753 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
754 strategy_bb);
755
756 tester::apply("bb6-g", box1neg, "BOX(-10 20, -8 25)",
757 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
758 strategy_bb);
759
760 tester::apply("bb6-h", box1neg, "BOX(-10 15 , -8 17)",
761 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
762 strategy_bb);
763
764 tester::apply("bb6-i", box1neg, "BOX(-10 8, -8 10)",
765 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
766 strategy_bb);
767
768 tester::apply("bb6-j", box1neg, "BOX(-17 8, -15 10)",
769 pp_distance<Point>("POINT(0 0)", "POINT(0 0)", strategy_pp),
770 strategy_bb);
771
772 // case 7
773 tester::apply("bb7", box1neg, "BOX(-17 22, -12 27)",
774 pp_distance<Point>("POINT(-17 20)",
775 "POINT(-17 22)", strategy_pp),
776 strategy_bb);
777
778 // case 8
779 tester::apply("bb8", box1neg, "BOX(-8 4, -4 8)",
780 pp_distance<Point>("POINT(-8 8)",
781 "POINT(-10 10)", strategy_pp),
782 strategy_bb);
783
784 // case 9
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),
788 strategy_bb);
789
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),
793 strategy_bb);
794
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),
798 strategy_bb);
799
800 // case 10
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),
804 strategy_bb);
805
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),
809 strategy_bb);
810
811 // case 11
812 tester::apply("bb11", box1neg, "BOX(-8 22, -4 24)",
813 pp_distance<Point>("POINT(-8 22)",
814 "POINT(-10 20)", strategy_pp),
815 strategy_bb);
816
817
818 //Degenerate cases
819
820 //1st box degenerates to a meridian segment
821 std::string const box1deg = "BOX(0 10,0 20)";
822
823 //2nd box generic
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),
827 strategy_bb);
828
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),
833 strategy_bb);
834
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()),
840 andoyer_bb());
841
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),
846 strategy_bb);
847
848 //---
849 //1st box degenerates to a horizontal line; that is not a geodesic segment
850 std::string const box2deg = "BOX(10 10,20 10)";
851
852 //2nd box generic
853 tester::apply("pbd5", box2deg, "BOX(15 15, 25 20)",
854 pp_distance<Point>("POINT(15 15)",
855 "POINT(15 10)", strategy_pp),
856 strategy_bb);
857
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),
862 strategy_bb);
863
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),
868 strategy_bb);
869
870 //---
871 //1st box degenerates to a point
872 std::string const box3deg = "BOX(0 6,0 6)";
873
874 //2nd box generic
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),
878 strategy_bb);
879
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),
884 strategy_bb);
885 }
886
887 //===========================================================================
888
889 template
890 <
891 typename Point,
892 typename Strategy_pp,
893 typename Strategy_ps,
894 typename Strategy_bb,
895 typename Strategy_sb
896 >
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)
901 {
902 test_distance_ring_ring<Point>(pp_strategy, ps_strategy);
903
904 test_distance_ring_polygon<Point>(pp_strategy, ps_strategy);
905 test_distance_polygon_polygon<Point>(pp_strategy, ps_strategy);
906
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);
910
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);
915
916 test_more_empty_input_areal_areal<Point>(ps_strategy);
917 }
918
919 BOOST_AUTO_TEST_CASE( test_all_areal_areal )
920 {
921 typedef bg::model::point
922 <
923 double, 2,
924 bg::cs::spherical_equatorial<bg::degree>
925 > sph_point;
926
927 test_all_ar_ar<sph_point>(spherical_pp(), spherical_ps(), spherical_bb(), spherical_sb());
928
929 typedef bg::model::point
930 <
931 double, 2,
932 bg::cs::geographic<bg::degree>
933 > geo_point;
934
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());
938
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));
943 }