@thi.ng/geom-tessellate 2.1.91 → 2.1.93

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**: 2023-12-03T12:13:31Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
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.
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
- 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;
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
- return [a, b, c];
15
+ }
18
16
  }
17
+ return [a, b, c];
18
+ }
19
19
  };
20
- /**
21
- * Tessellator for simple 2D polygons.
22
- *
23
- * @param points - polygon vertices
24
- */
25
- export const earCut2 = (points) => {
26
- const tris = [];
27
- let n = points.length;
28
- const ids = [...(polyArea2(points) > 0 ? range(n) : range(n - 1, -1, -1))];
29
- let count = 2 * n - 1;
30
- let v = n - 1, u, w, t;
31
- while (count > 0 && n > 2) {
32
- u = n <= v ? 0 : v;
33
- v = u + 1;
34
- v = n <= v ? 0 : v;
35
- w = v + 1;
36
- w = n <= w ? 0 : w;
37
- t = snip(points, u, v, w, n, ids);
38
- if (t !== undefined) {
39
- tris.push(t);
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
- return tris;
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
- export const edgeSplit = (points) => {
10
- const c = centroid(points);
11
- return transduce(comp(partition(2, 1), mapcat(([a, b]) => {
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
- [a, m, c],
15
- [m, b, c],
17
+ [a, m, c],
18
+ [m, b, c]
16
19
  ];
17
- })), push(), wrapSides(points, 0, 1));
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
- export 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(comp(partition(2, 1), map(([[a, b], [c, d]]) => [a, b, d, c])), push(), keepInterior ? [inner] : [], wrapSides([...zip(points, inner)], 0, 1));
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.91",
3
+ "version": "2.1.93",
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 clean && tsc --declaration",
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,16 +35,16 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/checks": "^3.4.10",
37
- "@thi.ng/geom-api": "^3.4.48",
38
- "@thi.ng/geom-isec": "^2.1.90",
39
- "@thi.ng/geom-poly-utils": "^2.3.74",
40
- "@thi.ng/transducers": "^8.8.13",
41
- "@thi.ng/vectors": "^7.8.7"
38
+ "@thi.ng/checks": "^3.4.12",
39
+ "@thi.ng/geom-api": "^3.4.50",
40
+ "@thi.ng/geom-isec": "^2.1.92",
41
+ "@thi.ng/geom-poly-utils": "^2.3.76",
42
+ "@thi.ng/transducers": "^8.8.15",
43
+ "@thi.ng/vectors": "^7.8.9"
42
44
  },
43
45
  "devDependencies": {
44
46
  "@microsoft/api-extractor": "^7.38.3",
45
- "@thi.ng/testament": "^0.4.3",
47
+ "esbuild": "^0.19.8",
46
48
  "rimraf": "^5.0.5",
47
49
  "tools": "^0.0.1",
48
50
  "typedoc": "^0.25.4",
@@ -99,5 +101,5 @@
99
101
  "parent": "@thi.ng/geom",
100
102
  "year": 2013
101
103
  },
102
- "gitHead": "04d1de79f256d7a53c6b5fd157b37f49bc88e11d\n"
104
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
103
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
- export const quadFan = (points) => {
10
- const p = centroid(points);
11
- return transduce(comp(partition(3, 1), map(([a, b, c]) => [mixN([], a, b, 0.5), b, mixN([], b, c, 0.5), p])), push(), wrapSides(points));
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
- export const rimTris = (points) => {
10
- const edgeCentroids = transduce(comp(partition(2, 1), map((e) => mixN([], e[0], e[1], 0.5))), push(), wrapSides(points, 0, 1));
11
- return transduce(comp(partition(2, 1), map((t) => [t[0][0], t[1][1], t[1][0]])), push(), [edgeCentroids], wrapSides([...zip(edgeCentroids, points)], 1, 0));
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
- export function tessellate(...args) {
10
- return transduce(scan(reducer(() => [args[0]], (acc, fn) => transduce(mapcat(fn), push(), acc))), last(), isFunction(args[1]) ? repeat(args[1], args[2] || 1) : args[1]);
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
- export const triFan = (points) => {
9
- const c = centroid(points);
10
- return transduce(comp(partition(2, 1), map(([a, b]) => [a, b, c])), push(), wrapSides(points, 0, 1));
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
  };