@thi.ng/geom-tessellate 2.1.92 → 2.1.94
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/earcut.js +36 -39
- package/edge-split.js +16 -6
- package/inset.js +15 -4
- package/package.json +12 -9
- package/quad-fan.js +13 -3
- package/rim-tris.js +21 -3
- package/tessellate.js +14 -2
- package/tri-fan.js +13 -3
package/CHANGELOG.md
CHANGED
package/earcut.js
CHANGED
|
@@ -3,47 +3,44 @@ import { polyArea2 } from "@thi.ng/geom-poly-utils/area";
|
|
|
3
3
|
import { range } from "@thi.ng/transducers/range";
|
|
4
4
|
import { signedArea2 } from "@thi.ng/vectors/signed-area";
|
|
5
5
|
const snip = (points, u, v, w, n, ids) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
}
|
|
6
|
+
const a = points[ids[u]];
|
|
7
|
+
const b = points[ids[v]];
|
|
8
|
+
const c = points[ids[w]];
|
|
9
|
+
if (signedArea2(a, b, c) > 0) {
|
|
10
|
+
for (let i = 0; i < n; i++) {
|
|
11
|
+
if (i !== u && i !== v && i !== w) {
|
|
12
|
+
if (pointInTriangle2(points[ids[i]], a, b, c)) {
|
|
13
|
+
return;
|
|
16
14
|
}
|
|
17
|
-
|
|
15
|
+
}
|
|
18
16
|
}
|
|
17
|
+
return [a, b, c];
|
|
18
|
+
}
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
ids.splice(v, 1);
|
|
41
|
-
n--;
|
|
42
|
-
count = 2 * n;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
count--;
|
|
46
|
-
}
|
|
20
|
+
const earCut2 = (points) => {
|
|
21
|
+
const tris = [];
|
|
22
|
+
let n = points.length;
|
|
23
|
+
const ids = [...polyArea2(points) > 0 ? range(n) : range(n - 1, -1, -1)];
|
|
24
|
+
let count = 2 * n - 1;
|
|
25
|
+
let v = n - 1, u, w, t;
|
|
26
|
+
while (count > 0 && n > 2) {
|
|
27
|
+
u = n <= v ? 0 : v;
|
|
28
|
+
v = u + 1;
|
|
29
|
+
v = n <= v ? 0 : v;
|
|
30
|
+
w = v + 1;
|
|
31
|
+
w = n <= w ? 0 : w;
|
|
32
|
+
t = snip(points, u, v, w, n, ids);
|
|
33
|
+
if (t !== void 0) {
|
|
34
|
+
tris.push(t);
|
|
35
|
+
ids.splice(v, 1);
|
|
36
|
+
n--;
|
|
37
|
+
count = 2 * n;
|
|
38
|
+
} else {
|
|
39
|
+
count--;
|
|
47
40
|
}
|
|
48
|
-
|
|
41
|
+
}
|
|
42
|
+
return tris;
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
earCut2
|
|
49
46
|
};
|
package/edge-split.js
CHANGED
|
@@ -6,13 +6,23 @@ import { push } from "@thi.ng/transducers/push";
|
|
|
6
6
|
import { transduce } from "@thi.ng/transducers/transduce";
|
|
7
7
|
import { wrapSides } from "@thi.ng/transducers/wrap-sides";
|
|
8
8
|
import { mixN } from "@thi.ng/vectors/mixn";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const edgeSplit = (points) => {
|
|
10
|
+
const c = centroid(points);
|
|
11
|
+
return transduce(
|
|
12
|
+
comp(
|
|
13
|
+
partition(2, 1),
|
|
14
|
+
mapcat(([a, b]) => {
|
|
12
15
|
const m = mixN([], a, b, 0.5);
|
|
13
16
|
return [
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
[a, m, c],
|
|
18
|
+
[m, b, c]
|
|
16
19
|
];
|
|
17
|
-
|
|
20
|
+
})
|
|
21
|
+
),
|
|
22
|
+
push(),
|
|
23
|
+
wrapSides(points, 0, 1)
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
edgeSplit
|
|
18
28
|
};
|
package/inset.js
CHANGED
|
@@ -7,8 +7,19 @@ import { transduce } from "@thi.ng/transducers/transduce";
|
|
|
7
7
|
import { wrapSides } from "@thi.ng/transducers/wrap-sides";
|
|
8
8
|
import { zip } from "@thi.ng/transducers/zip";
|
|
9
9
|
import { mixN } from "@thi.ng/vectors/mixn";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const tesselInset = (inset = 0.5, keepInterior = false) => (points) => {
|
|
11
|
+
const c = centroid(points);
|
|
12
|
+
const inner = points.map((p) => mixN([], p, c, inset));
|
|
13
|
+
return transduce(
|
|
14
|
+
comp(
|
|
15
|
+
partition(2, 1),
|
|
16
|
+
map(([[a, b], [c2, d]]) => [a, b, d, c2])
|
|
17
|
+
),
|
|
18
|
+
push(),
|
|
19
|
+
keepInterior ? [inner] : [],
|
|
20
|
+
wrapSides([...zip(points, inner)], 0, 1)
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
tesselInset
|
|
14
25
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/geom-tessellate",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.94",
|
|
4
4
|
"description": "2D/3D convex polygon tessellators",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,15 +35,16 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/checks": "^3.4.
|
|
37
|
-
"@thi.ng/geom-api": "^3.4.
|
|
38
|
-
"@thi.ng/geom-isec": "^2.1.
|
|
39
|
-
"@thi.ng/geom-poly-utils": "^2.3.
|
|
40
|
-
"@thi.ng/transducers": "^8.8.
|
|
41
|
-
"@thi.ng/vectors": "^7.8.
|
|
38
|
+
"@thi.ng/checks": "^3.4.12",
|
|
39
|
+
"@thi.ng/geom-api": "^3.4.51",
|
|
40
|
+
"@thi.ng/geom-isec": "^2.1.93",
|
|
41
|
+
"@thi.ng/geom-poly-utils": "^2.3.77",
|
|
42
|
+
"@thi.ng/transducers": "^8.8.15",
|
|
43
|
+
"@thi.ng/vectors": "^7.8.10"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"@microsoft/api-extractor": "^7.38.3",
|
|
47
|
+
"esbuild": "^0.19.8",
|
|
45
48
|
"rimraf": "^5.0.5",
|
|
46
49
|
"tools": "^0.0.1",
|
|
47
50
|
"typedoc": "^0.25.4",
|
|
@@ -98,5 +101,5 @@
|
|
|
98
101
|
"parent": "@thi.ng/geom",
|
|
99
102
|
"year": 2013
|
|
100
103
|
},
|
|
101
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "22e36fa838e5431d40165384918b395603bbd92f\n"
|
|
102
105
|
}
|
package/quad-fan.js
CHANGED
|
@@ -6,7 +6,17 @@ import { push } from "@thi.ng/transducers/push";
|
|
|
6
6
|
import { transduce } from "@thi.ng/transducers/transduce";
|
|
7
7
|
import { wrapSides } from "@thi.ng/transducers/wrap-sides";
|
|
8
8
|
import { mixN } from "@thi.ng/vectors/mixn";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const quadFan = (points) => {
|
|
10
|
+
const p = centroid(points);
|
|
11
|
+
return transduce(
|
|
12
|
+
comp(
|
|
13
|
+
partition(3, 1),
|
|
14
|
+
map(([a, b, c]) => [mixN([], a, b, 0.5), b, mixN([], b, c, 0.5), p])
|
|
15
|
+
),
|
|
16
|
+
push(),
|
|
17
|
+
wrapSides(points)
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
quadFan
|
|
12
22
|
};
|
package/rim-tris.js
CHANGED
|
@@ -6,7 +6,25 @@ import { transduce } from "@thi.ng/transducers/transduce";
|
|
|
6
6
|
import { wrapSides } from "@thi.ng/transducers/wrap-sides";
|
|
7
7
|
import { zip } from "@thi.ng/transducers/zip";
|
|
8
8
|
import { mixN } from "@thi.ng/vectors/mixn";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const rimTris = (points) => {
|
|
10
|
+
const edgeCentroids = transduce(
|
|
11
|
+
comp(
|
|
12
|
+
partition(2, 1),
|
|
13
|
+
map((e) => mixN([], e[0], e[1], 0.5))
|
|
14
|
+
),
|
|
15
|
+
push(),
|
|
16
|
+
wrapSides(points, 0, 1)
|
|
17
|
+
);
|
|
18
|
+
return transduce(
|
|
19
|
+
comp(
|
|
20
|
+
partition(2, 1),
|
|
21
|
+
map((t) => [t[0][0], t[1][1], t[1][0]])
|
|
22
|
+
),
|
|
23
|
+
push(),
|
|
24
|
+
[edgeCentroids],
|
|
25
|
+
wrapSides([...zip(edgeCentroids, points)], 1, 0)
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
rimTris
|
|
12
30
|
};
|
package/tessellate.js
CHANGED
|
@@ -6,6 +6,18 @@ import { reducer } from "@thi.ng/transducers/reduce";
|
|
|
6
6
|
import { repeat } from "@thi.ng/transducers/repeat";
|
|
7
7
|
import { scan } from "@thi.ng/transducers/scan";
|
|
8
8
|
import { transduce } from "@thi.ng/transducers/transduce";
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
function tessellate(...args) {
|
|
10
|
+
return transduce(
|
|
11
|
+
scan(
|
|
12
|
+
reducer(
|
|
13
|
+
() => [args[0]],
|
|
14
|
+
(acc, fn) => transduce(mapcat(fn), push(), acc)
|
|
15
|
+
)
|
|
16
|
+
),
|
|
17
|
+
last(),
|
|
18
|
+
isFunction(args[1]) ? repeat(args[1], args[2] || 1) : args[1]
|
|
19
|
+
);
|
|
11
20
|
}
|
|
21
|
+
export {
|
|
22
|
+
tessellate
|
|
23
|
+
};
|
package/tri-fan.js
CHANGED
|
@@ -5,7 +5,17 @@ import { partition } from "@thi.ng/transducers/partition";
|
|
|
5
5
|
import { push } from "@thi.ng/transducers/push";
|
|
6
6
|
import { transduce } from "@thi.ng/transducers/transduce";
|
|
7
7
|
import { wrapSides } from "@thi.ng/transducers/wrap-sides";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const triFan = (points) => {
|
|
9
|
+
const c = centroid(points);
|
|
10
|
+
return transduce(
|
|
11
|
+
comp(
|
|
12
|
+
partition(2, 1),
|
|
13
|
+
map(([a, b]) => [a, b, c])
|
|
14
|
+
),
|
|
15
|
+
push(),
|
|
16
|
+
wrapSides(points, 0, 1)
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
triFan
|
|
11
21
|
};
|