in src/apps/testapps/testPolygonToCellsExperimental.c [94:151]
static void fillIndex_assertions(H3Index h) {
if (isTransmeridianCell(h)) {
// TODO: these do not work correctly
return;
}
int currentRes = H3_EXPORT(getResolution)(h);
// TODO: Not testing more than one depth because the assertions fail.
for (int nextRes = currentRes; nextRes <= currentRes + 1; nextRes++) {
CellBoundary bndry;
H3_EXPORT(cellToBoundary)(h, &bndry);
GeoPolygon polygon = {
.geoloop = {.numVerts = bndry.numVerts, .verts = bndry.verts},
.numHoles = 0,
.holes = 0};
int64_t polygonToCellsSize;
t_assertSuccess(H3_EXPORT(maxPolygonToCellsSizeExperimental)(
&polygon, nextRes, 0, &polygonToCellsSize));
H3Index *polygonToCellsOut =
calloc(polygonToCellsSize, sizeof(H3Index));
t_assertSuccess(H3_EXPORT(polygonToCellsExperimental)(
&polygon, nextRes, CONTAINMENT_CENTER, polygonToCellsSize,
polygonToCellsOut));
int64_t polygonToCellsCount =
countNonNullIndexes(polygonToCellsOut, polygonToCellsSize);
int64_t childrenSize;
t_assertSuccess(
H3_EXPORT(cellToChildrenSize)(h, nextRes, &childrenSize));
H3Index *children = calloc(childrenSize, sizeof(H3Index));
t_assertSuccess(H3_EXPORT(cellToChildren)(h, nextRes, children));
int64_t cellToChildrenCount =
countNonNullIndexes(children, childrenSize);
t_assert(polygonToCellsCount == cellToChildrenCount,
"PolygonToCells count matches cellToChildren count");
for (int i = 0; i < childrenSize; i++) {
bool found = false;
if (children[i] == H3_NULL) continue;
for (int j = 0; j < polygonToCellsSize; j++) {
if (polygonToCellsOut[j] == children[i]) {
found = true;
break;
}
}
t_assert(
found,
"All indexes match between polygonToCells and cellToChildren");
}
free(polygonToCellsOut);
free(children);
}
}