Skip to content

Port pole-of-inaccessibility (polylabel) (#21)#89

Merged
trasch merged 3 commits into
mainfrom
21_polylabel
Jun 3, 2026
Merged

Port pole-of-inaccessibility (polylabel) (#21)#89
trasch merged 3 commits into
mainfrom
21_polylabel

Conversation

@trasch
Copy link
Copy Markdown
Contributor

@trasch trasch commented May 8, 2026

Summary

Ported polylabel (Mapbox) algorithm for finding the pole of inaccessibility.

Sources/GISTools/Algorithms/PoleOfInaccessibility.swift

Polygon.poleOfInaccessibility(precision:) -> Point? — finds the most distant internal point from the polygon outline.

  • Uses a priority-queue grid search
  • Starts with the polygon centroid and bounding box center as guesses
  • Subdivides the most promising cells until precision threshold is met
  • Handles holes (all rings are considered for distance)
  • Returns nil for polygons without an outer ring

Tests/PoleOfInaccessibilityTests.swift (5 tests)

Test Coverage
squarePole Square center
trianglePole Triangle interior
poleWithPrecision High and low precision
poleLShaped Concave L-shape
poleNoOuterRing Empty polygon → nil

README

Updated pole-of-inaccessibility from TODO to example with test link.

Test results

271 tests pass across 60 suites (+5 new).


Closes #21

Implements Polygon.poleOfInaccessibility(precision:) using
Mapbox's polylabel grid-search algorithm. Returns the most
distant interior point from the polygon outline.
@trasch trasch self-assigned this Jun 3, 2026
@trasch trasch added the enhancement New feature or request label Jun 3, 2026
@trasch trasch merged commit 6ab9736 into main Jun 3, 2026
1 check passed
@trasch trasch deleted the 21_polylabel branch June 3, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port pole-of-inaccessibility

1 participant