From 7a37a856ee96b38caadf32ddf8745b1c7c87e115 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 26 Sep 2024 16:52:29 -0700 Subject: [PATCH 01/12] bug on cellsToLinkedMultiPolygon for children of pentagon --- .../testapps/testCellsToLinkedMultiPolygon.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/apps/testapps/testCellsToLinkedMultiPolygon.c b/src/apps/testapps/testCellsToLinkedMultiPolygon.c index 5c903386e6..9476d1a831 100644 --- a/src/apps/testapps/testCellsToLinkedMultiPolygon.c +++ b/src/apps/testapps/testCellsToLinkedMultiPolygon.c @@ -72,6 +72,24 @@ SUITE(cellsToLinkedMultiPolygon) { H3_EXPORT(destroyLinkedMultiPolygon)(&polygon); } + TEST(pentagonChldren) { + // children of pentagon 0x80ebfffffffffff + H3Index kids[] = {0x81ea3ffffffffff, 0x81eabffffffffff, + 0x81eafffffffffff, 0x81eb3ffffffffff, + 0x81eb7ffffffffff, 0x81ebbffffffffff}; + int numCells = ARRAY_SIZE(set); + + LinkedGeoPolygon polygon; + t_assertSuccess( + H3_EXPORT(cellsToLinkedMultiPolygon)(kids, numCells, &polygon)); + + // Since these are the children of a cell, we exepect a single loop with + // no holes. + t_assert(countLinkedLoops(&polygon) == 2, "1 loop added to polygon"); + + H3_EXPORT(destroyLinkedMultiPolygon)(&polygon); + } + // TODO: This test asserts incorrect behavior - we should be creating // multiple polygons, each with their own single loop. Update when the // algorithm is corrected. From 6eca1ab5efa84b41db3de17c01749b1e63affadd Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 26 Sep 2024 16:55:13 -0700 Subject: [PATCH 02/12] bah --- src/apps/testapps/testCellsToLinkedMultiPolygon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/testapps/testCellsToLinkedMultiPolygon.c b/src/apps/testapps/testCellsToLinkedMultiPolygon.c index 9476d1a831..5d04480bf7 100644 --- a/src/apps/testapps/testCellsToLinkedMultiPolygon.c +++ b/src/apps/testapps/testCellsToLinkedMultiPolygon.c @@ -77,7 +77,7 @@ SUITE(cellsToLinkedMultiPolygon) { H3Index kids[] = {0x81ea3ffffffffff, 0x81eabffffffffff, 0x81eafffffffffff, 0x81eb3ffffffffff, 0x81eb7ffffffffff, 0x81ebbffffffffff}; - int numCells = ARRAY_SIZE(set); + int numCells = ARRAY_SIZE(kids); LinkedGeoPolygon polygon; t_assertSuccess( From dc7b15ada651fd0edc5a89426a77a5243159eb38 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 26 Sep 2024 17:03:00 -0700 Subject: [PATCH 03/12] we expect 1 loop, no holes --- src/apps/testapps/testCellsToLinkedMultiPolygon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/testapps/testCellsToLinkedMultiPolygon.c b/src/apps/testapps/testCellsToLinkedMultiPolygon.c index 5d04480bf7..b5f00a7b5d 100644 --- a/src/apps/testapps/testCellsToLinkedMultiPolygon.c +++ b/src/apps/testapps/testCellsToLinkedMultiPolygon.c @@ -85,7 +85,7 @@ SUITE(cellsToLinkedMultiPolygon) { // Since these are the children of a cell, we exepect a single loop with // no holes. - t_assert(countLinkedLoops(&polygon) == 2, "1 loop added to polygon"); + t_assert(countLinkedLoops(&polygon) == 1, "1 loop added to polygon"); H3_EXPORT(destroyLinkedMultiPolygon)(&polygon); } From 68b8d848e1521593f0e9d63447f86fe1eeb52be1 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 26 Sep 2024 17:18:40 -0700 Subject: [PATCH 04/12] test (incorrectly) for 2 loops --- src/apps/testapps/testCellsToLinkedMultiPolygon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/testapps/testCellsToLinkedMultiPolygon.c b/src/apps/testapps/testCellsToLinkedMultiPolygon.c index b5f00a7b5d..5d04480bf7 100644 --- a/src/apps/testapps/testCellsToLinkedMultiPolygon.c +++ b/src/apps/testapps/testCellsToLinkedMultiPolygon.c @@ -85,7 +85,7 @@ SUITE(cellsToLinkedMultiPolygon) { // Since these are the children of a cell, we exepect a single loop with // no holes. - t_assert(countLinkedLoops(&polygon) == 1, "1 loop added to polygon"); + t_assert(countLinkedLoops(&polygon) == 2, "1 loop added to polygon"); H3_EXPORT(destroyLinkedMultiPolygon)(&polygon); } From 87b70148aebee1cf770afbff40d0efacddd084f0 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 26 Sep 2024 17:26:36 -0700 Subject: [PATCH 05/12] back to expecting (correctly) 1 loop --- src/apps/testapps/testCellsToLinkedMultiPolygon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/testapps/testCellsToLinkedMultiPolygon.c b/src/apps/testapps/testCellsToLinkedMultiPolygon.c index 5d04480bf7..b5f00a7b5d 100644 --- a/src/apps/testapps/testCellsToLinkedMultiPolygon.c +++ b/src/apps/testapps/testCellsToLinkedMultiPolygon.c @@ -85,7 +85,7 @@ SUITE(cellsToLinkedMultiPolygon) { // Since these are the children of a cell, we exepect a single loop with // no holes. - t_assert(countLinkedLoops(&polygon) == 2, "1 loop added to polygon"); + t_assert(countLinkedLoops(&polygon) == 1, "1 loop added to polygon"); H3_EXPORT(destroyLinkedMultiPolygon)(&polygon); } From b7978f362ba74dcce484e35d8936941bd8c4e2ca Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 26 Sep 2024 17:30:28 -0700 Subject: [PATCH 06/12] try to test on both x86_64 and Apple Silicon --- .github/workflows/test-macos.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-macos.yml b/.github/workflows/test-macos.yml index b46d154c04..f197bf3aec 100644 --- a/.github/workflows/test-macos.yml +++ b/.github/workflows/test-macos.yml @@ -8,11 +8,12 @@ on: jobs: tests: - name: Test Compile ${{ matrix.build_type }} - runs-on: macos-latest + name: Test Compile ${{ matrix.build_type }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} strategy: matrix: + os: [macos-12, macos-13, macos-latest] build_type: ["Debug", "Release"] steps: From c30fb5ce9db45db5b68cc4a7980bb3383515300f Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 26 Sep 2024 17:58:05 -0700 Subject: [PATCH 07/12] for now, ensure all macos jobs run, even if one fails --- .github/workflows/test-macos.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-macos.yml b/.github/workflows/test-macos.yml index f197bf3aec..d86b1e5f58 100644 --- a/.github/workflows/test-macos.yml +++ b/.github/workflows/test-macos.yml @@ -12,6 +12,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: os: [macos-12, macos-13, macos-latest] build_type: ["Debug", "Release"] From e9a50e7b3921a8b33a8463776df4fa4a652552ac Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 26 Sep 2024 18:17:44 -0700 Subject: [PATCH 08/12] shorter name so we can see the OS version --- .github/workflows/test-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-macos.yml b/.github/workflows/test-macos.yml index d86b1e5f58..c12e21d950 100644 --- a/.github/workflows/test-macos.yml +++ b/.github/workflows/test-macos.yml @@ -8,7 +8,7 @@ on: jobs: tests: - name: Test Compile ${{ matrix.build_type }} on ${{ matrix.os }} + name: ${{ matrix.build_type }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: From 8aed51348f20b4f65c402b490a8b31276e888974 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 26 Sep 2024 19:44:37 -0700 Subject: [PATCH 09/12] Update src/apps/testapps/testCellsToLinkedMultiPolygon.c Co-authored-by: Isaac Brodsky --- src/apps/testapps/testCellsToLinkedMultiPolygon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/testapps/testCellsToLinkedMultiPolygon.c b/src/apps/testapps/testCellsToLinkedMultiPolygon.c index b5f00a7b5d..acb0003ed1 100644 --- a/src/apps/testapps/testCellsToLinkedMultiPolygon.c +++ b/src/apps/testapps/testCellsToLinkedMultiPolygon.c @@ -83,7 +83,7 @@ SUITE(cellsToLinkedMultiPolygon) { t_assertSuccess( H3_EXPORT(cellsToLinkedMultiPolygon)(kids, numCells, &polygon)); - // Since these are the children of a cell, we exepect a single loop with + // Since these are the children of a cell, we expect a single loop with // no holes. t_assert(countLinkedLoops(&polygon) == 1, "1 loop added to polygon"); From 61fc849c0aa1ea80f5e2660d0d6e75ac5218e043 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 26 Sep 2024 19:44:42 -0700 Subject: [PATCH 10/12] Update src/apps/testapps/testCellsToLinkedMultiPolygon.c Co-authored-by: Isaac Brodsky --- src/apps/testapps/testCellsToLinkedMultiPolygon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/testapps/testCellsToLinkedMultiPolygon.c b/src/apps/testapps/testCellsToLinkedMultiPolygon.c index acb0003ed1..7917fcc8f8 100644 --- a/src/apps/testapps/testCellsToLinkedMultiPolygon.c +++ b/src/apps/testapps/testCellsToLinkedMultiPolygon.c @@ -72,7 +72,7 @@ SUITE(cellsToLinkedMultiPolygon) { H3_EXPORT(destroyLinkedMultiPolygon)(&polygon); } - TEST(pentagonChldren) { + TEST(pentagonChildren) { // children of pentagon 0x80ebfffffffffff H3Index kids[] = {0x81ea3ffffffffff, 0x81eabffffffffff, 0x81eafffffffffff, 0x81eb3ffffffffff, From 1eee6f9dccbbe9a8b39665901143148815628024 Mon Sep 17 00:00:00 2001 From: Isaac Brodsky Date: Sun, 6 Oct 2024 12:46:25 -0700 Subject: [PATCH 11/12] begin using vertex mode for cellsToLinkedMultiPolygon --- src/h3lib/include/linkedGeo.h | 2 +- src/h3lib/include/vertexGraph.h | 18 +++++++------- src/h3lib/lib/algos.c | 35 +++++++++++++++++---------- src/h3lib/lib/linkedGeo.c | 10 ++++++-- src/h3lib/lib/vertexGraph.c | 42 +++++++++++++-------------------- 5 files changed, 56 insertions(+), 51 deletions(-) diff --git a/src/h3lib/include/linkedGeo.h b/src/h3lib/include/linkedGeo.h index 1abc341d51..fee45ac920 100644 --- a/src/h3lib/include/linkedGeo.h +++ b/src/h3lib/include/linkedGeo.h @@ -51,7 +51,7 @@ H3Error normalizeMultiPolygon(LinkedGeoPolygon *root); LinkedGeoPolygon *addNewLinkedPolygon(LinkedGeoPolygon *polygon); LinkedGeoLoop *addNewLinkedLoop(LinkedGeoPolygon *polygon); LinkedGeoLoop *addLinkedLoop(LinkedGeoPolygon *polygon, LinkedGeoLoop *loop); -LinkedLatLng *addLinkedCoord(LinkedGeoLoop *loop, const LatLng *vertex); +LinkedLatLng *addLinkedCoord(LinkedGeoLoop *loop, H3Index vertex); int countLinkedPolygons(LinkedGeoPolygon *polygon); int countLinkedLoops(LinkedGeoPolygon *polygon); int countLinkedCoords(LinkedGeoLoop *loop); diff --git a/src/h3lib/include/vertexGraph.h b/src/h3lib/include/vertexGraph.h index 5d17f59a67..bf95448ddf 100644 --- a/src/h3lib/include/vertexGraph.h +++ b/src/h3lib/include/vertexGraph.h @@ -30,8 +30,8 @@ */ typedef struct VertexNode VertexNode; struct VertexNode { - LatLng from; - LatLng to; + H3Index from; + H3Index to; VertexNode *next; }; @@ -49,21 +49,19 @@ void initVertexGraph(VertexGraph *graph, int numBuckets, int res); void destroyVertexGraph(VertexGraph *graph); -VertexNode *addVertexNode(VertexGraph *graph, const LatLng *fromVtx, - const LatLng *toVtx); +VertexNode *addVertexNode(VertexGraph *graph, H3Index fromVtx, H3Index toVtx); int removeVertexNode(VertexGraph *graph, VertexNode *node); -VertexNode *findNodeForEdge(const VertexGraph *graph, const LatLng *fromVtx, - const LatLng *toVtx); +VertexNode *findNodeForEdge(const VertexGraph *graph, H3Index fromVtx, + H3Index toVtx); -VertexNode *findNodeForVertex(const VertexGraph *graph, const LatLng *fromVtx); +VertexNode *findNodeForVertex(const VertexGraph *graph, H3Index fromVtx); VertexNode *firstVertexNode(const VertexGraph *graph); // Internal functions -uint32_t _hashVertex(const LatLng *vertex, int res, int numBuckets); -void _initVertexNode(VertexNode *node, const LatLng *fromVtx, - const LatLng *toVtx); +uint32_t _hashVertex(H3Index vertex, int numBuckets); +void _initVertexNode(VertexNode *node, H3Index fromVtx, H3Index toVtx); #endif diff --git a/src/h3lib/lib/algos.c b/src/h3lib/lib/algos.c index 1b20bf5efc..d945a8688e 100644 --- a/src/h3lib/lib/algos.c +++ b/src/h3lib/lib/algos.c @@ -1077,9 +1077,9 @@ H3Error H3_EXPORT(polygonToCells)(const GeoPolygon *geoPolygon, int res, */ H3Error h3SetToVertexGraph(const H3Index *h3Set, const int numHexes, VertexGraph *graph) { - CellBoundary vertices; - LatLng *fromVtx; - LatLng *toVtx; + H3Index vertices[NUM_HEX_VERTS] = {0}; + H3Index fromVtx; + H3Index toVtx; VertexNode *edge; if (numHexes < 1) { // We still need to init the graph, or calls to destroyVertexGraph will @@ -1094,17 +1094,28 @@ H3Error h3SetToVertexGraph(const H3Index *h3Set, const int numHexes, initVertexGraph(graph, numBuckets, res); // Iterate through every hexagon for (int i = 0; i < numHexes; i++) { - H3Error boundaryErr = H3_EXPORT(cellToBoundary)(h3Set[i], &vertices); - if (boundaryErr) { + H3Error vertexesError = H3_EXPORT(cellToVertexes)(h3Set[i], &vertices); + if (vertexesError) { // Destroy vertex graph as caller will not know to do so. destroyVertexGraph(graph); - return boundaryErr; + return vertexesError; } // iterate through every edge - for (int j = 0; j < vertices.numVerts; j++) { - fromVtx = &vertices.verts[j]; - toVtx = &vertices.verts[(j + 1) % vertices.numVerts]; + for (int j = 0; j < NUM_HEX_VERTS; j++) { + if (vertices[j] == H3_NULL) { + continue; + } + int next = j + 1; + for (int nextOffset = 0; nextOffset < NUM_HEX_VERTS; nextOffset++) { + if (vertices[(next + nextOffset) % NUM_HEX_VERTS] == H3_NULL) { + next = (next + nextOffset) % NUM_HEX_VERTS; + break; + } + } + fromVtx = vertices[j]; + toVtx = vertices[next]; // If we've seen this edge already, it will be reversed + // TODO: Wrong order of parameters edge = findNodeForEdge(graph, toVtx, fromVtx); if (edge != NULL) { // If we've seen it, drop it. No edge is shared by more than 2 @@ -1132,17 +1143,17 @@ void _vertexGraphToLinkedGeo(VertexGraph *graph, LinkedGeoPolygon *out) { *out = (LinkedGeoPolygon){0}; LinkedGeoLoop *loop; VertexNode *edge; - LatLng nextVtx; + H3Index nextVtx; // Find the next unused entry point while ((edge = firstVertexNode(graph)) != NULL) { loop = addNewLinkedLoop(out); // Walk the graph to get the outline do { - addLinkedCoord(loop, &edge->from); + addLinkedCoord(loop, edge->from); nextVtx = edge->to; // Remove frees the node, so we can't use edge after this removeVertexNode(graph, edge); - edge = findNodeForVertex(graph, &nextVtx); + edge = findNodeForVertex(graph, nextVtx); } while (edge); } } diff --git a/src/h3lib/lib/linkedGeo.c b/src/h3lib/lib/linkedGeo.c index 85308e8a4c..239497c0a0 100644 --- a/src/h3lib/lib/linkedGeo.c +++ b/src/h3lib/lib/linkedGeo.c @@ -23,6 +23,7 @@ #include #include "alloc.h" +#include "h3Assert.h" #include "h3api.h" #include "latLng.h" @@ -73,10 +74,15 @@ LinkedGeoLoop *addLinkedLoop(LinkedGeoPolygon *polygon, LinkedGeoLoop *loop) { * @param vertex Coordinate to add * @return Pointer to the coordinate */ -LinkedLatLng *addLinkedCoord(LinkedGeoLoop *loop, const LatLng *vertex) { +LinkedLatLng *addLinkedCoord(LinkedGeoLoop *loop, H3Index vertex) { LinkedLatLng *coord = H3_MEMORY(malloc)(sizeof(*coord)); assert(coord != NULL); - *coord = (LinkedLatLng){.vertex = *vertex, .next = NULL}; + LatLng vertexLatLng; + H3Error err = H3_EXPORT(vertexToLatLng)(vertex, &vertexLatLng); + if (NEVER(err)) { + return NULL; + } + *coord = (LinkedLatLng){.vertex = vertexLatLng, .next = NULL}; LinkedLatLng *last = loop->last; if (last == NULL) { assert(loop->first == NULL); diff --git a/src/h3lib/lib/vertexGraph.c b/src/h3lib/lib/vertexGraph.c index fd7c5299d0..e1bcb1c25b 100644 --- a/src/h3lib/lib/vertexGraph.c +++ b/src/h3lib/lib/vertexGraph.c @@ -62,25 +62,17 @@ void destroyVertexGraph(VertexGraph *graph) { /** * Get an integer hash for a lat/lng point, at a precision determined * by the current hexagon resolution. - * TODO: Light testing suggests this might not be sufficient at resolutions - * finer than 10. Design a better hash function if performance and collisions - * seem to be an issue here. * @param vertex Lat/lng vertex to hash - * @param res Resolution of the hexagon the vertex belongs to * @param numBuckets Number of buckets in the graph * @return Integer hash */ -uint32_t _hashVertex(const LatLng *vertex, int res, int numBuckets) { - // Simple hash: Take the sum of the lat and lng with a precision level - // determined by the resolution, converted to int, modulo bucket count. - return (uint32_t)fmod(fabs((vertex->lat + vertex->lng) * pow(10, 15 - res)), - numBuckets); +uint32_t _hashVertex(H3Index vertex, int numBuckets) { + return (uint32_t)(vertex % numBuckets); } -void _initVertexNode(VertexNode *node, const LatLng *fromVtx, - const LatLng *toVtx) { - node->from = *fromVtx; - node->to = *toVtx; +void _initVertexNode(VertexNode *node, H3Index fromVtx, H3Index toVtx) { + node->from = fromVtx; + node->to = toVtx; node->next = NULL; } @@ -91,14 +83,13 @@ void _initVertexNode(VertexNode *node, const LatLng *fromVtx, * @param toVtx End vertex * @return Pointer to the new node */ -VertexNode *addVertexNode(VertexGraph *graph, const LatLng *fromVtx, - const LatLng *toVtx) { +VertexNode *addVertexNode(VertexGraph *graph, H3Index fromVtx, H3Index toVtx) { // Make the new node VertexNode *node = H3_MEMORY(malloc)(sizeof(VertexNode)); assert(node != NULL); _initVertexNode(node, fromVtx, toVtx); // Determine location - uint32_t index = _hashVertex(fromVtx, graph->res, graph->numBuckets); + uint32_t index = _hashVertex(fromVtx, graph->numBuckets); // Check whether there's an existing node in that spot VertexNode *currentNode = graph->buckets[index]; if (currentNode == NULL) { @@ -108,8 +99,7 @@ VertexNode *addVertexNode(VertexGraph *graph, const LatLng *fromVtx, // Find the end of the list do { // Check the the edge we're adding doesn't already exist - if (geoAlmostEqual(¤tNode->from, fromVtx) && - geoAlmostEqual(¤tNode->to, toVtx)) { + if (currentNode->from == fromVtx && currentNode->to == toVtx) { // already exists, bail H3_MEMORY(free)(node); return currentNode; @@ -134,7 +124,7 @@ VertexNode *addVertexNode(VertexGraph *graph, const LatLng *fromVtx, */ int removeVertexNode(VertexGraph *graph, VertexNode *node) { // Determine location - uint32_t index = _hashVertex(&node->from, graph->res, graph->numBuckets); + uint32_t index = _hashVertex(node->from, graph->numBuckets); VertexNode *currentNode = graph->buckets[index]; int found = 0; if (currentNode != NULL) { @@ -168,17 +158,17 @@ int removeVertexNode(VertexGraph *graph, VertexNode *node) { * @param toVtx End vertex, or NULL if we don't care * @return Pointer to the vertex node, if found */ -VertexNode *findNodeForEdge(const VertexGraph *graph, const LatLng *fromVtx, - const LatLng *toVtx) { +VertexNode *findNodeForEdge(const VertexGraph *graph, H3Index fromVtx, + H3Index toVtx) { // Determine location - uint32_t index = _hashVertex(fromVtx, graph->res, graph->numBuckets); + uint32_t index = _hashVertex(fromVtx, graph->numBuckets); // Check whether there's an existing node in that spot VertexNode *node = graph->buckets[index]; if (node != NULL) { // Look through the list and see if we find the edge do { - if (geoAlmostEqual(&node->from, fromVtx) && - (toVtx == NULL || geoAlmostEqual(&node->to, toVtx))) { + if (node->from == fromVtx && + (toVtx == H3_NULL || node->to == toVtx)) { return node; } node = node->next; @@ -194,8 +184,8 @@ VertexNode *findNodeForEdge(const VertexGraph *graph, const LatLng *fromVtx, * @param fromVtx Start vertex * @return Pointer to the vertex node, if found */ -VertexNode *findNodeForVertex(const VertexGraph *graph, const LatLng *fromVtx) { - return findNodeForEdge(graph, fromVtx, NULL); +VertexNode *findNodeForVertex(const VertexGraph *graph, H3Index fromVtx) { + return findNodeForEdge(graph, fromVtx, H3_NULL); } /** From 64e0660f32629dd92999996cc2663140cb172d51 Mon Sep 17 00:00:00 2001 From: Isaac Brodsky Date: Sun, 6 Oct 2024 13:00:40 -0700 Subject: [PATCH 12/12] fix --- src/apps/testapps/testCellsToLinkedMultiPolygon.c | 2 +- src/h3lib/lib/algos.c | 12 +++++------- src/h3lib/lib/linkedGeo.c | 1 + 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/apps/testapps/testCellsToLinkedMultiPolygon.c b/src/apps/testapps/testCellsToLinkedMultiPolygon.c index 7917fcc8f8..c3f9a003df 100644 --- a/src/apps/testapps/testCellsToLinkedMultiPolygon.c +++ b/src/apps/testapps/testCellsToLinkedMultiPolygon.c @@ -53,7 +53,7 @@ SUITE(cellsToLinkedMultiPolygon) { int numHexes = ARRAY_SIZE(set); t_assert(H3_EXPORT(cellsToLinkedMultiPolygon)( - set, numHexes, &polygon) == E_CELL_INVALID, + set, numHexes, &polygon) != E_SUCCESS, "Invalid set fails"); } diff --git a/src/h3lib/lib/algos.c b/src/h3lib/lib/algos.c index d945a8688e..1d7589a22e 100644 --- a/src/h3lib/lib/algos.c +++ b/src/h3lib/lib/algos.c @@ -1094,7 +1094,7 @@ H3Error h3SetToVertexGraph(const H3Index *h3Set, const int numHexes, initVertexGraph(graph, numBuckets, res); // Iterate through every hexagon for (int i = 0; i < numHexes; i++) { - H3Error vertexesError = H3_EXPORT(cellToVertexes)(h3Set[i], &vertices); + H3Error vertexesError = H3_EXPORT(cellToVertexes)(h3Set[i], vertices); if (vertexesError) { // Destroy vertex graph as caller will not know to do so. destroyVertexGraph(graph); @@ -1106,14 +1106,12 @@ H3Error h3SetToVertexGraph(const H3Index *h3Set, const int numHexes, continue; } int next = j + 1; - for (int nextOffset = 0; nextOffset < NUM_HEX_VERTS; nextOffset++) { - if (vertices[(next + nextOffset) % NUM_HEX_VERTS] == H3_NULL) { - next = (next + nextOffset) % NUM_HEX_VERTS; - break; - } + if (vertices[next % NUM_HEX_VERTS] == H3_NULL) { + // There can only be one deleted vertex, for pentagons, so just advance past it. + next++; } fromVtx = vertices[j]; - toVtx = vertices[next]; + toVtx = vertices[next % NUM_HEX_VERTS]; // If we've seen this edge already, it will be reversed // TODO: Wrong order of parameters edge = findNodeForEdge(graph, toVtx, fromVtx); diff --git a/src/h3lib/lib/linkedGeo.c b/src/h3lib/lib/linkedGeo.c index 239497c0a0..4b6c41d050 100644 --- a/src/h3lib/lib/linkedGeo.c +++ b/src/h3lib/lib/linkedGeo.c @@ -78,6 +78,7 @@ LinkedLatLng *addLinkedCoord(LinkedGeoLoop *loop, H3Index vertex) { LinkedLatLng *coord = H3_MEMORY(malloc)(sizeof(*coord)); assert(coord != NULL); LatLng vertexLatLng; + // TODO: Also add the distrortion vertex here H3Error err = H3_EXPORT(vertexToLatLng)(vertex, &vertexLatLng); if (NEVER(err)) { return NULL;