@thi.ng/grid-iterators 4.0.74 → 4.0.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-05-08T18:24:32Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,14 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [4.0.75](https://github.com/thi-ng/umbrella/tree/@thi.ng/grid-iterators@4.0.75) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - dedupe interleave logic/iteration, add tests ([7bc9f7f](https://github.com/thi-ng/umbrella/commit/7bc9f7f))
17
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
18
+ - internal update floodFill() ([3af4715](https://github.com/thi-ng/umbrella/commit/3af4715))
19
+
12
20
  ### [4.0.71](https://github.com/thi-ng/umbrella/tree/@thi.ng/grid-iterators@4.0.71) (2024-04-20)
13
21
 
14
22
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -253,7 +253,7 @@ For Node.js REPL:
253
253
  const gi = await import("@thi.ng/grid-iterators");
254
254
  ```
255
255
 
256
- Package sizes (brotli'd, pre-treeshake): ESM: 2.58 KB
256
+ Package sizes (brotli'd, pre-treeshake): ESM: 2.67 KB
257
257
 
258
258
  ## Dependencies
259
259
 
package/clipping.js CHANGED
@@ -4,8 +4,8 @@ function* clipped(src, left, top, right, bottom) {
4
4
  yield p;
5
5
  }
6
6
  }
7
- const axis = (a, b, c) => (a < b ? a - b : a > b + c ? a - b - c : 0) ** 2;
8
- const intersectRectCircle = (x, y, w, h, cx, cy, r) => axis(cx, x, w) + axis(cy, y, h) <= r * r;
7
+ const __axis = (a, b, c) => (a < b ? a - b : a > b + c ? a - b - c : 0) ** 2;
8
+ const intersectRectCircle = (x, y, w, h, cx, cy, r) => __axis(cx, x, w) + __axis(cy, y, h) <= r * r;
9
9
  const liangBarsky = (ax, ay, bx, by, minx, miny, maxx, maxy) => {
10
10
  const dx = bx - ax;
11
11
  const dy = by - ay;
@@ -12,11 +12,13 @@ export interface DiagonalSlopeOpts extends GridIterOpts2D {
12
12
  * step in -x direction.
13
13
  *
14
14
  * @example
15
- * ```ts
15
+ * ```ts tangle:../export/diagonal-slopey.ts
16
16
  * import { diagonalSlopeY } from "@thi.ng/grid-iterators";
17
17
  *
18
18
  * // iterate grid in diagonals of 1:3 ratio (x:y)
19
- * [...diagonalSlopeY({ cols: 5, step: 3 })]
19
+ * console.log(
20
+ * [...diagonalSlopeY({ cols: 5, rows: 5, slope: 3 })]
21
+ * );
20
22
  * // [
21
23
  * // [0, 0], [0, 1 ], [0, 2 ],
22
24
  * // [1, 0], [1, 1 ], [1, 2 ],
@@ -8,11 +8,13 @@
8
8
  * Reference: https://en.wikipedia.org/wiki/Diamond-square_algorithm
9
9
  *
10
10
  * @example
11
- * ```ts
11
+ * ```ts tangle:../export/diamond-square.ts
12
12
  * import { diamondSquare } from "@thi.ng/grid-iterators";
13
13
  *
14
14
  * // generate coords for a 17x17 grid
15
- * [...diamondSquare(4)]
15
+ * console.log(
16
+ * [...diamondSquare(4)]
17
+ * );
16
18
  * // [
17
19
  * // [0, 0], [16, 0], [16, 16], [0, 16], [8, 0], [8, 16],
18
20
  * // [16, 8], [0, 8], [8, 8], [4, 0], [12, 0], [12, 16],
package/flood-fill.d.ts CHANGED
@@ -11,7 +11,7 @@ import type { Predicate2 } from "@thi.ng/api";
11
11
  * Grid cells are visited max. once. A bit field is used to mark visited cells.
12
12
  *
13
13
  * @example
14
- * ```ts
14
+ * ```ts tangle:../export/flood-fill.ts
15
15
  * import { floodFill } from "@thi.ng/grid-iterators";
16
16
  *
17
17
  * const img = [
@@ -22,7 +22,9 @@ import type { Predicate2 } from "@thi.ng/api";
22
22
  * ];
23
23
  *
24
24
  * // flood fill connected region from point (2,1)
25
- * [...floodFill((x, y) => img[y * 4 + x] === 0, 2, 1, 4, 4)]
25
+ * console.log(
26
+ * [...floodFill((x, y) => img[y * 4 + x] === 0, 2, 1, 4, 4)]
27
+ * );
26
28
  * // [
27
29
  * // [2, 1], [1, 1], [0, 1], [3, 1], [3, 2],
28
30
  * // [3, 0], [0, 2], [0, 3], [1, 0]
package/flood-fill.js CHANGED
@@ -6,13 +6,20 @@ function* floodFill(pred, x, y, width, height) {
6
6
  const queue = [[x, y]];
7
7
  const visited = defBitField(width * height);
8
8
  height--;
9
+ const state = { pred, queue, visited, width, height };
9
10
  while (queue.length) {
10
11
  [x, y] = queue.pop();
11
- yield* partialRow(pred, queue, visited, x, y, width, height, -1);
12
- yield* partialRow(pred, queue, visited, x + 1, y, width, height, 1);
12
+ yield* __partialRow(state, x, y, -1);
13
+ yield* __partialRow(state, x + 1, y, 1);
13
14
  }
14
15
  }
15
- function* partialRow(pred, queue, visited, x, y, width, height1, step) {
16
+ function* __partialRow({
17
+ pred,
18
+ queue,
19
+ visited,
20
+ width,
21
+ height
22
+ }, x, y, step) {
16
23
  let idx = y * width + x;
17
24
  if (visited.at(idx)) return;
18
25
  let scanUp = false;
@@ -28,7 +35,7 @@ function* partialRow(pred, queue, visited, x, y, width, height1, step) {
28
35
  scanUp = false;
29
36
  }
30
37
  }
31
- if (y < height1) {
38
+ if (y < height) {
32
39
  if (pred(x, y + 1) && !scanDown) {
33
40
  queue.push([x, y + 1]);
34
41
  scanDown = true;
package/interleave.d.ts CHANGED
@@ -22,7 +22,7 @@ export interface InterleaveOpts2D extends GridIterOpts2D {
22
22
  *
23
23
  * @param opts -
24
24
  */
25
- export declare function interleaveColumns2d(opts: InterleaveOpts2D): Generator<import("./api.js").GridCoord2D, void, undefined>;
25
+ export declare const interleaveColumns2d: (opts: InterleaveOpts2D) => Generator<import("./api.js").GridCoord2D, void, undefined>;
26
26
  /**
27
27
  * Similar to {@link interleaveColumns2d}, but yields 2D grid coordinates in
28
28
  * the order of interleaved rows with configurable `step` size (default:
@@ -37,5 +37,6 @@ export declare function interleaveColumns2d(opts: InterleaveOpts2D): Generator<i
37
37
  *
38
38
  * @param opts -
39
39
  */
40
- export declare function interleaveRows2d(opts: InterleaveOpts2D): Generator<import("./api.js").GridCoord2D, void, undefined>;
40
+ export declare const interleaveRows2d: (opts: InterleaveOpts2D) => Generator<import("./api.js").GridCoord2D, void, undefined>;
41
+ export declare function __interleave(opts: InterleaveOpts2D, order: [number, number], [x, y]: [number, number]): Generator<import("./api.js").GridCoord2D, void, undefined>;
41
42
  //# sourceMappingURL=interleave.d.ts.map
package/interleave.js CHANGED
@@ -1,21 +1,18 @@
1
1
  import { map } from "@thi.ng/transducers/map";
2
2
  import { range2d } from "@thi.ng/transducers/range2d";
3
3
  import { __opts } from "./utils.js";
4
- function* interleaveColumns2d(opts) {
4
+ const interleaveColumns2d = (opts) => __interleave(opts, [0, 1], [1, 0]);
5
+ const interleaveRows2d = (opts) => __interleave(opts, [1, 0], [0, 1]);
6
+ function* __interleave(opts, order, [x, y]) {
5
7
  const { cols, rows, tx } = __opts(opts);
6
- const step = (opts.step != null ? opts.step : 2) | 0;
8
+ const step = (opts.step ?? 2) | 0;
9
+ const [outer, inner] = order.map((x2) => [cols, rows][x2]);
7
10
  for (let j = 0; j < step; j++) {
8
- yield* map((p) => tx(p[1], p[0]), range2d(0, rows, j, cols, 1, step));
9
- }
10
- }
11
- function* interleaveRows2d(opts) {
12
- const { cols, rows, tx } = __opts(opts);
13
- const step = (opts.step != null ? opts.step : 2) | 0;
14
- for (let j = 0; j < step; j++) {
15
- yield* map((p) => tx(p[0], p[1]), range2d(0, cols, j, rows, 1, step));
11
+ yield* map((p) => tx(p[x], p[y]), range2d(0, inner, j, outer, 1, step));
16
12
  }
17
13
  }
18
14
  export {
15
+ __interleave,
19
16
  interleaveColumns2d,
20
17
  interleaveRows2d
21
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/grid-iterators",
3
- "version": "4.0.74",
3
+ "version": "4.0.75",
4
4
  "description": "2D grid and shape iterators w/ multiple orderings",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/grid-iterators#readme",
13
+ "homepage": "https://thi.ng/grid-iterators",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -38,20 +38,20 @@
38
38
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@thi.ng/api": "^8.11.2",
42
- "@thi.ng/arrays": "^2.9.6",
43
- "@thi.ng/binary": "^3.4.25",
44
- "@thi.ng/bitfield": "^2.3.41",
45
- "@thi.ng/errors": "^2.5.7",
46
- "@thi.ng/morton": "^3.1.86",
47
- "@thi.ng/random": "^3.8.0",
48
- "@thi.ng/transducers": "^9.0.5"
41
+ "@thi.ng/api": "^8.11.3",
42
+ "@thi.ng/arrays": "^2.9.7",
43
+ "@thi.ng/binary": "^3.4.26",
44
+ "@thi.ng/bitfield": "^2.3.42",
45
+ "@thi.ng/errors": "^2.5.8",
46
+ "@thi.ng/morton": "^3.1.87",
47
+ "@thi.ng/random": "^3.8.1",
48
+ "@thi.ng/transducers": "^9.0.6"
49
49
  },
50
50
  "devDependencies": {
51
- "@microsoft/api-extractor": "^7.43.2",
52
- "esbuild": "^0.21.1",
51
+ "@microsoft/api-extractor": "^7.47.0",
52
+ "esbuild": "^0.21.5",
53
53
  "typedoc": "^0.25.13",
54
- "typescript": "^5.4.5"
54
+ "typescript": "^5.5.2"
55
55
  },
56
56
  "keywords": [
57
57
  "2d",
@@ -166,5 +166,5 @@
166
166
  ],
167
167
  "year": 2019
168
168
  },
169
- "gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
169
+ "gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
170
170
  }