@motionscript/math 0.0.0-stage → 0.1.0-alpha.4

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.
Files changed (322) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +48 -0
  4. package/README.md +385 -3
  5. package/dist/annotate/angle-mark.d.ts +46 -0
  6. package/dist/annotate/angle-mark.d.ts.map +1 -0
  7. package/dist/annotate/angle-mark.js +132 -0
  8. package/dist/annotate/angle-mark.js.map +1 -0
  9. package/dist/annotate/curly-brace.d.ts +46 -0
  10. package/dist/annotate/curly-brace.d.ts.map +1 -0
  11. package/dist/annotate/curly-brace.js +114 -0
  12. package/dist/annotate/curly-brace.js.map +1 -0
  13. package/dist/annotate/emphasis-mark.d.ts +20 -0
  14. package/dist/annotate/emphasis-mark.d.ts.map +1 -0
  15. package/dist/annotate/emphasis-mark.js +81 -0
  16. package/dist/annotate/emphasis-mark.js.map +1 -0
  17. package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
  18. package/dist/browser/chunks/chunk-3GJB6AVO.js +2 -0
  19. package/dist/browser/chunks/chunk-3GJB6AVO.js.map +7 -0
  20. package/dist/browser/chunks/chunk-D5WHCVBC.js +2 -0
  21. package/dist/browser/chunks/chunk-D5WHCVBC.js.map +7 -0
  22. package/dist/browser/chunks/chunk-WL4KEX7Y.js +2 -0
  23. package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +7 -0
  24. package/dist/browser/chunks/mathjax-DNP3YRES.js +61 -0
  25. package/dist/browser/chunks/mathjax-DNP3YRES.js.map +7 -0
  26. package/dist/browser/index.js +2 -0
  27. package/dist/browser/index.js.map +7 -0
  28. package/dist/browser/kit.js +2 -0
  29. package/dist/browser/kit.js.map +7 -0
  30. package/dist/browser/manifest.json +30 -0
  31. package/dist/browser/tex.js +2 -0
  32. package/dist/browser/tex.js.map +7 -0
  33. package/dist/engine.d.ts +64 -0
  34. package/dist/engine.d.ts.map +1 -0
  35. package/dist/engine.js +42 -0
  36. package/dist/engine.js.map +1 -0
  37. package/dist/index.d.ts +30 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +30 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/kit/brace.d.ts +8 -0
  42. package/dist/kit/brace.d.ts.map +1 -0
  43. package/dist/kit/brace.js +36 -0
  44. package/dist/kit/brace.js.map +1 -0
  45. package/dist/kit/cache.d.ts +30 -0
  46. package/dist/kit/cache.d.ts.map +1 -0
  47. package/dist/kit/cache.js +53 -0
  48. package/dist/kit/cache.js.map +1 -0
  49. package/dist/kit/contour.d.ts +8 -0
  50. package/dist/kit/contour.d.ts.map +1 -0
  51. package/dist/kit/contour.js +93 -0
  52. package/dist/kit/contour.js.map +1 -0
  53. package/dist/kit/coords.d.ts +69 -0
  54. package/dist/kit/coords.d.ts.map +1 -0
  55. package/dist/kit/coords.js +224 -0
  56. package/dist/kit/coords.js.map +1 -0
  57. package/dist/kit/curve.d.ts +17 -0
  58. package/dist/kit/curve.d.ts.map +1 -0
  59. package/dist/kit/curve.js +22 -0
  60. package/dist/kit/curve.js.map +1 -0
  61. package/dist/kit/equation.d.ts +61 -0
  62. package/dist/kit/equation.d.ts.map +1 -0
  63. package/dist/kit/equation.js +168 -0
  64. package/dist/kit/equation.js.map +1 -0
  65. package/dist/kit/equation3d.d.ts +50 -0
  66. package/dist/kit/equation3d.d.ts.map +1 -0
  67. package/dist/kit/equation3d.js +103 -0
  68. package/dist/kit/equation3d.js.map +1 -0
  69. package/dist/kit/expression.d.ts +35 -0
  70. package/dist/kit/expression.d.ts.map +1 -0
  71. package/dist/kit/expression.js +124 -0
  72. package/dist/kit/expression.js.map +1 -0
  73. package/dist/kit/field-mark.d.ts +58 -0
  74. package/dist/kit/field-mark.d.ts.map +1 -0
  75. package/dist/kit/field-mark.js +129 -0
  76. package/dist/kit/field-mark.js.map +1 -0
  77. package/dist/kit/field.d.ts +14 -0
  78. package/dist/kit/field.d.ts.map +1 -0
  79. package/dist/kit/field.js +46 -0
  80. package/dist/kit/field.js.map +1 -0
  81. package/dist/kit/follow.d.ts +71 -0
  82. package/dist/kit/follow.d.ts.map +1 -0
  83. package/dist/kit/follow.js +159 -0
  84. package/dist/kit/follow.js.map +1 -0
  85. package/dist/kit/furniture.d.ts +30 -0
  86. package/dist/kit/furniture.d.ts.map +1 -0
  87. package/dist/kit/furniture.js +87 -0
  88. package/dist/kit/furniture.js.map +1 -0
  89. package/dist/kit/geometry.d.ts +13 -0
  90. package/dist/kit/geometry.d.ts.map +1 -0
  91. package/dist/kit/geometry.js +54 -0
  92. package/dist/kit/geometry.js.map +1 -0
  93. package/dist/kit/mark.d.ts +47 -0
  94. package/dist/kit/mark.d.ts.map +1 -0
  95. package/dist/kit/mark.js +103 -0
  96. package/dist/kit/mark.js.map +1 -0
  97. package/dist/kit/part-fills.d.ts +23 -0
  98. package/dist/kit/part-fills.d.ts.map +1 -0
  99. package/dist/kit/part-fills.js +46 -0
  100. package/dist/kit/part-fills.js.map +1 -0
  101. package/dist/kit/place.d.ts +18 -0
  102. package/dist/kit/place.d.ts.map +1 -0
  103. package/dist/kit/place.js +68 -0
  104. package/dist/kit/place.js.map +1 -0
  105. package/dist/kit/placement.d.ts +8 -0
  106. package/dist/kit/placement.d.ts.map +1 -0
  107. package/dist/kit/placement.js +8 -0
  108. package/dist/kit/placement.js.map +1 -0
  109. package/dist/kit/sampler.d.ts +17 -0
  110. package/dist/kit/sampler.d.ts.map +1 -0
  111. package/dist/kit/sampler.js +250 -0
  112. package/dist/kit/sampler.js.map +1 -0
  113. package/dist/kit/scale.d.ts +12 -0
  114. package/dist/kit/scale.d.ts.map +1 -0
  115. package/dist/kit/scale.js +37 -0
  116. package/dist/kit/scale.js.map +1 -0
  117. package/dist/kit/source.d.ts +22 -0
  118. package/dist/kit/source.d.ts.map +1 -0
  119. package/dist/kit/source.js +45 -0
  120. package/dist/kit/source.js.map +1 -0
  121. package/dist/kit/system.d.ts +33 -0
  122. package/dist/kit/system.d.ts.map +1 -0
  123. package/dist/kit/system.js +67 -0
  124. package/dist/kit/system.js.map +1 -0
  125. package/dist/kit/ticks.d.ts +19 -0
  126. package/dist/kit/ticks.d.ts.map +1 -0
  127. package/dist/kit/ticks.js +78 -0
  128. package/dist/kit/ticks.js.map +1 -0
  129. package/dist/kit/withdrawn.d.ts +9 -0
  130. package/dist/kit/withdrawn.d.ts.map +1 -0
  131. package/dist/kit/withdrawn.js +9 -0
  132. package/dist/kit/withdrawn.js.map +1 -0
  133. package/dist/marks/curve-area.d.ts +32 -0
  134. package/dist/marks/curve-area.d.ts.map +1 -0
  135. package/dist/marks/curve-area.js +82 -0
  136. package/dist/marks/curve-area.js.map +1 -0
  137. package/dist/marks/drop-lines.d.ts +22 -0
  138. package/dist/marks/drop-lines.d.ts.map +1 -0
  139. package/dist/marks/drop-lines.js +58 -0
  140. package/dist/marks/drop-lines.js.map +1 -0
  141. package/dist/marks/plot-point.d.ts +35 -0
  142. package/dist/marks/plot-point.d.ts.map +1 -0
  143. package/dist/marks/plot-point.js +97 -0
  144. package/dist/marks/plot-point.js.map +1 -0
  145. package/dist/marks/riemann-sum.d.ts +37 -0
  146. package/dist/marks/riemann-sum.d.ts.map +1 -0
  147. package/dist/marks/riemann-sum.js +91 -0
  148. package/dist/marks/riemann-sum.js.map +1 -0
  149. package/dist/marks/tangent-line.d.ts +27 -0
  150. package/dist/marks/tangent-line.d.ts.map +1 -0
  151. package/dist/marks/tangent-line.js +103 -0
  152. package/dist/marks/tangent-line.js.map +1 -0
  153. package/dist/marks/vector-arrow.d.ts +32 -0
  154. package/dist/marks/vector-arrow.d.ts.map +1 -0
  155. package/dist/marks/vector-arrow.js +87 -0
  156. package/dist/marks/vector-arrow.js.map +1 -0
  157. package/dist/nodes.d.ts +35 -0
  158. package/dist/nodes.d.ts.map +1 -0
  159. package/dist/nodes.js +63 -0
  160. package/dist/nodes.js.map +1 -0
  161. package/dist/plots/function-plot.d.ts +67 -0
  162. package/dist/plots/function-plot.d.ts.map +1 -0
  163. package/dist/plots/function-plot.js +215 -0
  164. package/dist/plots/function-plot.js.map +1 -0
  165. package/dist/plots/points-plot.d.ts +28 -0
  166. package/dist/plots/points-plot.d.ts.map +1 -0
  167. package/dist/plots/points-plot.js +99 -0
  168. package/dist/plots/points-plot.js.map +1 -0
  169. package/dist/plots/stream-lines.d.ts +35 -0
  170. package/dist/plots/stream-lines.d.ts.map +1 -0
  171. package/dist/plots/stream-lines.js +141 -0
  172. package/dist/plots/stream-lines.js.map +1 -0
  173. package/dist/plots/traced-path.d.ts +31 -0
  174. package/dist/plots/traced-path.d.ts.map +1 -0
  175. package/dist/plots/traced-path.js +56 -0
  176. package/dist/plots/traced-path.js.map +1 -0
  177. package/dist/plots/vector-field.d.ts +23 -0
  178. package/dist/plots/vector-field.d.ts.map +1 -0
  179. package/dist/plots/vector-field.js +91 -0
  180. package/dist/plots/vector-field.js.map +1 -0
  181. package/dist/structures/graph-layout.d.ts +11 -0
  182. package/dist/structures/graph-layout.d.ts.map +1 -0
  183. package/dist/structures/graph-layout.js +135 -0
  184. package/dist/structures/graph-layout.js.map +1 -0
  185. package/dist/structures/network-graph.d.ts +83 -0
  186. package/dist/structures/network-graph.d.ts.map +1 -0
  187. package/dist/structures/network-graph.js +289 -0
  188. package/dist/structures/network-graph.js.map +1 -0
  189. package/dist/structures/sample-space.d.ts +62 -0
  190. package/dist/structures/sample-space.d.ts.map +1 -0
  191. package/dist/structures/sample-space.js +199 -0
  192. package/dist/structures/sample-space.js.map +1 -0
  193. package/dist/systems/axes2d.d.ts +75 -0
  194. package/dist/systems/axes2d.d.ts.map +1 -0
  195. package/dist/systems/axes2d.js +193 -0
  196. package/dist/systems/axes2d.js.map +1 -0
  197. package/dist/systems/number-line.d.ts +49 -0
  198. package/dist/systems/number-line.d.ts.map +1 -0
  199. package/dist/systems/number-line.js +127 -0
  200. package/dist/systems/number-line.js.map +1 -0
  201. package/dist/systems/number-plane.d.ts +59 -0
  202. package/dist/systems/number-plane.d.ts.map +1 -0
  203. package/dist/systems/number-plane.js +193 -0
  204. package/dist/systems/number-plane.js.map +1 -0
  205. package/dist/systems/polar-plane.d.ts +48 -0
  206. package/dist/systems/polar-plane.d.ts.map +1 -0
  207. package/dist/systems/polar-plane.js +165 -0
  208. package/dist/systems/polar-plane.js.map +1 -0
  209. package/dist/tex/geometry.d.ts +85 -0
  210. package/dist/tex/geometry.d.ts.map +1 -0
  211. package/dist/tex/geometry.js +632 -0
  212. package/dist/tex/geometry.js.map +1 -0
  213. package/dist/tex/index.d.ts +11 -0
  214. package/dist/tex/index.d.ts.map +1 -0
  215. package/dist/tex/index.js +9 -0
  216. package/dist/tex/index.js.map +1 -0
  217. package/dist/tex/mathjax.d.ts +33 -0
  218. package/dist/tex/mathjax.d.ts.map +1 -0
  219. package/dist/tex/mathjax.js +74 -0
  220. package/dist/tex/mathjax.js.map +1 -0
  221. package/dist/tex/matrix.d.ts +31 -0
  222. package/dist/tex/matrix.d.ts.map +1 -0
  223. package/dist/tex/matrix.js +73 -0
  224. package/dist/tex/matrix.js.map +1 -0
  225. package/dist/tex/node.d.ts +215 -0
  226. package/dist/tex/node.d.ts.map +1 -0
  227. package/dist/tex/node.js +595 -0
  228. package/dist/tex/node.js.map +1 -0
  229. package/dist/tex/tween.d.ts +50 -0
  230. package/dist/tex/tween.d.ts.map +1 -0
  231. package/dist/tex/tween.js +253 -0
  232. package/dist/tex/tween.js.map +1 -0
  233. package/dist/three/axes3d.d.ts +87 -0
  234. package/dist/three/axes3d.d.ts.map +1 -0
  235. package/dist/three/axes3d.js +228 -0
  236. package/dist/three/axes3d.js.map +1 -0
  237. package/dist/three/curve-plot3d.d.ts +60 -0
  238. package/dist/three/curve-plot3d.d.ts.map +1 -0
  239. package/dist/three/curve-plot3d.js +143 -0
  240. package/dist/three/curve-plot3d.js.map +1 -0
  241. package/dist/three/label3d.d.ts +11 -0
  242. package/dist/three/label3d.d.ts.map +1 -0
  243. package/dist/three/label3d.js +40 -0
  244. package/dist/three/label3d.js.map +1 -0
  245. package/dist/three/plot-point3d.d.ts +26 -0
  246. package/dist/three/plot-point3d.d.ts.map +1 -0
  247. package/dist/three/plot-point3d.js +60 -0
  248. package/dist/three/plot-point3d.js.map +1 -0
  249. package/dist/three/space.d.ts +28 -0
  250. package/dist/three/space.d.ts.map +1 -0
  251. package/dist/three/space.js +47 -0
  252. package/dist/three/space.js.map +1 -0
  253. package/dist/three/surface-plot3d.d.ts +80 -0
  254. package/dist/three/surface-plot3d.d.ts.map +1 -0
  255. package/dist/three/surface-plot3d.js +290 -0
  256. package/dist/three/surface-plot3d.js.map +1 -0
  257. package/dist/three/vector-arrow3d.d.ts +25 -0
  258. package/dist/three/vector-arrow3d.d.ts.map +1 -0
  259. package/dist/three/vector-arrow3d.js +72 -0
  260. package/dist/three/vector-arrow3d.js.map +1 -0
  261. package/package.json +79 -3
  262. package/registry.json +251 -0
  263. package/src/annotate/angle-mark.ts +147 -0
  264. package/src/annotate/curly-brace.ts +126 -0
  265. package/src/annotate/emphasis-mark.ts +89 -0
  266. package/src/engine.ts +72 -0
  267. package/src/index.ts +29 -0
  268. package/src/kit/brace.ts +37 -0
  269. package/src/kit/cache.ts +61 -0
  270. package/src/kit/contour.ts +94 -0
  271. package/src/kit/coords.ts +278 -0
  272. package/src/kit/curve.ts +29 -0
  273. package/src/kit/equation.ts +181 -0
  274. package/src/kit/equation3d.ts +137 -0
  275. package/src/kit/expression.ts +159 -0
  276. package/src/kit/field-mark.ts +155 -0
  277. package/src/kit/field.ts +50 -0
  278. package/src/kit/follow.ts +203 -0
  279. package/src/kit/furniture.ts +108 -0
  280. package/src/kit/geometry.ts +49 -0
  281. package/src/kit/mark.ts +131 -0
  282. package/src/kit/part-fills.ts +61 -0
  283. package/src/kit/place.ts +101 -0
  284. package/src/kit/placement.ts +8 -0
  285. package/src/kit/sampler.ts +281 -0
  286. package/src/kit/scale.ts +39 -0
  287. package/src/kit/source.ts +57 -0
  288. package/src/kit/system.ts +99 -0
  289. package/src/kit/ticks.ts +85 -0
  290. package/src/kit/withdrawn.ts +8 -0
  291. package/src/marks/curve-area.ts +89 -0
  292. package/src/marks/drop-lines.ts +63 -0
  293. package/src/marks/plot-point.ts +107 -0
  294. package/src/marks/riemann-sum.ts +98 -0
  295. package/src/marks/tangent-line.ts +103 -0
  296. package/src/marks/vector-arrow.ts +98 -0
  297. package/src/nodes.ts +63 -0
  298. package/src/plots/function-plot.ts +236 -0
  299. package/src/plots/points-plot.ts +107 -0
  300. package/src/plots/stream-lines.ts +151 -0
  301. package/src/plots/traced-path.ts +52 -0
  302. package/src/plots/vector-field.ts +88 -0
  303. package/src/structures/graph-layout.ts +145 -0
  304. package/src/structures/network-graph.ts +308 -0
  305. package/src/structures/sample-space.ts +209 -0
  306. package/src/systems/axes2d.ts +217 -0
  307. package/src/systems/number-line.ts +131 -0
  308. package/src/systems/number-plane.ts +203 -0
  309. package/src/systems/polar-plane.ts +176 -0
  310. package/src/tex/geometry.ts +703 -0
  311. package/src/tex/index.ts +14 -0
  312. package/src/tex/mathjax.ts +82 -0
  313. package/src/tex/matrix.ts +75 -0
  314. package/src/tex/node.ts +641 -0
  315. package/src/tex/tween.ts +308 -0
  316. package/src/three/axes3d.ts +240 -0
  317. package/src/three/curve-plot3d.ts +147 -0
  318. package/src/three/label3d.ts +50 -0
  319. package/src/three/plot-point3d.ts +66 -0
  320. package/src/three/space.ts +67 -0
  321. package/src/three/surface-plot3d.ts +323 -0
  322. package/src/three/vector-arrow3d.ts +77 -0
