Add Gosper island boundary edge iterator#1138
Conversation
|
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}; |
There was a problem hiding this comment.
You could also write this with type Direction and use I_AXIS_DIGIT, etc.
There was a problem hiding this comment.
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.
| for (i = 0; iter.e; i++) { | ||
| H3Index prev = iter.e; | ||
| iterStepGosper(&iter); | ||
| t_assert(iter.e != prev, "edge should advance"); |
There was a problem hiding this comment.
This checks that the new cell is different but not necessarily unique (i.e., the iterator could swap between two different values and still pass this test). The comment on this function implies a more involved test that the same value will not be returned twice.
I guess this is handled practically by do_edges_connect/check_expected_edges?
| H3_EXPORT(getDirectedEdgeOrigin)(iter.e, &s); // source/origin cell | ||
| H3_EXPORT(getDirectedEdgeDestination)(iter.e, &d); // destination cell | ||
| H3_EXPORT(cellToParent)(s, parentRes, &ps); // parent of source | ||
| H3_EXPORT(cellToParent)(d, parentRes, &pd); // parent of destination |
There was a problem hiding this comment.
I think these should have t_assertSuccess?
| H3_EXPORT(directedEdgeToBoundary)(edge_a, &bd_a); | ||
| H3_EXPORT(directedEdgeToBoundary)(edge_b, &bd_b); |
There was a problem hiding this comment.
guard with t_assertSuccess?
| 0x1320807fffffffff, 0x1520807fffffffff, 0x1420807fffffffff, | ||
| 0x1620807fffffffff, 0x1220807fffffffff, |
There was a problem hiding this comment.
note: it would be nice if we could paste this list into h3geo.org and see the edges visualized alongside the cell
| while (iter->_isPentagon && ALWAYS(iter->e != H3_NULL) && | ||
| H3_GET_INDEX_DIGIT(iter->e, iter->_parentRes + 1) == 1) { | ||
| advanceEdge(iter); | ||
| } |
There was a problem hiding this comment.
I wonder if it could be possible to fast-forward to the next non-deleted edge, as an optimization.
I guess it's possible we start somewhere in the middle of the deleted subsequence, in which case it would probably be harder to compute how to get out of it in a single step.
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.rexpanded to child resolutionR: hexagons produce6 * 3^(R-r)edges, pentagons produce5 * 3^(R-r)Usage
Next step: Speed up
cellsToMultiPolygonThis is a building block for a faster
cellsToMultiPolygon. When given a pre-compacted input cell set, the iterator allows thecellsToMultiPolygonalgorithm 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 newcellsToMultiPolygonalgorithm.