Repository navigation
Conversation
Splits the triangulation until no edge is longer than a limit, splitting each edge at its middle from both sides, after flipping long slivers into rounder triangles. It's for renderers that project triangle corners and join them with straight lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Triangulating takes longitude and latitude as flat coordinates, so a ring that crosses the antimeridian, or goes around a pole as Antarctica's often does, needs its longitudes to run on, and the latter needs closing along the pole. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
Written by Claude on Adrian's behalf. Suggested squash-merge message: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
triangleIndices()gives a polygon's triangles as they come out of earcut: as few as possible, and often long and thin. That's what you want for filling the polygon on a flat plane, but not for renderers that project each triangle's corners and join them with straight lines, such as a GPU vertex shader or a CoreGraphics path. Those need two more things, which this PR adds.triangles(maxEdgeDegrees:): small trianglesA straight edge only follows a curved projection when it's short. Also, near a map's edge or across its seam, only a small triangle can be left out or cut without anyone noticing. So this keeps triangulating the same way, then:
All triangles come out counter-clockwise.
triangleIndices()itself is unchanged, andmaxEdgeDegrees: .infinitygives exactly its triangles as positions.unwrapped(): rings that don't jump across the antimeridianBoth triangulation calls take longitude and latitude as flat coordinates, which goes wrong for:
unwrapped()lets longitudes run on past ±180° so that each step is under 180°. It closes a ring that ends a turn away from where it started along its pole, setting off from the corner closest to the pole so the closing edge doesn't cut across the ring. It moves holes by whole turns to sit with the exterior, and drops the back-and-forth edges along the antimeridian that pre-split rings have.Both functions were first written for one app's GPU renderer and have been used there. Moving them here lets other renderers share them.
Testing
swift test. The newRefinedTrianglesTestscheck that:.infinitygives back whattriangleIndices()gives;For
unwrapped(), they check that each step is under 180° (except along a pole) and that the triangles' area adds up. The cases are rings across the antimeridian, holes across it or a turn away, rings around either pole, one that starts over a bay, and one already split along the pole. A polygon that doesn't wrap comes back unchanged.🤖 Generated with Claude Code