@thi.ng/geom-subdiv-curve 2.1.91 → 2.1.92

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-09T19:12:03Z
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/README.md CHANGED
@@ -70,7 +70,7 @@ For Node.js REPL:
70
70
  const geomSubdivCurve = await import("@thi.ng/geom-subdiv-curve");
71
71
  ```
72
72
 
73
- Package sizes (brotli'd, pre-treeshake): ESM: 656 bytes
73
+ Package sizes (brotli'd, pre-treeshake): ESM: 661 bytes
74
74
 
75
75
  ## Dependencies
76
76
 
package/api.js CHANGED
@@ -4,75 +4,55 @@ import { mixN } from "@thi.ng/vectors/mixn";
4
4
  import { kernel3 } from "./kernels.js";
5
5
  const MIDP = ([a, b]) => [a, addmN([], a, b, 0.5)];
6
6
  const THIRDS = ([a, b]) => [
7
- a,
8
- mixN([], a, b, 1 / 3),
9
- mixN([], a, b, 2 / 3),
7
+ a,
8
+ mixN([], a, b, 1 / 3),
9
+ mixN([], a, b, 2 / 3)
10
10
  ];
11
11
  const wrap2 = (pts) => wrapSides(pts, 0, 1);
12
12
  const wrap3 = (pts) => wrapSides(pts, 1, 1);
13
13
  const subdivWith = (fn) => (pts, i, n) => i < n - 2 ? fn(pts) : [...fn(pts), pts[1]];
14
- /**
15
- * Splits each curve / line segment into halves at midpoint. Version for
16
- * open curves.
17
- */
18
- export const SUBDIV_MID_OPEN = {
19
- fn: subdivWith(MIDP),
20
- size: 2,
14
+ const SUBDIV_MID_OPEN = {
15
+ fn: subdivWith(MIDP),
16
+ size: 2
21
17
  };
22
- /**
23
- * Splits each curve / line segment into halves at midpoint. Version for
24
- * closed curves.
25
- */
26
- export const SUBDIV_MID_CLOSED = {
27
- fn: MIDP,
28
- pre: wrap2,
29
- size: 2,
18
+ const SUBDIV_MID_CLOSED = {
19
+ fn: MIDP,
20
+ pre: wrap2,
21
+ size: 2
30
22
  };
31
- /**
32
- * Splits each curve / line segment into 3 parts at 1/3 and 2/3. Version for
33
- * open curves.
34
- */
35
- export const SUBDIV_THIRDS_OPEN = {
36
- fn: subdivWith(THIRDS),
37
- size: 2,
23
+ const SUBDIV_THIRDS_OPEN = {
24
+ fn: subdivWith(THIRDS),
25
+ size: 2
38
26
  };
39
- /**
40
- * Splits each curve / line segment into 3 parts at 1/3 and 2/3. Version for
41
- * open curves.
42
- */
43
- export const SUBDIV_THIRDS_CLOSED = {
44
- fn: THIRDS,
45
- pre: wrap2,
46
- size: 2,
27
+ const SUBDIV_THIRDS_CLOSED = {
28
+ fn: THIRDS,
29
+ pre: wrap2,
30
+ size: 2
47
31
  };
48
32
  const CHAIKIN_FIRST = kernel3([1 / 2, 1 / 2, 0], [0, 3 / 4, 1 / 4]);
49
33
  const CHAIKIN_MAIN = kernel3([1 / 4, 3 / 4, 0], [0, 3 / 4, 1 / 4]);
50
34
  const CHAIKIN_LAST = kernel3([1 / 4, 3 / 4, 0], [0, 1 / 2, 1 / 2]);
51
- /**
52
- * Chaikin subdivision scheme for open curves.
53
- */
54
- export const SUBDIV_CHAIKIN_OPEN = {
55
- fn: (pts, i, n) => i == 0
56
- ? [pts[0], ...CHAIKIN_FIRST(pts)]
57
- : i === n - 3
58
- ? [...CHAIKIN_LAST(pts), pts[2]]
59
- : CHAIKIN_MAIN(pts),
60
- size: 3,
35
+ const SUBDIV_CHAIKIN_OPEN = {
36
+ fn: (pts, i, n) => i == 0 ? [pts[0], ...CHAIKIN_FIRST(pts)] : i === n - 3 ? [...CHAIKIN_LAST(pts), pts[2]] : CHAIKIN_MAIN(pts),
37
+ size: 3
61
38
  };
62
- /**
63
- * Chaikin subdivision scheme for closed curves.
64
- */
65
- export const SUBDIV_CHAIKIN_CLOSED = {
66
- fn: CHAIKIN_MAIN,
67
- pre: wrap3,
68
- size: 3,
39
+ const SUBDIV_CHAIKIN_CLOSED = {
40
+ fn: CHAIKIN_MAIN,
41
+ pre: wrap3,
42
+ size: 3
69
43
  };
70
44
  const CUBIC_MAIN = kernel3([1 / 8, 3 / 4, 1 / 8], [0, 1 / 2, 1 / 2]);
71
- /**
72
- * Cubic bezier subdivision scheme for closed curves.
73
- */
74
- export const SUBDIV_CUBIC_CLOSED = {
75
- fn: CUBIC_MAIN,
76
- pre: wrap3,
77
- size: 3,
45
+ const SUBDIV_CUBIC_CLOSED = {
46
+ fn: CUBIC_MAIN,
47
+ pre: wrap3,
48
+ size: 3
49
+ };
50
+ export {
51
+ SUBDIV_CHAIKIN_CLOSED,
52
+ SUBDIV_CHAIKIN_OPEN,
53
+ SUBDIV_CUBIC_CLOSED,
54
+ SUBDIV_MID_CLOSED,
55
+ SUBDIV_MID_OPEN,
56
+ SUBDIV_THIRDS_CLOSED,
57
+ SUBDIV_THIRDS_OPEN
78
58
  };
package/kernels.js CHANGED
@@ -1,28 +1,12 @@
1
1
  import { addW2, addW3, addW5 } from "@thi.ng/vectors/addw";
2
- /**
3
- * HOF subdiv kernel function for computing 2 split points from 2 source
4
- * points, using weighted summation (thi.ng/vectors/addW2)
5
- *
6
- * @param u - split coeffs
7
- * @param v - split coeffs
8
- */
9
- export const kernel2 = ([ua, ub], [va, vb]) => ([a, b]) => [addW2([], a, b, ua, ub), addW2([], a, b, va, vb)];
10
- /**
11
- * HOF subdiv kernel function for computing 2 split points from 3 source
12
- * points, using weighted summation (thi.ng/vectors/addW3)
13
- *
14
- * @param u - split coeffs
15
- * @param v - split coeffs
16
- */
17
- export const kernel3 = ([ua, ub, uc], [va, vb, vc]) => ([a, b, c]) => [addW3([], a, b, c, ua, ub, uc), addW3([], a, b, c, va, vb, vc)];
18
- /**
19
- * HOF subdiv kernel function for computing 2 split points from 5 source
20
- * points, using weighted summation (thi.ng/vectors/addW5)
21
- *
22
- * @param u - split coeffs
23
- * @param v - split coeffs
24
- */
25
- export const kernel5 = ([ua, ub, uc, ud, ue], [va, vb, vc, vd, ve]) => ([a, b, c, d, e]) => [
26
- addW5([], a, b, c, d, e, ua, ub, uc, ud, ue),
27
- addW5([], a, b, c, d, e, va, vb, vc, vd, ve),
2
+ const kernel2 = ([ua, ub], [va, vb]) => ([a, b]) => [addW2([], a, b, ua, ub), addW2([], a, b, va, vb)];
3
+ const kernel3 = ([ua, ub, uc], [va, vb, vc]) => ([a, b, c]) => [addW3([], a, b, c, ua, ub, uc), addW3([], a, b, c, va, vb, vc)];
4
+ const kernel5 = ([ua, ub, uc, ud, ue], [va, vb, vc, vd, ve]) => ([a, b, c, d, e]) => [
5
+ addW5([], a, b, c, d, e, ua, ub, uc, ud, ue),
6
+ addW5([], a, b, c, d, e, va, vb, vc, vd, ve)
28
7
  ];
8
+ export {
9
+ kernel2,
10
+ kernel3,
11
+ kernel5
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/geom-subdiv-curve",
3
- "version": "2.1.91",
3
+ "version": "2.1.92",
4
4
  "description": "Freely customizable, iterative nD subdivision curves for open / closed geometries",
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,13 +35,14 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.11",
37
- "@thi.ng/geom-api": "^3.4.49",
38
- "@thi.ng/transducers": "^8.8.14",
39
- "@thi.ng/vectors": "^7.8.8"
38
+ "@thi.ng/api": "^8.9.12",
39
+ "@thi.ng/geom-api": "^3.4.50",
40
+ "@thi.ng/transducers": "^8.8.15",
41
+ "@thi.ng/vectors": "^7.8.9"
40
42
  },
41
43
  "devDependencies": {
42
44
  "@microsoft/api-extractor": "^7.38.3",
45
+ "esbuild": "^0.19.8",
43
46
  "rimraf": "^5.0.5",
44
47
  "tools": "^0.0.1",
45
48
  "typedoc": "^0.25.4",
@@ -89,5 +92,5 @@
89
92
  "geom-splines"
90
93
  ]
91
94
  },
92
- "gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
95
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
93
96
  }
package/subdivide.js CHANGED
@@ -3,17 +3,20 @@ import { mapcatIndexed } from "@thi.ng/transducers/mapcat-indexed";
3
3
  import { partition } from "@thi.ng/transducers/partition";
4
4
  import { push } from "@thi.ng/transducers/push";
5
5
  import { transduce } from "@thi.ng/transducers/transduce";
6
- /**
7
- * http://algorithmicbotany.org/papers/subgpu.sig2003.pdf
8
- *
9
- * @param kernel - subdivision scheme
10
- * @param pts - source points
11
- * @param iter - number of iterations
12
- */
13
- export const subdivide = (pts, { fn, pre, size }, iter = 1) => {
14
- while (iter-- > 0) {
15
- const nump = pts.length;
16
- pts = transduce(comp(partition(size, 1), mapcatIndexed((i, pts) => fn(pts, i, nump))), push(), pre ? pre(pts) : pts);
17
- }
18
- return pts;
6
+ const subdivide = (pts, { fn, pre, size }, iter = 1) => {
7
+ while (iter-- > 0) {
8
+ const nump = pts.length;
9
+ pts = transduce(
10
+ comp(
11
+ partition(size, 1),
12
+ mapcatIndexed((i, pts2) => fn(pts2, i, nump))
13
+ ),
14
+ push(),
15
+ pre ? pre(pts) : pts
16
+ );
17
+ }
18
+ return pts;
19
+ };
20
+ export {
21
+ subdivide
19
22
  };