Repository navigation
h3: add geodesic polygon filling - #179
Open
justinhwang wants to merge 1 commit into
Open
justinhwang wants to merge 1 commit into
justinhwang wants to merge 1 commit into
Conversation
Coverage Report for CI Build 41139745511Coverage remained the same at 100.0%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
PolygonToCellsExperimental accepts a ContainmentGeodesic flag on the center, full and overlapping modes that treats polygon edges as great-circle arcs instead of straight lines in latitude and longitude. Loops become unit vectors with per-edge plane normals and bounding boxes, points are tested by spherical winding behind a hemisphere-pole reject, and the traversal descends from the base cells, pruning coarse cells whose caps cannot touch the polygon. Two measured changes from the reference proposal: the cell cap radius is 1.05 edge lengths rather than 1.01, because grandchildren reach 3.5% past their grandparent's edge length and were pruned away; and a cap around the outer loop is tested alongside the Cartesian box, whose far corner lies off the sphere and let cells 14° away survive, so Colorado examines 2,541 cells instead of 41,370 for 1,051 returned. Cell boundaries are built as unit vectors and converted in a final loop, which the geodesic fill reads directly and which makes CellToBoundary about 25% faster. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
justinhwang
force-pushed
the
feat/geodesic-polyfill
branch
from
October 30, 2026 22:41
2fdaafa to
a77dfdf
Compare
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.
Summary
Adds geodesic polygon filling to
PolygonToCellsExperimental, ported from thereference library's open proposal. Setting the new
ContainmentGeodesicflag(bit 16) on
ContainmentCenter,ContainmentFullorContainmentOverlappingtreats polygon edges as great-circle arcs instead ofstraight lines in latitude and longitude.
The planar fill is unchanged; the flag selects a separate traversal:
great-circle normal and a Cartesian bounding box that accounts for the arc's
extrema, and each loop keeps its centroid and a hemisphere pole used to
reject far-side points before the spherical winding test.
CenterChild,pruning any coarse cell whose bounding cap cannot touch the polygon.
three containment modes decide from center containment, crossing, and
whether a loop vertex lies inside the cell.
vertex on one great circle, is
ErrDomain, andContainmentGeodesicwithContainmentOverlappingBboxor an invalid base mode isErrOptionInvalid.Cell boundaries are now computed as unit vectors first and converted to
latitude and longitude in a final loop. The geodesic fill reads the vectors
directly, and
CellToBoundarygets about 25% faster from the tighter loop.Two deviations from the reference
Cap scale factor. The reference bounds a cell with a cap of radius
1.01 × maxEdgeLength[res]. Measured against every cell at resolutions 0 to2, that holds the cell and its children but not its grandchildren, whose
boundary vertices reach about 3.5% beyond the edge length, and deeper
descendants reach about 4.5%. A polygon touching only such a vertex is pruned
at the coarse level and the descendant is dropped from an
OVERLAPPINGfill.This port uses
1.05, which encloses every descendant three levels down forall cells at resolutions 0 to 2. The reference fixtures' cell counts are
unchanged. I will report the finding upstream.
Bounding cap of the polygon. The reference prunes a coarse cell by
testing its cap against the polygon's Cartesian box through the box's far
corner. That corner lies outside the unit sphere, so the test is loose: for
Colorado, resolution 4 cells up to about 14° away survive and the traversal
examined 41,370 resolution 5 cells to return 1,051. This port also keeps a
bounding cap of the outer loop, centered on its hemisphere pole with the
farthest vertex as radius (an arc's farthest point from the pole is always a
vertex once the loop fits a hemisphere), and prunes a cell when the two caps
are disjoint. Both tests are conservative, so the results are identical.
Accuracy
degenerate, a point and a line loop) produce exactly the reference counts in
each mode.
test: a 360-gon inscribed in a 20° spherical circle, and a quadrilateral
between 30°N and 40°N spanning 120°W to 60°W, where the arc latitude between
two points on a parallel has a closed form. The geodesic center fill matches
the oracle on every cell. The planar fill is wrong on 1,737 of the
quadrilateral's resolution 4 cells, the band between the 40°N chord and the
arc that climbs to 44.1°N at 90°W.
FULL-mode cells smaller than a polygon or holding a hole, and a tinytriangle on every boundary vertex of every resolution 2 cell to pin the cap
factor.
Benchmarks
Overlapping mode,
-count=10, benchstat against master:Geodesic filling costs 2 to 4 times the planar fill on these polygons. With
the reference's box-only prune it cost 30 to 70 times.
Test plan
go test -count=1 -race -covermode atomic -coverprofile ./...passes with 100% coverage on both packagesgolangci-lint run ./...reports no issues