4 // Copyright (c) 2016 Oracle and/or its affiliates.
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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)
12 #include "test_formula.hpp"
13 #include "inverse_cases.hpp"
15 #include <boost/geometry/formulas/vincenty_inverse.hpp>
16 #include <boost/geometry/formulas/thomas_inverse.hpp>
17 #include <boost/geometry/formulas/andoyer_inverse.hpp>
19 template <typename Result>
20 void check_inverse(Result const& result, expected_result const& expected, expected_result const& reference, double reference_error)
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);
29 void test_all(expected_results const& results)
31 double const d2r = bg::math::d2r<double>();
32 double const r2d = bg::math::r2d<double>();
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;
40 bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
42 bg::formula::result_inverse<double> result_v, result_t, result_a;
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);
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);
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);
63 int test_main(int, char*[])
65 for (size_t i = 0; i < expected_size; ++i)
67 test_all(expected[i]);