File: distance_cross_track.cpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (116 lines) | stat: -rw-r--r-- 4,630 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Boost.Geometry
// Unit Test

// Copyright (c) 2019 Oracle and/or its affiliates.

// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)


#include <sstream>

#include "../formulas/test_formula.hpp"
#include "distance_cross_track_cases.hpp"

#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/srs/spheroid.hpp>

struct error{
    double long_distance;
    double short_distance;
    double very_short_distance;
    double very_very_short_distance;
};

void check_result(double const& result, double const& expected,
                  double const& reference, error const& reference_error)
{
    BOOST_GEOMETRY_CHECK_CLOSE(result, expected, 0.1,
    std::setprecision(20) << "result {" << result
                          << "} different than expected {" << expected << "}.");

    double reference_error_value = result > 2000 ? reference_error.long_distance
                                 : result > 100  ? reference_error.short_distance
                                 : result > 20   ? reference_error.very_short_distance
                                 : reference_error.very_very_short_distance;

    BOOST_GEOMETRY_CHECK_CLOSE(result, reference, reference_error_value,
        std::setprecision(20) << "result {" << result
                              << "} different than reference {"
                              << reference << "}.");
}

template <typename Point>
void test_all(expected_results const& results)
{
    double const d2r = bg::math::d2r<double>();

    double lon1r = results.p1.lon * d2r;
    double lat1r = results.p1.lat * d2r;
    double lon2r = results.p2.lon * d2r;
    double lat2r = results.p2.lat * d2r;
    double lon3r = results.p3.lon * d2r;
    double lat3r = results.p3.lat * d2r;

    typedef bg::srs::spheroid<double> Spheroid;

    // WGS84
    Spheroid spheroid(6378137.0, 6356752.3142451793);

    error errors [] =
    {
        {0.00000001, 0.00000001, 0.00000001, 0.000001}, //vincenty
        {0.0002, 0.002, 0.01, 0.2}, //thomas
        {0.002, 0.4, 15, 25}, //andoyer
        {1, 6, 15, 200} //spherical
    };

    //vincenty
    double distance = bg::strategy::distance::detail::geographic_cross_track<bg::strategy::vincenty, Spheroid, double, true>(spheroid)
            .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
    check_result(distance, results.vincenty_bisection, results.reference, errors[0]);

    distance = bg::strategy::distance::geographic_cross_track<bg::strategy::vincenty, Spheroid, double>(spheroid)
            .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
    check_result(distance, results.vincenty, results.reference, errors[0]);

    //thomas
    distance = bg::strategy::distance::detail::geographic_cross_track<bg::strategy::thomas, Spheroid, double, true>(spheroid)
            .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
    check_result(distance, results.thomas_bisection, results.reference, errors[1]);

    distance = bg::strategy::distance::geographic_cross_track<bg::strategy::thomas, Spheroid, double>(spheroid)
            .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
    check_result(distance, results.thomas, results.reference, errors[1]);

    //andoyer
    distance = bg::strategy::distance::detail::geographic_cross_track<bg::strategy::andoyer, Spheroid, double, true>(spheroid)
            .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
    check_result(distance, results.andoyer_bisection, results.reference, errors[2]);

    distance = bg::strategy::distance::geographic_cross_track<bg::strategy::andoyer, Spheroid, double>(spheroid)
            .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
    check_result(distance, results.andoyer, results.reference, errors[2]);

    //spherical
    distance = bg::strategy::distance::cross_track<>(bg::formula::mean_radius<double>(spheroid))
            .apply(Point(lon3r, lat3r), Point(lon1r, lat1r), Point(lon2r, lat2r));
    check_result(distance, results.spherical, results.reference, errors[3]);

}

int test_main(int, char*[])
{
    typedef bg::model::point<double, 2, bg::cs::geographic<bg::radian> > point;

    for (size_t i = 0; i < expected_size; ++i)
    {
        test_all<point>(expected[i]);
    }

    return 0;
}