]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/test/algorithms/distance/distance_geo_point_box.cpp
Add patch for failing prerm scripts
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / distance / distance_geo_point_box.cpp
CommitLineData
11fdf7f2
TL
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2// Unit Test
3
4// Copyright (c) 2017, 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_point_box
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
26typedef bg::cs::geographic<bg::degree> cs_type;
27typedef bg::model::point<double, 2, cs_type> point_type;
28typedef bg::model::multi_point<point_type> multi_point_type;
29typedef bg::model::segment<point_type> segment_type;
30typedef bg::model::box<point_type> box_type;
31
32namespace services = bg::strategy::distance::services;
33typedef bg::default_distance_result<point_type>::type return_type;
34
35typedef bg::srs::spheroid<double> stype;
36
37// Strategies for point-point distance
38
39typedef bg::strategy::distance::andoyer<stype> andoyer_pp;
40typedef bg::strategy::distance::thomas<stype> thomas_pp;
41typedef bg::strategy::distance::vincenty<stype> vincenty_pp;
42
43// Strategies for point-segment distance
44
45typedef bg::strategy::distance::geographic_cross_track<bg::strategy::andoyer, stype, double>
46 andoyer_ps;
47
48typedef bg::strategy::distance::geographic_cross_track<bg::strategy::thomas, stype, double>
49 thomas_ps;
50
51typedef bg::strategy::distance::geographic_cross_track<bg::strategy::vincenty, stype, double>
52 vincenty_ps;
53
54// Strategies for point-box distance
55
56typedef bg::strategy::distance::geographic_cross_track_point_box
57 <
58 bg::strategy::andoyer,
59 bg::srs::spheroid<double>,
60 double
61 > andoyer_pb;
62
63typedef bg::strategy::distance::geographic_cross_track_point_box
64 <
65 bg::strategy::thomas,
66 bg::srs::spheroid<double>,
67 double
68 > thomas_pb;
69
70typedef bg::strategy::distance::geographic_cross_track_point_box
71 <
72 bg::strategy::vincenty,
73 bg::srs::spheroid<double>,
74 double
75 > vincenty_pb;
76
77//===========================================================================
78
79template <typename Strategy>
80inline bg::default_distance_result<point_type>::type
81pp_distance(std::string const& wkt1,
82 std::string const& wkt2,
83 Strategy const& strategy)
84{
85 point_type p1, p2;
86 bg::read_wkt(wkt1, p1);
87 bg::read_wkt(wkt2, p2);
88 return bg::distance(p1, p2, strategy);
89}
90
91template <typename Strategy>
92inline bg::default_distance_result<point_type>::type
93ps_distance(std::string const& wkt1,
94 std::string const& wkt2,
95 Strategy const& strategy)
96{
97 point_type p;
98 segment_type s;
99 bg::read_wkt(wkt1, p);
100 bg::read_wkt(wkt2, s);
101 return bg::distance(p, s, strategy);
102}
103
104//===========================================================================
105// Cases for relative location of a point wrt to a box
106//
107// | |
108// | 3 |
109// | |
110// +---------+
111// | |
112// 1 | 5 | 2
113// | |
114// +---------+
115// | |
116// | 4 |
117// | |
118//
119// and also the following cases
120//
121// | |
122// A B
123// | |
124// +----C----+
125// | |
126// D E
127// | |
128// +----F----+
129// | |
130// G H
131// | |
132//
133// and finally we have the corners
134//
135// | |
136// | |
137// | |
138// a---------b
139// | |
140// | |
141// | |
142// c---------d
143// | |
144// | |
145// | |
146//
147// for each relative position we also have to test the shifted point
148// (this is due to the fact that boxes have longitudes in the
149// range [-180, 540)
150//===========================================================================
151
152template <typename Strategy_pp, typename Strategy_ps, typename Strategy_pb>
153void test_distance_point_box(Strategy_pp const& strategy_pp,
154 Strategy_ps const& strategy_ps,
155 Strategy_pb const& strategy_pb)
156{
157
158#ifdef BOOST_GEOMETRY_TEST_DEBUG
159 std::cout << std::endl;
160 std::cout << "point/box distance tests" << std::endl;
161#endif
162 typedef test_distance_of_geometries<point_type, box_type> tester;
163
164 std::string const box1 = "BOX(10 10,20 20)";
165
166 // case 1
167 tester::apply("pb1-1a", "POINT(5 25)", box1,
168 pp_distance("POINT(5 25)", "POINT(10 20)", strategy_pp),
169 strategy_pb);
170
171 // case 1
172 tester::apply("pb1-1b", "POINT(3 12)", box1,
173 ps_distance("POINT(3 12)", "SEGMENT(10 10,10 20)", strategy_ps),
174 strategy_pb);
175
176 // case 1
177 tester::apply("pb1-1c", "POINT(3 17)", box1,
178 ps_distance("POINT(3 17)", "SEGMENT(10 10,10 20)", strategy_ps),
179 strategy_pb);
180
181 // case 1
182 tester::apply("pb1-1d", "POINT(5 4)", box1,
183 pp_distance("POINT(5 4)", "POINT(10 10)", strategy_pp),
184 strategy_pb);
185
186 // case 1
187 tester::apply("pb1-1e", "POINT(-100 20)", box1,
188 pp_distance("POINT(-100 20)", "POINT(10 20)", strategy_pp),
189 strategy_pb);
190
191 // case 1
192 tester::apply("pb1-1g", "POINT(-100 10)", box1,
193 ps_distance("POINT(-100 10)", "SEGMENT(10 10,10 20)", strategy_ps),
194 strategy_pb);
195
196 // case 2
197 tester::apply("pb1-2a", "POINT(31 25)", box1,
198 pp_distance("POINT(31 25)", "POINT(20 20)", strategy_pp),
199 strategy_pb);
200
201 // case 2
202 tester::apply("pb1-2b", "POINT(23 17)", box1,
203 ps_distance("POINT(23 17)", "SEGMENT(20 10,20 20)", strategy_ps),
204 strategy_pb);
205
206 // case 2
207 tester::apply("pb1-2c", "POINT(29 3)", box1,
208 pp_distance("POINT(29 3)", "POINT(20 10)", strategy_pp),
209 strategy_pb);
210
211 // case 2
212 tester::apply("pb1-2d", "POINT(131 65)", box1,
213 pp_distance("POINT(131 65)", "POINT(20 20)", strategy_pp),
214 strategy_pb);
215
216 // case 2
217 tester::apply("pb1-2e", "POINT(110 10)", box1,
218 ps_distance("POINT(110 10)", "SEGMENT(20 10,20 20)", strategy_ps),
219 strategy_pb);
220
221 // case 2
222 tester::apply("pb1-2f", "POINT(150 20)", box1,
223 pp_distance("POINT(150 20)", "POINT(20 20)", strategy_pp),
224 strategy_pb);
225
226 // case 3
227 tester::apply("pb1-3a", "POINT(11 25)", box1,
228 pp_distance("POINT(11 25)", "POINT(11 20)", strategy_pp),
229 strategy_pb);
230
231 // case 3
232 tester::apply("pb1-3b", "POINT(15 25)", box1,
233 pp_distance("POINT(15 25)", "POINT(15 20)", strategy_pp),
234 strategy_pb);
235
236 // case 3
237 tester::apply("pb1-3c", "POINT(18 25)", box1,
238 pp_distance("POINT(18 25)", "POINT(18 20)", strategy_pp),
239 strategy_pb);
240
241 // case 4
242 tester::apply("pb1-4a", "POINT(13 4)", box1,
243 pp_distance("POINT(13 4)", "POINT(13 10)", strategy_pp),
244 strategy_pb);
245
246 // case 4
247 tester::apply("pb1-4b", "POINT(19 4)", box1,
248 pp_distance("POINT(19 4)", "POINT(19 10)", strategy_pp),
249 strategy_pb);
250
251 // case 5
252 tester::apply("pb1-5", "POINT(15 14)", box1, 0, strategy_pb);
253
254 // case A
255 tester::apply("pb1-A", "POINT(10 28)", box1,
256 pp_distance("POINT(10 28)", "POINT(10 20)", strategy_pp),
257 strategy_pb);
258
259 // case B
260 tester::apply("pb1-B", "POINT(20 28)", box1,
261 pp_distance("POINT(20 28)", "POINT(20 20)", strategy_pp),
262 strategy_pb);
263
264
265 // case C
266 tester::apply("pb1-C", "POINT(14 20)", box1, 0, strategy_pb);
267
268 // case D
269 tester::apply("pb1-D", "POINT(10 17)", box1, 0, strategy_pb);
270
271 // case E
272 tester::apply("pb1-E", "POINT(20 11)", box1, 0, strategy_pb);
273
274 // case F
275 tester::apply("pb1-F", "POINT(19 10)", box1, 0, strategy_pb);
276
277 // case G
278 tester::apply("pb1-G", "POINT(10 -40)", box1,
279 pp_distance("POINT(10 -40)", "POINT(10 10)", strategy_pp),
280 strategy_pb);
281
282 // case H
283 tester::apply("pb1-H", "POINT(20 -50)", box1,
284 pp_distance("POINT(20 -50)", "POINT(20 10)", strategy_pp),
285 strategy_pb);
286
287 // case a
288 tester::apply("pb1-a", "POINT(10 20)", box1, 0, strategy_pb);
289 // case b
290 tester::apply("pb1-b", "POINT(20 20)", box1, 0, strategy_pb);
291 // case c
292 tester::apply("pb1-c", "POINT(10 10)", box1, 0, strategy_pb);
293 // case d
294 tester::apply("pb1-d", "POINT(20 10)", box1, 0, strategy_pb);
295
296
297 std::string const box2 = "BOX(170 -60,400 80)";
298
299 // case 1 - point is closer to western meridian
300 tester::apply("pb2-1a", "POINT(160 0)", box2,
301 ps_distance("POINT(160 0)", "SEGMENT(170 -60,170 80)", strategy_ps),
302 strategy_pb);
303
304 // case 1 - point is closer to eastern meridian
305 tester::apply("pb2-1b", "POINT(50 0)", box2,
306 ps_distance("POINT(50 0)", "SEGMENT(40 -60,40 80)", strategy_ps),
307 strategy_pb);
308
309 // case 3 - equivalent point POINT(390 85) is above the box
310 tester::apply("pb2-3", "POINT(30 85)", box2,
311 pp_distance("POINT(30 85)", "POINT(30 80)", strategy_pp),
312 strategy_pb);
313
314 // case 4 - equivalent point POINT(390 -75) is below the box
315 tester::apply("pb2-4", "POINT(30 -75)", box2,
316 pp_distance("POINT(30 -75)", "POINT(30 -60)", strategy_pp),
317 strategy_pb);
318
319 // case 5 - equivalent point POINT(390 0) is inside box
320 tester::apply("pb2-5", "POINT(30 0)", box2, 0, strategy_pb);
321
322
323 std::string const box3 = "BOX(-150 -50,-40 70)";
324
325 // case 1 - point is closer to western meridian
326 tester::apply("pb3-1a", "POINT(-170 10)", box3,
327 ps_distance("POINT(-170 10)", "SEGMENT(-150 -50,-150 70)", strategy_ps),
328 strategy_pb);
329
330 // case 2 - point is closer to eastern meridian
331 tester::apply("pb3-2a", "POINT(5 10)", box3,
332 ps_distance("POINT(5 10)", "SEGMENT(-40 -50,-40 70)", strategy_ps),
333 strategy_pb);
334
335 // case 2 - point is closer to western meridian
336 tester::apply("pb3-2a", "POINT(160 10)", box3,
337 ps_distance("POINT(160 10)", "SEGMENT(-150 -50,-150 70)", strategy_ps),
338 strategy_pb);
339
340 // case 2 - point is at equal distance from eastern and western meridian
341 tester::apply("pb3-2c1", "POINT(85 20)", box3,
342 ps_distance("POINT(85 20)", "SEGMENT(-150 -50,-150 70)", strategy_ps),
343 strategy_pb);
344
345 // case 2 - point is at equal distance from eastern and western meridian
346 tester::apply("pb3-2c2", "POINT(85 20)", box3,
347 ps_distance("POINT(85 20)", "SEGMENT(-40 -50,-40 70)", strategy_ps),
348 strategy_pb);
349
350 // box that is symmetric wrt the prime meridian
351 std::string const box4 = "BOX(-75 -45,75 65)";
352
353 // case 1 - point is closer to western meridian
354 tester::apply("pb4-1a", "POINT(-100 10)", box4,
355 ps_distance("POINT(-100 10)", "SEGMENT(-75 -45,-75 65)", strategy_ps),
356 strategy_pb);
357
358 // case 2 - point is closer to eastern meridian
359 tester::apply("pb4-2a", "POINT(90 15)", box4,
360 ps_distance("POINT(90 15)", "SEGMENT(75 -45,75 65)", strategy_ps),
361 strategy_pb);
362
363 // case 2 - point is at equal distance from eastern and western meridian
364 tester::apply("pb4-2c1", "POINT(-180 20)", box4,
365 ps_distance("POINT(-180 20)", "SEGMENT(-75 -45,-75 65)", strategy_ps),
366 strategy_pb);
367
368 // case 2 - point is at equal distance from eastern and western meridian
369 tester::apply("pb4-2c2", "POINT(-180 20)", box4,
370 ps_distance("POINT(-180 20)", "SEGMENT(75 -45,75 65)", strategy_ps),
371 strategy_pb);
372}
373
374template <typename Strategy_pp, typename Strategy_ps, typename Strategy_pb>
375void test_distance_point_deg_box(Strategy_pp const& strategy_pp,
376 Strategy_ps const& strategy_ps,
377 Strategy_pb const& strategy_pb)
378{
379
380#ifdef BOOST_GEOMETRY_TEST_DEBUG
381 std::cout << std::endl;
382 std::cout << "point/box distance tests" << std::endl;
383#endif
384 typedef test_distance_of_geometries<point_type, box_type> tester;
385
386 //box degenerates to a meridian segment
387 std::string const box1 = "BOX(0 10,0 20)";
388
389 tester::apply("pbd1", "POINT(1 10)", box1,
390 ps_distance("POINT(1 10)", "SEGMENT(0 10, 0 20)", strategy_ps),
391 strategy_pb);
392 tester::apply("pbd2", "POINT(1 5)", box1,
393 ps_distance("POINT(1 5)", "SEGMENT(0 10, 0 20)", strategy_ps),
394 strategy_pb);
395 tester::apply("pbd3", "POINT(1 15)", box1,
396 ps_distance("POINT(1 15)", "SEGMENT(0 10, 0 20)", strategy_ps),
397 strategy_pb);
398 tester::apply("pbd4", "POINT(1 25)", box1,
399 ps_distance("POINT(1 25)", "SEGMENT(0 10, 0 20)", strategy_ps),
400 strategy_pb);
401
402 //box degenerates to a horizontal line; that is not a geodesic segment
403 std::string const box2 = "BOX(10 10,20 10)";
404
405 tester::apply("pbd5", "POINT(15 15)", box2,
406 pp_distance("POINT(15 15)", "POINT(15 10)", strategy_pp),
407 strategy_pb);
408 tester::apply("pbd6", "POINT(5 15)", box2,
409 pp_distance("POINT(5 15)", "POINT(10 10)", strategy_pp),
410 strategy_pb);
411 tester::apply("pbd7", "POINT(25 15)", box2,
412 pp_distance("POINT(25 15)", "POINT(20 10)", strategy_pp),
413 strategy_pb);
414
415 //box degenerates to a point
416 std::string const box3 = "BOX(0 10,0 10)";
417
418 tester::apply("pbd8", "POINT(1 11)", box3,
419 pp_distance("POINT(1 11)", "POINT(0 10)", strategy_pp),
420 strategy_pb);
421}
422
423template <typename Strategy_pp, typename Strategy_ps, typename Strategy_pb>
424void test_distance_multipoint_box(Strategy_pp const& strategy_pp,
425 Strategy_ps const& strategy_ps,
426 Strategy_pb const& strategy_pb)
427{
428
429#ifdef BOOST_GEOMETRY_TEST_DEBUG
430 std::cout << std::endl;
431 std::cout << "multipoint/box distance tests" << std::endl;
432#endif
433 typedef test_distance_of_geometries<multi_point_type, box_type> tester;
434
435 std::string const box1 = "BOX(10 10,20 20)";
436
437 tester::apply("mpb1-1a", "MULTIPOINT(5 25,25 26)", box1,
438 pp_distance("POINT(5 25)", "POINT(10 20)", strategy_pp),
439 strategy_pb);
440
441 tester::apply("mpb1-2e", "MULTIPOINT(110 10,110 9,110 0)", box1,
442 ps_distance("POINT(110 10)", "SEGMENT(20 10,20 20)", strategy_ps),
443 strategy_pb);
444}
445
446//===========================================================================
447//===========================================================================
448//===========================================================================
449
450BOOST_AUTO_TEST_CASE( test_all_point_segment )
451{
452 test_distance_point_box(vincenty_pp(), vincenty_ps(), vincenty_pb());
453 test_distance_point_box(thomas_pp(), thomas_ps(), thomas_pb());
454 test_distance_point_box(andoyer_pp(), andoyer_ps(), andoyer_pb());
455
456 test_distance_point_deg_box(vincenty_pp(), vincenty_ps(), vincenty_pb());
457 test_distance_point_deg_box(thomas_pp(), thomas_ps(), thomas_pb());
458 test_distance_point_deg_box(andoyer_pp(), andoyer_ps(), andoyer_pb());
459
460 test_distance_multipoint_box(vincenty_pp(), vincenty_ps(), vincenty_pb());
461 test_distance_multipoint_box(thomas_pp(), thomas_ps(), thomas_pb());
462 test_distance_multipoint_box(andoyer_pp(), andoyer_ps(), andoyer_pb());
463}