@motionscript/math 0.1.0-alpha.5 → 0.1.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +39 -33
- package/dist/annotate/angle-mark.d.ts +77 -27
- package/dist/annotate/angle-mark.d.ts.map +1 -1
- package/dist/annotate/angle-mark.js +80 -115
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.d.ts +94 -25
- package/dist/annotate/curly-brace.d.ts.map +1 -1
- package/dist/annotate/curly-brace.js +85 -100
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.d.ts +69 -9
- package/dist/annotate/emphasis-mark.d.ts.map +1 -1
- package/dist/annotate/emphasis-mark.js +33 -34
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/chunk-ABYBW64J.js +2 -0
- package/dist/browser/chunks/chunk-ABYBW64J.js.map +7 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js +2 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/browser/tex.js +1 -1
- package/dist/browser/tex.js.map +2 -2
- package/dist/engine.d.ts +26 -19
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +17 -14
- package/dist/engine.js.map +1 -1
- package/dist/kit/component.d.ts +51 -0
- package/dist/kit/component.d.ts.map +1 -0
- package/dist/kit/component.js +30 -0
- package/dist/kit/component.js.map +1 -0
- package/dist/kit/curve.d.ts +22 -11
- package/dist/kit/curve.d.ts.map +1 -1
- package/dist/kit/curve.js +25 -18
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/field-mark.d.ts +56 -35
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js +100 -120
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/follow.d.ts +67 -29
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js +114 -110
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.d.ts +3 -1
- package/dist/kit/furniture.d.ts.map +1 -1
- package/dist/kit/furniture.js +5 -0
- package/dist/kit/furniture.js.map +1 -1
- package/dist/kit/graph.d.ts +46 -0
- package/dist/kit/graph.d.ts.map +1 -0
- package/dist/kit/graph.js +90 -0
- package/dist/kit/graph.js.map +1 -0
- package/dist/kit/mark.d.ts +64 -39
- package/dist/kit/mark.d.ts.map +1 -1
- package/dist/kit/mark.js +80 -96
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/place.d.ts +10 -8
- package/dist/kit/place.d.ts.map +1 -1
- package/dist/kit/place.js +28 -30
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/system.d.ts +27 -29
- package/dist/kit/system.d.ts.map +1 -1
- package/dist/kit/system.js +62 -58
- package/dist/kit/system.js.map +1 -1
- package/dist/kit/withdrawn.d.ts +3 -3
- package/dist/kit/withdrawn.js +3 -3
- package/dist/kit/withdrawn.js.map +1 -1
- package/dist/marks/curve-area.d.ts +37 -18
- package/dist/marks/curve-area.d.ts.map +1 -1
- package/dist/marks/curve-area.js +50 -73
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.d.ts +45 -10
- package/dist/marks/drop-lines.d.ts.map +1 -1
- package/dist/marks/drop-lines.js +37 -52
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.d.ts +56 -20
- package/dist/marks/plot-point.d.ts.map +1 -1
- package/dist/marks/plot-point.js +65 -91
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.d.ts +47 -26
- package/dist/marks/riemann-sum.d.ts.map +1 -1
- package/dist/marks/riemann-sum.js +57 -85
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.d.ts +58 -14
- package/dist/marks/tangent-line.d.ts.map +1 -1
- package/dist/marks/tangent-line.js +73 -87
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.d.ts +48 -20
- package/dist/marks/vector-arrow.d.ts.map +1 -1
- package/dist/marks/vector-arrow.js +58 -78
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.d.ts +13 -5
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +0 -6
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts +135 -43
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js +146 -177
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.d.ts +55 -19
- package/dist/plots/points-plot.d.ts.map +1 -1
- package/dist/plots/points-plot.js +31 -58
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.d.ts +60 -19
- package/dist/plots/stream-lines.d.ts.map +1 -1
- package/dist/plots/stream-lines.js +60 -79
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.d.ts +54 -15
- package/dist/plots/traced-path.d.ts.map +1 -1
- package/dist/plots/traced-path.js +33 -48
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.d.ts +48 -11
- package/dist/plots/vector-field.d.ts.map +1 -1
- package/dist/plots/vector-field.js +50 -64
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/network-graph.d.ts +140 -49
- package/dist/structures/network-graph.d.ts.map +1 -1
- package/dist/structures/network-graph.js +168 -217
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.d.ts +90 -38
- package/dist/structures/sample-space.d.ts.map +1 -1
- package/dist/structures/sample-space.js +132 -170
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts +159 -37
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js +147 -183
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.d.ts +80 -28
- package/dist/systems/number-line.d.ts.map +1 -1
- package/dist/systems/number-line.js +82 -118
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.d.ts +140 -31
- package/dist/systems/number-plane.d.ts.map +1 -1
- package/dist/systems/number-plane.js +142 -149
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.d.ts +76 -26
- package/dist/systems/polar-plane.d.ts.map +1 -1
- package/dist/systems/polar-plane.js +107 -133
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/index.d.ts.map +1 -1
- package/dist/tex/index.js +1 -0
- package/dist/tex/index.js.map +1 -1
- package/dist/tex/matrix.d.ts +88 -18
- package/dist/tex/matrix.d.ts.map +1 -1
- package/dist/tex/matrix.js +33 -50
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/node.d.ts +84 -201
- package/dist/tex/node.d.ts.map +1 -1
- package/dist/tex/node.js +23 -593
- package/dist/tex/node.js.map +1 -1
- package/dist/tex/typeset.d.ts +133 -0
- package/dist/tex/typeset.d.ts.map +1 -0
- package/dist/tex/typeset.js +403 -0
- package/dist/tex/typeset.js.map +1 -0
- package/dist/three/axes3d.d.ts +214 -54
- package/dist/three/axes3d.d.ts.map +1 -1
- package/dist/three/axes3d.js +163 -204
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +108 -42
- package/dist/three/curve-plot3d.d.ts.map +1 -1
- package/dist/three/curve-plot3d.js +97 -132
- package/dist/three/curve-plot3d.js.map +1 -1
- package/dist/three/entries.d.ts +17 -0
- package/dist/three/entries.d.ts.map +1 -0
- package/dist/three/entries.js +15 -0
- package/dist/three/entries.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +85 -12
- package/dist/three/plot-point3d.d.ts.map +1 -1
- package/dist/three/plot-point3d.js +27 -53
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.d.ts +17 -2
- package/dist/three/space.d.ts.map +1 -1
- package/dist/three/space.js +19 -8
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.d.ts +176 -49
- package/dist/three/surface-plot3d.d.ts.map +1 -1
- package/dist/three/surface-plot3d.js +227 -261
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.d.ts +87 -16
- package/dist/three/vector-arrow3d.d.ts.map +1 -1
- package/dist/three/vector-arrow3d.js +48 -67
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +4 -4
- package/src/annotate/angle-mark.ts +95 -105
- package/src/annotate/curly-brace.ts +107 -85
- package/src/annotate/emphasis-mark.ts +55 -26
- package/src/engine.ts +35 -21
- package/src/kit/component.ts +57 -0
- package/src/kit/curve.ts +38 -20
- package/src/kit/field-mark.ts +124 -108
- package/src/kit/follow.ts +146 -120
- package/src/kit/furniture.ts +6 -1
- package/src/kit/graph.ts +116 -0
- package/src/kit/mark.ts +135 -114
- package/src/kit/place.ts +32 -56
- package/src/kit/system.ts +77 -71
- package/src/kit/withdrawn.ts +3 -3
- package/src/marks/curve-area.ts +65 -65
- package/src/marks/drop-lines.ts +50 -42
- package/src/marks/plot-point.ts +77 -82
- package/src/marks/riemann-sum.ts +73 -72
- package/src/marks/tangent-line.ts +87 -71
- package/src/marks/vector-arrow.ts +73 -73
- package/src/nodes.ts +41 -5
- package/src/plots/function-plot.ts +155 -171
- package/src/plots/points-plot.ts +46 -50
- package/src/plots/stream-lines.ts +75 -66
- package/src/plots/traced-path.ts +51 -33
- package/src/plots/vector-field.ts +68 -49
- package/src/structures/network-graph.ts +168 -185
- package/src/structures/sample-space.ts +149 -148
- package/src/systems/axes2d.ts +165 -156
- package/src/systems/number-line.ts +91 -92
- package/src/systems/number-plane.ts +149 -120
- package/src/systems/polar-plane.ts +117 -116
- package/src/tex/index.ts +2 -1
- package/src/tex/matrix.ts +62 -40
- package/src/tex/node.ts +54 -621
- package/src/tex/typeset.ts +461 -0
- package/src/three/axes3d.ts +187 -160
- package/src/three/curve-plot3d.ts +107 -110
- package/src/three/entries.ts +42 -0
- package/src/three/plot-point3d.ts +42 -45
- package/src/three/space.ts +34 -9
- package/src/three/surface-plot3d.ts +312 -323
- package/src/three/vector-arrow3d.ts +65 -54
- package/dist/browser/chunks/chunk-3GJB6AVO.js +0 -2
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +0 -7
- package/dist/browser/chunks/chunk-D5WHCVBC.js +0 -2
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +0 -7
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +0 -2
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +0 -7
- package/src/kit/placement.ts +0 -8
|
@@ -1,323 +1,312 @@
|
|
|
1
|
-
import {
|
|
2
|
-
colorOps,
|
|
3
|
-
|
|
4
|
-
Geo,
|
|
5
|
-
Graphics3D,
|
|
6
|
-
Mat,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type
|
|
11
|
-
type
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
type
|
|
15
|
-
type
|
|
16
|
-
type
|
|
17
|
-
type
|
|
18
|
-
|
|
19
|
-
type
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
// A hole in the data is drawn flat rather than as a hole in the mesh.
|
|
314
|
-
function finite(value: number): number {
|
|
315
|
-
return Number.isFinite(value) ? value : 0;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
function mapMaterials(
|
|
319
|
-
material: Material3D | readonly Material3D[],
|
|
320
|
-
change: (material: Material3D) => Material3D,
|
|
321
|
-
): Material3D | readonly Material3D[] {
|
|
322
|
-
return Array.isArray(material) ? (material as readonly Material3D[]).map(change) : change(material as Material3D);
|
|
323
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
colorOps,
|
|
3
|
+
component3d,
|
|
4
|
+
Geo,
|
|
5
|
+
Graphics3D,
|
|
6
|
+
Mat,
|
|
7
|
+
Material,
|
|
8
|
+
Types,
|
|
9
|
+
type ChildSpace3D,
|
|
10
|
+
type Color,
|
|
11
|
+
type Geometry3D,
|
|
12
|
+
type Material3D,
|
|
13
|
+
type Mesh3DProps,
|
|
14
|
+
type NodeOf,
|
|
15
|
+
type NormalizedColor,
|
|
16
|
+
type Values,
|
|
17
|
+
type Vector3,
|
|
18
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
19
|
+
type Blend3D as _Blend3D,
|
|
20
|
+
type Color as _Color,
|
|
21
|
+
type Faces3D as _Faces3D,
|
|
22
|
+
type Fill3D as _Fill3D,
|
|
23
|
+
type Node3D as _Node3D,
|
|
24
|
+
type Node3DProps as _Node3DProps,
|
|
25
|
+
type NormalizedColor as _NormalizedColor,
|
|
26
|
+
type Shading3D as _Shading3D,
|
|
27
|
+
type Texture3D as _Texture3D,
|
|
28
|
+
} from "@motionscript/sdk";
|
|
29
|
+
import type { Interval } from "../kit/coords";
|
|
30
|
+
import { parseSurface, surfaceParams, type SurfaceEquation } from "../kit/equation3d";
|
|
31
|
+
import type { ExpressionScope } from "../kit/expression";
|
|
32
|
+
import { PLOT_COLOR } from "../kit/furniture";
|
|
33
|
+
import { clamp } from "../kit/geometry";
|
|
34
|
+
import { colorAt, lerpScale, readScale } from "../kit/scale";
|
|
35
|
+
import { lerpParams, lerpSource, readSource, revisionOf, scopeFor, type PlotSource } from "../kit/source";
|
|
36
|
+
import { domainEntry, meshEntries } from "./entries";
|
|
37
|
+
import { graphEntry, graphOf, type GraphSpace } from "./space";
|
|
38
|
+
|
|
39
|
+
export interface SurfacePlot3dProps extends Mesh3DProps {
|
|
40
|
+
expression?: string | PlotSource;
|
|
41
|
+
uDomain?: Interval | null;
|
|
42
|
+
vDomain?: Interval | null;
|
|
43
|
+
params?: ExpressionScope;
|
|
44
|
+
segments?: number;
|
|
45
|
+
colorScale?: Color[];
|
|
46
|
+
meshLines?: number;
|
|
47
|
+
meshColor?: Color;
|
|
48
|
+
floorShadow?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A graph point for grid coordinate `(u, v)`, both 0 to 1, written into `out`. */
|
|
52
|
+
type SurfaceSampler = (u: number, v: number, out: Vector3) => void;
|
|
53
|
+
|
|
54
|
+
const state = {
|
|
55
|
+
...meshEntries,
|
|
56
|
+
expression: Types.custom<string | PlotSource, PlotSource>("", {
|
|
57
|
+
resolve: readSource,
|
|
58
|
+
lerp: lerpSource,
|
|
59
|
+
kind: "surfaceEquation",
|
|
60
|
+
}),
|
|
61
|
+
/**
|
|
62
|
+
* The span of each variable that is drawn: x and y for a height, which run
|
|
63
|
+
* the width of the axes when left out, u and v for a parametric surface,
|
|
64
|
+
* which run from 0 to 1.
|
|
65
|
+
*/
|
|
66
|
+
uDomain: domainEntry(-3, 3),
|
|
67
|
+
vDomain: domainEntry(-3, 3),
|
|
68
|
+
/** The equation's named values: any name in it that is not a variable, a function or a constant. */
|
|
69
|
+
params: Types.custom<ExpressionScope>({}, { lerp: lerpParams }),
|
|
70
|
+
/** How finely the surface is sampled, each way. */
|
|
71
|
+
segments: Types.number(48, { min: 2, max: 256, step: 1, animatable: false }),
|
|
72
|
+
/** Colours by height, lowest first, over the axes' z range. Empty paints the surface in its fill. */
|
|
73
|
+
colorScale: Types.custom<Color[], NormalizedColor[]>([], { resolve: readScale, lerp: lerpScale, kind: "vector" }),
|
|
74
|
+
/** How many lines are drawn across the surface each way; zero leaves it bare. */
|
|
75
|
+
meshLines: Types.number(12, { min: 0, max: 64, step: 1, animatable: false }),
|
|
76
|
+
meshColor: Types.custom<Color, Color>("#0b1220", { kind: "color" }),
|
|
77
|
+
/** The opacity of the surface's shadow, laid flat on the floor of the axes and coloured by height; zero draws none. */
|
|
78
|
+
floorShadow: Types.number(0, { min: 0, max: 1, step: 0.01 }),
|
|
79
|
+
graph: graphEntry(),
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/** What a surface is drawn from: its own entries, as its node and its helpers read them. */
|
|
83
|
+
export type SurfaceValues = Values<typeof state> & { readonly x: number; readonly y: number; readonly z: number };
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A surface in a 3D graph: a height over x and y (`sin(x) * cos(y)`), or three
|
|
87
|
+
* parts in u and v. A point put inside it rides it.
|
|
88
|
+
*/
|
|
89
|
+
export const SurfacePlot3d = component3d({
|
|
90
|
+
key: "surfacePlot3d",
|
|
91
|
+
state,
|
|
92
|
+
defaults: { fill: PLOT_COLOR },
|
|
93
|
+
commands: {
|
|
94
|
+
/** Change the equation, the surface bending from the one into the other. */
|
|
95
|
+
morphTo: { args: ["expression"] },
|
|
96
|
+
/** Animate the equation's named values. */
|
|
97
|
+
paramsTo: { args: ["params"] },
|
|
98
|
+
/** Animate the spans that are drawn. */
|
|
99
|
+
domainTo: { args: ["uDomain", "vDomain"] },
|
|
100
|
+
},
|
|
101
|
+
space: (s) => surfaceSpace(s),
|
|
102
|
+
render: (ctx, s) => ctx.draw(drawSurface(s)),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export type SurfacePlot3d = NodeOf<typeof SurfacePlot3d>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The surface's height above its own origin at graph `(x, y)`, or `NaN`
|
|
109
|
+
* where it has none or is not a height. What a point riding it reads.
|
|
110
|
+
*/
|
|
111
|
+
export function surfaceValueAt(surface: Pick<SurfaceValues, "expression" | "params">, x: number, y: number): number {
|
|
112
|
+
const { source, blend } = surface.expression;
|
|
113
|
+
const value = heightOf(surface, source, x, y);
|
|
114
|
+
if (!blend) return value;
|
|
115
|
+
const from = heightOf(surface, blend.from, x, y);
|
|
116
|
+
return from + (value - from) * blend.t;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** A point inside a surface stands on it: its `x` and `y` say where, and its height is the surface's. */
|
|
120
|
+
function surfaceSpace(s: SurfaceValues): ChildSpace3D | null {
|
|
121
|
+
const space = graphOf(s);
|
|
122
|
+
if (!space) return null;
|
|
123
|
+
return {
|
|
124
|
+
toLocal: (x, y, z) => {
|
|
125
|
+
const height = surfaceValueAt(s, x, y);
|
|
126
|
+
return space.offset(x, y, Number.isFinite(height) ? height : z);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function drawSurface(s: SurfaceValues): Graphics3D {
|
|
132
|
+
const g3 = new Graphics3D();
|
|
133
|
+
const space = graphOf(s);
|
|
134
|
+
const lines = space ? meshLines(s, space) : [];
|
|
135
|
+
const scaled = s.colorScale.length > 0;
|
|
136
|
+
// A surface is seen from both sides; a vertex colour multiplies the fill, so a scale is shown on white.
|
|
137
|
+
const surface = { ...s, faces: s.faces ?? "both", ...(scaled ? { vertexColors: true, fill: "white" } : {}) };
|
|
138
|
+
for (const op of Material.mesh(surface, space ? surfaceGeometry(s, space) : undefined).ops()) {
|
|
139
|
+
if (op.kind !== "mesh") continue;
|
|
140
|
+
g3.mesh(op.geometry, mapMaterials(op.material, (material) => ({
|
|
141
|
+
...material,
|
|
142
|
+
// Pushed back a hair so the lines drawn on it are not fought for, and blended rather than a hole when faded.
|
|
143
|
+
...(lines.length > 0 ? { polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 } : {}),
|
|
144
|
+
...((s.opacity ?? 1) < 1 ? { depthWrite: false } : {}),
|
|
145
|
+
} as Material3D)), op.transform);
|
|
146
|
+
}
|
|
147
|
+
if (lines.length > 0) {
|
|
148
|
+
const color = colorOps.resolve(s.meshColor);
|
|
149
|
+
g3.line({ points: lines, segments: true, stroke: { fill: color }, opacity: color[3] * (s.opacity ?? 1) });
|
|
150
|
+
}
|
|
151
|
+
const shadow = space && s.floorShadow > 0 ? floorShadow(s, space) : undefined;
|
|
152
|
+
if (shadow) {
|
|
153
|
+
g3.mesh(shadow, Mat.basic({
|
|
154
|
+
color: scaled ? "white" : PLOT_COLOR,
|
|
155
|
+
vertexColors: scaled,
|
|
156
|
+
opacity: s.floorShadow * (s.opacity ?? 1),
|
|
157
|
+
transparent: true,
|
|
158
|
+
// Translucent and under everything: writing depth would hide the floor's grid lines behind it.
|
|
159
|
+
depthWrite: false,
|
|
160
|
+
faces: "both",
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
return g3;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function surfaceGeometry(s: SurfaceValues, space: GraphSpace): Geometry3D | undefined {
|
|
167
|
+
const sample = sampler(s, space);
|
|
168
|
+
if (!sample) return undefined;
|
|
169
|
+
const scale = s.colorScale;
|
|
170
|
+
const point: Vector3 = { x: 0, y: 0, z: 0 };
|
|
171
|
+
const low = space.offset(0, 0, space.zRange[0] - s.z).y;
|
|
172
|
+
const high = space.offset(0, 0, space.zRange[1] - s.z).y;
|
|
173
|
+
return Geo.parametric({
|
|
174
|
+
segments: Math.max(2, Math.round(s.segments)),
|
|
175
|
+
vertex: (u, v) => {
|
|
176
|
+
sample(u, v, point);
|
|
177
|
+
return space.offset(point.x, point.y, point.z);
|
|
178
|
+
},
|
|
179
|
+
...(scale.length > 0
|
|
180
|
+
? { color: (_u, _v, position) => colorAt(scale, high > low ? (position.y - low) / (high - low) : 0) }
|
|
181
|
+
: {}),
|
|
182
|
+
computeNormals: true,
|
|
183
|
+
revision: revisionOf(`${keyOf(s, space)}|${JSON.stringify(scale)}`),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function heightOf(surface: Pick<SurfaceValues, "params">, source: string, x: number, y: number): number {
|
|
188
|
+
const equation = equationOf(source);
|
|
189
|
+
if (equation?.kind !== "height") return NaN;
|
|
190
|
+
return equation.f(x, y, scopeFor(surfaceParams(source), surface.params));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function keyOf(s: SurfaceValues, space: GraphSpace): string {
|
|
194
|
+
const { source, blend } = s.expression;
|
|
195
|
+
return [source, blend?.from, blend?.t, space.revision, s.uDomain, s.vDomain, JSON.stringify(s.params), s.x, s.y, s.z].join("|");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function sampler(s: SurfaceValues, space: GraphSpace): SurfaceSampler | null {
|
|
199
|
+
const { source, blend } = s.expression;
|
|
200
|
+
const to = surfaceOf(s, source, space);
|
|
201
|
+
if (!to || !blend) return to;
|
|
202
|
+
const from = surfaceOf(s, blend.from, space);
|
|
203
|
+
if (!from) return to;
|
|
204
|
+
const start: Vector3 = { x: 0, y: 0, z: 0 };
|
|
205
|
+
return (u, v, out) => {
|
|
206
|
+
from(u, v, start);
|
|
207
|
+
to(u, v, out);
|
|
208
|
+
out.x = start.x + (out.x - start.x) * blend.t;
|
|
209
|
+
out.y = start.y + (out.y - start.y) * blend.t;
|
|
210
|
+
out.z = start.z + (out.z - start.z) * blend.t;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** `source` as graph points, measured from the surface's own position. */
|
|
215
|
+
function surfaceOf(s: SurfaceValues, source: string, space: GraphSpace): SurfaceSampler | null {
|
|
216
|
+
const equation = equationOf(source);
|
|
217
|
+
if (!equation) return null;
|
|
218
|
+
const params = scopeFor(surfaceParams(source), s.params);
|
|
219
|
+
if (equation.kind === "parametric") {
|
|
220
|
+
const [u0, u1] = s.uDomain ?? [0, 1];
|
|
221
|
+
const [v0, v1] = s.vDomain ?? [0, 1];
|
|
222
|
+
const { x, y, z } = equation;
|
|
223
|
+
return (u, v, out) => {
|
|
224
|
+
const a = u0 + (u1 - u0) * u;
|
|
225
|
+
const b = v0 + (v1 - v0) * v;
|
|
226
|
+
out.x = finite(x(a, b, params));
|
|
227
|
+
out.y = finite(y(a, b, params));
|
|
228
|
+
out.z = finite(z(a, b, params));
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
const [x0, x1] = s.uDomain ?? [space.xRange[0] - s.x, space.xRange[1] - s.x];
|
|
232
|
+
const [y0, y1] = s.vDomain ?? [space.yRange[0] - s.y, space.yRange[1] - s.y];
|
|
233
|
+
// Held inside the axes: a pole would otherwise stretch one triangle across the scene.
|
|
234
|
+
const low = space.zRange[0] - s.z;
|
|
235
|
+
const high = space.zRange[1] - s.z;
|
|
236
|
+
const { f } = equation;
|
|
237
|
+
return (u, v, out) => {
|
|
238
|
+
out.x = x0 + (x1 - x0) * u;
|
|
239
|
+
out.y = y0 + (y1 - y0) * v;
|
|
240
|
+
out.z = clamp(finite(f(out.x, out.y, params)), low, high);
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function floorShadow(s: SurfaceValues, space: GraphSpace): Geometry3D | undefined {
|
|
245
|
+
const sample = sampler(s, space);
|
|
246
|
+
if (!sample) return undefined;
|
|
247
|
+
const scale = s.colorScale;
|
|
248
|
+
const [low, high] = space.zRange;
|
|
249
|
+
const floor = low - s.z;
|
|
250
|
+
const point: Vector3 = { x: 0, y: 0, z: 0 };
|
|
251
|
+
return Geo.parametric({
|
|
252
|
+
segments: Math.max(2, Math.round(s.segments)),
|
|
253
|
+
vertex: (u, v) => {
|
|
254
|
+
sample(u, v, point);
|
|
255
|
+
return space.offset(point.x, point.y, floor);
|
|
256
|
+
},
|
|
257
|
+
...(scale.length > 0
|
|
258
|
+
? {
|
|
259
|
+
color: (u: number, v: number) => {
|
|
260
|
+
sample(u, v, point);
|
|
261
|
+
return colorAt(scale, high > low ? (point.z + s.z - low) / (high - low) : 0);
|
|
262
|
+
},
|
|
263
|
+
}
|
|
264
|
+
: {}),
|
|
265
|
+
revision: revisionOf(`${keyOf(s, space)}|${JSON.stringify(scale)}|floor`),
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** The last lines drawn for each surface, kept while what they are drawn from is unchanged. */
|
|
270
|
+
const linesDrawn = new WeakMap<object, { readonly key: string; readonly lines: Vector3[] }>();
|
|
271
|
+
|
|
272
|
+
function meshLines(s: SurfaceValues, space: GraphSpace): Vector3[] {
|
|
273
|
+
const count = Math.round(s.meshLines);
|
|
274
|
+
const sample = count > 0 ? sampler(s, space) : null;
|
|
275
|
+
if (!sample) return [];
|
|
276
|
+
const steps = Math.max(2, Math.round(s.segments));
|
|
277
|
+
const key = `${keyOf(s, space)}|${count}|${steps}`;
|
|
278
|
+
const kept = linesDrawn.get(s);
|
|
279
|
+
if (kept?.key === key) return kept.lines;
|
|
280
|
+
const lines: Vector3[] = [];
|
|
281
|
+
const point: Vector3 = { x: 0, y: 0, z: 0 };
|
|
282
|
+
const at = (u: number, v: number): Vector3 => {
|
|
283
|
+
sample(u, v, point);
|
|
284
|
+
return space.offset(point.x, point.y, point.z);
|
|
285
|
+
};
|
|
286
|
+
for (let i = 0; i <= count; i++) {
|
|
287
|
+
const fixed = i / count;
|
|
288
|
+
for (let j = 0; j < steps; j++) {
|
|
289
|
+
lines.push(at(fixed, j / steps), at(fixed, (j + 1) / steps));
|
|
290
|
+
lines.push(at(j / steps, fixed), at((j + 1) / steps, fixed));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
linesDrawn.set(s, { key, lines });
|
|
294
|
+
return lines;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function equationOf(source: string): SurfaceEquation | null {
|
|
298
|
+
const equation = parseSurface(source, surfaceParams(source));
|
|
299
|
+
return equation instanceof Error ? null : equation;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// A hole in the data is drawn flat rather than as a hole in the mesh.
|
|
303
|
+
function finite(value: number): number {
|
|
304
|
+
return Number.isFinite(value) ? value : 0;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function mapMaterials(
|
|
308
|
+
material: Material3D | readonly Material3D[],
|
|
309
|
+
change: (material: Material3D) => Material3D,
|
|
310
|
+
): Material3D | readonly Material3D[] {
|
|
311
|
+
return Array.isArray(material) ? (material as readonly Material3D[]).map(change) : change(material as Material3D);
|
|
312
|
+
}
|