num_geometries_multi.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_geometries.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_geometries(geometry);
  18. BOOST_CHECK_MESSAGE(detected == expected,
  19. "num_geometries: " << 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::linestring<Point> ls;
  28. typedef bg::model::multi_point<Point> mpoint;
  29. typedef bg::model::multi_linestring<ls> mls;
  30. typedef bg::model::multi_polygon<poly> mpoly;
  31. test_geometry<Point>("POINT(0 0)", 1);
  32. test_geometry<ls>("LINESTRING(0 0,0 1)", 1);
  33. test_geometry<poly>("POLYGON((0 0,0 1,1 0,0 0))", 1);
  34. test_geometry<mpoint>("MULTIPOINT((0 0),(0 1),(1 0),(0 0))", 4);
  35. test_geometry<mls>("MULTILINESTRING((0 0,0 1),(1 0,0 0))", 2);
  36. test_geometry<mpoly>("MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((10 0,10 1,11 0,10 0)))", 2);
  37. }
  38. int test_main( int , char* [] )
  39. {
  40. test_all<bg::model::d2::point_xy<double> >();
  41. #ifdef HAVE_TTMATH
  42. test_all<bg::model::d2::point_xy<ttmath_big> >();
  43. #endif
  44. return 0;
  45. }