in src/apps/testapps/testH3ToLocalIjExhaustive.c [161:227]
void localIjToH3_traverse_assertions(H3Index h3) {
int r = H3_GET_RESOLUTION(h3);
t_assert(r <= 5, "resolution supported by test function (traverse)");
int k = MAX_DISTANCES[r];
CoordIJ ij;
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(h3, h3, &ij) == 0,
"Got origin coordinates");
// This logic is from hexRangeDistances.
// 0 < ring <= k, current ring
int ring = 1;
// 0 <= direction < 6, current side of the ring
int direction = 0;
// 0 <= i < ring, current position on the side of the ring
int i = 0;
while (ring <= k) {
if (direction == 0 && i == 0) {
ij.i += NEXT_RING_DIRECTION.i;
ij.j += NEXT_RING_DIRECTION.j;
}
ij.i += DIRECTIONS[direction].i;
ij.j += DIRECTIONS[direction].j;
H3Index testH3;
int failed = H3_EXPORT(experimentalLocalIjToH3)(h3, &ij, &testH3);
if (!failed) {
t_assert(H3_EXPORT(h3IsValid)(testH3),
"test coordinates result in valid index");
CoordIJ expectedIj;
int reverseFailed =
H3_EXPORT(experimentalH3ToLocalIj)(h3, testH3, &expectedIj);
// If it doesn't give a coordinate for this origin,index pair that's
// OK.
if (!reverseFailed) {
if (expectedIj.i != ij.i || expectedIj.j != ij.j) {
// Multiple coordinates for the same index can happen due to
// pentagon distortion. In that case, the other coordinates
// should also belong to the same index.
H3Index testTestH3;
t_assert(H3_EXPORT(experimentalLocalIjToH3)(
h3, &expectedIj, &testTestH3) == 0,
"converted coordinates again");
t_assert(testH3 == testTestH3,
"index has normalizable coordinates in "
"local IJ");
}
}
}
i++;
// Check if end of this side of the k-ring
if (i == ring) {
i = 0;
direction++;
// Check if end of this ring.
if (direction == 6) {
direction = 0;
ring++;
}
}
}
}