Skip to content

Fix Feature.contains for GeometryCollection geometries - #265

Merged
trasch merged 1 commit into
mainfrom
fix/contains-geometrycollection
Oct 19, 2026
Merged

trasch merged 1 commit into
mainfrom
fix/contains-geometrycollection

Conversation

@trasch

@trasch trasch commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Feature.contains and FeatureCollection.contains always returned false for features whose geometry is a GeometryCollection, even though GeometryCollection.contains itself worked.

Root cause

Feature.contains guarded on PolygonGeometry:

guard let polygonGeometry = snappedSelf.geometry as? PolygonGeometry else { return false }

GeometryCollection does not conform to PolygonGeometry, so the feature was never matched. FeatureCollection.contains delegates to Feature.contains and inherited the bug.

Changes

  • Feature.contains now dispatches on the concrete geometry: PolygonGeometry → its contains, GeometryCollection → GeometryCollection.contains, otherwise false.
  • GeometryCollection.contains now recurses into nested GeometryCollections, so a collection-wrapping-collection resolves to its polygon members instead of being silently ignored. This keeps Feature and GeometryCollection behaviour consistent.

Tests

Added to BooleanPointInPolygonTests:

Full suite: 2579 tests / 192 suites pass. With the fix reverted, the new featureContainsGeometryCollection* tests fail as expected, so the regression tests are effective.

Fixes #259

Feature.contains guarded on PolygonGeometry, so features wrapping a GeometryCollection always returned false; FeatureCollection.contains inherited the bug. Dispatch on the concrete geometry and delegate to GeometryCollection.contains.

Make GeometryCollection.contains recurse into nested collections so a collection-wrapping-collection resolves to its polygon members.

Add tests for Feature/FeatureCollection containment, nested collections, non-polygon collections, and EPSG:4326/3857/4978/noSRID coverage.

Fixes #259
@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 f1cf760 into main Oct 19, 2026
1 check passed
@trasch
trasch deleted the fix/contains-geometrycollection branch October 19, 2026 14:11
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

Development

Successfully merging this pull request may close these issues.

Feature.contains and FeatureCollection.contains always return false for features whose geometry is a GeometryCollection

1 participant