NMEA: make nmeatool available with/without ENABLE_IO
[marnav.git] / test / geo / Test_geo_geodesic.cpp
blob9bb6757019f9b8cdd742f283b56603001490e02d
1 #include <marnav/geo/geodesic.hpp>
2 #include <marnav/math/constants.hpp>
3 #include <gtest/gtest.h>
5 namespace
7 using namespace marnav;
8 using marnav::math::pi;
10 class Test_geo_geodesic : public ::testing::Test
14 TEST_F(Test_geo_geodesic, central_spherical_angle_default_constructed)
16 geo::position p0;
17 geo::position p1;
19 auto d = geo::central_spherical_angle(p0, p1);
21 EXPECT_NEAR(d, 0.0, 1e-6);
24 TEST_F(Test_geo_geodesic, central_spherical_angle)
26 struct test_data {
27 geo::position p0;
28 geo::position p1;
29 double angle_rad;
32 static const test_data DATA[] = {
33 {{0.0, 0.0}, {0.0, 0.0}, 0.0 * pi / 180.0},
34 {{45.0, 0.0}, {0.0, 0.0}, 45.0 * pi / 180.0},
35 {{0.0, 45.0}, {0.0, 0.0}, 45.0 * pi / 180.0},
36 {{0.0, 0.0}, {45.0, 0.0}, 45.0 * pi / 180.0},
37 {{0.0, 0.0}, {0.0, 45.0}, 45.0 * pi / 180.0},
40 for (auto const & item : DATA) {
41 auto d = geo::central_spherical_angle(item.p0, item.p1);
42 EXPECT_NEAR(d, item.angle_rad, 1e-6);
46 TEST_F(Test_geo_geodesic, distance_sphere)
48 const geo::position BNA = {36.12, -86.67};
49 const geo::position LAX = {33.94, -118.40};
51 const double expected = 2889615.861940;
52 // exact would be : 2892777.232346 m
54 auto result = geo::distance_sphere(BNA, LAX);
56 EXPECT_NEAR(expected, result.distance, 1e-3);
59 TEST_F(Test_geo_geodesic, distance_ellipsoid_vincenty_BNA_LAX)
61 const geo::position BNA = {36.12, -86.67};
62 const geo::position LAX = {33.94, -118.40};
64 const double expected = 2892777.2323462227;
65 // exact would be : 2892777.232346 m
67 auto result = geo::distance_ellipsoid_vincenty(BNA, LAX);
69 EXPECT_NEAR(expected, result.distance, 1e-3);
72 TEST_F(Test_geo_geodesic, distance_ellipsoid_vincenty_same_longitude)
74 const geo::position p1 = {00.0, 0.0};
75 const geo::position p2 = {30.0, 0.0};
77 // test value computed using: http://www.ga.gov.au/geodesy/datums/vincenty_inverse.jsp
78 const double expected = 3320113.398; // [m]
80 auto result = geo::distance_ellipsoid_vincenty(p1, p2);
82 EXPECT_NEAR(expected, result.distance, 0.1);
85 TEST_F(Test_geo_geodesic, distance_ellipsoid_vincenty_same_latitude)
87 const geo::position p1 = {0.0, 0.0};
88 const geo::position p2 = {0.0, 30.0};
90 // test value computed using: http://www.ga.gov.au/geodesy/datums/vincenty_inverse.jsp
91 const double expected = 3339584.724; // [m]
93 auto result = geo::distance_ellipsoid_vincenty(p1, p2);
95 EXPECT_NEAR(expected, result.distance, 0.1);
98 TEST_F(Test_geo_geodesic, distance_ellipsoid_lambert)
100 const geo::position BNA = {36.12, -86.67};
101 const geo::position LAX = {33.94, -118.40};
103 const double expected = 3013798.3235893762;
104 // exact would be : 2892777.232346 m
106 auto result = geo::distance_ellipsoid_lambert(BNA, LAX);
108 EXPECT_NEAR(expected, result.distance, 1e-3);
111 TEST_F(Test_geo_geodesic, point_ellipsoid_vincenty)
113 struct test_data {
114 geo::position start;
115 double azimuth;
116 double distance;
117 geo::position expected;
120 static const test_data DATA[] = {
121 {{0.0, 0.0}, 0.0 * pi / 180.0, 60 * 1852.0, {1.0049343, 0.0}},
122 {{0.0, 0.0}, 90.0 * pi / 180.0, 60 * 1852.0, {0.0, 0.99820794}},
125 for (auto const & item : DATA) {
126 double alpha2 = 0.0;
127 auto destination
128 = geo::point_ellipsoid_vincenty(item.start, item.distance, item.azimuth, alpha2);
129 EXPECT_NEAR(item.expected.lat(), destination.lat(), 1e-4);
130 EXPECT_NEAR(item.expected.lon(), destination.lon(), 1e-4);