Skip to content

Commit

Permalink
fix(grid-iterators): fix imports, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Nov 2, 2021
1 parent 46f7aa5 commit adff976
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
15 changes: 8 additions & 7 deletions packages/grid-iterators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ in
### Flood filling

The `floodFill()` iterator can be used to iterate arbitrary 2D grids using an
user-provided predicate function. It yields coordinates which would flood fill
the space in `[0,0]..(width,height)` range, starting at a given point. Any
eligible 90-degree connected regions will be found and iterated recursively. The
predicate function is used to select eligible grid indices (e.g. pixels of
sorts).
user-provided predicate function. 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. Any eligible 90-degree connected regions will be found and iterated
recursively. The predicate function is used to select eligible grid cells
(e.g. "pixels" of sorts).

```ts
// source "image"
Expand All @@ -162,7 +163,7 @@ const img = [
// flood fill iterator from point (1,0)
// only accept " " as source pixel value
// image size is 5x5
const region = floodFill((i) => img[i] === " ", 1, 0, 5, 5);
const region = floodFill((x, y) => img[x + y * 5] === " ", 1, 0, 5, 5);

// label filled pixels using increasing ASCII values
let ascii = 65; // "A"
Expand Down Expand Up @@ -223,7 +224,7 @@ node --experimental-repl-await
> const gridIterators = await import("@thi.ng/grid-iterators");
```

Package sizes (gzipped, pre-treeshake): ESM: 1.88 KB
Package sizes (gzipped, pre-treeshake): ESM: 2.08 KB

## Dependencies

Expand Down
2 changes: 1 addition & 1 deletion packages/grid-iterators/src/line.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { asInt } from "@thi.ng/api/typedarray";
import { liangBarsky } from "./clipping";
import { liangBarsky } from "./clipping.js";

export function* line(ax: number, ay: number, bx: number, by: number) {
[ax, ay, bx, by] = asInt(ax, ay, bx, by);
Expand Down
13 changes: 7 additions & 6 deletions packages/grid-iterators/tpl.readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ in
### Flood filling

The `floodFill()` iterator can be used to iterate arbitrary 2D grids using an
user-provided predicate function. It yields coordinates which would flood fill
the space in `[0,0]..(width,height)` range, starting at a given point. Any
eligible 90-degree connected regions will be found and iterated recursively. The
predicate function is used to select eligible grid indices (e.g. pixels of
sorts).
user-provided predicate function. 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. Any eligible 90-degree connected regions will be found and iterated
recursively. The predicate function is used to select eligible grid cells
(e.g. "pixels" of sorts).

```ts
// source "image"
Expand All @@ -138,7 +139,7 @@ const img = [
// flood fill iterator from point (1,0)
// only accept " " as source pixel value
// image size is 5x5
const region = floodFill((i) => img[i] === " ", 1, 0, 5, 5);
const region = floodFill((x, y) => img[x + y * 5] === " ", 1, 0, 5, 5);

// label filled pixels using increasing ASCII values
let ascii = 65; // "A"
Expand Down

0 comments on commit adff976

Please sign in to comment.