Skip to content

Don't bridge a hole to a vertex that faces away from it - #220

Closed
EpicDima wants to merge 1 commit into
mapbox:mainfrom
EpicDima:epicdima/bridge-healed-twin
Closed

EpicDima wants to merge 1 commit into
mapbox:mainfrom
EpicDima:epicdima/bridge-healed-twin

Conversation

@EpicDima

Copy link
Copy Markdown
Contributor

Fixes #219

When filterPoints removes the bridge copy of a vertex, the outer ring runs straight through that vertex. A later hole's ray can then hit the vertex and the healed edge at the same x, and findHoleBridge picks the vertex although the hole is outside its angle. With this PR, if a point was filtered out during hole elimination and the hit vertex doesn't face the hole, the bridge goes to the edge through that vertex.

polygon main this PR
example from #219 7 triangles, deviation 0.089 11 triangles, deviation 0
the same scaled by 0.12 in x and 3 in y 7 triangles, deviation 0.089 11 triangles, deviation 0
noisy raster region, 65426 vertices, 9113 holes triangles cover 1.3% more area than the polygon exact area
noisy raster region, 161064 vertices, 22662 holes 0.85% more area exact area

The new test covers both small polygons. It fails on main and passes with this PR.

Details
  • The output is identical to main's on the fixtures, all tile polygons from the benchmark and generated shapes. On a million random small polygons it differs on 50, all of them invalid.
  • The tile benchmark is within 1% of main. Small polygons with holes, where the check costs the most relative to the work, stay within main's run-to-run spread over six runs.

When filterPoints removes the bridge copy of a vertex, the outer ring runs straight through that vertex. A later hole's ray can then hit the vertex and the healed edge at the same x, and findHoleBridge picks the vertex although the hole is outside its angle. If a point was filtered out during hole elimination and the hit vertex doesn't face the hole, bridge to the edge through that vertex instead.
@EpicDima
EpicDima requested a review from a team as a code owner October 17, 2026 19:33
@EpicDima
EpicDima requested review from dcoj and removed request for a team October 17, 2026 19:33
@mourner

mourner commented Oct 17, 2026

Copy link
Copy Markdown
Member

Thanks! Also fixed with a much smaller change — I want to keep the code small and not add new complexity if possible. 77019d3

@mourner mourner closed this Oct 17, 2026
@EpicDima

Copy link
Copy Markdown
Contributor Author

Nice fix, much simpler than mine 👍
Keeping bridge2 stops the problem where it starts, and it also handles a few float cases my PR still got wrong. There's still a mirror case with bridge itself, I opened #221 for it

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.

Overlapping triangles on a simple polygon with two holes since 3.1.0

2 participants