Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / geometry / test / formulas / inverse_karney.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 #include "inverse_cases_antipodal.hpp"
22 #include "inverse_cases_small_angles.hpp"
23
24 #include <boost/geometry/formulas/karney_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 lon1d = results.p1.lon;
54     double lat1d = results.p1.lat;
55     double lon2d = results.p2.lon;
56     double lat2d = results.p2.lat;
57
58     // WGS84
59     bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
60
61     bg::formula::result_inverse<double> result_k;
62
63     typedef bg::formula::karney_inverse<double, true, true, true, true, true, 8> ka_t;
64     result_k = ka_t::apply(lon1d, lat1d, lon2d, lat2d, spheroid);
65     check_inverse("karney", results, result_k, results.vincenty, results.reference, 0.0000001);
66 }
67
68 template <typename ExpectedResults>
69 void test_karney(ExpectedResults const& results)
70 {
71     double lon1d = results.p1.lon;
72     double lat1d = results.p1.lat;
73     double lon2d = results.p2.lon;
74     double lat2d = results.p2.lat;
75
76     // WGS84
77     bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
78
79     bg::formula::result_inverse<double> result;
80
81     typedef bg::formula::karney_inverse<double, true, true, true, true, true, 8> ka_t;
82     result = ka_t::apply(lon1d, lat1d, lon2d, lat2d, spheroid);
83     check_inverse("karney", results, result, results.karney, results.karney, 0.0000001);
84 }
85
86 int test_main(int, char*[])
87 {
88     for (size_t i = 0; i < expected_size; ++i)
89     {
90         test_all(expected[i]);
91     }
92
93     for (size_t i = 0; i < expected_size_antipodal; ++i)
94     {
95         test_karney(expected_antipodal[i]);
96     }
97
98     for (size_t i = 0; i < expected_size_small_angles; ++i)
99     {
100         test_karney(expected_small_angles[i]);
101     }
102
103     return 0;
104 }