@motionscript/math 0.1.0-alpha.9 → 0.1.1-alpha.0
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 +23 -0
- package/dist/annotate/angle-mark.d.ts +4 -14
- package/dist/annotate/angle-mark.d.ts.map +1 -1
- package/dist/annotate/angle-mark.js +2 -1
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.d.ts +4 -16
- package/dist/annotate/curly-brace.d.ts.map +1 -1
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.d.ts +0 -5
- package/dist/annotate/emphasis-mark.d.ts.map +1 -1
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/chunk-FZ2YBTPL.js +2 -0
- package/dist/browser/chunks/chunk-FZ2YBTPL.js.map +7 -0
- package/dist/browser/chunks/chunk-T42HWKBC.js +2 -0
- package/dist/browser/chunks/chunk-T42HWKBC.js.map +7 -0
- package/dist/browser/chunks/{mathjax-WV55AC2P.js → mathjax-SOM6RSPV.js} +1 -1
- package/dist/browser/chunks/{mathjax-WV55AC2P.js.map → mathjax-SOM6RSPV.js.map} +2 -2
- 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/engine.d.ts +3 -4
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +3 -4
- package/dist/engine.js.map +1 -1
- package/dist/kit/cache.d.ts +10 -21
- package/dist/kit/cache.d.ts.map +1 -1
- package/dist/kit/cache.js +33 -24
- package/dist/kit/cache.js.map +1 -1
- package/dist/kit/component.d.ts +5 -14
- package/dist/kit/component.d.ts.map +1 -1
- package/dist/kit/component.js +1 -8
- package/dist/kit/component.js.map +1 -1
- package/dist/kit/coords.d.ts +1 -1
- package/dist/kit/coords.d.ts.map +1 -1
- package/dist/kit/coords.js +2 -1
- package/dist/kit/coords.js.map +1 -1
- package/dist/kit/curve.d.ts +1 -5
- package/dist/kit/curve.d.ts.map +1 -1
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/equation.d.ts +10 -30
- package/dist/kit/equation.d.ts.map +1 -1
- package/dist/kit/equation.js +9 -44
- package/dist/kit/equation.js.map +1 -1
- package/dist/kit/equation3d.d.ts +3 -3
- package/dist/kit/equation3d.d.ts.map +1 -1
- package/dist/kit/equation3d.js +27 -59
- package/dist/kit/equation3d.js.map +1 -1
- package/dist/kit/expression.d.ts +7 -7
- package/dist/kit/expression.d.ts.map +1 -1
- package/dist/kit/expression.js +18 -17
- package/dist/kit/expression.js.map +1 -1
- package/dist/kit/field-mark.d.ts +0 -7
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/field.d.ts +2 -2
- package/dist/kit/field.d.ts.map +1 -1
- package/dist/kit/field.js +11 -31
- package/dist/kit/field.js.map +1 -1
- package/dist/kit/follow.d.ts +3 -10
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js +5 -11
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.d.ts +2 -1
- package/dist/kit/furniture.d.ts.map +1 -1
- package/dist/kit/furniture.js +6 -3
- package/dist/kit/furniture.js.map +1 -1
- package/dist/kit/geometry.d.ts +1 -0
- package/dist/kit/geometry.d.ts.map +1 -1
- package/dist/kit/geometry.js +3 -0
- package/dist/kit/geometry.js.map +1 -1
- package/dist/kit/mark.d.ts +4 -10
- package/dist/kit/mark.d.ts.map +1 -1
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/place.d.ts +3 -5
- package/dist/kit/place.d.ts.map +1 -1
- package/dist/kit/place.js +3 -5
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/sampler.d.ts +0 -5
- package/dist/kit/sampler.d.ts.map +1 -1
- package/dist/kit/sampler.js.map +1 -1
- package/dist/kit/system.d.ts +0 -1
- package/dist/kit/system.d.ts.map +1 -1
- package/dist/kit/system.js +3 -10
- package/dist/kit/system.js.map +1 -1
- package/dist/marks/curve-area.d.ts +2 -12
- package/dist/marks/curve-area.d.ts.map +1 -1
- package/dist/marks/curve-area.js +4 -9
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.d.ts +1 -5
- package/dist/marks/drop-lines.d.ts.map +1 -1
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.d.ts +4 -13
- package/dist/marks/plot-point.d.ts.map +1 -1
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.d.ts +1 -7
- package/dist/marks/riemann-sum.d.ts.map +1 -1
- package/dist/marks/riemann-sum.js +2 -2
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.d.ts +2 -12
- package/dist/marks/tangent-line.d.ts.map +1 -1
- package/dist/marks/tangent-line.js +1 -5
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.d.ts +2 -11
- package/dist/marks/vector-arrow.d.ts.map +1 -1
- package/dist/marks/vector-arrow.js +3 -6
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.d.ts +1 -12
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts +1 -6
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js +1 -5
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.d.ts +1 -6
- package/dist/plots/points-plot.d.ts.map +1 -1
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.d.ts +0 -7
- package/dist/plots/stream-lines.d.ts.map +1 -1
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.d.ts +1 -12
- package/dist/plots/traced-path.d.ts.map +1 -1
- package/dist/plots/traced-path.js +1 -6
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.d.ts +1 -10
- package/dist/plots/vector-field.d.ts.map +1 -1
- package/dist/plots/vector-field.js +3 -6
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/network-graph.d.ts +15 -34
- package/dist/structures/network-graph.d.ts.map +1 -1
- package/dist/structures/network-graph.js +2 -5
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.d.ts +8 -22
- package/dist/structures/sample-space.d.ts.map +1 -1
- package/dist/structures/sample-space.js +3 -5
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts +0 -1
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js +3 -4
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.d.ts +7 -22
- package/dist/systems/number-line.d.ts.map +1 -1
- package/dist/systems/number-line.js +2 -2
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.d.ts +12 -27
- package/dist/systems/number-plane.d.ts.map +1 -1
- package/dist/systems/number-plane.js +1 -7
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.d.ts +11 -26
- package/dist/systems/polar-plane.d.ts.map +1 -1
- package/dist/systems/polar-plane.js +7 -10
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/geometry.d.ts +5 -24
- package/dist/tex/geometry.d.ts.map +1 -1
- package/dist/tex/geometry.js +19 -90
- package/dist/tex/geometry.js.map +1 -1
- package/dist/tex/mathjax.d.ts +0 -13
- package/dist/tex/mathjax.d.ts.map +1 -1
- package/dist/tex/mathjax.js +4 -24
- package/dist/tex/mathjax.js.map +1 -1
- package/dist/tex/matrix.d.ts +1 -10
- package/dist/tex/matrix.d.ts.map +1 -1
- package/dist/tex/matrix.js +1 -5
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/tween.d.ts +9 -30
- package/dist/tex/tween.d.ts.map +1 -1
- package/dist/tex/tween.js +19 -67
- package/dist/tex/tween.js.map +1 -1
- package/dist/tex/typeset.d.ts +2 -23
- package/dist/tex/typeset.d.ts.map +1 -1
- package/dist/tex/typeset.js +4 -30
- package/dist/tex/typeset.js.map +1 -1
- package/dist/three/axes3d.d.ts +32 -62
- package/dist/three/axes3d.d.ts.map +1 -1
- package/dist/three/axes3d.js +5 -13
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +4 -15
- package/dist/three/curve-plot3d.d.ts.map +1 -1
- package/dist/three/curve-plot3d.js.map +1 -1
- package/dist/three/plot-point3d.d.ts +7 -14
- package/dist/three/plot-point3d.d.ts.map +1 -1
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.d.ts +3 -8
- package/dist/three/space.d.ts.map +1 -1
- package/dist/three/space.js +1 -8
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.d.ts +9 -23
- package/dist/three/surface-plot3d.d.ts.map +1 -1
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.d.ts +1 -7
- package/dist/three/vector-arrow3d.d.ts.map +1 -1
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +4 -4
- package/src/annotate/angle-mark.ts +4 -14
- package/src/annotate/curly-brace.ts +2 -14
- package/src/annotate/emphasis-mark.ts +1 -6
- package/src/engine.ts +3 -4
- package/src/kit/cache.ts +33 -25
- package/src/kit/component.ts +5 -19
- package/src/kit/coords.ts +2 -2
- package/src/kit/curve.ts +1 -5
- package/src/kit/equation.ts +12 -50
- package/src/kit/equation3d.ts +23 -59
- package/src/kit/expression.ts +18 -23
- package/src/kit/field-mark.ts +1 -7
- package/src/kit/field.ts +10 -26
- package/src/kit/follow.ts +5 -13
- package/src/kit/furniture.ts +7 -4
- package/src/kit/geometry.ts +4 -0
- package/src/kit/mark.ts +4 -11
- package/src/kit/place.ts +3 -5
- package/src/kit/sampler.ts +0 -6
- package/src/kit/system.ts +3 -12
- package/src/marks/curve-area.ts +3 -16
- package/src/marks/drop-lines.ts +0 -6
- package/src/marks/plot-point.ts +2 -12
- package/src/marks/riemann-sum.ts +2 -10
- package/src/marks/tangent-line.ts +1 -13
- package/src/marks/vector-arrow.ts +3 -13
- package/src/nodes.ts +1 -12
- package/src/plots/function-plot.ts +1 -6
- package/src/plots/points-plot.ts +0 -7
- package/src/plots/stream-lines.ts +1 -8
- package/src/plots/traced-path.ts +2 -13
- package/src/plots/vector-field.ts +4 -12
- package/src/structures/network-graph.ts +6 -25
- package/src/structures/sample-space.ts +5 -20
- package/src/systems/axes2d.ts +3 -6
- package/src/systems/number-line.ts +4 -20
- package/src/systems/number-plane.ts +4 -19
- package/src/systems/polar-plane.ts +11 -25
- package/src/tex/geometry.ts +24 -126
- package/src/tex/mathjax.ts +4 -26
- package/src/tex/matrix.ts +1 -11
- package/src/tex/tween.ts +21 -75
- package/src/tex/typeset.ts +4 -37
- package/src/three/axes3d.ts +7 -42
- package/src/three/curve-plot3d.ts +0 -12
- package/src/three/plot-point3d.ts +0 -10
- package/src/three/space.ts +2 -11
- package/src/three/surface-plot3d.ts +0 -15
- package/src/three/vector-arrow3d.ts +0 -8
- package/dist/browser/chunks/chunk-IRZCG6PM.js +0 -2
- package/dist/browser/chunks/chunk-IRZCG6PM.js.map +0 -7
- package/dist/browser/chunks/chunk-WMVW6ZIV.js +0 -2
- package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +0 -7
- package/dist/kit/withdrawn.d.ts +0 -9
- package/dist/kit/withdrawn.d.ts.map +0 -1
- package/dist/kit/withdrawn.js +0 -9
- package/dist/kit/withdrawn.js.map +0 -1
- package/src/kit/withdrawn.ts +0 -8
package/dist/three/space.js
CHANGED
|
@@ -22,10 +22,7 @@ function unit([min, max], length) {
|
|
|
22
22
|
}
|
|
23
23
|
/** The graph a mark is inside: `axes3d` provides itself to everything in it. */
|
|
24
24
|
export const GRAPH_3D = createContext(null, "math:graph3d");
|
|
25
|
-
/**
|
|
26
|
-
* The entry a mark reads the graph it is drawn in through, set from the nearest
|
|
27
|
-
* `axes3d` above it, through any 3D node between; `null` outside one.
|
|
28
|
-
*/
|
|
25
|
+
/** The entry a mark reads its graph through, set from the nearest `axes3d` above it; `null` outside one. */
|
|
29
26
|
export function graphEntry() {
|
|
30
27
|
return Types.custom(null, {
|
|
31
28
|
private: true,
|
|
@@ -36,10 +33,6 @@ export function graphEntry() {
|
|
|
36
33
|
export function graphOf(mark) {
|
|
37
34
|
return mark.graph?.space() ?? null;
|
|
38
35
|
}
|
|
39
|
-
/** The graph a 3D node is drawn in: what the nearest `axes3d` above it provides, once it is in the tree. */
|
|
40
|
-
export function spaceOf(mark) {
|
|
41
|
-
return mark.useContext(GRAPH_3D)?.space() ?? null;
|
|
42
|
-
}
|
|
43
36
|
/** A unit quaternion turning the scene's +y, the way a cylinder or a cone points, onto `direction`. */
|
|
44
37
|
export function aim(direction) {
|
|
45
38
|
const length = Math.hypot(direction.x, direction.y, direction.z);
|
package/dist/three/space.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"space.js","sourceRoot":"","sources":["../../src/three/space.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,KAAK,
|
|
1
|
+
{"version":3,"file":"space.js","sourceRoot":"","sources":["../../src/three/space.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,KAAK,GAMR,MAAM,mBAAmB,CAAC;AAkB3B,6GAA6G;AAC7G,MAAM,UAAU,UAAU,CAAC,MAAgB,EAAE,MAAgB,EAAE,MAAgB,EAAE,OAAgB;IAC7F,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,GA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AAC,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC;AAC9D,CAAC","sourcesContent":["import {\n createContext,\n Types,\n type ChildSpace3D,\n type Type,\n type Vector3,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Context as _Context,\n} from \"@motionscript/sdk\";\nimport type { Interval } from \"../kit/coords\";\n\n/**\n * A 3D graph's coordinates, as its axes' local space sees them. A graph is\n * right-handed with z up, and the scene has y up, so graph x, y and z run along\n * the scene's z, x and y: looked at head-on, y is to the right and z is up.\n */\nexport interface GraphSpace extends ChildSpace3D {\n readonly xRange: Interval;\n readonly yRange: Interval;\n readonly zRange: Interval;\n /** Changes exactly when the mapping does: what a mark's geometry is cached under. */\n readonly revision: string;\n /** A graph step as a local one: what a mark's own geometry is drawn in. */\n offset(x: number, y: number, z: number): Vector3;\n}\n\n/** The space of a box `lengths` on a side, in scene units, showing the three ranges, centred on its node. */\nexport function graphSpace(xRange: Interval, yRange: Interval, zRange: Interval, lengths: Vector3): GraphSpace {\n const ux = unit(xRange, lengths.x);\n const uy = unit(yRange, lengths.y);\n const uz = unit(zRange, lengths.z);\n const cx = (xRange[0] + xRange[1]) / 2;\n const cy = (yRange[0] + yRange[1]) / 2;\n const cz = (zRange[0] + zRange[1]) / 2;\n return {\n xRange,\n yRange,\n zRange,\n revision: [xRange, yRange, zRange, lengths.x, lengths.y, lengths.z].join(\"|\"),\n toLocal: (x, y, z) => ({ x: (y - cy) * uy, y: (z - cz) * uz, z: (x - cx) * ux }),\n offset: (x, y, z) => ({ x: y * uy, y: z * uz, z: x * ux }),\n };\n}\n\nfunction unit([min, max]: Interval, length: number): number {\n const span = max - min;\n return span > 0 ? length / span : 0;\n}\n\n/** A 3D graph, as the marks inside it see it: its coordinates as they stand now. */\nexport interface Graph3D {\n space(): GraphSpace;\n}\n\n/** The graph a mark is inside: `axes3d` provides itself to everything in it. */\nexport const GRAPH_3D = createContext<Graph3D | null>(null, \"math:graph3d\");\n\n/** The entry a mark reads its graph through, set from the nearest `axes3d` above it; `null` outside one. */\nexport function graphEntry(): Type<Graph3D | null, Graph3D | null, true> {\n return Types.custom<Graph3D | null, Graph3D | null, { readonly private: true }>(null, {\n private: true,\n inherit: (use) => use(GRAPH_3D),\n });\n}\n\n/** The graph space a mark with a {@link graphEntry} is drawn in, or `null` outside a graph. */\nexport function graphOf(mark: { readonly graph: Graph3D | null }): GraphSpace | null {\n return mark.graph?.space() ?? null;\n}\n\n/** A unit quaternion turning the scene's +y, the way a cylinder or a cone points, onto `direction`. */\nexport function aim(direction: Vector3): { x: number; y: number; z: number; w: number } {\n const length = Math.hypot(direction.x, direction.y, direction.z);\n if (!(length > 0)) return { x: 0, y: 0, z: 0, w: 1 };\n const dx = direction.x / length;\n const dy = direction.y / length;\n const dz = direction.z / length;\n // Straight down is the one turn with no single axis: any in the ground plane will do.\n if (dy < -1 + 1e-9) return { x: 1, y: 0, z: 0, w: 0 };\n const w = 1 + dy;\n const norm = Math.hypot(dz, dx, w);\n return { x: dz / norm, y: 0, z: -dx / norm, w: w / norm };\n}\n"]}
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import { type Color, type Geometry3D, type Material3D, type
|
|
2
|
-
import type { Interval } from "../kit/coords.js";
|
|
3
|
-
import type { ExpressionScope } from "../kit/expression.js";
|
|
1
|
+
import { type Color, type Geometry3D, type Material3D, type NodeOf, type NormalizedColor, type Values, type Blend3D as _Blend3D, type Faces3D as _Faces3D, type Fill3D as _Fill3D, type Node3D as _Node3D, type Node3DProps as _Node3DProps, type Shading3D as _Shading3D, type Texture3D as _Texture3D } from "@motionscript/sdk";
|
|
4
2
|
import { type PlotSource } from "../kit/source.js";
|
|
5
|
-
export interface SurfacePlot3dProps extends Mesh3DProps {
|
|
6
|
-
expression?: string | PlotSource;
|
|
7
|
-
uDomain?: Interval | null;
|
|
8
|
-
vDomain?: Interval | null;
|
|
9
|
-
params?: ExpressionScope;
|
|
10
|
-
segments?: number;
|
|
11
|
-
colorScale?: Color[];
|
|
12
|
-
meshLines?: number;
|
|
13
|
-
meshColor?: Color;
|
|
14
|
-
floorShadow?: number;
|
|
15
|
-
}
|
|
16
3
|
declare const state: {
|
|
17
4
|
expression: import("@motionscript/sdk").Type<string | PlotSource, PlotSource, false>;
|
|
18
5
|
/**
|
|
@@ -20,8 +7,8 @@ declare const state: {
|
|
|
20
7
|
* the width of the axes when left out, u and v for a parametric surface,
|
|
21
8
|
* which run from 0 to 1.
|
|
22
9
|
*/
|
|
23
|
-
uDomain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
|
|
24
|
-
vDomain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
|
|
10
|
+
uDomain: import("@motionscript/sdk").Type<import("../index.js").Interval | null, import("../index.js").Interval | null, false>;
|
|
11
|
+
vDomain: import("@motionscript/sdk").Type<import("../index.js").Interval | null, import("../index.js").Interval | null, false>;
|
|
25
12
|
/** The equation's named values: any name in it that is not a variable, a function or a constant. */
|
|
26
13
|
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
27
14
|
/** How finely the surface is sampled, each way. */
|
|
@@ -55,7 +42,6 @@ declare const state: {
|
|
|
55
42
|
vertexColors: import("@motionscript/sdk").Type<boolean | undefined, boolean | undefined, false>;
|
|
56
43
|
unlit: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
57
44
|
};
|
|
58
|
-
/** What a surface is drawn from: its own entries, as its node and its helpers read them. */
|
|
59
45
|
export type SurfaceValues = Values<typeof state> & {
|
|
60
46
|
readonly x: number;
|
|
61
47
|
readonly y: number;
|
|
@@ -72,8 +58,8 @@ export declare const SurfacePlot3d: import("@motionscript/sdk").Component<"surfa
|
|
|
72
58
|
* the width of the axes when left out, u and v for a parametric surface,
|
|
73
59
|
* which run from 0 to 1.
|
|
74
60
|
*/
|
|
75
|
-
uDomain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
|
|
76
|
-
vDomain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
|
|
61
|
+
uDomain: import("@motionscript/sdk").Type<import("../index.js").Interval | null, import("../index.js").Interval | null, false>;
|
|
62
|
+
vDomain: import("@motionscript/sdk").Type<import("../index.js").Interval | null, import("../index.js").Interval | null, false>;
|
|
77
63
|
/** The equation's named values: any name in it that is not a variable, a function or a constant. */
|
|
78
64
|
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
79
65
|
/** How finely the surface is sampled, each way. */
|
|
@@ -117,8 +103,8 @@ export declare const SurfacePlot3d: import("@motionscript/sdk").Component<"surfa
|
|
|
117
103
|
* the width of the axes when left out, u and v for a parametric surface,
|
|
118
104
|
* which run from 0 to 1.
|
|
119
105
|
*/
|
|
120
|
-
uDomain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
|
|
121
|
-
vDomain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
|
|
106
|
+
uDomain: import("@motionscript/sdk").Type<import("../index.js").Interval | null, import("../index.js").Interval | null, false>;
|
|
107
|
+
vDomain: import("@motionscript/sdk").Type<import("../index.js").Interval | null, import("../index.js").Interval | null, false>;
|
|
122
108
|
/** The equation's named values: any name in it that is not a variable, a function or a constant. */
|
|
123
109
|
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
124
110
|
/** How finely the surface is sampled, each way. */
|
|
@@ -158,8 +144,8 @@ export declare const SurfacePlot3d: import("@motionscript/sdk").Component<"surfa
|
|
|
158
144
|
* the width of the axes when left out, u and v for a parametric surface,
|
|
159
145
|
* which run from 0 to 1.
|
|
160
146
|
*/
|
|
161
|
-
uDomain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
|
|
162
|
-
vDomain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
|
|
147
|
+
uDomain: import("@motionscript/sdk").Type<import("../index.js").Interval | null, import("../index.js").Interval | null, false>;
|
|
148
|
+
vDomain: import("@motionscript/sdk").Type<import("../index.js").Interval | null, import("../index.js").Interval | null, false>;
|
|
163
149
|
/** The equation's named values: any name in it that is not a variable, a function or a constant. */
|
|
164
150
|
params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
|
|
165
151
|
/** How finely the surface is sampled, each way. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface-plot3d.d.ts","sourceRoot":"","sources":["../../src/three/surface-plot3d.ts"],"names":[],"mappings":"AAAA,OAAO,EASH,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,
|
|
1
|
+
{"version":3,"file":"surface-plot3d.d.ts","sourceRoot":"","sources":["../../src/three/surface-plot3d.ts"],"names":[],"mappings":"AAAA,OAAO,EASH,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,MAAM,EAGX,KAAK,OAAO,IAAI,QAAQ,EAExB,KAAK,OAAO,IAAI,QAAQ,EACxB,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAEhC,KAAK,SAAS,IAAI,UAAU,EAC5B,KAAK,SAAS,IAAI,UAAU,EAC/B,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAA4D,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAO1G,QAAA,MAAM,KAAK;;IAOP;;;;OAIG;;;IAGH,oGAAoG;;IAEpG,mDAAmD;;IAEnD,qGAAqG;;IAErG,iFAAiF;;;IAGjF,uHAAuH;;;;;;;;;;;;;;;;;;;;;;;CAG1H,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,KAAK,CAAC,GAAG;IAAE,QAAQ,CAAC,CAAC,EAA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AAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,UAAU,CAAC,MAAc;IAC9B,MAAM,QAAQ,GAAG,YAAY,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7D,OAAO,QAAQ,YAAY,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;AACvD,CAAC;AAED,sEAAsE;AACtE,SAAS,MAAM,CAAC,KAAa;IACzB,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,YAAY,CACjB,QAA4C,EAC5C,MAA4C;IAE5C,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAE,QAAkC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAsB,CAAC,CAAC;AACtH,CAAC","sourcesContent":["import {\n colorOps,\n component3d,\n Geo,\n Graphics3D,\n Mat,\n Material,\n Types,\n type ChildSpace3D,\n type Color,\n type Geometry3D,\n type Material3D,\n type Mesh3DProps,\n type NodeOf,\n type NormalizedColor,\n type Values,\n type Vector3,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Blend3D as _Blend3D,\n type Color as _Color,\n type Faces3D as _Faces3D,\n type Fill3D as _Fill3D,\n type Node3D as _Node3D,\n type Node3DProps as _Node3DProps,\n type NormalizedColor as _NormalizedColor,\n type Shading3D as _Shading3D,\n type Texture3D as _Texture3D,\n} from \"@motionscript/sdk\";\nimport type { Interval } from \"../kit/coords\";\nimport { parseSurface, surfaceParams, type SurfaceEquation } from \"../kit/equation3d\";\nimport type { ExpressionScope } from \"../kit/expression\";\nimport { PLOT_COLOR } from \"../kit/furniture\";\nimport { clamp } from \"../kit/geometry\";\nimport { colorAt, lerpScale, readScale } from \"../kit/scale\";\nimport { lerpParams, lerpSource, readSource, revisionOf, scopeFor, type PlotSource } from \"../kit/source\";\nimport { domainEntry, meshEntries } from \"./entries\";\nimport { graphEntry, graphOf, type GraphSpace } from \"./space\";\n\nexport interface SurfacePlot3dProps extends Mesh3DProps {\n expression?: string | PlotSource;\n uDomain?: Interval | null;\n vDomain?: Interval | null;\n params?: ExpressionScope;\n segments?: number;\n colorScale?: Color[];\n meshLines?: number;\n meshColor?: Color;\n floorShadow?: number;\n}\n\n/** A graph point for grid coordinate `(u, v)`, both 0 to 1, written into `out`. */\ntype SurfaceSampler = (u: number, v: number, out: Vector3) => void;\n\nconst state = {\n ...meshEntries,\n expression: Types.custom<string | PlotSource, PlotSource>(\"\", {\n resolve: readSource,\n lerp: lerpSource,\n kind: \"surfaceEquation\",\n }),\n /**\n * The span of each variable that is drawn: x and y for a height, which run\n * the width of the axes when left out, u and v for a parametric surface,\n * which run from 0 to 1.\n */\n uDomain: domainEntry(-3, 3),\n vDomain: domainEntry(-3, 3),\n /** The equation's named values: any name in it that is not a variable, a function or a constant. */\n params: Types.custom<ExpressionScope>({}, { lerp: lerpParams }),\n /** How finely the surface is sampled, each way. */\n segments: Types.number(48, { min: 2, max: 256, step: 1, animatable: false }),\n /** Colours by height, lowest first, over the axes' z range. Empty paints the surface in its fill. */\n colorScale: Types.custom<Color[], NormalizedColor[]>([], { resolve: readScale, lerp: lerpScale, kind: \"vector\" }),\n /** How many lines are drawn across the surface each way; zero leaves it bare. */\n meshLines: Types.number(12, { min: 0, max: 64, step: 1, animatable: false }),\n meshColor: Types.custom<Color, Color>(\"#0b1220\", { kind: \"color\" }),\n /** The opacity of the surface's shadow, laid flat on the floor of the axes and coloured by height; zero draws none. */\n floorShadow: Types.number(0, { min: 0, max: 1, step: 0.01 }),\n graph: graphEntry(),\n};\n\n/** What a surface is drawn from: its own entries, as its node and its helpers read them. */\nexport type SurfaceValues = Values<typeof state> & { readonly x: number; readonly y: number; readonly z: number };\n\n/**\n * A surface in a 3D graph: a height over x and y (`sin(x) * cos(y)`), or three\n * parts in u and v. A point put inside it rides it.\n */\nexport const SurfacePlot3d = component3d({\n key: \"surfacePlot3d\",\n state,\n defaults: { fill: PLOT_COLOR },\n commands: {\n /** Change the equation, the surface bending from the one into the other. */\n morphTo: { args: [\"expression\"] },\n /** Animate the equation's named values. */\n paramsTo: { args: [\"params\"] },\n /** Animate the spans that are drawn. */\n domainTo: { args: [\"uDomain\", \"vDomain\"] },\n },\n space: (s) => surfaceSpace(s),\n render: (ctx, s) => ctx.draw(ctx.declaring ? declaredSurface(s) : drawSurface(s)),\n});\n\nexport type SurfacePlot3d = NodeOf<typeof SurfacePlot3d>;\n\n/**\n * The surface's height above its own origin at graph `(x, y)`, or `NaN`\n * where it has none or is not a height. What a point riding it reads.\n */\nexport function surfaceValueAt(surface: Pick<SurfaceValues, \"expression\" | \"params\">, x: number, y: number): number {\n const { source, blend } = surface.expression;\n const value = heightOf(surface, source, x, y);\n if (!blend) return value;\n const from = heightOf(surface, blend.from, x, y);\n return from + (value - from) * blend.t;\n}\n\n/** A point inside a surface stands on it: its `x` and `y` say where, and its height is the surface's. */\nfunction surfaceSpace(s: SurfaceValues): ChildSpace3D | null {\n const space = graphOf(s);\n if (!space) return null;\n return {\n toLocal: (x, y, z) => {\n const height = surfaceValueAt(s, x, y);\n return space.offset(x, y, Number.isFinite(height) ? height : z);\n },\n };\n}\n\n/** Its paint on a stand-in: only a material loads, and reading no equation keeps a morph from re-declaring. */\nfunction declaredSurface(s: SurfaceValues): Graphics3D {\n const paint = Material.shorthand(s);\n return new Graphics3D().plane(s.colorScale.length > 0 ? { ...paint, fill: \"white\" } : paint);\n}\n\nfunction drawSurface(s: SurfaceValues): Graphics3D {\n const g3 = new Graphics3D();\n const space = graphOf(s);\n const lines = space ? meshLines(s, space) : [];\n const scaled = s.colorScale.length > 0;\n // A surface is seen from both sides; a vertex colour multiplies the fill, so a scale is shown on white.\n const surface = { ...s, faces: s.faces ?? \"both\", ...(scaled ? { vertexColors: true, fill: \"white\" } : {}) };\n for (const op of Material.mesh(surface, space ? surfaceGeometry(s, space) : undefined).ops()) {\n if (op.kind !== \"mesh\") continue;\n g3.mesh(op.geometry, mapMaterials(op.material, (material) => ({\n ...material,\n // Pushed back a hair so the lines drawn on it are not fought for, and blended rather than a hole when faded.\n ...(lines.length > 0 ? { polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 } : {}),\n ...((s.opacity ?? 1) < 1 ? { depthWrite: false } : {}),\n } as Material3D)), op.transform);\n }\n if (lines.length > 0) {\n const color = colorOps.resolve(s.meshColor);\n g3.line({ points: lines, segments: true, stroke: { fill: color }, opacity: color[3] * (s.opacity ?? 1) });\n }\n const shadow = space && s.floorShadow > 0 ? floorShadow(s, space) : undefined;\n if (shadow) {\n g3.mesh(shadow, Mat.basic({\n color: scaled ? \"white\" : PLOT_COLOR,\n vertexColors: scaled,\n opacity: s.floorShadow * (s.opacity ?? 1),\n transparent: true,\n // Translucent and under everything: writing depth would hide the floor's grid lines behind it.\n depthWrite: false,\n faces: \"both\",\n }));\n }\n return g3;\n}\n\nfunction surfaceGeometry(s: SurfaceValues, space: GraphSpace): Geometry3D | undefined {\n const sample = sampler(s, space);\n if (!sample) return undefined;\n const scale = s.colorScale;\n const point: Vector3 = { x: 0, y: 0, z: 0 };\n const low = space.offset(0, 0, space.zRange[0] - s.z).y;\n const high = space.offset(0, 0, space.zRange[1] - s.z).y;\n return Geo.parametric({\n segments: Math.max(2, Math.round(s.segments)),\n vertex: (u, v) => {\n sample(u, v, point);\n return space.offset(point.x, point.y, point.z);\n },\n ...(scale.length > 0\n ? { color: (_u, _v, position) => colorAt(scale, high > low ? (position.y - low) / (high - low) : 0) }\n : {}),\n computeNormals: true,\n revision: revisionOf(`${keyOf(s, space)}|${JSON.stringify(scale)}`),\n });\n}\n\nfunction heightOf(surface: Pick<SurfaceValues, \"params\">, source: string, x: number, y: number): number {\n const equation = equationOf(source);\n if (equation?.kind !== \"height\") return NaN;\n return equation.f(x, y, scopeFor(surfaceParams(source), surface.params));\n}\n\nfunction keyOf(s: SurfaceValues, space: GraphSpace): string {\n const { source, blend } = s.expression;\n return [source, blend?.from, blend?.t, space.revision, s.uDomain, s.vDomain, JSON.stringify(s.params), s.x, s.y, s.z].join(\"|\");\n}\n\nfunction sampler(s: SurfaceValues, space: GraphSpace): SurfaceSampler | null {\n const { source, blend } = s.expression;\n const to = surfaceOf(s, source, space);\n if (!to || !blend) return to;\n const from = surfaceOf(s, blend.from, space);\n if (!from) return to;\n const start: Vector3 = { x: 0, y: 0, z: 0 };\n return (u, v, out) => {\n from(u, v, start);\n to(u, v, out);\n out.x = start.x + (out.x - start.x) * blend.t;\n out.y = start.y + (out.y - start.y) * blend.t;\n out.z = start.z + (out.z - start.z) * blend.t;\n };\n}\n\n/** `source` as graph points, measured from the surface's own position. */\nfunction surfaceOf(s: SurfaceValues, source: string, space: GraphSpace): SurfaceSampler | null {\n const equation = equationOf(source);\n if (!equation) return null;\n const params = scopeFor(surfaceParams(source), s.params);\n if (equation.kind === \"parametric\") {\n const [u0, u1] = s.uDomain ?? [0, 1];\n const [v0, v1] = s.vDomain ?? [0, 1];\n const { x, y, z } = equation;\n return (u, v, out) => {\n const a = u0 + (u1 - u0) * u;\n const b = v0 + (v1 - v0) * v;\n out.x = finite(x(a, b, params));\n out.y = finite(y(a, b, params));\n out.z = finite(z(a, b, params));\n };\n }\n const [x0, x1] = s.uDomain ?? [space.xRange[0] - s.x, space.xRange[1] - s.x];\n const [y0, y1] = s.vDomain ?? [space.yRange[0] - s.y, space.yRange[1] - s.y];\n // Held inside the axes: a pole would otherwise stretch one triangle across the scene.\n const low = space.zRange[0] - s.z;\n const high = space.zRange[1] - s.z;\n const { f } = equation;\n return (u, v, out) => {\n out.x = x0 + (x1 - x0) * u;\n out.y = y0 + (y1 - y0) * v;\n out.z = clamp(finite(f(out.x, out.y, params)), low, high);\n };\n}\n\nfunction floorShadow(s: SurfaceValues, space: GraphSpace): Geometry3D | undefined {\n const sample = sampler(s, space);\n if (!sample) return undefined;\n const scale = s.colorScale;\n const [low, high] = space.zRange;\n const floor = low - s.z;\n const point: Vector3 = { x: 0, y: 0, z: 0 };\n return Geo.parametric({\n segments: Math.max(2, Math.round(s.segments)),\n vertex: (u, v) => {\n sample(u, v, point);\n return space.offset(point.x, point.y, floor);\n },\n ...(scale.length > 0\n ? {\n color: (u: number, v: number) => {\n sample(u, v, point);\n return colorAt(scale, high > low ? (point.z + s.z - low) / (high - low) : 0);\n },\n }\n : {}),\n revision: revisionOf(`${keyOf(s, space)}|${JSON.stringify(scale)}|floor`),\n });\n}\n\n/** The last lines drawn for each surface, kept while what they are drawn from is unchanged. */\nconst linesDrawn = new WeakMap<object, { readonly key: string; readonly lines: Vector3[] }>();\n\nfunction meshLines(s: SurfaceValues, space: GraphSpace): Vector3[] {\n const count = Math.round(s.meshLines);\n const sample = count > 0 ? sampler(s, space) : null;\n if (!sample) return [];\n const steps = Math.max(2, Math.round(s.segments));\n const key = `${keyOf(s, space)}|${count}|${steps}`;\n const kept = linesDrawn.get(s);\n if (kept?.key === key) return kept.lines;\n const lines: Vector3[] = [];\n const point: Vector3 = { x: 0, y: 0, z: 0 };\n const at = (u: number, v: number): Vector3 => {\n sample(u, v, point);\n return space.offset(point.x, point.y, point.z);\n };\n for (let i = 0; i <= count; i++) {\n const fixed = i / count;\n for (let j = 0; j < steps; j++) {\n lines.push(at(fixed, j / steps), at(fixed, (j + 1) / steps));\n lines.push(at(j / steps, fixed), at((j + 1) / steps, fixed));\n }\n }\n linesDrawn.set(s, { key, lines });\n return lines;\n}\n\nfunction equationOf(source: string): SurfaceEquation | null {\n const equation = parseSurface(source, surfaceParams(source));\n return equation instanceof Error ? null : equation;\n}\n\n// A hole in the data is drawn flat rather than as a hole in the mesh.\nfunction finite(value: number): number {\n return Number.isFinite(value) ? value : 0;\n}\n\nfunction mapMaterials(\n material: Material3D | readonly Material3D[],\n change: (material: Material3D) => Material3D,\n): Material3D | readonly Material3D[] {\n return Array.isArray(material) ? (material as readonly Material3D[]).map(change) : change(material as Material3D);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"surface-plot3d.js","sourceRoot":"","sources":["../../src/three/surface-plot3d.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,WAAW,EACX,GAAG,EACH,UAAU,EACV,GAAG,EACH,QAAQ,EACR,KAAK,GAmBR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAwB,MAAM,mBAAmB,CAAC;AAEtF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAmB,MAAM,eAAe,CAAC;AAC1G,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAmB,MAAM,SAAS,CAAC;AAK/D,MAAM,KAAK,GAAG;IACV,GAAG,WAAW;IACd,UAAU,EAAE,KAAK,CAAC,MAAM,CAAkC,EAAE,EAAE;QAC1D,OAAO,EAAE,UAAU;QACnB,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,iBAAiB;KAC1B,CAAC;IACF;;;;OAIG;IACH,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC3B,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC3B,oGAAoG;IACpG,MAAM,EAAE,KAAK,CAAC,MAAM,CAAkB,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;IAC/D,mDAAmD;IACnD,QAAQ,EAAE,KAAK,CAAC,MA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ildSpace3D,\n type Color,\n type Geometry3D,\n type Material3D,\n type NodeOf,\n type NormalizedColor,\n type Values,\n type Vector3,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Blend3D as _Blend3D,\n type Color as _Color,\n type Faces3D as _Faces3D,\n type Fill3D as _Fill3D,\n type Node3D as _Node3D,\n type Node3DProps as _Node3DProps,\n type NormalizedColor as _NormalizedColor,\n type Shading3D as _Shading3D,\n type Texture3D as _Texture3D,\n} from \"@motionscript/sdk\";\nimport { parseSurface, surfaceParams, type SurfaceEquation } from \"../kit/equation3d\";\nimport type { ExpressionScope } from \"../kit/expression\";\nimport { PLOT_COLOR } from \"../kit/furniture\";\nimport { clamp } from \"../kit/geometry\";\nimport { colorAt, lerpScale, readScale } from \"../kit/scale\";\nimport { lerpParams, lerpSource, readSource, revisionOf, scopeFor, type PlotSource } from \"../kit/source\";\nimport { domainEntry, meshEntries } from \"./entries\";\nimport { graphEntry, graphOf, type GraphSpace } from \"./space\";\n\n/** A graph point for grid coordinate `(u, v)`, both 0 to 1, written into `out`. */\ntype SurfaceSampler = (u: number, v: number, out: Vector3) => void;\n\nconst state = {\n ...meshEntries,\n expression: Types.custom<string | PlotSource, PlotSource>(\"\", {\n resolve: readSource,\n lerp: lerpSource,\n kind: \"surfaceEquation\",\n }),\n /**\n * The span of each variable that is drawn: x and y for a height, which run\n * the width of the axes when left out, u and v for a parametric surface,\n * which run from 0 to 1.\n */\n uDomain: domainEntry(-3, 3),\n vDomain: domainEntry(-3, 3),\n /** The equation's named values: any name in it that is not a variable, a function or a constant. */\n params: Types.custom<ExpressionScope>({}, { lerp: lerpParams }),\n /** How finely the surface is sampled, each way. */\n segments: Types.number(48, { min: 2, max: 256, step: 1, animatable: false }),\n /** Colours by height, lowest first, over the axes' z range. Empty paints the surface in its fill. */\n colorScale: Types.custom<Color[], NormalizedColor[]>([], { resolve: readScale, lerp: lerpScale, kind: \"vector\" }),\n /** How many lines are drawn across the surface each way; zero leaves it bare. */\n meshLines: Types.number(12, { min: 0, max: 64, step: 1, animatable: false }),\n meshColor: Types.custom<Color, Color>(\"#0b1220\", { kind: \"color\" }),\n /** The opacity of the surface's shadow, laid flat on the floor of the axes and coloured by height; zero draws none. */\n floorShadow: Types.number(0, { min: 0, max: 1, step: 0.01 }),\n graph: graphEntry(),\n};\n\nexport type SurfaceValues = Values<typeof state> & { readonly x: number; readonly y: number; readonly z: number };\n\n/**\n * A surface in a 3D graph: a height over x and y (`sin(x) * cos(y)`), or three\n * parts in u and v. A point put inside it rides it.\n */\nexport const SurfacePlot3d = component3d({\n key: \"surfacePlot3d\",\n state,\n defaults: { fill: PLOT_COLOR },\n commands: {\n /** Change the equation, the surface bending from the one into the other. */\n morphTo: { args: [\"expression\"] },\n /** Animate the equation's named values. */\n paramsTo: { args: [\"params\"] },\n /** Animate the spans that are drawn. */\n domainTo: { args: [\"uDomain\", \"vDomain\"] },\n },\n space: (s) => surfaceSpace(s),\n render: (ctx, s) => ctx.draw(ctx.declaring ? declaredSurface(s) : drawSurface(s)),\n});\n\nexport type SurfacePlot3d = NodeOf<typeof SurfacePlot3d>;\n\n/**\n * The surface's height above its own origin at graph `(x, y)`, or `NaN`\n * where it has none or is not a height. What a point riding it reads.\n */\nexport function surfaceValueAt(surface: Pick<SurfaceValues, \"expression\" | \"params\">, x: number, y: number): number {\n const { source, blend } = surface.expression;\n const value = heightOf(surface, source, x, y);\n if (!blend) return value;\n const from = heightOf(surface, blend.from, x, y);\n return from + (value - from) * blend.t;\n}\n\n/** A point inside a surface stands on it: its `x` and `y` say where, and its height is the surface's. */\nfunction surfaceSpace(s: SurfaceValues): ChildSpace3D | null {\n const space = graphOf(s);\n if (!space) return null;\n return {\n toLocal: (x, y, z) => {\n const height = surfaceValueAt(s, x, y);\n return space.offset(x, y, Number.isFinite(height) ? height : z);\n },\n };\n}\n\n/** Its paint on a stand-in: only a material loads, and reading no equation keeps a morph from re-declaring. */\nfunction declaredSurface(s: SurfaceValues): Graphics3D {\n const paint = Material.shorthand(s);\n return new Graphics3D().plane(s.colorScale.length > 0 ? { ...paint, fill: \"white\" } : paint);\n}\n\nfunction drawSurface(s: SurfaceValues): Graphics3D {\n const g3 = new Graphics3D();\n const space = graphOf(s);\n const lines = space ? meshLines(s, space) : [];\n const scaled = s.colorScale.length > 0;\n // A surface is seen from both sides; a vertex colour multiplies the fill, so a scale is shown on white.\n const surface = { ...s, faces: s.faces ?? \"both\", ...(scaled ? { vertexColors: true, fill: \"white\" } : {}) };\n for (const op of Material.mesh(surface, space ? surfaceGeometry(s, space) : undefined).ops()) {\n if (op.kind !== \"mesh\") continue;\n g3.mesh(op.geometry, mapMaterials(op.material, (material) => ({\n ...material,\n // Pushed back a hair so the lines drawn on it are not fought for, and blended rather than a hole when faded.\n ...(lines.length > 0 ? { polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 } : {}),\n ...((s.opacity ?? 1) < 1 ? { depthWrite: false } : {}),\n } as Material3D)), op.transform);\n }\n if (lines.length > 0) {\n const color = colorOps.resolve(s.meshColor);\n g3.line({ points: lines, segments: true, stroke: { fill: color }, opacity: color[3] * (s.opacity ?? 1) });\n }\n const shadow = space && s.floorShadow > 0 ? floorShadow(s, space) : undefined;\n if (shadow) {\n g3.mesh(shadow, Mat.basic({\n color: scaled ? \"white\" : PLOT_COLOR,\n vertexColors: scaled,\n opacity: s.floorShadow * (s.opacity ?? 1),\n transparent: true,\n // Translucent and under everything: writing depth would hide the floor's grid lines behind it.\n depthWrite: false,\n faces: \"both\",\n }));\n }\n return g3;\n}\n\nfunction surfaceGeometry(s: SurfaceValues, space: GraphSpace): Geometry3D | undefined {\n const sample = sampler(s, space);\n if (!sample) return undefined;\n const scale = s.colorScale;\n const point: Vector3 = { x: 0, y: 0, z: 0 };\n const low = space.offset(0, 0, space.zRange[0] - s.z).y;\n const high = space.offset(0, 0, space.zRange[1] - s.z).y;\n return Geo.parametric({\n segments: Math.max(2, Math.round(s.segments)),\n vertex: (u, v) => {\n sample(u, v, point);\n return space.offset(point.x, point.y, point.z);\n },\n ...(scale.length > 0\n ? { color: (_u, _v, position) => colorAt(scale, high > low ? (position.y - low) / (high - low) : 0) }\n : {}),\n computeNormals: true,\n revision: revisionOf(`${keyOf(s, space)}|${JSON.stringify(scale)}`),\n });\n}\n\nfunction heightOf(surface: Pick<SurfaceValues, \"params\">, source: string, x: number, y: number): number {\n const equation = equationOf(source);\n if (equation?.kind !== \"height\") return NaN;\n return equation.f(x, y, scopeFor(surfaceParams(source), surface.params));\n}\n\nfunction keyOf(s: SurfaceValues, space: GraphSpace): string {\n const { source, blend } = s.expression;\n return [source, blend?.from, blend?.t, space.revision, s.uDomain, s.vDomain, JSON.stringify(s.params), s.x, s.y, s.z].join(\"|\");\n}\n\nfunction sampler(s: SurfaceValues, space: GraphSpace): SurfaceSampler | null {\n const { source, blend } = s.expression;\n const to = surfaceOf(s, source, space);\n if (!to || !blend) return to;\n const from = surfaceOf(s, blend.from, space);\n if (!from) return to;\n const start: Vector3 = { x: 0, y: 0, z: 0 };\n return (u, v, out) => {\n from(u, v, start);\n to(u, v, out);\n out.x = start.x + (out.x - start.x) * blend.t;\n out.y = start.y + (out.y - start.y) * blend.t;\n out.z = start.z + (out.z - start.z) * blend.t;\n };\n}\n\n/** `source` as graph points, measured from the surface's own position. */\nfunction surfaceOf(s: SurfaceValues, source: string, space: GraphSpace): SurfaceSampler | null {\n const equation = equationOf(source);\n if (!equation) return null;\n const params = scopeFor(surfaceParams(source), s.params);\n if (equation.kind === \"parametric\") {\n const [u0, u1] = s.uDomain ?? [0, 1];\n const [v0, v1] = s.vDomain ?? [0, 1];\n const { x, y, z } = equation;\n return (u, v, out) => {\n const a = u0 + (u1 - u0) * u;\n const b = v0 + (v1 - v0) * v;\n out.x = finite(x(a, b, params));\n out.y = finite(y(a, b, params));\n out.z = finite(z(a, b, params));\n };\n }\n const [x0, x1] = s.uDomain ?? [space.xRange[0] - s.x, space.xRange[1] - s.x];\n const [y0, y1] = s.vDomain ?? [space.yRange[0] - s.y, space.yRange[1] - s.y];\n // Held inside the axes: a pole would otherwise stretch one triangle across the scene.\n const low = space.zRange[0] - s.z;\n const high = space.zRange[1] - s.z;\n const { f } = equation;\n return (u, v, out) => {\n out.x = x0 + (x1 - x0) * u;\n out.y = y0 + (y1 - y0) * v;\n out.z = clamp(finite(f(out.x, out.y, params)), low, high);\n };\n}\n\nfunction floorShadow(s: SurfaceValues, space: GraphSpace): Geometry3D | undefined {\n const sample = sampler(s, space);\n if (!sample) return undefined;\n const scale = s.colorScale;\n const [low, high] = space.zRange;\n const floor = low - s.z;\n const point: Vector3 = { x: 0, y: 0, z: 0 };\n return Geo.parametric({\n segments: Math.max(2, Math.round(s.segments)),\n vertex: (u, v) => {\n sample(u, v, point);\n return space.offset(point.x, point.y, floor);\n },\n ...(scale.length > 0\n ? {\n color: (u: number, v: number) => {\n sample(u, v, point);\n return colorAt(scale, high > low ? (point.z + s.z - low) / (high - low) : 0);\n },\n }\n : {}),\n revision: revisionOf(`${keyOf(s, space)}|${JSON.stringify(scale)}|floor`),\n });\n}\n\n/** The last lines drawn for each surface, kept while what they are drawn from is unchanged. */\nconst linesDrawn = new WeakMap<object, { readonly key: string; readonly lines: Vector3[] }>();\n\nfunction meshLines(s: SurfaceValues, space: GraphSpace): Vector3[] {\n const count = Math.round(s.meshLines);\n const sample = count > 0 ? sampler(s, space) : null;\n if (!sample) return [];\n const steps = Math.max(2, Math.round(s.segments));\n const key = `${keyOf(s, space)}|${count}|${steps}`;\n const kept = linesDrawn.get(s);\n if (kept?.key === key) return kept.lines;\n const lines: Vector3[] = [];\n const point: Vector3 = { x: 0, y: 0, z: 0 };\n const at = (u: number, v: number): Vector3 => {\n sample(u, v, point);\n return space.offset(point.x, point.y, point.z);\n };\n for (let i = 0; i <= count; i++) {\n const fixed = i / count;\n for (let j = 0; j < steps; j++) {\n lines.push(at(fixed, j / steps), at(fixed, (j + 1) / steps));\n lines.push(at(j / steps, fixed), at((j + 1) / steps, fixed));\n }\n }\n linesDrawn.set(s, { key, lines });\n return lines;\n}\n\nfunction equationOf(source: string): SurfaceEquation | null {\n const equation = parseSurface(source, surfaceParams(source));\n return equation instanceof Error ? null : equation;\n}\n\n// A hole in the data is drawn flat rather than as a hole in the mesh.\nfunction finite(value: number): number {\n return Number.isFinite(value) ? value : 0;\n}\n\nfunction mapMaterials(\n material: Material3D | readonly Material3D[],\n change: (material: Material3D) => Material3D,\n): Material3D | readonly Material3D[] {\n return Array.isArray(material) ? (material as readonly Material3D[]).map(change) : change(material as Material3D);\n}\n"]}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export interface VectorArrow3dProps extends Mesh3DProps {
|
|
3
|
-
tail?: Vector3Input;
|
|
4
|
-
head?: Vector3Input;
|
|
5
|
-
thickness?: number;
|
|
6
|
-
tip?: boolean;
|
|
7
|
-
}
|
|
1
|
+
import { type NodeOf, type Vector3, type Vector3Input, type Blend3D as _Blend3D, type Color as _Color, type Faces3D as _Faces3D, type Fill3D as _Fill3D, type Geometry3D as _Geometry3D, type Material3D as _Material3D, type Node3D as _Node3D, type Node3DProps as _Node3DProps, type NormalizedColor as _NormalizedColor, type Shading3D as _Shading3D, type Texture3D as _Texture3D } from "@motionscript/sdk";
|
|
8
2
|
/** An arrow between two points of a 3D graph: a vector from the origin by default. */
|
|
9
3
|
export declare const VectorArrow3d: import("@motionscript/sdk").Component<"vectorArrow3d", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Transform3DState, {
|
|
10
4
|
tail: import("@motionscript/sdk").Type<Vector3Input, Vector3, false>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-arrow3d.d.ts","sourceRoot":"","sources":["../../src/three/vector-arrow3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAOH,KAAK,
|
|
1
|
+
{"version":3,"file":"vector-arrow3d.d.ts","sourceRoot":"","sources":["../../src/three/vector-arrow3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAOH,KAAK,MAAM,EAEX,KAAK,OAAO,EACZ,KAAK,YAAY,EAEjB,KAAK,OAAO,IAAI,QAAQ,EACxB,KAAK,KAAK,IAAI,MAAM,EACpB,KAAK,OAAO,IAAI,QAAQ,EACxB,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,UAAU,IAAI,WAAW,EAC9B,KAAK,UAAU,IAAI,WAAW,EAC9B,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,eAAe,IAAI,gBAAgB,EACxC,KAAK,SAAS,IAAI,UAAU,EAC5B,KAAK,SAAS,IAAI,UAAU,EAC/B,MAAM,mBAAmB,CAAC;AAkB3B,sFAAsF;AACtF,eAAO,MAAM,aAAa;;;IAPtB,yEAAyE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAzE,yEAAyE;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAzE,yEAAyE;;;;;;;;;;;;;;;;;;;;;;;;;;2BAe3E,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-arrow3d.js","sourceRoot":"","sources":["../../src/three/vector-arrow3d.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,WAAW,EACX,QAAQ,EACR,cAAc,EACd,KAAK,
|
|
1
|
+
{"version":3,"file":"vector-arrow3d.js","sourceRoot":"","sources":["../../src/three/vector-arrow3d.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,WAAW,EACX,QAAQ,EACR,cAAc,EACd,KAAK,GAiBR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEnD,SAAS,KAAK,CAAC,OAAgB;IAC3B,OAAO,KAAK,C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AAG,MAAM;QACzC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,MAAM;QACzC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,MAAM;KAC5C,CAAC,CAAC;IACH,IAAI,KAAK,GAAG,CAAC;QAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;IACnI,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAChB,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,SAAS,GAAG,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,KAAK,GAAG,SAAS,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;IAC1I,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC","sourcesContent":["import {\n component3d,\n Graphics3D,\n lerpVector3,\n Material,\n resolveVector3,\n Types,\n type NodeOf,\n type Values,\n type Vector3,\n type Vector3Input,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Blend3D as _Blend3D,\n type Color as _Color,\n type Faces3D as _Faces3D,\n type Fill3D as _Fill3D,\n type Geometry3D as _Geometry3D,\n type Material3D as _Material3D,\n type Node3D as _Node3D,\n type Node3DProps as _Node3DProps,\n type NormalizedColor as _NormalizedColor,\n type Shading3D as _Shading3D,\n type Texture3D as _Texture3D,\n} from \"@motionscript/sdk\";\nimport { meshEntries } from \"./entries\";\nimport { aim, graphEntry, graphOf } from \"./space\";\n\nfunction point(initial: Vector3) {\n return Types.custom<Vector3Input, Vector3>(initial, { resolve: resolveVector3, lerp: lerpVector3, kind: \"vector3\" });\n}\n\nconst state = {\n ...meshEntries,\n tail: point({ x: 0, y: 0, z: 0 }),\n head: point({ x: 1, y: 1, z: 1 }),\n /** The radius of the shaft, in scene units; the tip is sized from it. */\n thickness: Types.number(0.035, { min: 0.001, step: 0.005 }),\n tip: Types.boolean(true, { animatable: false }),\n graph: graphEntry(),\n};\n\n/** An arrow between two points of a 3D graph: a vector from the origin by default. */\nexport const VectorArrow3d = component3d({\n key: \"vectorArrow3d\",\n state,\n commands: {\n /** Animate either end, or both. */\n endpointsTo: { args: [\"tail\", \"head\"] },\n },\n render: (ctx, s) => ctx.draw(drawArrow(s)),\n});\n\nexport type VectorArrow3d = NodeOf<typeof VectorArrow3d>;\n\nfunction drawArrow(s: Values<typeof state>): Graphics3D {\n const g3 = new Graphics3D();\n const space = graphOf(s);\n const { tail, head, thickness } = s;\n // Outside a graph an arrow is drawn in the scene's own units.\n const from = space ? space.offset(tail.x, tail.y, tail.z) : tail;\n const to = space ? space.offset(head.x, head.y, head.z) : head;\n const along: Vector3 = { x: to.x - from.x, y: to.y - from.y, z: to.z - from.z };\n const length = Math.hypot(along.x, along.y, along.z);\n if (!(length > 0)) return g3;\n\n const paint = Material.shorthand(s);\n const quaternion = aim(along);\n const tipLength = s.tip ? Math.min(thickness * 8, length) : 0;\n const shaft = length - tipLength;\n const at = (distance: number): Vector3 => ({\n x: from.x + (along.x * distance) / length,\n y: from.y + (along.y * distance) / length,\n z: from.z + (along.z * distance) / length,\n });\n if (shaft > 0) g3.cylinder({ ...paint, radius: thickness, height: shaft, segments: [12, 1], position: at(shaft / 2), quaternion });\n if (tipLength > 0) {\n g3.cone({ ...paint, radius: thickness * 2.8, height: tipLength, segments: [20, 1], position: at(shaft + tipLength / 2), quaternion });\n }\n return g3;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motionscript/math",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Math for Motion Script: coordinate systems, function and vector-field plots, 3D graphs and surfaces, network graphs, and LaTeX formulas typeset to glyph paths that morph token by token.",
|
|
6
6
|
"repository": {
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"license": "Apache-2.0",
|
|
55
55
|
"author": "Motionscript",
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@motionscript/sdk": "^0.1.
|
|
57
|
+
"@motionscript/sdk": "^0.1.1-alpha.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@mathjax/mathjax-newcm-font": "^4.1.1",
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"typescript": "^6.0.3",
|
|
70
70
|
"typescript-eslint": "^8.48.0",
|
|
71
71
|
"vitest": "^4.1.5",
|
|
72
|
-
"@motionscript/core": "0.1.
|
|
73
|
-
"@motionscript/sdk": "0.1.
|
|
72
|
+
"@motionscript/core": "0.1.1-alpha.0",
|
|
73
|
+
"@motionscript/sdk": "0.1.1-alpha.0"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
76
|
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json --resolve-full-paths && node ../../../scripts/build-browser.mjs",
|
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
component2d,
|
|
3
3
|
Graphics2D,
|
|
4
4
|
Types,
|
|
5
|
-
type Color,
|
|
6
5
|
type NodeOf,
|
|
6
|
+
type Color as _Color,
|
|
7
|
+
|
|
7
8
|
type NormalizedColor,
|
|
8
|
-
type PaintProps,
|
|
9
9
|
type PathCommand,
|
|
10
10
|
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
11
11
|
type Node2D as _Node2D,
|
|
@@ -18,26 +18,16 @@ import {
|
|
|
18
18
|
import { listed, omit, PAINT, PAINT_COMMANDS, painted } from "../kit/component";
|
|
19
19
|
import { outlineBounds, OWN_FRAME } from "../kit/follow";
|
|
20
20
|
import { drawLabels, loadFormulas } from "../kit/furniture";
|
|
21
|
+
import { radians } from "../kit/geometry";
|
|
21
22
|
import { strokeShape } from "../kit/mark";
|
|
22
23
|
|
|
23
|
-
export interface AngleMarkProps extends PaintProps {
|
|
24
|
-
fromAngle?: number;
|
|
25
|
-
toAngle?: number;
|
|
26
|
-
radius?: number;
|
|
27
|
-
corner?: "arc" | "square" | "auto";
|
|
28
|
-
label?: string;
|
|
29
|
-
labelSize?: number;
|
|
30
|
-
labelColor?: Color;
|
|
31
|
-
fontFamily?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
24
|
/** Degrees of arc per drawn segment. */
|
|
35
25
|
const ARC_STEP = 4;
|
|
36
26
|
/** How close to a right angle `auto` draws the square. */
|
|
37
27
|
const RIGHT_SLOP = 0.5;
|
|
38
28
|
|
|
39
29
|
const point = (radius: number, degrees: number) => {
|
|
40
|
-
const turn = (degrees
|
|
30
|
+
const turn = radians(degrees);
|
|
41
31
|
return { x: radius * Math.cos(turn), y: radius * Math.sin(turn) };
|
|
42
32
|
};
|
|
43
33
|
|
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
component2d,
|
|
3
3
|
Graphics2D,
|
|
4
4
|
Types,
|
|
5
|
-
type Color,
|
|
6
5
|
type NodeOf,
|
|
7
6
|
type NodeView,
|
|
7
|
+
type Color as _Color,
|
|
8
8
|
type NormalizedColor,
|
|
9
9
|
type PathCommand,
|
|
10
10
|
type Vector2,
|
|
@@ -20,25 +20,13 @@ import { braceOutline } from "../kit/brace";
|
|
|
20
20
|
import { listed, painted } from "../kit/component";
|
|
21
21
|
import {
|
|
22
22
|
add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, heading, outlineBounds, OWN_FRAME, resting,
|
|
23
|
-
type
|
|
23
|
+
type FollowValues, type Quad,
|
|
24
24
|
} from "../kit/follow";
|
|
25
25
|
import { drawLabels, loadFormulas } from "../kit/furniture";
|
|
26
26
|
import { strokeShape } from "../kit/mark";
|
|
27
27
|
|
|
28
28
|
export type BraceSide = "below" | "above" | "left" | "right";
|
|
29
29
|
|
|
30
|
-
export interface CurlyBraceProps extends FollowProps {
|
|
31
|
-
side?: BraceSide;
|
|
32
|
-
tail?: Vector2;
|
|
33
|
-
head?: Vector2;
|
|
34
|
-
clearance?: number;
|
|
35
|
-
reach?: number;
|
|
36
|
-
label?: string;
|
|
37
|
-
labelSize?: number;
|
|
38
|
-
labelColor?: Color;
|
|
39
|
-
fontFamily?: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
30
|
/** The edge of a target a brace runs along, as two corner indexes of its quad, read with the brace's bulge to the left. */
|
|
43
31
|
const EDGE: Record<BraceSide, [number, number]> = {
|
|
44
32
|
below: [2, 3],
|
|
@@ -16,17 +16,12 @@ import {
|
|
|
16
16
|
} from "@motionscript/sdk";
|
|
17
17
|
import { listed, painted } from "../kit/component";
|
|
18
18
|
import {
|
|
19
|
-
add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, grown, heading, outlineBounds, OWN_FRAME, type
|
|
19
|
+
add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, grown, heading, outlineBounds, OWN_FRAME, type FollowValues, type Quad,
|
|
20
20
|
} from "../kit/follow";
|
|
21
21
|
import { strokeShape } from "../kit/mark";
|
|
22
22
|
|
|
23
23
|
export type EmphasisShape = "box" | "circle" | "underline" | "cross";
|
|
24
24
|
|
|
25
|
-
export interface EmphasisMarkProps extends FollowProps {
|
|
26
|
-
shape?: EmphasisShape;
|
|
27
|
-
clearance?: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
25
|
/** How far a cubic's handle reaches to draw a quarter of an ellipse. */
|
|
31
26
|
const QUARTER = 0.5523;
|
|
32
27
|
|
package/src/engine.ts
CHANGED
|
@@ -20,7 +20,6 @@ export {
|
|
|
20
20
|
export type { FormulaFrame, Morphing, TypesetValues } from './tex/typeset';
|
|
21
21
|
export { lerpPartFills, partPaint, readPartFills, withPartFill } from './kit/part-fills';
|
|
22
22
|
export type { PartFill, PartFillResolved } from './kit/part-fills';
|
|
23
|
-
export { FILL_PAINT, OUTLINE_TRIM, STROKE_PAINT } from './kit/withdrawn';
|
|
24
23
|
export { createBoundedCache } from './kit/cache';
|
|
25
24
|
export { listed, omit, PAINT, PAINT_COMMANDS, painted } from './kit/component';
|
|
26
25
|
export type { BoundedCache } from './kit/cache';
|
|
@@ -50,10 +49,10 @@ export { sampleCurve } from './kit/sampler';
|
|
|
50
49
|
export type { CurveProjection, SampleOptions } from './kit/sampler';
|
|
51
50
|
export { formatTick, ticksFor } from './kit/ticks';
|
|
52
51
|
export type { Ticks } from './kit/ticks';
|
|
53
|
-
export { boundsOfRuns, clamp, inflate, runsToPath, stated } from './kit/geometry';
|
|
52
|
+
export { boundsOfRuns, clamp, inflate, radians, runsToPath, stated } from './kit/geometry';
|
|
54
53
|
export { CURVE_KEYS, curveValue, isCurve } from './kit/curve';
|
|
55
54
|
export type { CurveValues } from './kit/curve';
|
|
56
|
-
export { along, AXIS_COLOR, declareFormulas, drawLabels, drawn, lerpInterval, loadFormulas, PLOT_COLOR, readInterval, withoutTips } from './kit/furniture';
|
|
55
|
+
export { along, AXIS_COLOR, declareFormulas, drawLabels, drawn, intervalEntry, lerpInterval, loadFormulas, PLOT_COLOR, readInterval, withoutTips } from './kit/furniture';
|
|
57
56
|
export type { Label, LabelStyle } from './kit/furniture';
|
|
58
57
|
export {
|
|
59
58
|
add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, grown, heading, outlineBounds, OWN_FRAME, resting,
|
|
@@ -63,7 +62,7 @@ export {
|
|
|
63
62
|
parseSpaceCurve, parseSurface, spaceCurveError, spaceCurveParams, surfaceError, surfaceParams, EQUATION_KINDS, EQUATION_VARIABLES_3D,
|
|
64
63
|
} from './kit/equation3d';
|
|
65
64
|
export type { EquationLanguage, SpaceCurveEquation, SurfaceEquation } from './kit/equation3d';
|
|
66
|
-
export { aim, graphEntry, graphOf, graphSpace,
|
|
65
|
+
export { aim, graphEntry, graphOf, graphSpace, GRAPH_3D } from './three/space';
|
|
67
66
|
export type { Graph3D, GraphSpace } from './three/space';
|
|
68
67
|
export { domainEntry, meshEntries } from './three/entries';
|
|
69
68
|
export { drawLabel3D } from './three/label3d';
|
package/src/kit/cache.ts
CHANGED
|
@@ -1,44 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
* A bounded, least-recently-used memo.
|
|
3
|
-
*
|
|
4
|
-
* Sits under `geometry.ts`, and imports nothing, so it is testable in bare Node:
|
|
5
|
-
* everything else in this package reaches MathJax's browser adaptor at module
|
|
6
|
-
* scope, which means a test that touches it needs a DOM. The one piece of logic
|
|
7
|
-
* here worth being sure about — what gets thrown away when the memo is full —
|
|
8
|
-
* is exactly the piece that does not need one.
|
|
9
|
-
*
|
|
10
|
-
* Least-recently-used rather than oldest-first, and that matters for the shape
|
|
11
|
-
* of work this sees. A `Latex` node re-resolves its formula whenever `fontSize`
|
|
12
|
-
* changes, so animating the size of one formula inserts a fresh key every frame
|
|
13
|
-
* and would, under a first-in-first-out rule, walk the whole memo out of it in a
|
|
14
|
-
* couple of seconds — including the entries for every *other* formula in the
|
|
15
|
-
* scene, none of which had done anything wrong. Touching an entry on read keeps
|
|
16
|
-
* the formulas that are actually being asked for ahead of the ones streaming
|
|
17
|
-
* past.
|
|
18
|
-
*/
|
|
1
|
+
// Imports nothing, so it is testable in bare Node (the rest of the package reaches MathJax's browser adaptor).
|
|
19
2
|
|
|
20
3
|
export interface BoundedCache<T> {
|
|
21
4
|
get(key: string): T | undefined;
|
|
22
5
|
set(key: string, value: T): void;
|
|
23
|
-
/** Entries held. For tests and for anyone measuring. */
|
|
24
6
|
readonly size: number;
|
|
25
7
|
}
|
|
26
8
|
|
|
27
9
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
10
|
+
* A least-recently-used memo holding at most `limit` entries. LRU rather than
|
|
11
|
+
* first-in-first-out: an animated `fontSize` inserts a fresh key every frame and
|
|
12
|
+
* would walk every other formula's entry out of a FIFO memo within seconds.
|
|
30
13
|
*/
|
|
31
14
|
export function createBoundedCache<T>(limit: number): BoundedCache<T> {
|
|
32
|
-
//
|
|
33
|
-
// an LRU as long as every read re-inserts.
|
|
15
|
+
// A plain `Map` is an LRU as long as every read re-inserts.
|
|
34
16
|
const entries = new Map<string, T>();
|
|
35
17
|
|
|
36
18
|
return {
|
|
37
19
|
get(key) {
|
|
38
20
|
if (!entries.has(key)) return undefined;
|
|
39
21
|
const value = entries.get(key) as T;
|
|
40
|
-
// Delete-then-set moves the key to the end, so the next eviction
|
|
41
|
-
// takes the genuinely coldest entry rather than the oldest one.
|
|
42
22
|
entries.delete(key);
|
|
43
23
|
entries.set(key, value);
|
|
44
24
|
return value;
|
|
@@ -59,3 +39,31 @@ export function createBoundedCache<T>(limit: number): BoundedCache<T> {
|
|
|
59
39
|
},
|
|
60
40
|
};
|
|
61
41
|
}
|
|
42
|
+
|
|
43
|
+
/** What `compute` returns, or the error it throws, remembered under `key` so a failure is not re-derived every frame. */
|
|
44
|
+
export function remember<T>(cache: BoundedCache<T | Error>, key: string, compute: () => T): T | Error {
|
|
45
|
+
const hit = cache.get(key);
|
|
46
|
+
if (hit !== undefined) return hit;
|
|
47
|
+
let result: T | Error;
|
|
48
|
+
try {
|
|
49
|
+
result = compute();
|
|
50
|
+
} catch (error) {
|
|
51
|
+
result = error instanceof Error ? error : new Error(String(error));
|
|
52
|
+
}
|
|
53
|
+
cache.set(key, result);
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A parser memoised per `(params, source)`: an unchanged equation is the
|
|
59
|
+
* identical object, and empty text fails as "Empty equation". `read` gets the trimmed text.
|
|
60
|
+
*/
|
|
61
|
+
export function memoParse<T>(limit: number, read: (text: string, params: readonly string[]) => T): (source: string, params?: readonly string[]) => T | Error {
|
|
62
|
+
const cache = createBoundedCache<T | Error>(limit);
|
|
63
|
+
return (source, params = []) =>
|
|
64
|
+
remember(cache, `${params.join(",")}|${source}`, () => {
|
|
65
|
+
const text = source.trim();
|
|
66
|
+
if (text === "") throw new Error("Empty equation");
|
|
67
|
+
return read(text, params);
|
|
68
|
+
});
|
|
69
|
+
}
|
package/src/kit/component.ts
CHANGED
|
@@ -13,11 +13,6 @@ import {
|
|
|
13
13
|
type StrokeResolved as _StrokeResolved,
|
|
14
14
|
} from "@motionscript/sdk";
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* What a component in this kit shares beyond the factory: the paints a math
|
|
18
|
-
* node draws with, listed choices, and the order a node paints in.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
16
|
const { overlay: _overlay, ...paint } = Paint.state;
|
|
22
17
|
const { overlayTo: _overlayTo, ...paintCommands } = Paint.commands;
|
|
23
18
|
|
|
@@ -25,20 +20,14 @@ const { overlayTo: _overlayTo, ...paintCommands } = Paint.commands;
|
|
|
25
20
|
export const PAINT = paint;
|
|
26
21
|
export const PAINT_COMMANDS = paintCommands;
|
|
27
22
|
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
*/
|
|
31
|
-
export function listed<const V extends readonly string[]>(values: V, initial: V[number], options?: ListedOptions): Type<V[number]>;
|
|
23
|
+
/** One of `values`, held as text with its choices listed (no `kind: "enum"`). */
|
|
24
|
+
export function listed<const V extends readonly string[]>(values: V, initial: V[number], options?: Pick<EntryOptions, "animatable">): Type<V[number]>;
|
|
32
25
|
/** With no default: an arg left out is one the command was not given. */
|
|
33
|
-
export function listed<const V extends readonly string[]>(values: V, initial: undefined, options?:
|
|
34
|
-
export function listed(values: readonly string[], initial: string | undefined, options:
|
|
26
|
+
export function listed<const V extends readonly string[]>(values: V, initial: undefined, options?: Pick<EntryOptions, "animatable">): Type<V[number] | undefined>;
|
|
27
|
+
export function listed(values: readonly string[], initial: string | undefined, options: Pick<EntryOptions, "animatable"> = {}): Type<string | undefined> {
|
|
35
28
|
return Types.custom<string | undefined, string | undefined, EntryOptions & { readonly options: readonly string[] }>(initial, { ...options, options: values });
|
|
36
29
|
}
|
|
37
30
|
|
|
38
|
-
interface ListedOptions {
|
|
39
|
-
readonly animatable?: boolean;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
31
|
/** `record` without `keys`: the paints a node has no use for. */
|
|
43
32
|
export function omit<T extends object, const K extends keyof T>(record: T, ...keys: K[]): Omit<T, K> {
|
|
44
33
|
const out = { ...record };
|
|
@@ -46,10 +35,7 @@ export function omit<T extends object, const K extends keyof T>(record: T, ...ke
|
|
|
46
35
|
return out;
|
|
47
36
|
}
|
|
48
37
|
|
|
49
|
-
/**
|
|
50
|
-
* A node's paint order: its own paint under its children, then what it lays
|
|
51
|
-
* over them, each cut at the near plane of a space it crosses.
|
|
52
|
-
*/
|
|
38
|
+
/** A node's own paint under its children, then what it lays over them. */
|
|
53
39
|
export function painted(ctx: RenderContext, own: () => void, over: () => void = () => { }): void {
|
|
54
40
|
ctx.inFront(own);
|
|
55
41
|
ctx.children();
|