distance_cross_track.cpp 4.5 KB

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