/Src/Dependencies/Boost/libs/geometry/test/strategies/cross_track.cpp

http://hadesmem.googlecode.com/ · C++ · 114 lines · 63 code · 32 blank · 19 comment · 0 complexity · 97d71657a5f92af4e61f181192b879b5 MD5 · raw file

  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <geometry_test_common.hpp>
  12. #include <boost/geometry/algorithms/assign.hpp>
  13. #include <boost/geometry/algorithms/distance.hpp>
  14. #include <boost/geometry/strategies/spherical/distance_haversine.hpp>
  15. #include <boost/geometry/strategies/spherical/distance_cross_track.hpp>
  16. #include <boost/geometry/strategies/concepts/distance_concept.hpp>
  17. #include <boost/geometry/geometries/point.hpp>
  18. #include <boost/geometry/geometries/segment.hpp>
  19. // This test is GIS oriented.
  20. template <typename Point, typename LatitudePolicy>
  21. void test_distance(
  22. typename bg::coordinate_type<Point>::type const& lon1,
  23. typename bg::coordinate_type<Point>::type const& lat1,
  24. typename bg::coordinate_type<Point>::type const& lon2,
  25. typename bg::coordinate_type<Point>::type const& lat2,
  26. typename bg::coordinate_type<Point>::type const& lon3,
  27. typename bg::coordinate_type<Point>::type const& lat3,
  28. typename bg::coordinate_type<Point>::type const& radius,
  29. typename bg::coordinate_type<Point>::type const& expected,
  30. typename bg::coordinate_type<Point>::type const& tolerance)
  31. {
  32. typedef bg::strategy::distance::cross_track
  33. <
  34. Point,
  35. Point
  36. > strategy_type;
  37. typedef typename bg::strategy::distance::services::return_type
  38. <
  39. strategy_type
  40. >::type return_type;
  41. BOOST_CONCEPT_ASSERT
  42. (
  43. (bg::concept::PointSegmentDistanceStrategy<strategy_type>)
  44. );
  45. Point p1, p2, p3;
  46. bg::assign_values(p1, lon1, LatitudePolicy::apply(lat1));
  47. bg::assign_values(p2, lon2, LatitudePolicy::apply(lat2));
  48. bg::assign_values(p3, lon3, LatitudePolicy::apply(lat3));
  49. strategy_type strategy;
  50. return_type d = strategy.apply(p1, p2, p3);
  51. BOOST_CHECK_CLOSE(radius * d, expected, tolerance);
  52. // Test specifying radius explicitly
  53. strategy_type strategy_radius(radius);
  54. d = strategy_radius.apply(p1, p2, p3);
  55. BOOST_CHECK_CLOSE(d, expected, tolerance);
  56. // Test the "default strategy" registration
  57. bg::model::referring_segment<Point const> segment(p2, p3);
  58. d = bg::distance(p1, segment);
  59. BOOST_CHECK_CLOSE(radius * d, expected, tolerance);
  60. }
  61. template <typename Point, typename LatitudePolicy>
  62. void test_all()
  63. {
  64. typename bg::coordinate_type<Point>::type const average_earth_radius = 6372795.0;
  65. // distance (Paris <-> Amsterdam/Barcelona),
  66. // with coordinates rounded as below ~87 km
  67. // is equal to distance (Paris <-> Barcelona/Amsterdam)
  68. typename bg::coordinate_type<Point>::type const p_to_ab = 86.798321 * 1000.0;
  69. test_distance<Point, LatitudePolicy>(2, 48, 4, 52, 2, 41, average_earth_radius, p_to_ab, 0.1);
  70. test_distance<Point, LatitudePolicy>(2, 48, 2, 41, 4, 52, average_earth_radius, p_to_ab, 0.1);
  71. }
  72. int test_main(int, char* [])
  73. {
  74. test_all<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> >, geographic_policy >();
  75. // NYI: haversine for mathematical spherical coordinate systems
  76. // test_all<bg::model::point<double, 2, bg::cs::spherical<bg::degree> >, mathematical_policya >();
  77. #if defined(HAVE_TTMATH)
  78. typedef ttmath::Big<1,4> tt;
  79. //test_all<bg::model::point<tt, 2, bg::cs::geographic<bg::degree> >, geographic_policy>();
  80. #endif
  81. return 0;
  82. }