in lib/h3core.js [967:1003]
export function gridDiskDistances(h3Index, ringSize) {
const [lower, upper] = h3IndexToSplitLong(h3Index);
const countPtr = C._malloc(SZ_INT64);
try {
throwIfError(H3.maxGridDiskSize(ringSize, countPtr));
const count = validateArrayLength(readInt64AsDoubleFromPointer(countPtr));
const kRings = C._calloc(count, SZ_H3INDEX);
const distances = C._calloc(count, SZ_INT);
try {
throwIfError(H3.gridDiskDistances(lower, upper, ringSize, kRings, distances));
/**
* An array of empty arrays to hold the output
* @type {string[][]}
* @private
*/
const out = [];
for (let i = 0; i < ringSize + 1; i++) {
out.push([]);
}
// Read the array of hexagons, putting them into the appropriate rings
for (let i = 0; i < count; i++) {
const cell = readH3IndexFromPointer(kRings, i);
const index = C.getValue(distances + SZ_INT * i, 'i32');
// eslint-disable-next-line max-depth
if (cell !== null) {
out[index].push(cell);
}
}
return out;
} finally {
C._free(kRings);
C._free(distances);
}
} finally {
C._free(countPtr);
}
}