export function forEachCell()

in packages/core/micro/src/matrix.ts [127:159]


export function forEachCell<T>(grid: SparseGrid<T>, cb: (r: number, c: number, value: T) => void): void {
    let i1 = 0;
    for (const t1 of grid) {
        if (t1 !== undefined) {
            let i2 = 0;
            const c1 = (i1 >> CONSTS.LOGH) << (3 * CONSTS.LOGW);
            const r1 = (i1 & CONSTS.MH) << (3 * CONSTS.LOGH);
            for (const t2 of t1) {
                if (t2 !== undefined) {
                    let i3 = 0;
                    const c2 = (i2 >> CONSTS.LOGH) << (2 * CONSTS.LOGW);
                    const r2 = (i2 & CONSTS.MH) << (2 * CONSTS.LOGH);
                    for (const t3 of t2) {
                        if (t3 !== undefined) {
                            let i4 = 0;
                            const c3 = (i3 >> CONSTS.LOGH) << CONSTS.LOGW;
                            const r3 = (i3 & CONSTS.MH) << CONSTS.LOGH;
                            for (const value of t3) {
                                if (value !== undefined) {
                                    cb(r1 | r2 | r3 | i4 & CONSTS.MH, c1 | c2 | c3 | i4 >> CONSTS.LOGH, value);
                                }
                                i4++;
                            }
                        }
                        i3++;
                    }
                }
                i2++;
            }
        }
        i1++;
    }
}