Skip to content

Commit

Permalink
Geometry::intersects: support CurvePolygon/Point arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Jul 18, 2024
1 parent f5084f8 commit 4586861
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/geom/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <geos/algorithm/InteriorPointLine.h>
#include <geos/algorithm/InteriorPointArea.h>
#include <geos/algorithm/ConvexHull.h>
#include <geos/algorithm/locate/SimplePointInAreaLocator.h>
#include <geos/geom/prep/PreparedGeometryFactory.h>
#include <geos/operation/intersection/Rectangle.h>
#include <geos/operation/intersection/RectangleIntersection.h>
Expand Down Expand Up @@ -310,11 +311,18 @@ Geometry::intersects(const Geometry* g) const
return predicate::RectangleIntersects::intersects(*p, *this);
}

if (getGeometryTypeId() == GEOS_GEOMETRYCOLLECTION) {
auto typ = getGeometryTypeId();
if (typ == GEOS_GEOMETRYCOLLECTION) {
auto im = relate(g);
bool res = im->isIntersects();
return res;
} else {
} else if (typ == GEOS_CURVEPOLYGON && g->getGeometryTypeId() == GEOS_POINT) {
auto loc = locate::SimplePointInAreaLocator::locatePointInSurface(*g->getCoordinate(), *detail::down_cast<const Surface*>(this));
return loc != Location::EXTERIOR;
} else if (typ == GEOS_POINT && g->getGeometryTypeId() == GEOS_CURVEPOLYGON) {
auto loc = locate::SimplePointInAreaLocator::locatePointInSurface(*getCoordinate(), *detail::down_cast<const Surface*>(g));
return loc != Location::EXTERIOR;
} else {
return prep::PreparedGeometryFactory::prepare(this)->intersects(g);
}
}
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/capi/GEOSIntersectsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,30 @@ void object::test<11>()
ensure_equals("curved geometry not supported", GEOSIntersects(geom2_, geom1_), 2);
}

// test PIP special case for CurvePolygon
template<>
template<>
void object::test<12>()
{
geom1_ = fromWKT("CURVEPOLYGON (COMPOUNDCURVE(CIRCULARSTRING(0 0, 1 1, 2 0), (2 0, 0 0)))");
geom2_ = fromWKT("POINT (0.1556955 0.5355459)");

// PostGIS would return false here because geom2 is inside geom1
// but outside the linearized form of geom1
ensure_equals(GEOSIntersects(geom1_, geom2_), 1);
ensure_equals(GEOSIntersects(geom2_, geom1_), 1);
}

template<>
template<>
void object::test<13>()
{
geom1_ = fromWKT("CURVEPOLYGON (COMPOUNDCURVE(CIRCULARSTRING(0 0, 1 1, 2 0), (2 0, 0 0)))");
geom2_ = fromWKT("POINT EMPTY");

ensure_equals(GEOSIntersects(geom1_, geom2_), 0);
ensure_equals(GEOSIntersects(geom2_, geom1_), 0);
}

} // namespace tut

0 comments on commit 4586861

Please sign in to comment.