clear_multi.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/clear.hpp>
  9. #include <boost/geometry/algorithms/num_points.hpp>
  10. #include <boost/geometry/io/wkt/wkt.hpp>
  11. #include <boost/geometry/geometries/geometries.hpp>
  12. #include <boost/geometry/geometries/point_xy.hpp>
  13. #include <boost/variant/variant.hpp>
  14. template <typename Geometry>
  15. void test_geometry(std::string const& wkt, unsigned int expected)
  16. {
  17. Geometry geometry;
  18. bg::read_wkt(wkt, geometry);
  19. boost::variant<Geometry> variant_geometry(geometry);
  20. bg::clear(geometry);
  21. BOOST_CHECK_EQUAL(bg::num_points(geometry), expected);
  22. bg::clear(variant_geometry);
  23. BOOST_CHECK_EQUAL(bg::num_points(variant_geometry), expected);
  24. }
  25. template <typename Point>
  26. void test_all()
  27. {
  28. typedef bg::model::polygon<Point> poly;
  29. typedef bg::model::linestring<Point> ls;
  30. typedef bg::model::multi_point<Point> mpoint;
  31. typedef bg::model::multi_linestring<ls> mls;
  32. typedef bg::model::multi_polygon<poly> mpoly;
  33. test_geometry<Point>("POINT(0 0)", 1);
  34. test_geometry<ls>("LINESTRING(0 0,0 1)", 0);
  35. test_geometry<poly>("POLYGON((0 0,0 1,1 0,0 0))", 0);
  36. test_geometry<mpoint>("MULTIPOINT((0 0),(0 1),(1 0),(0 0))", 0);
  37. test_geometry<mls>("MULTILINESTRING((0 0,0 1),(1 0,0 0))", 0);
  38. test_geometry<mpoly>("MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((10 0,10 1,11 0,10 0)))", 0);
  39. }
  40. int test_main( int , char* [] )
  41. {
  42. test_all<bg::model::d2::point_xy<double> >();
  43. #ifdef HAVE_TTMATH
  44. test_all<bg::model::d2::point_xy<ttmath_big> >();
  45. #endif
  46. return 0;
  47. }