num_points_multi.cpp 2.1 KB

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