• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry
2 // Unit Test
3 
4 // Copyright (c) 2019 Oracle and/or its affiliates.
5 
6 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8 
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12 
13 
14 #include <sstream>
15 
16 #include "../formulas/test_formula.hpp"
17 #include "distance_cross_track_cases.hpp"
18 
19 #include <boost/geometry/strategies/strategies.hpp>
20 #include <boost/geometry/srs/spheroid.hpp>
21 
22 struct error{
23     double long_distance;
24     double short_distance;
25     double very_short_distance;
26     double very_very_short_distance;
27 };
28 
check_result(double const & result,double const & expected,double const & reference,error const & reference_error)29 void check_result(double const& result, double const& expected,
30                   double const& reference, error const& reference_error)
31 {
32     BOOST_GEOMETRY_CHECK_CLOSE(result, expected, 0.1,
33     std::setprecision(20) << "result {" << result
34                           << "} different than expected {" << expected << "}.");
35 
36     double reference_error_value = result > 2000 ? reference_error.long_distance
37                                  : result > 100  ? reference_error.short_distance
38                                  : result > 20   ? reference_error.very_short_distance
39                                  : reference_error.very_very_short_distance;
40 
41     BOOST_GEOMETRY_CHECK_CLOSE(result, reference, reference_error_value,
42         std::setprecision(20) << "result {" << result
43                               << "} different than reference {"
44                               << reference << "}.");
45 }
46 
47 template <typename Point>
test_all(expected_results const & results)48 void test_all(expected_results const& results)
49 {
50     double const d2r = bg::math::d2r<double>();
51 
52     double lon1r = results.p1.lon * d2r;
53     double lat1r = results.p1.lat * d2r;
54     double lon2r = results.p2.lon * d2r;
55     double lat2r = results.p2.lat * d2r;
56     double lon3r = results.p3.lon * d2r;
57     double lat3r = results.p3.lat * d2r;
58 
59     typedef bg::srs::spheroid<double> Spheroid;
60 
61     // WGS84
62     Spheroid spheroid(6378137.0, 6356752.3142451793);
63 
64     error errors [] =
65     {
66         {0.00000001, 0.00000001, 0.00000001, 0.000001}, //vincenty
67         {0.0002, 0.002, 0.01, 0.2}, //thomas
68         {0.002, 0.4, 15, 25}, //andoyer
69         {1, 6, 15, 200} //spherical
70     };
71 
72     //vincenty
73     double distance = bg::strategy::distance::detail::geographic_cross_track<bg::strategy::vincenty, Spheroid, double, true>(spheroid)
74             .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
75     check_result(distance, results.vincenty_bisection, results.reference, errors[0]);
76 
77     distance = bg::strategy::distance::geographic_cross_track<bg::strategy::vincenty, Spheroid, double>(spheroid)
78             .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
79     check_result(distance, results.vincenty, results.reference, errors[0]);
80 
81     //thomas
82     distance = bg::strategy::distance::detail::geographic_cross_track<bg::strategy::thomas, Spheroid, double, true>(spheroid)
83             .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
84     check_result(distance, results.thomas_bisection, results.reference, errors[1]);
85 
86     distance = bg::strategy::distance::geographic_cross_track<bg::strategy::thomas, Spheroid, double>(spheroid)
87             .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
88     check_result(distance, results.thomas, results.reference, errors[1]);
89 
90     //andoyer
91     distance = bg::strategy::distance::detail::geographic_cross_track<bg::strategy::andoyer, Spheroid, double, true>(spheroid)
92             .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
93     check_result(distance, results.andoyer_bisection, results.reference, errors[2]);
94 
95     distance = bg::strategy::distance::geographic_cross_track<bg::strategy::andoyer, Spheroid, double>(spheroid)
96             .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
97     check_result(distance, results.andoyer, results.reference, errors[2]);
98 
99     //spherical
100     distance = bg::strategy::distance::cross_track<>(bg::formula::mean_radius<double>(spheroid))
101             .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
102     check_result(distance, results.spherical, results.reference, errors[3]);
103 
104 }
105 
test_main(int,char * [])106 int test_main(int, char*[])
107 {
108     typedef bg::model::point<double, 2, bg::cs::geographic<bg::radian> > point;
109 
110     for (size_t i = 0; i < expected_size; ++i)
111     {
112         test_all<point>(expected[i]);
113     }
114 
115     return 0;
116 }
117