]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/distance/distance_linear_areal.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / distance / distance_linear_areal.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2014-2015, Oracle and/or its affiliates.
5
6 // Contributed and/or modified by Menelaos Karavelas, 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 #include <iostream>
12
13 #ifndef BOOST_TEST_MODULE
14 #define BOOST_TEST_MODULE test_distance_linear_areal
15 #endif
16
17 #include <boost/test/included/unit_test.hpp>
18
19 #include "test_distance_common.hpp"
20
21
22 typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
23 typedef bg::model::point<int,2,bg::cs::cartesian> int_point_type;
24 typedef bg::model::segment<point_type> segment_type;
25 typedef bg::model::segment<int_point_type> int_segment_type;
26 typedef bg::model::linestring<point_type> linestring_type;
27 typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
28 typedef bg::model::polygon<point_type, false> polygon_type;
29 typedef bg::model::polygon<point_type, false, false> open_polygon_type;
30 typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
31 typedef bg::model::multi_polygon<open_polygon_type> open_multipolygon_type;
32 typedef bg::model::ring<point_type, false> ring_type;
33 typedef bg::model::box<point_type> box_type;
34 typedef bg::model::box<int_point_type> int_box_type;
35
36 namespace services = bg::strategy::distance::services;
37 typedef bg::default_distance_result<point_type>::type return_type;
38
39 typedef bg::strategy::distance::pythagoras<> point_point_strategy;
40 typedef bg::strategy::distance::projected_point<> point_segment_strategy;
41
42 //===========================================================================
43
44 template <typename Strategy>
45 void test_distance_segment_polygon(Strategy const& strategy)
46 {
47 #ifdef BOOST_GEOMETRY_TEST_DEBUG
48 std::cout << std::endl;
49 std::cout << "segment/polygon distance tests" << std::endl;
50 #endif
51 typedef test_distance_of_geometries<segment_type, polygon_type> tester;
52
53 tester::apply("segment(-1 20,1 20)",
54 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
55 10, 100, strategy);
56
57 tester::apply("segment(1 20,2 40)",
58 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
59 10, 100, strategy);
60
61 tester::apply("segment(-1 20,-1 5)",
62 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
63 0, 0, strategy);
64
65 tester::apply("segment(-1 20,-1 -20)",
66 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
67 0, 0, strategy);
68
69 tester::apply("segment(0 0,1 1)",
70 "polygon((2 2))",
71 sqrt(2.0), 2, strategy);
72 }
73
74 //===========================================================================
75
76 template <typename Strategy>
77 void test_distance_linestring_polygon(Strategy const& strategy)
78 {
79 #ifdef BOOST_GEOMETRY_TEST_DEBUG
80 std::cout << std::endl;
81 std::cout << "linestring/polygon distance tests" << std::endl;
82 #endif
83 typedef test_distance_of_geometries<linestring_type, polygon_type> tester;
84
85 tester::apply("linestring(-1 20,1 20,1 30)",
86 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
87 10, 100, strategy);
88
89 tester::apply("linestring(-5 1,-2 1)",
90 "polygon((0 0,10 0,10 10,0 10,0 0))",
91 2, 4, strategy);
92
93 tester::apply("linestring(-1 20,1 20,1 5)",
94 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
95 0, 0, strategy);
96
97 tester::apply("linestring(-1 20,1 20,1 -20)",
98 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
99 0, 0, strategy);
100
101 tester::apply("linestring(-2 1)",
102 "polygon((0 0,10 0,10 10,0 10,0 0))",
103 2, 4, strategy);
104
105 tester::apply("linestring(-5 1,-2 1)",
106 "polygon((0 0))",
107 sqrt(5.0), 5, strategy);
108 }
109
110 //===========================================================================
111
112 template <typename Strategy>
113 void test_distance_linestring_open_polygon(Strategy const& strategy)
114 {
115 #ifdef BOOST_GEOMETRY_TEST_DEBUG
116 std::cout << std::endl;
117 std::cout << "linestring/open polygon distance tests" << std::endl;
118 #endif
119 typedef test_distance_of_geometries
120 <
121 linestring_type, open_polygon_type
122 > tester;
123
124 tester::apply("linestring(-5 1,-2 1)",
125 "polygon((0 0,10 0,10 10,0 10))",
126 2, 4, strategy);
127 }
128
129 //===========================================================================
130
131 template <typename Strategy>
132 void test_distance_multilinestring_polygon(Strategy const& strategy)
133 {
134 #ifdef BOOST_GEOMETRY_TEST_DEBUG
135 std::cout << std::endl;
136 std::cout << "multilinestring/polygon distance tests" << std::endl;
137 #endif
138 typedef test_distance_of_geometries
139 <
140 multi_linestring_type, polygon_type
141 > tester;
142
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))",
145 10, 100, strategy);
146
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))",
149 0, 0, strategy);
150
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))",
153 0, 0, strategy);
154
155 tester::apply("multilinestring((-100 -100,-90 -90),(1 20))",
156 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
157 10, 100, strategy);
158
159 tester::apply("multilinestring((-100 -100,-90 -90),(-1 20,1 20,1 30))",
160 "polygon((-110 -110))",
161 sqrt(200.0), 200, strategy);
162 }
163
164 //===========================================================================
165
166 template <typename Strategy>
167 void test_distance_segment_multipolygon(Strategy const& strategy)
168 {
169 #ifdef BOOST_GEOMETRY_TEST_DEBUG
170 std::cout << std::endl;
171 std::cout << "segment/multipolygon distance tests" << std::endl;
172 #endif
173 typedef test_distance_of_geometries
174 <
175 segment_type, multi_polygon_type
176 > tester;
177
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)))",
181 2, 4, strategy);
182
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)))",
186 2, 4, strategy);
187
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)))",
191 0, 0, strategy);
192
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)))",
196 0, 0, strategy);
197 }
198
199 //===========================================================================
200
201 template <typename Strategy>
202 void test_distance_linestring_multipolygon(Strategy const& strategy)
203 {
204 #ifdef BOOST_GEOMETRY_TEST_DEBUG
205 std::cout << std::endl;
206 std::cout << "linestring/multipolygon distance tests" << std::endl;
207 #endif
208 typedef test_distance_of_geometries
209 <
210 linestring_type, multi_polygon_type
211 > tester;
212
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)))",
216 2, 4, strategy);
217
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)))",
221 2, 4, strategy);
222
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)))",
226 0, 0, strategy);
227
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)))",
231 0, 0, strategy);
232 }
233
234 //===========================================================================
235
236 template <typename Strategy>
237 void test_distance_linestring_open_multipolygon(Strategy const& strategy)
238 {
239 #ifdef BOOST_GEOMETRY_TEST_DEBUG
240 std::cout << std::endl;
241 std::cout << "linestring/open multipolygon distance tests" << std::endl;
242 #endif
243 typedef test_distance_of_geometries
244 <
245 linestring_type, open_multipolygon_type
246 > tester;
247
248 tester::apply("linestring(-5 1,-2 1)",
249 "multipolygon(((0 0,10 0,10 10,0 10)))",
250 2, 4, strategy);
251
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)))",
254 3, 9, strategy);
255 }
256
257 //===========================================================================
258
259 template <typename Strategy>
260 void test_distance_multilinestring_multipolygon(Strategy const& strategy)
261 {
262 #ifdef BOOST_GEOMETRY_TEST_DEBUG
263 std::cout << std::endl;
264 std::cout << "multilinestring/multipolygon distance tests" << std::endl;
265 #endif
266 typedef test_distance_of_geometries
267 <
268 multi_linestring_type, multi_polygon_type
269 > tester;
270
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);
275
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)))",
279 0, 0, strategy);
280 }
281
282 //===========================================================================
283
284 template <typename Strategy>
285 void test_distance_segment_ring(Strategy const& strategy)
286 {
287 #ifdef BOOST_GEOMETRY_TEST_DEBUG
288 std::cout << std::endl;
289 std::cout << "segment/ring distance tests" << std::endl;
290 #endif
291 typedef test_distance_of_geometries<segment_type, ring_type> tester;
292
293 tester::apply("segment(-1 20,1 20)",
294 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
295 10, 100, strategy);
296
297 tester::apply("segment(1 20,2 40)",
298 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
299 10, 100, strategy);
300
301 tester::apply("segment(-1 20,-1 5)",
302 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
303 0, 0, strategy);
304
305 tester::apply("segment(-1 20,-1 -20)",
306 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
307 0, 0, strategy);
308 }
309
310 //===========================================================================
311
312 template <typename Strategy>
313 void test_distance_linestring_ring(Strategy const& strategy)
314 {
315 #ifdef BOOST_GEOMETRY_TEST_DEBUG
316 std::cout << std::endl;
317 std::cout << "linestring/ring distance tests" << std::endl;
318 #endif
319 typedef test_distance_of_geometries<linestring_type, ring_type> tester;
320
321 tester::apply("linestring(-1 20,1 20,1 30)",
322 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
323 10, 100, strategy);
324
325 tester::apply("linestring(-1 20,1 20,1 5)",
326 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
327 0, 0, strategy);
328
329 tester::apply("linestring(-1 20,1 20,1 -20)",
330 "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
331 0, 0, strategy);
332 }
333
334 //===========================================================================
335
336 template <typename Strategy>
337 void test_distance_multilinestring_ring(Strategy const& strategy)
338 {
339 #ifdef BOOST_GEOMETRY_TEST_DEBUG
340 std::cout << std::endl;
341 std::cout << "multilinestring/ring distance tests" << std::endl;
342 #endif
343 typedef test_distance_of_geometries
344 <
345 multi_linestring_type, ring_type
346 > tester;
347
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))",
350 10, 100, strategy);
351
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))",
354 0, 0, strategy);
355
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))",
358 0, 0, strategy);
359 }
360
361 //===========================================================================
362
363 template <typename Strategy>
364 void test_distance_segment_box(Strategy const& strategy)
365 {
366 #ifdef BOOST_GEOMETRY_TEST_DEBUG
367 std::cout << std::endl;
368 std::cout << "2D segment/box distance tests" << std::endl;
369 #endif
370 typedef int_box_type B;
371 typedef segment_type S;
372 typedef int_segment_type IS;
373
374 typedef test_distance_of_geometries<B, S> tester;
375 typedef test_distance_of_geometries<B, IS> itester;
376
377 // 1st example by Adam Wulkiewicz
378 tester::apply("BOX(5 51,42 96)",
379 "SEGMENT(6.6799994 95.260002,35.119999 56.340004)",
380 0, 0, strategy);
381
382 // 2nd example by Adam Wulkiewicz
383 tester::apply("BOX(51 55,94 100)",
384 "SEGMENT(92.439995 50.130001,59.959999 80.870003)",
385 0, 0, strategy);
386
387 // segments that intersect the box
388 tester::apply("box(0 0,1 1)",
389 "segment(-1 0.5,0.5 0.75)",
390 0, 0, strategy);
391 tester::apply("box(0 0,1 1)",
392 "segment(-1 0.5,1.5 0.75)",
393 0, 0, strategy);
394 tester::apply("box(0 0,1 1)",
395 "segment(0.5 -1,0.5 2)",
396 0, 0, strategy);
397 tester::apply("box(0 0,1 1)",
398 "segment(1 1,1.5 0.75)",
399 0, 0, strategy);
400 tester::apply("box(0 0,1 1)",
401 "segment(2 0,0 2)",
402 0, 0, strategy);
403
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)",
407 3, 9, strategy);
408
409 // segment that has closest point on box corner
410 tester::apply("box(0 0,1 1)",
411 "segment(4 0,0 4)",
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)",
420 "segment(-4 0,0 4)",
421 1.5 * sqrt(2.0), 4.5, strategy);
422 tester::apply("box(0 0,1 1)",
423 "segment(-4 0,1 5)",
424 1.5 * sqrt(2.0), 4.5, strategy);
425 itester::apply("box(0 0,1 1)",
426 "segment(0 -2,3 1)",
427 0.5 * sqrt(2.0), 0.5, strategy);
428 itester::apply("box(0 0,1 1)",
429 "segment(0 -2,2 2)",
430 0, 0, strategy);
431
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)",
438 1, 1, strategy);
439 tester::apply("box(0 0,1 1)",
440 "segment(-0.5 -1,0.5 -1)",
441 1, 1, strategy);
442 tester::apply("box(0 0,1 1)",
443 "segment(0.5 -1,0.75 -1)",
444 1, 1, strategy);
445 tester::apply("box(0 0,1 1)",
446 "segment(0.5 -1,1.25 -1)",
447 1, 1, strategy);
448 tester::apply("box(0 0,1 1)",
449 "segment(1 -1,2 -1)",
450 1, 1, strategy);
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)",
456 1, 1, strategy);
457
458 tester::apply("box(0 0,1 1)",
459 "segment(-2 0,-1 0)",
460 1, 1, strategy);
461 tester::apply("box(0 0,1 1)",
462 "segment(-1 0,0 0)",
463 0, 0, strategy);
464 tester::apply("box(0 0,1 1)",
465 "segment(-0.5 0,0.5 0)",
466 0, 0, strategy);
467 tester::apply("box(0 0,1 1)",
468 "segment(0.5 0,0.75 0)",
469 0, 0, strategy);
470 tester::apply("box(0 0,1 1)",
471 "segment(0.5 0,1.25 0)",
472 0, 0, strategy);
473 tester::apply("box(0 0,1 1)",
474 "segment(1 0,2 0)",
475 0, 0, strategy);
476 tester::apply("box(0 0,1 1)",
477 "segment(2 0,3 0)",
478 1, 1, strategy);
479 tester::apply("box(0 0,1 1)",
480 "segment(-2 0,2 0)",
481 0, 0, strategy);
482
483 tester::apply("box(0 0,1 1)",
484 "segment(-2 0.5,-1 0.5)",
485 1, 1, strategy);
486 tester::apply("box(0 0,1 1)",
487 "segment(-1 0.5,0 0.5)",
488 0, 0, strategy);
489 tester::apply("box(0 0,1 1)",
490 "segment(-0.5 0.5,0.5 0.5)",
491 0, 0, strategy);
492 tester::apply("box(0 0,1 1)",
493 "segment(0.5 0.5,0.75 0.5)",
494 0, 0, strategy);
495 tester::apply("box(0 0,1 1)",
496 "segment(0.5 0.5,1.25 0.5)",
497 0, 0, strategy);
498 tester::apply("box(0 0,1 1)",
499 "segment(1 0.5,2 0.5)",
500 0, 0, strategy);
501 tester::apply("box(0 0,1 1)",
502 "segment(2 0.5,3 0.5)",
503 1, 1, strategy);
504 tester::apply("box(0 0,1 1)",
505 "segment(-2 0.5,2 0.5)",
506 0, 0, strategy);
507
508 tester::apply("box(0 0,1 1)",
509 "segment(-2 1,-1 1)",
510 1, 1, strategy);
511 tester::apply("box(0 0,1 1)",
512 "segment(-1 1,0 1)",
513 0, 0, strategy);
514 tester::apply("box(0 0,1 1)",
515 "segment(-0.5 1,0.5 1)",
516 0, 0, strategy);
517 tester::apply("box(0 0,1 1)",
518 "segment(0.5 1,0.75 1)",
519 0, 0, strategy);
520 tester::apply("box(0 0,1 1)",
521 "segment(0.5 1,1.25 1)",
522 0, 0, strategy);
523 tester::apply("box(0 0,1 1)",
524 "segment(1 1,2 1)",
525 0, 0, strategy);
526 tester::apply("box(0 0,1 1)",
527 "segment(2 1,3 1)",
528 1, 1, strategy);
529 tester::apply("box(0 0,1 1)",
530 "segment(-2 1,2 1)",
531 0, 0, strategy);
532
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)",
537 "segment(-1 3,0 3)",
538 2, 4, strategy);
539 tester::apply("box(0 0,1 1)",
540 "segment(-0.5 3,0.5 3)",
541 2, 4, strategy);
542 tester::apply("box(0 0,1 1)",
543 "segment(0.5 3,0.75 3)",
544 2, 4, strategy);
545 tester::apply("box(0 0,1 1)",
546 "segment(0.5 3,1.25 3)",
547 2, 4, strategy);
548 tester::apply("box(0 0,1 1)",
549 "segment(1 3,2 3)",
550 2, 4, strategy);
551 tester::apply("box(0 0,1 1)",
552 "segment(2 3,3 3)",
553 sqrt(5.0), 5, strategy);
554 tester::apply("box(0 0,1 1)",
555 "segment(-2 3,2 3)",
556 2, 4, strategy);
557
558 // vertical segments
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)",
564 1, 1, strategy);
565 tester::apply("box(0 0,1 1)",
566 "segment(-1 -0.5,-1 0.5)",
567 1, 1, strategy);
568 tester::apply("box(0 0,1 1)",
569 "segment(-1 0.5,-1 0.75)",
570 1, 1, strategy);
571 tester::apply("box(0 0,1 1)",
572 "segment(-1 0.5,-1 1.25)",
573 1, 1, strategy);
574 tester::apply("box(0 0,1 1)",
575 "segment(-1 1,-1 2)",
576 1, 1, strategy);
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)",
582 1, 1, strategy);
583
584 tester::apply("box(0 0,1 1)",
585 "segment(0 -2,0 -1)",
586 1, 1, strategy);
587 tester::apply("box(0 0,1 1)",
588 "segment(0 -1,0 0)",
589 0, 0, strategy);
590 tester::apply("box(0 0,1 1)",
591 "segment(0 -0.5,0 0.5)",
592 0, 0, strategy);
593 tester::apply("box(0 0,1 1)",
594 "segment(0 0.5,0 0.75)",
595 0, 0, strategy);
596 tester::apply("box(0 0,1 1)",
597 "segment(0 0.5,0 1.25)",
598 0, 0, strategy);
599 tester::apply("box(0 0,1 1)",
600 "segment(0 1,0 2)",
601 0, 0, strategy);
602 tester::apply("box(0 0,1 1)",
603 "segment(0 2,0 3)",
604 1, 1, strategy);
605 tester::apply("box(0 0,1 1)",
606 "segment(0 -2,0 2)",
607 0, 0, strategy);
608
609 tester::apply("box(0 0,1 1)",
610 "segment(0.5 -2,0.5 -1)",
611 1, 1, strategy);
612 tester::apply("box(0 0,1 1)",
613 "segment(0.5 -1,0.5 0)",
614 0, 0, strategy);
615 tester::apply("box(0 0,1 1)",
616 "segment(0.5 -0.5,0.5 0.5)",
617 0, 0, strategy);
618 tester::apply("box(0 0,1 1)",
619 "segment(0.5 0.5,0.5 0.75)",
620 0, 0, strategy);
621 tester::apply("box(0 0,1 1)",
622 "segment(0.5 0.5,0.5 1.25)",
623 0, 0, strategy);
624 tester::apply("box(0 0,1 1)",
625 "segment(0.5 1,0.5 2)",
626 0, 0, strategy);
627 tester::apply("box(0 0,1 1)",
628 "segment(0.5 2,0.5 3)",
629 1, 1, strategy);
630 tester::apply("box(0 0,1 1)",
631 "segment(0.5 -2,0.5 2)",
632 0, 0, strategy);
633
634 tester::apply("box(0 0,1 1)",
635 "segment(1 -2,1 -1)",
636 1, 1, strategy);
637 tester::apply("box(0 0,1 1)",
638 "segment(1 -1,1 0)",
639 0, 0, strategy);
640 tester::apply("box(0 0,1 1)",
641 "segment(1 -0.5,1 0.5)",
642 0, 0, strategy);
643 tester::apply("box(0 0,1 1)",
644 "segment(1 0.5,1 0.75)",
645 0, 0, strategy);
646 tester::apply("box(0 0,1 1)",
647 "segment(1 0.5,1 1.25)",
648 0, 0, strategy);
649 tester::apply("box(0 0,1 1)",
650 "segment(1 1,1 2)",
651 0, 0, strategy);
652 tester::apply("box(0 0,1 1)",
653 "segment(1 2,1 3)",
654 1, 1, strategy);
655 tester::apply("box(0 0,1 1)",
656 "segment(1 -2,1 2)",
657 0, 0, strategy);
658
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)",
663 "segment(3 -1,3 0)",
664 2, 4, strategy);
665 tester::apply("box(0 0,1 1)",
666 "segment(3 -0.5,3 0.5)",
667 2, 4, strategy);
668 tester::apply("box(0 0,1 1)",
669 "segment(3 0.5,3 0.75)",
670 2, 4, strategy);
671 tester::apply("box(0 0,1 1)",
672 "segment(3 0.5,3 1.25)",
673 2, 4, strategy);
674 tester::apply("box(0 0,1 1)",
675 "segment(3 1,3 2)",
676 2, 4, strategy);
677 tester::apply("box(0 0,1 1)",
678 "segment(3 2,3 3)",
679 sqrt(5.0), 5, strategy);
680 tester::apply("box(0 0,1 1)",
681 "segment(3 -2,3 2)",
682 2, 4, strategy);
683
684 // positive slope
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)",
720 0, 0, strategy);
721 tester::apply("box(0 0,1 1)",
722 "segment(-2 -2,2 4)",
723 0, 0, strategy);
724 tester::apply("box(0 0,1 1)",
725 "segment(-2 -2,4 3)",
726 0, 0, strategy);
727 tester::apply("box(0 0,1 1)",
728 "segment(-2 -2,3 4)",
729 0, 0, strategy);
730 tester::apply("box(0 0,1 1)",
731 "segment(-2 -2,3 3)",
732 0, 0, strategy);
733
734 // negative slope
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)",
754 "segment(0 2,2 0)",
755 0, 0, strategy);
756 tester::apply("box(0 0,1 1)",
757 "segment(0 3,3 0)",
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)",
763 "segment(-1 4,0 3)",
764 2, 4, strategy);
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)",
772 "segment(1 2,2 1)",
773 sqrt(0.5), 0.5, strategy);
774 tester::apply("box(0 0,1 1)",
775 "segment(0.5 -2,2 -3)",
776 2, 4, strategy);
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)",
791 0, 0, strategy);
792
793 // test degenerate segment
794 tester::apply("box(0 0,2 2)",
795 "segment(4 1,4 1)",
796 2, 4, strategy);
797 }
798
799 //===========================================================================
800
801 template <typename Strategy>
802 void test_distance_linestring_box(Strategy const& strategy)
803 {
804 #ifdef BOOST_GEOMETRY_TEST_DEBUG
805 std::cout << std::endl;
806 std::cout << "linestring/box distance tests" << std::endl;
807 #endif
808 typedef test_distance_of_geometries<linestring_type, box_type> tester;
809
810 // linestrings that intersect the box
811 tester::apply("linestring(-1 0.5,0.5 0.75)",
812 "box(0 0,1 1)",
813 0, 0, strategy);
814 tester::apply("linestring(-1 0.5,1.5 0.75)",
815 "box(0 0,1 1)",
816 0, 0, strategy);
817
818 // linestring that has closest point on box boundary
819 tester::apply("linestring(4 0.5,5 0.75)",
820 "box(0 0,1 1)",
821 3, 9, strategy);
822
823 // linestring that has closest point on box corner
824 tester::apply("linestring(4 0,0 4)",
825 "box(0 0,1 1)",
826 sqrt(2.0), 2, strategy);
827 }
828
829 //===========================================================================
830
831 template <typename Strategy>
832 void test_distance_multilinestring_box(Strategy const& strategy)
833 {
834 #ifdef BOOST_GEOMETRY_TEST_DEBUG
835 std::cout << std::endl;
836 std::cout << "multilinestring/box distance tests" << std::endl;
837 #endif
838 typedef test_distance_of_geometries<multi_linestring_type, box_type> tester;
839
840 // multilinestring that intersects the box
841 tester::apply("multilinestring((-1 0.5,0.5 0.75),(4 0.5,5 0.75))",
842 "box(0 0,1 1)",
843 0, 0, strategy);
844
845 // multilinestring that has closest point on box boundary
846 tester::apply("multilinestring((4 0.5,5 0.75))",
847 "box(0 0,1 1)",
848 3, 9, strategy);
849
850 // multilinestring that has closest point on box corner
851 tester::apply("multilinestring((5 0,0 5),(4 0,0 4))",
852 "box(0 0,1 1)",
853 sqrt(2.0), 2, strategy);
854 }
855
856 //===========================================================================
857
858 template <typename Point, typename Strategy>
859 void test_more_empty_input_linear_areal(Strategy const& strategy)
860 {
861 #ifdef BOOST_GEOMETRY_TEST_DEBUG
862 std::cout << std::endl;
863 std::cout << "testing on empty inputs... " << std::flush;
864 #endif
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;
870
871 bg::model::linestring<Point> line =
872 from_wkt<bg::model::linestring<Point> >("linestring(0 0,1 1)");
873
874 bg::model::polygon<Point> polygon =
875 from_wkt<bg::model::polygon<Point> >("polygon((0 0,1 0,0 1))");
876
877 bg::model::ring<Point> ring =
878 from_wkt<bg::model::ring<Point> >("polygon((0 0,1 0,0 1))");
879
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);
885
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);
890
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);
898
899 #ifdef BOOST_GEOMETRY_TEST_DEBUG
900 std::cout << "done!" << std::endl;
901 #endif
902 }
903
904 //===========================================================================
905
906 BOOST_AUTO_TEST_CASE( test_all_segment_polygon )
907 {
908 test_distance_segment_polygon(point_segment_strategy());
909 }
910
911 BOOST_AUTO_TEST_CASE( test_all_linestring_polygon )
912 {
913 test_distance_linestring_polygon(point_segment_strategy());
914 test_distance_linestring_open_polygon(point_segment_strategy());
915 }
916
917 BOOST_AUTO_TEST_CASE( test_all_multilinestring_polygon )
918 {
919 test_distance_multilinestring_polygon(point_segment_strategy());
920 }
921
922 BOOST_AUTO_TEST_CASE( test_all_segment_multipolygon )
923 {
924 test_distance_segment_multipolygon(point_segment_strategy());
925 }
926
927 BOOST_AUTO_TEST_CASE( test_all_linestring_multipolygon )
928 {
929 test_distance_linestring_multipolygon(point_segment_strategy());
930 test_distance_linestring_open_multipolygon(point_segment_strategy());
931 }
932
933 BOOST_AUTO_TEST_CASE( test_all_multilinestring_multipolygon )
934 {
935 test_distance_multilinestring_multipolygon(point_segment_strategy());
936 }
937
938 BOOST_AUTO_TEST_CASE( test_all_segment_ring )
939 {
940 test_distance_segment_ring(point_segment_strategy());
941 }
942
943 BOOST_AUTO_TEST_CASE( test_all_linestring_ring )
944 {
945 test_distance_linestring_ring(point_segment_strategy());
946 }
947
948 BOOST_AUTO_TEST_CASE( test_all_multilinestring_ring )
949 {
950 test_distance_multilinestring_ring(point_segment_strategy());
951 }
952
953 BOOST_AUTO_TEST_CASE( test_all_segment_box )
954 {
955 test_distance_segment_box(point_segment_strategy());
956 }
957
958 BOOST_AUTO_TEST_CASE( test_all_linestring_box )
959 {
960 test_distance_linestring_box(point_segment_strategy());
961 }
962
963 BOOST_AUTO_TEST_CASE( test_all_multilinestring_box )
964 {
965 test_distance_multilinestring_box(point_segment_strategy());
966 }
967
968 BOOST_AUTO_TEST_CASE( test_all_empty_input_linear_areal )
969 {
970 test_more_empty_input_linear_areal<point_type>(point_segment_strategy());
971 }