@thi.ng/grid-iterators 2.2.6 → 2.3.2
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 +7 -1
- package/README.md +1 -1
- package/diamond-square.d.ts +25 -0
- package/diamond-square.js +74 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +36 -33
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-
|
|
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.
|
|
228
|
+
Package sizes (gzipped, pre-treeshake): ESM: 2.43 KB
|
|
229
229
|
|
|
230
230
|
## Dependencies
|
|
231
231
|
|
|
@@ -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/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/grid-iterators",
|
|
3
|
-
"version": "2.2
|
|
3
|
+
"version": "2.3.2",
|
|
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.
|
|
39
|
-
"@thi.ng/arrays": "^2.2.
|
|
40
|
-
"@thi.ng/binary": "^3.2.
|
|
41
|
-
"@thi.ng/bitfield": "^2.1.
|
|
42
|
-
"@thi.ng/morton": "^3.1.
|
|
43
|
-
"@thi.ng/random": "^3.
|
|
44
|
-
"@thi.ng/transducers": "^8.3.
|
|
38
|
+
"@thi.ng/api": "^8.3.6",
|
|
39
|
+
"@thi.ng/arrays": "^2.2.3",
|
|
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.3.0",
|
|
44
|
+
"@thi.ng/transducers": "^8.3.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@microsoft/api-extractor": "^7.
|
|
48
|
-
"@thi.ng/testament": "^0.2.
|
|
47
|
+
"@microsoft/api-extractor": "^7.23.1",
|
|
48
|
+
"@thi.ng/testament": "^0.2.7",
|
|
49
49
|
"rimraf": "^3.0.2",
|
|
50
50
|
"tools": "^0.0.1",
|
|
51
|
-
"typedoc": "^0.22.
|
|
52
|
-
"typescript": "^4.6.
|
|
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
|
-
"
|
|
84
|
+
"default": "./index.js"
|
|
85
85
|
},
|
|
86
86
|
"./circle": {
|
|
87
|
-
"
|
|
87
|
+
"default": "./circle.js"
|
|
88
88
|
},
|
|
89
89
|
"./clipping": {
|
|
90
|
-
"
|
|
90
|
+
"default": "./clipping.js"
|
|
91
91
|
},
|
|
92
92
|
"./column-ends": {
|
|
93
|
-
"
|
|
93
|
+
"default": "./column-ends.js"
|
|
94
94
|
},
|
|
95
95
|
"./columns": {
|
|
96
|
-
"
|
|
96
|
+
"default": "./columns.js"
|
|
97
97
|
},
|
|
98
98
|
"./diagonal-ends": {
|
|
99
|
-
"
|
|
99
|
+
"default": "./diagonal-ends.js"
|
|
100
100
|
},
|
|
101
101
|
"./diagonal": {
|
|
102
|
-
"
|
|
102
|
+
"default": "./diagonal.js"
|
|
103
|
+
},
|
|
104
|
+
"./diamond-square": {
|
|
105
|
+
"default": "./diamond-square.js"
|
|
103
106
|
},
|
|
104
107
|
"./flood-fill": {
|
|
105
|
-
"
|
|
108
|
+
"default": "./flood-fill.js"
|
|
106
109
|
},
|
|
107
110
|
"./hilbert": {
|
|
108
|
-
"
|
|
111
|
+
"default": "./hilbert.js"
|
|
109
112
|
},
|
|
110
113
|
"./hvline": {
|
|
111
|
-
"
|
|
114
|
+
"default": "./hvline.js"
|
|
112
115
|
},
|
|
113
116
|
"./interleave": {
|
|
114
|
-
"
|
|
117
|
+
"default": "./interleave.js"
|
|
115
118
|
},
|
|
116
119
|
"./line": {
|
|
117
|
-
"
|
|
120
|
+
"default": "./line.js"
|
|
118
121
|
},
|
|
119
122
|
"./random": {
|
|
120
|
-
"
|
|
123
|
+
"default": "./random.js"
|
|
121
124
|
},
|
|
122
125
|
"./row-ends": {
|
|
123
|
-
"
|
|
126
|
+
"default": "./row-ends.js"
|
|
124
127
|
},
|
|
125
128
|
"./rows": {
|
|
126
|
-
"
|
|
129
|
+
"default": "./rows.js"
|
|
127
130
|
},
|
|
128
131
|
"./spiral": {
|
|
129
|
-
"
|
|
132
|
+
"default": "./spiral.js"
|
|
130
133
|
},
|
|
131
134
|
"./zcurve": {
|
|
132
|
-
"
|
|
135
|
+
"default": "./zcurve.js"
|
|
133
136
|
},
|
|
134
137
|
"./zigzag-columns": {
|
|
135
|
-
"
|
|
138
|
+
"default": "./zigzag-columns.js"
|
|
136
139
|
},
|
|
137
140
|
"./zigzag-diagonal": {
|
|
138
|
-
"
|
|
141
|
+
"default": "./zigzag-diagonal.js"
|
|
139
142
|
},
|
|
140
143
|
"./zigzag-rows": {
|
|
141
|
-
"
|
|
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": "
|
|
155
|
+
"gitHead": "e23901b8582af71d8a29e0ce4929f15ac509f9e5\n"
|
|
153
156
|
}
|