@@ -0,0 +1,49 @@
1
+ import type { Extents, PathCommand, Vector2 } from "@motionscript/sdk";
2
+
3
+ /**
4
+ * Runs of pixel points as path commands. Commands are y-up like every other
5
+ * `Graphics2D` op (only an SVG `d` string is y-down), so nothing is flipped here.
6
+ */
7
+ export function runsToPath(runs: readonly (readonly Vector2[])[], closed = false): PathCommand[] {
8
+ const out: PathCommand[] = [];
9
+ for (const run of runs) {
10
+ if (run.length < 2) continue;
11
+ out.push({ type: "M", x: run[0].x, y: run[0].y });
12
+ for (let i = 1; i < run.length; i++) out.push({ type: "L", x: run[i].x, y: run[i].y });
13
+ if (closed) out.push({ type: "Z" });
14
+ }
15
+ return out;
16
+ }
17
+
18
+ export function boundsOfRuns(runs: readonly (readonly Vector2[])[]): Extents | null {
19
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
20
+ for (const run of runs) {
21
+ if (run.length < 2) continue;
22
+ for (const p of run) {
23
+ if (p.x < minX) minX = p.x;
24
+ if (p.x > maxX) maxX = p.x;
25
+ if (p.y < minY) minY = p.y;
26
+ if (p.y > maxY) maxY = p.y;
27
+ }
28
+ }
29
+ return minX <= maxX ? { minX, minY, maxX, maxY } : null;
30
+ }
31
+
32
+ /** `area` grown by `margin` on every side. */
33
+ export function inflate(area: Extents, margin: number): Extents {
34
+ return { minX: area.minX - margin, minY: area.minY - margin, maxX: area.maxX + margin, maxY: area.maxY + margin };
35
+ }
36
+
37
+ export function clamp(value: number, min: number, max: number): number {
38
+ return value < min ? min : value > max ? max : value;
39
+ }
40
+
41
+ /** `data` without the arguments a command was not given, which arrive as `undefined` and are not destinations. */
42
+ export function stated<T extends object>(data: T | undefined): Partial<T> {
43
+ const out: Partial<T> = {};
44
+ if (!data) return out;
45
+ for (const key of Object.keys(data) as (keyof T)[]) {
46
+ if (data[key] !== undefined) out[key] = data[key];
47
+ }
48
+ return out;
49
+ }
@@ -0,0 +1,131 @@
1
+ import {
2
+ Graphics2D,
3
+ PaintNode,
4
+ type BoxBounds,
5
+ type ChildPlane,
6
+ type Extents,
7
+ type MeasureContext2D,
8
+ type Node2D,
9
+ type PaintProps,
10
+ type PathCommand,
11
+ type RenderContext2D,
12
+ type Size2D,
13
+ type Vector2,
14
+ } from "@motionscript/sdk";
15
+ import { PIXEL_MAP, type CoordinateMap } from "./coords";
16
+ import { boundsOfRuns, runsToPath } from "./geometry";
17
+ import { openPlane, placeOnMap } from "./place";
18
+
19
+ /**
20
+ * A node drawn in graph coordinates: a plot, an area, an arrow between two
21
+ * graph points. It answers with runs of pixel points and is otherwise a shape,
22
+ * so fill, stroke, shadow and `progressTo` are the inherited ones and its box
23
+ * is the tight box of its ink.
24
+ *
25
+ * Inside a coordinate system the system lays it out and its own `x`/`y` are a
26
+ * shift in graph units, which {@link shift} reports and {@link trace} applies.
27
+ * Outside one a graph unit is a pixel and `x`/`y` are the usual offset.
28
+ *
29
+ * A mark that takes children holds them on the same map it is drawn through: a
30
+ * plot holding the area under it and the point that rides it.
31
+ */
32
+ export abstract class Mark<P extends PaintProps = PaintProps> extends PaintNode<P> {
33
+ /** The runs this mark draws, in pixels, y-up from the system's centre. */
34
+ protected abstract trace(map: CoordinateMap): Vector2[][];
35
+
36
+ /** Whether each run is closed into an outline. */
37
+ protected isClosed(): boolean {
38
+ return false;
39
+ }
40
+
41
+ /** This mark's own `x`/`y` as a shift in graph units: zero outside a system, where they are pixels. */
42
+ protected shift(): Vector2 {
43
+ return this._inSystem ? { x: this.x, y: this.y } : NO_SHIFT;
44
+ }
45
+
46
+ /** A graph point in this mark's own frame, where a handle on it sits. */
47
+ protected ownPoint(point: Vector2): Vector2 {
48
+ const shift = this.shift();
49
+ const at = this._map.toPoint(point.x + shift.x, point.y + shift.y);
50
+ const centre = this._centre();
51
+ return { x: at.x - centre.x, y: at.y - centre.y };
52
+ }
53
+
54
+ /** The graph point at `at` in this mark's own frame: {@link ownPoint} undone. */
55
+ protected graphPoint(at: Vector2): Vector2 {
56
+ const shift = this.shift();
57
+ const centre = this._centre();
58
+ const point = this._map.toCoords(at.x + centre.x, at.y + centre.y);
59
+ return { x: point.x - shift.x, y: point.y - shift.y };
60
+ }
61
+
62
+ /** Whether the fill is painted: a mark whose ink has no inside yet (an open line) says no. */
63
+ protected paintsFill(): boolean {
64
+ return true;
65
+ }
66
+
67
+ override measure(): Partial<Size2D> {
68
+ const ink = this._resolve(PIXEL_MAP, false);
69
+ return ink ? { width: ink.maxX - ink.minX, height: ink.maxY - ink.minY } : { width: 0, height: 0 };
70
+ }
71
+
72
+ protected override shapeGraphics(): Graphics2D | null {
73
+ const ink = this._ink;
74
+ if (!ink || this._data.length === 0) return null;
75
+ return new Graphics2D().path({
76
+ data: this._data,
77
+ centerBounds: [ink.minX, ink.minY, ink.maxX, ink.maxY],
78
+ start: this.start,
79
+ end: this.end,
80
+ });
81
+ }
82
+
83
+ // A mark's stroke is its ink, so it is painted before its children rather
84
+ // than over them: a point or a tangent riding a plot sits on the curve.
85
+ protected override renderSelf(ctx: RenderContext2D): void {
86
+ if (this.paintsFill()) super.renderSelf(ctx);
87
+ this.renderInk(ctx);
88
+ }
89
+
90
+ /** The stroke along the ink. A mark that strokes it differently overrides this, not `renderStroke`. */
91
+ protected renderInk(ctx: RenderContext2D): void {
92
+ super.renderStroke(ctx);
93
+ }
94
+
95
+ protected override renderStroke(): void {}
96
+
97
+ protected override layoutChildren(rect: BoxBounds, scope: MeasureContext2D): void {
98
+ const children = this.flowChildren();
99
+ if (children.length === 0) return;
100
+ const room = { x: 0, y: 0, width: rect.width, height: rect.height };
101
+ this._planes = placeOnMap(children, this._map, this._centre(), room, scope);
102
+ }
103
+
104
+ override _planeOf(child: Node2D | null): ChildPlane | null {
105
+ return child ? (this._planes.get(child) ?? null) : openPlane(this._map, this._centre());
106
+ }
107
+
108
+ private _data: PathCommand[] = [];
109
+ private _ink: Extents | null = null;
110
+ private _inSystem = false;
111
+ private _map: CoordinateMap = PIXEL_MAP;
112
+ private _planes = new WeakMap<Node2D, ChildPlane>();
113
+
114
+ /** Its own centre in the map's pixels: where its children's boxes are placed from. */
115
+ private _centre(): Vector2 {
116
+ const ink = this._ink;
117
+ return ink ? { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2 } : NO_SHIFT;
118
+ }
119
+
120
+ /** @internal What a system lays this mark out on: its ink, drawn through `map`. */
121
+ _resolve(map: CoordinateMap, inSystem = true): Extents | null {
122
+ this._inSystem = inSystem;
123
+ this._map = map;
124
+ const runs = this.trace(map);
125
+ this._data = runsToPath(runs, this.isClosed());
126
+ this._ink = boundsOfRuns(runs);
127
+ return this._ink;
128
+ }
129
+ }
130
+
131
+ const NO_SHIFT: Vector2 = { x: 0, y: 0 };
@@ -0,0 +1,61 @@
1
+ import { fillOps, lerpNumber, type Fill, type FillResolved } from "@motionscript/sdk";
2
+
3
+ /** A paint for one part of a node, named the way the node names its parts: a formula's term, a graph's vertex or edge. */
4
+ export interface PartFill {
5
+ part: string;
6
+ fill: Fill;
7
+ /** Which of the places the part is written, counted from 1; 0 is all of them. */
8
+ occurrence?: number;
9
+ /** How far from the node's own paint to `fill`, 0 to 1. A tween's state: an author leaves it out. */
10
+ mix?: number;
11
+ }
12
+
13
+ export interface PartFillResolved {
14
+ part: string;
15
+ fill: FillResolved[];
16
+ occurrence: number;
17
+ mix: number;
18
+ }
19
+
20
+ // Every entry is kept as written, one with no part yet included, so an editor
21
+ // showing the list shows the row it just added; the drawing skips it.
22
+ export function readPartFills(value: readonly PartFill[] | null | undefined): PartFillResolved[] {
23
+ if (!Array.isArray(value)) return [];
24
+ return value.map((entry) => ({
25
+ part: String(entry?.part ?? ""),
26
+ fill: fillOps.resolve(entry?.fill ?? "#ffffff"),
27
+ occurrence: Math.max(0, Math.round(entry?.occurrence ?? 0)),
28
+ mix: Math.min(1, Math.max(0, entry?.mix ?? 1)),
29
+ }));
30
+ }
31
+
32
+ const keyOf = (entry: PartFillResolved) => `${entry.occurrence}|${entry.part}`;
33
+
34
+ // A paint that arrives grows from the node's own, and one that leaves fades back to it.
35
+ export function lerpPartFills(from: PartFillResolved[], to: PartFillResolved[], t: number): PartFillResolved[] {
36
+ if (t <= 0) return from;
37
+ if (t >= 1) return to;
38
+ const before = new Map(from.map((entry) => [keyOf(entry), entry]));
39
+ const out = to.map((entry) => {
40
+ const was = before.get(keyOf(entry));
41
+ before.delete(keyOf(entry));
42
+ return was
43
+ ? { ...entry, fill: fillOps.lerp(was.fill, entry.fill, t), mix: lerpNumber(was.mix, entry.mix, t) }
44
+ : { ...entry, mix: entry.mix * t };
45
+ });
46
+ for (const gone of before.values()) out.push({ ...gone, mix: gone.mix * (1 - t) });
47
+ return out;
48
+ }
49
+
50
+ /** Each part fill with its own key, the one in place of an earlier one for the same part and occurrence. */
51
+ export function withPartFill(fills: readonly PartFillResolved[], entry: PartFill): PartFill[] {
52
+ const occurrence = Math.max(0, Math.round(entry.occurrence ?? 0));
53
+ return [...fills.filter((was) => was.part !== entry.part || was.occurrence !== occurrence), { ...entry, occurrence }];
54
+ }
55
+
56
+ /** `base` with a part's fill laid over it while it arrives, in place of it once it has. */
57
+ export function partPaint(base: FillResolved[], entry: PartFillResolved | undefined): FillResolved[] {
58
+ if (!entry || entry.mix <= 0) return base;
59
+ if (entry.mix >= 1) return entry.fill;
60
+ return [...base, ...entry.fill.map((layer) => ({ ...layer, opacity: (layer.opacity ?? 1) * entry.mix }))];
61
+ }
@@ -0,0 +1,101 @@
1
+ import {
2
+ flowOps,
3
+ type BoxBounds,
4
+ type ChildPlane,
5
+ type Extents,
6
+ type MeasureContext2D,
7
+ type Node2D,
8
+ type Vector2,
9
+ } from "@motionscript/sdk";
10
+ import type { CoordinateMap } from "./coords";
11
+
12
+ /** A child that sits somewhere other than its own `x`/`y`: a point riding a curve. */
13
+ export interface Anchored {
14
+ /** The graph coordinates the child is at, given its own `x`/`y`. */
15
+ anchorAt(x: number, y: number): Vector2;
16
+ }
17
+
18
+ function isAnchored(node: object): node is Anchored {
19
+ return typeof (node as Partial<Anchored>).anchorAt === "function";
20
+ }
21
+
22
+ /** A child drawn through a map and laid out on its ink: a mark, told apart by what it does so a copied one is too. */
23
+ interface Traced {
24
+ _resolve(map: CoordinateMap, inSystem?: boolean): Extents | null;
25
+ }
26
+
27
+ function isTraced(node: object): node is Traced {
28
+ return typeof (node as Partial<Traced>)._resolve === "function";
29
+ }
30
+
31
+ /**
32
+ * Lay `children` out on `map`, for whichever node holds them: a coordinate
33
+ * system, or a plot holding the marks that read it. A mark goes on its ink;
34
+ * anything else keeps its own size and has its `x`/`y` read as graph
35
+ * coordinates. `origin` is the holder's own centre in the map's pixels (y-up),
36
+ * since a child's box is placed from there. Returns each child's plane.
37
+ */
38
+ export function placeOnMap(
39
+ children: readonly Node2D[],
40
+ map: CoordinateMap,
41
+ origin: Vector2,
42
+ room: BoxBounds,
43
+ scope: MeasureContext2D,
44
+ ): WeakMap<Node2D, ChildPlane> {
45
+ const planes = new WeakMap<Node2D, ChildPlane>();
46
+ const others: Node2D[] = [];
47
+ for (const child of children) {
48
+ if (!isTraced(child)) {
49
+ others.push(child);
50
+ continue;
51
+ }
52
+ const ink = child._resolve(map);
53
+ const cx = ink ? (ink.minX + ink.maxX) / 2 : origin.x;
54
+ const cy = ink ? (ink.minY + ink.maxY) / 2 : origin.y;
55
+ child.layout(
56
+ { x: cx - origin.x, y: origin.y - cy, width: ink ? ink.maxX - ink.minX : 0, height: ink ? ink.maxY - ink.minY : 0 },
57
+ scope,
58
+ );
59
+ planes.set(child, markPlane(map, cx, cy));
60
+ }
61
+ if (others.length === 0) return planes;
62
+ const sizes = flowOps.measure({}, others, room, scope).sizes;
63
+ others.forEach((child, i) => {
64
+ // Its box is centred on the map's own centre, so its offset from there is its point.
65
+ child.layout({ x: -origin.x, y: origin.y, width: sizes[i].width, height: sizes[i].height }, scope);
66
+ planes.set(child, pointPlane(map, child));
67
+ });
68
+ return planes;
69
+ }
70
+
71
+ /** The plane of a child that is not there yet, under a holder centred on `origin`: where a host would drop one. */
72
+ export function openPlane(map: CoordinateMap, origin: Vector2): ChildPlane {
73
+ return {
74
+ toOffset: (x, y) => {
75
+ const at = map.toPoint(x, y);
76
+ return { x: at.x - origin.x, y: at.y - origin.y };
77
+ },
78
+ toCoords: (x, y) => map.toCoords(x + origin.x, y + origin.y),
79
+ };
80
+ }
81
+
82
+ function pointPlane(map: CoordinateMap, child: Node2D): ChildPlane {
83
+ const point: Vector2 = { x: 0, y: 0 };
84
+ const anchored = isAnchored(child) ? child : null;
85
+ return {
86
+ toOffset: (x, y) => {
87
+ const at = anchored?.anchorAt(x, y);
88
+ return at ? map.toPoint(at.x, at.y, point) : map.toPoint(x, y, point);
89
+ },
90
+ toCoords: (x, y) => map.toCoords(x, y),
91
+ };
92
+ }
93
+
94
+ // A mark reads its own `x`/`y` as it draws, so its holder adds nothing; a drag still answers in graph units.
95
+ function markPlane(map: CoordinateMap, cx: number, cy: number): ChildPlane {
96
+ const none: Vector2 = { x: 0, y: 0 };
97
+ return {
98
+ toOffset: () => none,
99
+ toCoords: (x, y) => map.toCoords(cx + x, cy + y),
100
+ };
101
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The coordinate systems a 2D plot or mark goes inside, for a node's `within`.
3
+ * A number plane is built on `axes2d`, so naming that covers it.
4
+ */
5
+ export const SYSTEMS: readonly string[] = ["axes2d", "numberLine", "polarPlane"];
6
+
7
+ /** The systems, and a plot: where a mark that may ride a curve goes. */
8
+ export const SYSTEMS_AND_PLOT: readonly string[] = [...SYSTEMS, "functionPlot"];
@@ -0,0 +1,281 @@
1
+ import type { Extents, Vector2 } from "@motionscript/sdk";
2
+
3
+ /**
4
+ * Turns a curve into the polylines that draw it: adaptively, so a straight
5
+ * stretch costs two points and a tight bend as many as it needs, and broken
6
+ * wherever the curve is, at an asymptote or the edge of its domain.
7
+ */
8
+
9
+ /** A curve's parameter to its pixel, written into `out`. `false` where the curve is undefined. */
10
+ export type CurveProjection = (t: number, out: Vector2) => boolean;
11
+
12
+ export interface SampleOptions {
13
+ /** The equal steps the parameter range starts as, before any is split. */
14
+ seeds?: number;
15
+ /** A parameter step that is not split again, however bent. */
16
+ minStep?: number;
17
+ }
18
+
19
+ /** Skia's path coordinates are 32-bit floats; past this a clamped point still clips to the same edge. */
20
+ const COORD_LIMIT = 16_000;
21
+ /** How far, in pixels, the drawn chord may stray from the curve. */
22
+ const TOLERANCE_PX = 0.25;
23
+ /** A turn, in radians, a chord is allowed to hide: what keeps a symmetric bump from reading as flat. */
24
+ const ANGLE_TOLERANCE = 0.05;
25
+ const MAX_DEPTH = 12;
26
+ const MAX_EVALUATIONS = 40_000;
27
+ const MAX_POINTS = 24_000;
28
+ /** Bisections spent finding where a domain ends. */
29
+ const BOUNDARY_STEPS = 60;
30
+ const DEFAULT_SEEDS = 256;
31
+
32
+ interface Sample {
33
+ t: number;
34
+ px: number;
35
+ py: number;
36
+ /** The pixel before clamping: what tells an asymptote from a steep line. */
37
+ rx: number;
38
+ ry: number;
39
+ ok: boolean;
40
+ }
41
+
42
+ // Midpoints are pooled: a refine is a depth-first walk, so a slot is free again
43
+ // as soon as the seed interval it was taken for is done.
44
+ const arena: Sample[] = [];
45
+ let arenaMark = 0;
46
+
47
+ function takeSample(): Sample {
48
+ let slot = arena[arenaMark];
49
+ if (slot === undefined) {
50
+ slot = blank();
51
+ arena.push(slot);
52
+ }
53
+ arenaMark++;
54
+ return slot;
55
+ }
56
+
57
+ function blank(): Sample {
58
+ return { t: 0, px: 0, py: 0, rx: 0, ry: 0, ok: false };
59
+ }
60
+
61
+ const scratch: Vector2 = { x: 0, y: 0 };
62
+
63
+ /** The runs of points that draw `project` over `[t0, t1]`, clipped to `clip`. */
64
+ export function sampleCurve(
65
+ project: CurveProjection,
66
+ t0: number,
67
+ t1: number,
68
+ clip: Extents,
69
+ { seeds = DEFAULT_SEEDS, minStep = 0 }: SampleOptions = {},
70
+ ): Vector2[][] {
71
+ if (!(t1 > t0) || !Number.isFinite(t0) || !Number.isFinite(t1)) return [];
72
+ const pen = new CurvePen(clip);
73
+ let spent = 0;
74
+
75
+ const write = (slot: Sample, t: number): Sample => {
76
+ const defined = project(t, scratch);
77
+ spent++;
78
+ const ok = defined && Number.isFinite(scratch.x) && Number.isFinite(scratch.y);
79
+ slot.t = t;
80
+ slot.rx = ok ? scratch.x : 0;
81
+ slot.ry = ok ? scratch.y : 0;
82
+ slot.px = clampCoord(slot.rx);
83
+ slot.py = clampCoord(slot.ry);
84
+ slot.ok = ok;
85
+ return slot;
86
+ };
87
+ const at = (t: number): Sample => write(takeSample(), t);
88
+
89
+ // The last defined point before `to`, which is not: where `sqrt(x)` meets its axis.
90
+ const edgeOf = (from: Sample, to: Sample): Sample => {
91
+ let inside = from;
92
+ let outsideT = to.t;
93
+ for (let i = 0; i < BOUNDARY_STEPS; i++) {
94
+ if (spent >= MAX_EVALUATIONS || offFrame(inside, clip)) break;
95
+ const midT = (inside.t + outsideT) / 2;
96
+ if (midT === inside.t || midT === outsideT) break;
97
+ const mid = at(midT);
98
+ if (!mid.ok) {
99
+ outsideT = midT;
100
+ continue;
101
+ }
102
+ const settled = Math.abs(mid.px - inside.px) < TOLERANCE_PX && Math.abs(mid.py - inside.py) < TOLERANCE_PX;
103
+ inside = mid;
104
+ if (settled) break;
105
+ }
106
+ return inside;
107
+ };
108
+
109
+ const emit = (a: Sample, m: Sample | null, b: Sample, floored: boolean): void => {
110
+ if (a.ok && b.ok) {
111
+ if (floored && diverges(a, m, b, clip)) pen.break();
112
+ else pen.draw(a, b);
113
+ return;
114
+ }
115
+ if (a.ok) {
116
+ const edge = edgeOf(a, b);
117
+ if (edge.t !== a.t) pen.draw(a, edge);
118
+ pen.break();
119
+ return;
120
+ }
121
+ pen.break();
122
+ if (b.ok) {
123
+ const edge = edgeOf(b, a);
124
+ if (edge.t !== b.t) pen.draw(edge, b);
125
+ else pen.start(b);
126
+ }
127
+ };
128
+
129
+ const refine = (a: Sample, b: Sample, depth: number): void => {
130
+ if (spent >= MAX_EVALUATIONS || pen.points >= MAX_POINTS) {
131
+ emit(a, null, b, false);
132
+ return;
133
+ }
134
+ const m = at((a.t + b.t) / 2);
135
+ const floored = depth >= MAX_DEPTH || b.t - a.t <= minStep;
136
+ if (floored || flat(a, m, b)) {
137
+ emit(a, m, b, floored);
138
+ return;
139
+ }
140
+ refine(a, m, depth + 1);
141
+ refine(m, b, depth + 1);
142
+ };
143
+
144
+ const count = Math.max(1, Math.round(seeds));
145
+ const step = (t1 - t0) / count;
146
+ const ends: [Sample, Sample] = [blank(), blank()];
147
+ let previous = write(ends[0], t0);
148
+ for (let i = 1; i <= count; i++) {
149
+ const next = write(ends[i & 1], i === count ? t1 : t0 + i * step);
150
+ arenaMark = 0;
151
+ refine(previous, next, 0);
152
+ previous = next;
153
+ }
154
+ arenaMark = 0;
155
+ return pen.finish();
156
+ }
157
+
158
+ function flat(a: Sample, m: Sample, b: Sample): boolean {
159
+ if (a.ok !== m.ok || m.ok !== b.ok) return false;
160
+ if (!a.ok) return true;
161
+ const dx = b.px - a.px;
162
+ const dy = b.py - a.py;
163
+ const length = Math.hypot(dx, dy) || 1;
164
+ if (Math.abs((m.px - a.px) * dy - (m.py - a.py) * dx) / length > TOLERANCE_PX) return false;
165
+ let turn = Math.abs(Math.atan2(m.py - a.py, m.px - a.px) - Math.atan2(b.py - m.py, b.px - m.px));
166
+ if (turn > Math.PI) turn = 2 * Math.PI - turn;
167
+ return turn < ANGLE_TOLERANCE;
168
+ }
169
+
170
+ // Two neighbours on opposite sides of the frame, with nothing between them that
171
+ // is between them: an asymptote, not a steep line.
172
+ function diverges(a: Sample, m: Sample | null, b: Sample, clip: Extents): boolean {
173
+ const straddles =
174
+ (a.py > clip.maxY && b.py < clip.minY) || (a.py < clip.minY && b.py > clip.maxY) ||
175
+ (a.px > clip.maxX && b.px < clip.minX) || (a.px < clip.minX && b.px > clip.maxX);
176
+ if (!straddles || m === null) return false;
177
+ if (!m.ok) return true;
178
+ return (
179
+ m.ry < Math.min(a.ry, b.ry) || m.ry > Math.max(a.ry, b.ry) ||
180
+ m.rx < Math.min(a.rx, b.rx) || m.rx > Math.max(a.rx, b.rx)
181
+ );
182
+ }
183
+
184
+ function offFrame(sample: Sample, clip: Extents): boolean {
185
+ return sample.py > clip.maxY || sample.py < clip.minY || sample.px > clip.maxX || sample.px < clip.minX;
186
+ }
187
+
188
+ function clampCoord(value: number): number {
189
+ if (value > COORD_LIMIT) return COORD_LIMIT;
190
+ if (value < -COORD_LIMIT) return -COORD_LIMIT;
191
+ return value;
192
+ }
193
+
194
+ class CurvePen {
195
+ points = 0;
196
+ private readonly runs: Vector2[][] = [];
197
+ private open: Vector2[] = [];
198
+ private cursor: Vector2 | null = null;
199
+
200
+ constructor(private readonly clip: Extents) {}
201
+
202
+ draw(a: Sample, b: Sample): void {
203
+ const segment = clipSegment(a.px, a.py, b.px, b.py, this.clip);
204
+ if (!segment) {
205
+ this.break();
206
+ return;
207
+ }
208
+ const [start, end] = segment;
209
+ if (this.cursor && samePoint(this.cursor, start)) {
210
+ this.push(end);
211
+ } else {
212
+ this.break();
213
+ this.push(start);
214
+ this.push(end);
215
+ }
216
+ this.cursor = end;
217
+ }
218
+
219
+ start(b: Sample): void {
220
+ this.break();
221
+ if (!inside(b.px, b.py, this.clip)) return;
222
+ this.cursor = { x: b.px, y: b.py };
223
+ this.push(this.cursor);
224
+ }
225
+
226
+ break(): void {
227
+ if (this.open.length >= 2) this.runs.push(this.open);
228
+ this.open = [];
229
+ this.cursor = null;
230
+ }
231
+
232
+ finish(): Vector2[][] {
233
+ this.break();
234
+ return this.runs;
235
+ }
236
+
237
+ private push(point: Vector2): void {
238
+ this.open.push(point);
239
+ this.points++;
240
+ }
241
+ }
242
+
243
+ function samePoint(a: Vector2, b: Vector2): boolean {
244
+ return Math.abs(a.x - b.x) < 0.1 && Math.abs(a.y - b.y) < 0.1;
245
+ }
246
+
247
+ function inside(x: number, y: number, clip: Extents): boolean {
248
+ return x >= clip.minX && x <= clip.maxX && y >= clip.minY && y <= clip.maxY;
249
+ }
250
+
251
+ // Liang–Barsky: the part of a segment inside the clip, or null when none is.
252
+ function clipSegment(ax: number, ay: number, bx: number, by: number, clip: Extents): [Vector2, Vector2] | null {
253
+ const dx = bx - ax;
254
+ const dy = by - ay;
255
+ let t0 = 0;
256
+ let t1 = 1;
257
+ const edges: [number, number][] = [
258
+ [-dx, ax - clip.minX],
259
+ [dx, clip.maxX - ax],
260
+ [-dy, ay - clip.minY],
261
+ [dy, clip.maxY - ay],
262
+ ];
263
+ for (const [p, q] of edges) {
264
+ if (p === 0) {
265
+ if (q < 0) return null;
266
+ continue;
267
+ }
268
+ const r = q / p;
269
+ if (p < 0) {
270
+ if (r > t1) return null;
271
+ if (r > t0) t0 = r;
272
+ } else {
273
+ if (r < t0) return null;
274
+ if (r < t1) t1 = r;
275
+ }
276
+ }
277
+ return [
278
+ { x: ax + t0 * dx, y: ay + t0 * dy },
279
+ { x: ax + t1 * dx, y: ay + t1 * dy },
280
+ ];
281
+ }
@@ -0,0 +1,39 @@
1
+ import { colorOps, fillOps, type Color, type Fill, type FillResolved, type NormalizedColor } from "@motionscript/sdk";
2
+ import { clamp } from "./geometry";
3
+
4
+ /** A run of colours a value is read off, lowest first: a surface's height, a field's strength. */
5
+
6
+ export function readScale(value: readonly Color[] | undefined): NormalizedColor[] {
7
+ return (value ?? []).map((color) => colorOps.resolve(color));
8
+ }
9
+
10
+ export function lerpScale(from: NormalizedColor[], to: NormalizedColor[], t: number): NormalizedColor[] {
11
+ if (from.length !== to.length) return t < 1 ? from : to;
12
+ return to.map((color, index) => colorOps.lerp(from[index], color, t));
13
+ }
14
+
15
+ /** The colour `share` of the way along `scale`, 0 to 1. */
16
+ export function colorAt(scale: readonly NormalizedColor[], share: number): NormalizedColor {
17
+ if (scale.length === 1) return scale[0];
18
+ const at = clamp(share, 0, 1) * (scale.length - 1);
19
+ const index = Math.min(scale.length - 2, Math.floor(at));
20
+ return colorOps.lerp(scale[index], scale[index + 1], at - index);
21
+ }
22
+
23
+ /** A run of paints a value is read off, lowest first: a field's strength. Every entry is kept as written. */
24
+ export function readFillScale(value: readonly Fill[] | undefined): FillResolved[][] {
25
+ return (Array.isArray(value) ? value : []).map((fill) => fillOps.resolve(fill ?? []));
26
+ }
27
+
28
+ export function lerpFillScale(from: FillResolved[][], to: FillResolved[][], t: number): FillResolved[][] {
29
+ if (from.length !== to.length) return t < 1 ? from : to;
30
+ return to.map((fill, index) => fillOps.lerp(from[index], fill, t));
31
+ }
32
+
33
+ /** The paint `share` of the way along `scale`, 0 to 1. */
34
+ export function fillAt(scale: readonly FillResolved[][], share: number): FillResolved[] {
35
+ if (scale.length === 1) return scale[0];
36
+ const at = clamp(share, 0, 1) * (scale.length - 1);
37
+ const index = Math.min(scale.length - 2, Math.floor(at));
38
+ return fillOps.lerp(scale[index], scale[index + 1], at - index);
39
+ }