Skip to content

Commit

Permalink
Fix PreparedPolygonContains for GC with MultiPoint (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts authored Dec 5, 2023
1 parent b3d6d20 commit 136e8e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/geom/prep/AbstractPreparedPolygonContains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ bool AbstractPreparedPolygonContains::evalPointTestGeom(const Geometry *geom, Lo
if (outermostLoc == Location::EXTERIOR) {
return false;
}

// For the Covers predicate, we can return true
// since no Points are on the exterior of the target
// geometry.
Expand All @@ -195,19 +194,18 @@ bool AbstractPreparedPolygonContains::evalPointTestGeom(const Geometry *geom, Lo
}

// For the Contains predicate, we need to test if any
// of those points lie in the interior of the target
// of the test points lie in the interior of the target
// geometry.
if (outermostLoc == Location::INTERIOR) {
return true;
}

if (geom->getNumGeometries() > 1) {
// for MultiPoint, try to find at least one point
// in interior
return isAnyTestComponentInTargetInterior(geom);
// a single point must not be in interior
if (geom->getNumPoints() <= 1) {
return false;
}

return false;
// for multiple points have to check all
return isAnyTestComponentInTargetInterior(geom);
}

//
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/geom/prep/PreparedGeometryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,19 @@ void object::test<2>
ensure( pg1->intersects(g2.get()) );
}

// See https://github.com/libgeos/geos/issues/1007
template<>
template<>
void object::test<3>
()
{
g1 = reader.read( "MULTIPOLYGON(((-60 -50,-70 -50,-60 -40,-60 -50)))" );
g2 = reader.read( "GEOMETRYCOLLECTION(MULTIPOINT((-60 -50),(-63 -49)))" );

pg1 = prep::PreparedGeometryFactory::prepare(g1.get());

ensure( g1->contains(g2.get()) );
ensure( pg1->contains(g2.get()) );
}

} // namespace tut

0 comments on commit 136e8e4

Please sign in to comment.