@motionscript/math 0.1.0-alpha.8 → 0.1.0-alpha.9
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 +2 -0
- package/LICENSE +201 -201
- package/NOTICE +49 -49
- package/README.md +390 -391
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/{chunk-FETQZEN2.js → chunk-IRZCG6PM.js} +2 -2
- package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
- package/dist/browser/chunks/{chunk-K77KLQX4.js → chunk-WMVW6ZIV.js} +2 -2
- package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
- package/dist/browser/chunks/{mathjax-DNP3YRES.js → mathjax-WV55AC2P.js} +1 -1
- package/dist/browser/chunks/{mathjax-DNP3YRES.js.map → mathjax-WV55AC2P.js.map} +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/kit.js +1 -1
- package/dist/browser/tex.js +1 -1
- package/dist/browser/tex.js.map +1 -1
- package/dist/engine.d.ts +1 -1
- package/dist/engine.js +1 -1
- package/dist/engine.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kit/brace.js.map +1 -1
- package/dist/kit/cache.js.map +1 -1
- package/dist/kit/component.d.ts.map +1 -1
- package/dist/kit/component.js.map +1 -1
- package/dist/kit/contour.js.map +1 -1
- package/dist/kit/coords.js.map +1 -1
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/equation.js.map +1 -1
- package/dist/kit/equation3d.js.map +1 -1
- package/dist/kit/expression.js.map +1 -1
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/field.js.map +1 -1
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.js.map +1 -1
- package/dist/kit/geometry.js.map +1 -1
- package/dist/kit/graph.js.map +1 -1
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/part-fills.js.map +1 -1
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/sampler.js.map +1 -1
- package/dist/kit/scale.js.map +1 -1
- package/dist/kit/source.js.map +1 -1
- package/dist/kit/system.js.map +1 -1
- package/dist/kit/ticks.js.map +1 -1
- package/dist/kit/withdrawn.js.map +1 -1
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/graph-layout.js.map +1 -1
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/geometry.js.map +1 -1
- package/dist/tex/index.js.map +1 -1
- package/dist/tex/mathjax.js.map +1 -1
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/node.js.map +1 -1
- package/dist/tex/tween.js.map +1 -1
- package/dist/tex/typeset.d.ts.map +1 -1
- package/dist/tex/typeset.js.map +1 -1
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.js.map +1 -1
- package/dist/three/entries.js.map +1 -1
- package/dist/three/label3d.js.map +1 -1
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +4 -4
- package/registry.json +251 -251
- package/src/annotate/angle-mark.ts +137 -137
- package/src/annotate/curly-brace.ts +148 -148
- package/src/annotate/emphasis-mark.ts +118 -118
- package/src/engine.ts +86 -86
- package/src/index.ts +29 -29
- package/src/kit/brace.ts +37 -37
- package/src/kit/cache.ts +61 -61
- package/src/kit/component.ts +57 -57
- package/src/kit/contour.ts +94 -94
- package/src/kit/coords.ts +278 -278
- package/src/kit/curve.ts +47 -47
- package/src/kit/equation.ts +181 -181
- package/src/kit/equation3d.ts +137 -137
- package/src/kit/expression.ts +159 -159
- package/src/kit/field-mark.ts +171 -171
- package/src/kit/field.ts +50 -50
- package/src/kit/follow.ts +229 -229
- package/src/kit/furniture.ts +113 -113
- package/src/kit/geometry.ts +49 -49
- package/src/kit/graph.ts +116 -116
- package/src/kit/mark.ts +152 -152
- package/src/kit/part-fills.ts +61 -61
- package/src/kit/place.ts +77 -77
- package/src/kit/sampler.ts +281 -281
- package/src/kit/scale.ts +39 -39
- package/src/kit/source.ts +57 -57
- package/src/kit/system.ts +105 -105
- package/src/kit/ticks.ts +85 -85
- package/src/kit/withdrawn.ts +8 -8
- package/src/marks/curve-area.ts +89 -89
- package/src/marks/drop-lines.ts +71 -71
- package/src/marks/plot-point.ts +102 -102
- package/src/marks/riemann-sum.ts +99 -99
- package/src/marks/tangent-line.ts +119 -119
- package/src/marks/vector-arrow.ts +98 -98
- package/src/nodes.ts +99 -99
- package/src/plots/function-plot.ts +220 -220
- package/src/plots/points-plot.ts +103 -103
- package/src/plots/stream-lines.ts +160 -160
- package/src/plots/traced-path.ts +70 -70
- package/src/plots/vector-field.ts +107 -107
- package/src/structures/graph-layout.ts +145 -145
- package/src/structures/network-graph.ts +291 -291
- package/src/structures/sample-space.ts +210 -210
- package/src/systems/axes2d.ts +226 -226
- package/src/systems/number-line.ts +130 -130
- package/src/systems/number-plane.ts +232 -232
- package/src/systems/polar-plane.ts +177 -177
- package/src/tex/geometry.ts +703 -703
- package/src/tex/index.ts +15 -15
- package/src/tex/mathjax.ts +82 -82
- package/src/tex/matrix.ts +97 -97
- package/src/tex/node.ts +74 -74
- package/src/tex/tween.ts +308 -308
- package/src/tex/typeset.ts +461 -461
- package/src/three/axes3d.ts +267 -267
- package/src/three/curve-plot3d.ts +146 -146
- package/src/three/entries.ts +42 -42
- package/src/three/label3d.ts +52 -52
- package/src/three/plot-point3d.ts +63 -63
- package/src/three/space.ts +92 -92
- package/src/three/surface-plot3d.ts +318 -318
- package/src/three/vector-arrow3d.ts +88 -88
- package/dist/browser/chunks/chunk-FETQZEN2.js.map +0 -7
- package/dist/browser/chunks/chunk-K77KLQX4.js.map +0 -7
- package/dist/kit/placement.d.ts +0 -8
- package/dist/kit/placement.d.ts.map +0 -1
- package/dist/kit/placement.js +0 -8
- package/dist/kit/placement.js.map +0 -1
package/src/three/space.ts
CHANGED
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContext,
|
|
3
|
-
Types,
|
|
4
|
-
type ChildSpace3D,
|
|
5
|
-
type Node3D,
|
|
6
|
-
type Type,
|
|
7
|
-
type Vector3,
|
|
8
|
-
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
9
|
-
type Context as _Context,
|
|
10
|
-
} from "@motionscript/sdk";
|
|
11
|
-
import type { Interval } from "../kit/coords";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A 3D graph's coordinates, as its axes' local space sees them. A graph is
|
|
15
|
-
* right-handed with z up, and the scene has y up, so graph x, y and z run along
|
|
16
|
-
* the scene's z, x and y: looked at head-on, y is to the right and z is up.
|
|
17
|
-
*/
|
|
18
|
-
export interface GraphSpace extends ChildSpace3D {
|
|
19
|
-
readonly xRange: Interval;
|
|
20
|
-
readonly yRange: Interval;
|
|
21
|
-
readonly zRange: Interval;
|
|
22
|
-
/** Changes exactly when the mapping does: what a mark's geometry is cached under. */
|
|
23
|
-
readonly revision: string;
|
|
24
|
-
/** A step from one graph point to another, as the local one: what a mark's own geometry is drawn in. */
|
|
25
|
-
offset(x: number, y: number, z: number): Vector3;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** The space of a box `lengths` on a side, in scene units, showing the three ranges, centred on its node. */
|
|
29
|
-
export function graphSpace(xRange: Interval, yRange: Interval, zRange: Interval, lengths: Vector3): GraphSpace {
|
|
30
|
-
const ux = unit(xRange, lengths.x);
|
|
31
|
-
const uy = unit(yRange, lengths.y);
|
|
32
|
-
const uz = unit(zRange, lengths.z);
|
|
33
|
-
const cx = (xRange[0] + xRange[1]) / 2;
|
|
34
|
-
const cy = (yRange[0] + yRange[1]) / 2;
|
|
35
|
-
const cz = (zRange[0] + zRange[1]) / 2;
|
|
36
|
-
return {
|
|
37
|
-
xRange,
|
|
38
|
-
yRange,
|
|
39
|
-
zRange,
|
|
40
|
-
revision: [xRange, yRange, zRange, lengths.x, lengths.y, lengths.z].join("|"),
|
|
41
|
-
toLocal: (x, y, z) => ({ x: (y - cy) * uy, y: (z - cz) * uz, z: (x - cx) * ux }),
|
|
42
|
-
offset: (x, y, z) => ({ x: y * uy, y: z * uz, z: x * ux }),
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function unit([min, max]: Interval, length: number): number {
|
|
47
|
-
const span = max - min;
|
|
48
|
-
return span > 0 ? length / span : 0;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** A 3D graph, as the marks inside it see it: its coordinates as they stand now. */
|
|
52
|
-
export interface Graph3D {
|
|
53
|
-
space(): GraphSpace;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** The graph a mark is inside: `axes3d` provides itself to everything in it. */
|
|
57
|
-
export const GRAPH_3D = createContext<Graph3D | null>(null, "math:graph3d");
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* The entry a mark reads the graph it is drawn in through, set from the nearest
|
|
61
|
-
* `axes3d` above it, through any 3D node between; `null` outside one.
|
|
62
|
-
*/
|
|
63
|
-
export function graphEntry(): Type<Graph3D | null, Graph3D | null, true> {
|
|
64
|
-
return Types.custom<Graph3D | null, Graph3D | null, { readonly private: true }>(null, {
|
|
65
|
-
private: true,
|
|
66
|
-
inherit: (use) => use(GRAPH_3D),
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** The graph space a mark with a {@link graphEntry} is drawn in, or `null` outside a graph. */
|
|
71
|
-
export function graphOf(mark: { readonly graph: Graph3D | null }): GraphSpace | null {
|
|
72
|
-
return mark.graph?.space() ?? null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** The graph a 3D node is drawn in: what the nearest `axes3d` above it provides, once it is in the tree. */
|
|
76
|
-
export function spaceOf(mark: Node3D): GraphSpace | null {
|
|
77
|
-
return mark.useContext(GRAPH_3D)?.space() ?? null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** A unit quaternion turning the scene's +y, the way a cylinder or a cone points, onto `direction`. */
|
|
81
|
-
export function aim(direction: Vector3): { x: number; y: number; z: number; w: number } {
|
|
82
|
-
const length = Math.hypot(direction.x, direction.y, direction.z);
|
|
83
|
-
if (!(length > 0)) return { x: 0, y: 0, z: 0, w: 1 };
|
|
84
|
-
const dx = direction.x / length;
|
|
85
|
-
const dy = direction.y / length;
|
|
86
|
-
const dz = direction.z / length;
|
|
87
|
-
// Straight down is the one turn with no single axis: any in the ground plane will do.
|
|
88
|
-
if (dy < -1 + 1e-9) return { x: 1, y: 0, z: 0, w: 0 };
|
|
89
|
-
const w = 1 + dy;
|
|
90
|
-
const norm = Math.hypot(dz, dx, w);
|
|
91
|
-
return { x: dz / norm, y: 0, z: -dx / norm, w: w / norm };
|
|
92
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
Types,
|
|
4
|
+
type ChildSpace3D,
|
|
5
|
+
type Node3D,
|
|
6
|
+
type Type,
|
|
7
|
+
type Vector3,
|
|
8
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
9
|
+
type Context as _Context,
|
|
10
|
+
} from "@motionscript/sdk";
|
|
11
|
+
import type { Interval } from "../kit/coords";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A 3D graph's coordinates, as its axes' local space sees them. A graph is
|
|
15
|
+
* right-handed with z up, and the scene has y up, so graph x, y and z run along
|
|
16
|
+
* the scene's z, x and y: looked at head-on, y is to the right and z is up.
|
|
17
|
+
*/
|
|
18
|
+
export interface GraphSpace extends ChildSpace3D {
|
|
19
|
+
readonly xRange: Interval;
|
|
20
|
+
readonly yRange: Interval;
|
|
21
|
+
readonly zRange: Interval;
|
|
22
|
+
/** Changes exactly when the mapping does: what a mark's geometry is cached under. */
|
|
23
|
+
readonly revision: string;
|
|
24
|
+
/** A step from one graph point to another, as the local one: what a mark's own geometry is drawn in. */
|
|
25
|
+
offset(x: number, y: number, z: number): Vector3;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The space of a box `lengths` on a side, in scene units, showing the three ranges, centred on its node. */
|
|
29
|
+
export function graphSpace(xRange: Interval, yRange: Interval, zRange: Interval, lengths: Vector3): GraphSpace {
|
|
30
|
+
const ux = unit(xRange, lengths.x);
|
|
31
|
+
const uy = unit(yRange, lengths.y);
|
|
32
|
+
const uz = unit(zRange, lengths.z);
|
|
33
|
+
const cx = (xRange[0] + xRange[1]) / 2;
|
|
34
|
+
const cy = (yRange[0] + yRange[1]) / 2;
|
|
35
|
+
const cz = (zRange[0] + zRange[1]) / 2;
|
|
36
|
+
return {
|
|
37
|
+
xRange,
|
|
38
|
+
yRange,
|
|
39
|
+
zRange,
|
|
40
|
+
revision: [xRange, yRange, zRange, lengths.x, lengths.y, lengths.z].join("|"),
|
|
41
|
+
toLocal: (x, y, z) => ({ x: (y - cy) * uy, y: (z - cz) * uz, z: (x - cx) * ux }),
|
|
42
|
+
offset: (x, y, z) => ({ x: y * uy, y: z * uz, z: x * ux }),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function unit([min, max]: Interval, length: number): number {
|
|
47
|
+
const span = max - min;
|
|
48
|
+
return span > 0 ? length / span : 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A 3D graph, as the marks inside it see it: its coordinates as they stand now. */
|
|
52
|
+
export interface Graph3D {
|
|
53
|
+
space(): GraphSpace;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The graph a mark is inside: `axes3d` provides itself to everything in it. */
|
|
57
|
+
export const GRAPH_3D = createContext<Graph3D | null>(null, "math:graph3d");
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The entry a mark reads the graph it is drawn in through, set from the nearest
|
|
61
|
+
* `axes3d` above it, through any 3D node between; `null` outside one.
|
|
62
|
+
*/
|
|
63
|
+
export function graphEntry(): Type<Graph3D | null, Graph3D | null, true> {
|
|
64
|
+
return Types.custom<Graph3D | null, Graph3D | null, { readonly private: true }>(null, {
|
|
65
|
+
private: true,
|
|
66
|
+
inherit: (use) => use(GRAPH_3D),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The graph space a mark with a {@link graphEntry} is drawn in, or `null` outside a graph. */
|
|
71
|
+
export function graphOf(mark: { readonly graph: Graph3D | null }): GraphSpace | null {
|
|
72
|
+
return mark.graph?.space() ?? null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The graph a 3D node is drawn in: what the nearest `axes3d` above it provides, once it is in the tree. */
|
|
76
|
+
export function spaceOf(mark: Node3D): GraphSpace | null {
|
|
77
|
+
return mark.useContext(GRAPH_3D)?.space() ?? null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A unit quaternion turning the scene's +y, the way a cylinder or a cone points, onto `direction`. */
|
|
81
|
+
export function aim(direction: Vector3): { x: number; y: number; z: number; w: number } {
|
|
82
|
+
const length = Math.hypot(direction.x, direction.y, direction.z);
|
|
83
|
+
if (!(length > 0)) return { x: 0, y: 0, z: 0, w: 1 };
|
|
84
|
+
const dx = direction.x / length;
|
|
85
|
+
const dy = direction.y / length;
|
|
86
|
+
const dz = direction.z / length;
|
|
87
|
+
// Straight down is the one turn with no single axis: any in the ground plane will do.
|
|
88
|
+
if (dy < -1 + 1e-9) return { x: 1, y: 0, z: 0, w: 0 };
|
|
89
|
+
const w = 1 + dy;
|
|
90
|
+
const norm = Math.hypot(dz, dx, w);
|
|
91
|
+
return { x: dz / norm, y: 0, z: -dx / norm, w: w / norm };
|
|
92
|
+
}
|