[test] test simplifying away closing point / whole polygon

This commit is contained in:
Barend Gehrels 2018-02-14 17:06:25 +01:00
parent 00389227b2
commit 0ac8b51b41
2 changed files with 22 additions and 10 deletions

View File

@ -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<bg::model::polygon<P> >(near_triangle,
"POLYGON((0.55 0.55,1 0,0 0,0 1,0.55 0.55))", 0.1, 6);
test_geometry<bg::model::polygon<P> >(near_triangle,
"POLYGON((1 0,0 0,0 1,1 0))", 0.6, 6);
test_geometry<bg::model::polygon<P> >(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<bg::model::polygon<P> >(salamina, 195902881.31854457, 100);

View File

@ -78,17 +78,17 @@ struct test_inserter<bg::linestring_tag, Geometry>
}
};
template <typename Geometry, typename DistanceMeasure>
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 <typename Geometry, typename Strategy, typename DistanceMeasure>
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 <typename Geometry, typename DistanceMeasure>
void test_geometry(std::string const& wkt,
std::string const& expected,
DistanceMeasure distance)
DistanceMeasure distance,
int precision = 12)
{
typedef typename bg::point_type<Geometry>::type point_type;
@ -136,14 +138,14 @@ void test_geometry(std::string const& wkt,
bg::strategy::distance::projected_point<double>
> 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<dp, point_type>) );
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