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