@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,14 +1,8 @@
|
|
|
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 { command, node, property, strokeProperty, } from "@motionscript/sdk";
|
|
8
|
-
import { stated } from "../kit/geometry.js";
|
|
9
|
-
import { Mark } from "../kit/mark.js";
|
|
1
|
+
import { component2d, Types, } from "@motionscript/sdk";
|
|
2
|
+
import { PAINT, PAINT_COMMANDS } from "../kit/component.js";
|
|
10
3
|
import { PLOT_COLOR } from "../kit/furniture.js";
|
|
11
|
-
import {
|
|
4
|
+
import { PLANE_ENTRY } from "../kit/graph.js";
|
|
5
|
+
import { drawMark, inkSize, reading, traced } from "../kit/mark.js";
|
|
12
6
|
// A shorter list is padded with its own last point, so a line grows new points out of its end.
|
|
13
7
|
function lerpPoints(from, to, t) {
|
|
14
8
|
const count = Math.max(from.length, to.length);
|
|
@@ -24,56 +18,35 @@ function lerpPoints(from, to, t) {
|
|
|
24
18
|
}
|
|
25
19
|
/** Points on the curve between each pair of a smooth line's points. */
|
|
26
20
|
const SMOOTH_STEPS = 16;
|
|
21
|
+
const state = {
|
|
22
|
+
...PAINT,
|
|
23
|
+
points: Types.custom([], { lerp: lerpPoints }),
|
|
24
|
+
/** Join the last point to the first. */
|
|
25
|
+
closed: Types.boolean(false, { animatable: false }),
|
|
26
|
+
/** Curve through the points instead of turning a corner at each. */
|
|
27
|
+
smooth: Types.boolean(false, { animatable: false }),
|
|
28
|
+
graph: PLANE_ENTRY,
|
|
29
|
+
};
|
|
27
30
|
/** A line through listed graph points: data, or a shape drawn in graph coordinates when closed, which is when it is filled. */
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
31
|
+
export const PointsPlot = traced(component2d({
|
|
32
|
+
key: "pointsPlot",
|
|
33
|
+
state,
|
|
34
|
+
defaults: { stroke: { weight: 3, fill: PLOT_COLOR, align: "center", cap: "round", join: "round" }, width: "hug", height: "hug" },
|
|
35
|
+
commands: {
|
|
36
|
+
...PAINT_COMMANDS,
|
|
37
|
+
/** Move the points to new places; extra ones grow from the line's end. */
|
|
38
|
+
pointsTo: { args: ["points"] },
|
|
39
|
+
},
|
|
40
|
+
measure: (_measurer, s) => inkSize(tracePoints(s, reading(s))),
|
|
39
41
|
// An open line has no inside, so its fill waits until it is closed.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return [this.smooth && pixels.length > 2 ? spline(pixels, this.closed) : pixels];
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
__decorate([
|
|
52
|
-
property({ default: [], tween: lerpPoints })
|
|
53
|
-
], PointsPlot.prototype, "points", void 0);
|
|
54
|
-
__decorate([
|
|
55
|
-
property({ default: false, animatable: false })
|
|
56
|
-
], PointsPlot.prototype, "closed", void 0);
|
|
57
|
-
__decorate([
|
|
58
|
-
property({ default: false, animatable: false })
|
|
59
|
-
], PointsPlot.prototype, "smooth", void 0);
|
|
60
|
-
__decorate([
|
|
61
|
-
strokeProperty({ default: { weight: 3, fill: PLOT_COLOR, align: "center", cap: "round", join: "round" } })
|
|
62
|
-
], PointsPlot.prototype, "stroke", void 0);
|
|
63
|
-
__decorate([
|
|
64
|
-
command({ args: ["points"] })
|
|
65
|
-
], PointsPlot.prototype, "pointsTo", null);
|
|
66
|
-
PointsPlot = __decorate([
|
|
67
|
-
node({
|
|
68
|
-
key: "pointsPlot",
|
|
69
|
-
within: SYSTEMS,
|
|
70
|
-
parentKey: "shape",
|
|
71
|
-
forkable: true,
|
|
72
|
-
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
|
|
73
|
-
seed: { points: [{ x: -2, y: -1 }, { x: 0, y: 1 }, { x: 2, y: 0 }] },
|
|
74
|
-
})
|
|
75
|
-
], PointsPlot);
|
|
76
|
-
export { PointsPlot };
|
|
42
|
+
render: (ctx, s) => drawMark(ctx, s, tracePoints(s, reading(s)), { closed: s.closed, fills: s.closed }),
|
|
43
|
+
}), tracePoints);
|
|
44
|
+
function tracePoints(s, { map, shift }) {
|
|
45
|
+
const pixels = s.points.map((p) => map.toPoint(p.x + shift.x, p.y + shift.y));
|
|
46
|
+
if (pixels.length < 2)
|
|
47
|
+
return [];
|
|
48
|
+
return [s.smooth && pixels.length > 2 ? spline(pixels, s.closed) : pixels];
|
|
49
|
+
}
|
|
77
50
|
// Catmull–Rom, so the curve passes through every point it was given.
|
|
78
51
|
function spline(points, closed) {
|
|
79
52
|
const n = points.length;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"points-plot.js","sourceRoot":"","sources":["../../src/plots/points-plot.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"points-plot.js","sourceRoot":"","sources":["../../src/plots/points-plot.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,KAAK,GA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AAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;aACpI,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IACD,IAAI,CAAC,MAAM;QAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACrC,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import {\r\n component2d,\r\n Types,\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 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 { PAINT, PAINT_COMMANDS } from \"../kit/component\";\r\nimport { PLOT_COLOR } from \"../kit/furniture\";\r\nimport { PLANE_ENTRY } from \"../kit/graph\";\r\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\r\n\r\nexport interface PointsPlotProps extends PaintProps {\r\n points?: Vector2[];\r\n closed?: boolean;\r\n smooth?: boolean;\r\n}\r\n\r\n// A shorter list is padded with its own last point, so a line grows new points out of its end.\r\nfunction lerpPoints(from: Vector2[], to: Vector2[], t: number): Vector2[] {\r\n const count = Math.max(from.length, to.length);\r\n if (from.length === 0 || to.length === 0) return t < 1 ? from : to;\r\n const out = new Array<Vector2>(count);\r\n for (let i = 0; i < count; i++) {\r\n const a = from[Math.min(i, from.length - 1)];\r\n const b = to[Math.min(i, to.length - 1)];\r\n out[i] = { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };\r\n }\r\n return out;\r\n}\r\n\r\n/** Points on the curve between each pair of a smooth line's points. */\r\nconst SMOOTH_STEPS = 16;\r\n\r\nconst state = {\r\n ...PAINT,\r\n points: Types.custom<Vector2[]>([], { lerp: lerpPoints }),\r\n /** Join the last point to the first. */\r\n closed: Types.boolean(false, { animatable: false }),\r\n /** Curve through the points instead of turning a corner at each. */\r\n smooth: Types.boolean(false, { animatable: false }),\r\n graph: PLANE_ENTRY,\r\n};\r\n\r\ninterface PointsValues {\r\n readonly points: Vector2[];\r\n readonly closed: boolean;\r\n readonly smooth: boolean;\r\n}\r\n\r\n/** A line through listed graph points: data, or a shape drawn in graph coordinates when closed, which is when it is filled. */\r\nexport const PointsPlot = traced(component2d({\r\n key: \"pointsPlot\",\r\n state,\r\n defaults: { stroke: { weight: 3, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\r\n commands: {\r\n ...PAINT_COMMANDS,\r\n /** Move the points to new places; extra ones grow from the line's end. */\r\n pointsTo: { args: [\"points\"] },\r\n },\r\n measure: (_measurer, s) => inkSize(tracePoints(s, reading(s))),\r\n // An open line has no inside, so its fill waits until it is closed.\r\n render: (ctx, s) => drawMark(ctx, s, tracePoints(s, reading(s)), { closed: s.closed, fills: s.closed }),\r\n}), tracePoints);\r\n\r\nexport type PointsPlot = NodeOf<typeof PointsPlot>;\r\n\r\nfunction tracePoints(s: PointsValues, { map, shift }: MarkReading): Vector2[][] {\r\n const pixels = s.points.map((p) => map.toPoint(p.x + shift.x, p.y + shift.y));\r\n if (pixels.length < 2) return [];\r\n return [s.smooth && pixels.length > 2 ? spline(pixels, s.closed) : pixels];\r\n}\r\n\r\n// Catmull–Rom, so the curve passes through every point it was given.\r\nfunction spline(points: readonly Vector2[], closed: boolean): Vector2[] {\r\n const n = points.length;\r\n const at = (i: number): Vector2 => (closed ? points[((i % n) + n) % n] : points[Math.max(0, Math.min(n - 1, i))]);\r\n const out: Vector2[] = [];\r\n const spans = closed ? n : n - 1;\r\n for (let i = 0; i < spans; i++) {\r\n const p0 = at(i - 1), p1 = at(i), p2 = at(i + 1), p3 = at(i + 2);\r\n for (let s = 0; s < SMOOTH_STEPS; s++) {\r\n const t = s / SMOOTH_STEPS;\r\n const t2 = t * t;\r\n const t3 = t2 * t;\r\n out.push({\r\n x: 0.5 * (2 * p1.x + (p2.x - p0.x) * t + (2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t2 + (3 * p1.x - p0.x - 3 * p2.x + p3.x) * t3),\r\n y: 0.5 * (2 * p1.y + (p2.y - p0.y) * t + (2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t2 + (3 * p1.y - p0.y - 3 * p2.y + p3.y) * t3),\r\n });\r\n }\r\n }\r\n if (!closed) out.push(points[n - 1]);\r\n return out;\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 StreamLinesProps extends FieldProps {
|
|
5
4
|
spacing?: number;
|
|
6
5
|
length?: number;
|
|
@@ -12,24 +11,66 @@ export interface StreamLinesProps extends FieldProps {
|
|
|
12
11
|
* grid: `(-y, x)` draws circles. With a `window` below one, each line shows
|
|
13
12
|
* only a stretch of itself, and `flowTo` sends those stretches along.
|
|
14
13
|
*/
|
|
15
|
-
export declare
|
|
14
|
+
export declare const StreamLines: import("@motionscript/sdk").Component<"streamLines", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
16
15
|
/** How far apart the lines start, in graph units. */
|
|
17
|
-
spacing: number
|
|
16
|
+
spacing: import("@motionscript/sdk").Type<number, number, false>;
|
|
18
17
|
/** How far each line runs from where it starts, in graph units along itself. */
|
|
19
|
-
length: number
|
|
18
|
+
length: import("@motionscript/sdk").Type<number, number, false>;
|
|
20
19
|
/** The share of each line that is shown at once; one shows all of it. */
|
|
21
|
-
window: number
|
|
20
|
+
window: import("@motionscript/sdk").Type<number, number, false>;
|
|
22
21
|
/** Where along its line each shown stretch is: one turn of it runs every line from end to end. */
|
|
23
|
-
phase: number
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
phase: import("@motionscript/sdk").Type<number, number, false>;
|
|
23
|
+
expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
|
|
24
|
+
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
25
|
+
strengthFills: import("@motionscript/sdk").Type<_Fill[], _FillResolved[][], false>;
|
|
26
|
+
maxMagnitude: import("@motionscript/sdk").Type<number, number, false>;
|
|
27
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
28
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
29
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
30
|
+
}>, {
|
|
31
|
+
readonly flowTo: readonly ["phase"];
|
|
32
|
+
readonly morphTo: readonly ["expression"];
|
|
33
|
+
readonly paramsTo: readonly ["params"];
|
|
34
|
+
readonly strokeTo: readonly ["stroke"];
|
|
35
|
+
readonly shadowTo: readonly ["shadow"];
|
|
36
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
37
|
+
/** How far apart the lines start, in graph units. */
|
|
38
|
+
spacing: import("@motionscript/sdk").Type<number, number, false>;
|
|
39
|
+
/** How far each line runs from where it starts, in graph units along itself. */
|
|
40
|
+
length: import("@motionscript/sdk").Type<number, number, false>;
|
|
41
|
+
/** The share of each line that is shown at once; one shows all of it. */
|
|
42
|
+
window: import("@motionscript/sdk").Type<number, number, false>;
|
|
43
|
+
/** Where along its line each shown stretch is: one turn of it runs every line from end to end. */
|
|
44
|
+
phase: import("@motionscript/sdk").Type<number, number, false>;
|
|
45
|
+
expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
|
|
46
|
+
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
47
|
+
strengthFills: import("@motionscript/sdk").Type<_Fill[], _FillResolved[][], false>;
|
|
48
|
+
maxMagnitude: import("@motionscript/sdk").Type<number, number, false>;
|
|
49
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
50
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
51
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
52
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
53
|
+
/** How far apart the lines start, in graph units. */
|
|
54
|
+
spacing: import("@motionscript/sdk").Type<number, number, false>;
|
|
55
|
+
/** How far each line runs from where it starts, in graph units along itself. */
|
|
56
|
+
length: import("@motionscript/sdk").Type<number, number, false>;
|
|
57
|
+
/** The share of each line that is shown at once; one shows all of it. */
|
|
58
|
+
window: import("@motionscript/sdk").Type<number, number, false>;
|
|
59
|
+
/** Where along its line each shown stretch is: one turn of it runs every line from end to end. */
|
|
60
|
+
phase: import("@motionscript/sdk").Type<number, number, false>;
|
|
61
|
+
expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
|
|
62
|
+
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
63
|
+
strengthFills: import("@motionscript/sdk").Type<_Fill[], _FillResolved[][], false>;
|
|
64
|
+
maxMagnitude: import("@motionscript/sdk").Type<number, number, false>;
|
|
65
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
66
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
67
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
68
|
+
}>, {
|
|
69
|
+
readonly flowTo: readonly ["phase"];
|
|
70
|
+
readonly morphTo: readonly ["expression"];
|
|
71
|
+
readonly paramsTo: readonly ["params"];
|
|
72
|
+
readonly strokeTo: readonly ["stroke"];
|
|
73
|
+
readonly shadowTo: readonly ["shadow"];
|
|
74
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
75
|
+
export type StreamLines = NodeOf<typeof StreamLines>;
|
|
35
76
|
//# sourceMappingURL=stream-lines.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-lines.d.ts","sourceRoot":"","sources":["../../src/plots/stream-lines.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"stream-lines.d.ts","sourceRoot":"","sources":["../../src/plots/stream-lines.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;AAKlL,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAiCD;;;;GAIG;AACH,eAAO,MAAM,WAAW;IA7BpB,qDAAqD;;IAErD,gFAAgF;;IAEhF,yEAAyE;;IAEzE,kGAAkG;;;;;;;;;;;;;;;;IANlG,qDAAqD;;IAErD,gFAAgF;;IAEhF,yEAAyE;;IAEzE,kGAAkG;;;;;;;;;;IANlG,qDAAqD;;IAErD,gFAAgF;;IAEhF,yEAAyE;;IAEzE,kGAAkG;;;;;;;;;;;;;;;2BAkClC,CAAC;AAErE,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC"}
|
|
@@ -1,94 +1,75 @@
|
|
|
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 { command, 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 { clamp
|
|
11
|
-
import {
|
|
4
|
+
import { clamp } from "../kit/geometry.js";
|
|
5
|
+
import { inkSize, reading, traced } from "../kit/mark.js";
|
|
12
6
|
const MAX_LINES = 1600;
|
|
13
7
|
/** Steps a line takes across one spacing: what keeps a tight swirl round. */
|
|
14
8
|
const STEPS_PER_SPACING = 8;
|
|
15
9
|
const MAX_STEPS = 600;
|
|
10
|
+
const state = {
|
|
11
|
+
...FIELD_STATE,
|
|
12
|
+
/** How far apart the lines start, in graph units. */
|
|
13
|
+
spacing: Types.number(1, { min: 0.01, step: 0.1 }),
|
|
14
|
+
/** How far each line runs from where it starts, in graph units along itself. */
|
|
15
|
+
length: Types.number(3, { min: 0, step: 0.1 }),
|
|
16
|
+
/** The share of each line that is shown at once; one shows all of it. */
|
|
17
|
+
window: Types.number(1, { min: 0.01, max: 1, step: 0.01 }),
|
|
18
|
+
/** Where along its line each shown stretch is: one turn of it runs every line from end to end. */
|
|
19
|
+
phase: Types.number(0, { step: 0.01 }),
|
|
20
|
+
};
|
|
21
|
+
const LINES = {
|
|
22
|
+
own: (s) => `${s.spacing}|${s.length}|${s.window}|${s.phase}`,
|
|
23
|
+
strokes: (s, map, field) => lines(s, map, field),
|
|
24
|
+
};
|
|
25
|
+
const traceLines = (s, read) => traceField("streamLines", LINES, s, read);
|
|
16
26
|
/**
|
|
17
27
|
* The lines a vector field carries a point along, one from each point of a
|
|
18
28
|
* grid: `(-y, x)` draws circles. With a `window` below one, each line shows
|
|
19
29
|
* only a stretch of itself, and `flowTo` sends those stretches along.
|
|
20
30
|
*/
|
|
21
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
31
|
+
export const StreamLines = traced(component2d({
|
|
32
|
+
key: "streamLines",
|
|
33
|
+
state,
|
|
34
|
+
defaults: { stroke: { weight: 2, fill: PLOT_COLOR, align: "center", cap: "round", join: "round" }, width: "hug", height: "hug" },
|
|
35
|
+
commands: {
|
|
36
|
+
...FIELD_COMMANDS,
|
|
37
|
+
/** Send the shown stretches along their lines: a whole number runs each line that many times over. */
|
|
38
|
+
flowTo: { args: ["phase"] },
|
|
39
|
+
},
|
|
40
|
+
measure: (_measurer, s) => inkSize(traceLines(s, reading(s)).runs),
|
|
41
|
+
render: (ctx, s) => drawField(ctx, s, traceLines(s, reading(s))),
|
|
42
|
+
}), (s, read) => traceLines(s, read).runs);
|
|
43
|
+
function lines(s, map, field) {
|
|
44
|
+
const [x0, x1] = map.xRange;
|
|
45
|
+
const [y0, y1] = map.yRange;
|
|
46
|
+
let spacing = Math.max(s.spacing, 1e-6);
|
|
47
|
+
const count = () => (Math.floor((x1 - x0) / spacing) + 1) * (Math.floor((y1 - y0) / spacing) + 1);
|
|
48
|
+
while (count() > MAX_LINES)
|
|
49
|
+
spacing *= 2;
|
|
50
|
+
const step = spacing / STEPS_PER_SPACING;
|
|
51
|
+
const steps = Math.min(MAX_STEPS, Math.round(s.length / step));
|
|
52
|
+
if (steps < 1)
|
|
53
|
+
return [];
|
|
54
|
+
// A line is followed a little past what is shown, so it leaves the box rather than stopping at its edge.
|
|
55
|
+
const inside = (x, y) => x >= x0 - spacing && x <= x1 + spacing && y >= y0 - spacing && y <= y1 + spacing;
|
|
56
|
+
const window = clamp(s.window, 0, 1);
|
|
57
|
+
const drawn = [];
|
|
58
|
+
let index = 0;
|
|
59
|
+
for (let i = Math.ceil(x0 / spacing - 1e-9); i * spacing <= x1 + 1e-9; i++) {
|
|
60
|
+
for (let j = Math.ceil(y0 / spacing - 1e-9); j * spacing <= y1 + 1e-9; j++) {
|
|
61
|
+
const line = follow(field, i * spacing, j * spacing, step, steps, inside);
|
|
62
|
+
index++;
|
|
63
|
+
if (line.points.length < 2)
|
|
64
|
+
continue;
|
|
65
|
+
const shown = window >= 1 ? line.points : stretch(line.points, window, s.phase + stagger(index));
|
|
66
|
+
if (shown.length < 2)
|
|
67
|
+
continue;
|
|
68
|
+
drawn.push({ runs: [shown.map((p) => map.toPoint(p.x, p.y))], magnitude: line.magnitude });
|
|
59
69
|
}
|
|
60
|
-
return drawn;
|
|
61
70
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
property({ default: 1, min: 0.01, step: 0.1 })
|
|
65
|
-
], StreamLines.prototype, "spacing", void 0);
|
|
66
|
-
__decorate([
|
|
67
|
-
property({ default: 3, min: 0, step: 0.1 })
|
|
68
|
-
], StreamLines.prototype, "length", void 0);
|
|
69
|
-
__decorate([
|
|
70
|
-
property({ default: 1, min: 0.01, max: 1, step: 0.01 })
|
|
71
|
-
], StreamLines.prototype, "window", void 0);
|
|
72
|
-
__decorate([
|
|
73
|
-
property({ default: 0, step: 0.01 })
|
|
74
|
-
], StreamLines.prototype, "phase", void 0);
|
|
75
|
-
__decorate([
|
|
76
|
-
strokeProperty({ default: { weight: 2, fill: PLOT_COLOR, align: "center", cap: "round", join: "round" } })
|
|
77
|
-
], StreamLines.prototype, "stroke", void 0);
|
|
78
|
-
__decorate([
|
|
79
|
-
command({ args: ["phase"] })
|
|
80
|
-
], StreamLines.prototype, "flowTo", null);
|
|
81
|
-
StreamLines = __decorate([
|
|
82
|
-
node({
|
|
83
|
-
key: "streamLines",
|
|
84
|
-
within: SYSTEMS,
|
|
85
|
-
parentKey: "shape",
|
|
86
|
-
forkable: true,
|
|
87
|
-
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
|
|
88
|
-
seed: { expression: "(sin(y), cos(x))" },
|
|
89
|
-
})
|
|
90
|
-
], StreamLines);
|
|
91
|
-
export { StreamLines };
|
|
71
|
+
return drawn;
|
|
72
|
+
}
|
|
92
73
|
/** The graph points a field carries a point through from `(x, y)`, at an even pace, and how strong it was on the way. */
|
|
93
74
|
function follow(field, x, y, step, steps, inside) {
|
|
94
75
|
const points = [{ x, y }];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-lines.js","sourceRoot":"","sources":["../../src/plots/stream-lines.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,cAAc,GAMjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAwD,MAAM,mBAAmB,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAS3C,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,6EAA6E;AAC7E,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB;;;;GAIG;AASI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,SAA2B;IAaxD,YAAY,KAAiD;QACzD,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IACvB,CAAC;IAED,sGAAsG;IAEtG,MAAM,CAAC,IAA2D;QAC9D,OAAO,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9F,CAAC;IAES,GAAG;QACT,OAAO,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,KAAa;IAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,UAAU,CAAC;IACrD,OAAO,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import {\r\n command,\r\n node,\r\n property,\r\n strokeProperty,\r\n type Command,\r\n type CommandArgs,\r\n type NodeConfig,\r\n type Stroke,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport type { CoordinateMap } from \"../kit/coords\";\r\nimport { FieldMark, type FieldProps, type FieldSampler, type FieldStroke } from \"../kit/field-mark\";\r\nimport { PLOT_COLOR } from \"../kit/furniture\";\r\nimport { clamp, stated } from \"../kit/geometry\";\r\nimport { SYSTEMS } from \"../kit/placement\";\r\n\r\nexport interface StreamLinesProps extends FieldProps {\r\n spacing?: number;\r\n length?: number;\r\n window?: number;\r\n phase?: number;\r\n}\r\n\r\nconst MAX_LINES = 1600;\r\n/** Steps a line takes across one spacing: what keeps a tight swirl round. */\r\nconst STEPS_PER_SPACING = 8;\r\nconst MAX_STEPS = 600;\r\n\r\n/**\r\n * The lines a vector field carries a point along, one from each point of a\r\n * grid: `(-y, x)` draws circles. With a `window` below one, each line shows\r\n * only a stretch of itself, and `flowTo` sends those stretches along.\r\n */\r\n@node({\r\n key: \"streamLines\",\r\n within: SYSTEMS,\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: false },\r\n seed: { expression: \"(sin(y), cos(x))\" },\r\n})\r\nexport class StreamLines extends FieldMark<StreamLinesProps> {\r\n /** How far apart the lines start, in graph units. */\r\n @property({ default: 1, min: 0.01, step: 0.1 }) declare spacing: number;\r\n /** How far each line runs from where it starts, in graph units along itself. */\r\n @property({ default: 3, min: 0, step: 0.1 }) declare length: number;\r\n /** The share of each line that is shown at once; one shows all of it. */\r\n @property({ default: 1, min: 0.01, max: 1, step: 0.01 }) declare window: number;\r\n /** Where along its line each shown stretch is: one turn of it runs every line from end to end. */\r\n @property({ default: 0, step: 0.01 }) declare phase: number;\r\n\r\n @strokeProperty({ default: { weight: 2, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" } })\r\n declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<StreamLines, StreamLinesProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n /** Send the shown stretches along their lines: a whole number runs each line that many times over. */\r\n @command({ args: [\"phase\"] })\r\n flowTo(args: CommandArgs<{ phase: number }> & { duration: number }): Command<StreamLinesProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n protected own(): string {\r\n return `${this.spacing}|${this.length}|${this.window}|${this.phase}`;\r\n }\r\n\r\n protected strokes(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(this.spacing, 1e-6);\r\n const count = () => (Math.floor((x1 - x0) / spacing) + 1) * (Math.floor((y1 - y0) / spacing) + 1);\r\n while (count() > MAX_LINES) spacing *= 2;\r\n const step = spacing / STEPS_PER_SPACING;\r\n const steps = Math.min(MAX_STEPS, Math.round(this.length / step));\r\n if (steps < 1) return [];\r\n // A line is followed a little past what is shown, so it leaves the box rather than stopping at its edge.\r\n const inside = (x: number, y: number) => x >= x0 - spacing && x <= x1 + spacing && y >= y0 - spacing && y <= y1 + spacing;\r\n const window = clamp(this.window, 0, 1);\r\n\r\n const drawn: FieldStroke[] = [];\r\n let index = 0;\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 line = follow(field, i * spacing, j * spacing, step, steps, inside);\r\n index++;\r\n if (line.points.length < 2) continue;\r\n const shown = window >= 1 ? line.points : stretch(line.points, window, this.phase + stagger(index));\r\n if (shown.length < 2) continue;\r\n drawn.push({ runs: [shown.map((p) => map.toPoint(p.x, p.y))], magnitude: line.magnitude });\r\n }\r\n }\r\n return drawn;\r\n }\r\n}\r\n\r\n/** The graph points a field carries a point through from `(x, y)`, at an even pace, and how strong it was on the way. */\r\nfunction follow(\r\n field: FieldSampler,\r\n x: number,\r\n y: number,\r\n step: number,\r\n steps: number,\r\n inside: (x: number, y: number) => boolean,\r\n): { points: Vector2[]; magnitude: number } {\r\n const points: Vector2[] = [{ x, y }];\r\n const v: Vector2 = { x: 0, y: 0 };\r\n let strength = 0;\r\n let read = 0;\r\n // The field's direction at a point, as a unit step; `false` where it has none or is at rest.\r\n const heading = (px: number, py: number, out: Vector2): boolean => {\r\n if (!field(px, py, v)) return false;\r\n const magnitude = Math.hypot(v.x, v.y);\r\n if (!(magnitude > 1e-9)) return false;\r\n out.x = v.x / magnitude;\r\n out.y = v.y / magnitude;\r\n strength += magnitude;\r\n read++;\r\n return true;\r\n };\r\n const a: Vector2 = { x: 0, y: 0 };\r\n const b: Vector2 = { x: 0, y: 0 };\r\n for (let i = 0; i < steps; i++) {\r\n // Midpoint rule: the direction half a step on is the one the whole step takes.\r\n if (!heading(x, y, a) || !heading(x + (a.x * step) / 2, y + (a.y * step) / 2, b)) break;\r\n x += b.x * step;\r\n y += b.y * step;\r\n if (!inside(x, y)) break;\r\n points.push({ x, y });\r\n }\r\n return { points, magnitude: read > 0 ? strength / read : 0 };\r\n}\r\n\r\n/** The part of `points` a window `share` long shows at `phase`: it enters at one end and leaves by the other. */\r\nfunction stretch(points: Vector2[], share: number, phase: number): Vector2[] {\r\n const turn = phase - Math.floor(phase);\r\n const end = turn * (1 + share);\r\n const from = Math.max(0, end - share);\r\n const to = Math.min(1, end);\r\n if (!(to > from)) return [];\r\n const last = points.length - 1;\r\n return points.slice(Math.floor(from * last), Math.ceil(to * last) + 1);\r\n}\r\n\r\n/** A share of a turn that differs from line to line and never from frame to frame, so the stretches do not march in step. */\r\nfunction stagger(index: number): number {\r\n const mixed = Math.sin(index * 12.9898) * 43758.5453;\r\n return mixed - Math.floor(mixed);\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"stream-lines.js","sourceRoot":"","sources":["../../src/plots/stream-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,KAAK,GAYR,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAA6F,MAAM,mBAAmB,CAAC;AAClL,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AASzE,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,6EAA6E;AAC7E,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,MAAM,KAAK,GAAG;IACV,GAAG,WAAW;IACd,qDAAqD;IACrD,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAClD,gFAAgF;IAChF,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAC9C,yEAAyE;IACzE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC1D,kGAAkG;IAClG,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;CACzC,CAAC;AASF,MAAM,KAAK,GAA8B;IACrC,GAAG,E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G,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,6HAA6H;AAC7H,SAAS,OAAO,CAAC,KAAa;IAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,UAAU,CAAC;IACrD,OAAO,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACrC,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 FieldSampler, type FieldStroke, type FieldValues } from \"../kit/field-mark\";\r\nimport { PLOT_COLOR } from \"../kit/furniture\";\r\nimport { clamp } from \"../kit/geometry\";\r\nimport { inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\r\n\r\nexport interface StreamLinesProps extends FieldProps {\r\n spacing?: number;\r\n length?: number;\r\n window?: number;\r\n phase?: number;\r\n}\r\n\r\nconst MAX_LINES = 1600;\r\n/** Steps a line takes across one spacing: what keeps a tight swirl round. */\r\nconst STEPS_PER_SPACING = 8;\r\nconst MAX_STEPS = 600;\r\n\r\nconst state = {\r\n ...FIELD_STATE,\r\n /** How far apart the lines start, in graph units. */\r\n spacing: Types.number(1, { min: 0.01, step: 0.1 }),\r\n /** How far each line runs from where it starts, in graph units along itself. */\r\n length: Types.number(3, { min: 0, step: 0.1 }),\r\n /** The share of each line that is shown at once; one shows all of it. */\r\n window: Types.number(1, { min: 0.01, max: 1, step: 0.01 }),\r\n /** Where along its line each shown stretch is: one turn of it runs every line from end to end. */\r\n phase: Types.number(0, { step: 0.01 }),\r\n};\r\n\r\ninterface LinesValues extends FieldValues {\r\n readonly spacing: number;\r\n readonly length: number;\r\n readonly window: number;\r\n readonly phase: number;\r\n}\r\n\r\nconst LINES: FieldDrawing<LinesValues> = {\r\n own: (s) => `${s.spacing}|${s.length}|${s.window}|${s.phase}`,\r\n strokes: (s, map, field) => lines(s, map, field),\r\n};\r\n\r\nconst traceLines = (s: LinesValues, read: MarkReading) => traceField(\"streamLines\", LINES, s, read);\r\n\r\n/**\r\n * The lines a vector field carries a point along, one from each point of a\r\n * grid: `(-y, x)` draws circles. With a `window` below one, each line shows\r\n * only a stretch of itself, and `flowTo` sends those stretches along.\r\n */\r\nexport const StreamLines = traced(component2d({\r\n key: \"streamLines\",\r\n state,\r\n defaults: { stroke: { weight: 2, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\r\n commands: {\r\n ...FIELD_COMMANDS,\r\n /** Send the shown stretches along their lines: a whole number runs each line that many times over. */\r\n flowTo: { args: [\"phase\"] },\r\n },\r\n measure: (_measurer, s) => inkSize(traceLines(s, reading(s)).runs),\r\n render: (ctx, s) => drawField(ctx, s, traceLines(s, reading(s))),\r\n}), (s: LinesValues, read: MarkReading) => traceLines(s, read).runs);\r\n\r\nexport type StreamLines = NodeOf<typeof StreamLines>;\r\n\r\nfunction lines(s: LinesValues, 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_LINES) spacing *= 2;\r\n const step = spacing / STEPS_PER_SPACING;\r\n const steps = Math.min(MAX_STEPS, Math.round(s.length / step));\r\n if (steps < 1) return [];\r\n // A line is followed a little past what is shown, so it leaves the box rather than stopping at its edge.\r\n const inside = (x: number, y: number) => x >= x0 - spacing && x <= x1 + spacing && y >= y0 - spacing && y <= y1 + spacing;\r\n const window = clamp(s.window, 0, 1);\r\n\r\n const drawn: FieldStroke[] = [];\r\n let index = 0;\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 line = follow(field, i * spacing, j * spacing, step, steps, inside);\r\n index++;\r\n if (line.points.length < 2) continue;\r\n const shown = window >= 1 ? line.points : stretch(line.points, window, s.phase + stagger(index));\r\n if (shown.length < 2) continue;\r\n drawn.push({ runs: [shown.map((p) => map.toPoint(p.x, p.y))], magnitude: line.magnitude });\r\n }\r\n }\r\n return drawn;\r\n}\r\n\r\n/** The graph points a field carries a point through from `(x, y)`, at an even pace, and how strong it was on the way. */\r\nfunction follow(\r\n field: FieldSampler,\r\n x: number,\r\n y: number,\r\n step: number,\r\n steps: number,\r\n inside: (x: number, y: number) => boolean,\r\n): { points: Vector2[]; magnitude: number } {\r\n const points: Vector2[] = [{ x, y }];\r\n const v: Vector2 = { x: 0, y: 0 };\r\n let strength = 0;\r\n let read = 0;\r\n // The field's direction at a point, as a unit step; `false` where it has none or is at rest.\r\n const heading = (px: number, py: number, out: Vector2): boolean => {\r\n if (!field(px, py, v)) return false;\r\n const magnitude = Math.hypot(v.x, v.y);\r\n if (!(magnitude > 1e-9)) return false;\r\n out.x = v.x / magnitude;\r\n out.y = v.y / magnitude;\r\n strength += magnitude;\r\n read++;\r\n return true;\r\n };\r\n const a: Vector2 = { x: 0, y: 0 };\r\n const b: Vector2 = { x: 0, y: 0 };\r\n for (let i = 0; i < steps; i++) {\r\n // Midpoint rule: the direction half a step on is the one the whole step takes.\r\n if (!heading(x, y, a) || !heading(x + (a.x * step) / 2, y + (a.y * step) / 2, b)) break;\r\n x += b.x * step;\r\n y += b.y * step;\r\n if (!inside(x, y)) break;\r\n points.push({ x, y });\r\n }\r\n return { points, magnitude: read > 0 ? strength / read : 0 };\r\n}\r\n\r\n/** The part of `points` a window `share` long shows at `phase`: it enters at one end and leaves by the other. */\r\nfunction stretch(points: Vector2[], share: number, phase: number): Vector2[] {\r\n const turn = phase - Math.floor(phase);\r\n const end = turn * (1 + share);\r\n const from = Math.max(0, end - share);\r\n const to = Math.min(1, end);\r\n if (!(to > from)) return [];\r\n const last = points.length - 1;\r\n return points.slice(Math.floor(from * last), Math.ceil(to * last) + 1);\r\n}\r\n\r\n/** A share of a turn that differs from line to line and never from frame to frame, so the stretches do not march in step. */\r\nfunction stagger(index: number): number {\r\n const mixed = Math.sin(index * 12.9898) * 43758.5453;\r\n return mixed - Math.floor(mixed);\r\n}\r\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type NodeOf, 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
2
|
import type { Interval } from "../kit/coords.js";
|
|
3
|
-
import {
|
|
3
|
+
import { type FunctionPlotProps } from "./function-plot.js";
|
|
4
4
|
export interface TracedPathProps extends FunctionPlotProps {
|
|
5
5
|
from?: number;
|
|
6
6
|
value?: number;
|
|
@@ -12,20 +12,59 @@ export interface TracedPathProps extends FunctionPlotProps {
|
|
|
12
12
|
* (`"=[t]"`) and the trail grows as the variable is driven, or drive it with
|
|
13
13
|
* `traceTo`; a `tail` keeps only its most recent stretch.
|
|
14
14
|
*/
|
|
15
|
-
export declare
|
|
15
|
+
export declare const TracedPath: import("@motionscript/sdk").Component<"tracedPath", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
16
16
|
/** The value the trail starts at. */
|
|
17
|
-
from: number
|
|
17
|
+
from: import("@motionscript/sdk").Type<number, number, false>;
|
|
18
18
|
/** The value the point is at now: where the trail ends. */
|
|
19
|
-
value: number
|
|
19
|
+
value: import("@motionscript/sdk").Type<number, number, false>;
|
|
20
20
|
/** How much of the trail is kept, in the value's own units; zero keeps all of it. */
|
|
21
|
-
tail: number
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
tail: import("@motionscript/sdk").Type<number, number, false>;
|
|
22
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
23
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
24
|
+
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
25
|
+
expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
|
|
26
|
+
domain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
|
|
27
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
28
|
+
}>, {
|
|
29
|
+
readonly traceTo: readonly ["value"];
|
|
30
|
+
readonly strokeTo: readonly ["stroke"];
|
|
31
|
+
readonly shadowTo: readonly ["shadow"];
|
|
32
|
+
readonly morphTo: readonly ["expression"];
|
|
33
|
+
readonly paramsTo: readonly ["params"];
|
|
34
|
+
readonly domainTo: readonly ["domain"];
|
|
35
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
36
|
+
/** The value the trail starts at. */
|
|
37
|
+
from: import("@motionscript/sdk").Type<number, number, false>;
|
|
38
|
+
/** The value the point is at now: where the trail ends. */
|
|
39
|
+
value: import("@motionscript/sdk").Type<number, number, false>;
|
|
40
|
+
/** How much of the trail is kept, in the value's own units; zero keeps all of it. */
|
|
41
|
+
tail: import("@motionscript/sdk").Type<number, number, false>;
|
|
42
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
43
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
44
|
+
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
45
|
+
expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
|
|
46
|
+
domain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
|
|
47
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
48
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
49
|
+
/** The value the trail starts at. */
|
|
50
|
+
from: import("@motionscript/sdk").Type<number, number, false>;
|
|
51
|
+
/** The value the point is at now: where the trail ends. */
|
|
52
|
+
value: import("@motionscript/sdk").Type<number, number, false>;
|
|
53
|
+
/** How much of the trail is kept, in the value's own units; zero keeps all of it. */
|
|
54
|
+
tail: import("@motionscript/sdk").Type<number, number, false>;
|
|
55
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
56
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
57
|
+
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
58
|
+
expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
|
|
59
|
+
domain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
|
|
60
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
61
|
+
}>, {
|
|
62
|
+
readonly traceTo: readonly ["value"];
|
|
63
|
+
readonly strokeTo: readonly ["stroke"];
|
|
64
|
+
readonly shadowTo: readonly ["shadow"];
|
|
65
|
+
readonly morphTo: readonly ["expression"];
|
|
66
|
+
readonly paramsTo: readonly ["params"];
|
|
67
|
+
readonly domainTo: readonly ["domain"];
|
|
68
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
69
|
+
export type TracedPath = NodeOf<typeof TracedPath>;
|
|
31
70
|
//# sourceMappingURL=traced-path.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traced-path.d.ts","sourceRoot":"","sources":["../../src/plots/traced-path.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"traced-path.d.ts","sourceRoot":"","sources":["../../src/plots/traced-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,MAAM,EAEX,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,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAqD,KAAK,iBAAiB,EAAmB,MAAM,iBAAiB,CAAC;AAE7H,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAmBD;;;;;GAKG;AACH,eAAO,MAAM,UAAU;IApBnB,qCAAqC;;IAErC,2DAA2D;;IAE3D,qFAAqF;;;;;;;;;;;;;;;;IAJrF,qCAAqC;;IAErC,2DAA2D;;IAE3D,qFAAqF;;;;;;;;;IAJrF,qCAAqC;;IAErC,2DAA2D;;IAE3D,qFAAqF;;;;;;;;;;;;;;;2BA2B1E,CAAC;AAEhB,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC"}
|