@motionscript/math 0.0.0-stage → 0.1.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +110 -0
- package/LICENSE +201 -0
- package/NOTICE +48 -0
- package/README.md +385 -3
- package/dist/annotate/angle-mark.d.ts +46 -0
- package/dist/annotate/angle-mark.d.ts.map +1 -0
- package/dist/annotate/angle-mark.js +132 -0
- package/dist/annotate/angle-mark.js.map +1 -0
- package/dist/annotate/curly-brace.d.ts +46 -0
- package/dist/annotate/curly-brace.d.ts.map +1 -0
- package/dist/annotate/curly-brace.js +114 -0
- package/dist/annotate/curly-brace.js.map +1 -0
- package/dist/annotate/emphasis-mark.d.ts +20 -0
- package/dist/annotate/emphasis-mark.d.ts.map +1 -0
- package/dist/annotate/emphasis-mark.js +81 -0
- package/dist/annotate/emphasis-mark.js.map +1 -0
- package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
- package/dist/browser/chunks/chunk-3GJB6AVO.js +2 -0
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +7 -0
- package/dist/browser/chunks/chunk-D5WHCVBC.js +2 -0
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +7 -0
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +2 -0
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +7 -0
- package/dist/browser/chunks/mathjax-DNP3YRES.js +61 -0
- package/dist/browser/chunks/mathjax-DNP3YRES.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +30 -0
- package/dist/browser/tex.js +2 -0
- package/dist/browser/tex.js.map +7 -0
- package/dist/engine.d.ts +64 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +42 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/brace.d.ts +8 -0
- package/dist/kit/brace.d.ts.map +1 -0
- package/dist/kit/brace.js +36 -0
- package/dist/kit/brace.js.map +1 -0
- package/dist/kit/cache.d.ts +30 -0
- package/dist/kit/cache.d.ts.map +1 -0
- package/dist/kit/cache.js +53 -0
- package/dist/kit/cache.js.map +1 -0
- package/dist/kit/contour.d.ts +8 -0
- package/dist/kit/contour.d.ts.map +1 -0
- package/dist/kit/contour.js +93 -0
- package/dist/kit/contour.js.map +1 -0
- package/dist/kit/coords.d.ts +69 -0
- package/dist/kit/coords.d.ts.map +1 -0
- package/dist/kit/coords.js +224 -0
- package/dist/kit/coords.js.map +1 -0
- package/dist/kit/curve.d.ts +17 -0
- package/dist/kit/curve.d.ts.map +1 -0
- package/dist/kit/curve.js +22 -0
- package/dist/kit/curve.js.map +1 -0
- package/dist/kit/equation.d.ts +61 -0
- package/dist/kit/equation.d.ts.map +1 -0
- package/dist/kit/equation.js +168 -0
- package/dist/kit/equation.js.map +1 -0
- package/dist/kit/equation3d.d.ts +50 -0
- package/dist/kit/equation3d.d.ts.map +1 -0
- package/dist/kit/equation3d.js +103 -0
- package/dist/kit/equation3d.js.map +1 -0
- package/dist/kit/expression.d.ts +35 -0
- package/dist/kit/expression.d.ts.map +1 -0
- package/dist/kit/expression.js +124 -0
- package/dist/kit/expression.js.map +1 -0
- package/dist/kit/field-mark.d.ts +58 -0
- package/dist/kit/field-mark.d.ts.map +1 -0
- package/dist/kit/field-mark.js +129 -0
- package/dist/kit/field-mark.js.map +1 -0
- package/dist/kit/field.d.ts +14 -0
- package/dist/kit/field.d.ts.map +1 -0
- package/dist/kit/field.js +46 -0
- package/dist/kit/field.js.map +1 -0
- package/dist/kit/follow.d.ts +71 -0
- package/dist/kit/follow.d.ts.map +1 -0
- package/dist/kit/follow.js +159 -0
- package/dist/kit/follow.js.map +1 -0
- package/dist/kit/furniture.d.ts +30 -0
- package/dist/kit/furniture.d.ts.map +1 -0
- package/dist/kit/furniture.js +87 -0
- package/dist/kit/furniture.js.map +1 -0
- package/dist/kit/geometry.d.ts +13 -0
- package/dist/kit/geometry.d.ts.map +1 -0
- package/dist/kit/geometry.js +54 -0
- package/dist/kit/geometry.js.map +1 -0
- package/dist/kit/mark.d.ts +47 -0
- package/dist/kit/mark.d.ts.map +1 -0
- package/dist/kit/mark.js +103 -0
- package/dist/kit/mark.js.map +1 -0
- package/dist/kit/part-fills.d.ts +23 -0
- package/dist/kit/part-fills.d.ts.map +1 -0
- package/dist/kit/part-fills.js +46 -0
- package/dist/kit/part-fills.js.map +1 -0
- package/dist/kit/place.d.ts +18 -0
- package/dist/kit/place.d.ts.map +1 -0
- package/dist/kit/place.js +68 -0
- package/dist/kit/place.js.map +1 -0
- package/dist/kit/placement.d.ts +8 -0
- package/dist/kit/placement.d.ts.map +1 -0
- package/dist/kit/placement.js +8 -0
- package/dist/kit/placement.js.map +1 -0
- package/dist/kit/sampler.d.ts +17 -0
- package/dist/kit/sampler.d.ts.map +1 -0
- package/dist/kit/sampler.js +250 -0
- package/dist/kit/sampler.js.map +1 -0
- package/dist/kit/scale.d.ts +12 -0
- package/dist/kit/scale.d.ts.map +1 -0
- package/dist/kit/scale.js +37 -0
- package/dist/kit/scale.js.map +1 -0
- package/dist/kit/source.d.ts +22 -0
- package/dist/kit/source.d.ts.map +1 -0
- package/dist/kit/source.js +45 -0
- package/dist/kit/source.js.map +1 -0
- package/dist/kit/system.d.ts +33 -0
- package/dist/kit/system.d.ts.map +1 -0
- package/dist/kit/system.js +67 -0
- package/dist/kit/system.js.map +1 -0
- package/dist/kit/ticks.d.ts +19 -0
- package/dist/kit/ticks.d.ts.map +1 -0
- package/dist/kit/ticks.js +78 -0
- package/dist/kit/ticks.js.map +1 -0
- package/dist/kit/withdrawn.d.ts +9 -0
- package/dist/kit/withdrawn.d.ts.map +1 -0
- package/dist/kit/withdrawn.js +9 -0
- package/dist/kit/withdrawn.js.map +1 -0
- package/dist/marks/curve-area.d.ts +32 -0
- package/dist/marks/curve-area.d.ts.map +1 -0
- package/dist/marks/curve-area.js +82 -0
- package/dist/marks/curve-area.js.map +1 -0
- package/dist/marks/drop-lines.d.ts +22 -0
- package/dist/marks/drop-lines.d.ts.map +1 -0
- package/dist/marks/drop-lines.js +58 -0
- package/dist/marks/drop-lines.js.map +1 -0
- package/dist/marks/plot-point.d.ts +35 -0
- package/dist/marks/plot-point.d.ts.map +1 -0
- package/dist/marks/plot-point.js +97 -0
- package/dist/marks/plot-point.js.map +1 -0
- package/dist/marks/riemann-sum.d.ts +37 -0
- package/dist/marks/riemann-sum.d.ts.map +1 -0
- package/dist/marks/riemann-sum.js +91 -0
- package/dist/marks/riemann-sum.js.map +1 -0
- package/dist/marks/tangent-line.d.ts +27 -0
- package/dist/marks/tangent-line.d.ts.map +1 -0
- package/dist/marks/tangent-line.js +103 -0
- package/dist/marks/tangent-line.js.map +1 -0
- package/dist/marks/vector-arrow.d.ts +32 -0
- package/dist/marks/vector-arrow.d.ts.map +1 -0
- package/dist/marks/vector-arrow.js +87 -0
- package/dist/marks/vector-arrow.js.map +1 -0
- package/dist/nodes.d.ts +35 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +63 -0
- package/dist/nodes.js.map +1 -0
- package/dist/plots/function-plot.d.ts +67 -0
- package/dist/plots/function-plot.d.ts.map +1 -0
- package/dist/plots/function-plot.js +215 -0
- package/dist/plots/function-plot.js.map +1 -0
- package/dist/plots/points-plot.d.ts +28 -0
- package/dist/plots/points-plot.d.ts.map +1 -0
- package/dist/plots/points-plot.js +99 -0
- package/dist/plots/points-plot.js.map +1 -0
- package/dist/plots/stream-lines.d.ts +35 -0
- package/dist/plots/stream-lines.d.ts.map +1 -0
- package/dist/plots/stream-lines.js +141 -0
- package/dist/plots/stream-lines.js.map +1 -0
- package/dist/plots/traced-path.d.ts +31 -0
- package/dist/plots/traced-path.d.ts.map +1 -0
- package/dist/plots/traced-path.js +56 -0
- package/dist/plots/traced-path.js.map +1 -0
- package/dist/plots/vector-field.d.ts +23 -0
- package/dist/plots/vector-field.d.ts.map +1 -0
- package/dist/plots/vector-field.js +91 -0
- package/dist/plots/vector-field.js.map +1 -0
- package/dist/structures/graph-layout.d.ts +11 -0
- package/dist/structures/graph-layout.d.ts.map +1 -0
- package/dist/structures/graph-layout.js +135 -0
- package/dist/structures/graph-layout.js.map +1 -0
- package/dist/structures/network-graph.d.ts +83 -0
- package/dist/structures/network-graph.d.ts.map +1 -0
- package/dist/structures/network-graph.js +289 -0
- package/dist/structures/network-graph.js.map +1 -0
- package/dist/structures/sample-space.d.ts +62 -0
- package/dist/structures/sample-space.d.ts.map +1 -0
- package/dist/structures/sample-space.js +199 -0
- package/dist/structures/sample-space.js.map +1 -0
- package/dist/systems/axes2d.d.ts +75 -0
- package/dist/systems/axes2d.d.ts.map +1 -0
- package/dist/systems/axes2d.js +193 -0
- package/dist/systems/axes2d.js.map +1 -0
- package/dist/systems/number-line.d.ts +49 -0
- package/dist/systems/number-line.d.ts.map +1 -0
- package/dist/systems/number-line.js +127 -0
- package/dist/systems/number-line.js.map +1 -0
- package/dist/systems/number-plane.d.ts +59 -0
- package/dist/systems/number-plane.d.ts.map +1 -0
- package/dist/systems/number-plane.js +193 -0
- package/dist/systems/number-plane.js.map +1 -0
- package/dist/systems/polar-plane.d.ts +48 -0
- package/dist/systems/polar-plane.d.ts.map +1 -0
- package/dist/systems/polar-plane.js +165 -0
- package/dist/systems/polar-plane.js.map +1 -0
- package/dist/tex/geometry.d.ts +85 -0
- package/dist/tex/geometry.d.ts.map +1 -0
- package/dist/tex/geometry.js +632 -0
- package/dist/tex/geometry.js.map +1 -0
- package/dist/tex/index.d.ts +11 -0
- package/dist/tex/index.d.ts.map +1 -0
- package/dist/tex/index.js +9 -0
- package/dist/tex/index.js.map +1 -0
- package/dist/tex/mathjax.d.ts +33 -0
- package/dist/tex/mathjax.d.ts.map +1 -0
- package/dist/tex/mathjax.js +74 -0
- package/dist/tex/mathjax.js.map +1 -0
- package/dist/tex/matrix.d.ts +31 -0
- package/dist/tex/matrix.d.ts.map +1 -0
- package/dist/tex/matrix.js +73 -0
- package/dist/tex/matrix.js.map +1 -0
- package/dist/tex/node.d.ts +215 -0
- package/dist/tex/node.d.ts.map +1 -0
- package/dist/tex/node.js +595 -0
- package/dist/tex/node.js.map +1 -0
- package/dist/tex/tween.d.ts +50 -0
- package/dist/tex/tween.d.ts.map +1 -0
- package/dist/tex/tween.js +253 -0
- package/dist/tex/tween.js.map +1 -0
- package/dist/three/axes3d.d.ts +87 -0
- package/dist/three/axes3d.d.ts.map +1 -0
- package/dist/three/axes3d.js +228 -0
- package/dist/three/axes3d.js.map +1 -0
- package/dist/three/curve-plot3d.d.ts +60 -0
- package/dist/three/curve-plot3d.d.ts.map +1 -0
- package/dist/three/curve-plot3d.js +143 -0
- package/dist/three/curve-plot3d.js.map +1 -0
- package/dist/three/label3d.d.ts +11 -0
- package/dist/three/label3d.d.ts.map +1 -0
- package/dist/three/label3d.js +40 -0
- package/dist/three/label3d.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +26 -0
- package/dist/three/plot-point3d.d.ts.map +1 -0
- package/dist/three/plot-point3d.js +60 -0
- package/dist/three/plot-point3d.js.map +1 -0
- package/dist/three/space.d.ts +28 -0
- package/dist/three/space.d.ts.map +1 -0
- package/dist/three/space.js +47 -0
- package/dist/three/space.js.map +1 -0
- package/dist/three/surface-plot3d.d.ts +80 -0
- package/dist/three/surface-plot3d.d.ts.map +1 -0
- package/dist/three/surface-plot3d.js +290 -0
- package/dist/three/surface-plot3d.js.map +1 -0
- package/dist/three/vector-arrow3d.d.ts +25 -0
- package/dist/three/vector-arrow3d.d.ts.map +1 -0
- package/dist/three/vector-arrow3d.js +72 -0
- package/dist/three/vector-arrow3d.js.map +1 -0
- package/package.json +79 -3
- package/registry.json +251 -0
- package/src/annotate/angle-mark.ts +147 -0
- package/src/annotate/curly-brace.ts +126 -0
- package/src/annotate/emphasis-mark.ts +89 -0
- package/src/engine.ts +72 -0
- package/src/index.ts +29 -0
- package/src/kit/brace.ts +37 -0
- package/src/kit/cache.ts +61 -0
- package/src/kit/contour.ts +94 -0
- package/src/kit/coords.ts +278 -0
- package/src/kit/curve.ts +29 -0
- package/src/kit/equation.ts +181 -0
- package/src/kit/equation3d.ts +137 -0
- package/src/kit/expression.ts +159 -0
- package/src/kit/field-mark.ts +155 -0
- package/src/kit/field.ts +50 -0
- package/src/kit/follow.ts +203 -0
- package/src/kit/furniture.ts +108 -0
- package/src/kit/geometry.ts +49 -0
- package/src/kit/mark.ts +131 -0
- package/src/kit/part-fills.ts +61 -0
- package/src/kit/place.ts +101 -0
- package/src/kit/placement.ts +8 -0
- package/src/kit/sampler.ts +281 -0
- package/src/kit/scale.ts +39 -0
- package/src/kit/source.ts +57 -0
- package/src/kit/system.ts +99 -0
- package/src/kit/ticks.ts +85 -0
- package/src/kit/withdrawn.ts +8 -0
- package/src/marks/curve-area.ts +89 -0
- package/src/marks/drop-lines.ts +63 -0
- package/src/marks/plot-point.ts +107 -0
- package/src/marks/riemann-sum.ts +98 -0
- package/src/marks/tangent-line.ts +103 -0
- package/src/marks/vector-arrow.ts +98 -0
- package/src/nodes.ts +63 -0
- package/src/plots/function-plot.ts +236 -0
- package/src/plots/points-plot.ts +107 -0
- package/src/plots/stream-lines.ts +151 -0
- package/src/plots/traced-path.ts +52 -0
- package/src/plots/vector-field.ts +88 -0
- package/src/structures/graph-layout.ts +145 -0
- package/src/structures/network-graph.ts +308 -0
- package/src/structures/sample-space.ts +209 -0
- package/src/systems/axes2d.ts +217 -0
- package/src/systems/number-line.ts +131 -0
- package/src/systems/number-plane.ts +203 -0
- package/src/systems/polar-plane.ts +176 -0
- package/src/tex/geometry.ts +703 -0
- package/src/tex/index.ts +14 -0
- package/src/tex/mathjax.ts +82 -0
- package/src/tex/matrix.ts +75 -0
- package/src/tex/node.ts +641 -0
- package/src/tex/tween.ts +308 -0
- package/src/three/axes3d.ts +240 -0
- package/src/three/curve-plot3d.ts +147 -0
- package/src/three/label3d.ts +50 -0
- package/src/three/plot-point3d.ts +66 -0
- package/src/three/space.ts +67 -0
- package/src/three/surface-plot3d.ts +323 -0
- package/src/three/vector-arrow3d.ts +77 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/** Skia's path coordinates are 32-bit floats; past this a clamped point still clips to the same edge. */
|
|
2
|
+
const COORD_LIMIT = 16_000;
|
|
3
|
+
/** How far, in pixels, the drawn chord may stray from the curve. */
|
|
4
|
+
const TOLERANCE_PX = 0.25;
|
|
5
|
+
/** A turn, in radians, a chord is allowed to hide: what keeps a symmetric bump from reading as flat. */
|
|
6
|
+
const ANGLE_TOLERANCE = 0.05;
|
|
7
|
+
const MAX_DEPTH = 12;
|
|
8
|
+
const MAX_EVALUATIONS = 40_000;
|
|
9
|
+
const MAX_POINTS = 24_000;
|
|
10
|
+
/** Bisections spent finding where a domain ends. */
|
|
11
|
+
const BOUNDARY_STEPS = 60;
|
|
12
|
+
const DEFAULT_SEEDS = 256;
|
|
13
|
+
// Midpoints are pooled: a refine is a depth-first walk, so a slot is free again
|
|
14
|
+
// as soon as the seed interval it was taken for is done.
|
|
15
|
+
const arena = [];
|
|
16
|
+
let arenaMark = 0;
|
|
17
|
+
function takeSample() {
|
|
18
|
+
let slot = arena[arenaMark];
|
|
19
|
+
if (slot === undefined) {
|
|
20
|
+
slot = blank();
|
|
21
|
+
arena.push(slot);
|
|
22
|
+
}
|
|
23
|
+
arenaMark++;
|
|
24
|
+
return slot;
|
|
25
|
+
}
|
|
26
|
+
function blank() {
|
|
27
|
+
return { t: 0, px: 0, py: 0, rx: 0, ry: 0, ok: false };
|
|
28
|
+
}
|
|
29
|
+
const scratch = { x: 0, y: 0 };
|
|
30
|
+
/** The runs of points that draw `project` over `[t0, t1]`, clipped to `clip`. */
|
|
31
|
+
export function sampleCurve(project, t0, t1, clip, { seeds = DEFAULT_SEEDS, minStep = 0 } = {}) {
|
|
32
|
+
if (!(t1 > t0) || !Number.isFinite(t0) || !Number.isFinite(t1))
|
|
33
|
+
return [];
|
|
34
|
+
const pen = new CurvePen(clip);
|
|
35
|
+
let spent = 0;
|
|
36
|
+
const write = (slot, t) => {
|
|
37
|
+
const defined = project(t, scratch);
|
|
38
|
+
spent++;
|
|
39
|
+
const ok = defined && Number.isFinite(scratch.x) && Number.isFinite(scratch.y);
|
|
40
|
+
slot.t = t;
|
|
41
|
+
slot.rx = ok ? scratch.x : 0;
|
|
42
|
+
slot.ry = ok ? scratch.y : 0;
|
|
43
|
+
slot.px = clampCoord(slot.rx);
|
|
44
|
+
slot.py = clampCoord(slot.ry);
|
|
45
|
+
slot.ok = ok;
|
|
46
|
+
return slot;
|
|
47
|
+
};
|
|
48
|
+
const at = (t) => write(takeSample(), t);
|
|
49
|
+
// The last defined point before `to`, which is not: where `sqrt(x)` meets its axis.
|
|
50
|
+
const edgeOf = (from, to) => {
|
|
51
|
+
let inside = from;
|
|
52
|
+
let outsideT = to.t;
|
|
53
|
+
for (let i = 0; i < BOUNDARY_STEPS; i++) {
|
|
54
|
+
if (spent >= MAX_EVALUATIONS || offFrame(inside, clip))
|
|
55
|
+
break;
|
|
56
|
+
const midT = (inside.t + outsideT) / 2;
|
|
57
|
+
if (midT === inside.t || midT === outsideT)
|
|
58
|
+
break;
|
|
59
|
+
const mid = at(midT);
|
|
60
|
+
if (!mid.ok) {
|
|
61
|
+
outsideT = midT;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const settled = Math.abs(mid.px - inside.px) < TOLERANCE_PX && Math.abs(mid.py - inside.py) < TOLERANCE_PX;
|
|
65
|
+
inside = mid;
|
|
66
|
+
if (settled)
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
return inside;
|
|
70
|
+
};
|
|
71
|
+
const emit = (a, m, b, floored) => {
|
|
72
|
+
if (a.ok && b.ok) {
|
|
73
|
+
if (floored && diverges(a, m, b, clip))
|
|
74
|
+
pen.break();
|
|
75
|
+
else
|
|
76
|
+
pen.draw(a, b);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (a.ok) {
|
|
80
|
+
const edge = edgeOf(a, b);
|
|
81
|
+
if (edge.t !== a.t)
|
|
82
|
+
pen.draw(a, edge);
|
|
83
|
+
pen.break();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
pen.break();
|
|
87
|
+
if (b.ok) {
|
|
88
|
+
const edge = edgeOf(b, a);
|
|
89
|
+
if (edge.t !== b.t)
|
|
90
|
+
pen.draw(edge, b);
|
|
91
|
+
else
|
|
92
|
+
pen.start(b);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const refine = (a, b, depth) => {
|
|
96
|
+
if (spent >= MAX_EVALUATIONS || pen.points >= MAX_POINTS) {
|
|
97
|
+
emit(a, null, b, false);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const m = at((a.t + b.t) / 2);
|
|
101
|
+
const floored = depth >= MAX_DEPTH || b.t - a.t <= minStep;
|
|
102
|
+
if (floored || flat(a, m, b)) {
|
|
103
|
+
emit(a, m, b, floored);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
refine(a, m, depth + 1);
|
|
107
|
+
refine(m, b, depth + 1);
|
|
108
|
+
};
|
|
109
|
+
const count = Math.max(1, Math.round(seeds));
|
|
110
|
+
const step = (t1 - t0) / count;
|
|
111
|
+
const ends = [blank(), blank()];
|
|
112
|
+
let previous = write(ends[0], t0);
|
|
113
|
+
for (let i = 1; i <= count; i++) {
|
|
114
|
+
const next = write(ends[i & 1], i === count ? t1 : t0 + i * step);
|
|
115
|
+
arenaMark = 0;
|
|
116
|
+
refine(previous, next, 0);
|
|
117
|
+
previous = next;
|
|
118
|
+
}
|
|
119
|
+
arenaMark = 0;
|
|
120
|
+
return pen.finish();
|
|
121
|
+
}
|
|
122
|
+
function flat(a, m, b) {
|
|
123
|
+
if (a.ok !== m.ok || m.ok !== b.ok)
|
|
124
|
+
return false;
|
|
125
|
+
if (!a.ok)
|
|
126
|
+
return true;
|
|
127
|
+
const dx = b.px - a.px;
|
|
128
|
+
const dy = b.py - a.py;
|
|
129
|
+
const length = Math.hypot(dx, dy) || 1;
|
|
130
|
+
if (Math.abs((m.px - a.px) * dy - (m.py - a.py) * dx) / length > TOLERANCE_PX)
|
|
131
|
+
return false;
|
|
132
|
+
let turn = Math.abs(Math.atan2(m.py - a.py, m.px - a.px) - Math.atan2(b.py - m.py, b.px - m.px));
|
|
133
|
+
if (turn > Math.PI)
|
|
134
|
+
turn = 2 * Math.PI - turn;
|
|
135
|
+
return turn < ANGLE_TOLERANCE;
|
|
136
|
+
}
|
|
137
|
+
// Two neighbours on opposite sides of the frame, with nothing between them that
|
|
138
|
+
// is between them: an asymptote, not a steep line.
|
|
139
|
+
function diverges(a, m, b, clip) {
|
|
140
|
+
const straddles = (a.py > clip.maxY && b.py < clip.minY) || (a.py < clip.minY && b.py > clip.maxY) ||
|
|
141
|
+
(a.px > clip.maxX && b.px < clip.minX) || (a.px < clip.minX && b.px > clip.maxX);
|
|
142
|
+
if (!straddles || m === null)
|
|
143
|
+
return false;
|
|
144
|
+
if (!m.ok)
|
|
145
|
+
return true;
|
|
146
|
+
return (m.ry < Math.min(a.ry, b.ry) || m.ry > Math.max(a.ry, b.ry) ||
|
|
147
|
+
m.rx < Math.min(a.rx, b.rx) || m.rx > Math.max(a.rx, b.rx));
|
|
148
|
+
}
|
|
149
|
+
function offFrame(sample, clip) {
|
|
150
|
+
return sample.py > clip.maxY || sample.py < clip.minY || sample.px > clip.maxX || sample.px < clip.minX;
|
|
151
|
+
}
|
|
152
|
+
function clampCoord(value) {
|
|
153
|
+
if (value > COORD_LIMIT)
|
|
154
|
+
return COORD_LIMIT;
|
|
155
|
+
if (value < -COORD_LIMIT)
|
|
156
|
+
return -COORD_LIMIT;
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
class CurvePen {
|
|
160
|
+
clip;
|
|
161
|
+
points = 0;
|
|
162
|
+
runs = [];
|
|
163
|
+
open = [];
|
|
164
|
+
cursor = null;
|
|
165
|
+
constructor(clip) {
|
|
166
|
+
this.clip = clip;
|
|
167
|
+
}
|
|
168
|
+
draw(a, b) {
|
|
169
|
+
const segment = clipSegment(a.px, a.py, b.px, b.py, this.clip);
|
|
170
|
+
if (!segment) {
|
|
171
|
+
this.break();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const [start, end] = segment;
|
|
175
|
+
if (this.cursor && samePoint(this.cursor, start)) {
|
|
176
|
+
this.push(end);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.break();
|
|
180
|
+
this.push(start);
|
|
181
|
+
this.push(end);
|
|
182
|
+
}
|
|
183
|
+
this.cursor = end;
|
|
184
|
+
}
|
|
185
|
+
start(b) {
|
|
186
|
+
this.break();
|
|
187
|
+
if (!inside(b.px, b.py, this.clip))
|
|
188
|
+
return;
|
|
189
|
+
this.cursor = { x: b.px, y: b.py };
|
|
190
|
+
this.push(this.cursor);
|
|
191
|
+
}
|
|
192
|
+
break() {
|
|
193
|
+
if (this.open.length >= 2)
|
|
194
|
+
this.runs.push(this.open);
|
|
195
|
+
this.open = [];
|
|
196
|
+
this.cursor = null;
|
|
197
|
+
}
|
|
198
|
+
finish() {
|
|
199
|
+
this.break();
|
|
200
|
+
return this.runs;
|
|
201
|
+
}
|
|
202
|
+
push(point) {
|
|
203
|
+
this.open.push(point);
|
|
204
|
+
this.points++;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function samePoint(a, b) {
|
|
208
|
+
return Math.abs(a.x - b.x) < 0.1 && Math.abs(a.y - b.y) < 0.1;
|
|
209
|
+
}
|
|
210
|
+
function inside(x, y, clip) {
|
|
211
|
+
return x >= clip.minX && x <= clip.maxX && y >= clip.minY && y <= clip.maxY;
|
|
212
|
+
}
|
|
213
|
+
// Liang–Barsky: the part of a segment inside the clip, or null when none is.
|
|
214
|
+
function clipSegment(ax, ay, bx, by, clip) {
|
|
215
|
+
const dx = bx - ax;
|
|
216
|
+
const dy = by - ay;
|
|
217
|
+
let t0 = 0;
|
|
218
|
+
let t1 = 1;
|
|
219
|
+
const edges = [
|
|
220
|
+
[-dx, ax - clip.minX],
|
|
221
|
+
[dx, clip.maxX - ax],
|
|
222
|
+
[-dy, ay - clip.minY],
|
|
223
|
+
[dy, clip.maxY - ay],
|
|
224
|
+
];
|
|
225
|
+
for (const [p, q] of edges) {
|
|
226
|
+
if (p === 0) {
|
|
227
|
+
if (q < 0)
|
|
228
|
+
return null;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const r = q / p;
|
|
232
|
+
if (p < 0) {
|
|
233
|
+
if (r > t1)
|
|
234
|
+
return null;
|
|
235
|
+
if (r > t0)
|
|
236
|
+
t0 = r;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
if (r < t0)
|
|
240
|
+
return null;
|
|
241
|
+
if (r < t1)
|
|
242
|
+
t1 = r;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return [
|
|
246
|
+
{ x: ax + t0 * dx, y: ay + t0 * dy },
|
|
247
|
+
{ x: ax + t1 * dx, y: ay + t1 * dy },
|
|
248
|
+
];
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=sampler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sampler.js","sourceRoot":"","sources":["../../src/kit/sampler.ts"],"names":[],"mappings":"AAkBA,yGAAyG;AACzG,MAAM,WAAW,GAAG,MAAM,CAAC;AAC3B,oEAAoE;AACpE,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,wGAAwG;AACxG,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,oDAAoD;AACpD,MAAM,cAAc,GAAG,EAAE,CAAC;A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AAG,EAAE,CAAC;KACvB,CAAC;IACF,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACV,IAAI,CAAC,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;YACvB,SAAS;QACb,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACR,IAAI,CAAC,GAAG,EAAE;gBAAE,OAAO,IAAI,CAAC;YACxB,IAAI,CAAC,GAAG,EAAE;gBAAE,EAAE,GAAG,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,GAAG,EAAE;gBAAE,OAAO,IAAI,CAAC;YACxB,IAAI,CAAC,GAAG,EAAE;gBAAE,EAAE,GAAG,CAAC,CAAC;QACvB,CAAC;IACL,CAAC;IACD,OAAO;QACH,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QACpC,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;KACvC,CAAC;AACN,CAAC","sourcesContent":["import type { Extents, Vector2 } from \"@motionscript/sdk\";\r\n\r\n/**\r\n * Turns a curve into the polylines that draw it: adaptively, so a straight\r\n * stretch costs two points and a tight bend as many as it needs, and broken\r\n * wherever the curve is, at an asymptote or the edge of its domain.\r\n */\r\n\r\n/** A curve's parameter to its pixel, written into `out`. `false` where the curve is undefined. */\r\nexport type CurveProjection = (t: number, out: Vector2) => boolean;\r\n\r\nexport interface SampleOptions {\r\n /** The equal steps the parameter range starts as, before any is split. */\r\n seeds?: number;\r\n /** A parameter step that is not split again, however bent. */\r\n minStep?: number;\r\n}\r\n\r\n/** Skia's path coordinates are 32-bit floats; past this a clamped point still clips to the same edge. */\r\nconst COORD_LIMIT = 16_000;\r\n/** How far, in pixels, the drawn chord may stray from the curve. */\r\nconst TOLERANCE_PX = 0.25;\r\n/** A turn, in radians, a chord is allowed to hide: what keeps a symmetric bump from reading as flat. */\r\nconst ANGLE_TOLERANCE = 0.05;\r\nconst MAX_DEPTH = 12;\r\nconst MAX_EVALUATIONS = 40_000;\r\nconst MAX_POINTS = 24_000;\r\n/** Bisections spent finding where a domain ends. */\r\nconst BOUNDARY_STEPS = 60;\r\nconst DEFAULT_SEEDS = 256;\r\n\r\ninterface Sample {\r\n t: number;\r\n px: number;\r\n py: number;\r\n /** The pixel before clamping: what tells an asymptote from a steep line. */\r\n rx: number;\r\n ry: number;\r\n ok: boolean;\r\n}\r\n\r\n// Midpoints are pooled: a refine is a depth-first walk, so a slot is free again\r\n// as soon as the seed interval it was taken for is done.\r\nconst arena: Sample[] = [];\r\nlet arenaMark = 0;\r\n\r\nfunction takeSample(): Sample {\r\n let slot = arena[arenaMark];\r\n if (slot === undefined) {\r\n slot = blank();\r\n arena.push(slot);\r\n }\r\n arenaMark++;\r\n return slot;\r\n}\r\n\r\nfunction blank(): Sample {\r\n return { t: 0, px: 0, py: 0, rx: 0, ry: 0, ok: false };\r\n}\r\n\r\nconst scratch: Vector2 = { x: 0, y: 0 };\r\n\r\n/** The runs of points that draw `project` over `[t0, t1]`, clipped to `clip`. */\r\nexport function sampleCurve(\r\n project: CurveProjection,\r\n t0: number,\r\n t1: number,\r\n clip: Extents,\r\n { seeds = DEFAULT_SEEDS, minStep = 0 }: SampleOptions = {},\r\n): Vector2[][] {\r\n if (!(t1 > t0) || !Number.isFinite(t0) || !Number.isFinite(t1)) return [];\r\n const pen = new CurvePen(clip);\r\n let spent = 0;\r\n\r\n const write = (slot: Sample, t: number): Sample => {\r\n const defined = project(t, scratch);\r\n spent++;\r\n const ok = defined && Number.isFinite(scratch.x) && Number.isFinite(scratch.y);\r\n slot.t = t;\r\n slot.rx = ok ? scratch.x : 0;\r\n slot.ry = ok ? scratch.y : 0;\r\n slot.px = clampCoord(slot.rx);\r\n slot.py = clampCoord(slot.ry);\r\n slot.ok = ok;\r\n return slot;\r\n };\r\n const at = (t: number): Sample => write(takeSample(), t);\r\n\r\n // The last defined point before `to`, which is not: where `sqrt(x)` meets its axis.\r\n const edgeOf = (from: Sample, to: Sample): Sample => {\r\n let inside = from;\r\n let outsideT = to.t;\r\n for (let i = 0; i < BOUNDARY_STEPS; i++) {\r\n if (spent >= MAX_EVALUATIONS || offFrame(inside, clip)) break;\r\n const midT = (inside.t + outsideT) / 2;\r\n if (midT === inside.t || midT === outsideT) break;\r\n const mid = at(midT);\r\n if (!mid.ok) {\r\n outsideT = midT;\r\n continue;\r\n }\r\n const settled = Math.abs(mid.px - inside.px) < TOLERANCE_PX && Math.abs(mid.py - inside.py) < TOLERANCE_PX;\r\n inside = mid;\r\n if (settled) break;\r\n }\r\n return inside;\r\n };\r\n\r\n const emit = (a: Sample, m: Sample | null, b: Sample, floored: boolean): void => {\r\n if (a.ok && b.ok) {\r\n if (floored && diverges(a, m, b, clip)) pen.break();\r\n else pen.draw(a, b);\r\n return;\r\n }\r\n if (a.ok) {\r\n const edge = edgeOf(a, b);\r\n if (edge.t !== a.t) pen.draw(a, edge);\r\n pen.break();\r\n return;\r\n }\r\n pen.break();\r\n if (b.ok) {\r\n const edge = edgeOf(b, a);\r\n if (edge.t !== b.t) pen.draw(edge, b);\r\n else pen.start(b);\r\n }\r\n };\r\n\r\n const refine = (a: Sample, b: Sample, depth: number): void => {\r\n if (spent >= MAX_EVALUATIONS || pen.points >= MAX_POINTS) {\r\n emit(a, null, b, false);\r\n return;\r\n }\r\n const m = at((a.t + b.t) / 2);\r\n const floored = depth >= MAX_DEPTH || b.t - a.t <= minStep;\r\n if (floored || flat(a, m, b)) {\r\n emit(a, m, b, floored);\r\n return;\r\n }\r\n refine(a, m, depth + 1);\r\n refine(m, b, depth + 1);\r\n };\r\n\r\n const count = Math.max(1, Math.round(seeds));\r\n const step = (t1 - t0) / count;\r\n const ends: [Sample, Sample] = [blank(), blank()];\r\n let previous = write(ends[0], t0);\r\n for (let i = 1; i <= count; i++) {\r\n const next = write(ends[i & 1], i === count ? t1 : t0 + i * step);\r\n arenaMark = 0;\r\n refine(previous, next, 0);\r\n previous = next;\r\n }\r\n arenaMark = 0;\r\n return pen.finish();\r\n}\r\n\r\nfunction flat(a: Sample, m: Sample, b: Sample): boolean {\r\n if (a.ok !== m.ok || m.ok !== b.ok) return false;\r\n if (!a.ok) return true;\r\n const dx = b.px - a.px;\r\n const dy = b.py - a.py;\r\n const length = Math.hypot(dx, dy) || 1;\r\n if (Math.abs((m.px - a.px) * dy - (m.py - a.py) * dx) / length > TOLERANCE_PX) return false;\r\n let turn = Math.abs(Math.atan2(m.py - a.py, m.px - a.px) - Math.atan2(b.py - m.py, b.px - m.px));\r\n if (turn > Math.PI) turn = 2 * Math.PI - turn;\r\n return turn < ANGLE_TOLERANCE;\r\n}\r\n\r\n// Two neighbours on opposite sides of the frame, with nothing between them that\r\n// is between them: an asymptote, not a steep line.\r\nfunction diverges(a: Sample, m: Sample | null, b: Sample, clip: Extents): boolean {\r\n const straddles =\r\n (a.py > clip.maxY && b.py < clip.minY) || (a.py < clip.minY && b.py > clip.maxY) ||\r\n (a.px > clip.maxX && b.px < clip.minX) || (a.px < clip.minX && b.px > clip.maxX);\r\n if (!straddles || m === null) return false;\r\n if (!m.ok) return true;\r\n return (\r\n m.ry < Math.min(a.ry, b.ry) || m.ry > Math.max(a.ry, b.ry) ||\r\n m.rx < Math.min(a.rx, b.rx) || m.rx > Math.max(a.rx, b.rx)\r\n );\r\n}\r\n\r\nfunction offFrame(sample: Sample, clip: Extents): boolean {\r\n return sample.py > clip.maxY || sample.py < clip.minY || sample.px > clip.maxX || sample.px < clip.minX;\r\n}\r\n\r\nfunction clampCoord(value: number): number {\r\n if (value > COORD_LIMIT) return COORD_LIMIT;\r\n if (value < -COORD_LIMIT) return -COORD_LIMIT;\r\n return value;\r\n}\r\n\r\nclass CurvePen {\r\n points = 0;\r\n private readonly runs: Vector2[][] = [];\r\n private open: Vector2[] = [];\r\n private cursor: Vector2 | null = null;\r\n\r\n constructor(private readonly clip: Extents) {}\r\n\r\n draw(a: Sample, b: Sample): void {\r\n const segment = clipSegment(a.px, a.py, b.px, b.py, this.clip);\r\n if (!segment) {\r\n this.break();\r\n return;\r\n }\r\n const [start, end] = segment;\r\n if (this.cursor && samePoint(this.cursor, start)) {\r\n this.push(end);\r\n } else {\r\n this.break();\r\n this.push(start);\r\n this.push(end);\r\n }\r\n this.cursor = end;\r\n }\r\n\r\n start(b: Sample): void {\r\n this.break();\r\n if (!inside(b.px, b.py, this.clip)) return;\r\n this.cursor = { x: b.px, y: b.py };\r\n this.push(this.cursor);\r\n }\r\n\r\n break(): void {\r\n if (this.open.length >= 2) this.runs.push(this.open);\r\n this.open = [];\r\n this.cursor = null;\r\n }\r\n\r\n finish(): Vector2[][] {\r\n this.break();\r\n return this.runs;\r\n }\r\n\r\n private push(point: Vector2): void {\r\n this.open.push(point);\r\n this.points++;\r\n }\r\n}\r\n\r\nfunction samePoint(a: Vector2, b: Vector2): boolean {\r\n return Math.abs(a.x - b.x) < 0.1 && Math.abs(a.y - b.y) < 0.1;\r\n}\r\n\r\nfunction inside(x: number, y: number, clip: Extents): boolean {\r\n return x >= clip.minX && x <= clip.maxX && y >= clip.minY && y <= clip.maxY;\r\n}\r\n\r\n// Liang–Barsky: the part of a segment inside the clip, or null when none is.\r\nfunction clipSegment(ax: number, ay: number, bx: number, by: number, clip: Extents): [Vector2, Vector2] | null {\r\n const dx = bx - ax;\r\n const dy = by - ay;\r\n let t0 = 0;\r\n let t1 = 1;\r\n const edges: [number, number][] = [\r\n [-dx, ax - clip.minX],\r\n [dx, clip.maxX - ax],\r\n [-dy, ay - clip.minY],\r\n [dy, clip.maxY - ay],\r\n ];\r\n for (const [p, q] of edges) {\r\n if (p === 0) {\r\n if (q < 0) return null;\r\n continue;\r\n }\r\n const r = q / p;\r\n if (p < 0) {\r\n if (r > t1) return null;\r\n if (r > t0) t0 = r;\r\n } else {\r\n if (r < t0) return null;\r\n if (r < t1) t1 = r;\r\n }\r\n }\r\n return [\r\n { x: ax + t0 * dx, y: ay + t0 * dy },\r\n { x: ax + t1 * dx, y: ay + t1 * dy },\r\n ];\r\n}\r\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Color, type Fill, type FillResolved, type NormalizedColor } from "@motionscript/sdk";
|
|
2
|
+
/** A run of colours a value is read off, lowest first: a surface's height, a field's strength. */
|
|
3
|
+
export declare function readScale(value: readonly Color[] | undefined): NormalizedColor[];
|
|
4
|
+
export declare function lerpScale(from: NormalizedColor[], to: NormalizedColor[], t: number): NormalizedColor[];
|
|
5
|
+
/** The colour `share` of the way along `scale`, 0 to 1. */
|
|
6
|
+
export declare function colorAt(scale: readonly NormalizedColor[], share: number): NormalizedColor;
|
|
7
|
+
/** A run of paints a value is read off, lowest first: a field's strength. Every entry is kept as written. */
|
|
8
|
+
export declare function readFillScale(value: readonly Fill[] | undefined): FillResolved[][];
|
|
9
|
+
export declare function lerpFillScale(from: FillResolved[][], to: FillResolved[][], t: number): FillResolved[][];
|
|
10
|
+
/** The paint `share` of the way along `scale`, 0 to 1. */
|
|
11
|
+
export declare function fillAt(scale: readonly FillResolved[][], share: number): FillResolved[];
|
|
12
|
+
//# sourceMappingURL=scale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scale.d.ts","sourceRoot":"","sources":["../../src/kit/scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,KAAK,EAAE,KAAK,IAAI,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGtH,kGAAkG;AAElG,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,GAAG,eAAe,EAAE,CAEhF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,eAAe,EAAE,CAGtG;AAED,2DAA2D;AAC3D,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,eAAe,CAKzF;AAED,6GAA6G;AAC7G,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,SAAS,GAAG,YAAY,EAAE,EAAE,CAElF;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE,EAAE,CAGvG;AAED,0DAA0D;AAC1D,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,EAAE,CAKtF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { colorOps, fillOps } from "@motionscript/sdk";
|
|
2
|
+
import { clamp } from "./geometry.js";
|
|
3
|
+
/** A run of colours a value is read off, lowest first: a surface's height, a field's strength. */
|
|
4
|
+
export function readScale(value) {
|
|
5
|
+
return (value ?? []).map((color) => colorOps.resolve(color));
|
|
6
|
+
}
|
|
7
|
+
export function lerpScale(from, to, t) {
|
|
8
|
+
if (from.length !== to.length)
|
|
9
|
+
return t < 1 ? from : to;
|
|
10
|
+
return to.map((color, index) => colorOps.lerp(from[index], color, t));
|
|
11
|
+
}
|
|
12
|
+
/** The colour `share` of the way along `scale`, 0 to 1. */
|
|
13
|
+
export function colorAt(scale, share) {
|
|
14
|
+
if (scale.length === 1)
|
|
15
|
+
return scale[0];
|
|
16
|
+
const at = clamp(share, 0, 1) * (scale.length - 1);
|
|
17
|
+
const index = Math.min(scale.length - 2, Math.floor(at));
|
|
18
|
+
return colorOps.lerp(scale[index], scale[index + 1], at - index);
|
|
19
|
+
}
|
|
20
|
+
/** A run of paints a value is read off, lowest first: a field's strength. Every entry is kept as written. */
|
|
21
|
+
export function readFillScale(value) {
|
|
22
|
+
return (Array.isArray(value) ? value : []).map((fill) => fillOps.resolve(fill ?? []));
|
|
23
|
+
}
|
|
24
|
+
export function lerpFillScale(from, to, t) {
|
|
25
|
+
if (from.length !== to.length)
|
|
26
|
+
return t < 1 ? from : to;
|
|
27
|
+
return to.map((fill, index) => fillOps.lerp(from[index], fill, t));
|
|
28
|
+
}
|
|
29
|
+
/** The paint `share` of the way along `scale`, 0 to 1. */
|
|
30
|
+
export function fillAt(scale, share) {
|
|
31
|
+
if (scale.length === 1)
|
|
32
|
+
return scale[0];
|
|
33
|
+
const at = clamp(share, 0, 1) * (scale.length - 1);
|
|
34
|
+
const index = Math.min(scale.length - 2, Math.floor(at));
|
|
35
|
+
return fillOps.lerp(scale[index], scale[index + 1], at - index);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=scale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scale.js","sourceRoot":"","sources":["../../src/kit/scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAkE,MAAM,mBAAmB,CAAC;AACtH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,kGAAkG;AAElG,MAAM,UAAU,SAAS,CAAC,KAAmC;IACzD,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAuB,EAAE,EAAqB,EAAE,CAAS;IAC/E,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,CAAC,MAAM;QAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CA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,CAAC;IACxD,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,MAAM,CAAC,KAAgC,EAAE,KAAa;IAClE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IACxC,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IACzD,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import { colorOps, fillOps, type Color, type Fill, type FillResolved, type NormalizedColor } from \"@motionscript/sdk\";\r\nimport { clamp } from \"./geometry\";\r\n\r\n/** A run of colours a value is read off, lowest first: a surface's height, a field's strength. */\r\n\r\nexport function readScale(value: readonly Color[] | undefined): NormalizedColor[] {\r\n return (value ?? []).map((color) => colorOps.resolve(color));\r\n}\r\n\r\nexport function lerpScale(from: NormalizedColor[], to: NormalizedColor[], t: number): NormalizedColor[] {\r\n if (from.length !== to.length) return t < 1 ? from : to;\r\n return to.map((color, index) => colorOps.lerp(from[index], color, t));\r\n}\r\n\r\n/** The colour `share` of the way along `scale`, 0 to 1. */\r\nexport function colorAt(scale: readonly NormalizedColor[], share: number): NormalizedColor {\r\n if (scale.length === 1) return scale[0];\r\n const at = clamp(share, 0, 1) * (scale.length - 1);\r\n const index = Math.min(scale.length - 2, Math.floor(at));\r\n return colorOps.lerp(scale[index], scale[index + 1], at - index);\r\n}\r\n\r\n/** A run of paints a value is read off, lowest first: a field's strength. Every entry is kept as written. */\r\nexport function readFillScale(value: readonly Fill[] | undefined): FillResolved[][] {\r\n return (Array.isArray(value) ? value : []).map((fill) => fillOps.resolve(fill ?? []));\r\n}\r\n\r\nexport function lerpFillScale(from: FillResolved[][], to: FillResolved[][], t: number): FillResolved[][] {\r\n if (from.length !== to.length) return t < 1 ? from : to;\r\n return to.map((fill, index) => fillOps.lerp(from[index], fill, t));\r\n}\r\n\r\n/** The paint `share` of the way along `scale`, 0 to 1. */\r\nexport function fillAt(scale: readonly FillResolved[][], share: number): FillResolved[] {\r\n if (scale.length === 1) return scale[0];\r\n const at = clamp(share, 0, 1) * (scale.length - 1);\r\n const index = Math.min(scale.length - 2, Math.floor(at));\r\n return fillOps.lerp(scale[index], scale[index + 1], at - index);\r\n}\r\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Interval } from "./coords.js";
|
|
2
|
+
import type { ExpressionScope } from "./expression.js";
|
|
3
|
+
/** What a plot's equation, domain and named values are held as, and how each tweens: shared by every plot, 2D and 3D. */
|
|
4
|
+
/** An equation on its way to another: both are drawn, `t` of the way across. */
|
|
5
|
+
export interface PlotSource {
|
|
6
|
+
source: string;
|
|
7
|
+
blend?: {
|
|
8
|
+
from: string;
|
|
9
|
+
t: number;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare function readSource(value: string | PlotSource | undefined): PlotSource;
|
|
13
|
+
export declare function lerpSource(from: PlotSource, to: PlotSource, t: number): PlotSource;
|
|
14
|
+
export declare function lerpDomain(from: Interval | null, to: Interval | null, t: number): Interval | null;
|
|
15
|
+
/** What a named value is until it is given one. */
|
|
16
|
+
export declare const UNSET_PARAM = 1;
|
|
17
|
+
export declare function lerpParams(from: ExpressionScope, to: ExpressionScope, t: number): ExpressionScope;
|
|
18
|
+
/** `params` with every name of `names` given a value, so one nobody has set yet still draws. */
|
|
19
|
+
export declare function scopeFor(names: readonly string[], params: ExpressionScope): ExpressionScope;
|
|
20
|
+
/** A string as a number that changes when it does: what a geometry's `revision` wants. */
|
|
21
|
+
export declare function revisionOf(key: string): number;
|
|
22
|
+
//# sourceMappingURL=source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/kit/source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,yHAAyH;AAEzH,gFAAgF;AAChF,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACvC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,CAG7E;AAGD,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,CAGlF;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,EAAE,EAAE,EAAE,QAAQ,GAAG,IAAI,EAAE,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAGjG;AAED,mDAAmD;AACnD,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B,wBAAgB,UAAU,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,GAAG,eAAe,CAOjG;AAED,gGAAgG;AAChG,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,eAAe,GAAG,eAAe,CAM3F;AAED,0FAA0F;AAC1F,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9C"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function readSource(value) {
|
|
2
|
+
if (typeof value === "string")
|
|
3
|
+
return { source: value };
|
|
4
|
+
return value ?? { source: "" };
|
|
5
|
+
}
|
|
6
|
+
// Mid-tween the prop holds both equations, so a seek restores the blend with it.
|
|
7
|
+
export function lerpSource(from, to, t) {
|
|
8
|
+
if (t <= 0 || from.source === to.source)
|
|
9
|
+
return t <= 0 ? from : to;
|
|
10
|
+
return t >= 1 ? to : { source: to.source, blend: { from: from.source, t } };
|
|
11
|
+
}
|
|
12
|
+
export function lerpDomain(from, to, t) {
|
|
13
|
+
if (!from || !to)
|
|
14
|
+
return t < 1 ? from : to;
|
|
15
|
+
return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];
|
|
16
|
+
}
|
|
17
|
+
/** What a named value is until it is given one. */
|
|
18
|
+
export const UNSET_PARAM = 1;
|
|
19
|
+
export function lerpParams(from, to, t) {
|
|
20
|
+
const out = { ...from };
|
|
21
|
+
for (const [name, value] of Object.entries(to)) {
|
|
22
|
+
const start = from[name] ?? UNSET_PARAM;
|
|
23
|
+
out[name] = start + (value - start) * t;
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
/** `params` with every name of `names` given a value, so one nobody has set yet still draws. */
|
|
28
|
+
export function scopeFor(names, params) {
|
|
29
|
+
let filled = null;
|
|
30
|
+
for (const name of names) {
|
|
31
|
+
if (typeof params[name] !== "number")
|
|
32
|
+
(filled ??= { ...params })[name] = UNSET_PARAM;
|
|
33
|
+
}
|
|
34
|
+
return filled ?? params;
|
|
35
|
+
}
|
|
36
|
+
/** A string as a number that changes when it does: what a geometry's `revision` wants. */
|
|
37
|
+
export function revisionOf(key) {
|
|
38
|
+
let hash = 0x811c9dc5;
|
|
39
|
+
for (let i = 0; i < key.length; i++) {
|
|
40
|
+
hash ^= key.charCodeAt(i);
|
|
41
|
+
hash = Math.imul(hash, 0x01000193);
|
|
42
|
+
}
|
|
43
|
+
return hash >>> 0;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../src/kit/source.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,UAAU,CAAC,KAAsC;IAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IACxD,OAAO,KAAK,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AACnC,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,UAAU,CAAC,IAAgB,EAAE,EAAc,EAAE,CAAS;IAClE,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,CAAC,MAAM;QAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAqB,EAAE,EAAmB,EAAE,CAAS;IAC5E,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC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C,CAAC;QAC1B,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,CAAC;AACtB,CAAC","sourcesContent":["import type { Interval } from \"./coords\";\r\nimport type { ExpressionScope } from \"./expression\";\r\n\r\n/** What a plot's equation, domain and named values are held as, and how each tweens: shared by every plot, 2D and 3D. */\r\n\r\n/** An equation on its way to another: both are drawn, `t` of the way across. */\r\nexport interface PlotSource {\r\n source: string;\r\n blend?: { from: string; t: number };\r\n}\r\n\r\nexport function readSource(value: string | PlotSource | undefined): PlotSource {\r\n if (typeof value === \"string\") return { source: value };\r\n return value ?? { source: \"\" };\r\n}\r\n\r\n// Mid-tween the prop holds both equations, so a seek restores the blend with it.\r\nexport function lerpSource(from: PlotSource, to: PlotSource, t: number): PlotSource {\r\n if (t <= 0 || from.source === to.source) return t <= 0 ? from : to;\r\n return t >= 1 ? to : { source: to.source, blend: { from: from.source, t } };\r\n}\r\n\r\nexport function lerpDomain(from: Interval | null, to: Interval | null, t: number): Interval | null {\r\n if (!from || !to) return t < 1 ? from : to;\r\n return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];\r\n}\r\n\r\n/** What a named value is until it is given one. */\r\nexport const UNSET_PARAM = 1;\r\n\r\nexport function lerpParams(from: ExpressionScope, to: ExpressionScope, t: number): ExpressionScope {\r\n const out: Record<string, number> = { ...from };\r\n for (const [name, value] of Object.entries(to)) {\r\n const start = from[name] ?? UNSET_PARAM;\r\n out[name] = start + (value - start) * t;\r\n }\r\n return out;\r\n}\r\n\r\n/** `params` with every name of `names` given a value, so one nobody has set yet still draws. */\r\nexport function scopeFor(names: readonly string[], params: ExpressionScope): ExpressionScope {\r\n let filled: Record<string, number> | null = null;\r\n for (const name of names) {\r\n if (typeof params[name] !== \"number\") (filled ??= { ...params })[name] = UNSET_PARAM;\r\n }\r\n return filled ?? params;\r\n}\r\n\r\n/** A string as a number that changes when it does: what a geometry's `revision` wants. */\r\nexport function revisionOf(key: string): number {\r\n let hash = 0x811c9dc5;\r\n for (let i = 0; i < key.length; i++) {\r\n hash ^= key.charCodeAt(i);\r\n hash = Math.imul(hash, 0x01000193);\r\n }\r\n return hash >>> 0;\r\n}\r\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Clip, Graphics2D, PaintNode, type BoxBounds, type ChildPlane, type Extents, type MeasureContext2D, type Node2D, type PaintProps, type RenderContext2D, type Size2D, type SizeConstraints } from "@motionscript/sdk";
|
|
2
|
+
import type { CoordinateMap } from "./coords.js";
|
|
3
|
+
export type { Anchored } from "./place.js";
|
|
4
|
+
/**
|
|
5
|
+
* A node whose children sit in its graph coordinates. A child's `x`/`y` are in
|
|
6
|
+
* the system's units and the child keeps its own size, so anything can be put
|
|
7
|
+
* on a graph: a dot, a label, an image. A mark is drawn through the
|
|
8
|
+
* system's map instead and laid out on its ink.
|
|
9
|
+
*
|
|
10
|
+
* The system's `stroke` is its axis line (so `endCap` is the tip) and its `fill`
|
|
11
|
+
* the backdrop. Ticks, grid and labels are drawing ops, never child nodes: a
|
|
12
|
+
* document's children would otherwise share their indices with them.
|
|
13
|
+
*/
|
|
14
|
+
export declare abstract class CoordinateSystem<P extends PaintProps = PaintProps> extends PaintNode<P> {
|
|
15
|
+
/** How graph values land on a plot area of this size. */
|
|
16
|
+
protected abstract mapFor(area: Extents): CoordinateMap;
|
|
17
|
+
/** What the system draws of itself, under its children. */
|
|
18
|
+
protected abstract furniture(map: CoordinateMap): Graphics2D[];
|
|
19
|
+
/** This system's coordinates, as last laid out. */
|
|
20
|
+
get coordinates(): CoordinateMap;
|
|
21
|
+
measure(constraints: SizeConstraints): Partial<Size2D>;
|
|
22
|
+
protected layoutChildren(rect: BoxBounds, scope: MeasureContext2D): void;
|
|
23
|
+
_planeOf(child: Node2D | null): ChildPlane | null;
|
|
24
|
+
protected shapeGraphics(): Graphics2D | null;
|
|
25
|
+
protected renderSelf(ctx: RenderContext2D): void;
|
|
26
|
+
protected renderStroke(): void;
|
|
27
|
+
protected clipSelf(): Clip | null;
|
|
28
|
+
private _map;
|
|
29
|
+
private _planes;
|
|
30
|
+
/** The plot area: the box less its padding, y-up from the box's centre. */
|
|
31
|
+
private _area;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=system.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../src/kit/system.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EAEJ,UAAU,EAEV,SAAS,EACT,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,eAAe,EAEvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKxC;;;;;;;;;GASG;AACH,8BAAsB,gBAAgB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAC1F,yDAAyD;IACzD,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa;IAEvD,2DAA2D;IAC3D,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,aAAa,GAAG,UAAU,EAAE;IAE9D,mDAAmD;IACnD,IAAI,WAAW,IAAI,aAAa,CAE/B;IAGQ,OAAO,CAAC,WAAW,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;cAI5C,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,GAAG,IAAI;IAOxE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,UAAU,GAAG,IAAI;cAIvC,aAAa,IAAI,UAAU,GAAG,IAAI;cAKlC,UAAU,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI;cAUtC,YAAY,IAAI,IAAI;cAEpB,QAAQ,IAAI,IAAI,GAAG,IAAI;IAK1C,OAAO,CAAC,IAAI,CAA8B;IAC1C,OAAO,CAAC,OAAO,CAAqC;IAEpD,2EAA2E;IAC3E,OAAO,CAAC,KAAK;CAShB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Clip, flowOps, Graphics2D, insetsOps, PaintNode, } from "@motionscript/sdk";
|
|
2
|
+
import { openPlane, placeOnMap } from "./place.js";
|
|
3
|
+
const NO_CONTENT = { width: 0, height: 0 };
|
|
4
|
+
const CENTRE = { x: 0, y: 0 };
|
|
5
|
+
/**
|
|
6
|
+
* A node whose children sit in its graph coordinates. A child's `x`/`y` are in
|
|
7
|
+
* the system's units and the child keeps its own size, so anything can be put
|
|
8
|
+
* on a graph: a dot, a label, an image. A mark is drawn through the
|
|
9
|
+
* system's map instead and laid out on its ink.
|
|
10
|
+
*
|
|
11
|
+
* The system's `stroke` is its axis line (so `endCap` is the tip) and its `fill`
|
|
12
|
+
* the backdrop. Ticks, grid and labels are drawing ops, never child nodes: a
|
|
13
|
+
* document's children would otherwise share their indices with them.
|
|
14
|
+
*/
|
|
15
|
+
export class CoordinateSystem extends PaintNode {
|
|
16
|
+
/** This system's coordinates, as last laid out. */
|
|
17
|
+
get coordinates() {
|
|
18
|
+
return this._map ?? (this._map = this.mapFor(this._area(this.layoutBounds)));
|
|
19
|
+
}
|
|
20
|
+
// A system is the size it is given: its children are placed in it, not measured into it.
|
|
21
|
+
measure(constraints) {
|
|
22
|
+
return flowOps.size(this, constraints, this.effectivePadding(), NO_CONTENT);
|
|
23
|
+
}
|
|
24
|
+
layoutChildren(rect, scope) {
|
|
25
|
+
const map = this.mapFor(this._area(rect));
|
|
26
|
+
this._map = map;
|
|
27
|
+
const inner = insetsOps.insetBounds(rect.width, rect.height, this.effectivePadding());
|
|
28
|
+
this._planes = placeOnMap(this.flowChildren(), map, CENTRE, inner, scope);
|
|
29
|
+
}
|
|
30
|
+
_planeOf(child) {
|
|
31
|
+
return child ? (this._planes.get(child) ?? null) : openPlane(this.coordinates, CENTRE);
|
|
32
|
+
}
|
|
33
|
+
shapeGraphics() {
|
|
34
|
+
const r = this.layoutBounds;
|
|
35
|
+
return new Graphics2D().rect({ x: 0, y: 0, width: r.width, height: r.height });
|
|
36
|
+
}
|
|
37
|
+
renderSelf(ctx) {
|
|
38
|
+
super.renderSelf(ctx);
|
|
39
|
+
const map = this.coordinates;
|
|
40
|
+
const clip = map.spills ? this.clipSelf() : null;
|
|
41
|
+
if (clip)
|
|
42
|
+
ctx.beginClip(clip);
|
|
43
|
+
for (const part of this.furniture(map))
|
|
44
|
+
ctx.draw(part);
|
|
45
|
+
if (clip)
|
|
46
|
+
ctx.endClip();
|
|
47
|
+
}
|
|
48
|
+
// The stroke is the axis line, drawn with the furniture: painted here it would land over the children.
|
|
49
|
+
renderStroke() { }
|
|
50
|
+
clipSelf() {
|
|
51
|
+
const { minX, minY, maxX, maxY } = this.coordinates.area;
|
|
52
|
+
return new Clip().rect({ x: (minX + maxX) / 2, y: (minY + maxY) / 2, width: maxX - minX, height: maxY - minY });
|
|
53
|
+
}
|
|
54
|
+
_map = null;
|
|
55
|
+
_planes = new WeakMap();
|
|
56
|
+
/** The plot area: the box less its padding, y-up from the box's centre. */
|
|
57
|
+
_area(rect) {
|
|
58
|
+
const inner = insetsOps.insetBounds(rect.width, rect.height, this.effectivePadding());
|
|
59
|
+
return {
|
|
60
|
+
minX: inner.x - inner.width / 2,
|
|
61
|
+
maxX: inner.x + inner.width / 2,
|
|
62
|
+
minY: -inner.y - inner.height / 2,
|
|
63
|
+
maxY: -inner.y + inner.height / 2,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=system.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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EAAE,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC;IACpH,CAAC;IAEO,IAAI,GAAyB,IAAI,CAAC;IAClC,OAAO,GAAG,IAAI,OAAO,EAAsB,CAAC;IAEpD,2EAA2E;IACnE,KAAK,CAAC,IAAe;QACzB,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;QACtF,OAAO;YACH,IAAI,EAAE,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC;YAC/B,IAAI,EAAE,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC;YAC/B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC;YACjC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC;SACpC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import {\r\n Clip,\r\n flowOps,\r\n Graphics2D,\r\n insetsOps,\r\n PaintNode,\r\n type BoxBounds,\r\n type ChildPlane,\r\n type Extents,\r\n type MeasureContext2D,\r\n type Node2D,\r\n type PaintProps,\r\n type RenderContext2D,\r\n type Size2D,\r\n type SizeConstraints,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport type { CoordinateMap } from \"./coords\";\r\nimport { openPlane, placeOnMap } from \"./place\";\r\n\r\nexport type { Anchored } from \"./place\";\r\n\r\nconst NO_CONTENT: Size2D = { width: 0, height: 0 };\r\nconst CENTRE: Vector2 = { x: 0, y: 0 };\r\n\r\n/**\r\n * A node whose children sit in its graph coordinates. A child's `x`/`y` are in\r\n * the system's units and the child keeps its own size, so anything can be put\r\n * on a graph: a dot, a label, an image. A mark is drawn through the\r\n * system's map instead and laid out on its ink.\r\n *\r\n * The system's `stroke` is its axis line (so `endCap` is the tip) and its `fill`\r\n * the backdrop. Ticks, grid and labels are drawing ops, never child nodes: a\r\n * document's children would otherwise share their indices with them.\r\n */\r\nexport abstract class CoordinateSystem<P extends PaintProps = PaintProps> extends PaintNode<P> {\r\n /** How graph values land on a plot area of this size. */\r\n protected abstract mapFor(area: Extents): CoordinateMap;\r\n\r\n /** What the system draws of itself, under its children. */\r\n protected abstract furniture(map: CoordinateMap): Graphics2D[];\r\n\r\n /** This system's coordinates, as last laid out. */\r\n get coordinates(): CoordinateMap {\r\n return this._map ?? (this._map = this.mapFor(this._area(this.layoutBounds)));\r\n }\r\n\r\n // A system is the size it is given: its children are placed in it, not measured into it.\r\n override measure(constraints: SizeConstraints): Partial<Size2D> {\r\n return flowOps.size(this, constraints, this.effectivePadding(), NO_CONTENT);\r\n }\r\n\r\n protected override layoutChildren(rect: BoxBounds, scope: MeasureContext2D): void {\r\n const map = this.mapFor(this._area(rect));\r\n this._map = map;\r\n const inner = insetsOps.insetBounds(rect.width, rect.height, this.effectivePadding());\r\n this._planes = placeOnMap(this.flowChildren(), map, CENTRE, inner, scope);\r\n }\r\n\r\n override _planeOf(child: Node2D | null): ChildPlane | null {\r\n return child ? (this._planes.get(child) ?? null) : openPlane(this.coordinates, CENTRE);\r\n }\r\n\r\n protected override shapeGraphics(): Graphics2D | null {\r\n const r = this.layoutBounds;\r\n return new Graphics2D().rect({ x: 0, y: 0, width: r.width, height: r.height });\r\n }\r\n\r\n protected override renderSelf(ctx: RenderContext2D): void {\r\n super.renderSelf(ctx);\r\n const map = this.coordinates;\r\n const clip = map.spills ? this.clipSelf() : null;\r\n if (clip) ctx.beginClip(clip);\r\n for (const part of this.furniture(map)) ctx.draw(part);\r\n if (clip) ctx.endClip();\r\n }\r\n\r\n // The stroke is the axis line, drawn with the furniture: painted here it would land over the children.\r\n protected override renderStroke(): void {}\r\n\r\n protected override clipSelf(): Clip | null {\r\n const { minX, minY, maxX, maxY } = this.coordinates.area;\r\n return new Clip().rect({ x: (minX + maxX) / 2, y: (minY + maxY) / 2, width: maxX - minX, height: maxY - minY });\r\n }\r\n\r\n private _map: CoordinateMap | null = null;\r\n private _planes = new WeakMap<Node2D, ChildPlane>();\r\n\r\n /** The plot area: the box less its padding, y-up from the box's centre. */\r\n private _area(rect: BoxBounds): Extents {\r\n const inner = insetsOps.insetBounds(rect.width, rect.height, this.effectivePadding());\r\n return {\r\n minX: inner.x - inner.width / 2,\r\n maxX: inner.x + inner.width / 2,\r\n minY: -inner.y - inner.height / 2,\r\n maxY: -inner.y + inner.height / 2,\r\n };\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AxisScaling, Interval } from "./coords.js";
|
|
2
|
+
/** Where an axis is marked, and the spacing its labels are rounded to. */
|
|
3
|
+
export interface Ticks {
|
|
4
|
+
values: number[];
|
|
5
|
+
step: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The marks along `range`, drawn over `length` pixels. A `step` of zero lets the
|
|
9
|
+
* axis choose a tidy one (1, 2 or 5 times a power of ten) for its size; a log
|
|
10
|
+
* axis is marked at the powers of ten whatever the step.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ticksFor(range: Interval, step: number, length: number, scaling?: AxisScaling): Ticks;
|
|
13
|
+
/**
|
|
14
|
+
* `value` as a tick label, with as many decimals as `step` needs and no more:
|
|
15
|
+
* 0.30000000000000004 on a 0.1 ladder is `0.3`. A `step` of zero (a log axis)
|
|
16
|
+
* prints the value as it is.
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatTick(value: number, step: number): string;
|
|
19
|
+
//# sourceMappingURL=ticks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticks.d.ts","sourceRoot":"","sources":["../../src/kit/ticks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEtD,0EAA0E;AAC1E,MAAM,WAAW,KAAK;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CAChB;AAQD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,WAAsB,GAAG,KAAK,CAO9G;AAyBD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAa9D"}
|