@motionscript/math 0.0.0-stage → 0.1.0-alpha.5
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 +110 -0
- package/LICENSE +201 -0
- package/NOTICE +48 -0
- package/README.md +385 -3
- package/dist/annotate/angle-mark.d.ts +46 -0
- package/dist/annotate/angle-mark.d.ts.map +1 -0
- package/dist/annotate/angle-mark.js +132 -0
- package/dist/annotate/angle-mark.js.map +1 -0
- package/dist/annotate/curly-brace.d.ts +46 -0
- package/dist/annotate/curly-brace.d.ts.map +1 -0
- package/dist/annotate/curly-brace.js +114 -0
- package/dist/annotate/curly-brace.js.map +1 -0
- package/dist/annotate/emphasis-mark.d.ts +20 -0
- package/dist/annotate/emphasis-mark.d.ts.map +1 -0
- package/dist/annotate/emphasis-mark.js +81 -0
- package/dist/annotate/emphasis-mark.js.map +1 -0
- package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
- package/dist/browser/chunks/chunk-3GJB6AVO.js +2 -0
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +7 -0
- package/dist/browser/chunks/chunk-D5WHCVBC.js +2 -0
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +7 -0
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +2 -0
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +7 -0
- package/dist/browser/chunks/mathjax-DNP3YRES.js +61 -0
- package/dist/browser/chunks/mathjax-DNP3YRES.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +30 -0
- package/dist/browser/tex.js +2 -0
- package/dist/browser/tex.js.map +7 -0
- package/dist/engine.d.ts +64 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +42 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/brace.d.ts +8 -0
- package/dist/kit/brace.d.ts.map +1 -0
- package/dist/kit/brace.js +36 -0
- package/dist/kit/brace.js.map +1 -0
- package/dist/kit/cache.d.ts +30 -0
- package/dist/kit/cache.d.ts.map +1 -0
- package/dist/kit/cache.js +53 -0
- package/dist/kit/cache.js.map +1 -0
- package/dist/kit/contour.d.ts +8 -0
- package/dist/kit/contour.d.ts.map +1 -0
- package/dist/kit/contour.js +93 -0
- package/dist/kit/contour.js.map +1 -0
- package/dist/kit/coords.d.ts +69 -0
- package/dist/kit/coords.d.ts.map +1 -0
- package/dist/kit/coords.js +224 -0
- package/dist/kit/coords.js.map +1 -0
- package/dist/kit/curve.d.ts +17 -0
- package/dist/kit/curve.d.ts.map +1 -0
- package/dist/kit/curve.js +22 -0
- package/dist/kit/curve.js.map +1 -0
- package/dist/kit/equation.d.ts +61 -0
- package/dist/kit/equation.d.ts.map +1 -0
- package/dist/kit/equation.js +168 -0
- package/dist/kit/equation.js.map +1 -0
- package/dist/kit/equation3d.d.ts +50 -0
- package/dist/kit/equation3d.d.ts.map +1 -0
- package/dist/kit/equation3d.js +103 -0
- package/dist/kit/equation3d.js.map +1 -0
- package/dist/kit/expression.d.ts +35 -0
- package/dist/kit/expression.d.ts.map +1 -0
- package/dist/kit/expression.js +124 -0
- package/dist/kit/expression.js.map +1 -0
- package/dist/kit/field-mark.d.ts +58 -0
- package/dist/kit/field-mark.d.ts.map +1 -0
- package/dist/kit/field-mark.js +129 -0
- package/dist/kit/field-mark.js.map +1 -0
- package/dist/kit/field.d.ts +14 -0
- package/dist/kit/field.d.ts.map +1 -0
- package/dist/kit/field.js +46 -0
- package/dist/kit/field.js.map +1 -0
- package/dist/kit/follow.d.ts +71 -0
- package/dist/kit/follow.d.ts.map +1 -0
- package/dist/kit/follow.js +159 -0
- package/dist/kit/follow.js.map +1 -0
- package/dist/kit/furniture.d.ts +30 -0
- package/dist/kit/furniture.d.ts.map +1 -0
- package/dist/kit/furniture.js +87 -0
- package/dist/kit/furniture.js.map +1 -0
- package/dist/kit/geometry.d.ts +13 -0
- package/dist/kit/geometry.d.ts.map +1 -0
- package/dist/kit/geometry.js +54 -0
- package/dist/kit/geometry.js.map +1 -0
- package/dist/kit/mark.d.ts +47 -0
- package/dist/kit/mark.d.ts.map +1 -0
- package/dist/kit/mark.js +103 -0
- package/dist/kit/mark.js.map +1 -0
- package/dist/kit/part-fills.d.ts +23 -0
- package/dist/kit/part-fills.d.ts.map +1 -0
- package/dist/kit/part-fills.js +46 -0
- package/dist/kit/part-fills.js.map +1 -0
- package/dist/kit/place.d.ts +18 -0
- package/dist/kit/place.d.ts.map +1 -0
- package/dist/kit/place.js +68 -0
- package/dist/kit/place.js.map +1 -0
- package/dist/kit/placement.d.ts +8 -0
- package/dist/kit/placement.d.ts.map +1 -0
- package/dist/kit/placement.js +8 -0
- package/dist/kit/placement.js.map +1 -0
- package/dist/kit/sampler.d.ts +17 -0
- package/dist/kit/sampler.d.ts.map +1 -0
- package/dist/kit/sampler.js +250 -0
- package/dist/kit/sampler.js.map +1 -0
- package/dist/kit/scale.d.ts +12 -0
- package/dist/kit/scale.d.ts.map +1 -0
- package/dist/kit/scale.js +37 -0
- package/dist/kit/scale.js.map +1 -0
- package/dist/kit/source.d.ts +22 -0
- package/dist/kit/source.d.ts.map +1 -0
- package/dist/kit/source.js +45 -0
- package/dist/kit/source.js.map +1 -0
- package/dist/kit/system.d.ts +33 -0
- package/dist/kit/system.d.ts.map +1 -0
- package/dist/kit/system.js +67 -0
- package/dist/kit/system.js.map +1 -0
- package/dist/kit/ticks.d.ts +19 -0
- package/dist/kit/ticks.d.ts.map +1 -0
- package/dist/kit/ticks.js +78 -0
- package/dist/kit/ticks.js.map +1 -0
- package/dist/kit/withdrawn.d.ts +9 -0
- package/dist/kit/withdrawn.d.ts.map +1 -0
- package/dist/kit/withdrawn.js +9 -0
- package/dist/kit/withdrawn.js.map +1 -0
- package/dist/marks/curve-area.d.ts +32 -0
- package/dist/marks/curve-area.d.ts.map +1 -0
- package/dist/marks/curve-area.js +82 -0
- package/dist/marks/curve-area.js.map +1 -0
- package/dist/marks/drop-lines.d.ts +22 -0
- package/dist/marks/drop-lines.d.ts.map +1 -0
- package/dist/marks/drop-lines.js +58 -0
- package/dist/marks/drop-lines.js.map +1 -0
- package/dist/marks/plot-point.d.ts +35 -0
- package/dist/marks/plot-point.d.ts.map +1 -0
- package/dist/marks/plot-point.js +97 -0
- package/dist/marks/plot-point.js.map +1 -0
- package/dist/marks/riemann-sum.d.ts +37 -0
- package/dist/marks/riemann-sum.d.ts.map +1 -0
- package/dist/marks/riemann-sum.js +91 -0
- package/dist/marks/riemann-sum.js.map +1 -0
- package/dist/marks/tangent-line.d.ts +27 -0
- package/dist/marks/tangent-line.d.ts.map +1 -0
- package/dist/marks/tangent-line.js +103 -0
- package/dist/marks/tangent-line.js.map +1 -0
- package/dist/marks/vector-arrow.d.ts +32 -0
- package/dist/marks/vector-arrow.d.ts.map +1 -0
- package/dist/marks/vector-arrow.js +87 -0
- package/dist/marks/vector-arrow.js.map +1 -0
- package/dist/nodes.d.ts +35 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +63 -0
- package/dist/nodes.js.map +1 -0
- package/dist/plots/function-plot.d.ts +67 -0
- package/dist/plots/function-plot.d.ts.map +1 -0
- package/dist/plots/function-plot.js +215 -0
- package/dist/plots/function-plot.js.map +1 -0
- package/dist/plots/points-plot.d.ts +28 -0
- package/dist/plots/points-plot.d.ts.map +1 -0
- package/dist/plots/points-plot.js +99 -0
- package/dist/plots/points-plot.js.map +1 -0
- package/dist/plots/stream-lines.d.ts +35 -0
- package/dist/plots/stream-lines.d.ts.map +1 -0
- package/dist/plots/stream-lines.js +141 -0
- package/dist/plots/stream-lines.js.map +1 -0
- package/dist/plots/traced-path.d.ts +31 -0
- package/dist/plots/traced-path.d.ts.map +1 -0
- package/dist/plots/traced-path.js +56 -0
- package/dist/plots/traced-path.js.map +1 -0
- package/dist/plots/vector-field.d.ts +23 -0
- package/dist/plots/vector-field.d.ts.map +1 -0
- package/dist/plots/vector-field.js +91 -0
- package/dist/plots/vector-field.js.map +1 -0
- package/dist/structures/graph-layout.d.ts +11 -0
- package/dist/structures/graph-layout.d.ts.map +1 -0
- package/dist/structures/graph-layout.js +135 -0
- package/dist/structures/graph-layout.js.map +1 -0
- package/dist/structures/network-graph.d.ts +83 -0
- package/dist/structures/network-graph.d.ts.map +1 -0
- package/dist/structures/network-graph.js +289 -0
- package/dist/structures/network-graph.js.map +1 -0
- package/dist/structures/sample-space.d.ts +62 -0
- package/dist/structures/sample-space.d.ts.map +1 -0
- package/dist/structures/sample-space.js +199 -0
- package/dist/structures/sample-space.js.map +1 -0
- package/dist/systems/axes2d.d.ts +75 -0
- package/dist/systems/axes2d.d.ts.map +1 -0
- package/dist/systems/axes2d.js +193 -0
- package/dist/systems/axes2d.js.map +1 -0
- package/dist/systems/number-line.d.ts +49 -0
- package/dist/systems/number-line.d.ts.map +1 -0
- package/dist/systems/number-line.js +127 -0
- package/dist/systems/number-line.js.map +1 -0
- package/dist/systems/number-plane.d.ts +59 -0
- package/dist/systems/number-plane.d.ts.map +1 -0
- package/dist/systems/number-plane.js +193 -0
- package/dist/systems/number-plane.js.map +1 -0
- package/dist/systems/polar-plane.d.ts +48 -0
- package/dist/systems/polar-plane.d.ts.map +1 -0
- package/dist/systems/polar-plane.js +165 -0
- package/dist/systems/polar-plane.js.map +1 -0
- package/dist/tex/geometry.d.ts +85 -0
- package/dist/tex/geometry.d.ts.map +1 -0
- package/dist/tex/geometry.js +632 -0
- package/dist/tex/geometry.js.map +1 -0
- package/dist/tex/index.d.ts +11 -0
- package/dist/tex/index.d.ts.map +1 -0
- package/dist/tex/index.js +9 -0
- package/dist/tex/index.js.map +1 -0
- package/dist/tex/mathjax.d.ts +33 -0
- package/dist/tex/mathjax.d.ts.map +1 -0
- package/dist/tex/mathjax.js +74 -0
- package/dist/tex/mathjax.js.map +1 -0
- package/dist/tex/matrix.d.ts +31 -0
- package/dist/tex/matrix.d.ts.map +1 -0
- package/dist/tex/matrix.js +73 -0
- package/dist/tex/matrix.js.map +1 -0
- package/dist/tex/node.d.ts +215 -0
- package/dist/tex/node.d.ts.map +1 -0
- package/dist/tex/node.js +595 -0
- package/dist/tex/node.js.map +1 -0
- package/dist/tex/tween.d.ts +50 -0
- package/dist/tex/tween.d.ts.map +1 -0
- package/dist/tex/tween.js +253 -0
- package/dist/tex/tween.js.map +1 -0
- package/dist/three/axes3d.d.ts +87 -0
- package/dist/three/axes3d.d.ts.map +1 -0
- package/dist/three/axes3d.js +228 -0
- package/dist/three/axes3d.js.map +1 -0
- package/dist/three/curve-plot3d.d.ts +60 -0
- package/dist/three/curve-plot3d.d.ts.map +1 -0
- package/dist/three/curve-plot3d.js +143 -0
- package/dist/three/curve-plot3d.js.map +1 -0
- package/dist/three/label3d.d.ts +11 -0
- package/dist/three/label3d.d.ts.map +1 -0
- package/dist/three/label3d.js +40 -0
- package/dist/three/label3d.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +26 -0
- package/dist/three/plot-point3d.d.ts.map +1 -0
- package/dist/three/plot-point3d.js +60 -0
- package/dist/three/plot-point3d.js.map +1 -0
- package/dist/three/space.d.ts +28 -0
- package/dist/three/space.d.ts.map +1 -0
- package/dist/three/space.js +47 -0
- package/dist/three/space.js.map +1 -0
- package/dist/three/surface-plot3d.d.ts +80 -0
- package/dist/three/surface-plot3d.d.ts.map +1 -0
- package/dist/three/surface-plot3d.js +290 -0
- package/dist/three/surface-plot3d.js.map +1 -0
- package/dist/three/vector-arrow3d.d.ts +25 -0
- package/dist/three/vector-arrow3d.d.ts.map +1 -0
- package/dist/three/vector-arrow3d.js +72 -0
- package/dist/three/vector-arrow3d.js.map +1 -0
- package/package.json +79 -3
- package/registry.json +251 -0
- package/src/annotate/angle-mark.ts +147 -0
- package/src/annotate/curly-brace.ts +126 -0
- package/src/annotate/emphasis-mark.ts +89 -0
- package/src/engine.ts +72 -0
- package/src/index.ts +29 -0
- package/src/kit/brace.ts +37 -0
- package/src/kit/cache.ts +61 -0
- package/src/kit/contour.ts +94 -0
- package/src/kit/coords.ts +278 -0
- package/src/kit/curve.ts +29 -0
- package/src/kit/equation.ts +181 -0
- package/src/kit/equation3d.ts +137 -0
- package/src/kit/expression.ts +159 -0
- package/src/kit/field-mark.ts +155 -0
- package/src/kit/field.ts +50 -0
- package/src/kit/follow.ts +203 -0
- package/src/kit/furniture.ts +108 -0
- package/src/kit/geometry.ts +49 -0
- package/src/kit/mark.ts +131 -0
- package/src/kit/part-fills.ts +61 -0
- package/src/kit/place.ts +101 -0
- package/src/kit/placement.ts +8 -0
- package/src/kit/sampler.ts +281 -0
- package/src/kit/scale.ts +39 -0
- package/src/kit/source.ts +57 -0
- package/src/kit/system.ts +99 -0
- package/src/kit/ticks.ts +85 -0
- package/src/kit/withdrawn.ts +8 -0
- package/src/marks/curve-area.ts +89 -0
- package/src/marks/drop-lines.ts +63 -0
- package/src/marks/plot-point.ts +107 -0
- package/src/marks/riemann-sum.ts +98 -0
- package/src/marks/tangent-line.ts +103 -0
- package/src/marks/vector-arrow.ts +98 -0
- package/src/nodes.ts +63 -0
- package/src/plots/function-plot.ts +236 -0
- package/src/plots/points-plot.ts +107 -0
- package/src/plots/stream-lines.ts +151 -0
- package/src/plots/traced-path.ts +52 -0
- package/src/plots/vector-field.ts +88 -0
- package/src/structures/graph-layout.ts +145 -0
- package/src/structures/network-graph.ts +308 -0
- package/src/structures/sample-space.ts +209 -0
- package/src/systems/axes2d.ts +217 -0
- package/src/systems/number-line.ts +131 -0
- package/src/systems/number-plane.ts +203 -0
- package/src/systems/polar-plane.ts +176 -0
- package/src/tex/geometry.ts +703 -0
- package/src/tex/index.ts +14 -0
- package/src/tex/mathjax.ts +82 -0
- package/src/tex/matrix.ts +75 -0
- package/src/tex/node.ts +641 -0
- package/src/tex/tween.ts +308 -0
- package/src/three/axes3d.ts +240 -0
- package/src/three/curve-plot3d.ts +147 -0
- package/src/three/label3d.ts +50 -0
- package/src/three/plot-point3d.ts +66 -0
- package/src/three/space.ts +67 -0
- package/src/three/surface-plot3d.ts +323 -0
- package/src/three/vector-arrow3d.ts +77 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { command, Graphics3D, lerpVector3, Mesh3D, node, property, resolveVector3, } from "@motionscript/sdk";
|
|
8
|
+
import { stated } from "../kit/geometry.js";
|
|
9
|
+
import { aim, spaceOf } from "./space.js";
|
|
10
|
+
/** An arrow between two points of a 3D graph: a vector from the origin by default. */
|
|
11
|
+
let VectorArrow3d = class VectorArrow3d extends Mesh3D {
|
|
12
|
+
constructor(props) {
|
|
13
|
+
super(props ?? {});
|
|
14
|
+
}
|
|
15
|
+
/** Animate either end, or both. */
|
|
16
|
+
endpointsTo(args) {
|
|
17
|
+
return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
|
|
18
|
+
}
|
|
19
|
+
buildGraphics3D() {
|
|
20
|
+
const g3 = new Graphics3D();
|
|
21
|
+
const space = spaceOf(this);
|
|
22
|
+
const { tail, head, thickness } = this;
|
|
23
|
+
// Outside a graph an arrow is drawn in the scene's own units.
|
|
24
|
+
const from = space ? space.offset(tail.x, tail.y, tail.z) : tail;
|
|
25
|
+
const to = space ? space.offset(head.x, head.y, head.z) : head;
|
|
26
|
+
const along = { x: to.x - from.x, y: to.y - from.y, z: to.z - from.z };
|
|
27
|
+
const length = Math.hypot(along.x, along.y, along.z);
|
|
28
|
+
if (!(length > 0))
|
|
29
|
+
return g3;
|
|
30
|
+
const paint = this.materialShorthand();
|
|
31
|
+
const quaternion = aim(along);
|
|
32
|
+
const tipLength = this.tip ? Math.min(thickness * 8, length) : 0;
|
|
33
|
+
const shaft = length - tipLength;
|
|
34
|
+
const at = (distance) => ({
|
|
35
|
+
x: from.x + (along.x * distance) / length,
|
|
36
|
+
y: from.y + (along.y * distance) / length,
|
|
37
|
+
z: from.z + (along.z * distance) / length,
|
|
38
|
+
});
|
|
39
|
+
if (shaft > 0)
|
|
40
|
+
g3.cylinder({ ...paint, radius: thickness, height: shaft, segments: [12, 1], position: at(shaft / 2), quaternion });
|
|
41
|
+
if (tipLength > 0) {
|
|
42
|
+
g3.cone({ ...paint, radius: thickness * 2.8, height: tipLength, segments: [20, 1], position: at(shaft + tipLength / 2), quaternion });
|
|
43
|
+
}
|
|
44
|
+
return g3;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
__decorate([
|
|
48
|
+
property({ default: { x: 0, y: 0, z: 0 }, mapper: resolveVector3, tween: lerpVector3, kind: "vector3" })
|
|
49
|
+
], VectorArrow3d.prototype, "tail", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
property({ default: { x: 1, y: 1, z: 1 }, mapper: resolveVector3, tween: lerpVector3, kind: "vector3" })
|
|
52
|
+
], VectorArrow3d.prototype, "head", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
property({ default: 0.035, min: 0.001, step: 0.005 })
|
|
55
|
+
], VectorArrow3d.prototype, "thickness", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
property({ default: true, animatable: false })
|
|
58
|
+
], VectorArrow3d.prototype, "tip", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
command({ args: ["tail", "head"] })
|
|
61
|
+
], VectorArrow3d.prototype, "endpointsTo", null);
|
|
62
|
+
VectorArrow3d = __decorate([
|
|
63
|
+
node({
|
|
64
|
+
key: "vectorArrow3d",
|
|
65
|
+
within: ["axes3d"],
|
|
66
|
+
forkable: true,
|
|
67
|
+
layout: { acceptsChildren: false },
|
|
68
|
+
seed: { head: { x: 2, y: 1, z: 1.5 }, fill: "#f97316" },
|
|
69
|
+
})
|
|
70
|
+
], VectorArrow3d);
|
|
71
|
+
export { VectorArrow3d };
|
|
72
|
+
//# sourceMappingURL=vector-arrow3d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-arrow3d.js","sourceRoot":"","sources":["../../src/three/vector-arrow3d.ts"],"names":[],"mappings":"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","sourcesContent":["import {\r\n command,\r\n Graphics3D,\r\n lerpVector3,\r\n Mesh3D,\r\n node,\r\n property,\r\n resolveVector3,\r\n type Command,\r\n type CommandArgs,\r\n type Mesh3DProps,\r\n type NodeConfig,\r\n type Vector3,\r\n type Vector3Input,\r\n} from \"@motionscript/sdk\";\r\nimport { stated } from \"../kit/geometry\";\r\nimport { aim, spaceOf } from \"./space\";\r\n\r\nexport interface VectorArrow3dProps extends Mesh3DProps {\r\n tail?: Vector3Input;\r\n head?: Vector3Input;\r\n thickness?: number;\r\n tip?: boolean;\r\n}\r\n\r\n/** An arrow between two points of a 3D graph: a vector from the origin by default. */\r\n@node({\r\n key: \"vectorArrow3d\",\r\n within: [\"axes3d\"],\r\n forkable: true,\r\n layout: { acceptsChildren: false },\r\n seed: { head: { x: 2, y: 1, z: 1.5 }, fill: \"#f97316\" },\r\n})\r\nexport class VectorArrow3d extends Mesh3D<VectorArrow3dProps> {\r\n @property({ default: { x: 0, y: 0, z: 0 }, mapper: resolveVector3, tween: lerpVector3, kind: \"vector3\" }) declare tail: Vector3;\r\n @property({ default: { x: 1, y: 1, z: 1 }, mapper: resolveVector3, tween: lerpVector3, kind: \"vector3\" }) declare head: Vector3;\r\n /** The radius of the shaft, in scene units; the tip is sized from it. */\r\n @property({ default: 0.035, min: 0.001, step: 0.005 }) declare thickness: number;\r\n @property({ default: true, animatable: false }) declare tip: boolean;\r\n\r\n constructor(props?: NodeConfig<VectorArrow3d, VectorArrow3dProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n /** Animate either end, or both. */\r\n @command({ args: [\"tail\", \"head\"] })\r\n endpointsTo(args: CommandArgs<{ tail?: Vector3Input; head?: Vector3Input }> & { duration: number }): Command<VectorArrow3dProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n protected override buildGraphics3D(): Graphics3D {\r\n const g3 = new Graphics3D();\r\n const space = spaceOf(this);\r\n const { tail, head, thickness } = this;\r\n // Outside a graph an arrow is drawn in the scene's own units.\r\n const from = space ? space.offset(tail.x, tail.y, tail.z) : tail;\r\n const to = space ? space.offset(head.x, head.y, head.z) : head;\r\n const along: Vector3 = { x: to.x - from.x, y: to.y - from.y, z: to.z - from.z };\r\n const length = Math.hypot(along.x, along.y, along.z);\r\n if (!(length > 0)) return g3;\r\n\r\n const paint = this.materialShorthand();\r\n const quaternion = aim(along);\r\n const tipLength = this.tip ? Math.min(thickness * 8, length) : 0;\r\n const shaft = length - tipLength;\r\n const at = (distance: number): Vector3 => ({\r\n x: from.x + (along.x * distance) / length,\r\n y: from.y + (along.y * distance) / length,\r\n z: from.z + (along.z * distance) / length,\r\n });\r\n if (shaft > 0) g3.cylinder({ ...paint, radius: thickness, height: shaft, segments: [12, 1], position: at(shaft / 2), quaternion });\r\n if (tipLength > 0) {\r\n g3.cone({ ...paint, radius: thickness * 2.8, height: tipLength, segments: [20, 1], position: at(shaft + tipLength / 2), quaternion });\r\n }\r\n return g3;\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,82 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motionscript/math",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-alpha.5",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Math for Motion Script: coordinate systems, function and vector-field plots, 3D graphs and surfaces, network graphs, and LaTeX formulas typeset to glyph paths that morph token by token.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/motionscript-dev/motionscript.git",
|
|
9
|
+
"directory": "packages/components/math"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://motionscript.dev",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/motionscript-dev/motionscript/issues"
|
|
14
|
+
},
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"files": [
|
|
19
|
+
"NOTICE",
|
|
20
|
+
"dist",
|
|
21
|
+
"src",
|
|
22
|
+
"registry.json",
|
|
23
|
+
"CHANGELOG.md",
|
|
24
|
+
"!dist/**/*.tsbuildinfo",
|
|
25
|
+
"!src/**/tests/**",
|
|
26
|
+
"!src/**/*.test.ts",
|
|
27
|
+
"!src/**/*.test.tsx",
|
|
28
|
+
"!src/**/*.fixtures.ts"
|
|
29
|
+
],
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./kit": {
|
|
36
|
+
"types": "./dist/engine.d.ts",
|
|
37
|
+
"default": "./dist/engine.js"
|
|
38
|
+
},
|
|
39
|
+
"./tex": {
|
|
40
|
+
"types": "./dist/tex/index.d.ts",
|
|
41
|
+
"default": "./dist/tex/index.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"motion-script",
|
|
46
|
+
"motion script",
|
|
47
|
+
"math",
|
|
48
|
+
"latex",
|
|
49
|
+
"animation"
|
|
50
|
+
],
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"license": "Apache-2.0",
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@motionscript/sdk": "^0.1.0-alpha.5"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@mathjax/mathjax-newcm-font": "^4.1.1",
|
|
60
|
+
"@mathjax/src": "^4.1.1"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@types/node": "^25.6.2",
|
|
64
|
+
"eslint": "^9.39.4",
|
|
65
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
66
|
+
"eslint-plugin-import-x": "^4.16.1",
|
|
67
|
+
"tsc-alias": "^1.8.16",
|
|
68
|
+
"typescript": "^6.0.3",
|
|
69
|
+
"typescript-eslint": "^8.48.0",
|
|
70
|
+
"vitest": "^4.1.5",
|
|
71
|
+
"@motionscript/sdk": "0.1.0-alpha.5",
|
|
72
|
+
"@motionscript/core": "0.1.0-alpha.5"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json --resolve-full-paths && node ../../../scripts/build-browser.mjs",
|
|
76
|
+
"dev": "tsc -p tsconfig.build.json --watch & tsc-alias -p tsconfig.build.json --resolve-full-paths -w",
|
|
77
|
+
"clean": "rimraf --glob dist .turbo *.tsbuildinfo",
|
|
78
|
+
"test": "vitest",
|
|
79
|
+
"lint": "eslint .",
|
|
80
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
81
|
+
}
|
|
6
82
|
}
|
package/registry.json
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kit": {
|
|
3
|
+
"barrel": "src/engine.ts",
|
|
4
|
+
"specifier": "@motionscript/math"
|
|
5
|
+
},
|
|
6
|
+
"items": [
|
|
7
|
+
{
|
|
8
|
+
"name": "latex",
|
|
9
|
+
"description": "A LaTeX formula drawn as glyph paths, morphing token by token between formulas.",
|
|
10
|
+
"root": "src/tex",
|
|
11
|
+
"files": [
|
|
12
|
+
"node.ts"
|
|
13
|
+
],
|
|
14
|
+
"flatten": true
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "latex-matrix",
|
|
18
|
+
"description": "A matrix typeset from its entries, each one addressable as a part.",
|
|
19
|
+
"root": "src/tex",
|
|
20
|
+
"files": [
|
|
21
|
+
"matrix.ts"
|
|
22
|
+
],
|
|
23
|
+
"flatten": true
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "number-line",
|
|
27
|
+
"description": "One axis with ticks and numbers; children sit at a value along it.",
|
|
28
|
+
"root": "src/systems",
|
|
29
|
+
"files": [
|
|
30
|
+
"number-line.ts"
|
|
31
|
+
],
|
|
32
|
+
"flatten": true
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "axes2d",
|
|
36
|
+
"description": "An x and a y axis whose children sit in graph coordinates.",
|
|
37
|
+
"root": "src/systems",
|
|
38
|
+
"files": [
|
|
39
|
+
"axes2d.ts"
|
|
40
|
+
],
|
|
41
|
+
"flatten": true
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "number-plane",
|
|
45
|
+
"description": "Axes over a full grid with square units.",
|
|
46
|
+
"root": "src/systems",
|
|
47
|
+
"files": [
|
|
48
|
+
"number-plane.ts"
|
|
49
|
+
],
|
|
50
|
+
"flatten": true
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "function-plot",
|
|
54
|
+
"description": "The curve of an equation: a function, a polar or a parametric one.",
|
|
55
|
+
"root": "src/plots",
|
|
56
|
+
"files": [
|
|
57
|
+
"function-plot.ts"
|
|
58
|
+
],
|
|
59
|
+
"flatten": true
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "points-plot",
|
|
63
|
+
"description": "A line or closed shape through listed graph points.",
|
|
64
|
+
"root": "src/plots",
|
|
65
|
+
"files": [
|
|
66
|
+
"points-plot.ts"
|
|
67
|
+
],
|
|
68
|
+
"flatten": true
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": "plot-point",
|
|
72
|
+
"description": "A labelled dot at graph coordinates, or riding a plot.",
|
|
73
|
+
"root": "src/marks",
|
|
74
|
+
"files": [
|
|
75
|
+
"plot-point.ts"
|
|
76
|
+
],
|
|
77
|
+
"flatten": true
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"name": "vector-arrow",
|
|
81
|
+
"description": "An arrow between two graph points.",
|
|
82
|
+
"root": "src/marks",
|
|
83
|
+
"files": [
|
|
84
|
+
"vector-arrow.ts"
|
|
85
|
+
],
|
|
86
|
+
"flatten": true
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"name": "curve-area",
|
|
90
|
+
"description": "The region under a plot or between two.",
|
|
91
|
+
"root": "src/marks",
|
|
92
|
+
"files": [
|
|
93
|
+
"curve-area.ts"
|
|
94
|
+
],
|
|
95
|
+
"flatten": true
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"name": "riemann-sum",
|
|
99
|
+
"description": "Rectangles approximating the area under a plot.",
|
|
100
|
+
"root": "src/marks",
|
|
101
|
+
"files": [
|
|
102
|
+
"riemann-sum.ts"
|
|
103
|
+
],
|
|
104
|
+
"flatten": true
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "tangent-line",
|
|
108
|
+
"description": "The tangent or a secant to a plot.",
|
|
109
|
+
"root": "src/marks",
|
|
110
|
+
"files": [
|
|
111
|
+
"tangent-line.ts"
|
|
112
|
+
],
|
|
113
|
+
"flatten": true
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"name": "drop-lines",
|
|
117
|
+
"description": "Guide lines from a graph point to the axes.",
|
|
118
|
+
"root": "src/marks",
|
|
119
|
+
"files": [
|
|
120
|
+
"drop-lines.ts"
|
|
121
|
+
],
|
|
122
|
+
"flatten": true
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"name": "curly-brace",
|
|
126
|
+
"description": "A curly brace along a node, a part of a formula, or two points.",
|
|
127
|
+
"root": "src/annotate",
|
|
128
|
+
"files": [
|
|
129
|
+
"curly-brace.ts"
|
|
130
|
+
],
|
|
131
|
+
"flatten": true
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"name": "angle-mark",
|
|
135
|
+
"description": "The arc or square of an angle, with its label.",
|
|
136
|
+
"root": "src/annotate",
|
|
137
|
+
"files": [
|
|
138
|
+
"angle-mark.ts"
|
|
139
|
+
],
|
|
140
|
+
"flatten": true
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"name": "emphasis-mark",
|
|
144
|
+
"description": "A box, circle, underline or cross drawn on a node or a part of a formula.",
|
|
145
|
+
"root": "src/annotate",
|
|
146
|
+
"files": [
|
|
147
|
+
"emphasis-mark.ts"
|
|
148
|
+
],
|
|
149
|
+
"flatten": true
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"name": "axes3d",
|
|
153
|
+
"description": "A 3D graph with its own camera: three axes through a box of graph coordinates, z up, whose children sit in graph units.",
|
|
154
|
+
"root": "src/three",
|
|
155
|
+
"files": [
|
|
156
|
+
"axes3d.ts"
|
|
157
|
+
],
|
|
158
|
+
"flatten": true
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"name": "surface-plot3d",
|
|
162
|
+
"description": "A surface in a 3D graph: a height over x and y, or three parts in u and v.",
|
|
163
|
+
"root": "src/three",
|
|
164
|
+
"files": [
|
|
165
|
+
"surface-plot3d.ts"
|
|
166
|
+
],
|
|
167
|
+
"flatten": true
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"name": "curve-plot3d",
|
|
171
|
+
"description": "A curve through a 3D graph, three parts in t, drawn as a tube.",
|
|
172
|
+
"root": "src/three",
|
|
173
|
+
"files": [
|
|
174
|
+
"curve-plot3d.ts"
|
|
175
|
+
],
|
|
176
|
+
"flatten": true
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"name": "plot-point3d",
|
|
180
|
+
"description": "A labelled dot at 3D graph coordinates, riding a surface it is put inside.",
|
|
181
|
+
"root": "src/three",
|
|
182
|
+
"files": [
|
|
183
|
+
"plot-point3d.ts"
|
|
184
|
+
],
|
|
185
|
+
"flatten": true
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"name": "vector-arrow3d",
|
|
189
|
+
"description": "An arrow between two points of a 3D graph.",
|
|
190
|
+
"root": "src/three",
|
|
191
|
+
"files": [
|
|
192
|
+
"vector-arrow3d.ts"
|
|
193
|
+
],
|
|
194
|
+
"flatten": true
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"name": "polar-plane",
|
|
198
|
+
"description": "Rings and spokes about an origin, whose children sit in graph coordinates.",
|
|
199
|
+
"root": "src/systems",
|
|
200
|
+
"files": [
|
|
201
|
+
"polar-plane.ts"
|
|
202
|
+
],
|
|
203
|
+
"flatten": true
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"name": "vector-field",
|
|
207
|
+
"description": "A grid of arrows showing a vector field, coloured by its strength.",
|
|
208
|
+
"root": "src/plots",
|
|
209
|
+
"files": [
|
|
210
|
+
"vector-field.ts"
|
|
211
|
+
],
|
|
212
|
+
"flatten": true
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"name": "stream-lines",
|
|
216
|
+
"description": "The lines a vector field carries a point along, which can be sent flowing.",
|
|
217
|
+
"root": "src/plots",
|
|
218
|
+
"files": [
|
|
219
|
+
"stream-lines.ts"
|
|
220
|
+
],
|
|
221
|
+
"flatten": true
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"name": "traced-path",
|
|
225
|
+
"description": "The trail a point leaves as a value changes.",
|
|
226
|
+
"root": "src/plots",
|
|
227
|
+
"files": [
|
|
228
|
+
"traced-path.ts"
|
|
229
|
+
],
|
|
230
|
+
"flatten": true
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"name": "network-graph",
|
|
234
|
+
"description": "Vertices and edges arranged in a circle, by springs, as a tree or in a grid.",
|
|
235
|
+
"root": "src/structures",
|
|
236
|
+
"files": [
|
|
237
|
+
"network-graph.ts"
|
|
238
|
+
],
|
|
239
|
+
"flatten": true
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"name": "sample-space",
|
|
243
|
+
"description": "A probability's whole cut into parts whose areas are their probabilities.",
|
|
244
|
+
"root": "src/structures",
|
|
245
|
+
"files": [
|
|
246
|
+
"sample-space.ts"
|
|
247
|
+
],
|
|
248
|
+
"flatten": true
|
|
249
|
+
}
|
|
250
|
+
]
|
|
251
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
colorProperty,
|
|
3
|
+
command,
|
|
4
|
+
Graphics2D,
|
|
5
|
+
node,
|
|
6
|
+
PaintNode,
|
|
7
|
+
pathOps,
|
|
8
|
+
property,
|
|
9
|
+
strokeProperty,
|
|
10
|
+
withdraw,
|
|
11
|
+
type AssetScope,
|
|
12
|
+
type BoxBounds,
|
|
13
|
+
type Color,
|
|
14
|
+
type Command,
|
|
15
|
+
type CommandArgs,
|
|
16
|
+
type NodeConfig,
|
|
17
|
+
type NormalizedColor,
|
|
18
|
+
type PaintProps,
|
|
19
|
+
type PathCommand,
|
|
20
|
+
type RenderContext2D,
|
|
21
|
+
type Size2D,
|
|
22
|
+
type Stroke,
|
|
23
|
+
} from "@motionscript/sdk";
|
|
24
|
+
import { declareFormulas, drawLabels } from "../kit/furniture";
|
|
25
|
+
import { stated } from "../kit/geometry";
|
|
26
|
+
import { FILL_PAINT } from "../kit/withdrawn";
|
|
27
|
+
|
|
28
|
+
export interface AngleMarkProps extends PaintProps {
|
|
29
|
+
fromAngle?: number;
|
|
30
|
+
toAngle?: number;
|
|
31
|
+
radius?: number;
|
|
32
|
+
corner?: "arc" | "square" | "auto";
|
|
33
|
+
label?: string;
|
|
34
|
+
labelSize?: number;
|
|
35
|
+
labelColor?: Color;
|
|
36
|
+
fontFamily?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const OWN_FRAME: [number, number, number, number] = [-1, -1, 1, 1];
|
|
40
|
+
/** Degrees of arc per drawn segment. */
|
|
41
|
+
const ARC_STEP = 4;
|
|
42
|
+
/** How close to a right angle `auto` draws the square. */
|
|
43
|
+
const RIGHT_SLOP = 0.5;
|
|
44
|
+
|
|
45
|
+
const point = (radius: number, degrees: number) => {
|
|
46
|
+
const turn = (degrees * Math.PI) / 180;
|
|
47
|
+
return { x: radius * Math.cos(turn), y: radius * Math.sin(turn) };
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The mark of an angle at the node's own position: an arc from one direction
|
|
52
|
+
* to another, or the small square of a right angle, with an optional label.
|
|
53
|
+
* Directions are degrees counter-clockwise from the right, so binding one to a
|
|
54
|
+
* variable opens and closes the angle. A label of `°` shows the angle's size.
|
|
55
|
+
*/
|
|
56
|
+
@node({
|
|
57
|
+
key: "angleMark",
|
|
58
|
+
parentKey: "shape",
|
|
59
|
+
forkable: true,
|
|
60
|
+
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
|
|
61
|
+
})
|
|
62
|
+
@withdraw(...FILL_PAINT)
|
|
63
|
+
export class AngleMark extends PaintNode<AngleMarkProps> {
|
|
64
|
+
@property({ default: 0, unit: "°" }) declare fromAngle: number;
|
|
65
|
+
@property({ default: 60, unit: "°" }) declare toAngle: number;
|
|
66
|
+
@property({ default: 48, min: 0, unit: "px" }) declare radius: number;
|
|
67
|
+
/** `auto` draws the square where the angle is a right one. */
|
|
68
|
+
@property({ default: "auto", options: ["auto", "arc", "square"], animatable: false }) declare corner: "arc" | "square" | "auto";
|
|
69
|
+
|
|
70
|
+
/** Text, a formula between dollar signs, or `°` for the angle's own size. */
|
|
71
|
+
@property({ default: "", animatable: false }) declare label: string;
|
|
72
|
+
@property({ default: 24, min: 1, unit: "px" }) declare labelSize: number;
|
|
73
|
+
@colorProperty({ default: "#e5e7eb" }) declare labelColor: Color;
|
|
74
|
+
@property({ default: "", animatable: false }) declare fontFamily: string;
|
|
75
|
+
|
|
76
|
+
@strokeProperty({ default: { weight: 3, fill: "#e5e7eb", align: "center", cap: "round", join: "round" } })
|
|
77
|
+
declare stroke: Stroke;
|
|
78
|
+
|
|
79
|
+
constructor(props?: NodeConfig<AngleMark, AngleMarkProps>) {
|
|
80
|
+
super(props ?? {});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Grow or shrink the mark. */
|
|
84
|
+
@command({ args: ["radius"] })
|
|
85
|
+
radiusTo(args: CommandArgs<{ radius: number }> & { duration: number }): Command<AngleMarkProps> {
|
|
86
|
+
return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The angle marked, in degrees: positive counter-clockwise. */
|
|
90
|
+
get value(): number {
|
|
91
|
+
return this.toAngle - this.fromAngle;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
override declareAssets(assets: AssetScope): void {
|
|
95
|
+
super.declareAssets(assets);
|
|
96
|
+
if (this.label !== "" && this.fontFamily !== "") assets.font(this.fontFamily);
|
|
97
|
+
declareFormulas(assets, [this.label]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
override measure(): Partial<Size2D> {
|
|
101
|
+
return { width: 0, height: 0 };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
protected override shapeGraphics(): Graphics2D | null {
|
|
105
|
+
const data = this._outline();
|
|
106
|
+
return data.length === 0 ? null : new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: this.start, end: this.end });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
protected override renderSelf(ctx: RenderContext2D): void {
|
|
110
|
+
super.renderSelf(ctx);
|
|
111
|
+
if (this.label === "" || this.radius <= 0) return;
|
|
112
|
+
const text = this.label === "°" ? `${Math.round(Math.abs(this.value) * 10) / 10}°` : this.label;
|
|
113
|
+
const at = point(this.radius + this.labelSize * 0.9, (this.fromAngle + this.toAngle) / 2);
|
|
114
|
+
const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor };
|
|
115
|
+
for (const part of drawLabels([{ text, at, align: "center" }], style)) ctx.draw(part);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
override _localBounds(): BoxBounds {
|
|
119
|
+
const ink = pathOps.bounds(this._outline());
|
|
120
|
+
if (!ink) return { x: 0, y: 0, width: 0, height: 0 };
|
|
121
|
+
return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private _outline(): PathCommand[] {
|
|
125
|
+
const { fromAngle, toAngle, radius } = this;
|
|
126
|
+
const sweep = toAngle - fromAngle;
|
|
127
|
+
if (radius <= 0 || sweep === 0) return [];
|
|
128
|
+
const square = this.corner === "square" || (this.corner === "auto" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);
|
|
129
|
+
if (square) {
|
|
130
|
+
const side = radius * 0.6;
|
|
131
|
+
const a = point(side, fromAngle);
|
|
132
|
+
const b = point(side, toAngle);
|
|
133
|
+
return [
|
|
134
|
+
{ type: "M", x: a.x, y: a.y },
|
|
135
|
+
{ type: "L", x: a.x + b.x, y: a.y + b.y },
|
|
136
|
+
{ type: "L", x: b.x, y: b.y },
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));
|
|
140
|
+
const out: PathCommand[] = [];
|
|
141
|
+
for (let i = 0; i <= steps; i++) {
|
|
142
|
+
const p = point(radius, fromAngle + (sweep * i) / steps);
|
|
143
|
+
out.push({ type: i === 0 ? "M" : "L", x: p.x, y: p.y });
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
}
|