Skip to content

Align point containment with OGC/PostGIS semantics - #266

Merged
trasch merged 1 commit into
mainfrom
fix/ogc-point-containment
Oct 20, 2026
Merged

trasch merged 1 commit into
mainfrom
fix/ogc-point-containment

Conversation

@trasch

@trasch trasch commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Aligns point containment with OGC Simple Features / PostGIS naming, fixing the hole-boundary inversion from #257. Turf was only the porting reference; OGC/PostGIS is now the semantic reference.

New API

public enum PointLocation { case interior, boundary, exterior }

Available on Ring, Polygon, MultiPolygon, GeometryCollection, Feature and FeatureCollection, for both Coordinate3D and Point:

API OGC/PostGIS equivalent
contains(_:) ST_Contains: interior only
covers(_:) ST_Covers: interior or boundary
locate(_:) JTS/GEOS Location

contains(_:ignoringBoundary:gridSize:) is removed. gridSize: remains on all three methods.

Hole semantics

Polygon.locate now mirrors JTS SimplePointInAreaLocator:

  • outer ring exterior → .exterior
  • outer ring boundary → .boundary
  • hole boundary → .boundary (previously treated as outside the polygon or inside the hole depending on the flag)
  • hole interior → .exterior
  • otherwise .interior

Changes

  • All 34 internal ignoringBoundary call sites migrated explicitly: true → contains, false → covers. This preserves the intended behaviour in touches, difference, union, intersection, symmetric difference, overlay, mask, collect, disjoint, crosses, polygonize and PointsWithinPolygon.
  • PolygonGeometry protocol requirements updated to locate/contains/covers.
  • CHANGELOG.md added with the breaking-change section and migration table.

Tests

  • 2,586 tests / 192 suites pass; clean build, no warnings.
  • Boundary matrix for outer/hole boundaries and vertices, asserting both predicates and locate.
  • Enclave test: a shared boundary is covered by both polygons and contained by neither.
  • Feature, FeatureCollection, MultiPolygon and nested GeometryCollection coverage.
  • EPSG:4326, 3857, 4978 and noSRID coverage. Two EPSG:4978 tests were corrected to use realistic ECEF geometries instead of coordinates at the Earth's centre; they previously passed only because contains included the boundary.

Follow-up

Geometry-level GeoJson.contains(_:) / covers(_:) for line and polygon operands still use boundary-inclusive vertex checks. The interior-only split with segment-aware coverage is the next step, as noted in CHANGELOG.md and the doc comments.

Fixes #257

Point containment on Ring, Polygon, MultiPolygon, GeometryCollection, Feature and FeatureCollection now follows OGC/PostGIS naming:

- contains(_:) is interior-only (ST_Contains)
- covers(_:) includes the boundary (ST_Covers)
- locate(_:) returns .interior/.boundary/.exterior (JTS/GEOS Location)

Remove the ignoringBoundary parameter and update all internal call sites to state their intent explicitly. A point on a hole boundary is now classified as .boundary, matching JTS SimplePointInAreaLocator and fixing the inverted hole-boundary behaviour (#257).

Add CHANGELOG.md documenting the breaking API changes and the migration mapping.
@trasch trasch added the bug Something isn't working label Oct 19, 2026
@trasch trasch self-assigned this Oct 19, 2026
@trasch
trasch merged commit 40a9224 into main Oct 20, 2026
1 check passed
@trasch
trasch deleted the fix/ogc-point-containment branch October 20, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

1 participant