Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / geometry / test / formulas / inverse.cpp
1 // Boost.Geometry
2 // Unit Test
3
4 // Copyright (c) 2016 Oracle and/or its affiliates.
5
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7
8 // Use, modification and distribution is subject to the Boost Software License,
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11
12 #include "test_formula.hpp"
13 #include "inverse_cases.hpp"
14
15 #include <boost/geometry/formulas/vincenty_inverse.hpp>
16 #include <boost/geometry/formulas/thomas_inverse.hpp>
17 #include <boost/geometry/formulas/andoyer_inverse.hpp>
18
19 template <typename Result>
20 void check_inverse(Result const& result, expected_result const& expected, expected_result const& reference, double reference_error)
21 {
22     check_one(result.distance, expected.distance, reference.distance, reference_error);
23     check_one(result.azimuth, expected.azimuth, reference.azimuth, reference_error, true);
24     check_one(result.reverse_azimuth, expected.reverse_azimuth, reference.reverse_azimuth, reference_error, true);
25     check_one(result.reduced_length, expected.reduced_length, reference.reduced_length, reference_error);
26     check_one(result.geodesic_scale, expected.geodesic_scale, reference.geodesic_scale, reference_error);
27 }
28
29 void test_all(expected_results const& results)
30 {
31     double const d2r = bg::math::d2r<double>();
32     double const r2d = bg::math::r2d<double>();
33
34     double lon1r = results.p1.lon * d2r;
35     double lat1r = results.p1.lat * d2r;
36     double lon2r = results.p2.lon * d2r;
37     double lat2r = results.p2.lat * d2r;
38
39     // WGS84
40     bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
41
42     bg::formula::result_inverse<double> result_v, result_t, result_a;
43
44     typedef bg::formula::vincenty_inverse<double, true, true, true, true, true> vi_t;
45     result_v = vi_t::apply(lon1r, lat1r, lon2r, lat2r, spheroid);
46     result_v.azimuth *= r2d;
47     result_v.reverse_azimuth *= r2d;
48     check_inverse(result_v, results.vincenty, results.reference, 0.0000001);
49
50     typedef bg::formula::thomas_inverse<double, true, true, true, true, true> th_t;
51     result_t = th_t::apply(lon1r, lat1r, lon2r, lat2r, spheroid);
52     result_t.azimuth *= r2d;
53     result_t.reverse_azimuth *= r2d;
54     check_inverse(result_t, results.thomas, results.reference, 0.00001);
55
56     typedef bg::formula::andoyer_inverse<double, true, true, true, true, true> an_t;
57     result_a = an_t::apply(lon1r, lat1r, lon2r, lat2r, spheroid);
58     result_a.azimuth *= r2d;
59     result_a.reverse_azimuth *= r2d;
60     check_inverse(result_a, results.andoyer, results.reference, 0.001);
61 }
62
63 int test_main(int, char*[])
64 {
65     for (size_t i = 0; i < expected_size; ++i)
66     {
67         test_all(expected[i]);
68     }
69
70     return 0;
71 }