in h3_algos.c [1078:1120]
H3Error h3SetToVertexGraph(const H3Index *h3Set, const int numHexes,
VertexGraph *graph) {
CellBoundary vertices;
LatLng *fromVtx;
LatLng *toVtx;
VertexNode *edge;
if (numHexes < 1) {
// We still need to init the graph, or calls to destroyVertexGraph will
// fail
initVertexGraph(graph, 0, 0);
return E_SUCCESS;
}
int res = H3_GET_RESOLUTION(h3Set[0]);
const int minBuckets = 6;
// TODO: Better way to calculate/guess?
int numBuckets = numHexes > minBuckets ? numHexes : minBuckets;
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) {
// Destroy vertex graph as caller will not know to do so.
destroyVertexGraph(graph);
return boundaryErr;
}
// iterate through every edge
for (int j = 0; j < vertices.numVerts; j++) {
fromVtx = &vertices.verts[j];
toVtx = &vertices.verts[(j + 1) % vertices.numVerts];
// If we've seen this edge already, it will be reversed
edge = findNodeForEdge(graph, toVtx, fromVtx);
if (edge != NULL) {
// If we've seen it, drop it. No edge is shared by more than 2
// hexagons, so we'll never see it again.
removeVertexNode(graph, edge);
} else {
// Add a new node for this edge
addVertexNode(graph, fromVtx, toVtx);
}
}
}
return E_SUCCESS;
}