]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/formulas/inverse.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / geometry / test / formulas / inverse.cpp
1 // Boost.Geometry
2 // Unit Test
3
4 // Copyright (c) 2016-2019 Oracle and/or its affiliates.
5
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7
8 // Copyright (c) 2018 Adeel Ahmad, Islamabad, Pakistan.
9
10 // Contributed and/or modified by Adeel Ahmad, as part of Google Summer of Code 2018 program
11
12 // Use, modification and distribution is subject to the Boost Software License,
13 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
14 // http://www.boost.org/LICENSE_1_0.txt)
15
16
17 #include <sstream>
18
19 #include "test_formula.hpp"
20 #include "inverse_cases.hpp"
21
22 #include <boost/geometry/formulas/vincenty_inverse.hpp>
23 #include <boost/geometry/formulas/thomas_inverse.hpp>
24 #include <boost/geometry/formulas/andoyer_inverse.hpp>
25
26 #include <boost/geometry/srs/spheroid.hpp>
27
28 template <typename Result>
29 void check_inverse(std::string const& name,
30 Result const& results,
31 bg::formula::result_inverse<double> const& result,
32 expected_result const& expected,
33 expected_result const& reference,
34 double reference_error)
35 {
36 std::stringstream ss;
37 ss << "(" << results.p1.lon << " " << results.p1.lat << ")->(" << results.p2.lon << " " << results.p2.lat << ")";
38
39 check_one(name + "_d " + ss.str(),
40 result.distance, expected.distance, reference.distance, reference_error);
41 check_one(name + "_a " + ss.str(),
42 result.azimuth, expected.azimuth, reference.azimuth, reference_error, true);
43 check_one(name + "_ra " + ss.str(),
44 result.reverse_azimuth, expected.reverse_azimuth, reference.reverse_azimuth, reference_error, true);
45 check_one(name + "_rl " + ss.str(),
46 result.reduced_length, expected.reduced_length, reference.reduced_length, reference_error);
47 check_one(name + "_gs " + ss.str(),
48 result.geodesic_scale, expected.geodesic_scale, reference.geodesic_scale, reference_error);
49 }
50
51 void test_all(expected_results const& results)
52 {
53 double const d2r = bg::math::d2r<double>();
54 double const r2d = bg::math::r2d<double>();
55
56 double lon1r = results.p1.lon * d2r;
57 double lat1r = results.p1.lat * d2r;
58 double lon2r = results.p2.lon * d2r;
59 double lat2r = results.p2.lat * d2r;
60
61 // WGS84
62 bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
63
64 bg::formula::result_inverse<double> result_v, result_t, result_a;
65
66 typedef bg::formula::vincenty_inverse<double, true, true, true, true, true> vi_t;
67 result_v = vi_t::apply(lon1r, lat1r, lon2r, lat2r, spheroid);
68 result_v.azimuth *= r2d;
69 result_v.reverse_azimuth *= r2d;
70 check_inverse("vincenty", results, result_v, results.vincenty, results.reference, 0.0000001);
71
72 typedef bg::formula::thomas_inverse<double, true, true, true, true, true> th_t;
73 result_t = th_t::apply(lon1r, lat1r, lon2r, lat2r, spheroid);
74 result_t.azimuth *= r2d;
75 result_t.reverse_azimuth *= r2d;
76 check_inverse("thomas", results, result_t, results.thomas, results.reference, 0.00001);
77
78 typedef bg::formula::andoyer_inverse<double, true, true, true, true, true> an_t;
79 result_a = an_t::apply(lon1r, lat1r, lon2r, lat2r, spheroid);
80 result_a.azimuth *= r2d;
81 result_a.reverse_azimuth *= r2d;
82 check_inverse("andoyer", results, result_a, results.andoyer, results.reference, 0.001);
83 }
84
85 int test_main(int, char*[])
86 {
87 for (size_t i = 0; i < expected_size; ++i)
88 {
89 test_all(expected[i]);
90 }
91
92 return 0;
93 }