UNPKG

@thi.ng/grid-iterators

Version:

2D grid and shape iterators w/ multiple orderings

41 lines 1.28 kB
import type { Predicate2 } from "@thi.ng/api"; /** * Yields an iterator of 2D coordinates of the connected region around `x,y` for * which the given predicate succeeds. I.e. The function recursively explores * (in a row-major manner) the space in the `[0,0]..(width,height)` interval, * starting at given `x,y` and continues as long given predicate function * returns a truthy value. * * @remarks * Only the behavior is recursive, not the actual implementation (stack based). * Grid cells are visited max. once. A bit field is used to mark visited cells. * * @example * ```ts tangle:../export/flood-fill.ts * import { floodFill } from "@thi.ng/grid-iterators"; * * const img = [ * 1,0,1,0, * 0,0,0,0, * 0,1,1,0, * 0,1,1,1, * ]; * * // flood fill connected region from point (2,1) * console.log( * [...floodFill((x, y) => img[y * 4 + x] === 0, 2, 1, 4, 4)] * ); * // [ * // [2, 1], [1, 1], [0, 1], [3, 1], [3, 2], * // [3, 0], [0, 2], [0, 3], [1, 0] * // ] * ``` * * @param pred - * @param x - * @param y - * @param width - * @param height - */ export declare function floodFill(pred: Predicate2<number>, x: number, y: number, width: number, height: number): Generator<number[], void, unknown>; //# sourceMappingURL=flood-fill.d.ts.map