perimeter.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 <boost/geometry/geometries/geometries.hpp>
  10. #include <boost/geometry/geometries/point_xy.hpp>
  11. template <typename P>
  12. void test_all()
  13. {
  14. // Simple
  15. test_geometry<bg::model::polygon<P> >("POLYGON((0 0,3 4,4 3,0 0))",
  16. 5 + sqrt(2.0) + 5);
  17. // Non-simple
  18. test_geometry<bg::model::polygon<P> >("POLYGON((0 0,3 4,4 3,0 3,0 0))",
  19. 5 + sqrt(2.0) + 4 + 3);
  20. // With holes
  21. test_geometry<bg::model::polygon<P> >("POLYGON((0 0,3 4,4 3,0 0),\
  22. (2 2,3 4,3 3,2 2))",
  23. 5 + sqrt(2.0) + 5 +
  24. sqrt(5.0) + 1 + sqrt(2.0));
  25. // Repeated points
  26. test_geometry<bg::model::polygon<P> >("POLYGON((0 0,3 4,3 4,3 4,4 3,4 3,\
  27. 4 3,4 3,4 3,4 3,0 3,0 0))",
  28. 5 + sqrt(2.0) + 4 + 3);
  29. // Multipolygon
  30. test_geometry<bg::model::multi_polygon<bg::model::polygon<P> > >
  31. (
  32. "MULTIPOLYGON(((0 0,3 4,4 3,0 0)), ((0 0,3 4,4 3,0 3,0 0)))",
  33. 5 + sqrt(2.0) + 5 + 5 + sqrt(2.0) + 4 + 3
  34. );
  35. // Geometries with perimeter zero
  36. test_geometry<P>("POINT(0 0)", 0);
  37. test_geometry<bg::model::linestring<P> >("LINESTRING(0 0,3 4,4 3)", 0);
  38. }
  39. template <typename P>
  40. void test_empty_input()
  41. {
  42. test_empty_input(bg::model::polygon<P>());
  43. test_empty_input(bg::model::multi_polygon<bg::model::polygon<P> >());
  44. }
  45. int test_main(int, char* [])
  46. {
  47. test_all<bg::model::d2::point_xy<int> >();
  48. test_all<bg::model::d2::point_xy<float> >();
  49. test_all<bg::model::d2::point_xy<double> >();
  50. #if defined(HAVE_TTMATH)
  51. test_all<bg::model::d2::point_xy<ttmath_big> >();
  52. #endif
  53. // test_empty_input<bg::model::d2::point_xy<int> >();
  54. return 0;
  55. }