@motionscript/math 0.1.0-alpha.5 → 0.1.0-alpha.7
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 +28 -0
- package/README.md +39 -33
- package/dist/annotate/angle-mark.d.ts +77 -27
- package/dist/annotate/angle-mark.d.ts.map +1 -1
- package/dist/annotate/angle-mark.js +80 -115
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.d.ts +94 -25
- package/dist/annotate/curly-brace.d.ts.map +1 -1
- package/dist/annotate/curly-brace.js +85 -100
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.d.ts +69 -9
- package/dist/annotate/emphasis-mark.d.ts.map +1 -1
- package/dist/annotate/emphasis-mark.js +33 -34
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/chunk-ABYBW64J.js +2 -0
- package/dist/browser/chunks/chunk-ABYBW64J.js.map +7 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js +2 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/browser/tex.js +1 -1
- package/dist/browser/tex.js.map +2 -2
- package/dist/engine.d.ts +26 -19
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +17 -14
- package/dist/engine.js.map +1 -1
- package/dist/kit/component.d.ts +51 -0
- package/dist/kit/component.d.ts.map +1 -0
- package/dist/kit/component.js +30 -0
- package/dist/kit/component.js.map +1 -0
- package/dist/kit/curve.d.ts +22 -11
- package/dist/kit/curve.d.ts.map +1 -1
- package/dist/kit/curve.js +25 -18
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/field-mark.d.ts +56 -35
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js +100 -120
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/follow.d.ts +67 -29
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js +114 -110
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.d.ts +3 -1
- package/dist/kit/furniture.d.ts.map +1 -1
- package/dist/kit/furniture.js +5 -0
- package/dist/kit/furniture.js.map +1 -1
- package/dist/kit/graph.d.ts +46 -0
- package/dist/kit/graph.d.ts.map +1 -0
- package/dist/kit/graph.js +90 -0
- package/dist/kit/graph.js.map +1 -0
- package/dist/kit/mark.d.ts +64 -39
- package/dist/kit/mark.d.ts.map +1 -1
- package/dist/kit/mark.js +80 -96
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/place.d.ts +10 -8
- package/dist/kit/place.d.ts.map +1 -1
- package/dist/kit/place.js +28 -30
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/system.d.ts +27 -29
- package/dist/kit/system.d.ts.map +1 -1
- package/dist/kit/system.js +62 -58
- package/dist/kit/system.js.map +1 -1
- package/dist/kit/withdrawn.d.ts +3 -3
- package/dist/kit/withdrawn.js +3 -3
- package/dist/kit/withdrawn.js.map +1 -1
- package/dist/marks/curve-area.d.ts +37 -18
- package/dist/marks/curve-area.d.ts.map +1 -1
- package/dist/marks/curve-area.js +50 -73
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.d.ts +45 -10
- package/dist/marks/drop-lines.d.ts.map +1 -1
- package/dist/marks/drop-lines.js +37 -52
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.d.ts +56 -20
- package/dist/marks/plot-point.d.ts.map +1 -1
- package/dist/marks/plot-point.js +65 -91
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.d.ts +47 -26
- package/dist/marks/riemann-sum.d.ts.map +1 -1
- package/dist/marks/riemann-sum.js +57 -85
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.d.ts +58 -14
- package/dist/marks/tangent-line.d.ts.map +1 -1
- package/dist/marks/tangent-line.js +73 -87
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.d.ts +48 -20
- package/dist/marks/vector-arrow.d.ts.map +1 -1
- package/dist/marks/vector-arrow.js +58 -78
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.d.ts +13 -5
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +0 -6
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts +135 -43
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js +146 -177
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.d.ts +55 -19
- package/dist/plots/points-plot.d.ts.map +1 -1
- package/dist/plots/points-plot.js +31 -58
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.d.ts +60 -19
- package/dist/plots/stream-lines.d.ts.map +1 -1
- package/dist/plots/stream-lines.js +60 -79
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.d.ts +54 -15
- package/dist/plots/traced-path.d.ts.map +1 -1
- package/dist/plots/traced-path.js +33 -48
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.d.ts +48 -11
- package/dist/plots/vector-field.d.ts.map +1 -1
- package/dist/plots/vector-field.js +50 -64
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/network-graph.d.ts +140 -49
- package/dist/structures/network-graph.d.ts.map +1 -1
- package/dist/structures/network-graph.js +168 -217
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.d.ts +90 -38
- package/dist/structures/sample-space.d.ts.map +1 -1
- package/dist/structures/sample-space.js +132 -170
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts +159 -37
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js +147 -183
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.d.ts +80 -28
- package/dist/systems/number-line.d.ts.map +1 -1
- package/dist/systems/number-line.js +82 -118
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.d.ts +140 -31
- package/dist/systems/number-plane.d.ts.map +1 -1
- package/dist/systems/number-plane.js +142 -149
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.d.ts +76 -26
- package/dist/systems/polar-plane.d.ts.map +1 -1
- package/dist/systems/polar-plane.js +107 -133
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/index.d.ts.map +1 -1
- package/dist/tex/index.js +1 -0
- package/dist/tex/index.js.map +1 -1
- package/dist/tex/matrix.d.ts +88 -18
- package/dist/tex/matrix.d.ts.map +1 -1
- package/dist/tex/matrix.js +33 -50
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/node.d.ts +84 -201
- package/dist/tex/node.d.ts.map +1 -1
- package/dist/tex/node.js +23 -593
- package/dist/tex/node.js.map +1 -1
- package/dist/tex/typeset.d.ts +133 -0
- package/dist/tex/typeset.d.ts.map +1 -0
- package/dist/tex/typeset.js +403 -0
- package/dist/tex/typeset.js.map +1 -0
- package/dist/three/axes3d.d.ts +214 -54
- package/dist/three/axes3d.d.ts.map +1 -1
- package/dist/three/axes3d.js +163 -204
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +108 -42
- package/dist/three/curve-plot3d.d.ts.map +1 -1
- package/dist/three/curve-plot3d.js +97 -132
- package/dist/three/curve-plot3d.js.map +1 -1
- package/dist/three/entries.d.ts +17 -0
- package/dist/three/entries.d.ts.map +1 -0
- package/dist/three/entries.js +15 -0
- package/dist/three/entries.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +85 -12
- package/dist/three/plot-point3d.d.ts.map +1 -1
- package/dist/three/plot-point3d.js +27 -53
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.d.ts +17 -2
- package/dist/three/space.d.ts.map +1 -1
- package/dist/three/space.js +19 -8
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.d.ts +176 -49
- package/dist/three/surface-plot3d.d.ts.map +1 -1
- package/dist/three/surface-plot3d.js +227 -261
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.d.ts +87 -16
- package/dist/three/vector-arrow3d.d.ts.map +1 -1
- package/dist/three/vector-arrow3d.js +48 -67
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +4 -4
- package/src/annotate/angle-mark.ts +95 -105
- package/src/annotate/curly-brace.ts +107 -85
- package/src/annotate/emphasis-mark.ts +55 -26
- package/src/engine.ts +35 -21
- package/src/kit/component.ts +57 -0
- package/src/kit/curve.ts +38 -20
- package/src/kit/field-mark.ts +124 -108
- package/src/kit/follow.ts +146 -120
- package/src/kit/furniture.ts +6 -1
- package/src/kit/graph.ts +116 -0
- package/src/kit/mark.ts +135 -114
- package/src/kit/place.ts +32 -56
- package/src/kit/system.ts +77 -71
- package/src/kit/withdrawn.ts +3 -3
- package/src/marks/curve-area.ts +65 -65
- package/src/marks/drop-lines.ts +50 -42
- package/src/marks/plot-point.ts +77 -82
- package/src/marks/riemann-sum.ts +73 -72
- package/src/marks/tangent-line.ts +87 -71
- package/src/marks/vector-arrow.ts +73 -73
- package/src/nodes.ts +41 -5
- package/src/plots/function-plot.ts +155 -171
- package/src/plots/points-plot.ts +46 -50
- package/src/plots/stream-lines.ts +75 -66
- package/src/plots/traced-path.ts +51 -33
- package/src/plots/vector-field.ts +68 -49
- package/src/structures/network-graph.ts +168 -185
- package/src/structures/sample-space.ts +149 -148
- package/src/systems/axes2d.ts +165 -156
- package/src/systems/number-line.ts +91 -92
- package/src/systems/number-plane.ts +149 -120
- package/src/systems/polar-plane.ts +117 -116
- package/src/tex/index.ts +2 -1
- package/src/tex/matrix.ts +62 -40
- package/src/tex/node.ts +54 -621
- package/src/tex/typeset.ts +461 -0
- package/src/three/axes3d.ts +187 -160
- package/src/three/curve-plot3d.ts +107 -110
- package/src/three/entries.ts +42 -0
- package/src/three/plot-point3d.ts +42 -45
- package/src/three/space.ts +34 -9
- package/src/three/surface-plot3d.ts +312 -323
- package/src/three/vector-arrow3d.ts +65 -54
- package/dist/browser/chunks/chunk-3GJB6AVO.js +0 -2
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +0 -7
- package/dist/browser/chunks/chunk-D5WHCVBC.js +0 -2
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +0 -7
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +0 -2
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +0 -7
- package/src/kit/placement.ts +0 -8
|
@@ -1,56 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { component2d, Types, } from "@motionscript/sdk";
|
|
2
|
+
import { omit } from "../kit/component.js";
|
|
3
|
+
import { drawMark, inkSize, reading, traced } from "../kit/mark.js";
|
|
4
|
+
import { PLOT_COMMANDS, PLOT_STATE, PLOT_STROKE, tracePlot } from "./function-plot.js";
|
|
5
|
+
const state = {
|
|
6
|
+
// It reveals itself by its value, so it trims no outline of its own.
|
|
7
|
+
...omit(PLOT_STATE, "start", "end"),
|
|
8
|
+
/** The value the trail starts at. */
|
|
9
|
+
from: Types.number(0, { step: 0.1 }),
|
|
10
|
+
/** The value the point is at now: where the trail ends. */
|
|
11
|
+
value: Types.number(0, { step: 0.1 }),
|
|
12
|
+
/** How much of the trail is kept, in the value's own units; zero keeps all of it. */
|
|
13
|
+
tail: Types.number(0, { min: 0, step: 0.1 }),
|
|
6
14
|
};
|
|
7
|
-
import { command, node, property, withdraw } from "@motionscript/sdk";
|
|
8
|
-
import { stated } from "../kit/geometry.js";
|
|
9
|
-
import { SYSTEMS } from "../kit/placement.js";
|
|
10
|
-
import { FunctionPlot } from "./function-plot.js";
|
|
11
|
-
import { OUTLINE_TRIM } from "../kit/withdrawn.js";
|
|
12
15
|
/**
|
|
13
16
|
* The trail a point leaves as a value changes: the curve of its equation from
|
|
14
17
|
* where the value began to where it is now. Bind `value` to a variable
|
|
15
18
|
* (`"=[t]"`) and the trail grows as the variable is driven, or drive it with
|
|
16
19
|
* `traceTo`; a `tail` keeps only its most recent stretch.
|
|
17
20
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
__decorate([
|
|
39
|
-
property({ default: 0, min: 0, step: 0.1 })
|
|
40
|
-
], TracedPath.prototype, "tail", void 0);
|
|
41
|
-
__decorate([
|
|
42
|
-
command({ args: ["value"] })
|
|
43
|
-
], TracedPath.prototype, "traceTo", null);
|
|
44
|
-
TracedPath = __decorate([
|
|
45
|
-
node({
|
|
46
|
-
key: "tracedPath",
|
|
47
|
-
within: SYSTEMS,
|
|
48
|
-
parentKey: "functionPlot",
|
|
49
|
-
forkable: true,
|
|
50
|
-
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
|
|
51
|
-
seed: { expression: "(2cos(t), sin(2t))", value: 6.28 },
|
|
52
|
-
}),
|
|
53
|
-
withdraw(...OUTLINE_TRIM)
|
|
54
|
-
], TracedPath);
|
|
55
|
-
export { TracedPath };
|
|
21
|
+
export const TracedPath = traced(component2d({
|
|
22
|
+
key: "tracedPath",
|
|
23
|
+
state,
|
|
24
|
+
defaults: { stroke: PLOT_STROKE, width: "hug", height: "hug" },
|
|
25
|
+
commands: {
|
|
26
|
+
...omit(PLOT_COMMANDS, "progressTo", "flash"),
|
|
27
|
+
/** Carry the point on to another value, the trail following it. */
|
|
28
|
+
traceTo: { args: ["value"] },
|
|
29
|
+
},
|
|
30
|
+
measure: (_measurer, s) => inkSize(traceTrail(s, reading(s))),
|
|
31
|
+
render: (ctx, s) => drawMark(ctx, s, traceTrail(s, reading(s))),
|
|
32
|
+
}), traceTrail);
|
|
33
|
+
function traceTrail(s, read) {
|
|
34
|
+
return tracePlot(s, read, span(s));
|
|
35
|
+
}
|
|
36
|
+
/** The span of the free variable the trail covers: from where the value began, or its tail, to where it is. */
|
|
37
|
+
function span({ from, value, tail }) {
|
|
38
|
+
const kept = tail > 0 ? Math.min(Math.abs(value - from), tail) : Math.abs(value - from);
|
|
39
|
+
return value >= from ? [value - kept, value] : [value, value + kept];
|
|
40
|
+
}
|
|
56
41
|
//# sourceMappingURL=traced-path.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traced-path.js","sourceRoot":"","sources":["../../src/plots/traced-path.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"traced-path.js","sourceRoot":"","sources":["../../src/plots/traced-path.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,KAAK,GASR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAA2C,MAAM,iBAAiB,CAAC;AAQ7H,MAAM,KAAK,GAAG;IACV,qEAAqE;IACrE,GAAG,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC;IACnC,qCAAqC;IACrC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IACpC,2DAA2D;IAC3D,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IACrC,qFAAqF;IACrF,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,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,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import {\r\n component2d,\r\n Types,\r\n type NodeOf,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport { omit } from \"../kit/component\";\r\nimport type { Interval } from \"../kit/coords\";\r\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\r\nimport { PLOT_COMMANDS, PLOT_STATE, PLOT_STROKE, tracePlot, type FunctionPlotProps, type PlotValues } from \"./function-plot\";\r\n\r\nexport interface TracedPathProps extends FunctionPlotProps {\r\n from?: number;\r\n value?: number;\r\n tail?: number;\r\n}\r\n\r\nconst state = {\r\n // It reveals itself by its value, so it trims no outline of its own.\r\n ...omit(PLOT_STATE, \"start\", \"end\"),\r\n /** The value the trail starts at. */\r\n from: Types.number(0, { step: 0.1 }),\r\n /** The value the point is at now: where the trail ends. */\r\n value: Types.number(0, { step: 0.1 }),\r\n /** How much of the trail is kept, in the value's own units; zero keeps all of it. */\r\n tail: Types.number(0, { min: 0, step: 0.1 }),\r\n};\r\n\r\ninterface TrailValues extends PlotValues {\r\n readonly from: number;\r\n readonly value: number;\r\n readonly tail: number;\r\n}\r\n\r\n/**\r\n * The trail a point leaves as a value changes: the curve of its equation from\r\n * where the value began to where it is now. Bind `value` to a variable\r\n * (`\"=[t]\"`) and the trail grows as the variable is driven, or drive it with\r\n * `traceTo`; a `tail` keeps only its most recent stretch.\r\n */\r\nexport const TracedPath = traced(component2d({\r\n key: \"tracedPath\",\r\n state,\r\n defaults: { stroke: PLOT_STROKE, width: \"hug\", height: \"hug\" },\r\n commands: {\r\n ...omit(PLOT_COMMANDS, \"progressTo\", \"flash\"),\r\n /** Carry the point on to another value, the trail following it. */\r\n traceTo: { args: [\"value\"] },\r\n },\r\n measure: (_measurer, s) => inkSize(traceTrail(s, reading(s))),\r\n render: (ctx, s) => drawMark(ctx, s, traceTrail(s, reading(s))),\r\n}), traceTrail);\r\n\r\nexport type TracedPath = NodeOf<typeof TracedPath>;\r\n\r\nfunction traceTrail(s: TrailValues, read: MarkReading) {\r\n return tracePlot(s, read, span(s));\r\n}\r\n\r\n/** The span of the free variable the trail covers: from where the value began, or its tail, to where it is. */\r\nfunction span({ from, value, tail }: TrailValues): Interval {\r\n const kept = tail > 0 ? Math.min(Math.abs(value - from), tail) : Math.abs(value - from);\r\n return value >= from ? [value - kept, value] : [value, value + kept];\r\n}\r\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type
|
|
3
|
-
import { FieldMark, type FieldProps, type FieldSampler, type FieldStroke } from "../kit/field-mark.js";
|
|
1
|
+
import { type NodeOf, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
|
|
2
|
+
import { type FieldProps } from "../kit/field-mark.js";
|
|
4
3
|
export interface VectorFieldProps extends FieldProps {
|
|
5
4
|
spacing?: number;
|
|
6
5
|
arrowScale?: number;
|
|
@@ -10,14 +9,52 @@ export interface VectorFieldProps extends FieldProps {
|
|
|
10
9
|
* Each arrow is centred on its point and is as long as the field is strong
|
|
11
10
|
* there, up to the spacing.
|
|
12
11
|
*/
|
|
13
|
-
export declare
|
|
12
|
+
export declare const VectorField: import("@motionscript/sdk").Component<"vectorField", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
14
13
|
/** How far apart the arrows stand, in graph units. */
|
|
15
|
-
spacing: number
|
|
14
|
+
spacing: import("@motionscript/sdk").Type<number, number, false>;
|
|
16
15
|
/** How long an arrow is drawn for a vector of length one, in graph units. */
|
|
17
|
-
arrowScale: number
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
arrowScale: import("@motionscript/sdk").Type<number, number, false>;
|
|
17
|
+
expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
|
|
18
|
+
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
19
|
+
strengthFills: import("@motionscript/sdk").Type<_Fill[], _FillResolved[][], false>;
|
|
20
|
+
maxMagnitude: import("@motionscript/sdk").Type<number, number, false>;
|
|
21
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
22
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
23
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
24
|
+
}>, {
|
|
25
|
+
morphTo: readonly ["expression"];
|
|
26
|
+
paramsTo: readonly ["params"];
|
|
27
|
+
strokeTo: readonly ["stroke"];
|
|
28
|
+
shadowTo: readonly ["shadow"];
|
|
29
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
30
|
+
/** How far apart the arrows stand, in graph units. */
|
|
31
|
+
spacing: import("@motionscript/sdk").Type<number, number, false>;
|
|
32
|
+
/** How long an arrow is drawn for a vector of length one, in graph units. */
|
|
33
|
+
arrowScale: import("@motionscript/sdk").Type<number, number, false>;
|
|
34
|
+
expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
|
|
35
|
+
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
36
|
+
strengthFills: import("@motionscript/sdk").Type<_Fill[], _FillResolved[][], false>;
|
|
37
|
+
maxMagnitude: import("@motionscript/sdk").Type<number, number, false>;
|
|
38
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
39
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
40
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
41
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
42
|
+
/** How far apart the arrows stand, in graph units. */
|
|
43
|
+
spacing: import("@motionscript/sdk").Type<number, number, false>;
|
|
44
|
+
/** How long an arrow is drawn for a vector of length one, in graph units. */
|
|
45
|
+
arrowScale: import("@motionscript/sdk").Type<number, number, false>;
|
|
46
|
+
expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
|
|
47
|
+
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
48
|
+
strengthFills: import("@motionscript/sdk").Type<_Fill[], _FillResolved[][], false>;
|
|
49
|
+
maxMagnitude: import("@motionscript/sdk").Type<number, number, false>;
|
|
50
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
51
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
52
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
53
|
+
}>, {
|
|
54
|
+
morphTo: readonly ["expression"];
|
|
55
|
+
paramsTo: readonly ["params"];
|
|
56
|
+
strokeTo: readonly ["stroke"];
|
|
57
|
+
shadowTo: readonly ["shadow"];
|
|
58
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
59
|
+
export type VectorField = NodeOf<typeof VectorField>;
|
|
23
60
|
//# sourceMappingURL=vector-field.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-field.d.ts","sourceRoot":"","sources":["../../src/plots/vector-field.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"vector-field.d.ts","sourceRoot":"","sources":["../../src/plots/vector-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,MAAM,EAGX,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAyE,KAAK,UAAU,EAAyD,MAAM,mBAAmB,CAAC;AAIlL,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AA6BD;;;;GAIG;AACH,eAAO,MAAM,WAAW;IAvBpB,sDAAsD;;IAEtD,6EAA6E;;;;;;;;;;;;;;;IAF7E,sDAAsD;;IAEtD,6EAA6E;;;;;;;;;;IAF7E,sDAAsD;;IAEtD,6EAA6E;;;;;;;;;;;;;;2BA4BX,CAAC;AAEvE,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC"}
|
|
@@ -1,81 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { node, property, strokeProperty } from "@motionscript/sdk";
|
|
8
|
-
import { FieldMark } from "../kit/field-mark.js";
|
|
1
|
+
import { component2d, Types, } from "@motionscript/sdk";
|
|
2
|
+
import { drawField, FIELD_COMMANDS, FIELD_STATE, traceField } from "../kit/field-mark.js";
|
|
9
3
|
import { PLOT_COLOR } from "../kit/furniture.js";
|
|
10
|
-
import {
|
|
4
|
+
import { inkSize, reading, traced } from "../kit/mark.js";
|
|
11
5
|
/** Past this many arrows the spacing is widened, so a field over a huge range is still a field and not a wash. */
|
|
12
6
|
const MAX_ARROWS = 2400;
|
|
13
7
|
/** An arrow's head, as a share of its length and in pixels at most, and the half-angle it opens to. */
|
|
14
8
|
const HEAD_SHARE = 0.38;
|
|
15
9
|
const HEAD_MAX = 11;
|
|
16
10
|
const HEAD_ANGLE = (26 * Math.PI) / 180;
|
|
11
|
+
const state = {
|
|
12
|
+
...FIELD_STATE,
|
|
13
|
+
/** How far apart the arrows stand, in graph units. */
|
|
14
|
+
spacing: Types.number(1, { min: 0.01, step: 0.1 }),
|
|
15
|
+
/** How long an arrow is drawn for a vector of length one, in graph units. */
|
|
16
|
+
arrowScale: Types.number(0.4, { min: 0, step: 0.05 }),
|
|
17
|
+
};
|
|
18
|
+
const ARROWS = {
|
|
19
|
+
own: (s) => `${s.spacing}|${s.arrowScale}`,
|
|
20
|
+
strokes: (s, map, field) => arrows(s, map, field),
|
|
21
|
+
};
|
|
22
|
+
const traceArrows = (s, read) => traceField("vectorField", ARROWS, s, read);
|
|
17
23
|
/**
|
|
18
24
|
* A grid of arrows showing a vector field, two parts in x and y: `(-y, x)`.
|
|
19
25
|
* Each arrow is centred on its point and is as long as the field is strong
|
|
20
26
|
* there, up to the spacing.
|
|
21
27
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
28
|
+
export const VectorField = traced(component2d({
|
|
29
|
+
key: "vectorField",
|
|
30
|
+
state,
|
|
31
|
+
defaults: { stroke: { weight: 2.5, fill: PLOT_COLOR, align: "center", cap: "round", join: "round" }, width: "hug", height: "hug" },
|
|
32
|
+
commands: FIELD_COMMANDS,
|
|
33
|
+
measure: (_measurer, s) => inkSize(traceArrows(s, reading(s)).runs),
|
|
34
|
+
render: (ctx, s) => drawField(ctx, s, traceArrows(s, reading(s))),
|
|
35
|
+
}), (s, read) => traceArrows(s, read).runs);
|
|
36
|
+
function arrows(s, map, field) {
|
|
37
|
+
const [x0, x1] = map.xRange;
|
|
38
|
+
const [y0, y1] = map.yRange;
|
|
39
|
+
let spacing = Math.max(s.spacing, 1e-6);
|
|
40
|
+
const count = () => (Math.floor((x1 - x0) / spacing) + 1) * (Math.floor((y1 - y0) / spacing) + 1);
|
|
41
|
+
while (count() > MAX_ARROWS)
|
|
42
|
+
spacing *= 2;
|
|
43
|
+
const drawn = [];
|
|
44
|
+
const v = { x: 0, y: 0 };
|
|
45
|
+
const longest = spacing * 0.9;
|
|
46
|
+
for (let i = Math.ceil(x0 / spacing - 1e-9); i * spacing <= x1 + 1e-9; i++) {
|
|
47
|
+
for (let j = Math.ceil(y0 / spacing - 1e-9); j * spacing <= y1 + 1e-9; j++) {
|
|
48
|
+
const gx = i * spacing;
|
|
49
|
+
const gy = j * spacing;
|
|
50
|
+
if (!field(gx, gy, v))
|
|
51
|
+
continue;
|
|
52
|
+
const magnitude = Math.hypot(v.x, v.y);
|
|
53
|
+
const length = Math.min(magnitude * s.arrowScale, longest);
|
|
54
|
+
if (!(length > 0))
|
|
55
|
+
continue;
|
|
56
|
+
const hx = ((v.x / magnitude) * length) / 2;
|
|
57
|
+
const hy = ((v.y / magnitude) * length) / 2;
|
|
58
|
+
const tail = map.toPoint(gx - hx, gy - hy);
|
|
59
|
+
const head = map.toPoint(gx + hx, gy + hy);
|
|
60
|
+
drawn.push({ runs: arrow(tail, head), magnitude });
|
|
55
61
|
}
|
|
56
|
-
return drawn;
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
property({ default: 1, min: 0.01, step: 0.1 })
|
|
61
|
-
], VectorField.prototype, "spacing", void 0);
|
|
62
|
-
__decorate([
|
|
63
|
-
property({ default: 0.4, min: 0, step: 0.05 })
|
|
64
|
-
], VectorField.prototype, "arrowScale", void 0);
|
|
65
|
-
__decorate([
|
|
66
|
-
strokeProperty({ default: { weight: 2.5, fill: PLOT_COLOR, align: "center", cap: "round", join: "round" } })
|
|
67
|
-
], VectorField.prototype, "stroke", void 0);
|
|
68
|
-
VectorField = __decorate([
|
|
69
|
-
node({
|
|
70
|
-
key: "vectorField",
|
|
71
|
-
within: SYSTEMS,
|
|
72
|
-
parentKey: "shape",
|
|
73
|
-
forkable: true,
|
|
74
|
-
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
|
|
75
|
-
seed: { expression: "(-y, x)" },
|
|
76
|
-
})
|
|
77
|
-
], VectorField);
|
|
78
|
-
export { VectorField };
|
|
63
|
+
return drawn;
|
|
64
|
+
}
|
|
79
65
|
/** A shaft and the two barbs of its head, in pixels. */
|
|
80
66
|
function arrow(tail, head) {
|
|
81
67
|
const dx = head.x - tail.x;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-field.js","sourceRoot":"","sources":["../../src/plots/vector-field.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":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AAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;IACpH,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,GAAG,UAAU,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AAChF,CAAC","sourcesContent":["import {\r\n component2d,\r\n Types,\r\n type NodeOf,\r\n type Vector2,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Fill as _Fill,\r\n type FillResolved as _FillResolved,\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport type { CoordinateMap } from \"../kit/coords\";\r\nimport { drawField, FIELD_COMMANDS, FIELD_STATE, traceField, type FieldDrawing, type FieldProps, type FieldValues, type FieldSampler, type FieldStroke } from \"../kit/field-mark\";\r\nimport { PLOT_COLOR } from \"../kit/furniture\";\r\nimport { inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\r\n\r\nexport interface VectorFieldProps extends FieldProps {\r\n spacing?: number;\r\n arrowScale?: number;\r\n}\r\n\r\n/** Past this many arrows the spacing is widened, so a field over a huge range is still a field and not a wash. */\r\nconst MAX_ARROWS = 2400;\r\n/** An arrow's head, as a share of its length and in pixels at most, and the half-angle it opens to. */\r\nconst HEAD_SHARE = 0.38;\r\nconst HEAD_MAX = 11;\r\nconst HEAD_ANGLE = (26 * Math.PI) / 180;\r\n\r\nconst state = {\r\n ...FIELD_STATE,\r\n /** How far apart the arrows stand, in graph units. */\r\n spacing: Types.number(1, { min: 0.01, step: 0.1 }),\r\n /** How long an arrow is drawn for a vector of length one, in graph units. */\r\n arrowScale: Types.number(0.4, { min: 0, step: 0.05 }),\r\n};\r\n\r\ninterface ArrowsValues extends FieldValues {\r\n readonly spacing: number;\r\n readonly arrowScale: number;\r\n}\r\n\r\nconst ARROWS: FieldDrawing<ArrowsValues> = {\r\n own: (s) => `${s.spacing}|${s.arrowScale}`,\r\n strokes: (s, map, field) => arrows(s, map, field),\r\n};\r\n\r\nconst traceArrows = (s: ArrowsValues, read: MarkReading) => traceField(\"vectorField\", ARROWS, s, read);\r\n\r\n/**\r\n * A grid of arrows showing a vector field, two parts in x and y: `(-y, x)`.\r\n * Each arrow is centred on its point and is as long as the field is strong\r\n * there, up to the spacing.\r\n */\r\nexport const VectorField = traced(component2d({\r\n key: \"vectorField\",\r\n state,\r\n defaults: { stroke: { weight: 2.5, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\r\n commands: FIELD_COMMANDS,\r\n measure: (_measurer, s) => inkSize(traceArrows(s, reading(s)).runs),\r\n render: (ctx, s) => drawField(ctx, s, traceArrows(s, reading(s))),\r\n}), (s: ArrowsValues, read: MarkReading) => traceArrows(s, read).runs);\r\n\r\nexport type VectorField = NodeOf<typeof VectorField>;\r\n\r\nfunction arrows(s: ArrowsValues, map: CoordinateMap, field: FieldSampler): FieldStroke[] {\r\n const [x0, x1] = map.xRange;\r\n const [y0, y1] = map.yRange;\r\n let spacing = Math.max(s.spacing, 1e-6);\r\n const count = () => (Math.floor((x1 - x0) / spacing) + 1) * (Math.floor((y1 - y0) / spacing) + 1);\r\n while (count() > MAX_ARROWS) spacing *= 2;\r\n\r\n const drawn: FieldStroke[] = [];\r\n const v: Vector2 = { x: 0, y: 0 };\r\n const longest = spacing * 0.9;\r\n for (let i = Math.ceil(x0 / spacing - 1e-9); i * spacing <= x1 + 1e-9; i++) {\r\n for (let j = Math.ceil(y0 / spacing - 1e-9); j * spacing <= y1 + 1e-9; j++) {\r\n const gx = i * spacing;\r\n const gy = j * spacing;\r\n if (!field(gx, gy, v)) continue;\r\n const magnitude = Math.hypot(v.x, v.y);\r\n const length = Math.min(magnitude * s.arrowScale, longest);\r\n if (!(length > 0)) continue;\r\n const hx = ((v.x / magnitude) * length) / 2;\r\n const hy = ((v.y / magnitude) * length) / 2;\r\n const tail = map.toPoint(gx - hx, gy - hy);\r\n const head = map.toPoint(gx + hx, gy + hy);\r\n drawn.push({ runs: arrow(tail, head), magnitude });\r\n }\r\n }\r\n return drawn;\r\n}\r\n\r\n/** A shaft and the two barbs of its head, in pixels. */\r\nfunction arrow(tail: Vector2, head: Vector2): Vector2[][] {\r\n const dx = head.x - tail.x;\r\n const dy = head.y - tail.y;\r\n const length = Math.hypot(dx, dy);\r\n if (!(length > 0)) return [];\r\n const barb = Math.min(length * HEAD_SHARE, HEAD_MAX);\r\n const back = Math.atan2(dy, dx) + Math.PI;\r\n const at = (angle: number): Vector2 => ({ x: head.x + Math.cos(angle) * barb, y: head.y + Math.sin(angle) * barb });\r\n return [[tail, head], [at(back - HEAD_ANGLE), head, at(back + HEAD_ANGLE)]];\r\n}\r\n"]}
|