]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/strategies/distance.cpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / libs / geometry / test / strategies / distance.cpp
1 // Boost.Geometry
2
3 // Copyright (c) 2017-2021 Oracle and/or its affiliates.
4 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 #include <geometry_test_common.hpp>
12
13 #include <boost/concept_check.hpp>
14
15 #include <boost/geometry/srs/srs.hpp>
16 #include <boost/geometry/algorithms/assign.hpp>
17 #include <boost/geometry/geometries/point.hpp>
18 #include <boost/geometry/strategies/strategies.hpp>
19
20 #include <test_common/test_point.hpp>
21
22 typedef bg::srs::spheroid<double> stype;
23
24 typedef bg::strategy::andoyer andoyer_formula;
25 typedef bg::strategy::thomas thomas_formula;
26 typedef bg::strategy::vincenty vincenty_formula;
27
28 template <typename P>
29 bool non_precise_ct()
30 {
31 using ct = typename bg::coordinate_type<P>::type;
32 return std::is_integral<ct>::value || std::is_floating_point<ct>::value;
33 }
34
35 template <typename P1, typename P2, typename FormulaPolicy>
36 void test_distance(double lon1, double lat1, double lon2, double lat2)
37 {
38 typedef typename bg::promote_floating_point
39 <
40 typename bg::select_calculation_type<P1, P2, void>::type
41 >::type calc_t;
42
43 calc_t tolerance = non_precise_ct<P1>() || non_precise_ct<P2>() ?
44 5.0 : 0.001;
45
46 P1 p1;
47 P2 p2;
48
49 bg::assign_values(p1, lon1, lat1);
50 bg::assign_values(p2, lon2, lat2);
51
52 // Test strategy that implements meridian distance against formula
53 // that implements general distance
54 // That may change in the future but in any case these calls must return
55 // the same result
56
57 calc_t dist_formula = FormulaPolicy::template inverse
58 <
59 double, true, false, false, false, false
60 >::apply(lon1 * bg::math::d2r<double>(),
61 lat1 * bg::math::d2r<double>(),
62 lon2 * bg::math::d2r<double>(),
63 lat2 * bg::math::d2r<double>(),
64 stype()).distance;
65
66 bg::strategy::distance::geographic<FormulaPolicy, stype> strategy;
67 calc_t dist_strategy = strategy.apply(p1, p2);
68 BOOST_CHECK_CLOSE(dist_formula, dist_strategy, tolerance);
69 }
70
71 template <typename P1, typename P2, typename FormulaPolicy>
72 void test_distance_reverse(double lon1, double lat1,
73 double lon2, double lat2)
74 {
75 test_distance<P1, P2, FormulaPolicy>(lon1, lat1, lon2, lat2);
76 test_distance<P1, P2, FormulaPolicy>(lon2, lat2, lon1, lat1);
77 }
78
79 template <typename P1, typename P2, typename FormulaPolicy>
80 void test_meridian()
81 {
82 test_distance_reverse<P1, P2, FormulaPolicy>(0., 70., 0., 80.);
83 test_distance_reverse<P1, P2, FormulaPolicy>(0, 70, 0., -80.);
84 test_distance_reverse<P1, P2, FormulaPolicy>(0., -70., 0., 80.);
85 test_distance_reverse<P1, P2, FormulaPolicy>(0., -70., 0., -80.);
86
87 test_distance_reverse<P1, P2, FormulaPolicy>(0., 70., 180., 80.);
88 test_distance_reverse<P1, P2, FormulaPolicy>(0., 70., 180., -80.);
89 test_distance_reverse<P1, P2, FormulaPolicy>(0., -70., 180., 80.);
90 test_distance_reverse<P1, P2, FormulaPolicy>(0., -70., 180., -80.);
91
92 test_distance_reverse<P1, P2, FormulaPolicy>(350., 70., 170., 80.);
93 test_distance_reverse<P1, P2, FormulaPolicy>(350., 70., 170., -80.);
94 test_distance_reverse<P1, P2, FormulaPolicy>(350., -70., 170., 80.);
95 test_distance_reverse<P1, P2, FormulaPolicy>(350., -70., 170., -80.);
96 }
97
98 template <typename P>
99 void test_all()
100 {
101 test_meridian<P, P, andoyer_formula>();
102 test_meridian<P, P, thomas_formula>();
103 test_meridian<P, P, vincenty_formula>();
104 }
105
106 int test_main(int, char* [])
107 {
108 test_all<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > >();
109 test_all<bg::model::point<float, 2, bg::cs::geographic<bg::degree> > >();
110 test_all<bg::model::point<int, 2, bg::cs::geographic<bg::degree> > >();
111
112 return 0;
113 }