@ac-kit/math-curves 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @ac-kit/math-curves
2
+
3
+ Parametric curves: Bézier segments, splines, and the operations that make them
4
+ usable — evaluation, subdivision, arc length, closest point.
5
+
6
+ ## Scope
7
+
8
+ A curve is a map from a scalar parameter to a point. That is the boundary of
9
+ this package: anything parameterised by `t` belongs here, anything defined by a
10
+ boundary or an area belongs in `@ac-kit/math-geometry`.
11
+
12
+ Points are the `Vec2` and `Vec3` tuples from `@ac-kit/math-linear`.
13
+
14
+ ## Contents
15
+
16
+ | Symbol | Description |
17
+ | --------------------------------- | --------------------------------------- |
18
+ | `quadraticBezier2(p0, p1, p2, t)` | Quadratic Bézier in the Bernstein basis |
19
+ | `cubicBezier2(p0, p1, p2, p3, t)` | Cubic Bézier in the Bernstein basis |
20
+
21
+ ## Parameter is not arc length
22
+
23
+ A Bézier evaluated at evenly spaced `t` does not produce evenly spaced points.
24
+ The parameter advances uniformly in the control polygon's basis, not along the
25
+ curve, so a segment with distant control points traverses faster in its middle.
26
+ Anything that animates along a curve, or spaces dashes on it, needs an arc
27
+ length reparameterisation rather than the raw parameter.
28
+
29
+ ## Usage
30
+
31
+ ```ts
32
+ import { cubicBezier2 } from "@ac-kit/math-curves";
33
+
34
+ cubicBezier2([0, 0], [0, 1], [1, 1], [1, 0], 0.5); // [0.5, 0.75]
35
+ ```
36
+
37
+ See the
38
+ [generated API docs](https://anthochamp.github.io/node-essentials/api/math-curves/)
39
+ for the full reference.
@@ -0,0 +1,34 @@
1
+ import type { Vec2 } from "@ac-kit/math-linear";
2
+ /**
3
+ * Evaluates a quadratic Bézier curve at parameter `t` using the Bernstein form:
4
+ *
5
+ * ```text
6
+ * B(t) = (1 − t)²·p0 + 2(1 − t)t·p1 + t²·p2
7
+ * ```
8
+ *
9
+ * The curve starts at `p0`, ends at `p2`, and is tangent to `p0 → p1` and `p1 →
10
+ * p2` at its endpoints; it does not pass through `p1`.
11
+ *
12
+ * @param p0 - Start point.
13
+ * @param p1 - Control point.
14
+ * @param p2 - End point.
15
+ * @param t - Curve parameter, normally in `[0, 1]`.
16
+ * @returns The point on the curve at `t`.
17
+ */
18
+ export declare function quadraticBezier2(p0: Vec2, p1: Vec2, p2: Vec2, t: number): Vec2;
19
+ /**
20
+ * Evaluates a cubic Bézier curve at parameter `t`:
21
+ *
22
+ * ```text
23
+ * B(t) = (1 − t)³·p0 + 3(1 − t)²t·p1 + 3(1 − t)t²·p2 + t³·p3
24
+ * ```
25
+ *
26
+ * @param p0 - Start point.
27
+ * @param p1 - First control point.
28
+ * @param p2 - Second control point.
29
+ * @param p3 - End point.
30
+ * @param t - Curve parameter, normally in `[0, 1]`.
31
+ * @returns The point on the curve at `t`.
32
+ */
33
+ export declare function cubicBezier2(p0: Vec2, p1: Vec2, p2: Vec2, p3: Vec2, t: number): Vec2;
34
+ //# sourceMappingURL=bezier2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bezier2.d.ts","sourceRoot":"","sources":["../src/bezier2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAGhD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAC/B,EAAE,EAAE,IAAI,EACR,EAAE,EAAE,IAAI,EACR,EAAE,EAAE,IAAI,EACR,CAAC,EAAE,MAAM,GACP,IAAI,CAQN;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAC3B,EAAE,EAAE,IAAI,EACR,EAAE,EAAE,IAAI,EACR,EAAE,EAAE,IAAI,EACR,EAAE,EAAE,IAAI,EACR,CAAC,EAAE,MAAM,GACP,IAAI,CAUN"}
@@ -0,0 +1,50 @@
1
+ import { dotPrecise } from "@ac-kit/math-scalar";
2
+ /**
3
+ * Evaluates a quadratic Bézier curve at parameter `t` using the Bernstein form:
4
+ *
5
+ * ```text
6
+ * B(t) = (1 − t)²·p0 + 2(1 − t)t·p1 + t²·p2
7
+ * ```
8
+ *
9
+ * The curve starts at `p0`, ends at `p2`, and is tangent to `p0 → p1` and `p1 →
10
+ * p2` at its endpoints; it does not pass through `p1`.
11
+ *
12
+ * @param p0 - Start point.
13
+ * @param p1 - Control point.
14
+ * @param p2 - End point.
15
+ * @param t - Curve parameter, normally in `[0, 1]`.
16
+ * @returns The point on the curve at `t`.
17
+ */
18
+ export function quadraticBezier2(p0, p1, p2, t) {
19
+ const u = 1 - t;
20
+ const basis = [u * u, 2 * u * t, t * t];
21
+ return [
22
+ dotPrecise(basis, [p0[0], p1[0], p2[0]]),
23
+ dotPrecise(basis, [p0[1], p1[1], p2[1]]),
24
+ ];
25
+ }
26
+ /**
27
+ * Evaluates a cubic Bézier curve at parameter `t`:
28
+ *
29
+ * ```text
30
+ * B(t) = (1 − t)³·p0 + 3(1 − t)²t·p1 + 3(1 − t)t²·p2 + t³·p3
31
+ * ```
32
+ *
33
+ * @param p0 - Start point.
34
+ * @param p1 - First control point.
35
+ * @param p2 - Second control point.
36
+ * @param p3 - End point.
37
+ * @param t - Curve parameter, normally in `[0, 1]`.
38
+ * @returns The point on the curve at `t`.
39
+ */
40
+ export function cubicBezier2(p0, p1, p2, p3, t) {
41
+ const u = 1 - t;
42
+ const uu = u * u;
43
+ const tt = t * t;
44
+ const basis = [uu * u, 3 * uu * t, 3 * u * tt, tt * t];
45
+ return [
46
+ dotPrecise(basis, [p0[0], p1[0], p2[0], p3[0]]),
47
+ dotPrecise(basis, [p0[1], p1[1], p2[1], p3[1]]),
48
+ ];
49
+ }
50
+ //# sourceMappingURL=bezier2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bezier2.js","sourceRoot":"","sources":["../src/bezier2.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,gBAAgB,CAC/B,EAAQ,EACR,EAAQ,EACR,EAAQ,EACR,CAAS;IAET,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChB,MAAM,KAAK,GAAG,CAAC,CAAC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,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./bezier2.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@ac-kit/math-curves",
3
+ "version": "0.1.0",
4
+ "description": "Parametric curves: Bezier segments, splines, and evaluation, subdivision, arc length and closest point over them.",
5
+ "keywords": [
6
+ "bezier",
7
+ "curves",
8
+ "geometry",
9
+ "spline"
10
+ ],
11
+ "homepage": "https://anthochamp.github.io/node-essentials/api/math-curves/",
12
+ "bugs": {
13
+ "url": "https://github.com/anthochamp/node-essentials/issues"
14
+ },
15
+ "license": "BSD-3-Clause",
16
+ "author": "Anthony Champagne <dev@anthonychampagne.fr>",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/anthochamp/node-essentials.git",
20
+ "directory": "packages/math-curves"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "main": "./dist/index.js",
28
+ "exports": {
29
+ ".": "./dist/index.js"
30
+ },
31
+ "publishConfig": {
32
+ "main": "./dist/index.js",
33
+ "exports": {
34
+ ".": "./dist/index.js"
35
+ },
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "compile": "tsc -p ./tsconfig.build.json -outDir dist",
40
+ "compile:check": "tsc -noEmit -p ./tsconfig.json",
41
+ "clean": "rimraf dist",
42
+ "build": "yarn clean && yarn compile",
43
+ "test": "yarn run -T vitest run",
44
+ "prepack": "yarn build"
45
+ },
46
+ "dependencies": {
47
+ "@ac-kit/core": "^0.1.0",
48
+ "@ac-kit/math-linear": "^0.1.0",
49
+ "@ac-kit/math-scalar": "^0.1.0",
50
+ "@types/web": "^0.0.354"
51
+ },
52
+ "devDependencies": {
53
+ "@ac-kit/tsconfig": "0.1.0",
54
+ "@ac-kit/typedoc-config": "0.1.0",
55
+ "@ac-kit/vitest-config": "0.1.0",
56
+ "@typescript/native": "typescript@7.0.2",
57
+ "rimraf": "6.1.3",
58
+ "typedoc": "0.28.20",
59
+ "typescript": "@typescript/typescript6@6.0.2"
60
+ },
61
+ "engines": {
62
+ "node": ">=24"
63
+ }
64
+ }