@thi.ng/grid-iterators
Version:
2D grid and shape iterators w/ multiple orderings
19 lines (18 loc) • 479 B
JavaScript
const ident = () => (x, y) => [x, y];
const flipX = (cols) => (x, y) => [cols - 1 - x, y];
const flipY = (_, rows) => (x, y) => [x, rows - 1 - y];
const flipXY = (cols, rows) => (x, y) => [cols - 1 - x, rows - 1 - y];
const swapXY = () => (x, y) => [y, x];
const compTransforms = (a, b) => (cols, rows) => {
const $a = a(cols, rows);
const $b = b(cols, rows);
return (x, y) => $b(...$a(x, y));
};
export {
compTransforms,
flipX,
flipXY,
flipY,
ident,
swapXY
};