@motionscript/math 0.1.0-alpha.5 → 0.1.0-alpha.6
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 +22 -0
- package/README.md +39 -33
- package/dist/annotate/angle-mark.d.ts +52 -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 +59 -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 +43 -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 +58 -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 +24 -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 +28 -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 +37 -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 +30 -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 +38 -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 +30 -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 +107 -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 +34 -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 +38 -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 +34 -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 +31 -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 +99 -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 +69 -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 +126 -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 +51 -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 +92 -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 +47 -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 +56 -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 +55 -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 +140 -54
- package/dist/three/axes3d.d.ts.map +1 -1
- package/dist/three/axes3d.js +159 -204
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +70 -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 +57 -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 +131 -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 +58 -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 +182 -161
- 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,15 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
component2d,
|
|
3
3
|
Graphics2D,
|
|
4
|
-
|
|
5
|
-
property,
|
|
6
|
-
strokeProperty,
|
|
7
|
-
type Command,
|
|
8
|
-
type CommandArgs,
|
|
4
|
+
Types,
|
|
9
5
|
type Extents,
|
|
10
|
-
type
|
|
6
|
+
type NodeOf,
|
|
11
7
|
type Stroke,
|
|
12
8
|
type StrokeResolved,
|
|
9
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
10
|
+
type Color as _Color,
|
|
11
|
+
type Fill as _Fill,
|
|
12
|
+
type FillResolved as _FillResolved,
|
|
13
|
+
type Node2D as _Node2D,
|
|
14
|
+
type Node2DProps as _Node2DProps,
|
|
15
|
+
type NormalizedColor as _NormalizedColor,
|
|
16
|
+
type Shadow as _Shadow,
|
|
17
|
+
type ShadowResolved as _ShadowResolved,
|
|
13
18
|
} from "@motionscript/sdk";
|
|
14
19
|
import {
|
|
15
20
|
isIdentityMatrix,
|
|
@@ -23,10 +28,10 @@ import {
|
|
|
23
28
|
type Warp,
|
|
24
29
|
} from "../kit/coords";
|
|
25
30
|
import { fieldParams, parseField } from "../kit/field";
|
|
26
|
-
import { Axes2d, type Axes2dProps, type AxisLayout } from "./axes2d";
|
|
27
31
|
import { AXIS_COLOR } from "../kit/furniture";
|
|
28
|
-
import { stated } from "../kit/geometry";
|
|
29
32
|
import { lerpSource, readSource, type PlotSource } from "../kit/source";
|
|
33
|
+
import { drawSystem, plotArea, systemLayout, systemOpenPlane, systemProvides, systemSize } from "../kit/system";
|
|
34
|
+
import { AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes, type Axes2dProps, type AxesValues, type AxisLayout } from "./axes2d";
|
|
30
35
|
|
|
31
36
|
export interface NumberPlaneProps extends Axes2dProps {
|
|
32
37
|
grid?: boolean;
|
|
@@ -38,72 +43,91 @@ export interface NumberPlaneProps extends Axes2dProps {
|
|
|
38
43
|
ghost?: boolean;
|
|
39
44
|
}
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* squeezes the whole plane about its origin, and its `warp` bends it by a
|
|
45
|
-
* function of its own points; the grid, the axes and everything on the plane
|
|
46
|
-
* go with it.
|
|
47
|
-
*/
|
|
48
|
-
@node({
|
|
49
|
-
key: "numberPlane",
|
|
50
|
-
parentKey: "axes2d",
|
|
51
|
-
forkable: true,
|
|
52
|
-
layout: { children: "freeform", defaultWidthMode: "fixed", defaultHeightMode: "fixed", acceptsChildren: true },
|
|
53
|
-
seed: { width: 800, height: 500 },
|
|
54
|
-
})
|
|
55
|
-
export class NumberPlane extends Axes2d<NumberPlaneProps> {
|
|
56
|
-
@property({ default: true, animatable: false }) declare grid: boolean;
|
|
46
|
+
const state = {
|
|
47
|
+
...AXES,
|
|
48
|
+
grid: Types.boolean(true, { animatable: false }),
|
|
57
49
|
/** The line at every tick. */
|
|
58
|
-
|
|
50
|
+
gridStroke: Types.stroke({ weight: 1.5, fill: "#3b4658", align: "center" }),
|
|
59
51
|
/** The lines between ticks. */
|
|
60
|
-
|
|
52
|
+
minorStroke: Types.stroke({ weight: 1, fill: "#232b38", align: "center" }),
|
|
61
53
|
/** How many parts the space between two ticks is cut into; one draws no line between them. */
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
minorDivisions: Types.number(2, { min: 1, max: 10, step: 1 }),
|
|
64
55
|
/** A linear map of the plane, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */
|
|
65
|
-
|
|
56
|
+
matrix: Types.custom<Matrix2 | readonly (readonly number[])[], Matrix2>([1, 0, 0, 1], { resolve: readMatrix, lerp: lerpMatrix }),
|
|
66
57
|
/**
|
|
67
58
|
* Where each point of the plane is sent, two parts in x and y:
|
|
68
59
|
* `(x + sin(y), y + sin(x))`. Empty leaves the plane flat.
|
|
69
60
|
*/
|
|
70
|
-
|
|
61
|
+
warp: Types.custom<string | PlotSource, PlotSource>("", { resolve: readSource, lerp: lerpSource, kind: "fieldEquation" }),
|
|
71
62
|
/** Leave the plane as it was, faintly, behind one that has been transformed or warped. */
|
|
72
|
-
|
|
63
|
+
ghost: Types.boolean(true, { animatable: false }),
|
|
64
|
+
};
|
|
73
65
|
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
type PlaneValues = AxesValues & {
|
|
67
|
+
readonly grid: boolean;
|
|
68
|
+
readonly gridStroke: StrokeResolved[];
|
|
69
|
+
readonly minorStroke: StrokeResolved[];
|
|
70
|
+
readonly minorDivisions: number;
|
|
71
|
+
readonly matrix: Matrix2;
|
|
72
|
+
readonly warp: PlotSource;
|
|
73
|
+
readonly ghost: boolean;
|
|
74
|
+
};
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Axes over a full grid, with square units unless told otherwise: the plane
|
|
78
|
+
* vectors and transformations are drawn on. Its `matrix` shears, turns or
|
|
79
|
+
* squeezes the whole plane about its origin, and its `warp` bends it by a
|
|
80
|
+
* function of its own points; the grid, the axes and everything on the plane
|
|
81
|
+
* go with it.
|
|
82
|
+
*/
|
|
83
|
+
export const NumberPlane = component2d({
|
|
84
|
+
key: "numberPlane",
|
|
85
|
+
state,
|
|
86
|
+
defaults: {
|
|
87
|
+
squareUnits: true,
|
|
88
|
+
stroke: { weight: 2, fill: AXIS_COLOR, align: "center" },
|
|
79
89
|
// A transformed plane reaches past its box, and so does what is on it: both are kept in unless told otherwise.
|
|
80
|
-
|
|
81
|
-
}
|
|
90
|
+
clip: (s) => spills(s),
|
|
91
|
+
},
|
|
92
|
+
load: (loader, s) => loadAxes(loader, s),
|
|
93
|
+
commands: {
|
|
94
|
+
...AXES_COMMANDS,
|
|
95
|
+
/** Send the plane through a matrix: a shear, a turn, a squeeze, a flip. */
|
|
96
|
+
transformTo: { args: ["matrix"] },
|
|
97
|
+
/** Bend the plane, each point travelling to where the warp sends it; an empty one flattens it again. */
|
|
98
|
+
warpTo: { args: ["warp"] },
|
|
99
|
+
},
|
|
100
|
+
provide: (s) => systemProvides(s),
|
|
101
|
+
measure: (_measurer, s) => systemSize(s),
|
|
102
|
+
layout: (box, s, children) => systemLayout(box, s, children, planeMap),
|
|
103
|
+
plane: (box, s) => systemOpenPlane(box, s, planeMap),
|
|
104
|
+
render: (ctx, s) => {
|
|
105
|
+
const { flat, map } = planeMaps(plotArea(ctx.size, s.padding), s);
|
|
106
|
+
drawSystem(ctx, s, map, (on) => axesFurniture(on, s, (x, y) => grid(s, flat, on, x, y)));
|
|
107
|
+
},
|
|
108
|
+
});
|
|
82
109
|
|
|
83
|
-
|
|
84
|
-
@command({ args: ["matrix"] })
|
|
85
|
-
transformTo(args: CommandArgs<{ matrix: Matrix2 | readonly (readonly number[])[] }> & { duration: number }): Command<NumberPlaneProps> {
|
|
86
|
-
return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
|
|
87
|
-
}
|
|
110
|
+
export type NumberPlane = NodeOf<typeof NumberPlane>;
|
|
88
111
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
112
|
+
/** The plane's map on a plot area: the flat one, sent through its matrix and its warp. */
|
|
113
|
+
export function planeMap(area: Extents, s: PlaneValues): CoordinateMap {
|
|
114
|
+
return planeMaps(area, s).map;
|
|
115
|
+
}
|
|
94
116
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
117
|
+
/** The flat plane on a plot area, and the plane as its matrix and its warp have it. */
|
|
118
|
+
function planeMaps(area: Extents, s: PlaneValues): { flat: CoordinateMap; map: CoordinateMap } {
|
|
119
|
+
const flat = axesMap(area, s);
|
|
120
|
+
const map = isIdentityMatrix(s.matrix) ? flat : transformedMap(flat, s.matrix);
|
|
121
|
+
const { source, blend } = s.warp;
|
|
122
|
+
const to = warpOf(source);
|
|
123
|
+
if (!blend) return { flat, map: to ? warpedMap(map, to, source) : map };
|
|
124
|
+
// Mid-warp each point is part of the way from where the old warp had it to where the new one sends it.
|
|
125
|
+
const from = warpOf(blend.from);
|
|
126
|
+
if (!from && !to) return { flat, map };
|
|
127
|
+
const start = { x: 0, y: 0 };
|
|
128
|
+
return {
|
|
129
|
+
flat,
|
|
130
|
+
map: warpedMap(
|
|
107
131
|
map,
|
|
108
132
|
(x, y, out) => {
|
|
109
133
|
if (!(from ?? STAY)(x, y, start) || !(to ?? STAY)(x, y, out)) return false;
|
|
@@ -112,74 +136,79 @@ export class NumberPlane extends Axes2d<NumberPlaneProps> {
|
|
|
112
136
|
return true;
|
|
113
137
|
},
|
|
114
138
|
`${blend.from}>${source}@${blend.t}`,
|
|
115
|
-
)
|
|
139
|
+
),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Whether the plane reaches past its box: it is transformed or warped. */
|
|
144
|
+
function spills(s: PlaneValues): boolean {
|
|
145
|
+
if (!isIdentityMatrix(s.matrix)) return true;
|
|
146
|
+
const { source, blend } = s.warp;
|
|
147
|
+
return warpOf(source) !== null || (blend !== undefined && warpOf(blend.from) !== null);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** The grid behind the axes, with the flat plane faintly behind a transformed one. */
|
|
151
|
+
function grid(s: PlaneValues, flat: CoordinateMap, map: CoordinateMap, x: AxisLayout, y: AxisLayout): Graphics2D[] {
|
|
152
|
+
if (!s.grid) return [];
|
|
153
|
+
const parts: Graphics2D[] = [];
|
|
154
|
+
if (s.ghost && flat.revision !== map.revision) {
|
|
155
|
+
const [gx, gy] = axesOf(flat, s);
|
|
156
|
+
parts.push(...ruled(s, flat, gx, gy, true));
|
|
116
157
|
}
|
|
158
|
+
parts.push(...ruled(s, map, x, y, false));
|
|
159
|
+
return parts;
|
|
160
|
+
}
|
|
117
161
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
162
|
+
/** The grid of `map`: every line, or only the ones at a tick, in the fainter stroke, for a ghost. */
|
|
163
|
+
function ruled(s: PlaneValues, map: CoordinateMap, x: AxisLayout, y: AxisLayout, ghost: boolean): Graphics2D[] {
|
|
164
|
+
const { start, end } = s;
|
|
165
|
+
const [xMin, xMax] = map.xRange;
|
|
166
|
+
const [yMin, yMax] = map.yRange;
|
|
167
|
+
const lines = (values: readonly number[], vertical: boolean): Graphics2D => {
|
|
168
|
+
const g = new Graphics2D();
|
|
169
|
+
for (const value of values) {
|
|
170
|
+
g.line({
|
|
171
|
+
points: vertical ? lineThrough(map, value, yMin, value, yMax) : lineThrough(map, xMin, value, xMax, value),
|
|
172
|
+
radius: 0,
|
|
173
|
+
start,
|
|
174
|
+
end,
|
|
175
|
+
});
|
|
125
176
|
}
|
|
126
|
-
|
|
177
|
+
return g;
|
|
178
|
+
};
|
|
179
|
+
const parts: Graphics2D[] = [];
|
|
180
|
+
const minor = s.minorStroke;
|
|
181
|
+
if (ghost) {
|
|
182
|
+
if (minor.length === 0) return parts;
|
|
183
|
+
if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(minor));
|
|
184
|
+
if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(minor));
|
|
127
185
|
return parts;
|
|
128
186
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
g.line({
|
|
141
|
-
points: vertical ? lineThrough(map, value, yMin, value, yMax) : lineThrough(map, xMin, value, xMax, value),
|
|
142
|
-
radius: 0,
|
|
143
|
-
start,
|
|
144
|
-
end,
|
|
145
|
-
});
|
|
187
|
+
const divisions = Math.round(s.minorDivisions);
|
|
188
|
+
if (minor.length > 0 && divisions > 1) {
|
|
189
|
+
const between = (axis: AxisLayout, [min, max]: readonly [number, number]): number[] => {
|
|
190
|
+
const { step, values } = axis.marks;
|
|
191
|
+
if (!(step > 0) || values.length === 0) return [];
|
|
192
|
+
const out: number[] = [];
|
|
193
|
+
for (let base = values[0] - step; base < max; base += step) {
|
|
194
|
+
for (let i = 1; i < divisions; i++) {
|
|
195
|
+
const value = base + (step * i) / divisions;
|
|
196
|
+
if (value > min && value < max) out.push(value);
|
|
197
|
+
}
|
|
146
198
|
}
|
|
147
|
-
return
|
|
199
|
+
return out;
|
|
148
200
|
};
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (minor.length > 0 && divisions > 1) {
|
|
159
|
-
const between = (axis: AxisLayout, [min, max]: readonly [number, number]): number[] => {
|
|
160
|
-
const { step, values } = axis.marks;
|
|
161
|
-
if (!(step > 0) || values.length === 0) return [];
|
|
162
|
-
const out: number[] = [];
|
|
163
|
-
for (let base = values[0] - step; base < max; base += step) {
|
|
164
|
-
for (let i = 1; i < divisions; i++) {
|
|
165
|
-
const value = base + (step * i) / divisions;
|
|
166
|
-
if (value > min && value < max) out.push(value);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return out;
|
|
170
|
-
};
|
|
171
|
-
const xs = between(x, map.xRange);
|
|
172
|
-
const ys = between(y, map.yRange);
|
|
173
|
-
if (xs.length > 0) parts.push(lines(xs, true).stroke(minor));
|
|
174
|
-
if (ys.length > 0) parts.push(lines(ys, false).stroke(minor));
|
|
175
|
-
}
|
|
176
|
-
const major = this.gridStroke as StrokeResolved[];
|
|
177
|
-
if (major.length > 0) {
|
|
178
|
-
if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(major));
|
|
179
|
-
if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(major));
|
|
180
|
-
}
|
|
181
|
-
return parts;
|
|
201
|
+
const xs = between(x, map.xRange);
|
|
202
|
+
const ys = between(y, map.yRange);
|
|
203
|
+
if (xs.length > 0) parts.push(lines(xs, true).stroke(minor));
|
|
204
|
+
if (ys.length > 0) parts.push(lines(ys, false).stroke(minor));
|
|
205
|
+
}
|
|
206
|
+
const major = s.gridStroke;
|
|
207
|
+
if (major.length > 0) {
|
|
208
|
+
if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(major));
|
|
209
|
+
if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(major));
|
|
182
210
|
}
|
|
211
|
+
return parts;
|
|
183
212
|
}
|
|
184
213
|
|
|
185
214
|
const STAY: Warp = (x, y, out) => {
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
command,
|
|
2
|
+
component2d,
|
|
4
3
|
Graphics2D,
|
|
5
|
-
|
|
6
|
-
property,
|
|
7
|
-
strokeProperty,
|
|
8
|
-
type AssetScope,
|
|
4
|
+
Types,
|
|
9
5
|
type Color,
|
|
10
|
-
type Command,
|
|
11
|
-
type CommandArgs,
|
|
12
6
|
type Extents,
|
|
13
|
-
type
|
|
7
|
+
type NodeOf,
|
|
14
8
|
type NormalizedColor,
|
|
15
9
|
type PaintProps,
|
|
16
10
|
type Stroke,
|
|
17
11
|
type StrokeResolved,
|
|
12
|
+
type Values,
|
|
13
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
14
|
+
type Fill as _Fill,
|
|
15
|
+
type FillResolved as _FillResolved,
|
|
16
|
+
type Node2D as _Node2D,
|
|
17
|
+
type Node2DProps as _Node2DProps,
|
|
18
|
+
type Shadow as _Shadow,
|
|
19
|
+
type ShadowResolved as _ShadowResolved,
|
|
18
20
|
} from "@motionscript/sdk";
|
|
21
|
+
import { listed, PAINT, PAINT_COMMANDS } from "../kit/component";
|
|
19
22
|
import { cartesianMap, type CoordinateMap } from "../kit/coords";
|
|
20
23
|
import { AXIS_COLOR, drawLabels, type Label } from "../kit/furniture";
|
|
21
|
-
import {
|
|
22
|
-
import { CoordinateSystem } from "../kit/system";
|
|
24
|
+
import { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from "../kit/system";
|
|
23
25
|
import { formatTick, ticksFor } from "../kit/ticks";
|
|
24
26
|
|
|
25
27
|
export interface PolarPlaneProps extends PaintProps {
|
|
@@ -37,126 +39,125 @@ export interface PolarPlaneProps extends PaintProps {
|
|
|
37
39
|
/** How much room, in label sizes, the angles written round the outer ring take from the plane. */
|
|
38
40
|
const LABEL_ROOM = 2.2;
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* Children sit in its graph coordinates, x and y in the units its rings count,
|
|
43
|
-
* so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.
|
|
44
|
-
*/
|
|
45
|
-
@node({
|
|
46
|
-
key: "polarPlane",
|
|
47
|
-
parentKey: "node",
|
|
48
|
-
forkable: true,
|
|
49
|
-
layout: { children: "freeform", defaultWidthMode: "fixed", defaultHeightMode: "fixed", acceptsChildren: true },
|
|
50
|
-
seed: { width: 560, height: 560 },
|
|
51
|
-
})
|
|
52
|
-
export class PolarPlane extends CoordinateSystem<PolarPlaneProps> {
|
|
42
|
+
const state = {
|
|
43
|
+
...PAINT,
|
|
53
44
|
/** The radius of the outermost ring, in graph units. */
|
|
54
|
-
|
|
45
|
+
radius: Types.number(4, { min: 0.0001, step: 0.5 }),
|
|
55
46
|
/** The spacing of the rings; zero picks a tidy one for the plane's size. */
|
|
56
|
-
|
|
47
|
+
ringStep: Types.number(0, { min: 0 }),
|
|
57
48
|
/** How many spokes divide the turn; zero draws none. */
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
spokes: Types.number(12, { min: 0, max: 72, step: 1, animatable: false }),
|
|
50
|
+
angleUnit: listed(["degrees", "radians"], "degrees", { animatable: false }),
|
|
61
51
|
/** The inner rings and the spokes. */
|
|
62
|
-
|
|
63
|
-
/** The outer ring and the two lines through the origin. */
|
|
64
|
-
@strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: "center" } }) declare stroke: Stroke;
|
|
65
|
-
|
|
52
|
+
gridStroke: Types.stroke({ weight: 1.25, fill: "#3b4658", align: "center" }),
|
|
66
53
|
/** A number at each ring, and an angle at each spoke. */
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
constructor(props?: NodeConfig<PolarPlane, PolarPlaneProps>) {
|
|
73
|
-
super(props ?? {});
|
|
74
|
-
}
|
|
54
|
+
labels: Types.boolean(true, { animatable: false }),
|
|
55
|
+
labelSize: Types.number(16, { min: 1, unit: "px" }),
|
|
56
|
+
labelColor: Types.color(AXIS_COLOR),
|
|
57
|
+
fontFamily: Types.text("", { animatable: false }),
|
|
58
|
+
};
|
|
75
59
|
|
|
76
|
-
|
|
77
|
-
@command({ args: ["radius"] })
|
|
78
|
-
rangeTo(args: CommandArgs<{ radius: number }> & { duration: number }): Command<PolarPlaneProps> {
|
|
79
|
-
return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
|
|
80
|
-
}
|
|
60
|
+
type PolarValues = Values<typeof state>;
|
|
81
61
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Rings and spokes about an origin: the plane a polar curve is read on.
|
|
64
|
+
* Children sit in its graph coordinates, x and y in the units its rings count,
|
|
65
|
+
* so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.
|
|
66
|
+
*/
|
|
67
|
+
export const PolarPlane = component2d({
|
|
68
|
+
key: "polarPlane",
|
|
69
|
+
state,
|
|
70
|
+
/** The outer ring and the two lines through the origin. */
|
|
71
|
+
defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: "center" } },
|
|
72
|
+
load: (loader, s) => {
|
|
73
|
+
if (s.fontFamily !== "") loader.font(s.fontFamily);
|
|
74
|
+
},
|
|
75
|
+
commands: {
|
|
76
|
+
...PAINT_COMMANDS,
|
|
77
|
+
/** Animate how far out the plane reaches: a zoom about its origin. */
|
|
78
|
+
rangeTo: { args: ["radius"] },
|
|
79
|
+
},
|
|
80
|
+
provide: (s) => systemProvides(s),
|
|
81
|
+
measure: (_measurer, s) => systemSize(s),
|
|
82
|
+
layout: (box, s, children) => systemLayout(box, s, children, polarMap),
|
|
83
|
+
plane: (box, s) => systemOpenPlane(box, s, polarMap),
|
|
84
|
+
render: (ctx, s) => drawSystem(ctx, s, systemMap(ctx.size, s, polarMap), (map) => polarFurniture(map, s)),
|
|
85
|
+
});
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
const width = area.maxX - area.minX;
|
|
89
|
-
const height = area.maxY - area.minY;
|
|
90
|
-
// The outer ring fits the shorter side, less the room its angles are written in; units are square.
|
|
91
|
-
const reach = Math.max(1, Math.min(width, height) / 2 - (this.labels ? this.labelSize * LABEL_ROOM : 0));
|
|
92
|
-
const unit = reach / Math.max(this.radius, 1e-9);
|
|
93
|
-
return cartesianMap({
|
|
94
|
-
xRange: [-width / 2 / unit, width / 2 / unit],
|
|
95
|
-
yRange: [-height / 2 / unit, height / 2 / unit],
|
|
96
|
-
area,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
87
|
+
export type PolarPlane = NodeOf<typeof PolarPlane>;
|
|
99
88
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const size = (map.toPoint(r, 0).x - centre.x) * 2;
|
|
113
|
-
return g.ellipse({ x: centre.x, y: centre.y, width: size, height: size, start, end });
|
|
114
|
-
};
|
|
89
|
+
function polarMap(area: Extents, s: PolarValues): CoordinateMap {
|
|
90
|
+
const width = area.maxX - area.minX;
|
|
91
|
+
const height = area.maxY - area.minY;
|
|
92
|
+
// The outer ring fits the shorter side, less the room its angles are written in; units are square.
|
|
93
|
+
const reach = Math.max(1, Math.min(width, height) / 2 - (s.labels ? s.labelSize * LABEL_ROOM : 0));
|
|
94
|
+
const unit = reach / Math.max(s.radius, 1e-9);
|
|
95
|
+
return cartesianMap({
|
|
96
|
+
xRange: [-width / 2 / unit, width / 2 / unit],
|
|
97
|
+
yRange: [-height / 2 / unit, height / 2 / unit],
|
|
98
|
+
area,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
115
101
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
102
|
+
function polarFurniture(map: CoordinateMap, s: PolarValues): Graphics2D[] {
|
|
103
|
+
const stroke = s.stroke as StrokeResolved[];
|
|
104
|
+
const grid = s.gridStroke as StrokeResolved[];
|
|
105
|
+
const { start, end, radius } = s;
|
|
106
|
+
const centre = map.toPoint(0, 0);
|
|
107
|
+
const reach = map.toPoint(radius, 0).x - centre.x;
|
|
108
|
+
if (!(reach > 0)) return [];
|
|
109
|
+
const at = (r: number, degrees: number) => {
|
|
110
|
+
const angle = (degrees * Math.PI) / 180;
|
|
111
|
+
return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));
|
|
112
|
+
};
|
|
113
|
+
const ring = (g: Graphics2D, r: number): Graphics2D => {
|
|
114
|
+
const size = (map.toPoint(r, 0).x - centre.x) * 2;
|
|
115
|
+
return g.ellipse({ x: centre.x, y: centre.y, width: size, height: size, start, end });
|
|
116
|
+
};
|
|
121
117
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (degrees % 90 !== 0) inner.line({ points: [centre, at(radius, degrees)], radius: 0, start, end });
|
|
128
|
-
}
|
|
129
|
-
if (rings.length > 0 || turns.some((degrees) => degrees % 90 !== 0)) parts.push(inner.stroke(grid));
|
|
130
|
-
}
|
|
131
|
-
if (stroke.length > 0) {
|
|
132
|
-
parts.push(
|
|
133
|
-
ring(new Graphics2D(), radius)
|
|
134
|
-
.line({ points: [at(radius, 180), at(radius, 0)], radius: 0, start, end })
|
|
135
|
-
.line({ points: [at(radius, 270), at(radius, 90)], radius: 0, start, end })
|
|
136
|
-
.stroke(stroke),
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
if (!this.labels) return parts;
|
|
118
|
+
const parts: Graphics2D[] = [];
|
|
119
|
+
const marks = ticksFor([0, radius], s.ringStep, reach);
|
|
120
|
+
const rings = marks.values.filter((r) => r > 0 && r < radius * (1 - 1e-9));
|
|
121
|
+
const count = Math.round(s.spokes);
|
|
122
|
+
const turns = Array.from({ length: count }, (_, i) => (360 * i) / count);
|
|
140
123
|
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
for (const r of
|
|
144
|
-
|
|
145
|
-
labels.push({ text: formatTick(r, marks.step), at: { x: p.x - size * 0.2, y: p.y - size * 0.95 }, align: "right" });
|
|
146
|
-
}
|
|
124
|
+
if (grid.length > 0) {
|
|
125
|
+
const inner = new Graphics2D();
|
|
126
|
+
for (const r of rings) ring(inner, r);
|
|
127
|
+
// The four along the axes are drawn with them.
|
|
147
128
|
for (const degrees of turns) {
|
|
148
|
-
|
|
149
|
-
const cos = Math.cos((degrees * Math.PI) / 180);
|
|
150
|
-
const sin = Math.sin((degrees * Math.PI) / 180);
|
|
151
|
-
labels.push({
|
|
152
|
-
text: this.angleUnit === "degrees" ? `${formatTick(degrees, 1)}°` : radians(degrees),
|
|
153
|
-
at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },
|
|
154
|
-
align: cos > 0.3 ? "left" : cos < -0.3 ? "right" : "center",
|
|
155
|
-
});
|
|
129
|
+
if (degrees % 90 !== 0) inner.line({ points: [centre, at(radius, degrees)], radius: 0, start, end });
|
|
156
130
|
}
|
|
157
|
-
|
|
158
|
-
|
|
131
|
+
if (rings.length > 0 || turns.some((degrees) => degrees % 90 !== 0)) parts.push(inner.stroke(grid));
|
|
132
|
+
}
|
|
133
|
+
if (stroke.length > 0) {
|
|
134
|
+
parts.push(
|
|
135
|
+
ring(new Graphics2D(), radius)
|
|
136
|
+
.line({ points: [at(radius, 180), at(radius, 0)], radius: 0, start, end })
|
|
137
|
+
.line({ points: [at(radius, 270), at(radius, 90)], radius: 0, start, end })
|
|
138
|
+
.stroke(stroke),
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
if (!s.labels) return parts;
|
|
142
|
+
|
|
143
|
+
const size = s.labelSize;
|
|
144
|
+
const labels: Label[] = [];
|
|
145
|
+
for (const r of [...rings, radius]) {
|
|
146
|
+
const p = map.toPoint(r, 0);
|
|
147
|
+
labels.push({ text: formatTick(r, marks.step), at: { x: p.x - size * 0.2, y: p.y - size * 0.95 }, align: "right" });
|
|
148
|
+
}
|
|
149
|
+
for (const degrees of turns) {
|
|
150
|
+
const p = at(radius, degrees);
|
|
151
|
+
const cos = Math.cos((degrees * Math.PI) / 180);
|
|
152
|
+
const sin = Math.sin((degrees * Math.PI) / 180);
|
|
153
|
+
labels.push({
|
|
154
|
+
text: s.angleUnit === "degrees" ? `${formatTick(degrees, 1)}°` : radians(degrees),
|
|
155
|
+
at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },
|
|
156
|
+
align: cos > 0.3 ? "left" : cos < -0.3 ? "right" : "center",
|
|
157
|
+
});
|
|
159
158
|
}
|
|
159
|
+
parts.push(...drawLabels(labels, { fontSize: size, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));
|
|
160
|
+
return parts;
|
|
160
161
|
}
|
|
161
162
|
|
|
162
163
|
/** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */
|
package/src/tex/index.ts
CHANGED
|
@@ -11,4 +11,5 @@ export { defaultLatexMorph } from './tween';
|
|
|
11
11
|
export type { AnimatedToken, LatexMorphStrategy } from './tween';
|
|
12
12
|
|
|
13
13
|
/** The typeset-math node types, for a host that registers only these. */
|
|
14
|
-
|
|
14
|
+
// Typed by name, so the declaration names each component rather than spelling out its type through core.
|
|
15
|
+
export const TEX_NODES: (typeof Latex | typeof LatexMatrix)[] = [Latex, LatexMatrix];
|