@thi.ng/grid-iterators 2.2.5 → 2.3.1

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**: 2021-12-13T10:26:00Z
3
+ - **Last updated**: 2022-05-07T11:33:35Z
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,12 @@ 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
+ ## [2.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/grid-iterators@2.3.0) (2022-04-07)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add diamondSquare() ([4fabaad](https://github.com/thi-ng/umbrella/commit/4fabaad))
17
+
12
18
  ### [2.2.4](https://github.com/thi-ng/umbrella/tree/@thi.ng/grid-iterators@2.2.4) (2021-12-13)
13
19
 
14
20
  #### 🩹 Bug fixes
package/README.md CHANGED
@@ -225,7 +225,7 @@ node --experimental-repl-await
225
225
  > const gridIterators = await import("@thi.ng/grid-iterators");
226
226
  ```
227
227
 
228
- Package sizes (gzipped, pre-treeshake): ESM: 2.22 KB
228
+ Package sizes (gzipped, pre-treeshake): ESM: 2.43 KB
229
229
 
230
230
  ## Dependencies
231
231
 
@@ -283,4 +283,4 @@ If this project contributes to an academic publication, please cite it as:
283
283
 
284
284
  ## License
285
285
 
286
- © 2019 - 2021 Karsten Schmidt // Apache Software License 2.0
286
+ © 2019 - 2022 Karsten Schmidt // Apache Software License 2.0
package/circle.d.ts CHANGED
@@ -4,14 +4,14 @@ export declare function circle(cx: number, cy: number, r: number, fill?: boolean
4
4
  * `left,top`..`right,bottom`. Returns undefined if circle lies completely
5
5
  * outside given clip rectangle.
6
6
  *
7
- * @param cx
8
- * @param cy
9
- * @param r
10
- * @param left
11
- * @param top
12
- * @param right
13
- * @param bottom
14
- * @param fill
7
+ * @param cx -
8
+ * @param cy -
9
+ * @param r -
10
+ * @param left -
11
+ * @param top -
12
+ * @param right -
13
+ * @param bottom -
14
+ * @param fill -
15
15
  */
16
16
  export declare const circleClipped: (cx: number, cy: number, r: number, left: number, top: number, right: number, bottom: number, fill?: boolean) => Generator<number[], void, unknown> | undefined;
17
17
  //# sourceMappingURL=circle.d.ts.map
package/circle.js CHANGED
@@ -57,14 +57,14 @@ export function* circle(cx, cy, r, fill = true) {
57
57
  * `left,top`..`right,bottom`. Returns undefined if circle lies completely
58
58
  * outside given clip rectangle.
59
59
  *
60
- * @param cx
61
- * @param cy
62
- * @param r
63
- * @param left
64
- * @param top
65
- * @param right
66
- * @param bottom
67
- * @param fill
60
+ * @param cx -
61
+ * @param cy -
62
+ * @param r -
63
+ * @param left -
64
+ * @param top -
65
+ * @param right -
66
+ * @param bottom -
67
+ * @param fill -
68
68
  */
69
69
  export const circleClipped = (cx, cy, r, left, top, right, bottom, fill = true) => {
70
70
  return intersectRectCircle(left, top, right, bottom, cx, cy, r)
package/clipping.d.ts CHANGED
@@ -3,23 +3,23 @@ import type { FnU7, FnU8, Tuple } from "@thi.ng/api";
3
3
  * Filters points from `src` iterable to remove any falling outside the rect
4
4
  * defined by `left,top`..`right,bottom`.
5
5
  *
6
- * @param src
7
- * @param left
8
- * @param top
9
- * @param right
10
- * @param bottom
6
+ * @param src -
7
+ * @param left -
8
+ * @param top -
9
+ * @param right -
10
+ * @param bottom -
11
11
  */
12
12
  export declare function clipped(src: Iterable<number[]>, left: number, top: number, right: number, bottom: number): Generator<number[], void, unknown>;
13
13
  /**
14
14
  * Based on {@link @thi.ng/geom-isec}, but inlined to avoid dependency.
15
15
  *
16
- * @param x
17
- * @param y
18
- * @param w
19
- * @param h
20
- * @param cx
21
- * @param cy
22
- * @param r
16
+ * @param x -
17
+ * @param y -
18
+ * @param w -
19
+ * @param h -
20
+ * @param cx -
21
+ * @param cy -
22
+ * @param r -
23
23
  *
24
24
  * @internal
25
25
  */
@@ -27,14 +27,14 @@ export declare const intersectRectCircle: FnU7<number, boolean>;
27
27
  /**
28
28
  * Based on {@link @thi.ng/geom-clip-line#liangBarsky2Raw}, but with diff return type.
29
29
  *
30
- * @param ax
31
- * @param ay
32
- * @param bx
33
- * @param by
34
- * @param minx
35
- * @param miny
36
- * @param maxx
37
- * @param maxy
30
+ * @param ax -
31
+ * @param ay -
32
+ * @param bx -
33
+ * @param by -
34
+ * @param minx -
35
+ * @param miny -
36
+ * @param maxx -
37
+ * @param maxy -
38
38
  *
39
39
  * @internal
40
40
  */
package/clipping.js CHANGED
@@ -2,11 +2,11 @@
2
2
  * Filters points from `src` iterable to remove any falling outside the rect
3
3
  * defined by `left,top`..`right,bottom`.
4
4
  *
5
- * @param src
6
- * @param left
7
- * @param top
8
- * @param right
9
- * @param bottom
5
+ * @param src -
6
+ * @param left -
7
+ * @param top -
8
+ * @param right -
9
+ * @param bottom -
10
10
  */
11
11
  export function* clipped(src, left, top, right, bottom) {
12
12
  for (let p of src) {
@@ -19,13 +19,13 @@ const axis = (a, b, c) => (a < b ? a - b : a > b + c ? a - b - c : 0) ** 2;
19
19
  /**
20
20
  * Based on {@link @thi.ng/geom-isec}, but inlined to avoid dependency.
21
21
  *
22
- * @param x
23
- * @param y
24
- * @param w
25
- * @param h
26
- * @param cx
27
- * @param cy
28
- * @param r
22
+ * @param x -
23
+ * @param y -
24
+ * @param w -
25
+ * @param h -
26
+ * @param cx -
27
+ * @param cy -
28
+ * @param r -
29
29
  *
30
30
  * @internal
31
31
  */
@@ -33,14 +33,14 @@ export const intersectRectCircle = (x, y, w, h, cx, cy, r) => axis(cx, x, w) + a
33
33
  /**
34
34
  * Based on {@link @thi.ng/geom-clip-line#liangBarsky2Raw}, but with diff return type.
35
35
  *
36
- * @param ax
37
- * @param ay
38
- * @param bx
39
- * @param by
40
- * @param minx
41
- * @param miny
42
- * @param maxx
43
- * @param maxy
36
+ * @param ax -
37
+ * @param ay -
38
+ * @param bx -
39
+ * @param by -
40
+ * @param minx -
41
+ * @param miny -
42
+ * @param maxx -
43
+ * @param maxy -
44
44
  *
45
45
  * @internal
46
46
  */
package/columns.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Yields sequence of 2D grid coordinates in column-major order.
3
3
  *
4
- * @param cols
5
- * @param rows
4
+ * @param cols -
5
+ * @param rows -
6
6
  */
7
7
  export declare const columns2d: (cols: number, rows?: number) => IterableIterator<number[]>;
8
8
  //# sourceMappingURL=columns.d.ts.map
package/columns.js CHANGED
@@ -4,7 +4,7 @@ import { swapxy } from "./utils.js";
4
4
  /**
5
5
  * Yields sequence of 2D grid coordinates in column-major order.
6
6
  *
7
- * @param cols
8
- * @param rows
7
+ * @param cols -
8
+ * @param rows -
9
9
  */
10
10
  export const columns2d = (cols, rows = cols) => map(swapxy, range2d(rows | 0, cols | 0));
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Yields iterator of 2D grid coordinates based on the recursive Diamond Square
3
+ * algorithm. The given `exp` is a power of 2 exponent and the resulting
4
+ * coordinates (in both directions) will be in the closed [0..2^exp] interval
5
+ * (i.e. each axis is always a power-of-2 plus 1).
6
+ *
7
+ * @remarks
8
+ * Reference: https://en.wikipedia.org/wiki/Diamond-square_algorithm
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * // generate coords for a 17x17 grid
13
+ * [...diamondSquare(4)]
14
+ * // [
15
+ * // [0, 0], [16, 0], [16, 16], [0, 16], [8, 0], [8, 16],
16
+ * // [16, 8], [0, 8], [8, 8], [4, 0], [12, 0], [12, 16],
17
+ * // [4, 16], [8, 4], [8, 12], [4, 8], [12, 8], [0, 4],
18
+ * // ...
19
+ * // ]
20
+ * ```
21
+ *
22
+ * @param exp
23
+ */
24
+ export declare function diamondSquare(exp: number): Generator<number[], void, undefined>;
25
+ //# sourceMappingURL=diamond-square.d.ts.map
@@ -0,0 +1,74 @@
1
+ import { defBitField } from "@thi.ng/bitfield/bitfield";
2
+ /**
3
+ * Yields iterator of 2D grid coordinates based on the recursive Diamond Square
4
+ * algorithm. The given `exp` is a power of 2 exponent and the resulting
5
+ * coordinates (in both directions) will be in the closed [0..2^exp] interval
6
+ * (i.e. each axis is always a power-of-2 plus 1).
7
+ *
8
+ * @remarks
9
+ * Reference: https://en.wikipedia.org/wiki/Diamond-square_algorithm
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // generate coords for a 17x17 grid
14
+ * [...diamondSquare(4)]
15
+ * // [
16
+ * // [0, 0], [16, 0], [16, 16], [0, 16], [8, 0], [8, 16],
17
+ * // [16, 8], [0, 8], [8, 8], [4, 0], [12, 0], [12, 16],
18
+ * // [4, 16], [8, 4], [8, 12], [4, 8], [12, 8], [0, 4],
19
+ * // ...
20
+ * // ]
21
+ * ```
22
+ *
23
+ * @param exp
24
+ */
25
+ export function* diamondSquare(exp) {
26
+ const size = 1 << exp;
27
+ const size1 = size + 1;
28
+ const s2 = size >> 1;
29
+ let res = size;
30
+ const idx = defBitField(size1 * size1);
31
+ const acc = [];
32
+ const $ = (x, y) => {
33
+ !idx.setAt(x + y * size1) && acc.push([x, y]);
34
+ };
35
+ $(0, 0);
36
+ $(res, 0);
37
+ $(res, res);
38
+ $(0, res);
39
+ yield* acc;
40
+ while (res > 1) {
41
+ const r2 = res >> 1;
42
+ for (let y = 0; y <= s2; y += res) {
43
+ const y1 = y + r2;
44
+ const y2 = y + res;
45
+ for (let x = r2; x <= s2; x += res) {
46
+ acc.length = 0;
47
+ const x1 = x - r2;
48
+ const x2 = x + r2;
49
+ $(x, y);
50
+ $(size - x, y);
51
+ $(size - x, size - y);
52
+ $(x, size - y);
53
+ $(x2, y1);
54
+ $(size - x2, y1);
55
+ $(size - x2, size - y1);
56
+ $(x2, size - y1);
57
+ $(x, y2);
58
+ $(size - x, y2);
59
+ $(size - x, size - y2);
60
+ $(x, size - y2);
61
+ $(x1, y1);
62
+ $(size - x1, y1);
63
+ $(size - x1, size - y1);
64
+ $(x1, size - y1);
65
+ $(x, y1);
66
+ $(size - x, y1);
67
+ $(size - x, size - y1);
68
+ $(x, size - y1);
69
+ yield* acc;
70
+ }
71
+ }
72
+ res = r2;
73
+ }
74
+ }
package/flood-fill.d.ts CHANGED
@@ -27,11 +27,11 @@ import type { Predicate2 } from "@thi.ng/api";
27
27
  * // ]
