Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid values from CoverageUnionNG #1226

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/operation/overlayng/CoverageUnion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace overlayng { // geos.operation.overlayng
std::unique_ptr<Geometry>
CoverageUnion::geomunion(const Geometry* coverage)
{
double area_in = coverage->getArea();
std::unique_ptr<Geometry> result;

// a precision model is not needed since no noding is done
Expand All @@ -47,9 +46,10 @@ CoverageUnion::geomunion(const Geometry* coverage)
result = OverlayNG::geomunion(coverage, nullptr, &bcn);
}

double area_out = result->getArea();
double area_in = coverage->getArea();

if (std::abs((area_out - area_in)/area_in) > AREA_PCT_DIFF_TOL) {
if ( (area_in != 0.0) &&
(std::abs((result->getArea() - area_in)/area_in) > AREA_PCT_DIFF_TOL)) {
throw geos::util::TopologyException("CoverageUnion cannot process overlapping inputs.");
}

Expand Down
30 changes: 30 additions & 0 deletions tests/unit/operation/overlayng/CoverageUnionNGTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <geos/util.h>

// std
#include <cfenv>
#include <memory>

using namespace geos::geom;
Expand All @@ -32,7 +33,9 @@ struct test_coverageunionng_data {
{
std::unique_ptr<Geometry> geom = r.read(wkt);
std::unique_ptr<Geometry> expected = r.read(wktExpected);
std::feclearexcept(FE_ALL_EXCEPT);
std::unique_ptr<Geometry> result = CoverageUnion::geomunion(geom.get());
ensure("FE_INVALID raised", !std::fetestexcept(FE_INVALID));

try {
ensure_equals_geometry_xyzm(result.get(), expected.get());
Expand Down Expand Up @@ -222,4 +225,31 @@ void object::test<17>()
"POLYGON M ((0 0 0, 1 0 1, 1 1 2, 0 1 3, 0 0 0))");
}

// Check empty polygon
template<>
template<>
void object::test<18>()
{
checkUnion("POLYGON EMPTY",
"POLYGON EMPTY");
}

// Check empty GeometryCollection, with M dimension
template<>
template<>
void object::test<19>()
{
checkUnion("GEOMETRYCOLLECTION M EMPTY",
"GEOMETRYCOLLECTION M EMPTY");
}

// Check GeometryCollection of empty polygon
template<>
template<>
void object::test<20>()
{
checkUnion("GEOMETRYCOLLECTION( POLYGON EMPTY )",
"POLYGON EMPTY");
}

} // namespace tut
Loading