perimeter_sph.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_perimeter.hpp>
  9. #include <algorithms/perimeter/perimeter_polygon_cases.hpp>
  10. #include <boost/geometry/geometries/geometries.hpp>
  11. #include <boost/geometry/geometries/point_xy.hpp>
  12. template <typename P>
  13. void test_all_default() //test the default strategy
  14. {
  15. double const pi = boost::math::constants::pi<double>();
  16. for (std::size_t i = 0; i <= 2; ++i)
  17. {
  18. test_geometry<bg::model::polygon<P> >(poly_data_sph[i], 2 * pi);
  19. }
  20. // Multipolygon
  21. test_geometry<bg::model::multi_polygon<bg::model::polygon<P> > >
  22. (multipoly_data[0], 3 * pi);
  23. // Geometries with length zero
  24. test_geometry<P>("POINT(0 0)", 0);
  25. test_geometry<bg::model::linestring<P> >("LINESTRING(0 0,3 4,4 3)", 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<double> haversine_strategy(mean_radius);
  32. for (std::size_t i = 0; i <= 2; ++i)
  33. {
  34. test_geometry<bg::model::polygon<P> >(poly_data_sph[i],
  35. 2 * pi * mean_radius,
  36. haversine_strategy);
  37. }
  38. // Multipolygon
  39. test_geometry<bg::model::multi_polygon<bg::model::polygon<P> > >
  40. (multipoly_data[0],
  41. 3 * pi * mean_radius,
  42. haversine_strategy);
  43. // Geometries with length zero
  44. test_geometry<P>("POINT(0 0)", 0, haversine_strategy);
  45. test_geometry<bg::model::linestring<P> >("LINESTRING(0 0,3 4,4 3)",
  46. 0,
  47. haversine_strategy);
  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. return 0;
  70. }