@thi.ng/grid-iterators 4.0.72 → 4.0.74
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 +1 -1
- package/circle.js +7 -14
- package/clipping.js +2 -4
- package/diagonal-ends.js +1 -2
- package/diagonal-slope.js +8 -16
- package/flood-fill.js +2 -4
- package/hilbert.js +1 -2
- package/hvline.js +2 -4
- package/line.js +1 -2
- package/package.json +14 -14
package/CHANGELOG.md
CHANGED
package/circle.js
CHANGED
|
@@ -3,8 +3,7 @@ import { clipped, intersectRectCircle } from "./clipping.js";
|
|
|
3
3
|
import { hline } from "./hvline.js";
|
|
4
4
|
function* circle(cx, cy, r, fill = true) {
|
|
5
5
|
[cx, cy, r] = asInt(cx, cy, r);
|
|
6
|
-
if (r < 1)
|
|
7
|
-
return;
|
|
6
|
+
if (r < 1) return;
|
|
8
7
|
let x = 0;
|
|
9
8
|
let y = r;
|
|
10
9
|
let y2 = r * r;
|
|
@@ -14,25 +13,20 @@ function* circle(cx, cy, r, fill = true) {
|
|
|
14
13
|
while (x <= y) {
|
|
15
14
|
if (fill) {
|
|
16
15
|
yield* hline(cx - y, cy + x, y << 1);
|
|
17
|
-
if (x)
|
|
18
|
-
yield* hline(cx - y, cy - x, y << 1);
|
|
16
|
+
if (x) yield* hline(cx - y, cy - x, y << 1);
|
|
19
17
|
} else {
|
|
20
18
|
yield [cx - y, cy + x];
|
|
21
|
-
if (y)
|
|
22
|
-
yield [cx + y, cy + x];
|
|
19
|
+
if (y) yield [cx + y, cy + x];
|
|
23
20
|
if (x) {
|
|
24
21
|
yield [cx - y, cy - x];
|
|
25
|
-
if (y)
|
|
26
|
-
yield [cx + y, cy - x];
|
|
22
|
+
if (y) yield [cx + y, cy - x];
|
|
27
23
|
}
|
|
28
24
|
if (x !== y) {
|
|
29
25
|
yield [cx - x, cy - y];
|
|
30
|
-
if (x)
|
|
31
|
-
yield [cx + x, cy - y];
|
|
26
|
+
if (x) yield [cx + x, cy - y];
|
|
32
27
|
if (y) {
|
|
33
28
|
yield [cx - x, cy + y];
|
|
34
|
-
if (x)
|
|
35
|
-
yield [cx + x, cy + y];
|
|
29
|
+
if (x) yield [cx + x, cy + y];
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
32
|
}
|
|
@@ -40,8 +34,7 @@ function* circle(cx, cy, r, fill = true) {
|
|
|
40
34
|
if (sum <= y2) {
|
|
41
35
|
if (fill && x !== y) {
|
|
42
36
|
yield* hline(cx - x, cy - y, x << 1);
|
|
43
|
-
if (y)
|
|
44
|
-
yield* hline(cx - x, cy + y, x << 1);
|
|
37
|
+
if (y) yield* hline(cx - x, cy + y, x << 1);
|
|
45
38
|
}
|
|
46
39
|
y--;
|
|
47
40
|
y2 -= dy2;
|
package/clipping.js
CHANGED
|
@@ -14,13 +14,11 @@ const liangBarsky = (ax, ay, bx, by, minx, miny, maxx, maxy) => {
|
|
|
14
14
|
const clip = (p, q) => {
|
|
15
15
|
if (p < 0) {
|
|
16
16
|
const r = q / p;
|
|
17
|
-
if (r > beta)
|
|
18
|
-
return false;
|
|
17
|
+
if (r > beta) return false;
|
|
19
18
|
r > alpha && (alpha = r);
|
|
20
19
|
} else if (p > 0) {
|
|
21
20
|
const r = q / p;
|
|
22
|
-
if (r < alpha)
|
|
23
|
-
return false;
|
|
21
|
+
if (r < alpha) return false;
|
|
24
22
|
r < beta && (beta = r);
|
|
25
23
|
} else if (q < 0) {
|
|
26
24
|
return false;
|
package/diagonal-ends.js
CHANGED
|
@@ -10,8 +10,7 @@ function* diagonalEnds2d(opts) {
|
|
|
10
10
|
for (let p of diagonal2d({ cols, rows })) {
|
|
11
11
|
if (check(i)) {
|
|
12
12
|
const [x, y] = p;
|
|
13
|
-
if (x === 0 || x === maxX || y === 0 || y === maxY)
|
|
14
|
-
yield tx(x, y);
|
|
13
|
+
if (x === 0 || x === maxX || y === 0 || y === maxY) yield tx(x, y);
|
|
15
14
|
}
|
|
16
15
|
i++;
|
|
17
16
|
}
|
package/diagonal-slope.js
CHANGED
|
@@ -15,24 +15,19 @@ function* diagonalSlopeY(opts) {
|
|
|
15
15
|
n = slope;
|
|
16
16
|
x = nx;
|
|
17
17
|
y = ny;
|
|
18
|
-
if (nx < maxX)
|
|
19
|
-
|
|
20
|
-
else
|
|
21
|
-
ny += slope;
|
|
18
|
+
if (nx < maxX) nx++;
|
|
19
|
+
else ny += slope;
|
|
22
20
|
};
|
|
23
21
|
for (let i = 0; i <= num; i++) {
|
|
24
22
|
yield tx(x, y);
|
|
25
23
|
if (--n > 0) {
|
|
26
24
|
y++;
|
|
27
|
-
if (y >= rows)
|
|
28
|
-
reset();
|
|
25
|
+
if (y >= rows) reset();
|
|
29
26
|
} else {
|
|
30
27
|
x--;
|
|
31
28
|
y++;
|
|
32
|
-
if (x < 0 || y >= rows)
|
|
33
|
-
|
|
34
|
-
else
|
|
35
|
-
n = slope;
|
|
29
|
+
if (x < 0 || y >= rows) reset();
|
|
30
|
+
else n = slope;
|
|
36
31
|
}
|
|
37
32
|
}
|
|
38
33
|
}
|
|
@@ -62,15 +57,12 @@ function* diagonalSlopeX(opts) {
|
|
|
62
57
|
yield tx(x, y);
|
|
63
58
|
if (--n > 0) {
|
|
64
59
|
x--;
|
|
65
|
-
if (x < 0)
|
|
66
|
-
reset();
|
|
60
|
+
if (x < 0) reset();
|
|
67
61
|
} else {
|
|
68
62
|
x--;
|
|
69
63
|
y++;
|
|
70
|
-
if (x < 0 || y >= rows)
|
|
71
|
-
|
|
72
|
-
else
|
|
73
|
-
n = slope;
|
|
64
|
+
if (x < 0 || y >= rows) reset();
|
|
65
|
+
else n = slope;
|
|
74
66
|
}
|
|
75
67
|
}
|
|
76
68
|
}
|
package/flood-fill.js
CHANGED
|
@@ -2,8 +2,7 @@ import { BitField, defBitField } from "@thi.ng/bitfield/bitfield";
|
|
|
2
2
|
function* floodFill(pred, x, y, width, height) {
|
|
3
3
|
x |= 0;
|
|
4
4
|
y |= 0;
|
|
5
|
-
if (!pred(x, y))
|
|
6
|
-
return;
|
|
5
|
+
if (!pred(x, y)) return;
|
|
7
6
|
const queue = [[x, y]];
|
|
8
7
|
const visited = defBitField(width * height);
|
|
9
8
|
height--;
|
|
@@ -15,8 +14,7 @@ function* floodFill(pred, x, y, width, height) {
|
|
|
15
14
|
}
|
|
16
15
|
function* partialRow(pred, queue, visited, x, y, width, height1, step) {
|
|
17
16
|
let idx = y * width + x;
|
|
18
|
-
if (visited.at(idx))
|
|
19
|
-
return;
|
|
17
|
+
if (visited.at(idx)) return;
|
|
20
18
|
let scanUp = false;
|
|
21
19
|
let scanDown = false;
|
|
22
20
|
while (x >= 0 && x < width && pred(x, y)) {
|
package/hilbert.js
CHANGED
|
@@ -3,8 +3,7 @@ function* hilbert2d(opts) {
|
|
|
3
3
|
const { cols, rows, tx } = __opts(opts);
|
|
4
4
|
let hIndex = 0;
|
|
5
5
|
let hOrder = 0;
|
|
6
|
-
while ((1 << hOrder < cols || 1 << hOrder < rows) && hOrder < 15)
|
|
7
|
-
hOrder++;
|
|
6
|
+
while ((1 << hOrder < cols || 1 << hOrder < rows) && hOrder < 15) hOrder++;
|
|
8
7
|
const numBuckets = 1 << 2 * hOrder;
|
|
9
8
|
for (let i = 0, n = cols * rows; i < n; i++) {
|
|
10
9
|
let hx, hy;
|
package/hvline.js
CHANGED
|
@@ -13,8 +13,7 @@ function* vline(x, y, len) {
|
|
|
13
13
|
}
|
|
14
14
|
function* hlineClipped(x, y, len, left, top, right, bottom) {
|
|
15
15
|
[x, y, len] = asInt(x, y, len);
|
|
16
|
-
if (x >= right || y < top || y >= bottom)
|
|
17
|
-
return;
|
|
16
|
+
if (x >= right || y < top || y >= bottom) return;
|
|
18
17
|
if (x < left) {
|
|
19
18
|
len += x - left;
|
|
20
19
|
x = left;
|
|
@@ -23,8 +22,7 @@ function* hlineClipped(x, y, len, left, top, right, bottom) {
|
|
|
23
22
|
}
|
|
24
23
|
function* vlineClipped(x, y, len, left, top, right, bottom) {
|
|
25
24
|
[x, y, len] = asInt(x, y, len);
|
|
26
|
-
if (x < left || x >= right || y >= bottom)
|
|
27
|
-
return;
|
|
25
|
+
if (x < left || x >= right || y >= bottom) return;
|
|
28
26
|
if (y < top) {
|
|
29
27
|
len += y - top;
|
|
30
28
|
y = top;
|
package/line.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/grid-iterators",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.74",
|
|
4
4
|
"description": "2D grid and shape iterators w/ multiple orderings",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -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.
|
|
42
|
-
"@thi.ng/arrays": "^2.9.
|
|
43
|
-
"@thi.ng/binary": "^3.4.
|
|
44
|
-
"@thi.ng/bitfield": "^2.3.
|
|
45
|
-
"@thi.ng/errors": "^2.5.
|
|
46
|
-
"@thi.ng/morton": "^3.1.
|
|
47
|
-
"@thi.ng/random": "^3.
|
|
48
|
-
"@thi.ng/transducers": "^9.0.
|
|
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"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@microsoft/api-extractor": "^7.43.
|
|
52
|
-
"esbuild": "^0.
|
|
53
|
-
"typedoc": "^0.25.
|
|
54
|
-
"typescript": "^5.4.
|
|
51
|
+
"@microsoft/api-extractor": "^7.43.2",
|
|
52
|
+
"esbuild": "^0.21.1",
|
|
53
|
+
"typedoc": "^0.25.13",
|
|
54
|
+
"typescript": "^5.4.5"
|
|
55
55
|
},
|
|
56
56
|
"keywords": [
|
|
57
57
|
"2d",
|
|
@@ -166,5 +166,5 @@
|
|
|
166
166
|
],
|
|
167
167
|
"year": 2019
|
|
168
168
|
},
|
|
169
|
-
"gitHead": "
|
|
169
|
+
"gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
|
|
170
170
|
}
|