@thi.ng/geom-splines 2.1.25 → 2.2.1

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**: 2022-08-07T15:28:01Z
3
+ - **Last updated**: 2022-09-21T21:37:59Z
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.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom-splines@2.2.0) (2022-09-21)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add quadraticFromCubic() conversion ([0060a36](https://github.com/thi-ng/umbrella/commit/0060a36))
17
+
12
18
  ### [2.1.22](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom-splines@2.1.22) (2022-08-06)
13
19
 
14
20
  #### ⏱ Performance improvements
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <!-- This file is generated - DO NOT EDIT! -->
2
2
 
3
- # ![geom-splines](https://media.thi.ng/umbrella/banners/thing-geom-splines.svg?8b86baa9)
3
+ # ![geom-splines](https://media.thi.ng/umbrella/banners-20220914/thing-geom-splines.svg?098d31a0)
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@thi.ng/geom-splines.svg)](https://www.npmjs.com/package/@thi.ng/geom-splines)
6
6
  ![npm downloads](https://img.shields.io/npm/dm/@thi.ng/geom-splines.svg)
@@ -10,8 +10,8 @@ This project is part of the
10
10
  [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo.
11
11
 
12
12
  - [About](#about)
13
- - [Status](#status)
14
- - [Related packages](#related-packages)
13
+ - [Status](#status)
14
+ - [Related packages](#related-packages)
15
15
  - [Installation](#installation)
16
16
  - [Dependencies](#dependencies)
17
17
  - [Usage examples](#usage-examples)
@@ -30,13 +30,13 @@ Current implementations partially based on
30
30
  [toxiclibs](http://toxiclibs.org) (Java) and Clojure version of
31
31
  [thi.ng/geom](http://thi.ng/geom).
32
32
 
33
- ### Status
33
+ ## Status
34
34
 
35
35
  **STABLE** - used in production
36
36
 
37
37
  [Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Bgeom-splines%5D+in%3Atitle)
38
38
 
39
- ### Related packages
39
+ ## Related packages
40
40
 
41
41
  - [@thi.ng/geom-subdiv-curve](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-subdiv-curve) - Freely customizable, iterative nD subdivision curves for open / closed geometries
42
42
 
@@ -63,7 +63,7 @@ node --experimental-repl-await
63
63
  > const geomSplines = await import("@thi.ng/geom-splines");
64
64
  ```
65
65
 
66
- Package sizes (gzipped, pre-treeshake): ESM: 2.59 KB
66
+ Package sizes (gzipped, pre-treeshake): ESM: 2.64 KB
67
67
 
68
68
  ## Dependencies
69
69
 
@@ -1,4 +1,28 @@
1
1
  import type { FnU3 } from "@thi.ng/api";
2
- import type { Vec } from "@thi.ng/vectors";
3
- export declare const cubicFromQuadratic: FnU3<Vec, Vec[]>;
2
+ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
3
+ /**
4
+ * Converts the quadratic curve defined by given control points into a cubic
5
+ * bezier. Returns array of 4 new control points.
6
+ *
7
+ * @param a
8
+ * @param b
9
+ * @param c
10
+ */
11
+ export declare const cubicFromQuadratic: FnU3<ReadonlyVec, Vec[]>;
12
+ /**
13
+ * Splits given cubic curve (defined by given control points) into 2 quadratic
14
+ * curve segments approximating the original curve. The `gamma` param (in [0..1]
15
+ * interval) can be used to control the split point (default: 0.5). Returns
16
+ * array of new curves (each a 3-tuple of control points).
17
+ *
18
+ * @remarks
19
+ * Reference: https://ttnghia.github.io/pdf/QuadraticApproximation.pdf
20
+ *
21
+ * @param a
22
+ * @param b
23
+ * @param c
24
+ * @param d
25
+ * @param gamma
26
+ */
27
+ export declare const quadraticFromCubic: (a: ReadonlyVec, b: ReadonlyVec, c: ReadonlyVec, d: ReadonlyVec, gamma?: number) => Vec[][];
4
28
  //# sourceMappingURL=cubic-quadratic.d.ts.map
@@ -1,8 +1,40 @@
1
1
  import { mixN } from "@thi.ng/vectors/mixn";
2
2
  import { set } from "@thi.ng/vectors/set";
3
+ /**
4
+ * Converts the quadratic curve defined by given control points into a cubic
5
+ * bezier. Returns array of 4 new control points.
6
+ *
7
+ * @param a
8
+ * @param b
9
+ * @param c
10
+ */
3
11
  export const cubicFromQuadratic = (a, b, c) => [
4
12
  set([], a),
5
13
  mixN([], a, b, 2 / 3),
6
14
  mixN([], c, b, 2 / 3),
7
15
  set([], c),
8
16
  ];
17
+ /**
18
+ * Splits given cubic curve (defined by given control points) into 2 quadratic
19
+ * curve segments approximating the original curve. The `gamma` param (in [0..1]
20
+ * interval) can be used to control the split point (default: 0.5). Returns
21
+ * array of new curves (each a 3-tuple of control points).
22
+ *
23
+ * @remarks
24
+ * Reference: https://ttnghia.github.io/pdf/QuadraticApproximation.pdf
25
+ *
26
+ * @param a
27
+ * @param b
28
+ * @param c
29
+ * @param d
30
+ * @param gamma
31
+ */
32
+ export const quadraticFromCubic = (a, b, c, d, gamma = 0.5) => {
33
+ const qb = mixN([], a, b, 1.5 * gamma);
34
+ const qd = mixN([], d, c, 1.5 * (1 - gamma));
35
+ const qc = mixN([], qb, qd, gamma);
36
+ return [
37
+ [set([], a), qb, qc],
38
+ [set([], qc), qd, set([], d)],
39
+ ];
40
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/geom-splines",
3
- "version": "2.1.25",
3
+ "version": "2.2.1",
4
4
  "description": "nD cubic & quadratic curve analysis, conversion, interpolation, splitting",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,21 +34,21 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.4.1",
38
- "@thi.ng/checks": "^3.2.4",
39
- "@thi.ng/geom-api": "^3.3.8",
40
- "@thi.ng/geom-arc": "^2.1.25",
41
- "@thi.ng/geom-resample": "^2.1.25",
42
- "@thi.ng/math": "^5.3.7",
43
- "@thi.ng/vectors": "^7.5.14"
37
+ "@thi.ng/api": "^8.4.2",
38
+ "@thi.ng/checks": "^3.2.5",
39
+ "@thi.ng/geom-api": "^3.3.10",
40
+ "@thi.ng/geom-arc": "^2.1.27",
41
+ "@thi.ng/geom-resample": "^2.1.27",
42
+ "@thi.ng/math": "^5.3.9",
43
+ "@thi.ng/vectors": "^7.5.16"
44
44
  },
45
45
  "devDependencies": {
46
- "@microsoft/api-extractor": "^7.25.0",
47
- "@thi.ng/testament": "^0.2.12",
46
+ "@microsoft/api-extractor": "^7.31.1",
47
+ "@thi.ng/testament": "^0.3.0",
48
48
  "rimraf": "^3.0.2",
49
49
  "tools": "^0.0.1",
50
50
  "typedoc": "^0.22.17",
51
- "typescript": "^4.7.4"
51
+ "typescript": "^4.8.3"
52
52
  },
53
53
  "keywords": [
54
54
  "2d",
@@ -144,5 +144,5 @@
144
144
  "geom-subdiv-curve"
145
145
  ]
146
146
  },
147
- "gitHead": "be8423e2019e95c14a096260a93b9762dde0c768\n"
147
+ "gitHead": "f4c59114f2d2dfafa9014626038a9ec5242b0606\n"
148
148
  }