Skip to content

Port convex hull from turf (#51)#86

Open
trasch wants to merge 2 commits into
mainfrom
51_convex_hull
Open

Port convex hull from turf (#51)#86
trasch wants to merge 2 commits into
mainfrom
51_convex_hull

Conversation

@trasch
Copy link
Copy Markdown
Contributor

@trasch trasch commented May 8, 2026

Summary

Ported convex hull algorithm using Andrew's monotone chain algorithm.

Sources/GISTools/Algorithms/ConvexHull.swift

GeoJson.convexHull() -> Polygon? — computes the convex hull of all coordinates in any geometry or feature.

  • Uses monotone chain (O(n log n))
  • Handles anti-meridian spanning by shifting negative longitudes to [0, 360]
  • Deduplicates coordinates via Set
  • Returns nil for < 3 distinct points

Tests/ConvexHullTests.swift (7 tests)

Test Coverage
convexHullSquare 4 corners
convexHullTriangle 3 corners
convexHullWithInteriorPoint Interior point excluded from hull
convexHullCollinearTop Collinear points on top edge
convexHullInsufficientPoints < 3 points → nil
convexHullLineString From LineString input
convexHullFeature From Feature wrapper

Test results

273 tests pass across 60 suites (+7 new).


Closes #51

trasch added 2 commits May 8, 2026 18:52
Implements GeoJson.convexHull() returning a Polygon using
Andrew's monotone chain algorithm. Handles anti-meridian
spanning, collinear points, and deduplication.
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 turf-concave and turf-convex

1 participant