4 // Copyright (c) 2016-2019 Oracle and/or its affiliates.
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8 // Copyright (c) 2018 Adeel Ahmad, Islamabad, Pakistan.
10 // Contributed and/or modified by Adeel Ahmad, as part of Google Summer of Code 2018 program
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)
19 #include "test_formula.hpp"
20 #include "inverse_cases.hpp"
21 #include "inverse_cases_antipodal.hpp"
22 #include "inverse_cases_small_angles.hpp"
24 #include <boost/geometry/formulas/karney_inverse.hpp>
26 #include <boost/geometry/srs/spheroid.hpp>
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)
37 ss << "(" << results.p1.lon << " " << results.p1.lat << ")->(" << results.p2.lon << " " << results.p2.lat << ")";
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);
51 void test_all(expected_results const& results)
53 double lon1d = results.p1.lon;
54 double lat1d = results.p1.lat;
55 double lon2d = results.p2.lon;
56 double lat2d = results.p2.lat;
59 bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
61 bg::formula::result_inverse<double> result_k;
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);
68 template <typename ExpectedResults>
69 void test_karney(ExpectedResults const& results)
71 double lon1d = results.p1.lon;
72 double lat1d = results.p1.lat;
73 double lon2d = results.p2.lon;
74 double lat2d = results.p2.lat;
77 bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
79 bg::formula::result_inverse<double> result;
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);
86 int test_main(int, char*[])
88 for (size_t i = 0; i < expected_size; ++i)
90 test_all(expected[i]);
93 for (size_t i = 0; i < expected_size_antipodal; ++i)
95 test_karney(expected_antipodal[i]);
98 for (size_t i = 0; i < expected_size_small_angles; ++i)
100 test_karney(expected_small_angles[i]);