From 0ac8b51b4156d31569c54f9f5f72ce183c656c58 Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 14 Feb 2018 17:06:25 +0100 Subject: [PATCH] [test] test simplifying away closing point / whole polygon --- test/algorithms/simplify.cpp | 10 ++++++++++ test/algorithms/test_simplify.hpp | 22 ++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/test/algorithms/simplify.cpp b/test/algorithms/simplify.cpp index 730f4fec3..8852096e9 100644 --- a/test/algorithms/simplify.cpp +++ b/test/algorithms/simplify.cpp @@ -155,6 +155,16 @@ void test_all() "POLYGON((0 0,0 5,5 5,5 0,4 0,3 0,2 0,1 0,0 0))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", 0.1); + // Test simplifying away one of the sides (collinear), then closing point + // and finally the whole polygon + std::string const near_triangle = "POLYGON((0.55 0.55,1 0,0.5 0,0 0,0 1,0.55 0.55))"; + test_geometry >(near_triangle, + "POLYGON((0.55 0.55,1 0,0 0,0 1,0.55 0.55))", 0.1, 6); + test_geometry >(near_triangle, + "POLYGON((1 0,0 0,0 1,1 0))", 0.6, 6); + test_geometry >(near_triangle, + "POLYGON(())", 0.9, 6); + // Test simplifying away the closing point, and closing it explicitly std::string const salamina = "POLYGON((2616131.59828 4579307.29099,2616687.86177 4579151.05325,2618172.52982 4578718.79836,2618728.79332 4578522.73574,2620336.91468 4577424.54293,2620522.48427 4576992.50129,2621264.76264 4569815.3917,2621140.75272 4569502.07546,2620491.53745 4568208.96982,2620151.34509 4567855.90928,2612606.55528 4562800.36094,2611833.3301 4562291.50023,2611369.5731 4562174.16117,2610225.54269 4562408.69959,2605896.21638 4564367.29512,2605494.13038 4564641.6634,2605277.94792 4566288.44857,2606019.89233 4569423.46562,2609050.12019 4577424.54293,2614337.90732 4579347.12775,2615296.7021 4579543.34723,2616131.59828 4579307.29099))"; test_geometry >(salamina, 195902881.31854457, 100); diff --git a/test/algorithms/test_simplify.hpp b/test/algorithms/test_simplify.hpp index 265d1a7a9..3e02e1287 100644 --- a/test/algorithms/test_simplify.hpp +++ b/test/algorithms/test_simplify.hpp @@ -78,17 +78,17 @@ struct test_inserter } }; - template void check_geometry(Geometry const& geometry, std::string const& expected, - DistanceMeasure const& distance) + DistanceMeasure const& distance, + int precision = 12) { Geometry simplified; bg::simplify(geometry, simplified, distance); std::ostringstream out; - out << std::setprecision(12) << bg::wkt(simplified); + out << std::setprecision(precision) << bg::wkt(simplified); BOOST_CHECK_EQUAL(out.str(), expected); } @@ -96,13 +96,14 @@ template void check_geometry(Geometry const& geometry, std::string const& expected, DistanceMeasure const& distance, - Strategy const& strategy) + Strategy const& strategy, + int precision = 12) { Geometry simplified; bg::simplify(geometry, simplified, distance, strategy); std::ostringstream out; - out << std::setprecision(12) << bg::wkt(simplified); + out << std::setprecision(precision) << bg::wkt(simplified); BOOST_CHECK_EQUAL(out.str(), expected); } @@ -121,7 +122,8 @@ void check_geometry(Geometry const& geometry, template void test_geometry(std::string const& wkt, std::string const& expected, - DistanceMeasure distance) + DistanceMeasure distance, + int precision = 12) { typedef typename bg::point_type::type point_type; @@ -136,14 +138,14 @@ void test_geometry(std::string const& wkt, bg::strategy::distance::projected_point > dp; - check_geometry(geometry, expected, distance); - check_geometry(v, expected, distance); + check_geometry(geometry, expected, distance, precision); + check_geometry(v, expected, distance, precision); BOOST_CONCEPT_ASSERT( (bg::concepts::SimplifyStrategy) ); - check_geometry(geometry, expected, distance, dp()); - check_geometry(v, expected, distance, dp()); + check_geometry(geometry, expected, distance, dp(), precision); + check_geometry(v, expected, distance, dp(), precision); // Check inserter (if applicable) test_inserter