]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/test/algorithms/distance/distance_se_pl_l.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / distance / distance_se_pl_l.cpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2// Unit Test
3
4// Copyright (c) 2014-2016, Oracle and/or its affiliates.
5
6// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8
9// Licensed under the Boost Software License version 1.0.
10// http://www.boost.org/users/license.html
11
12#include <iostream>
b32b8144 13#define BOOST_GEOMETRY_TEST_DEBUG
7c673cae
FG
14
15#ifndef BOOST_TEST_MODULE
16#define BOOST_TEST_MODULE test_distance_spherical_equatorial_pl_l
17#endif
18
19#include <boost/test/included/unit_test.hpp>
20
21#include "test_distance_se_common.hpp"
22
23
24typedef bg::cs::spherical_equatorial<bg::degree> cs_type;
25typedef bg::model::point<double, 2, cs_type> point_type;
26typedef bg::model::segment<point_type> segment_type;
27typedef bg::model::multi_point<point_type> multi_point_type;
28typedef bg::model::segment<point_type> segment_type;
29typedef bg::model::linestring<point_type> linestring_type;
30typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
31
32namespace services = bg::strategy::distance::services;
33typedef bg::default_distance_result<point_type>::type return_type;
34
35typedef bg::strategy::distance::haversine<double> point_point_strategy;
36typedef bg::strategy::distance::cross_track<> point_segment_strategy;
37
38
39//===========================================================================
40
41template <typename Strategy>
42inline bg::default_distance_result<point_type>::type
43pp_distance(std::string const& wkt1,
44 std::string const& wkt2,
45 Strategy const& strategy)
46{
47 point_type p1, p2;
48 bg::read_wkt(wkt1, p1);
49 bg::read_wkt(wkt2, p2);
50 return bg::distance(p1, p2) * strategy.radius();
51}
52
53template <typename Strategy>
54inline bg::default_comparable_distance_result<point_type>::type
55pp_comparable_distance(std::string const& wkt1,
56 std::string const& wkt2,
57 Strategy const&)
58{
59 point_type p1, p2;
60 bg::read_wkt(wkt1, p1);
61 bg::read_wkt(wkt2, p2);
62 return bg::comparable_distance(p1, p2);
63}
64
65template <typename Strategy>
66inline bg::default_distance_result<point_type>::type
67ps_distance(std::string const& wkt1,
68 std::string const& wkt2,
69 Strategy const& strategy)
70{
71 point_type p;
72 segment_type s;
73 bg::read_wkt(wkt1, p);
74 bg::read_wkt(wkt2, s);
75 return bg::distance(p, s, strategy);
76}
77
78template <typename Strategy>
79inline bg::default_comparable_distance_result<point_type>::type
80ps_comparable_distance(std::string const& wkt1,
81 std::string const& wkt2,
82 Strategy const& strategy)
83{
84 point_type p;
85 segment_type s;
86 bg::read_wkt(wkt1, p);
87 bg::read_wkt(wkt2, s);
88 return bg::comparable_distance(p, s, strategy);
89}
90
91template <typename Strategy, typename T>
92T to_comparable(Strategy const& strategy, T const& distance)
93{
94 namespace services = bg::strategy::distance::services;
95
96 typedef typename services::comparable_type
97 <
98 Strategy
99 >::type comparable_strategy;
100
101 typedef typename services::result_from_distance
102 <
103 comparable_strategy,
104 point_type,
105 bg::point_type<segment_type>::type
106 > get_comparable_distance;
107
108 comparable_strategy cstrategy = services::get_comparable
109 <
110 Strategy
111 >::apply(strategy);
112
113 return get_comparable_distance::apply(cstrategy, distance);
114}
115
116//===========================================================================
117
118template <typename Strategy>
119void test_distance_point_segment(Strategy const& strategy)
120{
121#ifdef BOOST_GEOMETRY_TEST_DEBUG
122 std::cout << std::endl;
123 std::cout << "point/segment distance tests" << std::endl;
124#endif
125 typedef test_distance_of_geometries<point_type, segment_type> tester;
126
127 double const d2r = bg::math::d2r<double>();
128
129 tester::apply("p-s-01",
130 "POINT(0 0)",
131 "SEGMENT(2 0,3 0)",
132 2.0 * d2r * strategy.radius(),
133 to_comparable(strategy, 2.0 * d2r * strategy.radius()),
134 strategy);
135 tester::apply("p-s-02",
136 "POINT(2.5 3)",
137 "SEGMENT(2 0,3 0)",
138 3.0 * d2r * strategy.radius(),
139 to_comparable(strategy, 3.0 * d2r * strategy.radius()),
140 strategy);
141 tester::apply("p-s-03",
142 "POINT(2 0)",
143 "SEGMENT(2 0,3 0)",
144 0,
145 strategy);
146 tester::apply("p-s-04",
147 "POINT(3 0)",
148 "SEGMENT(2 0,3 0)",
149 0,
150 strategy);
151 tester::apply("p-s-05",
152 "POINT(2.5 0)",
153 "SEGMENT(2 0,3 0)",
154 0,
155 strategy);
156 tester::apply("p-s-06",
157 "POINT(3.5 3)",
158 "SEGMENT(2 0,3 0)",
159 pp_distance("POINT(3 0)", "POINT(3.5 3)", strategy),
160 pp_comparable_distance("POINT(3 0)",
161 "POINT(3.5 3)",
162 strategy),
163 strategy);
b32b8144
FG
164 tester::apply("p-s-07",
165 "POINT(0 0)",
166 "SEGMENT(0 10,10 10)",
167 ps_distance("POINT(0 0)", "SEGMENT(10 10,0 10)", strategy),
168 pp_comparable_distance("POINT(0 0)",
169 "POINT(0 10)",
170 strategy),
171 strategy);
7c673cae
FG
172 // very small distances to segment
173 tester::apply("p-s-07",
174 "POINT(90 1e-3)",
175 "SEGMENT(0.5 0,175.5 0)",
176 1e-3 * d2r * strategy.radius(),
177 to_comparable(strategy, 1e-3 * d2r * strategy.radius()),
178 strategy);
179 tester::apply("p-s-08",
180 "POINT(90 1e-4)",
181 "SEGMENT(0.5 0,175.5 0)",
182 1e-4 * d2r * strategy.radius(),
183 to_comparable(strategy, 1e-4 * d2r * strategy.radius()),
184 strategy);
185 tester::apply("p-s-09",
186 "POINT(90 1e-5)",
187 "SEGMENT(0.5 0,175.5 0)",
188 1e-5 * d2r * strategy.radius(),
189 to_comparable(strategy, 1e-5 * d2r * strategy.radius()),
190 strategy);
191 tester::apply("p-s-10",
192 "POINT(90 1e-6)",
193 "SEGMENT(0.5 0,175.5 0)",
194 1e-6 * d2r * strategy.radius(),
195 to_comparable(strategy, 1e-6 * d2r * strategy.radius()),
196 strategy);
197 tester::apply("p-s-11",
198 "POINT(90 1e-7)",
199 "SEGMENT(0.5 0,175.5 0)",
200 1e-7 * d2r * strategy.radius(),
201 to_comparable(strategy, 1e-7 * d2r * strategy.radius()),
202 strategy);
203 tester::apply("p-s-12",
204 "POINT(90 1e-8)",
205 "SEGMENT(0.5 0,175.5 0)",
206 1e-8 * d2r * strategy.radius(),
207 to_comparable(strategy, 1e-8 * d2r * strategy.radius()),
208 strategy);
209}
210
211//===========================================================================
212
213template <typename Strategy>
214void test_distance_point_linestring(Strategy const& strategy)
215{
216#ifdef BOOST_GEOMETRY_TEST_DEBUG
217 std::cout << std::endl;
218 std::cout << "point/linestring distance tests" << std::endl;
219#endif
220 typedef test_distance_of_geometries<point_type, linestring_type> tester;
221
222 double const r = strategy.radius();
223 double const d2r = bg::math::d2r<double>();
224
225 tester::apply("p-l-01",
226 "POINT(0 0)",
227 "LINESTRING(2 0,2 0)",
228 2.0 * d2r * r,
229 to_comparable(strategy, 2.0 * d2r * r),
230 strategy);
231 tester::apply("p-l-02",
232 "POINT(0 0)",
233 "LINESTRING(2 0,3 0)",
234 2.0 * d2r * r,
235 to_comparable(strategy, 2.0 * d2r * r),
236 strategy);
237 tester::apply("p-l-03",
238 "POINT(2.5 3)",
239 "LINESTRING(2 0,3 0)",
240 3.0 * d2r * r,
241 to_comparable(strategy, 3.0 * d2r * r),
242 strategy);
243 tester::apply("p-l-04",
244 "POINT(2 0)",
245 "LINESTRING(2 0,3 0)",
246 0,
247 strategy);
248 tester::apply("p-l-05",
249 "POINT(3 0)",
250 "LINESTRING(2 0,3 0)",
251 0,
252 strategy);
253 tester::apply("p-l-06",
254 "POINT(2.5 0)",
255 "LINESTRING(2 0,3 0)",
256 0,
257 strategy);
258 tester::apply("p-l-07",
259 "POINT(7.5 10)",
260 "LINESTRING(1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 0)",
261 10.0 * d2r * r,
262 to_comparable(strategy, 10.0 * d2r * r),
263 strategy);
264 tester::apply("p-l-08",
265 "POINT(7.5 10)",
266 "LINESTRING(1 1,2 1,3 1,4 1,5 1,6 1,7 1,20 2,21 2)",
267 ps_distance("POINT(7.5 10)", "SEGMENT(7 1,20 2)", strategy),
268 ps_comparable_distance("POINT(7.5 10)",
269 "SEGMENT(7 1,20 2)",
270 strategy),
271 strategy);
272
273 // https://svn.boost.org/trac/boost/ticket/11982
274 tester::apply("p-l-09",
275 "POINT(10.4 63.43)",
276 "LINESTRING(10.733557 59.911923, 10.521812 59.887214)",
277 0.06146397739758279 * r,
278 0.000944156107132969,
279 strategy);
280}
281
282//===========================================================================
283
284template <typename Strategy>
285void test_distance_point_multilinestring(Strategy const& strategy)
286{
287#ifdef BOOST_GEOMETRY_TEST_DEBUG
288 std::cout << std::endl;
289 std::cout << "point/multilinestring distance tests" << std::endl;
290#endif
291 typedef test_distance_of_geometries
292 <
293 point_type, multi_linestring_type
294 > tester;
295
296 double const d2r = bg::math::d2r<double>();
297
298 tester::apply("p-ml-01",
299 "POINT(0 0)",
300 "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
301 2.0 * d2r * strategy.radius(),
302 to_comparable(strategy, 2.0 * d2r * strategy.radius()),
303 strategy);
304 tester::apply("p-ml-02",
305 "POINT(2.5 3)",
306 "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
307 3.0 * d2r * strategy.radius(),
308 to_comparable(strategy, 3.0 * d2r * strategy.radius()),
309 strategy);
310 tester::apply("p-ml-03",
311 "POINT(2 0)",
312 "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
313 0,
314 strategy);
315 tester::apply("p-ml-04",
316 "POINT(3 0)",
317 "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
318 0,
319 strategy);
320 tester::apply("p-ml-05",
321 "POINT(2.5 0)",
322 "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
323 0,
324 strategy);
325 tester::apply("p-ml-06",
326 "POINT(7.5 10)",
327 "MULTILINESTRING((-5 0,-3 0),(2 0,3 0,4 0,5 0,6 0,20 1,21 1))",
328 ps_distance("POINT(7.5 10)", "SEGMENT(6 0,20 1)", strategy),
329 ps_comparable_distance("POINT(7.5 10)",
330 "SEGMENT(6 0,20 1)",
331 strategy),
332 strategy);
333 tester::apply("p-ml-07",
334 "POINT(-8 10)",
335 "MULTILINESTRING((-20 10,-19 11,-18 10,-6 0,-5 0,-3 0),(2 0,6 0,20 1,21 1))",
336 ps_distance("POINT(-8 10)", "SEGMENT(-6 0,-18 10)", strategy),
337 ps_comparable_distance("POINT(-8 10)",
338 "SEGMENT(-6 0,-18 10)",
339 strategy),
340 strategy);
341}
342
343//===========================================================================
344
345template <typename Strategy>
346void test_distance_linestring_multipoint(Strategy const& strategy)
347{
348#ifdef BOOST_GEOMETRY_TEST_DEBUG
349 std::cout << std::endl;
350 std::cout << "linestring/multipoint distance tests" << std::endl;
351#endif
352 typedef test_distance_of_geometries
353 <
354 linestring_type, multi_point_type
355 > tester;
356
357 tester::apply("l-mp-01",
358 "LINESTRING(2 0,0 2,100 80)",
359 "MULTIPOINT(0 0,1 0,0 1,1 1)",
360 ps_distance("POINT(1 1)", "SEGMENT(2 0,0 2)", strategy),
361 ps_comparable_distance("POINT(1 1)",
362 "SEGMENT(2 0,0 2)",
363 strategy),
364 strategy);
365 tester::apply("l-mp-02",
366 "LINESTRING(4 0,0 4,100 80)",
367 "MULTIPOINT(0 0,1 0,0 1,1 1)",
368 ps_distance("POINT(1 1)", "SEGMENT(0 4,4 0)", strategy),
369 ps_comparable_distance("POINT(1 1)",
370 "SEGMENT(0 4,4 0)",
371 strategy),
372 strategy);
373 tester::apply("l-mp-03",
374 "LINESTRING(1 1,2 2,100 80)",
375 "MULTIPOINT(0 0,1 0,0 1,1 1)",
376 0,
377 strategy);
378 tester::apply("l-mp-04",
379 "LINESTRING(3 3,4 4,100 80)",
380 "MULTIPOINT(0 0,1 0,0 1,1 1)",
381 pp_distance("POINT(1 1)", "POINT(3 3)", strategy),
382 pp_comparable_distance("POINT(1 1)", "POINT(3 3)", strategy),
383 strategy);
384 tester::apply("l-mp-05",
385 "LINESTRING(0 0,10 0,10 10,0 10,0 0)",
386 "MULTIPOINT(1 -1,80 80,5 0,150 90)",
387 0,
388 strategy);
389}
390
391//===========================================================================
392
393template <typename Strategy>
394void test_distance_multipoint_multilinestring(Strategy const& strategy)
395{
396#ifdef BOOST_GEOMETRY_TEST_DEBUG
397 std::cout << std::endl;
398 std::cout << "multipoint/multilinestring distance tests" << std::endl;
399#endif
400 typedef test_distance_of_geometries
401 <
402 multi_point_type, multi_linestring_type
403 > tester;
404
405 tester::apply("mp-ml-01",
406 "MULTIPOINT(0 0,1 0,0 1,1 1)",
407 "MULTILINESTRING((2 0,0 2),(2 2,3 3))",
408 ps_distance("POINT(1 1)", "SEGMENT(2 0,0 2)", strategy),
409 ps_comparable_distance("POINT(1 1)",
410 "SEGMENT(2 0,0 2)",
411 strategy),
412 strategy);
413 tester::apply("mp-ml-02",
414 "MULTIPOINT(0 0,1 0,0 1,1 1)",
415 "MULTILINESTRING((3 0,0 3),(4 4,5 5))",
416 ps_distance("POINT(1 1)", "SEGMENT(3 0,0 3)", strategy),
417 ps_comparable_distance("POINT(1 1)",
418 "SEGMENT(3 0,0 3)",
419 strategy),
420 strategy);
421 tester::apply("mp-ml-03",
422 "MULTIPOINT(0 0,1 0,0 1,1 1)",
423 "MULTILINESTRING((4 4,5 5),(1 1,2 2))",
424 0,
425 strategy);
426 tester::apply("mp-ml-04",
427 "MULTIPOINT(0 0,1 0,0 1,1 1)",
428 "MULTILINESTRING((4 4,3 3),(4 4,5 5))",
429 pp_distance("POINT(1 1)", "POINT(3 3)", strategy),
430 pp_comparable_distance("POINT(1 1)", "POINT(3 3)", strategy),
431 strategy);
432}
433
434//===========================================================================
435
436template <typename Strategy>
437void test_distance_multipoint_segment(Strategy const& strategy)
438{
439#ifdef BOOST_GEOMETRY_TEST_DEBUG
440 std::cout << std::endl;
441 std::cout << "multipoint/segment distance tests" << std::endl;
442#endif
443 typedef test_distance_of_geometries<multi_point_type, segment_type> tester;
444
445 double d2r = bg::math::d2r<double>();
446
447 tester::apply("mp-s-01",
448 "MULTIPOINT(0 0,1 0,0 1,1 1)",
449 "SEGMENT(2 0,0 2)",
450 ps_distance("POINT(1 1)", "SEGMENT(2 0,0 2)", strategy),
451 ps_comparable_distance("POINT(1 1)",
452 "SEGMENT(2 0,0 2)",
453 strategy),
454 strategy);
455 tester::apply("mp-s-02",
456 "MULTIPOINT(0 0,1 0,0 1,1 1)",
457 "SEGMENT(0 -3,1 -10)",
458 3.0 * d2r * strategy.radius(),
459 to_comparable(strategy, 3.0 * d2r * strategy.radius()),
460 strategy);
461 tester::apply("mp-s-03",
462 "MULTIPOINT(0 0,1 0,0 1,1 1)",
463 "SEGMENT(1 1,2 2)",
464 0,
465 strategy);
466 tester::apply("mp-s-04",
467 "MULTIPOINT(0 0,1 0,0 1,1 1)",
468 "SEGMENT(3 3,4 4)",
469 pp_distance("POINT(1 1)", "POINT(3 3)", strategy),
470 pp_comparable_distance("POINT(1 1)", "POINT(3 3)", strategy),
471 strategy);
472 tester::apply("mp-s-05",
473 "MULTIPOINT(0 0,1 0,0 1,1 1)",
474 "SEGMENT(0.5 -3,1 -10)",
475 pp_distance("POINT(1 0)", "POINT(0.5 -3)", strategy),
476 pp_comparable_distance("POINT(1 0)",
477 "POINT(0.5 -3)",
478 strategy),
479 strategy);
480}
481
482//===========================================================================
483
484template <typename Point, typename Strategy>
485void test_more_empty_input_pointlike_linear(Strategy const& strategy)
486{
487#ifdef BOOST_GEOMETRY_TEST_DEBUG
488 std::cout << std::endl;
489 std::cout << "testing on empty inputs... " << std::flush;
490#endif
491 bg::model::linestring<Point> line_empty;
492 bg::model::multi_point<Point> multipoint_empty;
493 bg::model::multi_linestring<bg::model::linestring<Point> > multiline_empty;
494
495 Point point = from_wkt<Point>("POINT(0 0)");
496 bg::model::linestring<Point> line =
497 from_wkt<bg::model::linestring<Point> >("LINESTRING(0 0,1 1)");
498
499 // 1st geometry is empty
500 test_empty_input(multipoint_empty, line, strategy);
501
502 // 2nd geometry is empty
503 test_empty_input(point, line_empty, strategy);
504 test_empty_input(point, multiline_empty, strategy);
505
506 // both geometries are empty
507 test_empty_input(multipoint_empty, line_empty, strategy);
508 test_empty_input(multipoint_empty, multiline_empty, strategy);
509
510#ifdef BOOST_GEOMETRY_TEST_DEBUG
511 std::cout << "done!" << std::endl;
512#endif
513}
514
515
516//===========================================================================
517//===========================================================================
518//===========================================================================
519
520BOOST_AUTO_TEST_CASE( test_all_point_segment )
521{
522 test_distance_point_segment(point_segment_strategy());
523 test_distance_point_segment(point_segment_strategy(earth_radius_km));
524 test_distance_point_segment(point_segment_strategy(earth_radius_miles));
525}
526
527BOOST_AUTO_TEST_CASE( test_all_point_linestring )
528{
529 test_distance_point_linestring(point_segment_strategy());
530 test_distance_point_linestring(point_segment_strategy(earth_radius_km));
531 test_distance_point_linestring(point_segment_strategy(earth_radius_miles));
532}
533
534BOOST_AUTO_TEST_CASE( test_all_point_multilinestring )
535{
536 test_distance_point_multilinestring(point_segment_strategy());
537 test_distance_point_multilinestring(point_segment_strategy(earth_radius_km));
538 test_distance_point_multilinestring(point_segment_strategy(earth_radius_miles));
539}
540
541BOOST_AUTO_TEST_CASE( test_all_linestring_multipoint )
542{
543 test_distance_linestring_multipoint(point_segment_strategy());
544 test_distance_linestring_multipoint(point_segment_strategy(earth_radius_km));
545 test_distance_linestring_multipoint(point_segment_strategy(earth_radius_miles));
546}
547
548BOOST_AUTO_TEST_CASE( test_all_multipoint_multilinestring )
549{
550 test_distance_multipoint_multilinestring(point_segment_strategy());
551 test_distance_multipoint_multilinestring(point_segment_strategy(earth_radius_km));
552 test_distance_multipoint_multilinestring(point_segment_strategy(earth_radius_miles));
553}
554
555BOOST_AUTO_TEST_CASE( test_all_multipoint_segment )
556{
557 test_distance_multipoint_segment(point_segment_strategy());
558 test_distance_multipoint_segment(point_segment_strategy(earth_radius_km));
559 test_distance_multipoint_segment(point_segment_strategy(earth_radius_miles));
560}
561
562BOOST_AUTO_TEST_CASE( test_all_empty_input_pointlike_linear )
563{
564 test_more_empty_input_pointlike_linear
565 <
566 point_type
567 >(point_segment_strategy());
568
569 test_more_empty_input_pointlike_linear
570 <
571 point_type
572 >(point_segment_strategy(earth_radius_km));
573
574 test_more_empty_input_pointlike_linear
575 <
576 point_type
577 >(point_segment_strategy(earth_radius_miles));
578}