-
Notifications
You must be signed in to change notification settings - Fork 539
Implement vertex mode #417
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
37829ea
WIP on Vertex Mode indexes
38bdeb5
WIP on getCellVertex, works on all but res 0
1ea7019
Vertex mode fully functional
bc62457
WIP on Vertex Mode, fix calculation of left neighbor
335915a
Use directionForNeighbor to calculate vertex
4e90554
Add getCellVertexes, improve tests
23a1c6b
Fix left/right, implement faster(?) neighbor vertex lookup
c4a464c
Add benchmark
fd0e92b
Remove apparently ineffective optimization
9a7eb9a
Make functions public, move exhaustive tests to separate suite
86b3f10
Improve coverage
86f39a2
Rename functions, remove adjustForPentagon
202331c
Rename in .in file
198a478
Fix compile issue
21cdbc4
Fix API description
a4eafef
Fixing function name
9486f8f
Code review tweaks, updated CHANGELOG and indexing docs
0d47450
Reserved -> Mode-Dependent
edfb4dc
Clarify owner in indexing docs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright 2021 Uber Technologies, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #include "benchmark.h" | ||
| #include "h3api.h" | ||
| #include "vertex.h" | ||
|
|
||
| // Fixtures. Cells are arbitrary, except that ring2 is all hexagons and | ||
| // ring2Pent is centered on a pentagon. | ||
| H3Index ring2[] = { | ||
| 0x89283081083ffff, 0x8928308109bffff, 0x8928308108bffff, 0x8928308108fffff, | ||
| 0x89283081087ffff, 0x89283081097ffff, 0x89283081093ffff, 0x89283081467ffff, | ||
| 0x8928308146fffff, 0x892830810d7ffff, 0x892830810c7ffff, 0x89283081013ffff, | ||
| 0x89283081017ffff, 0x892830810bbffff, 0x892830810b3ffff, 0x8928308154bffff, | ||
| 0x8928308155bffff, 0x8928308142fffff, 0x8928308142bffff}; | ||
| int ring2Count = 19; | ||
|
|
||
| H3Index ring2Pent[] = { | ||
| 0x8508008bfffffff, 0x8508000ffffffff, 0x85080077fffffff, 0x85080047fffffff, | ||
| 0x85080017fffffff, 0x85080003fffffff, 0x8508000bfffffff, 0x85080073fffffff, | ||
| 0x85080057fffffff, 0x850800abfffffff, 0x8508008ffffffff, 0x85080013fffffff, | ||
| 0x8508001bfffffff, 0x850800c7fffffff, 0x850800cffffffff, 0x850800bbfffffff}; | ||
| int ring2PentCount = 16; | ||
|
|
||
| BEGIN_BENCHMARKS(); | ||
|
|
||
| H3Index* vertexes = calloc(6, sizeof(H3Index)); | ||
|
|
||
| BENCHMARK(cellToVertexes, 10000, { | ||
| for (int i = 0; i < ring2Count; i++) { | ||
| H3_EXPORT(cellToVertexes)(ring2[i], vertexes); | ||
| } | ||
| }); | ||
|
|
||
| BENCHMARK(cellToVertexesPent, 10000, { | ||
| for (int i = 0; i < ring2PentCount; i++) { | ||
| H3_EXPORT(cellToVertexes)(ring2Pent[i], vertexes); | ||
| } | ||
| }); | ||
|
|
||
| free(vertexes); | ||
|
|
||
| END_BENCHMARKS(); |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /* | ||
| * Copyright 2020-2021 Uber Technologies, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| /** @file | ||
| * @brief tests H3 vertex functions, exhaustively checking all cells at res 0-4 | ||
| */ | ||
|
|
||
| #include "test.h" | ||
| #include "utility.h" | ||
| #include "vertex.h" | ||
|
|
||
| static void directionForVertexNum_symmetry_assertions(H3Index h3) { | ||
| int numVerts = H3_EXPORT(h3IsPentagon)(h3) ? NUM_PENT_VERTS : NUM_HEX_VERTS; | ||
| for (int i = 0; i < numVerts; i++) { | ||
| Direction dir = directionForVertexNum(h3, i); | ||
| int vertexNum = vertexNumForDirection(h3, dir); | ||
| t_assert( | ||
| vertexNum == i, | ||
| "directionForVertexNum and vertexNumForDirection are symmetrical"); | ||
| } | ||
| } | ||
|
|
||
| static void cellToVertex_point_assertions(H3Index h3) { | ||
| GeoBoundary gb; | ||
| H3_EXPORT(h3ToGeoBoundary)(h3, &gb); | ||
| int numVerts = H3_EXPORT(h3IsPentagon)(h3) ? NUM_PENT_VERTS : NUM_HEX_VERTS; | ||
|
|
||
| // This test won't work if there are distortion vertexes in the boundary | ||
| if (numVerts < gb.numVerts) return; | ||
|
|
||
| GeoCoord coord; | ||
| for (int i = 0; i < numVerts; i++) { | ||
| H3Index vertex = H3_EXPORT(cellToVertex)(h3, i); | ||
| H3_EXPORT(vertexToPoint)(vertex, &coord); | ||
| int almostEqual = | ||
| geoAlmostEqualThreshold(&gb.verts[i], &coord, 0.000001); | ||
| t_assert(almostEqual, "Vertex coordinates match boundary vertex"); | ||
| } | ||
| } | ||
|
|
||
| static void cellToVertex_uniqueness_assertions(H3Index h3) { | ||
| H3Index originVerts[NUM_HEX_VERTS] = {0}; | ||
| H3_EXPORT(cellToVertexes)(h3, originVerts); | ||
|
|
||
| for (int v1 = 0; v1 < NUM_HEX_VERTS - 1; v1++) { | ||
| for (int v2 = v1 + 1; v2 < NUM_HEX_VERTS; v2++) { | ||
| if (originVerts[v1] == originVerts[v2]) { | ||
| t_assert(false, "vertex should be unique"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static void cellToVertex_neighbor_assertions(H3Index h3) { | ||
| H3Index neighbors[7] = {0}; | ||
| H3Index originVerts[NUM_HEX_VERTS] = {0}; | ||
| H3Index neighborVerts[NUM_HEX_VERTS] = {0}; | ||
|
|
||
| H3_EXPORT(kRing)(h3, 1, neighbors); | ||
| H3_EXPORT(cellToVertexes)(h3, originVerts); | ||
|
|
||
| for (int i = 0; i < 7; i++) { | ||
| H3Index neighbor = neighbors[i]; | ||
| if (neighbor == H3_NULL || neighbor == h3) continue; | ||
| H3_EXPORT(cellToVertexes)(neighbor, neighborVerts); | ||
|
|
||
| // calculate the set intersection | ||
| int intersection = 0; | ||
| for (int v1 = 0; v1 < NUM_HEX_VERTS; v1++) { | ||
| for (int v2 = 0; v2 < NUM_HEX_VERTS; v2++) { | ||
| if (neighborVerts[v1] == originVerts[v2]) { | ||
| intersection++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| t_assert(intersection == 2, | ||
| "Neighbor shares 2 unique vertexes with origin"); | ||
| } | ||
| } | ||
|
|
||
| SUITE(Vertex) { | ||
| TEST(directionForVertexNum_symmetry) { | ||
| iterateAllIndexesAtRes(0, directionForVertexNum_symmetry_assertions); | ||
| iterateAllIndexesAtRes(1, directionForVertexNum_symmetry_assertions); | ||
| iterateAllIndexesAtRes(2, directionForVertexNum_symmetry_assertions); | ||
| iterateAllIndexesAtRes(3, directionForVertexNum_symmetry_assertions); | ||
| iterateAllIndexesAtRes(4, directionForVertexNum_symmetry_assertions); | ||
| } | ||
|
|
||
| TEST(cellToVertex_point) { | ||
| iterateAllIndexesAtRes(0, cellToVertex_point_assertions); | ||
| iterateAllIndexesAtRes(1, cellToVertex_point_assertions); | ||
| iterateAllIndexesAtRes(2, cellToVertex_point_assertions); | ||
| iterateAllIndexesAtRes(3, cellToVertex_point_assertions); | ||
| iterateAllIndexesAtRes(4, cellToVertex_point_assertions); | ||
|
|
||
| // Res 5: normal base cell | ||
| iterateBaseCellIndexesAtRes(5, cellToVertex_point_assertions, 0); | ||
| // Res 5: pentagon base cell | ||
| iterateBaseCellIndexesAtRes(5, cellToVertex_point_assertions, 14); | ||
| // Res 5: polar pentagon base cell | ||
| iterateBaseCellIndexesAtRes(5, cellToVertex_point_assertions, 117); | ||
| } | ||
|
|
||
| TEST(cellToVertex_neighbors) { | ||
| iterateAllIndexesAtRes(0, cellToVertex_neighbor_assertions); | ||
| iterateAllIndexesAtRes(1, cellToVertex_neighbor_assertions); | ||
| iterateAllIndexesAtRes(2, cellToVertex_neighbor_assertions); | ||
| iterateAllIndexesAtRes(3, cellToVertex_neighbor_assertions); | ||
| iterateAllIndexesAtRes(4, cellToVertex_neighbor_assertions); | ||
| } | ||
|
|
||
| TEST(cellToVertex_uniqueness) { | ||
| iterateAllIndexesAtRes(0, cellToVertex_uniqueness_assertions); | ||
| iterateAllIndexesAtRes(1, cellToVertex_uniqueness_assertions); | ||
| iterateAllIndexesAtRes(2, cellToVertex_uniqueness_assertions); | ||
| iterateAllIndexesAtRes(3, cellToVertex_uniqueness_assertions); | ||
| iterateAllIndexesAtRes(4, cellToVertex_uniqueness_assertions); | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,5 +80,7 @@ | |
| /** H3 index modes */ | ||
| #define H3_HEXAGON_MODE 1 | ||
| #define H3_UNIEDGE_MODE 2 | ||
| #define H3_EDGE_MODE 3 | ||
| #define H3_VERTEX_MODE 4 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the new mode to the specification in docs
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the Indexing docs, reformatting, clarifying a bit, and adding the new mode. |
||
|
|
||
| #endif | ||
Oops, something went wrong.
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.
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.
the edge mode is reserved I presume?
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.
Yes - I added
H3_EDGE_MODEproactively because it made more sense for it to be sequentially next toH3_UNIEDGE_MODE, and we're pretty sure we're going to add it. Could remove here, I just thought it would look funny to haveH3_UNIEDGE_MODE,H3_VERTEX_MODE, andH3_EDGE_MODEin that order.