[test][algorithms][num_points] add test cases for open geometries (including

the edge case where the geometry is defined as open but the first/last points
are identical)
This commit is contained in:
Menelaos Karavelas 2014-09-05 10:19:43 +03:00
parent 61c33ca109
commit b43faf5457

View File

@ -32,7 +32,9 @@ struct box_dD
};
template <typename Geometry>
inline void test_num_points(std::string const& wkt, std::size_t expected)
inline void test_num_points(std::string const& wkt,
std::size_t expected,
std::size_t expected_add_for_open)
{
namespace bg = boost::geometry;
Geometry geometry;
@ -42,6 +44,13 @@ inline void test_num_points(std::string const& wkt, std::size_t expected)
detected = bg::num_points(geometry, false);
BOOST_CHECK_EQUAL(expected, detected);
detected = bg::num_points(geometry, true);
BOOST_CHECK_EQUAL(expected_add_for_open, detected);
}
template <typename Geometry>
inline void test_num_points(std::string const& wkt, std::size_t expected)
{
test_num_points<Geometry>(wkt, expected, expected);
}
int test_main(int, char* [])
@ -56,6 +65,11 @@ int test_main(int, char* [])
typedef bg::model::multi_linestring<linestring> multi_linestring;
typedef bg::model::multi_polygon<polygon> multi_polygon;
// open geometries
typedef bg::model::ring<point, true, false> open_ring;
typedef bg::model::polygon<point, true, false> open_polygon;
typedef bg::model::multi_polygon<open_polygon> open_multi_polygon;
test_num_points<point>("POINT(0 0)", 1u);
test_num_points<linestring>("LINESTRING(0 0,1 1)", 2u);
test_num_points<segment>("LINESTRING(0 0,1 1)", 2u);
@ -70,6 +84,14 @@ int test_main(int, char* [])
test_num_points<multi_linestring>("MULTILINESTRING((0 0,1 1),(2 2,3 3,4 4))", 5u);
test_num_points<multi_polygon>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 10,1 10,1 9,0 10)))", 9u);
// test open geometries
test_num_points<open_ring>("POLYGON((0 0,1 1,0 1))", 3u, 4u);
test_num_points<open_ring>("POLYGON((0 0,1 1,0 1,0 0))", 4u, 5u);
test_num_points<open_polygon>("POLYGON((0 0,10 10,0 10))", 3u, 4u);
test_num_points<open_polygon>("POLYGON((0 0,10 10,0 10,0 0))", 4u, 5u);
test_num_points<open_multi_polygon>("MULTIPOLYGON(((0 0,0 10,10 10,10 0)),((0 10,1 10,1 9)))", 7u, 9u);
test_num_points<open_multi_polygon>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 10,1 10,1 9,0 10)))", 9u, 11u);
return 0;
}