Skip to content

Port boolean-crosses from turf (#12)#79

Open
trasch wants to merge 2 commits into
mainfrom
12_boolean_crosses
Open

Port boolean-crosses from turf (#12)#79
trasch wants to merge 2 commits into
mainfrom
12_boolean_crosses

Conversation

@trasch
Copy link
Copy Markdown
Contributor

@trasch trasch commented May 8, 2026

Summary

Ported turf-boolean-crosses from Turf.js to Swift per OpenGIS Simple Features spec.

Returns true if the intersection of two geometries results in a geometry whose dimension is one less than the maximum dimension of the two source geometries, and the intersection set is interior to both.

Supported combinations

Geometry 1 Geometry 2 Behavior
MultiPoint LineString Some points on line interior, some exterior
MultiPoint Polygon / MultiPolygon Some points inside, some outside
LineString LineString Intersection at non-endpoint
LineString Polygon / MultiPolygon Line intersects polygon boundary
Feature any Unwraps to geometry automatically
FeatureCollection any Checks each contained feature
Unsupported pairs Returns false

Changes

Sources/GISTools/Algorithms/BooleanCrosses.swift

  • Replaced // TODO with full implementation
  • GeoJson.crosses(_:) -> Bool — main entry point
  • Handles Feature unwrapping and FeatureCollection flattening
  • Private helpers for each geometry pair + isPointOnLineSegment utility
  • Coordinate3D.isCoincident(to:) helper for endpoint tolerance check

Tests/GISToolsTests/Algorithms/BooleanCrossesTests.swift — 16 tests

  • LineString × LineString crossing, non-crossing (parallel), endpoint-touching
  • MultiPoint × LineString / MultiPoint × Polygon crossing + non-crossing
  • LineString × Polygon / LineString × MultiPolygon crossing + non-crossing
  • Feature unwrapping, FeatureCollection support
  • Unsupported combinations return false
  • Commutativity check

Test results

All 282 tests pass across 60 suites (was 266, +16 new).


Closes #12

trasch added 2 commits May 8, 2026 18:17
Implements booleanCrosses per the OpenGIS Simple Features spec, ported
from turf-boolean-crosses. Supports MultiPoint/LineString,
MultiPoint/Polygon, LineString/LineString, and LineString/Polygon
comparisons. Also handles Feature and FeatureCollection inputs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port boolean-crosses

1 participant