direct.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // Boost.Geometry
  2. // Unit Test
  3. // Copyright (c) 2016-2018 Oracle and/or its affiliates.
  4. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Contributed and/or modified by Adeel Ahmad, as part of Google Summer of Code 2018 program
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #include "test_formula.hpp"
  11. #include "direct_cases.hpp"
  12. #include "direct_cases_antipodal.hpp"
  13. #include <boost/geometry/formulas/vincenty_direct.hpp>
  14. #include <boost/geometry/formulas/thomas_direct.hpp>
  15. #include <boost/geometry/formulas/karney_direct.hpp>
  16. //#include <boost/geometry/formulas/series_expansion_direct.hpp>
  17. #include <boost/geometry/formulas/spherical.hpp>
  18. #include <boost/geometry/srs/srs.hpp>
  19. #ifdef BOOST_GEOEMTRY_TEST_WITH_GEOGRAPHICLIB
  20. #include <GeographicLib/Geodesic.hpp>
  21. #include <GeographicLib/Constants.hpp>
  22. #endif // BOOST_GEOEMTRY_TEST_WITH_GEOGRAPHICLIB
  23. inline void symmetrize_wrt_origin(expected_result & r)
  24. {
  25. r.lon2 = -r.lon2;
  26. r.lat2 = -r.lat2;
  27. r.reduced_length = -r.reduced_length;
  28. }
  29. inline expected_results symmetric_wrt_origin(expected_results r)
  30. {
  31. r.distance = -r.distance;
  32. symmetrize_wrt_origin(r.karney);
  33. symmetrize_wrt_origin(r.series);
  34. symmetrize_wrt_origin(r.spherical);
  35. symmetrize_wrt_origin(r.thomas);
  36. symmetrize_wrt_origin(r.thomas1st);
  37. symmetrize_wrt_origin(r.vincenty);
  38. return r;
  39. }
  40. template <typename Result>
  41. void check_direct(Result const& result, expected_result const& expected, expected_result const& reference,
  42. double reference_error, bool check_reference_only = false)
  43. {
  44. check_direct_sph(result, expected, reference, reference_error, check_reference_only);
  45. check_one(result.reduced_length, expected.reduced_length, reference.reduced_length, reference_error);
  46. check_one(result.geodesic_scale, expected.geodesic_scale, reference.geodesic_scale, reference_error);
  47. }
  48. template <typename Result>
  49. void check_direct_sph(Result const& result, expected_result const& expected, expected_result const& reference,
  50. double reference_error, bool check_reference_only = false)
  51. {
  52. check_one(result.lon2, expected.lon2, reference.lon2, reference_error, true, check_reference_only);
  53. check_one(result.lat2, expected.lat2, reference.lat2, reference_error, true, check_reference_only);
  54. check_one(result.reverse_azimuth, expected.reverse_azimuth, reference.reverse_azimuth, reference_error, true, check_reference_only);
  55. }
  56. void test_all(expected_results const& results)
  57. {
  58. double const d2r = bg::math::d2r<double>();
  59. double const r2d = bg::math::r2d<double>();
  60. double lon1r = results.p1.lon * d2r;
  61. double lat1r = results.p1.lat * d2r;
  62. double distance = results.distance;
  63. double azi12r = results.azimuth12 * d2r;
  64. double lon1d = results.p1.lon;
  65. double lat1d = results.p1.lat;
  66. double azi12d = results.azimuth12;
  67. // WGS84
  68. bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
  69. bg::srs::sphere<double> const sphere;
  70. bg::formula::result_direct<double> result;
  71. typedef bg::formula::vincenty_direct<double, true, true, true, true> vi_t;
  72. result = vi_t::apply(lon1r, lat1r, distance, azi12r, spheroid);
  73. result.lon2 *= r2d;
  74. result.lat2 *= r2d;
  75. result.reverse_azimuth *= r2d;
  76. check_direct(result, results.vincenty, results.karney, 0.00000001);
  77. typedef bg::formula::thomas_direct<double, true, true, true, true, true> th_t;
  78. result = th_t::apply(lon1r, lat1r, distance, azi12r, spheroid);
  79. result.lon2 *= r2d;
  80. result.lat2 *= r2d;
  81. result.reverse_azimuth *= r2d;
  82. check_direct(result, results.thomas, results.karney, 0.0000001);
  83. typedef bg::formula::thomas_direct<double, false, true, true, true, true> th_t1st;
  84. result = th_t1st::apply(lon1r, lat1r, distance, azi12r, spheroid);
  85. result.lon2 *= r2d;
  86. result.lat2 *= r2d;
  87. result.reverse_azimuth *= r2d;
  88. check_direct(result, results.thomas1st, results.karney, 0.0000001);
  89. /*
  90. typedef bg::formula::series_expansion_direct<double, true, true, true, true, 4> series;
  91. result = series::apply(lon1r, lat1r, distance, azi12r, spheroid);
  92. result.lon2 *= r2d;
  93. result.lat2 *= r2d;
  94. result.reverse_azimuth *= r2d;
  95. check_direct(result, results.series, results.karney, 0.0000001);
  96. */
  97. result = bg::formula::spherical_direct<true, true>(lon1r, lat1r, distance,
  98. azi12r, sphere);
  99. result.lon2 *= r2d;
  100. result.lat2 *= r2d;
  101. result.reverse_azimuth *= r2d;
  102. check_direct_sph(result, results.spherical, results.karney, 0.1);
  103. typedef bg::formula::karney_direct<double, true, true, true, true, 2> ka_t;
  104. result = ka_t::apply(lon1d, lat1d, distance, azi12d, spheroid);
  105. check_direct(result, results.karney, results.karney, 0.0000001);
  106. #ifdef BOOST_GEOEMTRY_TEST_WITH_GEOGRAPHICLIB
  107. {
  108. using namespace GeographicLib;
  109. Geodesic geod(Constants::WGS84_a(), Constants::WGS84_f());
  110. double foo = 0;
  111. geod.Direct(lat1d, lon1d, azi12d, distance,
  112. result.lat2, result.lon2, result.reverse_azimuth,
  113. result.reduced_length, result.geodesic_scale, foo);
  114. boost::ignore_unused(foo);
  115. check_direct(result, results.karney, results.karney, 0.0000001);
  116. }
  117. #endif
  118. }
  119. void test_karney_antipodal(expected_results_antipodal const& results)
  120. {
  121. double lon1d = results.p1.lon;
  122. double lat1d = results.p1.lat;
  123. double distance = results.distance;
  124. double azi12d = results.azimuth12;
  125. // WGS84
  126. bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
  127. bg::formula::result_direct<double> result;
  128. typedef bg::formula::karney_direct<double, true, true, true, true, 8> ka_t;
  129. result = ka_t::apply(lon1d, lat1d, distance, azi12d, spheroid);
  130. check_direct(result, results.karney, results.karney, 0.0000001, true);
  131. }
  132. int test_main(int, char*[])
  133. {
  134. for (size_t i = 0; i < expected_size; ++i)
  135. {
  136. test_all(expected[i]);
  137. if (expected[i].p1.lon == 0 && expected[i].p1.lat == 0)
  138. {
  139. test_all(symmetric_wrt_origin(expected[i]));
  140. }
  141. }
  142. for (size_t i = 0; i < expected_size_antipodal; ++i)
  143. {
  144. test_karney_antipodal(expected_antipodal[i]);
  145. }
  146. return 0;
  147. }