@thi.ng/grid-iterators
Version:
2D grid and shape iterators w/ multiple orderings
17 lines (16 loc) • 411 B
JavaScript
import { ceilPow2 } from "@thi.ng/binary/pow";
import { demux2 } from "@thi.ng/morton/mux";
import { __opts } from "./utils.js";
function* zcurve2d(opts) {
const { cols, rows, tx } = __opts(opts);
const max = ceilPow2(Math.pow(Math.max(cols, rows), 2));
for (let i = 0; i < max; i++) {
const [x, y] = demux2(i);
if (x < cols && y < rows) {
yield tx(x, y);
}
}
}
export {
zcurve2d
};