@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,202 +1,171 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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, node, property, strokeProperty, withdraw, } from "@motionscript/sdk";
|
|
1
|
+
import { component2d, provides, Types, } from "@motionscript/sdk";
|
|
2
|
+
import { createBoundedCache } from "../kit/cache.js";
|
|
3
|
+
import { omit, PAINT, PAINT_COMMANDS } from "../kit/component.js";
|
|
8
4
|
import { traceContour } from "../kit/contour.js";
|
|
9
5
|
import { equationParams, parseEquation } from "../kit/equation.js";
|
|
10
6
|
import { PLOT_COLOR } from "../kit/furniture.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
7
|
+
import { PLOT, plotPlane, SYSTEM, SYSTEM_ENTRY } from "../kit/graph.js";
|
|
8
|
+
import { drawMark, inkCentre, inkSize, reading, traced } from "../kit/mark.js";
|
|
9
|
+
import { openPlane, placeOnMap } from "../kit/place.js";
|
|
13
10
|
import { sampleCurve } from "../kit/sampler.js";
|
|
14
11
|
import { lerpDomain, lerpParams, lerpSource, readSource, scopeFor } from "../kit/source.js";
|
|
15
|
-
import { SYSTEMS } from "../kit/placement.js";
|
|
16
|
-
import { FILL_PAINT } from "../kit/withdrawn.js";
|
|
17
12
|
const TAU = Math.PI * 2;
|
|
13
|
+
/** A plot's entries: what a traced path is built on too. It is only a line, so it has no fill. */
|
|
14
|
+
export const PLOT_STATE = {
|
|
15
|
+
...omit(PAINT, "fill"),
|
|
16
|
+
expression: Types.custom("", { resolve: readSource, lerp: lerpSource, kind: "equation" }),
|
|
17
|
+
/**
|
|
18
|
+
* The span of the free variable that is drawn. Left out, a function runs the
|
|
19
|
+
* width of its system, a polar curve one turn and a parametric one from 0 to 1.
|
|
20
|
+
*/
|
|
21
|
+
domain: Types.custom(null, { lerp: lerpDomain, kind: "range", defaultMin: -5, defaultMax: 5 }),
|
|
22
|
+
/**
|
|
23
|
+
* The equation's named values: any name in it that is not a variable, a
|
|
24
|
+
* function or a constant. One left unset is 1, and a formula can bind each
|
|
25
|
+
* to a variable.
|
|
26
|
+
*/
|
|
27
|
+
params: Types.custom({}, { lerp: lerpParams }),
|
|
28
|
+
graph: SYSTEM_ENTRY,
|
|
29
|
+
};
|
|
30
|
+
/** A plot's own commands, beside a line's paints. */
|
|
31
|
+
export const PLOT_COMMANDS = {
|
|
32
|
+
...omit(PAINT_COMMANDS, "fillTo"),
|
|
33
|
+
/** Change the equation, the curve bending from the one into the other. */
|
|
34
|
+
morphTo: { args: ["expression"] },
|
|
35
|
+
/** Animate the equation's named values. */
|
|
36
|
+
paramsTo: { args: ["params"] },
|
|
37
|
+
/** Animate the span that is drawn. */
|
|
38
|
+
domainTo: { args: ["domain"] },
|
|
39
|
+
};
|
|
40
|
+
export const PLOT_STROKE = { weight: 3, fill: PLOT_COLOR, align: "center", cap: "round", join: "round" };
|
|
18
41
|
/**
|
|
19
42
|
* The curve of an equation, drawn in the coordinate system it is a child of.
|
|
20
43
|
* How the equation is written says what it is: see `Equation`. A mark put
|
|
21
44
|
* inside it reads it: the area under it, a tangent, a point that rides it.
|
|
22
45
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return
|
|
46
|
+
export const FunctionPlot = traced(component2d({
|
|
47
|
+
key: "functionPlot",
|
|
48
|
+
state: PLOT_STATE,
|
|
49
|
+
defaults: { stroke: PLOT_STROKE, width: "hug", height: "hug" },
|
|
50
|
+
commands: PLOT_COMMANDS,
|
|
51
|
+
// The marks inside it ride it, on its system's map.
|
|
52
|
+
provide: (s, inherited) => [provides(PLOT, plotPlane(s, inherited(SYSTEM)))],
|
|
53
|
+
measure: (_measurer, s) => inkSize(tracePlot(s, reading(s), s.domain)),
|
|
54
|
+
layout: (box, s, children) => {
|
|
55
|
+
const read = reading(s);
|
|
56
|
+
return placeOnMap(children, read.map, inkCentre(tracePlot(s, read, s.domain)), box, plotPlane(s, s.graph));
|
|
57
|
+
},
|
|
58
|
+
plane: (_box, s) => {
|
|
59
|
+
const read = reading(s);
|
|
60
|
+
return openPlane(read.map, inkCentre(tracePlot(s, read, s.domain)));
|
|
61
|
+
},
|
|
62
|
+
render: (ctx, s) => drawMark(ctx, s, tracePlot(s, reading(s), s.domain)),
|
|
63
|
+
}), (s, read) => tracePlot(s, read, s.domain));
|
|
64
|
+
const traces = createBoundedCache(256);
|
|
65
|
+
/** The runs a plot of `s` draws through `read`, over `span` of its free variable (all of it for `null`). */
|
|
66
|
+
export function tracePlot(s, read, span) {
|
|
67
|
+
const { map, shift } = read;
|
|
68
|
+
const { area } = map;
|
|
69
|
+
if (!Number.isFinite(area.maxX - area.minX))
|
|
70
|
+
return [];
|
|
71
|
+
const { source, blend } = s.expression;
|
|
72
|
+
const key = [source, blend?.from, blend?.t, map.revision, span, JSON.stringify(s.params), shift.x, shift.y].join("|");
|
|
73
|
+
const known = traces.get(key);
|
|
74
|
+
if (known)
|
|
75
|
+
return known;
|
|
76
|
+
let runs;
|
|
77
|
+
// A curve with no parameter to walk cannot bend into another: it changes over half way.
|
|
78
|
+
const shown = blend && blend.t < 0.5 ? blend.from : source;
|
|
79
|
+
if (equationOf(source)?.kind === "implicit" || (blend && equationOf(blend.from)?.kind === "implicit")) {
|
|
80
|
+
runs = contour(shown, s.params, map, shift);
|
|
38
81
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* function of `x`. What a point, a tangent or an area riding this plot reads.
|
|
42
|
-
*/
|
|
43
|
-
valueAt(x) {
|
|
44
|
-
const { source, blend } = this.expression;
|
|
45
|
-
const shift = this.shift();
|
|
46
|
-
const value = this._heightOf(source, x - shift.x) + shift.y;
|
|
47
|
-
if (!blend)
|
|
48
|
-
return value;
|
|
49
|
-
const from = this._heightOf(blend.from, x - shift.x) + shift.y;
|
|
50
|
-
return from + (value - from) * blend.t;
|
|
51
|
-
}
|
|
52
|
-
/** The span of the free variable that is drawn: `domain`, unless a node built on this one says otherwise. */
|
|
53
|
-
span() {
|
|
54
|
-
return this.domain;
|
|
55
|
-
}
|
|
56
|
-
trace(map) {
|
|
57
|
-
const { area } = map;
|
|
58
|
-
if (!Number.isFinite(area.maxX - area.minX))
|
|
59
|
-
return [];
|
|
60
|
-
const { source, blend } = this.expression;
|
|
61
|
-
const shift = this.shift();
|
|
62
|
-
const key = [source, blend?.from, blend?.t, map.revision, this.span(), JSON.stringify(this.params), shift.x, shift.y].join("|");
|
|
63
|
-
if (key === this._key)
|
|
64
|
-
return this._runs;
|
|
65
|
-
this._key = key;
|
|
66
|
-
// A curve with no parameter to walk cannot bend into another: it changes over half way.
|
|
67
|
-
const shown = blend && blend.t < 0.5 ? blend.from : source;
|
|
68
|
-
if (this._equation(source)?.kind === "implicit" || (blend && this._equation(blend.from)?.kind === "implicit")) {
|
|
69
|
-
this._runs = this._contour(shown, map, shift);
|
|
70
|
-
return this._runs;
|
|
71
|
-
}
|
|
72
|
-
let curve = this._curve(source, map, shift);
|
|
82
|
+
else {
|
|
83
|
+
let curve = projectionOf(source, s.params, span, map, shift);
|
|
73
84
|
if (curve && blend) {
|
|
74
|
-
const from =
|
|
85
|
+
const from = projectionOf(blend.from, s.params, span, map, shift);
|
|
75
86
|
if (from)
|
|
76
87
|
curve = between(from, curve, blend.t);
|
|
77
88
|
}
|
|
78
89
|
const width = area.maxX - area.minX;
|
|
79
|
-
|
|
90
|
+
runs = curve
|
|
80
91
|
? sampleCurve(curve, 0, 1, area, { seeds: Math.min(512, Math.max(64, Math.round(width / 8))), minStep: 0.5 / Math.max(1, width) })
|
|
81
92
|
: [];
|
|
82
|
-
return this._runs;
|
|
83
|
-
}
|
|
84
|
-
_key = "";
|
|
85
|
-
_runs = [];
|
|
86
|
-
_equation(source) {
|
|
87
|
-
const equation = parseEquation(source, equationParams(source));
|
|
88
|
-
return equation instanceof Error ? null : equation;
|
|
89
|
-
}
|
|
90
|
-
_heightOf(source, x) {
|
|
91
|
-
const equation = this._equation(source);
|
|
92
|
-
if (equation?.kind !== "function" || equation.of !== "x")
|
|
93
|
-
return NaN;
|
|
94
|
-
return equation.f(x, 0, scopeFor(equationParams(source), this.params));
|
|
95
|
-
}
|
|
96
|
-
/** Where an implicit `source` holds, over what the system shows, as pixel runs. */
|
|
97
|
-
_contour(source, map, shift) {
|
|
98
|
-
const equation = this._equation(source);
|
|
99
|
-
if (equation?.kind !== "implicit")
|
|
100
|
-
return [];
|
|
101
|
-
const params = scopeFor(equationParams(source), this.params);
|
|
102
|
-
const { area } = map;
|
|
103
|
-
const cells = (pixels) => Math.min(CONTOUR_MAX, Math.max(8, Math.round(pixels / CONTOUR_CELL)));
|
|
104
|
-
const { f } = equation;
|
|
105
|
-
const runs = traceContour((x, y) => f(x - shift.x, y - shift.y, params), map.xRange, map.yRange, cells(area.maxX - area.minX), cells(area.maxY - area.minY));
|
|
106
|
-
return runs.map((run) => run.map((point) => map.toPoint(point.x, point.y)));
|
|
107
93
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
94
|
+
traces.set(key, runs);
|
|
95
|
+
return runs;
|
|
96
|
+
}
|
|
97
|
+
function equationOf(source) {
|
|
98
|
+
const equation = parseEquation(source, equationParams(source));
|
|
99
|
+
return equation instanceof Error ? null : equation;
|
|
100
|
+
}
|
|
101
|
+
/** Where an implicit `source` holds, over what the system shows, as pixel runs. */
|
|
102
|
+
function contour(source, params, map, shift) {
|
|
103
|
+
const equation = equationOf(source);
|
|
104
|
+
if (equation?.kind !== "implicit")
|
|
105
|
+
return [];
|
|
106
|
+
const scope = scopeFor(equationParams(source), params);
|
|
107
|
+
const { area } = map;
|
|
108
|
+
const cells = (pixels) => Math.min(CONTOUR_MAX, Math.max(8, Math.round(pixels / CONTOUR_CELL)));
|
|
109
|
+
const { f } = equation;
|
|
110
|
+
const runs = traceContour((x, y) => f(x - shift.x, y - shift.y, scope), map.xRange, map.yRange, cells(area.maxX - area.minX), cells(area.maxY - area.minY));
|
|
111
|
+
return runs.map((run) => run.map((point) => map.toPoint(point.x, point.y)));
|
|
112
|
+
}
|
|
113
|
+
/** `source` as a pixel curve over a parameter running 0 to 1. */
|
|
114
|
+
function projectionOf(source, params, domain, map, shift) {
|
|
115
|
+
const equation = equationOf(source);
|
|
116
|
+
if (!equation || equation.kind === "implicit")
|
|
117
|
+
return null;
|
|
118
|
+
const scope = scopeFor(equationParams(source), params);
|
|
119
|
+
switch (equation.kind) {
|
|
120
|
+
case "function": {
|
|
121
|
+
const horizontal = equation.of === "x";
|
|
122
|
+
const [lo, hi] = horizontal ? map.xRange : map.yRange;
|
|
123
|
+
const offset = horizontal ? shift.x : shift.y;
|
|
124
|
+
// Only what the system shows is sampled, however wide the domain.
|
|
125
|
+
const a = Math.max(lo - offset, domain?.[0] ?? -Infinity);
|
|
126
|
+
const b = Math.min(hi - offset, domain?.[1] ?? Infinity);
|
|
127
|
+
if (!(b > a))
|
|
128
|
+
return null;
|
|
129
|
+
const { f } = equation;
|
|
130
|
+
return (u, out) => {
|
|
131
|
+
const v = a + (b - a) * u;
|
|
132
|
+
const w = f(v, 0, scope);
|
|
133
|
+
if (!Number.isFinite(w))
|
|
134
|
+
return false;
|
|
135
|
+
if (horizontal)
|
|
136
|
+
map.toPoint(v + shift.x, w + shift.y, out);
|
|
137
|
+
else
|
|
138
|
+
map.toPoint(w + shift.x, v + shift.y, out);
|
|
139
|
+
return true;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
case "polar": {
|
|
143
|
+
const [a, b] = domain ?? [0, TAU];
|
|
144
|
+
const { f } = equation;
|
|
145
|
+
return (u, out) => {
|
|
146
|
+
const theta = a + (b - a) * u;
|
|
147
|
+
const r = f(theta, 0, scope);
|
|
148
|
+
if (!Number.isFinite(r))
|
|
149
|
+
return false;
|
|
150
|
+
map.toPoint(r * Math.cos(theta) + shift.x, r * Math.sin(theta) + shift.y, out);
|
|
151
|
+
return true;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
case "parametric": {
|
|
155
|
+
const [a, b] = domain ?? [0, 1];
|
|
156
|
+
const { x, y } = equation;
|
|
157
|
+
return (u, out) => {
|
|
158
|
+
const t = a + (b - a) * u;
|
|
159
|
+
const gx = x(t, 0, scope);
|
|
160
|
+
const gy = y(t, 0, scope);
|
|
161
|
+
if (!Number.isFinite(gx) || !Number.isFinite(gy))
|
|
162
|
+
return false;
|
|
163
|
+
map.toPoint(gx + shift.x, gy + shift.y, out);
|
|
164
|
+
return true;
|
|
165
|
+
};
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
|
-
}
|
|
166
|
-
__decorate([
|
|
167
|
-
property({ default: "", mapper: readSource, tween: lerpSource, kind: "equation" })
|
|
168
|
-
], FunctionPlot.prototype, "expression", void 0);
|
|
169
|
-
__decorate([
|
|
170
|
-
property({ default: null, tween: lerpDomain, kind: "range", defaultMin: -5, defaultMax: 5 })
|
|
171
|
-
], FunctionPlot.prototype, "domain", void 0);
|
|
172
|
-
__decorate([
|
|
173
|
-
property({ default: {}, tween: lerpParams })
|
|
174
|
-
], FunctionPlot.prototype, "params", void 0);
|
|
175
|
-
__decorate([
|
|
176
|
-
strokeProperty({ default: { weight: 3, fill: PLOT_COLOR, align: "center", cap: "round", join: "round" } })
|
|
177
|
-
], FunctionPlot.prototype, "stroke", void 0);
|
|
178
|
-
__decorate([
|
|
179
|
-
command({ args: ["expression"] })
|
|
180
|
-
], FunctionPlot.prototype, "morphTo", null);
|
|
181
|
-
__decorate([
|
|
182
|
-
command({ args: ["params"] })
|
|
183
|
-
], FunctionPlot.prototype, "paramsTo", null);
|
|
184
|
-
__decorate([
|
|
185
|
-
command({ args: ["domain"] })
|
|
186
|
-
], FunctionPlot.prototype, "domainTo", null);
|
|
187
|
-
FunctionPlot = __decorate([
|
|
188
|
-
node({
|
|
189
|
-
key: "functionPlot",
|
|
190
|
-
within: SYSTEMS,
|
|
191
|
-
closed: true,
|
|
192
|
-
parentKey: "shape",
|
|
193
|
-
forkable: true,
|
|
194
|
-
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: true },
|
|
195
|
-
seed: { expression: "sin(x)" },
|
|
196
|
-
}),
|
|
197
|
-
withdraw(...FILL_PAINT)
|
|
198
|
-
], FunctionPlot);
|
|
199
|
-
export { FunctionPlot };
|
|
168
|
+
}
|
|
200
169
|
// Roughly one cell of the contour's grid to this many pixels, each way.
|
|
201
170
|
const CONTOUR_CELL = 5;
|
|
202
171
|
const CONTOUR_MAX = 220;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-plot.js","sourceRoot":"","sources":["../../src/plots/function-plot.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,cAAc,EACd,QAAQ,GAOX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAiB,MAAM,iBAAiB,CAAC;AAE/E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,WAAW,EAAwB,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAmB,MAAM,eAAe,CAAC;AAC1G,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAQ9C,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AAExB;;;;GAIG;AAWI,IAAM,YAAY,GAAlB,MAAM,YAA8D,SAAQ,IAAO;IAoBtF,YAAY,KAAsC;QAC9C,KAAK,CAAC,CAAC,KAAK,IAAI,EAAE,CAAmC,CAAC,CAAC;IAC3D,CAAC;IAED,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,CAAC,CAAC;AACvB,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,+EAA+E;AAC/E,6BAA6B;AAC7B,SAAS,OAAO,CAAC,IAAqB,EAAE,EAAmB,EAAE,CAAS;IAClE,MAAM,CAAC,GAAY,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAClC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;QACd,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAC7C,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAChC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {\r\n command,\r\n node,\r\n property,\r\n strokeProperty,\r\n withdraw,\r\n type Command,\r\n type CommandArgs,\r\n type NodeConfig,\r\n type PaintProps,\r\n type Stroke,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport { traceContour } from \"../kit/contour\";\r\nimport type { CoordinateMap, Interval } from \"../kit/coords\";\r\nimport type { Curve } from \"../kit/curve\";\r\nimport { equationParams, parseEquation, type Equation } from \"../kit/equation\";\r\nimport type { ExpressionScope } from \"../kit/expression\";\r\nimport { PLOT_COLOR } from \"../kit/furniture\";\r\nimport { stated } from \"../kit/geometry\";\r\nimport { Mark } from \"../kit/mark\";\r\nimport { sampleCurve, type CurveProjection } from \"../kit/sampler\";\r\nimport { lerpDomain, lerpParams, lerpSource, readSource, scopeFor, type PlotSource } from \"../kit/source\";\r\nimport { SYSTEMS } from \"../kit/placement\";\r\nimport { FILL_PAINT } from \"../kit/withdrawn\";\r\n\r\nexport interface FunctionPlotProps extends PaintProps {\r\n expression?: string | PlotSource;\r\n domain?: Interval | null;\r\n params?: ExpressionScope;\r\n}\r\n\r\nconst TAU = Math.PI * 2;\r\n\r\n/**\r\n * The curve of an equation, drawn in the coordinate system it is a child of.\r\n * How the equation is written says what it is: see `Equation`. A mark put\r\n * inside it reads it: the area under it, a tangent, a point that rides it.\r\n */\r\n@node({\r\n key: \"functionPlot\",\r\n within: SYSTEMS,\r\n closed: true,\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: true },\r\n seed: { expression: \"sin(x)\" },\r\n})\r\n@withdraw(...FILL_PAINT)\r\nexport class FunctionPlot<P extends FunctionPlotProps = FunctionPlotProps> extends Mark<P> implements Curve {\r\n @property({ default: \"\", mapper: readSource, tween: lerpSource, kind: \"equation\" })\r\n declare expression: PlotSource;\r\n\r\n /**\r\n * The span of the free variable that is drawn. Left out, a function runs the\r\n * width of its system, a polar curve one turn and a parametric one from 0 to 1.\r\n */\r\n @property({ default: null, tween: lerpDomain, kind: \"range\", defaultMin: -5, defaultMax: 5 }) declare domain: Interval | null;\r\n\r\n /**\r\n * The equation's named values: any name in it that is not a variable, a\r\n * function or a constant. One left unset is 1, and a formula can bind each\r\n * to a variable.\r\n */\r\n @property({ default: {}, tween: lerpParams }) declare params: ExpressionScope;\r\n\r\n @strokeProperty({ default: { weight: 3, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" } })\r\n declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<FunctionPlot<P>, P>) {\r\n super((props ?? {}) as NodeConfig<FunctionPlot<P>, P>);\r\n }\r\n\r\n /** Change the equation, the curve bending from the one into the other. */\r\n @command({ args: [\"expression\"] })\r\n morphTo(args: CommandArgs<{ expression: string }> & { duration: number }): Command<P> {\r\n return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** Animate the equation's named values. */\r\n @command({ args: [\"params\"] })\r\n paramsTo(args: CommandArgs<{ params: ExpressionScope }> & { duration: number }): Command<P> {\r\n return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** Animate the span that is drawn. */\r\n @command({ args: [\"domain\"] })\r\n domainTo(args: CommandArgs<{ domain: Interval | null }> & { duration: number }): Command<P> {\r\n return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /**\r\n * The curve's height at graph `x`, or `NaN` where it has none or is not a\r\n * function of `x`. What a point, a tangent or an area riding this plot reads.\r\n */\r\n valueAt(x: number): number {\r\n const { source, blend } = this.expression;\r\n const shift = this.shift();\r\n const value = this._heightOf(source, x - shift.x) + shift.y;\r\n if (!blend) return value;\r\n const from = this._heightOf(blend.from, x - shift.x) + shift.y;\r\n return from + (value - from) * blend.t;\r\n }\r\n\r\n /** The span of the free variable that is drawn: `domain`, unless a node built on this one says otherwise. */\r\n protected span(): Interval | null {\r\n return this.domain;\r\n }\r\n\r\n protected trace(map: CoordinateMap): Vector2[][] {\r\n const { area } = map;\r\n if (!Number.isFinite(area.maxX - area.minX)) return [];\r\n const { source, blend } = this.expression;\r\n const shift = this.shift();\r\n const key = [source, blend?.from, blend?.t, map.revision, this.span(), JSON.stringify(this.params), shift.x, shift.y].join(\"|\");\r\n if (key === this._key) return this._runs;\r\n this._key = key;\r\n\r\n // A curve with no parameter to walk cannot bend into another: it changes over half way.\r\n const shown = blend && blend.t < 0.5 ? blend.from : source;\r\n if (this._equation(source)?.kind === \"implicit\" || (blend && this._equation(blend.from)?.kind === \"implicit\")) {\r\n this._runs = this._contour(shown, map, shift);\r\n return this._runs;\r\n }\r\n\r\n let curve = this._curve(source, map, shift);\r\n if (curve && blend) {\r\n const from = this._curve(blend.from, map, shift);\r\n if (from) curve = between(from, curve, blend.t);\r\n }\r\n const width = area.maxX - area.minX;\r\n this._runs = curve\r\n ? sampleCurve(curve, 0, 1, area, { seeds: Math.min(512, Math.max(64, Math.round(width / 8))), minStep: 0.5 / Math.max(1, width) })\r\n : [];\r\n return this._runs;\r\n }\r\n\r\n private _key = \"\";\r\n private _runs: Vector2[][] = [];\r\n\r\n private _equation(source: string): Equation | null {\r\n const equation = parseEquation(source, equationParams(source));\r\n return equation instanceof Error ? null : equation;\r\n }\r\n\r\n private _heightOf(source: string, x: number): number {\r\n const equation = this._equation(source);\r\n if (equation?.kind !== \"function\" || equation.of !== \"x\") return NaN;\r\n return equation.f(x, 0, scopeFor(equationParams(source), this.params));\r\n }\r\n\r\n /** Where an implicit `source` holds, over what the system shows, as pixel runs. */\r\n private _contour(source: string, map: CoordinateMap, shift: Vector2): Vector2[][] {\r\n const equation = this._equation(source);\r\n if (equation?.kind !== \"implicit\") return [];\r\n const params = scopeFor(equationParams(source), this.params);\r\n const { area } = map;\r\n const cells = (pixels: number) => Math.min(CONTOUR_MAX, Math.max(8, Math.round(pixels / CONTOUR_CELL)));\r\n const { f } = equation;\r\n const runs = traceContour(\r\n (x, y) => f(x - shift.x, y - shift.y, params),\r\n map.xRange,\r\n map.yRange,\r\n cells(area.maxX - area.minX),\r\n cells(area.maxY - area.minY),\r\n );\r\n return runs.map((run) => run.map((point) => map.toPoint(point.x, point.y)));\r\n }\r\n\r\n /** `source` as a pixel curve over a parameter running 0 to 1. */\r\n private _curve(source: string, map: CoordinateMap, shift: Vector2): CurveProjection | null {\r\n const equation = this._equation(source);\r\n if (!equation || equation.kind === \"implicit\") return null;\r\n const params = scopeFor(equationParams(source), this.params);\r\n const domain = this.span();\r\n switch (equation.kind) {\r\n case \"function\": {\r\n const horizontal = equation.of === \"x\";\r\n const [lo, hi] = horizontal ? map.xRange : map.yRange;\r\n const offset = horizontal ? shift.x : shift.y;\r\n // Only what the system shows is sampled, however wide the domain.\r\n const a = Math.max(lo - offset, domain?.[0] ?? -Infinity);\r\n const b = Math.min(hi - offset, domain?.[1] ?? Infinity);\r\n if (!(b > a)) return null;\r\n const { f } = equation;\r\n return (u, out) => {\r\n const v = a + (b - a) * u;\r\n const w = f(v, 0, params);\r\n if (!Number.isFinite(w)) return false;\r\n if (horizontal) map.toPoint(v + shift.x, w + shift.y, out);\r\n else map.toPoint(w + shift.x, v + shift.y, out);\r\n return true;\r\n };\r\n }\r\n case \"polar\": {\r\n const [a, b] = domain ?? [0, TAU];\r\n const { f } = equation;\r\n return (u, out) => {\r\n const theta = a + (b - a) * u;\r\n const r = f(theta, 0, params);\r\n if (!Number.isFinite(r)) return false;\r\n map.toPoint(r * Math.cos(theta) + shift.x, r * Math.sin(theta) + shift.y, out);\r\n return true;\r\n };\r\n }\r\n case \"parametric\": {\r\n const [a, b] = domain ?? [0, 1];\r\n const { x, y } = equation;\r\n return (u, out) => {\r\n const t = a + (b - a) * u;\r\n const gx = x(t, 0, params);\r\n const gy = y(t, 0, params);\r\n if (!Number.isFinite(gx) || !Number.isFinite(gy)) return false;\r\n map.toPoint(gx + shift.x, gy + shift.y, out);\r\n return true;\r\n };\r\n }\r\n }\r\n }\r\n}\r\n\r\n// Roughly one cell of the contour's grid to this many pixels, each way.\r\nconst CONTOUR_CELL = 5;\r\nconst CONTOUR_MAX = 220;\r\n\r\n// Two curves blended point for point along their parameters, in pixels, so any\r\n// kind bends into any other.\r\nfunction between(from: CurveProjection, to: CurveProjection, t: number): CurveProjection {\r\n const a: Vector2 = { x: 0, y: 0 };\r\n return (u, out) => {\r\n if (!from(u, a) || !to(u, out)) return false;\r\n out.x = a.x + (out.x - a.x) * t;\r\n out.y = a.y + (out.y - a.y) * t;\r\n return true;\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"function-plot.js","sourceRoot":"","sources":["../../src/plots/function-plot.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,QAAQ,EACR,KAAK,GAYR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAA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AC,CAAC;gBAC1B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAAE,OAAO,KAAK,CAAC;gBAC/D,GAAG,CAAC,OAAO,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;gBAC7C,OAAO,IAAI,CAAC;YAChB,CAAC,CAAC;QACN,CAAC;IACL,CAAC;AACL,CAAC;AAED,wEAAwE;AACxE,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,+EAA+E;AAC/E,6BAA6B;AAC7B,SAAS,OAAO,CAAC,IAAqB,EAAE,EAAmB,EAAE,CAAS;IAClE,MAAM,CAAC,GAAY,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAClC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;QACd,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAC7C,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAChC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {\r\n component2d,\r\n provides,\r\n Types,\r\n type EntryOptions,\r\n type NodeOf,\r\n type PaintProps,\r\n type Vector2,\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 { createBoundedCache } from \"../kit/cache\";\r\nimport { omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\r\nimport { traceContour } from \"../kit/contour\";\r\nimport type { CoordinateMap, Interval } from \"../kit/coords\";\r\nimport { equationParams, parseEquation, type Equation } from \"../kit/equation\";\r\nimport type { ExpressionScope } from \"../kit/expression\";\r\nimport { PLOT_COLOR } from \"../kit/furniture\";\r\nimport { PLOT, plotPlane, SYSTEM, SYSTEM_ENTRY } from \"../kit/graph\";\r\nimport { drawMark, inkCentre, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\r\nimport { openPlane, placeOnMap } from \"../kit/place\";\r\nimport { sampleCurve, type CurveProjection } from \"../kit/sampler\";\r\nimport { lerpDomain, lerpParams, lerpSource, readSource, scopeFor, type PlotSource } from \"../kit/source\";\r\n\r\nexport interface FunctionPlotProps extends PaintProps {\r\n expression?: string | PlotSource;\r\n domain?: Interval | null;\r\n params?: ExpressionScope;\r\n}\r\n\r\nconst TAU = Math.PI * 2;\r\n\r\n/** A plot's entries: what a traced path is built on too. It is only a line, so it has no fill. */\r\nexport const PLOT_STATE = {\r\n ...omit(PAINT, \"fill\"),\r\n expression: Types.custom<string | PlotSource, PlotSource>(\"\", { resolve: readSource, lerp: lerpSource, kind: \"equation\" }),\r\n /**\r\n * The span of the free variable that is drawn. Left out, a function runs the\r\n * width of its system, a polar curve one turn and a parametric one from 0 to 1.\r\n */\r\n domain: Types.custom<Interval | null, Interval | null, EntryOptions & { readonly defaultMin: number; readonly defaultMax: number }>(null, { lerp: lerpDomain, kind: \"range\", defaultMin: -5, defaultMax: 5 }),\r\n /**\r\n * The equation's named values: any name in it that is not a variable, a\r\n * function or a constant. One left unset is 1, and a formula can bind each\r\n * to a variable.\r\n */\r\n params: Types.custom<ExpressionScope>({}, { lerp: lerpParams }),\r\n graph: SYSTEM_ENTRY,\r\n};\r\n\r\n/** A plot's own commands, beside a line's paints. */\r\nexport const PLOT_COMMANDS = {\r\n ...omit(PAINT_COMMANDS, \"fillTo\"),\r\n /** Change the equation, the curve bending from the one into the other. */\r\n morphTo: { args: [\"expression\"] as const },\r\n /** Animate the equation's named values. */\r\n paramsTo: { args: [\"params\"] as const },\r\n /** Animate the span that is drawn. */\r\n domainTo: { args: [\"domain\"] as const },\r\n};\r\n\r\nexport const PLOT_STROKE = { weight: 3, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" } as const;\r\n\r\n/** What a plot's curve is drawn from. */\r\nexport interface PlotValues {\r\n readonly expression: PlotSource;\r\n readonly params: ExpressionScope;\r\n}\r\n\r\n/**\r\n * The curve of an equation, drawn in the coordinate system it is a child of.\r\n * How the equation is written says what it is: see `Equation`. A mark put\r\n * inside it reads it: the area under it, a tangent, a point that rides it.\r\n */\r\nexport const FunctionPlot = traced(component2d({\r\n key: \"functionPlot\",\r\n state: PLOT_STATE,\r\n defaults: { stroke: PLOT_STROKE, width: \"hug\", height: \"hug\" },\r\n commands: PLOT_COMMANDS,\r\n // The marks inside it ride it, on its system's map.\r\n provide: (s, inherited) => [provides(PLOT, plotPlane(s, inherited(SYSTEM)))],\r\n measure: (_measurer, s) => inkSize(tracePlot(s, reading(s), s.domain)),\r\n layout: (box, s, children) => {\r\n const read = reading(s);\r\n return placeOnMap(children, read.map, inkCentre(tracePlot(s, read, s.domain)), box, plotPlane(s, s.graph));\r\n },\r\n plane: (_box, s) => {\r\n const read = reading(s);\r\n return openPlane(read.map, inkCentre(tracePlot(s, read, s.domain)));\r\n },\r\n render: (ctx, s) => drawMark(ctx, s, tracePlot(s, reading(s), s.domain)),\r\n}), (s: PlotValues & { readonly domain: Interval | null }, read: MarkReading) => tracePlot(s, read, s.domain));\r\n\r\nexport type FunctionPlot = NodeOf<typeof FunctionPlot>;\r\n\r\nconst traces = createBoundedCache<Vector2[][]>(256);\r\n\r\n/** The runs a plot of `s` draws through `read`, over `span` of its free variable (all of it for `null`). */\r\nexport function tracePlot(s: PlotValues, read: MarkReading, span: Interval | null): Vector2[][] {\r\n const { map, shift } = read;\r\n const { area } = map;\r\n if (!Number.isFinite(area.maxX - area.minX)) return [];\r\n const { source, blend } = s.expression;\r\n const key = [source, blend?.from, blend?.t, map.revision, span, JSON.stringify(s.params), shift.x, shift.y].join(\"|\");\r\n const known = traces.get(key);\r\n if (known) return known;\r\n\r\n let runs: Vector2[][];\r\n // A curve with no parameter to walk cannot bend into another: it changes over half way.\r\n const shown = blend && blend.t < 0.5 ? blend.from : source;\r\n if (equationOf(source)?.kind === \"implicit\" || (blend && equationOf(blend.from)?.kind === \"implicit\")) {\r\n runs = contour(shown, s.params, map, shift);\r\n } else {\r\n let curve = projectionOf(source, s.params, span, map, shift);\r\n if (curve && blend) {\r\n const from = projectionOf(blend.from, s.params, span, map, shift);\r\n if (from) curve = between(from, curve, blend.t);\r\n }\r\n const width = area.maxX - area.minX;\r\n runs = curve\r\n ? sampleCurve(curve, 0, 1, area, { seeds: Math.min(512, Math.max(64, Math.round(width / 8))), minStep: 0.5 / Math.max(1, width) })\r\n : [];\r\n }\r\n traces.set(key, runs);\r\n return runs;\r\n}\r\n\r\nfunction equationOf(source: string): Equation | null {\r\n const equation = parseEquation(source, equationParams(source));\r\n return equation instanceof Error ? null : equation;\r\n}\r\n\r\n/** Where an implicit `source` holds, over what the system shows, as pixel runs. */\r\nfunction contour(source: string, params: ExpressionScope, map: CoordinateMap, shift: Vector2): Vector2[][] {\r\n const equation = equationOf(source);\r\n if (equation?.kind !== \"implicit\") return [];\r\n const scope = scopeFor(equationParams(source), params);\r\n const { area } = map;\r\n const cells = (pixels: number) => Math.min(CONTOUR_MAX, Math.max(8, Math.round(pixels / CONTOUR_CELL)));\r\n const { f } = equation;\r\n const runs = traceContour(\r\n (x, y) => f(x - shift.x, y - shift.y, scope),\r\n map.xRange,\r\n map.yRange,\r\n cells(area.maxX - area.minX),\r\n cells(area.maxY - area.minY),\r\n );\r\n return runs.map((run) => run.map((point) => map.toPoint(point.x, point.y)));\r\n}\r\n\r\n/** `source` as a pixel curve over a parameter running 0 to 1. */\r\nfunction projectionOf(source: string, params: ExpressionScope, domain: Interval | null, map: CoordinateMap, shift: Vector2): CurveProjection | null {\r\n const equation = equationOf(source);\r\n if (!equation || equation.kind === \"implicit\") return null;\r\n const scope = scopeFor(equationParams(source), params);\r\n switch (equation.kind) {\r\n case \"function\": {\r\n const horizontal = equation.of === \"x\";\r\n const [lo, hi] = horizontal ? map.xRange : map.yRange;\r\n const offset = horizontal ? shift.x : shift.y;\r\n // Only what the system shows is sampled, however wide the domain.\r\n const a = Math.max(lo - offset, domain?.[0] ?? -Infinity);\r\n const b = Math.min(hi - offset, domain?.[1] ?? Infinity);\r\n if (!(b > a)) return null;\r\n const { f } = equation;\r\n return (u, out) => {\r\n const v = a + (b - a) * u;\r\n const w = f(v, 0, scope);\r\n if (!Number.isFinite(w)) return false;\r\n if (horizontal) map.toPoint(v + shift.x, w + shift.y, out);\r\n else map.toPoint(w + shift.x, v + shift.y, out);\r\n return true;\r\n };\r\n }\r\n case \"polar\": {\r\n const [a, b] = domain ?? [0, TAU];\r\n const { f } = equation;\r\n return (u, out) => {\r\n const theta = a + (b - a) * u;\r\n const r = f(theta, 0, scope);\r\n if (!Number.isFinite(r)) return false;\r\n map.toPoint(r * Math.cos(theta) + shift.x, r * Math.sin(theta) + shift.y, out);\r\n return true;\r\n };\r\n }\r\n case \"parametric\": {\r\n const [a, b] = domain ?? [0, 1];\r\n const { x, y } = equation;\r\n return (u, out) => {\r\n const t = a + (b - a) * u;\r\n const gx = x(t, 0, scope);\r\n const gy = y(t, 0, scope);\r\n if (!Number.isFinite(gx) || !Number.isFinite(gy)) return false;\r\n map.toPoint(gx + shift.x, gy + shift.y, out);\r\n return true;\r\n };\r\n }\r\n }\r\n}\r\n\r\n// Roughly one cell of the contour's grid to this many pixels, each way.\r\nconst CONTOUR_CELL = 5;\r\nconst CONTOUR_MAX = 220;\r\n\r\n// Two curves blended point for point along their parameters, in pixels, so any\r\n// kind bends into any other.\r\nfunction between(from: CurveProjection, to: CurveProjection, t: number): CurveProjection {\r\n const a: Vector2 = { x: 0, y: 0 };\r\n return (u, out) => {\r\n if (!from(u, a) || !to(u, out)) return false;\r\n out.x = a.x + (out.x - a.x) * t;\r\n out.y = a.y + (out.y - a.y) * t;\r\n return true;\r\n };\r\n}\r\n"]}
|
|
@@ -1,28 +1,64 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type { CoordinateMap } from "../kit/coords.js";
|
|
3
|
-
import { Mark } from "../kit/mark.js";
|
|
1
|
+
import { type NodeOf, type PaintProps, type Vector2, 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";
|
|
4
2
|
export interface PointsPlotProps extends PaintProps {
|
|
5
3
|
points?: Vector2[];
|
|
6
4
|
closed?: boolean;
|
|
7
5
|
smooth?: boolean;
|
|
8
6
|
}
|
|
9
7
|
/** A line through listed graph points: data, or a shape drawn in graph coordinates when closed, which is when it is filled. */
|
|
10
|
-
export declare
|
|
11
|
-
points: Vector2[]
|
|
8
|
+
export declare const PointsPlot: import("@motionscript/sdk").Component<"pointsPlot", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
9
|
+
points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
12
10
|
/** Join the last point to the first. */
|
|
13
|
-
closed: boolean
|
|
11
|
+
closed: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
14
12
|
/** Curve through the points instead of turning a corner at each. */
|
|
15
|
-
smooth: boolean
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
smooth: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
14
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
15
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
16
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
17
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
18
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
19
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
20
|
+
}>, {
|
|
21
|
+
readonly pointsTo: readonly ["points"];
|
|
22
|
+
readonly fillTo: readonly ["fill"];
|
|
23
|
+
readonly strokeTo: readonly ["stroke"];
|
|
24
|
+
readonly shadowTo: readonly ["shadow"];
|
|
25
|
+
readonly progressTo: readonly ["start", "end"];
|
|
26
|
+
readonly flash: {
|
|
27
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
28
|
+
};
|
|
29
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
30
|
+
points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
31
|
+
/** Join the last point to the first. */
|
|
32
|
+
closed: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
33
|
+
/** Curve through the points instead of turning a corner at each. */
|
|
34
|
+
smooth: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
35
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
36
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
37
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
38
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
39
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
40
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
41
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
42
|
+
points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
43
|
+
/** Join the last point to the first. */
|
|
44
|
+
closed: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
45
|
+
/** Curve through the points instead of turning a corner at each. */
|
|
46
|
+
smooth: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
47
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
48
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
49
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
50
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
51
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
52
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
53
|
+
}>, {
|
|
54
|
+
readonly pointsTo: readonly ["points"];
|
|
55
|
+
readonly fillTo: readonly ["fill"];
|
|
56
|
+
readonly strokeTo: readonly ["stroke"];
|
|
57
|
+
readonly shadowTo: readonly ["shadow"];
|
|
58
|
+
readonly progressTo: readonly ["start", "end"];
|
|
59
|
+
readonly flash: {
|
|
60
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
61
|
+
};
|
|
62
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
63
|
+
export type PointsPlot = NodeOf<typeof PointsPlot>;
|
|
28
64
|
//# sourceMappingURL=points-plot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"points-plot.d.ts","sourceRoot":"","sources":["../../src/plots/points-plot.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"points-plot.d.ts","sourceRoot":"","sources":["../../src/plots/points-plot.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,OAAO,EAEZ,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;AAM3B,MAAM,WAAW,eAAgB,SAAQ,UAAU;IAC/C,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAkCD,+HAA+H;AAC/H,eAAO,MAAM,UAAU;;IAdnB,wCAAwC;;IAExC,oEAAoE;;;;;;;;;;;;;;;;;;;IAFpE,wCAAwC;;IAExC,oEAAoE;;;;;;;;;;IAFpE,wCAAwC;;IAExC,oEAAoE;;;;;;;;;;;;;;;;;2BAwBxD,CAAC;AAEjB,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC"}
|