diff options
Diffstat (limited to 'libs/geometry/test/algorithms/centroid.cpp')
-rw-r--r-- | libs/geometry/test/algorithms/centroid.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/libs/geometry/test/algorithms/centroid.cpp b/libs/geometry/test/algorithms/centroid.cpp index 8e3af7f75..dc6993996 100644 --- a/libs/geometry/test/algorithms/centroid.cpp +++ b/libs/geometry/test/algorithms/centroid.cpp @@ -5,8 +5,8 @@ // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. -// This file was modified by Oracle on 2014. -// Modifications copyright (c) 2014 Oracle and/or its affiliates. +// This file was modified by Oracle on 2014, 2015. +// Modifications copyright (c) 2014-2015 Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle @@ -29,7 +29,6 @@ BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) - template <typename Polygon> void test_polygon() { @@ -42,10 +41,21 @@ void test_polygon() test_centroid<Polygon>( "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2" ",3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)" - ",(4 2,4.2 1.4,4.8 1.9,4.4 2.2,4 2))" - , + ",(4 2,4.2 1.4,4.8 1.9,4.4 2.2,4 2))", 4.0466264962959677, 1.6348996057331333); + test_centroid<Polygon>("POLYGON((0 0,0 10,10 10,10 0,0 0))", 5.0, 5.0); + test_centroid<Polygon>("POLYGON((-10 0,0 0,0 -10,-10 -10,-10 0))", -5.0, -5.0); + + // invalid, self-intersecting polygon (area = 0) + test_centroid<Polygon>("POLYGON((1 1,4 -2,4 2,10 0,1 0,10 1,1 1))", 1.0, 1.0); + // invalid, degenerated + test_centroid<Polygon>("POLYGON((1 1,1 1,1 1,1 1))", 1.0, 1.0); + test_centroid<Polygon>("POLYGON((1 1))", 1.0, 1.0); + + // should (1.5 1) be returned? + // if yes, then all other Polygons degenerated to Linestrings should be handled + test_centroid<Polygon>("POLYGON((1 1,2 1,1 1,1 1))", 1.0, 1.0); } @@ -56,6 +66,13 @@ void test_2d() test_centroid<bg::model::linestring<P> >("LINESTRING(0 0,0 4, 4 4)", 1.0, 3.0); test_centroid<bg::model::linestring<P> >("LINESTRING(0 0,3 3,0 6,3 9,0 12)", 1.5, 6.0); + test_centroid<bg::model::linestring<P> >("LINESTRING(1 1,10 1,1 0,10 0,4 -2,1 1)", + 5.41385255923004, 0.13507358481085); + + // degenerated linestring (length = 0) + test_centroid<bg::model::linestring<P> >("LINESTRING(1 1, 1 1)", 1.0, 1.0); + test_centroid<bg::model::linestring<P> >("LINESTRING(1 1)", 1.0, 1.0); + test_centroid<bg::model::segment<P> >("LINESTRING(1 1, 3 3)", 2.0, 2.0); test_centroid<bg::model::ring<P> >( |