inverse_karney.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Boost.Geometry
  2. // Unit Test
  3. // Copyright (c) 2016-2019 Oracle and/or its affiliates.
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Copyright (c) 2018 Adeel Ahmad, Islamabad, Pakistan.
  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 <sstream>
  11. #include "test_formula.hpp"
  12. #include "inverse_cases.hpp"
  13. #include "inverse_cases_antipodal.hpp"
  14. #include "inverse_cases_small_angles.hpp"
  15. #include <boost/geometry/formulas/karney_inverse.hpp>
  16. #include <boost/geometry/srs/spheroid.hpp>
  17. template <typename Result>
  18. void check_inverse(std::string const& name,
  19. Result const& results,
  20. bg::formula::result_inverse<double> const& result,
  21. expected_result const& expected,
  22. expected_result const& reference,
  23. double reference_error)
  24. {
  25. std::stringstream ss;
  26. ss << "(" << results.p1.lon << " " << results.p1.lat << ")->(" << results.p2.lon << " " << results.p2.lat << ")";
  27. check_one(name + "_d " + ss.str(),
  28. result.distance, expected.distance, reference.distance, reference_error);
  29. check_one(name + "_a " + ss.str(),
  30. result.azimuth, expected.azimuth, reference.azimuth, reference_error, true);
  31. check_one(name + "_ra " + ss.str(),
  32. result.reverse_azimuth, expected.reverse_azimuth, reference.reverse_azimuth, reference_error, true);
  33. check_one(name + "_rl " + ss.str(),
  34. result.reduced_length, expected.reduced_length, reference.reduced_length, reference_error);
  35. check_one(name + "_gs " + ss.str(),
  36. result.geodesic_scale, expected.geodesic_scale, reference.geodesic_scale, reference_error);
  37. }
  38. void test_all(expected_results const& results)
  39. {
  40. double lon1d = results.p1.lon;
  41. double lat1d = results.p1.lat;
  42. double lon2d = results.p2.lon;
  43. double lat2d = results.p2.lat;
  44. // WGS84
  45. bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
  46. bg::formula::result_inverse<double> result_k;
  47. typedef bg::formula::karney_inverse<double, true, true, true, true, true, 8> ka_t;
  48. result_k = ka_t::apply(lon1d, lat1d, lon2d, lat2d, spheroid);
  49. check_inverse("karney", results, result_k, results.vincenty, results.reference, 0.0000001);
  50. }
  51. template <typename ExpectedResults>
  52. void test_karney(ExpectedResults const& results)
  53. {
  54. double lon1d = results.p1.lon;
  55. double lat1d = results.p1.lat;
  56. double lon2d = results.p2.lon;
  57. double lat2d = results.p2.lat;
  58. // WGS84
  59. bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
  60. bg::formula::result_inverse<double> result;
  61. typedef bg::formula::karney_inverse<double, true, true, true, true, true, 8> ka_t;
  62. result = ka_t::apply(lon1d, lat1d, lon2d, lat2d, spheroid);
  63. check_inverse("karney", results, result, results.karney, results.karney, 0.0000001);
  64. }
  65. int test_main(int, char*[])
  66. {
  67. for (size_t i = 0; i < expected_size; ++i)
  68. {
  69. test_all(expected[i]);
  70. }
  71. for (size_t i = 0; i < expected_size_antipodal; ++i)
  72. {
  73. test_karney(expected_antipodal[i]);
  74. }
  75. for (size_t i = 0; i < expected_size_small_angles; ++i)
  76. {
  77. test_karney(expected_small_angles[i]);
  78. }
  79. return 0;
  80. }