28
28
  * ```
29
29
  *
30
- * @param pred
31
- * @param x
32
- * @param y
33
- * @param width
34
- * @param height
30
+ * @param pred -
31
+ * @param x -
32
+ * @param y -
33
+ * @param width -
34
+ * @param height -
35
35
  */
36
36
  export declare function floodFill(pred: Predicate2<number>, x: number, y: number, width: number, height: number): Generator<number[], void, unknown>;
37
37
  //# sourceMappingURL=flood-fill.d.ts.map
package/flood-fill.js CHANGED
@@ -27,11 +27,11 @@ import { defBitField } from "@thi.ng/bitfield/bitfield";
27
27
  * // ]
28
28
  * ```
29
29
  *
30
- * @param pred
31
- * @param x
32
- * @param y
33
- * @param width
34
- * @param height
30
+ * @param pred -
31
+ * @param x -
32
+ * @param y -
33
+ * @param width -
34
+ * @param height -
35
35
  */
36
36
  export function* floodFill(pred, x, y, width, height) {
37
37
  x |= 0;
package/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from "./column-ends.js";
4
4
  export * from "./columns.js";
5
5
  export * from "./diagonal.js";
6
6
  export * from "./diagonal-ends.js";
7
+ export * from "./diamond-square.js";
7
8
  export * from "./flood-fill.js";
8
9
  export * from "./hilbert.js";
9
10
  export * from "./hvline.js";
package/index.js CHANGED
@@ -4,6 +4,7 @@ export * from "./column-ends.js";
4
4
  export * from "./columns.js";
5
5
  export * from "./diagonal.js";
6
6
  export * from "./diagonal-ends.js";
7
+ export * from "./diamond-square.js";
7
8
  export * from "./flood-fill.js";
8
9
  export * from "./hilbert.js";
9
10
  export * from "./hvline.js";
package/line.d.ts CHANGED
@@ -4,14 +4,14 @@ export declare function line(ax: number, ay: number, bx: number, by: number): Ge
4
4
  * `left,top`..`right,bottom`. Returns undefined if circle lies completely
5
5
  * outside given clip rectangle.
6
6
  *
7
- * @param x1
8
- * @param y1
9
- * @param x2
10
- * @param y2
11
- * @param left
12
- * @param top
13
- * @param right
14
- * @param bottom
7
+ * @param x1 -
8
+ * @param y1 -
9
+ * @param x2 -
10
+ * @param y2 -
11
+ * @param left -
12
+ * @param top -
13
+ * @param right -
14
+ * @param bottom -
15
15
  */
16
16
  export declare const lineClipped: (x1: number, y1: number, x2: number, y2: number, left: number, top: number, right: number, bottom: number) => Generator<number[], void, unknown> | undefined;
17
17
  //# sourceMappingURL=line.d.ts.map
package/line.js CHANGED
@@ -27,14 +27,14 @@ export function* line(ax, ay, bx, by) {
27
27
  * `left,top`..`right,bottom`. Returns undefined if circle lies completely
28
28
  * outside given clip rectangle.
29
29
  *
30
- * @param x1
31
- * @param y1
32
- * @param x2
33
- * @param y2
34
- * @param left
35
- * @param top
36
- * @param right
37
- * @param bottom
30
+ * @param x1 -
31
+ * @param y1 -
32
+ * @param x2 -
33
+ * @param y2 -
34
+ * @param left -
35
+ * @param top -
36
+ * @param right -
37
+ * @param bottom -
38
38
  */
39
39
  export const lineClipped = (x1, y1, x2, y2, left, top, right, bottom) => {
40
40
  const res = liangBarsky(x1, y1, x2, y2, left, top, right - 1, bottom - 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/grid-iterators",
3
- "version": "2.2.5",
3
+ "version": "2.3.1",
4
4
  "description": "2D grid and shape iterators w/ multiple orderings",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -35,21 +35,21 @@
35
35
  "test": "testament test"
36
36
  },
37
37
  "dependencies": {
38
- "@thi.ng/api": "^8.3.3",
39
- "@thi.ng/arrays": "^2.1.3",
40
- "@thi.ng/binary": "^3.1.3",
41
- "@thi.ng/bitfield": "^2.1.4",
42
- "@thi.ng/morton": "^3.1.3",
43
- "@thi.ng/random": "^3.2.3",
44
- "@thi.ng/transducers": "^8.2.0"
38
+ "@thi.ng/api": "^8.3.6",
39
+ "@thi.ng/arrays": "^2.2.2",
40
+ "@thi.ng/binary": "^3.2.2",
41
+ "@thi.ng/bitfield": "^2.1.7",
42
+ "@thi.ng/morton": "^3.1.6",
43
+ "@thi.ng/random": "^3.2.6",
44
+ "@thi.ng/transducers": "^8.3.2"
45
45
  },
46
46
  "devDependencies": {
47
- "@microsoft/api-extractor": "^7.19.2",
48
- "@thi.ng/testament": "^0.2.3",
47
+ "@microsoft/api-extractor": "^7.23.1",
48
+ "@thi.ng/testament": "^0.2.6",
49
49
  "rimraf": "^3.0.2",
50
50
  "tools": "^0.0.1",
51
- "typedoc": "^0.22.10",
52
- "typescript": "^4.5.3"
51
+ "typedoc": "^0.22.15",
52
+ "typescript": "^4.6.4"
53
53
  },
54
54
  "keywords": [
55
55
  "2d",
@@ -81,64 +81,67 @@
81
81
  ],
82
82
  "exports": {
83
83
  ".": {
84
- "import": "./index.js"
84
+ "default": "./index.js"
85
85
  },
86
86
  "./circle": {
87
- "import": "./circle.js"
87
+ "default": "./circle.js"
88
88
  },
89
89
  "./clipping": {
90
- "import": "./clipping.js"
90
+ "default": "./clipping.js"
91
91
  },
92
92
  "./column-ends": {
93
- "import": "./column-ends.js"
93
+ "default": "./column-ends.js"
94
94
  },
95
95
  "./columns": {
96
- "import": "./columns.js"
96
+ "default": "./columns.js"
97
97
  },
98
98
  "./diagonal-ends": {
99
- "import": "./diagonal-ends.js"
99
+ "default": "./diagonal-ends.js"
100
100
  },
101
101
  "./diagonal": {
102
- "import": "./diagonal.js"
102
+ "default": "./diagonal.js"
103
+ },
104
+ "./diamond-square": {
105
+ "default": "./diamond-square.js"
103
106
  },
104
107
  "./flood-fill": {
105
- "import": "./flood-fill.js"
108
+ "default": "./flood-fill.js"
106
109
  },
107
110
  "./hilbert": {
108
- "import": "./hilbert.js"
111
+ "default": "./hilbert.js"
109
112
  },
110
113
  "./hvline": {
111
- "import": "./hvline.js"
114
+ "default": "./hvline.js"
112
115
  },
113
116
  "./interleave": {
114
- "import": "./interleave.js"
117
+ "default": "./interleave.js"
115
118
  },
116
119
  "./line": {
117
- "import": "./line.js"
120
+ "default": "./line.js"
118
121
  },
119
122
  "./random": {
120
- "import": "./random.js"
123
+ "default": "./random.js"
121
124
  },
122
125
  "./row-ends": {
123
- "import": "./row-ends.js"
126
+ "default": "./row-ends.js"
124
127
  },
125
128
  "./rows": {
126
- "import": "./rows.js"
129
+ "default": "./rows.js"
127
130
  },
128
131
  "./spiral": {
129
- "import": "./spiral.js"
132
+ "default": "./spiral.js"
130
133
  },
131
134
  "./zcurve": {
132
- "import": "./zcurve.js"
135
+ "default": "./zcurve.js"
133
136
  },
134
137
  "./zigzag-columns": {
135
- "import": "./zigzag-columns.js"
138
+ "default": "./zigzag-columns.js"
136
139
  },
137
140
  "./zigzag-diagonal": {
138
- "import": "./zigzag-diagonal.js"
141
+ "default": "./zigzag-diagonal.js"
139
142
  },
140
143
  "./zigzag-rows": {
141
- "import": "./zigzag-rows.js"
144
+ "default": "./zigzag-rows.js"
142
145
  }
143
146
  },
144
147
  "thi.ng": {
@@ -149,5 +152,5 @@
149
152
  ],
150
153
  "year": 2019
151
154
  },
152
- "gitHead": "1ba92c6b9509e74e509b4c0b875fc380a97bbbc1\n"
155
+ "gitHead": "cf084be5fd5932226054d2dd32bad35481379f5d\n"
153
156
  }
package/rows.d.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  * Yields sequence of 2D grid coordinates in row-major order. Same as
3
3
  * {@link @thi.ng/transducers#range2d}.
4
4
  *
5
- * @param cols
6
- * @param rows
5
+ * @param cols -
6
+ * @param rows -
7
7
  */
8
8
  export declare const rows2d: (cols: number, rows?: number) => IterableIterator<[number, number]>;
9
9
  //# sourceMappingURL=rows.d.ts.map
package/rows.js CHANGED
@@ -3,7 +3,7 @@ import { range2d } from "@thi.ng/transducers/range2d";
3
3
  * Yields sequence of 2D grid coordinates in row-major order. Same as
4
4
  * {@link @thi.ng/transducers#range2d}.
5
5
  *
6
- * @param cols
7
- * @param rows
6
+ * @param cols -
7
+ * @param rows -
8
8
  */
9
9
  export const rows2d = (cols, rows = cols) => range2d(cols | 0, rows | 0);
package/utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Swaps XY in-place.
3
3
  *
4
- * @param p
4
+ * @param p -
5
5
  *
6
6
  * @internal
7
7
  */
package/utils.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Swaps XY in-place.
4
4
  *
5
- * @param p
5
+ * @param p -
6
6
  *
7
7
  * @internal
8
8
  */