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 committed Dec 5, 2023
1 parent ba32d54 commit e00254f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/geom/prep/AbstractPreparedPolygonContains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,12 @@ bool AbstractPreparedPolygonContains::evalPointTestGeom(const Geometry *geom, Lo
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
30 changes: 30 additions & 0 deletions tests/unit/geom/prep/PreparedGeometryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,34 @@ void object::test<1>
ensure( pg1->covers(g2.get()));
}

// See https://trac.osgeo.org/postgis/ticket/5601
template<>
template<>
void object::test<2>
()
{
g1 = reader.read( "LINESTRING(-1 0,0 0)" );
g2 = reader.read( "GEOMETRYCOLLECTION(MULTIPOINT(-1 0),LINESTRING(0 -1,1 0))" );

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

ensure( g1->intersects(g2.get()) );
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 e00254f

Please sign in to comment.