length_sph.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2016 Oracle and/or its affiliates.
  4. // Contributed and/or modified by Vissarion Fisikopoulos, on behalf of Oracle
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #include <algorithms/test_length.hpp>
  9. #include <algorithms/length/linestring_cases.hpp>
  10. #include <boost/geometry/geometries/geometries.hpp>
  11. #include <boost/geometry/geometries/point_xy.hpp>
  12. #include <boost/geometry/geometries/adapted/std_pair_as_segment.hpp>
  13. #include <test_geometries/all_custom_linestring.hpp>
  14. #include <test_geometries/wrapped_boost_array.hpp>
  15. template <typename P>
  16. void test_all_default() //test the default strategy
  17. {
  18. double const pi = boost::math::constants::pi<double>();
  19. for(std::size_t i = 0; i < 2; ++i)
  20. {
  21. test_geometry<bg::model::linestring<P> >(Ls_data_sph[i], 2 * pi);
  22. }
  23. // Geometries with length zero
  24. test_geometry<P>("POINT(0 0)", 0);
  25. test_geometry<bg::model::polygon<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 0);
  26. }
  27. template <typename P>
  28. void test_all_haversine(double const mean_radius)
  29. {
  30. double const pi = boost::math::constants::pi<double>();
  31. bg::strategy::distance::haversine<float> haversine_strategy(mean_radius);
  32. for(std::size_t i = 0; i < 2; ++i)
  33. {
  34. test_geometry<bg::model::linestring<P> >(Ls_data_sph[i],
  35. 2 * pi * mean_radius,
  36. haversine_strategy);
  37. }
  38. // Geometries with length zero
  39. test_geometry<P>("POINT(0 0)", 0, haversine_strategy);
  40. test_geometry<bg::model::polygon<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))",
  41. 0, haversine_strategy);
  42. }
  43. template <typename P>
  44. void test_empty_input()
  45. {
  46. test_empty_input(bg::model::linestring<P>());
  47. test_empty_input(bg::model::multi_linestring<P>());
  48. }
  49. int test_main(int, char* [])
  50. {
  51. //Earth radius estimation in Km
  52. //(see https://en.wikipedia.org/wiki/Earth_radius)
  53. double const mean_radius = 6371.0;
  54. test_all_default<bg::model::d2::point_xy<int,
  55. bg::cs::spherical_equatorial<bg::degree> > >();
  56. test_all_default<bg::model::d2::point_xy<float,
  57. bg::cs::spherical_equatorial<bg::degree> > >();
  58. test_all_default<bg::model::d2::point_xy<double,
  59. bg::cs::spherical_equatorial<bg::degree> > >();
  60. test_all_haversine<bg::model::d2::point_xy<int,
  61. bg::cs::spherical_equatorial<bg::degree> > >(mean_radius);
  62. test_all_haversine<bg::model::d2::point_xy<float,
  63. bg::cs::spherical_equatorial<bg::degree> > >(mean_radius);
  64. test_all_haversine<bg::model::d2::point_xy<double,
  65. bg::cs::spherical_equatorial<bg::degree> > >(mean_radius);
  66. #if defined(HAVE_TTMATH)
  67. test_all<bg::model::d2::point_xy<ttmath_big> >();
  68. #endif
  69. //test_empty_input<bg::model::d2::point_xy<int> >();
  70. return 0;
  71. }