num_interior_rings_multi.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. //
  3. // Copyright (c) 2011-2015 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <geometry_test_common.hpp>
  8. #include <boost/geometry/algorithms/num_interior_rings.hpp>
  9. #include <boost/geometry/io/wkt/wkt.hpp>
  10. #include <boost/geometry/geometries/geometries.hpp>
  11. #include <boost/geometry/geometries/point_xy.hpp>
  12. template <typename Geometry>
  13. void test_geometry(std::string const& wkt, std::size_t expected)
  14. {
  15. Geometry geometry;
  16. bg::read_wkt(wkt, geometry);
  17. std::size_t detected = bg::num_interior_rings(geometry);
  18. BOOST_CHECK_MESSAGE(detected == expected,
  19. "num_interior_rings: " << wkt
  20. << " -> Expected: " << expected
  21. << " detected: " << detected);
  22. }
  23. template <typename Point>
  24. void test_all()
  25. {
  26. typedef bg::model::polygon<Point> poly;
  27. typedef bg::model::multi_polygon<poly> mpoly;
  28. test_geometry<poly>("POLYGON((0 0,0 10,10 0,0 0),(1 1,1 9,9 1,1 1))", 1);
  29. test_geometry<mpoly>("MULTIPOLYGON(((0 0,0 10,10 0,0 0),(1 1,1 9,9 1,1 1)),((0 0,0 10,10 0,0 0),(1 1,1 4,4 1,1 1),(5 1,5 4,9 1,5 1)))", 3);
  30. }
  31. int test_main( int , char* [] )
  32. {
  33. test_all<bg::model::d2::point_xy<double> >();
  34. #ifdef HAVE_TTMATH
  35. test_all<bg::model::d2::point_xy<ttmath_big> >();
  36. #endif
  37. return 0;
  38. }