@thi.ng/grid-iterators
Version:
2D grid and shape iterators w/ multiple orderings
21 lines (20 loc) • 533 B
JavaScript
import { diagonal2d } from "./diagonal.js";
import { __opts } from "./utils.js";
function* diagonalEnds2d(opts) {
const { cols, rows, tx } = __opts(opts);
const num = cols * rows - 1;
const maxX = cols - 1;
const maxY = rows - 1;
const check = opts.all ? (i2) => i2 > 0 && i2 < num : () => true;
let i = 0;
for (let p of diagonal2d({ cols, rows })) {
if (check(i)) {
const [x, y] = p;
if (x === 0 || x === maxX || y === 0 || y === maxY) yield tx(x, y);
}
i++;
}
}
export {
diagonalEnds2d
};