export function forEachCellInColumns()

in packages/core/micro/src/matrix.ts [199:241]


export function forEachCellInColumns<T>(grid: SparseGrid<T>, columnStart: number, colCount: number, cb: (r: number, c: number, value: T) => void): void {
    const colEnd = columnStart + colCount - 1;
    for (let r1 = 0; r1 < CONSTS.H; r1++) {
        const cStart1 = colIdxUnshifted(columnStart, 3);
        const cEnd1 = colIdxUnshifted(colEnd, 3);
        for (let c1 = cStart1; c1 <= cEnd1; c1++) {
            const t1 = grid[(c1 << CONSTS.LOGH) | r1];
            if (t1 === undefined) { continue; }
            for (let r2 = 0; r2 < CONSTS.H; r2++) {
                const cStart2 = colIdxUnshifted(columnStart, 2);
                const cEnd2 = colIdxUnshifted(colEnd, 2);
                for (let c2 = cStart2; c2 <= cEnd2; c2++) {
                    const t2 = t1[(c2 << CONSTS.LOGH) | r2];
                    if (t2 === undefined) { continue; }
                    for (let r3 = 0; r3 < CONSTS.H; r3++) {
                        const cStart3 = colIdxUnshifted(columnStart, 1);
                        const cEnd3 = colIdxUnshifted(colEnd, 1);
                        for (let c3 = cStart3; c3 <= cEnd3; c3++) {
                            const t3 = t2[(c3 << CONSTS.LOGH) | r3];
                            if (t3 === undefined) { continue; }
                            for (let r4 = 0; r4 < CONSTS.H; r4++) {
                                const cStart4 = colIdxUnshifted(columnStart, 0);
                                const cEnd4 = colIdxUnshifted(colEnd, 0);
                                for (let c4 = cStart4; c4 <= cEnd4; c4++) {
                                    const cell = t3[(c4 << CONSTS.LOGH) | r4];
                                    if (cell === undefined) { continue; }
                                    cb(
                                        (r1 & CONSTS.MH) << (3 * CONSTS.LOGH) |
                                        (r2 & CONSTS.MH) << (2 * CONSTS.LOGH) |
                                        (r3 & CONSTS.MH) << CONSTS.LOGH |
                                        r4 & CONSTS.MH,
                                        (c1 << (3 * CONSTS.LOGW)) | (c2 << (2 * CONSTS.LOGW)) | (c3 << CONSTS.LOGW) | c4,
                                        cell
                                    );
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}