-
Notifications
You must be signed in to change notification settings - Fork 516
Refactor edge boundary, implement core vertex mode logic #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* @param g The spherical coordinates of the cell boundary. | ||
*/ | ||
void _faceIjkToGeoBoundary(const FaceIJK* h, int res, int isPentagon, | ||
void _faceIjkToGeoBoundary(const FaceIJK* h, int res, int start, int length, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two main changes to _faceIjkToGeoBoundary
:
- It now takes
start
andlength
to allow it to efficiently return only a subset of the vertex sequence - The caller is now responsible for switching between
_faceIjkToGeoBoundary
and_faceIjkPentToGeoBoundary
, instead of passing inisPentagon
. This is in part to limit the number of arguments, and in part because requesting all vertexes now requires passing in different lengths for hexes and pentagons.
There was only one other callsite, so this was an easy refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one minor nit from my end. This is great! :)
// Get the res 2 pentagon, whose neighbors have the same base cell | ||
// and are unambiguously on the correct faces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is res 2 used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…g over deleted pentagon subsequences
88b2b71
to
4f59c03
Compare
|
||
SUITE(Vertex) { | ||
TEST(vertexNumForDirection_hex) { | ||
H3Index origin = 0x823d6ffffffffff; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need the L
suffix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently not? We don't seem to be consistent, and there are a number of indexes in tests and benchmarks that don't include the L
suffix and work fine. Is there a reason we thought it was required?
* Note that faces are in directional order, starting at J_AXES_DIGIT. | ||
* This table is generated by the generatePentagonDirectionFaces script. | ||
*/ | ||
static const PentagonDirectionFaces pentagonDirectionFaces[NUM_PENTAGONS] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aside: this table could be used to implement getPentagonIndexes rather than looping through the base cell table.
src/h3lib/lib/vertex.c
Outdated
// additional CCW rotation for polar neighbors or IK neighbors | ||
if (fijk.face != baseFijk.face && | ||
(_isBaseCellPolarPentagon(baseCell) || | ||
fijk.face == dirFaces.faces[IK_AXES_DIGIT - 2])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this table a little confusing to use because it starts indexing directions starting with J (2) rather than 0 or 1. Perhaps at least extract the 2
to a reused constant for this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will extract to a const. The alternative was adding two INVALID_FACE
entries to each array in the table, which didn't seem worthwhile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added as a defined macro (I put this in the .c
file itself, rather than the header file, because this seemed clearer and it didn't make sense to export it - let me know if you disagree).
Refactor edge boundary, implement core vertex mode logic
Changes
vertex.c
, which will eventually hold vertex mode functions.vertexNumForDirection
, which allows us to get the number (index, in the traditional sense) of the topological vertex in a given direction. The logic here is based on determining the number of rotations of the vertexes compared to a given "base" arrangement of direction-to-vertex. The base arrangement occurs when a cell is on the "home" face of its base cell. Additional rotations are required when the cell appears on a different face from its base cell's home face.faceIjkBaseCells
, but that table is not optimized for this lookup, and there are additional rules for pentagons and polar pentagons. I've created a new lookup table to facilitate this operation,baseCellVertexRotations
, along with a script to generate it.vertexNumForDirection
and a small refactor offaceIjkToGeoBoundary
, allowing it to take a start vertex and sequence length, I've refactoredgetH3UnidirectionalEdgeBoundary
to stop comparing geo coordinates and instead look up the vertex directly based on the direction.Benefits
getH3UnidirectionalEdgeBoundary
at resolutions > 12 (see changes intestH3UniEdge.c
), which were broken due to inaccuracies in comparing geo coordinates.getH3UnidirectionalEdgeBoundary
by about 3x:Before
After
Future Work
Implementing
vertexNumForDirection
and a more efficient version ofgetH3UnidirectionalEdgeBoundary
set us up nicely for Vertex Mode functions and a significantly more efficient version ofh3SetToLinkedGeo
.