@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 @@
1
+ {"version":3,"file":"number-plane.d.ts","sourceRoot":"","sources":["../../src/systems/number-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,UAAU,EAIV,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,MAAM,EAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAOH,KAAK,aAAa,EAClB,KAAK,OAAO,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AAgB,CAAC;IAItI,wGAAwG;IAExG,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;cAI1E,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa;cAuBpC,QAAQ,CAAC,GAAG,EAAE,aAAa,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,EAAE;IAY3F,OAAO,CAAC,KAAK,CAA8B;IAE3C,qGAAqG;IACrG,OAAO,CAAC,MAAM;CAkDjB"}
@@ -0,0 +1,193 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { command, Graphics2D, node, property, strokeProperty, } from "@motionscript/sdk";
8
+ import { isIdentityMatrix, lerpMatrix, lineThrough, readMatrix, transformedMap, warpedMap, } from "../kit/coords.js";
9
+ import { fieldParams, parseField } from "../kit/field.js";
10
+ import { Axes2d } from "./axes2d.js";
11
+ import { AXIS_COLOR } from "../kit/furniture.js";
12
+ import { stated } from "../kit/geometry.js";
13
+ import { lerpSource, readSource } from "../kit/source.js";
14
+ /**
15
+ * Axes over a full grid, with square units unless told otherwise: the plane
16
+ * vectors and transformations are drawn on. Its `matrix` shears, turns or
17
+ * squeezes the whole plane about its origin, and its `warp` bends it by a
18
+ * function of its own points; the grid, the axes and everything on the plane
19
+ * go with it.
20
+ */
21
+ let NumberPlane = class NumberPlane extends Axes2d {
22
+ constructor(props) {
23
+ super((props ?? {}));
24
+ // A transformed plane reaches past its box, and so does what is on it: both are kept in unless told otherwise.
25
+ if (props?.clip === undefined)
26
+ this.applyProp("clip", () => this.coordinates.spills === true);
27
+ }
28
+ /** Send the plane through a matrix: a shear, a turn, a squeeze, a flip. */
29
+ transformTo(args) {
30
+ return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
31
+ }
32
+ /** Bend the plane, each point travelling to where the warp sends it; an empty one flattens it again. */
33
+ warpTo(args) {
34
+ return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
35
+ }
36
+ mapFor(area) {
37
+ const flat = super.mapFor(area);
38
+ this._flat = flat;
39
+ const map = isIdentityMatrix(this.matrix) ? flat : transformedMap(flat, this.matrix);
40
+ const { source, blend } = this.warp;
41
+ const to = warpOf(source);
42
+ if (!blend)
43
+ return to ? warpedMap(map, to, source) : map;
44
+ // Mid-warp each point is part of the way from where the old warp had it to where the new one sends it.
45
+ const from = warpOf(blend.from);
46
+ if (!from && !to)
47
+ return map;
48
+ const start = { x: 0, y: 0 };
49
+ return warpedMap(map, (x, y, out) => {
50
+ if (!(from ?? STAY)(x, y, start) || !(to ?? STAY)(x, y, out))
51
+ return false;
52
+ out.x = start.x + (out.x - start.x) * blend.t;
53
+ out.y = start.y + (out.y - start.y) * blend.t;
54
+ return true;
55
+ }, `${blend.from}>${source}@${blend.t}`);
56
+ }
57
+ backdrop(map, x, y) {
58
+ if (!this.grid)
59
+ return [];
60
+ const parts = [];
61
+ const flat = this._flat;
62
+ if (this.ghost && flat && flat.revision !== map.revision) {
63
+ const [gx, gy] = this.axes(flat);
64
+ parts.push(...this._ruled(flat, gx, gy, true));
65
+ }
66
+ parts.push(...this._ruled(map, x, y, false));
67
+ return parts;
68
+ }
69
+ _flat = null;
70
+ /** The grid of `map`: every line, or only the ones at a tick, in the fainter stroke, for a ghost. */
71
+ _ruled(map, x, y, ghost) {
72
+ const { start, end } = this;
73
+ const [xMin, xMax] = map.xRange;
74
+ const [yMin, yMax] = map.yRange;
75
+ const lines = (values, vertical) => {
76
+ const g = new Graphics2D();
77
+ for (const value of values) {
78
+ g.line({
79
+ points: vertical ? lineThrough(map, value, yMin, value, yMax) : lineThrough(map, xMin, value, xMax, value),
80
+ radius: 0,
81
+ start,
82
+ end,
83
+ });
84
+ }
85
+ return g;
86
+ };
87
+ const parts = [];
88
+ const minor = this.minorStroke;
89
+ if (ghost) {
90
+ if (minor.length === 0)
91
+ return parts;
92
+ if (x.marks.values.length > 0)
93
+ parts.push(lines(x.marks.values, true).stroke(minor));
94
+ if (y.marks.values.length > 0)
95
+ parts.push(lines(y.marks.values, false).stroke(minor));
96
+ return parts;
97
+ }
98
+ const divisions = Math.round(this.minorDivisions);
99
+ if (minor.length > 0 && divisions > 1) {
100
+ const between = (axis, [min, max]) => {
101
+ const { step, values } = axis.marks;
102
+ if (!(step > 0) || values.length === 0)
103
+ return [];
104
+ const out = [];
105
+ for (let base = values[0] - step; base < max; base += step) {
106
+ for (let i = 1; i < divisions; i++) {
107
+ const value = base + (step * i) / divisions;
108
+ if (value > min && value < max)
109
+ out.push(value);
110
+ }
111
+ }
112
+ return out;
113
+ };
114
+ const xs = between(x, map.xRange);
115
+ const ys = between(y, map.yRange);
116
+ if (xs.length > 0)
117
+ parts.push(lines(xs, true).stroke(minor));
118
+ if (ys.length > 0)
119
+ parts.push(lines(ys, false).stroke(minor));
120
+ }
121
+ const major = this.gridStroke;
122
+ if (major.length > 0) {
123
+ if (x.marks.values.length > 0)
124
+ parts.push(lines(x.marks.values, true).stroke(major));
125
+ if (y.marks.values.length > 0)
126
+ parts.push(lines(y.marks.values, false).stroke(major));
127
+ }
128
+ return parts;
129
+ }
130
+ };
131
+ __decorate([
132
+ property({ default: true, animatable: false })
133
+ ], NumberPlane.prototype, "grid", void 0);
134
+ __decorate([
135
+ strokeProperty({ default: { weight: 1.5, fill: "#3b4658", align: "center" } })
136
+ ], NumberPlane.prototype, "gridStroke", void 0);
137
+ __decorate([
138
+ strokeProperty({ default: { weight: 1, fill: "#232b38", align: "center" } })
139
+ ], NumberPlane.prototype, "minorStroke", void 0);
140
+ __decorate([
141
+ property({ default: 2, min: 1, max: 10, step: 1 })
142
+ ], NumberPlane.prototype, "minorDivisions", void 0);
143
+ __decorate([
144
+ property({ default: [1, 0, 0, 1], mapper: readMatrix, tween: lerpMatrix })
145
+ ], NumberPlane.prototype, "matrix", void 0);
146
+ __decorate([
147
+ property({ default: "", mapper: readSource, tween: lerpSource, kind: "fieldEquation" })
148
+ ], NumberPlane.prototype, "warp", void 0);
149
+ __decorate([
150
+ property({ default: true, animatable: false })
151
+ ], NumberPlane.prototype, "ghost", void 0);
152
+ __decorate([
153
+ property({ default: true, animatable: false })
154
+ ], NumberPlane.prototype, "squareUnits", void 0);
155
+ __decorate([
156
+ strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: "center" } })
157
+ ], NumberPlane.prototype, "stroke", void 0);
158
+ __decorate([
159
+ command({ args: ["matrix"] })
160
+ ], NumberPlane.prototype, "transformTo", null);
161
+ __decorate([
162
+ command({ args: ["warp"] })
163
+ ], NumberPlane.prototype, "warpTo", null);
164
+ NumberPlane = __decorate([
165
+ node({
166
+ key: "numberPlane",
167
+ parentKey: "axes2d",
168
+ forkable: true,
169
+ layout: { children: "freeform", defaultWidthMode: "fixed", defaultHeightMode: "fixed", acceptsChildren: true },
170
+ seed: { width: 800, height: 500 },
171
+ })
172
+ ], NumberPlane);
173
+ export { NumberPlane };
174
+ const STAY = (x, y, out) => {
175
+ out.x = x;
176
+ out.y = y;
177
+ return true;
178
+ };
179
+ /** `source` as a warp, or `null` for text that is empty or not a field: the plane is then left as it is. */
180
+ function warpOf(source) {
181
+ const field = source.trim() === "" ? null : parseField(source, fieldParams(source));
182
+ if (!field || field instanceof Error)
183
+ return null;
184
+ const { x, y } = field;
185
+ return (gx, gy, out) => {
186
+ const wx = x(gx, gy);
187
+ const wy = y(gx, gy);
188
+ out.x = wx;
189
+ out.y = wy;
190
+ return Number.isFinite(wx) && Number.isFinite(wy);
191
+ };
192
+ }
193
+ //# sourceMappingURL=number-plane.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number-plane.js","sourceRoot":"","sources":["../../src/systems/number-plane.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,OAAO,EACP,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,cAAc,GAOjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,UAAU,EACV,cAAc,EACd,SAAS,GAIZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,MAAM,EAAqC,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAmB,MAAM,eAAe,CAAC;AAYxE;;;;;;GAMG;AAQI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,MAAwB;IAsBrD,YAAY,KAAiD;QACzD,KAAK,CAAC,CAAC,KAAK,IAAI,EAAE,CAA2D,CAAC,CAAC;QAC/E,+GAA+G;QAC/G,IAAI,KAAK,EAAE,IAAI,KAAK,SAAS;YAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC;IAClG,CAAC;IAED,2EAA2E;IAE3E,WAAW,CAAC,IAA8F;QACtG,OAAO,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IA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AI,EAAE;QAC9G,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;KACpC,CAAC;GACW,WAAW,CAgIvB;;AAED,MAAM,IAAI,GAAS,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE;IAC7B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACV,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,4GAA4G;AAC5G,SAAS,MAAM,CAAC,MAAc;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACpF,IAAI,CAAC,KAAK,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,IAAI,CAAC;IAClD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC;IACvB,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;QACnB,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACrB,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACrB,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {\r\n command,\r\n Graphics2D,\r\n node,\r\n property,\r\n strokeProperty,\r\n type Command,\r\n type CommandArgs,\r\n type Extents,\r\n type NodeConfig,\r\n type Stroke,\r\n type StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport {\r\n isIdentityMatrix,\r\n lerpMatrix,\r\n lineThrough,\r\n readMatrix,\r\n transformedMap,\r\n warpedMap,\r\n type CoordinateMap,\r\n type Matrix2,\r\n type Warp,\r\n} from \"../kit/coords\";\r\nimport { fieldParams, parseField } from \"../kit/field\";\r\nimport { Axes2d, type Axes2dProps, type AxisLayout } from \"./axes2d\";\r\nimport { AXIS_COLOR } from \"../kit/furniture\";\r\nimport { stated } from \"../kit/geometry\";\r\nimport { lerpSource, readSource, type PlotSource } from \"../kit/source\";\r\n\r\nexport interface NumberPlaneProps extends Axes2dProps {\r\n grid?: boolean;\r\n gridStroke?: Stroke;\r\n minorStroke?: Stroke;\r\n minorDivisions?: number;\r\n matrix?: Matrix2 | readonly (readonly number[])[];\r\n warp?: string | PlotSource;\r\n ghost?: boolean;\r\n}\r\n\r\n/**\r\n * Axes over a full grid, with square units unless told otherwise: the plane\r\n * vectors and transformations are drawn on. Its `matrix` shears, turns or\r\n * squeezes the whole plane about its origin, and its `warp` bends it by a\r\n * function of its own points; the grid, the axes and everything on the plane\r\n * go with it.\r\n */\r\n@node({\r\n key: \"numberPlane\",\r\n parentKey: \"axes2d\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"fixed\", defaultHeightMode: \"fixed\", acceptsChildren: true },\r\n seed: { width: 800, height: 500 },\r\n})\r\nexport class NumberPlane extends Axes2d<NumberPlaneProps> {\r\n @property({ default: true, animatable: false }) declare grid: boolean;\r\n /** The line at every tick. */\r\n @strokeProperty({ default: { weight: 1.5, fill: \"#3b4658\", align: \"center\" } }) declare gridStroke: Stroke;\r\n /** The lines between ticks. */\r\n @strokeProperty({ default: { weight: 1, fill: \"#232b38\", align: \"center\" } }) declare minorStroke: Stroke;\r\n /** How many parts the space between two ticks is cut into; one draws no line between them. */\r\n @property({ default: 2, min: 1, max: 10, step: 1 }) declare minorDivisions: number;\r\n\r\n /** A linear map of the plane, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */\r\n @property({ default: [1, 0, 0, 1], mapper: readMatrix, tween: lerpMatrix }) declare matrix: Matrix2;\r\n /**\r\n * Where each point of the plane is sent, two parts in x and y:\r\n * `(x + sin(y), y + sin(x))`. Empty leaves the plane flat.\r\n */\r\n @property({ default: \"\", mapper: readSource, tween: lerpSource, kind: \"fieldEquation\" }) declare warp: PlotSource;\r\n /** Leave the plane as it was, faintly, behind one that has been transformed or warped. */\r\n @property({ default: true, animatable: false }) declare ghost: boolean;\r\n\r\n @property({ default: true, animatable: false }) declare squareUnits: boolean;\r\n @strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: \"center\" } }) declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<NumberPlane, NumberPlaneProps>) {\r\n super((props ?? {}) as NodeConfig<Axes2d<NumberPlaneProps>, NumberPlaneProps>);\r\n // A transformed plane reaches past its box, and so does what is on it: both are kept in unless told otherwise.\r\n if (props?.clip === undefined) this.applyProp(\"clip\", () => this.coordinates.spills === true);\r\n }\r\n\r\n /** Send the plane through a matrix: a shear, a turn, a squeeze, a flip. */\r\n @command({ args: [\"matrix\"] })\r\n transformTo(args: CommandArgs<{ matrix: Matrix2 | readonly (readonly number[])[] }> & { duration: number }): Command<NumberPlaneProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** Bend the plane, each point travelling to where the warp sends it; an empty one flattens it again. */\r\n @command({ args: [\"warp\"] })\r\n warpTo(args: CommandArgs<{ warp: string }> & { duration: number }): Command<NumberPlaneProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n protected override mapFor(area: Extents): CoordinateMap {\r\n const flat = super.mapFor(area);\r\n this._flat = flat;\r\n const map = isIdentityMatrix(this.matrix) ? flat : transformedMap(flat, this.matrix);\r\n const { source, blend } = this.warp;\r\n const to = warpOf(source);\r\n if (!blend) return to ? warpedMap(map, to, source) : map;\r\n // Mid-warp each point is part of the way from where the old warp had it to where the new one sends it.\r\n const from = warpOf(blend.from);\r\n if (!from && !to) return map;\r\n const start = { x: 0, y: 0 };\r\n return warpedMap(\r\n map,\r\n (x, y, out) => {\r\n if (!(from ?? STAY)(x, y, start) || !(to ?? STAY)(x, y, out)) return false;\r\n out.x = start.x + (out.x - start.x) * blend.t;\r\n out.y = start.y + (out.y - start.y) * blend.t;\r\n return true;\r\n },\r\n `${blend.from}>${source}@${blend.t}`,\r\n );\r\n }\r\n\r\n protected override backdrop(map: CoordinateMap, x: AxisLayout, y: AxisLayout): Graphics2D[] {\r\n if (!this.grid) return [];\r\n const parts: Graphics2D[] = [];\r\n const flat = this._flat;\r\n if (this.ghost && flat && flat.revision !== map.revision) {\r\n const [gx, gy] = this.axes(flat);\r\n parts.push(...this._ruled(flat, gx, gy, true));\r\n }\r\n parts.push(...this._ruled(map, x, y, false));\r\n return parts;\r\n }\r\n\r\n private _flat: CoordinateMap | null = null;\r\n\r\n /** The grid of `map`: every line, or only the ones at a tick, in the fainter stroke, for a ghost. */\r\n private _ruled(map: CoordinateMap, x: AxisLayout, y: AxisLayout, ghost: boolean): Graphics2D[] {\r\n const { start, end } = this;\r\n const [xMin, xMax] = map.xRange;\r\n const [yMin, yMax] = map.yRange;\r\n const lines = (values: readonly number[], vertical: boolean): Graphics2D => {\r\n const g = new Graphics2D();\r\n for (const value of values) {\r\n g.line({\r\n points: vertical ? lineThrough(map, value, yMin, value, yMax) : lineThrough(map, xMin, value, xMax, value),\r\n radius: 0,\r\n start,\r\n end,\r\n });\r\n }\r\n return g;\r\n };\r\n const parts: Graphics2D[] = [];\r\n const minor = this.minorStroke as StrokeResolved[];\r\n if (ghost) {\r\n if (minor.length === 0) return parts;\r\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(minor));\r\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(minor));\r\n return parts;\r\n }\r\n const divisions = Math.round(this.minorDivisions);\r\n if (minor.length > 0 && divisions > 1) {\r\n const between = (axis: AxisLayout, [min, max]: readonly [number, number]): number[] => {\r\n const { step, values } = axis.marks;\r\n if (!(step > 0) || values.length === 0) return [];\r\n const out: number[] = [];\r\n for (let base = values[0] - step; base < max; base += step) {\r\n for (let i = 1; i < divisions; i++) {\r\n const value = base + (step * i) / divisions;\r\n if (value > min && value < max) out.push(value);\r\n }\r\n }\r\n return out;\r\n };\r\n const xs = between(x, map.xRange);\r\n const ys = between(y, map.yRange);\r\n if (xs.length > 0) parts.push(lines(xs, true).stroke(minor));\r\n if (ys.length > 0) parts.push(lines(ys, false).stroke(minor));\r\n }\r\n const major = this.gridStroke as StrokeResolved[];\r\n if (major.length > 0) {\r\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(major));\r\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(major));\r\n }\r\n return parts;\r\n }\r\n}\r\n\r\nconst STAY: Warp = (x, y, out) => {\r\n out.x = x;\r\n out.y = y;\r\n return true;\r\n};\r\n\r\n/** `source` as a warp, or `null` for text that is empty or not a field: the plane is then left as it is. */\r\nfunction warpOf(source: string): Warp | null {\r\n const field = source.trim() === \"\" ? null : parseField(source, fieldParams(source));\r\n if (!field || field instanceof Error) return null;\r\n const { x, y } = field;\r\n return (gx, gy, out) => {\r\n const wx = x(gx, gy);\r\n const wy = y(gx, gy);\r\n out.x = wx;\r\n out.y = wy;\r\n return Number.isFinite(wx) && Number.isFinite(wy);\r\n };\r\n}\r\n"]}
@@ -0,0 +1,48 @@
1
+ import { Graphics2D, type AssetScope, type Color, type Command, type CommandArgs, type Extents, type NodeConfig, type PaintProps, type Stroke } from "@motionscript/sdk";
2
+ import { type CoordinateMap } from "../kit/coords.js";
3
+ import { CoordinateSystem } from "../kit/system.js";
4
+ export interface PolarPlaneProps extends PaintProps {
5
+ radius?: number;
6
+ ringStep?: number;
7
+ spokes?: number;
8
+ angleUnit?: "degrees" | "radians";
9
+ gridStroke?: Stroke;
10
+ labels?: boolean;
11
+ labelSize?: number;
12
+ labelColor?: Color;
13
+ fontFamily?: string;
14
+ }
15
+ /**
16
+ * Rings and spokes about an origin: the plane a polar curve is read on.
17
+ * Children sit in its graph coordinates, x and y in the units its rings count,
18
+ * so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.
19
+ */
20
+ export declare class PolarPlane extends CoordinateSystem<PolarPlaneProps> {
21
+ /** The radius of the outermost ring, in graph units. */
22
+ radius: number;
23
+ /** The spacing of the rings; zero picks a tidy one for the plane's size. */
24
+ ringStep: number;
25
+ /** How many spokes divide the turn; zero draws none. */
26
+ spokes: number;
27
+ angleUnit: "degrees" | "radians";
28
+ /** The inner rings and the spokes. */
29
+ gridStroke: Stroke;
30
+ /** The outer ring and the two lines through the origin. */
31
+ stroke: Stroke;
32
+ /** A number at each ring, and an angle at each spoke. */
33
+ labels: boolean;
34
+ labelSize: number;
35
+ labelColor: Color;
36
+ fontFamily: string;
37
+ constructor(props?: NodeConfig<PolarPlane, PolarPlaneProps>);
38
+ /** Animate how far out the plane reaches: a zoom about its origin. */
39
+ rangeTo(args: CommandArgs<{
40
+ radius: number;
41
+ }> & {
42
+ duration: number;
43
+ }): Command<PolarPlaneProps>;
44
+ declareAssets(assets: AssetScope): void;
45
+ protected mapFor(area: Extents): CoordinateMap;
46
+ protected furniture(map: CoordinateMap): Graphics2D[];
47
+ }
48
+ //# sourceMappingURL=polar-plane.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polar-plane.d.ts","sourceRoot":"","sources":["../../src/systems/polar-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,UAAU,EAIV,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,UAAU,EAEf,KAAK,UAAU,EACf,KAAK,MAAM,EAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAGjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,e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,SAAS,CAAC,GAAG,EAAE,aAAa,GAAG,UAAU,EAAE;CA4DxD"}
@@ -0,0 +1,165 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { colorProperty, command, Graphics2D, node, property, strokeProperty, } from "@motionscript/sdk";
8
+ import { cartesianMap } from "../kit/coords.js";
9
+ import { AXIS_COLOR, drawLabels } from "../kit/furniture.js";
10
+ import { stated } from "../kit/geometry.js";
11
+ import { CoordinateSystem } from "../kit/system.js";
12
+ import { formatTick, ticksFor } from "../kit/ticks.js";
13
+ /** How much room, in label sizes, the angles written round the outer ring take from the plane. */
14
+ const LABEL_ROOM = 2.2;
15
+ /**
16
+ * Rings and spokes about an origin: the plane a polar curve is read on.
17
+ * Children sit in its graph coordinates, x and y in the units its rings count,
18
+ * so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.
19
+ */
20
+ let PolarPlane = class PolarPlane extends CoordinateSystem {
21
+ constructor(props) {
22
+ super(props ?? {});
23
+ }
24
+ /** Animate how far out the plane reaches: a zoom about its origin. */
25
+ rangeTo(args) {
26
+ return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
27
+ }
28
+ declareAssets(assets) {
29
+ super.declareAssets(assets);
30
+ if (this.fontFamily !== "")
31
+ assets.font(this.fontFamily);
32
+ }
33
+ mapFor(area) {
34
+ const width = area.maxX - area.minX;
35
+ const height = area.maxY - area.minY;
36
+ // The outer ring fits the shorter side, less the room its angles are written in; units are square.
37
+ const reach = Math.max(1, Math.min(width, height) / 2 - (this.labels ? this.labelSize * LABEL_ROOM : 0));
38
+ const unit = reach / Math.max(this.radius, 1e-9);
39
+ return cartesianMap({
40
+ xRange: [-width / 2 / unit, width / 2 / unit],
41
+ yRange: [-height / 2 / unit, height / 2 / unit],
42
+ area,
43
+ });
44
+ }
45
+ furniture(map) {
46
+ const stroke = this.stroke;
47
+ const grid = this.gridStroke;
48
+ const { start, end, radius } = this;
49
+ const centre = map.toPoint(0, 0);
50
+ const reach = map.toPoint(radius, 0).x - centre.x;
51
+ if (!(reach > 0))
52
+ return [];
53
+ const at = (r, degrees) => {
54
+ const angle = (degrees * Math.PI) / 180;
55
+ return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));
56
+ };
57
+ const ring = (g, r) => {
58
+ const size = (map.toPoint(r, 0).x - centre.x) * 2;
59
+ return g.ellipse({ x: centre.x, y: centre.y, width: size, height: size, start, end });
60
+ };
61
+ const parts = [];
62
+ const marks = ticksFor([0, radius], this.ringStep, reach);
63
+ const rings = marks.values.filter((r) => r > 0 && r < radius * (1 - 1e-9));
64
+ const count = Math.round(this.spokes);
65
+ const turns = Array.from({ length: count }, (_, i) => (360 * i) / count);
66
+ if (grid.length > 0) {
67
+ const inner = new Graphics2D();
68
+ for (const r of rings)
69
+ ring(inner, r);
70
+ // The four along the axes are drawn with them.
71
+ for (const degrees of turns) {
72
+ if (degrees % 90 !== 0)
73
+ inner.line({ points: [centre, at(radius, degrees)], radius: 0, start, end });
74
+ }
75
+ if (rings.length > 0 || turns.some((degrees) => degrees % 90 !== 0))
76
+ parts.push(inner.stroke(grid));
77
+ }
78
+ if (stroke.length > 0) {
79
+ parts.push(ring(new Graphics2D(), radius)
80
+ .line({ points: [at(radius, 180), at(radius, 0)], radius: 0, start, end })
81
+ .line({ points: [at(radius, 270), at(radius, 90)], radius: 0, start, end })
82
+ .stroke(stroke));
83
+ }
84
+ if (!this.labels)
85
+ return parts;
86
+ const size = this.labelSize;
87
+ const labels = [];
88
+ for (const r of [...rings, radius]) {
89
+ const p = map.toPoint(r, 0);
90
+ labels.push({ text: formatTick(r, marks.step), at: { x: p.x - size * 0.2, y: p.y - size * 0.95 }, align: "right" });
91
+ }
92
+ for (const degrees of turns) {
93
+ const p = at(radius, degrees);
94
+ const cos = Math.cos((degrees * Math.PI) / 180);
95
+ const sin = Math.sin((degrees * Math.PI) / 180);
96
+ labels.push({
97
+ text: this.angleUnit === "degrees" ? `${formatTick(degrees, 1)}°` : radians(degrees),
98
+ at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },
99
+ align: cos > 0.3 ? "left" : cos < -0.3 ? "right" : "center",
100
+ });
101
+ }
102
+ parts.push(...drawLabels(labels, { fontSize: size, fontFamily: this.fontFamily, color: this.labelColor }));
103
+ return parts;
104
+ }
105
+ };
106
+ __decorate([
107
+ property({ default: 4, min: 0.0001, step: 0.5 })
108
+ ], PolarPlane.prototype, "radius", void 0);
109
+ __decorate([
110
+ property({ default: 0, min: 0 })
111
+ ], PolarPlane.prototype, "ringStep", void 0);
112
+ __decorate([
113
+ property({ default: 12, min: 0, max: 72, step: 1, animatable: false })
114
+ ], PolarPlane.prototype, "spokes", void 0);
115
+ __decorate([
116
+ property({ default: "degrees", options: ["degrees", "radians"], animatable: false })
117
+ ], PolarPlane.prototype, "angleUnit", void 0);
118
+ __decorate([
119
+ strokeProperty({ default: { weight: 1.25, fill: "#3b4658", align: "center" } })
120
+ ], PolarPlane.prototype, "gridStroke", void 0);
121
+ __decorate([
122
+ strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: "center" } })
123
+ ], PolarPlane.prototype, "stroke", void 0);
124
+ __decorate([
125
+ property({ default: true, animatable: false })
126
+ ], PolarPlane.prototype, "labels", void 0);
127
+ __decorate([
128
+ property({ default: 16, min: 1, unit: "px" })
129
+ ], PolarPlane.prototype, "labelSize", void 0);
130
+ __decorate([
131
+ colorProperty({ default: AXIS_COLOR })
132
+ ], PolarPlane.prototype, "labelColor", void 0);
133
+ __decorate([
134
+ property({ default: "", animatable: false })
135
+ ], PolarPlane.prototype, "fontFamily", void 0);
136
+ __decorate([
137
+ command({ args: ["radius"] })
138
+ ], PolarPlane.prototype, "rangeTo", null);
139
+ PolarPlane = __decorate([
140
+ node({
141
+ key: "polarPlane",
142
+ parentKey: "node",
143
+ forkable: true,
144
+ layout: { children: "freeform", defaultWidthMode: "fixed", defaultHeightMode: "fixed", acceptsChildren: true },
145
+ seed: { width: 560, height: 560 },
146
+ })
147
+ ], PolarPlane);
148
+ export { PolarPlane };
149
+ /** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */
150
+ function radians(degrees) {
151
+ if (degrees === 0)
152
+ return "0";
153
+ let numerator = Math.round(degrees);
154
+ let denominator = 180;
155
+ for (let a = numerator, b = denominator;; [a, b] = [b, a % b]) {
156
+ if (b === 0) {
157
+ numerator /= a;
158
+ denominator /= a;
159
+ break;
160
+ }
161
+ }
162
+ const top = numerator === 1 ? "π" : `${numerator}π`;
163
+ return denominator === 1 ? top : `${top}/${denominator}`;
164
+ }
165
+ //# sourceMappingURL=polar-plane.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polar-plane.js","sourceRoot":"","sources":["../../src/systems/polar-plane.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,aAAa,EACb,OAAO,EACP,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,cAAc,GAWjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAsB,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAc,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAcpD,kGAAkG;AAClG,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB;;;;GAIG;AAQI,IAAM,UAA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7B;AA5BQ,UAAU;IAPtB,IAAI,CAAC;QACF,GAAG,EAAE,YAAY;QACjB,SAAS,EAAE,MAAM;QACjB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,gBAAgB,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE;QAC9G,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;KACpC,CAAC;GACW,UAAU,CA4GtB;;AAED,0EAA0E;AAC1E,SAAS,OAAO,CAAC,OAAe;IAC5B,IAAI,OAAO,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IAC9B,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,WAAW,GAAG,GAAG,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,WAAW,GAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC7D,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACV,SAAS,IAAI,CAAC,CAAC;YACf,WAAW,IAAI,CAAC,CAAC;YACjB,MAAM;QACV,CAAC;IACL,CAAC;IACD,MAAM,GAAG,GAAG,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC;IACpD,OAAO,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAC7D,CAAC","sourcesContent":["import {\r\n colorProperty,\r\n command,\r\n Graphics2D,\r\n node,\r\n property,\r\n strokeProperty,\r\n type AssetScope,\r\n type Color,\r\n type Command,\r\n type CommandArgs,\r\n type Extents,\r\n type NodeConfig,\r\n type NormalizedColor,\r\n type PaintProps,\r\n type Stroke,\r\n type StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport { cartesianMap, type CoordinateMap } from \"../kit/coords\";\r\nimport { AXIS_COLOR, drawLabels, type Label } from \"../kit/furniture\";\r\nimport { stated } from \"../kit/geometry\";\r\nimport { CoordinateSystem } from \"../kit/system\";\r\nimport { formatTick, ticksFor } from \"../kit/ticks\";\r\n\r\nexport interface PolarPlaneProps extends PaintProps {\r\n radius?: number;\r\n ringStep?: number;\r\n spokes?: number;\r\n angleUnit?: \"degrees\" | \"radians\";\r\n gridStroke?: Stroke;\r\n labels?: boolean;\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n}\r\n\r\n/** How much room, in label sizes, the angles written round the outer ring take from the plane. */\r\nconst LABEL_ROOM = 2.2;\r\n\r\n/**\r\n * Rings and spokes about an origin: the plane a polar curve is read on.\r\n * Children sit in its graph coordinates, x and y in the units its rings count,\r\n * so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.\r\n */\r\n@node({\r\n key: \"polarPlane\",\r\n parentKey: \"node\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"fixed\", defaultHeightMode: \"fixed\", acceptsChildren: true },\r\n seed: { width: 560, height: 560 },\r\n})\r\nexport class PolarPlane extends CoordinateSystem<PolarPlaneProps> {\r\n /** The radius of the outermost ring, in graph units. */\r\n @property({ default: 4, min: 0.0001, step: 0.5 }) declare radius: number;\r\n /** The spacing of the rings; zero picks a tidy one for the plane's size. */\r\n @property({ default: 0, min: 0 }) declare ringStep: number;\r\n /** How many spokes divide the turn; zero draws none. */\r\n @property({ default: 12, min: 0, max: 72, step: 1, animatable: false }) declare spokes: number;\r\n @property({ default: \"degrees\", options: [\"degrees\", \"radians\"], animatable: false }) declare angleUnit: \"degrees\" | \"radians\";\r\n\r\n /** The inner rings and the spokes. */\r\n @strokeProperty({ default: { weight: 1.25, fill: \"#3b4658\", align: \"center\" } }) declare gridStroke: Stroke;\r\n /** The outer ring and the two lines through the origin. */\r\n @strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: \"center\" } }) declare stroke: Stroke;\r\n\r\n /** A number at each ring, and an angle at each spoke. */\r\n @property({ default: true, animatable: false }) declare labels: boolean;\r\n @property({ default: 16, min: 1, unit: \"px\" }) declare labelSize: number;\r\n @colorProperty({ default: AXIS_COLOR }) declare labelColor: Color;\r\n @property({ default: \"\", animatable: false }) declare fontFamily: string;\r\n\r\n constructor(props?: NodeConfig<PolarPlane, PolarPlaneProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n /** Animate how far out the plane reaches: a zoom about its origin. */\r\n @command({ args: [\"radius\"] })\r\n rangeTo(args: CommandArgs<{ radius: number }> & { duration: number }): Command<PolarPlaneProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets);\r\n if (this.fontFamily !== \"\") assets.font(this.fontFamily);\r\n }\r\n\r\n protected mapFor(area: Extents): CoordinateMap {\r\n const width = area.maxX - area.minX;\r\n const height = area.maxY - area.minY;\r\n // The outer ring fits the shorter side, less the room its angles are written in; units are square.\r\n const reach = Math.max(1, Math.min(width, height) / 2 - (this.labels ? this.labelSize * LABEL_ROOM : 0));\r\n const unit = reach / Math.max(this.radius, 1e-9);\r\n return cartesianMap({\r\n xRange: [-width / 2 / unit, width / 2 / unit],\r\n yRange: [-height / 2 / unit, height / 2 / unit],\r\n area,\r\n });\r\n }\r\n\r\n protected furniture(map: CoordinateMap): Graphics2D[] {\r\n const stroke = this.stroke as StrokeResolved[];\r\n const grid = this.gridStroke as StrokeResolved[];\r\n const { start, end, radius } = this;\r\n const centre = map.toPoint(0, 0);\r\n const reach = map.toPoint(radius, 0).x - centre.x;\r\n if (!(reach > 0)) return [];\r\n const at = (r: number, degrees: number) => {\r\n const angle = (degrees * Math.PI) / 180;\r\n return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));\r\n };\r\n const ring = (g: Graphics2D, r: number): Graphics2D => {\r\n const size = (map.toPoint(r, 0).x - centre.x) * 2;\r\n return g.ellipse({ x: centre.x, y: centre.y, width: size, height: size, start, end });\r\n };\r\n\r\n const parts: Graphics2D[] = [];\r\n const marks = ticksFor([0, radius], this.ringStep, reach);\r\n const rings = marks.values.filter((r) => r > 0 && r < radius * (1 - 1e-9));\r\n const count = Math.round(this.spokes);\r\n const turns = Array.from({ length: count }, (_, i) => (360 * i) / count);\r\n\r\n if (grid.length > 0) {\r\n const inner = new Graphics2D();\r\n for (const r of rings) ring(inner, r);\r\n // The four along the axes are drawn with them.\r\n for (const degrees of turns) {\r\n if (degrees % 90 !== 0) inner.line({ points: [centre, at(radius, degrees)], radius: 0, start, end });\r\n }\r\n if (rings.length > 0 || turns.some((degrees) => degrees % 90 !== 0)) parts.push(inner.stroke(grid));\r\n }\r\n if (stroke.length > 0) {\r\n parts.push(\r\n ring(new Graphics2D(), radius)\r\n .line({ points: [at(radius, 180), at(radius, 0)], radius: 0, start, end })\r\n .line({ points: [at(radius, 270), at(radius, 90)], radius: 0, start, end })\r\n .stroke(stroke),\r\n );\r\n }\r\n if (!this.labels) return parts;\r\n\r\n const size = this.labelSize;\r\n const labels: Label[] = [];\r\n for (const r of [...rings, radius]) {\r\n const p = map.toPoint(r, 0);\r\n labels.push({ text: formatTick(r, marks.step), at: { x: p.x - size * 0.2, y: p.y - size * 0.95 }, align: \"right\" });\r\n }\r\n for (const degrees of turns) {\r\n const p = at(radius, degrees);\r\n const cos = Math.cos((degrees * Math.PI) / 180);\r\n const sin = Math.sin((degrees * Math.PI) / 180);\r\n labels.push({\r\n text: this.angleUnit === \"degrees\" ? `${formatTick(degrees, 1)}°` : radians(degrees),\r\n at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },\r\n align: cos > 0.3 ? \"left\" : cos < -0.3 ? \"right\" : \"center\",\r\n });\r\n }\r\n parts.push(...drawLabels(labels, { fontSize: size, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor }));\r\n return parts;\r\n }\r\n}\r\n\r\n/** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */\r\nfunction radians(degrees: number): string {\r\n if (degrees === 0) return \"0\";\r\n let numerator = Math.round(degrees);\r\n let denominator = 180;\r\n for (let a = numerator, b = denominator; ; [a, b] = [b, a % b]) {\r\n if (b === 0) {\r\n numerator /= a;\r\n denominator /= a;\r\n break;\r\n }\r\n }\r\n const top = numerator === 1 ? \"π\" : `${numerator}π`;\r\n return denominator === 1 ? top : `${top}/${denominator}`;\r\n}\r\n"]}
@@ -0,0 +1,85 @@
1
+ import { PathCommand } from '@motionscript/sdk';
2
+ /**
3
+ * The asset key a node that typesets declares its loader under: the host waits
4
+ * for it before laying the node out, and a scene with no formula never loads it.
5
+ */
6
+ export declare const MATHJAX_LOADER = "math:mathjax";
7
+ /** Load MathJax, once. A host that typesets outside a scene (a tool, a test) awaits this first. */
8
+ export declare function loadMathJax(): Promise<void>;
9
+ /** Whether MathJax has loaded, so a formula can be typeset now. */
10
+ export declare function mathJaxLoaded(): boolean;
11
+ /** What a formula is before MathJax has loaded: nothing to draw, and nothing cached. */
12
+ export declare function blankLatex(): LatexPathResult;
13
+ /** MathJax is not loaded yet: what typesetting throws before {@link loadMathJax} has resolved. */
14
+ export declare class LatexNotLoaded extends Error {
15
+ constructor();
16
+ }
17
+ /**
18
+ * A formula MathJax could not typeset.
19
+ *
20
+ * MathJax does not throw on malformed TeX. It typesets an error box in place of
21
+ * the formula and tags it `data-mjx-error`, so the failure arrives as a drawing:
22
+ * nothing at all from the browser adaptor and a filled bar from the DOM-free
23
+ * one, which left a host able to tell a bad formula from a blank one only by the
24
+ * token count. {@link buildLatexPath} raises this instead, the same way under
25
+ * both adaptors. `\require` is an error too, since only the packages named above
26
+ * are loaded.
27
+ */
28
+ export declare class LatexError extends Error {
29
+ /** The formula that failed, as it was given. */
30
+ readonly latex: string;
31
+ /** MathJax's own description of what is wrong with it. */
32
+ readonly reason: string;
33
+ constructor(latex: string, reason: string);
34
+ }
35
+ /** A single rendered glyph or shape with its character key and path commands. */
36
+ export interface LatexToken {
37
+ /** Character this token represents, or a synthetic key for non-glyph shapes. */
38
+ token: string;
39
+ path: PathCommand[];
40
+ /** The source of the top-level term the token belongs to, `a^2` in `a^2 + b^2`; empty for none. */
41
+ term?: string;
42
+ }
43
+ /**
44
+ * A piece of a formula as its source wrote it: `x^2`, `\frac{d}{dx}`, a lone
45
+ * `+`. Every group the typesetter makes is one, so parts nest.
46
+ */
47
+ export interface LatexPart {
48
+ /** The part's own source. */
49
+ latex: string;
50
+ /** The tokens it draws, as a span of the formula's token list: `from` up to, not including, `to`. */
51
+ from: number;
52
+ to: number;
53
+ /** The index of the part it sits in, or -1 at the top. */
54
+ parent: number;
55
+ }
56
+ export interface LatexPathResult {
57
+ /** All tokens in render order. */
58
+ tokens: LatexToken[];
59
+ /** Every part of the formula, outermost first, in source order. */
60
+ parts: LatexPart[];
61
+ /** Flat array of all path commands (for legacy single-path rendering). */
62
+ commands: PathCommand[];
63
+ width: number;
64
+ height: number;
65
+ /**
66
+ * Bounding box over every token, in token coordinate space:
67
+ * [minX, minY, maxX, maxY]. All tokens share this frame, so passing it as
68
+ * each path's center frame keeps their relative layout (instead of each
69
+ * glyph centering on its own bbox).
70
+ */
71
+ bounds: [number, number, number, number];
72
+ }
73
+ export declare function buildLatexPath(text: string, fontSize: number): LatexPathResult;
74
+ /**
75
+ * The sources of a formula's parts, each once, in the order written: what a
76
+ * host offers to pick a part from. Empty for a formula that will not typeset.
77
+ */
78
+ export declare function latexPartNames(source: string): string[];
79
+ /**
80
+ * The token spans `selector` names in a formula, in source order: every part
81
+ * whose source it is, and every run of neighbouring parts that spell it
82
+ * together (`b^2 = c^2` in `a^2 + b^2 = c^2`). Empty when it names nothing.
83
+ */
84
+ export declare function findLatexParts(parts: readonly LatexPart[], selector: string): Array<[from: number, to: number]>;
85
+ //# sourceMappingURL=geometry.d.ts.map
@@ -0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