Skip to content

Add Gosper island boundary edge iterator#1138

Open
ajfriend wants to merge 4 commits intouber:masterfrom
ajfriend:gosper_iter
Open

Add Gosper island boundary edge iterator#1138
ajfriend wants to merge 4 commits intouber:masterfrom
ajfriend:gosper_iter

Conversation

@ajfriend
Copy link
Copy Markdown
Collaborator

@ajfriend ajfriend commented Mar 10, 2026

Closes #1114

Adds IterEdgesGosper, an iterator that yields the directed edges forming the boundary (Gosper island outline) of a cell's child set at a given resolution.

  • Each edge's origin cell is a child of the parent cell; its destination cell is not
  • Edges form a closed counter-clockwise loop
  • For a parent at resolution r expanded to child resolution R: hexagons produce 6 * 3^(R-r) edges, pentagons produce 5 * 3^(R-r)
  • For now, this is an internal-only iterator, not included in the public API

Usage

IterEdgesGosper iter = iterInitGosper(cell, childRes);
while (iter.e) {
    // iter.e is the current directed edge
    // iter.remaining is the number of edges left
    iterStepGosper(&iter);
}

Next step: Speed up cellsToMultiPolygon

This is a building block for a faster cellsToMultiPolygon. When given a pre-compacted input cell set, the iterator allows the cellsToMultiPolygon algorithm to walk the Gosper island boundary edges directly, skipping all internal edges. On a Colorado polygon at resolution 8, this yields a 35x speedup. The higher the resolution, the better the speedup. This speedup is separate from the 3-4x improvement already achieved with the new cellsToMultiPolygon algorithm.

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 10, 2026

Coverage Status

coverage: 99.081% (-0.01%) from 99.095%
when pulling d96092e on ajfriend:gosper_iter
into 1d5346b on uber:master.

@ajfriend
Copy link
Copy Markdown
Collaborator Author

Talk explaining how this fits in: https://ajfriend.com/h3c2p-talk/


// H3 edge direction at each edge index, in counter-clockwise order around the
// hexagon. Stored in the directed edge's reserved bits.
static const int8_t edge_dir[] = {3, 1, 5, 4, 6, 2};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also write this with type Direction and use I_AXIS_DIGIT, etc.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's better. Updated.

I left some comments on the numeric sequence, because I think that makes it easier to see the shared pattern.

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.

Implement iterator for edges in "Gosper Island"

3 participants