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 #include <iostream>
12
13 #ifndef BOOST_TEST_MODULE
14 #define BOOST_TEST_MODULE test_distance_geographic_linear_areal
15 #endif
16
17 #include <boost/range.hpp>
18 #include <boost/type_traits/is_same.hpp>
19
20 #include <boost/test/included/unit_test.hpp>
21 #include <boost/geometry/util/condition.hpp>
22 #include <boost/geometry/strategies/strategies.hpp>
23
24 #include "test_distance_geo_common.hpp"
25 #include "test_empty_geometry.hpp"
26
27
28 template <typename Point, typename Strategy_pp, typename Strategy_ps>
test_distance_segment_polygon(Strategy_pp const & strategy_pp,Strategy_ps const & strategy_ps)29 void test_distance_segment_polygon(Strategy_pp const& strategy_pp,
30 Strategy_ps const& strategy_ps)
31 {
32
33 #ifdef BOOST_GEOMETRY_TEST_DEBUG
34 std::cout << std::endl;
35 std::cout << "segment/polygon distance tests" << std::endl;
36 #endif
37 typedef bg::model::segment<Point> segment_type;
38 typedef bg::model::polygon<Point> polygon_type;
39 typedef test_distance_of_geometries<segment_type, polygon_type> tester;
40
41 std::string const polygon = "POLYGON((10 10,0 20,15 30,20 15,15 10,10 10))";
42
43 tester::apply("s-p-1", "SEGMENT(0 0, 0 10)", polygon,
44 ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
45 strategy_ps, true, false, false);
46
47 tester::apply("s-p-2", "SEGMENT(9 0, 10 9)", polygon,
48 pp_distance<Point>("POINT(10 10)", "POINT(10 9)", strategy_pp),
49 strategy_ps, true, false, false);
50
51 tester::apply("s-p-3", "SEGMENT(9 0, 10 10)", polygon,
52 0, strategy_ps, true, false, false);
53
54 tester::apply("s-p-4", "SEGMENT(9 0, 10 11)", polygon,
55 0, strategy_ps, true, false, false);
56 }
57
58 template <typename Point, typename Strategy_pp, typename Strategy_ps>
test_distance_linestring_polygon(Strategy_pp const & strategy_pp,Strategy_ps const & strategy_ps)59 void test_distance_linestring_polygon(Strategy_pp const& strategy_pp,
60 Strategy_ps const& strategy_ps)
61 {
62
63 #ifdef BOOST_GEOMETRY_TEST_DEBUG
64 std::cout << std::endl;
65 std::cout << "linestring/polygon distance tests" << std::endl;
66 #endif
67 typedef bg::model::linestring<Point> linestring_type;
68 typedef bg::model::polygon<Point> polygon_type;
69 typedef test_distance_of_geometries<linestring_type, polygon_type> tester;
70
71 std::string const polygon = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))";
72
73 tester::apply("l-p-1", "LINESTRING(0 0,0 10)", polygon,
74 ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
75 strategy_ps, true, false, false);
76
77 tester::apply("l-p-2", "LINESTRING(9 0,10 9,11 8,15 8,20 9)", polygon,
78 pp_distance<Point>("POINT(10 10)", "POINT(10 9)", strategy_pp),
79 strategy_ps, true, false, false);
80
81 tester::apply("l-p-3", "LINESTRING(9 0,10 1,10 10,11 9)", polygon,
82 0, strategy_ps, true, false, false);
83
84 tester::apply("l-p-4", "LINESTRING(9 0,10 11,10 9,11 9)", polygon,
85 0, strategy_ps, true, false, false);
86 }
87
88 template <typename Point, typename Strategy_pp, typename Strategy_ps>
test_distance_multi_linestring_polygon(Strategy_pp const & strategy_pp,Strategy_ps const & strategy_ps)89 void test_distance_multi_linestring_polygon(Strategy_pp const& strategy_pp,
90 Strategy_ps const& strategy_ps)
91 {
92
93 #ifdef BOOST_GEOMETRY_TEST_DEBUG
94 std::cout << std::endl;
95 std::cout << "multilinestring/polygon distance tests" << std::endl;
96 #endif
97 typedef bg::model::linestring<Point> linestring_type;
98 typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
99 typedef bg::model::polygon<Point> polygon_type;
100 typedef test_distance_of_geometries<multi_linestring_type, polygon_type> tester;
101
102 std::string const polygon = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))";
103
104 tester::apply("ml-p-1", "MULTILINESTRING((0 0,0 10)\
105 (0 0,1 0,2 0,3 0,4 0,10 0,15 0,20 0))", polygon,
106 ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
107 strategy_ps, true, false, false);
108
109 tester::apply("ml-p-2", "MULTILINESTRING((9 0,10 9,11 8,15 8,20 9)\
110 (0 0,1 0,2 0,3 0,4 0,10 0,15 0,20 0))", polygon,
111 pp_distance<Point>("POINT(10 10)", "POINT(10 9)", strategy_pp),
112 strategy_ps, true, false, false);
113
114 tester::apply("ml-p-3", "MULTILINESTRING((9 0,10 1,10 10,11 9)\
115 (0 0,1 0,2 0,3 0,4 0,10 0,15 0,20 0))", polygon,
116 0, strategy_ps, true, false, false);
117
118 tester::apply("ml-p-4", "MULTILINESTRING((9 0,10 11,10 9,11 9)\
119 (0 0,1 0,2 0,3 0,4 0,10 0,15 0,20 0))", polygon,
120 0, strategy_ps, true, false, false);
121 }
122
123 //=====================================================================
124
125 template <typename Point, typename Strategy_pp, typename Strategy_ps>
test_distance_segment_multi_polygon(Strategy_pp const & strategy_pp,Strategy_ps const & strategy_ps)126 void test_distance_segment_multi_polygon(Strategy_pp const& strategy_pp,
127 Strategy_ps const& strategy_ps)
128 {
129
130 #ifdef BOOST_GEOMETRY_TEST_DEBUG
131 std::cout << std::endl;
132 std::cout << "segment/multi_polygon distance tests" << std::endl;
133 #endif
134 typedef bg::model::segment<Point> segment_type;
135 typedef bg::model::polygon<Point> polygon_type;
136 typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
137 typedef test_distance_of_geometries<segment_type, multi_polygon_type> tester;
138
139 std::string const mp = "MULTIPOLYGON(((20 20, 20 30, 30 40, 20 20)),\
140 ((10 10,0 20, 15 30, 20 15, 15 10, 10 10)))";
141
142 tester::apply("s-mp-1", "SEGMENT(0 0, 0 10)", mp,
143 ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
144 strategy_ps, true, false, false);
145
146 tester::apply("s-mp-2", "SEGMENT(9 0, 10 9)", mp,
147 pp_distance<Point>("POINT(10 10)", "POINT(10 9)", strategy_pp),
148 strategy_ps, true, false, false);
149
150 tester::apply("s-mp-3", "SEGMENT(9 0, 10 10)", mp,
151 0, strategy_ps, true, false, false);
152
153 tester::apply("s-mp-4", "SEGMENT(9 0, 10 11)", mp,
154 0, strategy_ps, true, false, false);
155 }
156
157 template <typename Point, typename Strategy_pp, typename Strategy_ps>
test_distance_linestring_multi_polygon(Strategy_pp const & strategy_pp,Strategy_ps const & strategy_ps)158 void test_distance_linestring_multi_polygon(Strategy_pp const& strategy_pp,
159 Strategy_ps const& strategy_ps)
160 {
161
162 #ifdef BOOST_GEOMETRY_TEST_DEBUG
163 std::cout << std::endl;
164 std::cout << "linestring/multi_polygon distance tests" << std::endl;
165 #endif
166 typedef bg::model::linestring<Point> linestring_type;
167 typedef bg::model::polygon<Point> polygon_type;
168 typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
169 typedef test_distance_of_geometries<linestring_type, multi_polygon_type> tester;
170
171 std::string const mp = "MULTIPOLYGON(((20 20, 20 30, 30 40, 20 20)),\
172 ((10 10,0 20, 15 30, 20 15, 15 10, 10 10)))";
173
174 tester::apply("l-mp-1", "LINESTRING(0 0, 0 10)", mp,
175 ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
176 strategy_ps, true, false, false);
177
178 tester::apply("l-mp-2", "LINESTRING(9 0,10 9,11 8,15 8,20 9)", mp,
179 pp_distance<Point>("POINT(10 10)", "POINT(10 9)", strategy_pp),
180 strategy_ps, true, false, false);
181
182 tester::apply("l-mp-3", "LINESTRING(9 0,10 1,10 10,11 9)", mp,
183 0, strategy_ps, true, false, false);
184
185 tester::apply("l-mp-4", "LINESTRING(9 0,10 11,10 9,11 9)", mp,
186 0, strategy_ps, true, false, false);
187
188 }
189
190 template <typename Point, typename Strategy_pp, typename Strategy_ps>
test_distance_multi_linestring_multi_polygon(Strategy_pp const & strategy_pp,Strategy_ps const & strategy_ps)191 void test_distance_multi_linestring_multi_polygon(Strategy_pp const& strategy_pp,
192 Strategy_ps const& strategy_ps)
193 {
194
195 #ifdef BOOST_GEOMETRY_TEST_DEBUG
196 std::cout << std::endl;
197 std::cout << "multilinestring/multi_polygon distance tests" << std::endl;
198 #endif
199 typedef bg::model::linestring<Point> linestring_type;
200 typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
201 typedef bg::model::polygon<Point> polygon_type;
202 typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
203 typedef test_distance_of_geometries<multi_linestring_type, multi_polygon_type> tester;
204
205 std::string const mp = "MULTIPOLYGON(((20 20, 20 30, 30 40, 20 20)),\
206 ((10 10,0 20, 15 30, 20 15, 15 10, 10 10)))";
207
208 tester::apply("ml-mp-1", "MULTILINESTRING((0 0, 0 10)(0 0, 10 0))", mp,
209 ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
210 strategy_ps, true, false, false);
211
212 tester::apply("ml-mp-2", "MULTILINESTRING((9 0,10 9,11 8,15 8,20 9)\
213 (0 0,1 0,2 0,3 0,4 0,10 0,15 0,20 0))", mp,
214 pp_distance<Point>("POINT(10 10)", "POINT(10 9)", strategy_pp),
215 strategy_ps, true, false, false);
216
217 tester::apply("ml-mp-3", "MULTILINESTRING((9 0,10 1,10 10,11 9)\
218 (0 0,1 0,2 0,3 0,4 0,10 0,15 0,20 0))", mp,
219 0, strategy_ps, true, false, false);
220
221 tester::apply("ml-mp-4", "MULTILINESTRING((9 0,10 11,10 9,11 9)\
222 (0 0,1 0,2 0,3 0,4 0,10 0,15 0,20 0))", mp,
223 0, strategy_ps, true, false, false);
224 }
225
226 //=====================================================================
227
228 template <typename Point, typename Strategy_ps>
test_distance_segment_ring(Strategy_ps const & strategy_ps)229 void test_distance_segment_ring(Strategy_ps const& strategy_ps)
230 {
231
232 #ifdef BOOST_GEOMETRY_TEST_DEBUG
233 std::cout << std::endl;
234 std::cout << "segment/ring distance tests" << std::endl;
235 #endif
236 typedef bg::model::segment<Point> segment_type;
237 typedef bg::model::ring<Point> ring_type;
238 typedef test_distance_of_geometries<segment_type, ring_type> tester;
239
240 std::string const ring = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))";
241
242 tester::apply("s-r-1", "SEGMENT(0 0, 0 10)", ring,
243 ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
244 strategy_ps, true, false, false);
245 }
246
247 template <typename Point, typename Strategy_ps>
test_distance_linestring_ring(Strategy_ps const & strategy_ps)248 void test_distance_linestring_ring(Strategy_ps const& strategy_ps)
249 {
250
251 #ifdef BOOST_GEOMETRY_TEST_DEBUG
252 std::cout << std::endl;
253 std::cout << "linestring/ring distance tests" << std::endl;
254 #endif
255 typedef bg::model::linestring<Point> linestring_type;
256 typedef bg::model::ring<Point> ring_type;
257 typedef test_distance_of_geometries<linestring_type, ring_type> tester;
258
259 std::string const ring = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))";
260
261 tester::apply("l-r-1", "LINESTRING(0 0, 0 10)", ring,
262 ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
263 strategy_ps, true, false, false);
264 }
265
266 template <typename Point, typename Strategy_ps>
test_distance_multi_linestring_ring(Strategy_ps const & strategy_ps)267 void test_distance_multi_linestring_ring(Strategy_ps const& strategy_ps)
268 {
269
270 #ifdef BOOST_GEOMETRY_TEST_DEBUG
271 std::cout << std::endl;
272 std::cout << "multilinestring/ring distance tests" << std::endl;
273 #endif
274 typedef bg::model::linestring<Point> linestring_type;
275 typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
276 typedef bg::model::ring<Point> ring_type;
277 typedef test_distance_of_geometries<multi_linestring_type, ring_type> tester;
278
279 std::string const ring = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))";
280
281 tester::apply("ml-r-1", "MULTILINESTRING((0 0, 0 10)(0 0, 10 0))", ring,
282 ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
283 strategy_ps, true, false, false);
284 }
285
286 //======================================================================
287
288 template <typename Point, typename Strategy_pp, typename Strategy_ps, typename Strategy_sb>
test_distance_segment_box(Strategy_pp const & strategy_pp,Strategy_ps const & strategy_ps,Strategy_sb const & strategy_sb)289 void test_distance_segment_box(Strategy_pp const& strategy_pp,
290 Strategy_ps const& strategy_ps,
291 Strategy_sb const& strategy_sb)
292 {
293
294 #ifdef BOOST_GEOMETRY_TEST_DEBUG
295 std::cout << std::endl;
296 std::cout << "segment/box distance tests" << std::endl;
297 #endif
298 typedef bg::model::segment<Point> segment_type;
299 typedef bg::model::box<Point> box_type;
300 typedef test_distance_of_geometries<segment_type, box_type> tester;
301
302 std::string const box_north = "BOX(10 10,20 20)";
303
304 tester::apply("sb1-1a", "SEGMENT(0 0, 0 20)", box_north,
305 pp_distance<Point>("POINT(0 20)", "POINT(10 20)", strategy_pp),
306 strategy_sb);
307 //segment with slope
308 tester::apply("sb1-1b", "SEGMENT(10 5, 20 6)", box_north,
309 pp_distance<Point>("POINT(20 6)", "POINT(20 10)", strategy_pp),
310 strategy_sb);
311 tester::apply("sb1-2", "SEGMENT(0 0, 0 10)", box_north,
312 ps_distance<Point>("POINT(0 10)", "SEGMENT(10 10,10 20)", strategy_ps),
313 strategy_sb);
314 tester::apply("sb1-3", "SEGMENT(0 0, 0 15)", box_north,
315 ps_distance<Point>("POINT(0 15)", "SEGMENT(10 10,10 20)", strategy_ps),
316 strategy_sb);
317 tester::apply("sb1-4", "SEGMENT(0 0, 0 25)", box_north,
318 ps_distance<Point>("POINT(10 20)", "SEGMENT(0 0,0 25)", strategy_ps),
319 strategy_sb);
320 tester::apply("sb1-5", "SEGMENT(0 10, 0 25)", box_north,
321 ps_distance<Point>("POINT(10 20)", "SEGMENT(0 0,0 25)", strategy_ps),
322 strategy_sb);
323
324 tester::apply("sb2-2", "SEGMENT(0 5, 15 5)", box_north,
325 ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5,15 5)", strategy_ps),
326 strategy_sb);
327 tester::apply("sb2-3a", "SEGMENT(0 5, 20 5)", box_north,
328 ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5,20 5)", strategy_ps),
329 strategy_sb);
330
331 // Test segments below box
332 tester::apply("test_b1", "SEGMENT(0 5, 9 5)", box_north,
333 ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5, 9 5)", strategy_ps),
334 strategy_sb);
335 tester::apply("test_b2", "SEGMENT(0 5, 10 5)", box_north,
336 ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5, 10 5)", strategy_ps),
337 strategy_sb);
338 tester::apply("test_b3", "SEGMENT(0 5, 11 5)", box_north,
339 ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5, 11 5)", strategy_ps),
340 strategy_sb);
341 tester::apply("test_b4", "SEGMENT(0 5, 20 5)", box_north,
342 ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5,20 5)", strategy_ps),
343 strategy_sb);
344 tester::apply("test_b5", "SEGMENT(0 5, 22 5)", box_north,
345 ps_distance<Point>("POINT(11 10)", "SEGMENT(0 5,22 5)", strategy_ps),
346 strategy_sb);
347 tester::apply("test_b6", "SEGMENT(10 5, 20 5)", box_north,
348 ps_distance<Point>("POINT(15 10)", "SEGMENT(10 5,20 5)", strategy_ps),
349 strategy_sb);
350 tester::apply("test_b7", "SEGMENT(10 5, 22 5)", box_north,
351 ps_distance<Point>("POINT(16 10)", "SEGMENT(10 5,22 5)", strategy_ps),
352 strategy_sb);
353 tester::apply("test_b8", "SEGMENT(12 5, 22 5)", box_north,
354 ps_distance<Point>("POINT(17 10)", "SEGMENT(12 5,22 5)", strategy_ps),
355 strategy_sb);
356 tester::apply("test_b9", "SEGMENT(18 5, 22 5)", box_north,
357 ps_distance<Point>("POINT(20 10)", "SEGMENT(18 5,22 5)", strategy_ps),
358 strategy_sb);
359 tester::apply("test_b10", "SEGMENT(18 5, 24 5)", box_north,
360 ps_distance<Point>("POINT(20 10)", "SEGMENT(18 5,24 5)", strategy_ps),
361 strategy_sb);
362 tester::apply("test_b11", "SEGMENT(20 5, 24 5)", box_north,
363 ps_distance<Point>("POINT(20 10)", "SEGMENT(20 5,24 5)", strategy_ps),
364 strategy_sb);
365 tester::apply("test_b12", "SEGMENT(22 5, 24 5)", box_north,
366 ps_distance<Point>("POINT(20 10)", "SEGMENT(22 5,24 5)", strategy_ps),
367 strategy_sb);
368 tester::apply("test_b13", "SEGMENT(0 5, 125 5)", box_north,
369 ps_distance<Point>("POINT(20 10)", "SEGMENT(0 5, 125 5)", strategy_ps),
370 strategy_sb);
371
372 // Test segments above box
373 tester::apply("test_a1", "SEGMENT(0 25, 9 25)", box_north,
374 ps_distance<Point>("POINT(10 20)", "SEGMENT(0 25, 9 25)", strategy_ps),
375 strategy_sb);
376 tester::apply("test_a2", "SEGMENT(0 25, 10 25)", box_north,
377 ps_distance<Point>("POINT(10 20)", "SEGMENT(0 25, 10 25)", strategy_ps),
378 strategy_sb);
379 tester::apply("test_a3", "SEGMENT(0 25, 11 25)", box_north,
380 ps_distance<Point>("POINT(11 20)", "SEGMENT(0 25, 11 25)", strategy_ps),
381 strategy_sb);
382 tester::apply("test_a4", "SEGMENT(0 25, 20 25)", box_north,
383 ps_distance<Point>("POINT(20 20)", "SEGMENT(0 25, 20 25)", strategy_ps),
384 strategy_sb);
385 tester::apply("test_a5", "SEGMENT(0 25, 22 25)", box_north,
386 ps_distance<Point>("POINT(20 20)", "SEGMENT(0 25, 22 25)", strategy_ps),
387 strategy_sb);
388 tester::apply("test_a6", "SEGMENT(10 25, 20 25)", box_north,
389 ps_distance<Point>("POINT(20 20)", "SEGMENT(10 25, 20 25)", strategy_ps),
390 strategy_sb);
391 tester::apply("test_a7", "SEGMENT(10 25, 22 25)", box_north,
392 ps_distance<Point>("POINT(10 20)", "SEGMENT(10 25, 22 25)", strategy_ps),
393 strategy_sb);
394 tester::apply("test_a8", "SEGMENT(12 25, 22 25)", box_north,
395 ps_distance<Point>("POINT(12 20)", "SEGMENT(12 25, 22 25)", strategy_ps),
396 strategy_sb);
397 tester::apply("test_a9", "SEGMENT(18 25, 22 25)", box_north,
398 ps_distance<Point>("POINT(18 20)", "SEGMENT(18 25, 22 25)", strategy_ps),
399 strategy_sb);
400 tester::apply("test_a10", "SEGMENT(18 25, 24 25)", box_north,
401 ps_distance<Point>("POINT(18 20)", "SEGMENT(18 25, 24 25)", strategy_ps),
402 strategy_sb);
403 tester::apply("test_a11", "SEGMENT(20 25, 24 25)", box_north,
404 ps_distance<Point>("POINT(20 20)", "SEGMENT(20 25, 24 25)", strategy_ps),
405 strategy_sb);
406 tester::apply("test_a12", "SEGMENT(22 25, 24 25)", box_north,
407 ps_distance<Point>("POINT(20 20)", "SEGMENT(22 25, 24 25)", strategy_ps),
408 strategy_sb);
409
410 // Segments left-right of box
411 tester::apply("test_l1", "SEGMENT(0 5, 9 5)", box_north,
412 ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5, 9 5)", strategy_ps),
413 strategy_sb);
414 tester::apply("test_l2", "SEGMENT(0 10, 9 10)", box_north,
415 ps_distance<Point>("POINT(9 10)", "SEGMENT(10 10, 10 20)", strategy_ps),
416 strategy_sb);
417 tester::apply("test_l3", "SEGMENT(0 10, 9 15)", box_north,
418 ps_distance<Point>("POINT(9 15)", "SEGMENT(10 10, 10 20)", strategy_ps),
419 strategy_sb);
420 tester::apply("test_l4", "SEGMENT(0 10, 0 15)", box_north,
421 ps_distance<Point>("POINT(0 15)", "SEGMENT(10 10, 10 20)", strategy_ps),
422 strategy_sb);
423 tester::apply("test_l5", "SEGMENT(1 10, 0 15)", box_north,
424 ps_distance<Point>("POINT(1 10)", "SEGMENT(10 10, 10 20)", strategy_ps),
425 strategy_sb);
426 tester::apply("test_l6", "SEGMENT(0 20, 9 21)", box_north,
427 ps_distance<Point>("POINT(9 21)", "SEGMENT(10 10, 10 20)", strategy_ps),
428 strategy_sb);
429 tester::apply("test_r1", "SEGMENT(21 5, 29 5)", box_north,
430 ps_distance<Point>("POINT(20 10)", "SEGMENT(21 5, 29 5)", strategy_ps),
431 strategy_sb);
432 tester::apply("test_r2", "SEGMENT(21 10, 29 10)", box_north,
433 ps_distance<Point>("POINT(21 10)", "SEGMENT(20 10, 20 20)", strategy_ps),
434 strategy_sb);
435 tester::apply("test_r3", "SEGMENT(21 10, 29 15)", box_north,
436 ps_distance<Point>("POINT(21 10)", "SEGMENT(20 10, 20 20)", strategy_ps),
437 strategy_sb);
438 tester::apply("test_r4", "SEGMENT(21 10, 21 15)", box_north,
439 ps_distance<Point>("POINT(21 15)", "SEGMENT(20 10, 20 20)", strategy_ps),
440 strategy_sb);
441 tester::apply("test_r5", "SEGMENT(21 10, 22 15)", box_north,
442 ps_distance<Point>("POINT(21 10)", "SEGMENT(20 10, 20 20)", strategy_ps),
443 strategy_sb);
444 tester::apply("test_r6", "SEGMENT(29 20, 21 21)", box_north,
445 ps_distance<Point>("POINT(21 21)", "SEGMENT(20 10, 20 20)", strategy_ps),
446 strategy_sb);
447
448 //Segments on corners of box
449 //left-top corner
450 //generic
451 tester::apply("test_c1", "SEGMENT(9 19.5, 11 21)", box_north,
452 ps_distance<Point>("POINT(10 20)", "SEGMENT(9 19.5, 11 21)", strategy_ps),
453 strategy_sb);
454 //degenerate
455 tester::apply("test_c2", "SEGMENT(9 19, 11 21)", box_north,
456 ps_distance<Point>("POINT(10 20)", "SEGMENT(9 19, 11 21)", strategy_ps),
457 strategy_sb);
458 //left-bottom corner
459 //generic
460 tester::apply("test_c3", "SEGMENT(8.5 11, 11 9)", box_north,
461 ps_distance<Point>("POINT(10 10)", "SEGMENT(8.5 11, 11 9)", strategy_ps),
462 strategy_sb);
463 //degenerate
464 tester::apply("test_c4", "SEGMENT(9 11, 11 9)", box_north,
465 0,
466 strategy_sb);
467 //right-top corner
468 //generic
469 tester::apply("test_c5", "SEGMENT(19 21, 21 19.5)", box_north,
470 ps_distance<Point>("POINT(20 20)", "SEGMENT(19 21, 21 19.5)", strategy_ps),
471 strategy_sb);
472 //degenerate
473 tester::apply("test_c6", "SEGMENT(19 21, 21 19)", box_north,
474 ps_distance<Point>("POINT(20 20)", "SEGMENT(19 21, 21 19)", strategy_ps),
475 strategy_sb);
476 //right-bottom corner
477 //generic
478 tester::apply("test_c7", "SEGMENT(19 9, 21 10.5)", box_north,
479 ps_distance<Point>("POINT(20 10)", "SEGMENT(19 9, 21 10.5)", strategy_ps),
480 strategy_sb);
481 tester::apply("test_c7", "SEGMENT(19 9, 21 11)", box_north,
482 0,
483 strategy_sb);
484
485 //Segment and box on different hemispheres
486 std::string const box_south = "BOX(10 -20,20 -10)";
487
488 tester::apply("test_ns1", "SEGMENT(10 20, 15 30)", box_south,
489 ps_distance<Point>("POINT(10 -10)", "SEGMENT(10 20, 15 30)", strategy_ps),
490 strategy_sb);
491 tester::apply("test_ns2", "SEGMENT(0 10, 12 10)", box_south,
492 pp_distance<Point>("POINT(12 10)", "POINT(12 -10)", strategy_pp),
493 strategy_sb);
494 tester::apply("test_ns3", "SEGMENT(10 10, 20 10)", box_south,
495 pp_distance<Point>("POINT(10 10)", "POINT(10 -10)", strategy_pp),
496 strategy_sb);
497 tester::apply("test_ns4", "SEGMENT(0 -10, 12 -10)", box_north,
498 pp_distance<Point>("POINT(12 10)", "POINT(12 -10)", strategy_pp),
499 strategy_sb);
500 tester::apply("test_ns5", "SEGMENT(10 -10, 20 -10)", box_north,
501 pp_distance<Point>("POINT(10 -10)", "POINT(10 10)", strategy_pp),
502 strategy_sb);
503
504 //Box crossing equator
505 std::string const box_crossing_eq = "BOX(10 -10,20 10)";
506
507 tester::apply("test_cr1", "SEGMENT(10 20, 15 30)", box_crossing_eq,
508 pp_distance<Point>("POINT(10 10)", "POINT(10 20)", strategy_pp),
509 strategy_sb);
510 tester::apply("test_cr2", "SEGMENT(10 -20, 15 -30)", box_crossing_eq,
511 pp_distance<Point>("POINT(10 10)", "POINT(10 20)", strategy_pp),
512 strategy_sb);
513
514 //Box crossing prime meridian
515
516 std::string const box_crossing_mer = "BOX(-10 10,15 20)";
517
518 tester::apply("test_cr3", "SEGMENT(-5 25, 10 30)", box_crossing_mer,
519 pp_distance<Point>("POINT(-5 25)", "POINT(-5 20)", strategy_pp),
520 strategy_sb);
521 tester::apply("test_cr4", "SEGMENT(-5 5, 10 7)", box_crossing_mer,
522 pp_distance<Point>("POINT(10 7)", "POINT(10 10)", strategy_pp),
523 strategy_sb);
524 tester::apply("test_cr5", "SEGMENT(-5 5, 10 5)", box_crossing_mer,
525 ps_distance<Point>("POINT(2.5 10)", "SEGMENT(-5 5, 10 5)", strategy_ps),
526 strategy_sb);
527
528
529 //Geometries in south hemisphere
530 tester::apply("test_south1", "SEGMENT(10 -30, 15 -30)", box_south,
531 ps_distance<Point>("POINT(10 -20)", "SEGMENT(10 -30, 15 -30)", strategy_ps),
532 strategy_sb);
533
534 //Segments in boxes corner
535 tester::apply("corner1", "SEGMENT(17 21, 25 20)", box_north,
536 ps_distance<Point>("POINT(20 20)", "SEGMENT(17 21, 25 20)", strategy_ps),
537 strategy_sb);
538 tester::apply("corner2", "SEGMENT(17 21, 0 20)", box_north,
539 ps_distance<Point>("POINT(10 20)", "SEGMENT(17 21, 0 20)", strategy_ps),
540 strategy_sb);
541 tester::apply("corner3", "SEGMENT(17 5, 0 10)", box_north,
542 ps_distance<Point>("POINT(10 10)", "SEGMENT(17 5, 0 10)", strategy_ps),
543 strategy_sb);
544 tester::apply("corner4", "SEGMENT(17 5, 25 9)", box_north,
545 ps_distance<Point>("POINT(20 10)", "SEGMENT(17 5, 25 9)", strategy_ps),
546 strategy_sb);
547 }
548
549 template <typename Point, typename Strategy_ps, typename Strategy_sb>
test_distance_linestring_box(Strategy_ps const & strategy_ps,Strategy_sb const & strategy_sb)550 void test_distance_linestring_box(Strategy_ps const& strategy_ps,
551 Strategy_sb const& strategy_sb)
552 {
553
554 #ifdef BOOST_GEOMETRY_TEST_DEBUG
555 std::cout << std::endl;
556 std::cout << "linestring/box distance tests" << std::endl;
557 #endif
558 typedef bg::model::linestring<Point> linestring_type;
559 typedef bg::model::box<Point> box_type;
560 typedef test_distance_of_geometries<linestring_type, box_type> tester;
561
562 std::string const box_north = "BOX(10 10,20 20)";
563
564 tester::apply("sl1", "LINESTRING(0 20, 15 21, 25 19.9, 21 5, 15 5, 0 10)", box_north,
565 ps_distance<Point>("POINT(20 20)", "SEGMENT(15 21, 25 19.9)", strategy_ps),
566 strategy_sb, true, false, false);
567
568 tester::apply("sl2", "LINESTRING(0 20, 15 21, 25 19.9, 21 5, 15 5, 15 15)", box_north,
569 0, strategy_sb, true, false, false);
570
571 tester::apply("sl3", "LINESTRING(0 20, 15 21, 25 19.9, 21 5, 15 5, 2 20)", box_north,
572 0, strategy_sb, true, false, false);
573 }
574
575 template <typename Point, typename Strategy_ps, typename Strategy_sb>
test_distance_multi_linestring_box(Strategy_ps const & strategy_ps,Strategy_sb const & strategy_sb)576 void test_distance_multi_linestring_box(Strategy_ps const& strategy_ps,
577 Strategy_sb const& strategy_sb)
578 {
579
580
581 #ifdef BOOST_GEOMETRY_TEST_DEBUG
582 std::cout << std::endl;
583 std::cout << "multi_linestring/box distance tests" << std::endl;
584 #endif
585 typedef bg::model::linestring<Point> linestring_type;
586 typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
587 typedef bg::model::box<Point> box_type;
588 typedef test_distance_of_geometries<multi_linestring_type, box_type> tester;
589
590 std::string const box_north = "BOX(10 10,20 20)";
591
592 tester::apply("sl1", "MULTILINESTRING((0 20, 15 21, 25 19.9, 21 5, 15 5, 0 10)(25 20, 22 4, 0 0))", box_north,
593 ps_distance<Point>("POINT(20 20)", "SEGMENT(15 21, 25 19.9)", strategy_ps),
594 strategy_sb, true, false, false);
595 }
596
597 //===========================================================================
598 //===========================================================================
599 //===========================================================================
600
601
602 template
603 <
604 typename Point,
605 typename Strategy_pp,
606 typename Strategy_ps,
607 typename Strategy_sb
608 >
test_all_l_ar(Strategy_pp pp_strategy,Strategy_ps ps_strategy,Strategy_sb sb_strategy)609 void test_all_l_ar(Strategy_pp pp_strategy,
610 Strategy_ps ps_strategy,
611 Strategy_sb sb_strategy)
612 {
613 test_distance_segment_polygon<Point>(pp_strategy, ps_strategy);
614 test_distance_linestring_polygon<Point>(pp_strategy, ps_strategy);
615 test_distance_multi_linestring_polygon<Point>(pp_strategy, ps_strategy);
616
617 test_distance_segment_multi_polygon<Point>(pp_strategy, ps_strategy);
618 test_distance_linestring_multi_polygon<Point>(pp_strategy, ps_strategy);
619 test_distance_multi_linestring_multi_polygon<Point>(pp_strategy, ps_strategy);
620
621 test_distance_segment_ring<Point>(ps_strategy);
622 test_distance_linestring_ring<Point>(ps_strategy);
623 test_distance_multi_linestring_ring<Point>(ps_strategy);
624
625 test_distance_segment_box<Point>(pp_strategy, ps_strategy, sb_strategy);
626 test_distance_linestring_box<Point>(ps_strategy, sb_strategy);
627 test_distance_multi_linestring_box<Point>(ps_strategy, sb_strategy);
628
629 test_more_empty_input_linear_areal<Point>(ps_strategy);
630 }
631
BOOST_AUTO_TEST_CASE(test_all_linear_areal)632 BOOST_AUTO_TEST_CASE( test_all_linear_areal )
633 {
634 typedef bg::model::point
635 <
636 double, 2,
637 bg::cs::spherical_equatorial<bg::degree>
638 > sph_point;
639
640 test_all_l_ar<sph_point>(spherical_pp(), spherical_ps(), spherical_sb());
641
642 typedef bg::model::point
643 <
644 double, 2,
645 bg::cs::geographic<bg::degree>
646 > geo_point;
647
648 test_all_l_ar<geo_point>(vincenty_pp(), vincenty_ps(), vincenty_sb());
649 test_all_l_ar<geo_point>(thomas_pp(), thomas_ps(), thomas_sb());
650 test_all_l_ar<geo_point>(andoyer_pp(), andoyer_ps(), andoyer_sb());
651 }
652