@motionscript/math 0.1.0-alpha.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +49 -49
  4. package/README.md +390 -391
  5. package/dist/annotate/angle-mark.js.map +1 -1
  6. package/dist/annotate/curly-brace.js.map +1 -1
  7. package/dist/annotate/emphasis-mark.js.map +1 -1
  8. package/dist/browser/chunks/{chunk-FETQZEN2.js → chunk-IRZCG6PM.js} +2 -2
  9. package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
  10. package/dist/browser/chunks/{chunk-K77KLQX4.js → chunk-WMVW6ZIV.js} +2 -2
  11. package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
  12. package/dist/browser/chunks/{mathjax-DNP3YRES.js → mathjax-WV55AC2P.js} +1 -1
  13. package/dist/browser/chunks/{mathjax-DNP3YRES.js.map → mathjax-WV55AC2P.js.map} +1 -1
  14. package/dist/browser/index.js +1 -1
  15. package/dist/browser/index.js.map +1 -1
  16. package/dist/browser/kit.js +1 -1
  17. package/dist/browser/manifest.json +1 -1
  18. package/dist/browser/tex.js +1 -1
  19. package/dist/browser/tex.js.map +1 -1
  20. package/dist/engine.d.ts +1 -1
  21. package/dist/engine.js +1 -1
  22. package/dist/engine.js.map +1 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/kit/brace.js.map +1 -1
  25. package/dist/kit/cache.js.map +1 -1
  26. package/dist/kit/component.d.ts.map +1 -1
  27. package/dist/kit/component.js.map +1 -1
  28. package/dist/kit/contour.js.map +1 -1
  29. package/dist/kit/coords.js.map +1 -1
  30. package/dist/kit/curve.js.map +1 -1
  31. package/dist/kit/equation.js.map +1 -1
  32. package/dist/kit/equation3d.js.map +1 -1
  33. package/dist/kit/expression.js.map +1 -1
  34. package/dist/kit/field-mark.d.ts.map +1 -1
  35. package/dist/kit/field-mark.js.map +1 -1
  36. package/dist/kit/field.js.map +1 -1
  37. package/dist/kit/follow.d.ts.map +1 -1
  38. package/dist/kit/follow.js.map +1 -1
  39. package/dist/kit/furniture.js.map +1 -1
  40. package/dist/kit/geometry.js.map +1 -1
  41. package/dist/kit/graph.js.map +1 -1
  42. package/dist/kit/mark.js.map +1 -1
  43. package/dist/kit/part-fills.js.map +1 -1
  44. package/dist/kit/place.js.map +1 -1
  45. package/dist/kit/sampler.js.map +1 -1
  46. package/dist/kit/scale.js.map +1 -1
  47. package/dist/kit/source.js.map +1 -1
  48. package/dist/kit/system.js.map +1 -1
  49. package/dist/kit/ticks.js.map +1 -1
  50. package/dist/kit/withdrawn.js.map +1 -1
  51. package/dist/marks/curve-area.js.map +1 -1
  52. package/dist/marks/drop-lines.js.map +1 -1
  53. package/dist/marks/plot-point.js.map +1 -1
  54. package/dist/marks/riemann-sum.js.map +1 -1
  55. package/dist/marks/tangent-line.js.map +1 -1
  56. package/dist/marks/vector-arrow.js.map +1 -1
  57. package/dist/nodes.js.map +1 -1
  58. package/dist/plots/function-plot.d.ts.map +1 -1
  59. package/dist/plots/function-plot.js.map +1 -1
  60. package/dist/plots/points-plot.js.map +1 -1
  61. package/dist/plots/stream-lines.js.map +1 -1
  62. package/dist/plots/traced-path.js.map +1 -1
  63. package/dist/plots/vector-field.js.map +1 -1
  64. package/dist/structures/graph-layout.js.map +1 -1
  65. package/dist/structures/network-graph.js.map +1 -1
  66. package/dist/structures/sample-space.js.map +1 -1
  67. package/dist/systems/axes2d.d.ts.map +1 -1
  68. package/dist/systems/axes2d.js.map +1 -1
  69. package/dist/systems/number-line.js.map +1 -1
  70. package/dist/systems/number-plane.js.map +1 -1
  71. package/dist/systems/polar-plane.js.map +1 -1
  72. package/dist/tex/geometry.js.map +1 -1
  73. package/dist/tex/index.js.map +1 -1
  74. package/dist/tex/mathjax.js.map +1 -1
  75. package/dist/tex/matrix.js.map +1 -1
  76. package/dist/tex/node.js.map +1 -1
  77. package/dist/tex/tween.js.map +1 -1
  78. package/dist/tex/typeset.d.ts.map +1 -1
  79. package/dist/tex/typeset.js.map +1 -1
  80. package/dist/three/axes3d.js.map +1 -1
  81. package/dist/three/curve-plot3d.js.map +1 -1
  82. package/dist/three/entries.js.map +1 -1
  83. package/dist/three/label3d.js.map +1 -1
  84. package/dist/three/plot-point3d.js.map +1 -1
  85. package/dist/three/space.js.map +1 -1
  86. package/dist/three/surface-plot3d.js.map +1 -1
  87. package/dist/three/vector-arrow3d.js.map +1 -1
  88. package/package.json +4 -4
  89. package/registry.json +251 -251
  90. package/src/annotate/angle-mark.ts +137 -137
  91. package/src/annotate/curly-brace.ts +148 -148
  92. package/src/annotate/emphasis-mark.ts +118 -118
  93. package/src/engine.ts +86 -86
  94. package/src/index.ts +29 -29
  95. package/src/kit/brace.ts +37 -37
  96. package/src/kit/cache.ts +61 -61
  97. package/src/kit/component.ts +57 -57
  98. package/src/kit/contour.ts +94 -94
  99. package/src/kit/coords.ts +278 -278
  100. package/src/kit/curve.ts +47 -47
  101. package/src/kit/equation.ts +181 -181
  102. package/src/kit/equation3d.ts +137 -137
  103. package/src/kit/expression.ts +159 -159
  104. package/src/kit/field-mark.ts +171 -171
  105. package/src/kit/field.ts +50 -50
  106. package/src/kit/follow.ts +229 -229
  107. package/src/kit/furniture.ts +113 -113
  108. package/src/kit/geometry.ts +49 -49
  109. package/src/kit/graph.ts +116 -116
  110. package/src/kit/mark.ts +152 -152
  111. package/src/kit/part-fills.ts +61 -61
  112. package/src/kit/place.ts +77 -77
  113. package/src/kit/sampler.ts +281 -281
  114. package/src/kit/scale.ts +39 -39
  115. package/src/kit/source.ts +57 -57
  116. package/src/kit/system.ts +105 -105
  117. package/src/kit/ticks.ts +85 -85
  118. package/src/kit/withdrawn.ts +8 -8
  119. package/src/marks/curve-area.ts +89 -89
  120. package/src/marks/drop-lines.ts +71 -71
  121. package/src/marks/plot-point.ts +102 -102
  122. package/src/marks/riemann-sum.ts +99 -99
  123. package/src/marks/tangent-line.ts +119 -119
  124. package/src/marks/vector-arrow.ts +98 -98
  125. package/src/nodes.ts +99 -99
  126. package/src/plots/function-plot.ts +220 -220
  127. package/src/plots/points-plot.ts +103 -103
  128. package/src/plots/stream-lines.ts +160 -160
  129. package/src/plots/traced-path.ts +70 -70
  130. package/src/plots/vector-field.ts +107 -107
  131. package/src/structures/graph-layout.ts +145 -145
  132. package/src/structures/network-graph.ts +291 -291
  133. package/src/structures/sample-space.ts +210 -210
  134. package/src/systems/axes2d.ts +226 -226
  135. package/src/systems/number-line.ts +130 -130
  136. package/src/systems/number-plane.ts +232 -232
  137. package/src/systems/polar-plane.ts +177 -177
  138. package/src/tex/geometry.ts +703 -703
  139. package/src/tex/index.ts +15 -15
  140. package/src/tex/mathjax.ts +82 -82
  141. package/src/tex/matrix.ts +97 -97
  142. package/src/tex/node.ts +74 -74
  143. package/src/tex/tween.ts +308 -308
  144. package/src/tex/typeset.ts +461 -461
  145. package/src/three/axes3d.ts +267 -267
  146. package/src/three/curve-plot3d.ts +146 -146
  147. package/src/three/entries.ts +42 -42
  148. package/src/three/label3d.ts +52 -52
  149. package/src/three/plot-point3d.ts +63 -63
  150. package/src/three/space.ts +92 -92
  151. package/src/three/surface-plot3d.ts +318 -318
  152. package/src/three/vector-arrow3d.ts +88 -88
  153. package/dist/browser/chunks/chunk-FETQZEN2.js.map +0 -7
  154. package/dist/browser/chunks/chunk-K77KLQX4.js.map +0 -7
  155. package/dist/kit/placement.d.ts +0 -8
  156. package/dist/kit/placement.d.ts.map +0 -1
  157. package/dist/kit/placement.js +0 -8
  158. package/dist/kit/placement.js.map +0 -1
@@ -1,177 +1,177 @@
1
- import {
2
- component2d,
3
- Graphics2D,
4
- Types,
5
- type Color,
6
- type Extents,
7
- type NodeOf,
8
- type NormalizedColor,
9
- type PaintProps,
10
- type Stroke,
11
- type StrokeResolved,
12
- type Values,
13
- // Named so the emitted declaration reaches these through the sdk, not core.
14
- type Fill as _Fill,
15
- type FillResolved as _FillResolved,
16
- type Node2D as _Node2D,
17
- type Node2DProps as _Node2DProps,
18
- type Shadow as _Shadow,
19
- type ShadowResolved as _ShadowResolved,
20
- } from "@motionscript/sdk";
21
- import { listed, PAINT, PAINT_COMMANDS } from "../kit/component";
22
- import { cartesianMap, type CoordinateMap } from "../kit/coords";
23
- import { AXIS_COLOR, drawLabels, type Label } from "../kit/furniture";
24
- import { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from "../kit/system";
25
- import { formatTick, ticksFor } from "../kit/ticks";
26
-
27
- export interface PolarPlaneProps extends PaintProps {
28
- radius?: number;
29
- ringStep?: number;
30
- spokes?: number;
31
- angleUnit?: "degrees" | "radians";
32
- gridStroke?: Stroke;
33
- labels?: boolean;
34
- labelSize?: number;
35
- labelColor?: Color;
36
- fontFamily?: string;
37
- }
38
-
39
- /** How much room, in label sizes, the angles written round the outer ring take from the plane. */
40
- const LABEL_ROOM = 2.2;
41
-
42
- const state = {
43
- ...PAINT,
44
- /** The radius of the outermost ring, in graph units. */
45
- radius: Types.number(4, { min: 0.0001, step: 0.5 }),
46
- /** The spacing of the rings; zero picks a tidy one for the plane's size. */
47
- ringStep: Types.number(0, { min: 0 }),
48
- /** How many spokes divide the turn; zero draws none. */
49
- spokes: Types.number(12, { min: 0, max: 72, step: 1, animatable: false }),
50
- angleUnit: listed(["degrees", "radians"], "degrees", { animatable: false }),
51
- /** The inner rings and the spokes. */
52
- gridStroke: Types.stroke({ weight: 1.25, fill: "#3b4658", align: "center" }),
53
- /** A number at each ring, and an angle at each spoke. */
54
- labels: Types.boolean(true, { animatable: false }),
55
- labelSize: Types.number(16, { min: 1, unit: "px" }),
56
- labelColor: Types.color(AXIS_COLOR),
57
- fontFamily: Types.text("", { animatable: false }),
58
- };
59
-
60
- type PolarValues = Values<typeof state>;
61
-
62
- /**
63
- * Rings and spokes about an origin: the plane a polar curve is read on.
64
- * Children sit in its graph coordinates, x and y in the units its rings count,
65
- * so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.
66
- */
67
- export const PolarPlane = component2d({
68
- key: "polarPlane",
69
- state,
70
- /** The outer ring and the two lines through the origin. */
71
- defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: "center" } },
72
- load: (loader, s) => {
73
- if (s.fontFamily !== "") loader.font(s.fontFamily);
74
- },
75
- commands: {
76
- ...PAINT_COMMANDS,
77
- /** Animate how far out the plane reaches: a zoom about its origin. */
78
- rangeTo: { args: ["radius"] },
79
- },
80
- provide: (s) => systemProvides(s),
81
- measure: (_measurer, s) => systemSize(s),
82
- layout: (box, s, children) => systemLayout(box, s, children, polarMap),
83
- plane: (box, s) => systemOpenPlane(box, s, polarMap),
84
- render: (ctx, s) => drawSystem(ctx, s, systemMap(ctx.size, s, polarMap), (map) => polarFurniture(map, s)),
85
- });
86
-
87
- export type PolarPlane = NodeOf<typeof PolarPlane>;
88
-
89
- function polarMap(area: Extents, s: PolarValues): CoordinateMap {
90
- const width = area.maxX - area.minX;
91
- const height = area.maxY - area.minY;
92
- // The outer ring fits the shorter side, less the room its angles are written in; units are square.
93
- const reach = Math.max(1, Math.min(width, height) / 2 - (s.labels ? s.labelSize * LABEL_ROOM : 0));
94
- const unit = reach / Math.max(s.radius, 1e-9);
95
- return cartesianMap({
96
- xRange: [-width / 2 / unit, width / 2 / unit],
97
- yRange: [-height / 2 / unit, height / 2 / unit],
98
- area,
99
- });
100
- }
101
-
102
- function polarFurniture(map: CoordinateMap, s: PolarValues): Graphics2D[] {
103
- const stroke = s.stroke as StrokeResolved[];
104
- const grid = s.gridStroke as StrokeResolved[];
105
- const { start, end, radius } = s;
106
- const centre = map.toPoint(0, 0);
107
- const reach = map.toPoint(radius, 0).x - centre.x;
108
- if (!(reach > 0)) return [];
109
- const at = (r: number, degrees: number) => {
110
- const angle = (degrees * Math.PI) / 180;
111
- return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));
112
- };
113
- const ring = (g: Graphics2D, r: number): Graphics2D => {
114
- const size = (map.toPoint(r, 0).x - centre.x) * 2;
115
- return g.ellipse({ x: centre.x, y: centre.y, width: size, height: size, start, end });
116
- };
117
-
118
- const parts: Graphics2D[] = [];
119
- const marks = ticksFor([0, radius], s.ringStep, reach);
120
- const rings = marks.values.filter((r) => r > 0 && r < radius * (1 - 1e-9));
121
- const count = Math.round(s.spokes);
122
- const turns = Array.from({ length: count }, (_, i) => (360 * i) / count);
123
-
124
- if (grid.length > 0) {
125
- const inner = new Graphics2D();
126
- for (const r of rings) ring(inner, r);
127
- // The four along the axes are drawn with them.
128
- for (const degrees of turns) {
129
- if (degrees % 90 !== 0) inner.line({ points: [centre, at(radius, degrees)], radius: 0, start, end });
130
- }
131
- if (rings.length > 0 || turns.some((degrees) => degrees % 90 !== 0)) parts.push(inner.stroke(grid));
132
- }
133
- if (stroke.length > 0) {
134
- parts.push(
135
- ring(new Graphics2D(), radius)
136
- .line({ points: [at(radius, 180), at(radius, 0)], radius: 0, start, end })
137
- .line({ points: [at(radius, 270), at(radius, 90)], radius: 0, start, end })
138
- .stroke(stroke),
139
- );
140
- }
141
- if (!s.labels) return parts;
142
-
143
- const size = s.labelSize;
144
- const labels: Label[] = [];
145
- for (const r of [...rings, radius]) {
146
- const p = map.toPoint(r, 0);
147
- labels.push({ text: formatTick(r, marks.step), at: { x: p.x - size * 0.2, y: p.y - size * 0.95 }, align: "right" });
148
- }
149
- for (const degrees of turns) {
150
- const p = at(radius, degrees);
151
- const cos = Math.cos((degrees * Math.PI) / 180);
152
- const sin = Math.sin((degrees * Math.PI) / 180);
153
- labels.push({
154
- text: s.angleUnit === "degrees" ? `${formatTick(degrees, 1)}°` : radians(degrees),
155
- at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },
156
- align: cos > 0.3 ? "left" : cos < -0.3 ? "right" : "center",
157
- });
158
- }
159
- parts.push(...drawLabels(labels, { fontSize: size, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));
160
- return parts;
161
- }
162
-
163
- /** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */
164
- function radians(degrees: number): string {
165
- if (degrees === 0) return "0";
166
- let numerator = Math.round(degrees);
167
- let denominator = 180;
168
- for (let a = numerator, b = denominator; ; [a, b] = [b, a % b]) {
169
- if (b === 0) {
170
- numerator /= a;
171
- denominator /= a;
172
- break;
173
- }
174
- }
175
- const top = numerator === 1 ? "π" : `${numerator}π`;
176
- return denominator === 1 ? top : `${top}/${denominator}`;
177
- }
1
+ import {
2
+ component2d,
3
+ Graphics2D,
4
+ Types,
5
+ type Color,
6
+ type Extents,
7
+ type NodeOf,
8
+ type NormalizedColor,
9
+ type PaintProps,
10
+ type Stroke,
11
+ type StrokeResolved,
12
+ type Values,
13
+ // Named so the emitted declaration reaches these through the sdk, not core.
14
+ type Fill as _Fill,
15
+ type FillResolved as _FillResolved,
16
+ type Node2D as _Node2D,
17
+ type Node2DProps as _Node2DProps,
18
+ type Shadow as _Shadow,
19
+ type ShadowResolved as _ShadowResolved,
20
+ } from "@motionscript/sdk";
21
+ import { listed, PAINT, PAINT_COMMANDS } from "../kit/component";
22
+ import { cartesianMap, type CoordinateMap } from "../kit/coords";
23
+ import { AXIS_COLOR, drawLabels, type Label } from "../kit/furniture";
24
+ import { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from "../kit/system";
25
+ import { formatTick, ticksFor } from "../kit/ticks";
26
+
27
+ export interface PolarPlaneProps extends PaintProps {
28
+ radius?: number;
29
+ ringStep?: number;
30
+ spokes?: number;
31
+ angleUnit?: "degrees" | "radians";
32
+ gridStroke?: Stroke;
33
+ labels?: boolean;
34
+ labelSize?: number;
35
+ labelColor?: Color;
36
+ fontFamily?: string;
37
+ }
38
+
39
+ /** How much room, in label sizes, the angles written round the outer ring take from the plane. */
40
+ const LABEL_ROOM = 2.2;
41
+
42
+ const state = {
43
+ ...PAINT,
44
+ /** The radius of the outermost ring, in graph units. */
45
+ radius: Types.number(4, { min: 0.0001, step: 0.5 }),
46
+ /** The spacing of the rings; zero picks a tidy one for the plane's size. */
47
+ ringStep: Types.number(0, { min: 0 }),
48
+ /** How many spokes divide the turn; zero draws none. */
49
+ spokes: Types.number(12, { min: 0, max: 72, step: 1, animatable: false }),
50
+ angleUnit: listed(["degrees", "radians"], "degrees", { animatable: false }),
51
+ /** The inner rings and the spokes. */
52
+ gridStroke: Types.stroke({ weight: 1.25, fill: "#3b4658", align: "center" }),
53
+ /** A number at each ring, and an angle at each spoke. */
54
+ labels: Types.boolean(true, { animatable: false }),
55
+ labelSize: Types.number(16, { min: 1, unit: "px" }),
56
+ labelColor: Types.color(AXIS_COLOR),
57
+ fontFamily: Types.text("", { animatable: false }),
58
+ };
59
+
60
+ type PolarValues = Values<typeof state>;
61
+
62
+ /**
63
+ * Rings and spokes about an origin: the plane a polar curve is read on.
64
+ * Children sit in its graph coordinates, x and y in the units its rings count,
65
+ * so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.
66
+ */
67
+ export const PolarPlane = component2d({
68
+ key: "polarPlane",
69
+ state,
70
+ /** The outer ring and the two lines through the origin. */
71
+ defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: "center" } },
72
+ load: (loader, s) => {
73
+ if (s.fontFamily !== "") loader.font(s.fontFamily);
74
+ },
75
+ commands: {
76
+ ...PAINT_COMMANDS,
77
+ /** Animate how far out the plane reaches: a zoom about its origin. */
78
+ rangeTo: { args: ["radius"] },
79
+ },
80
+ provide: (s) => systemProvides(s),
81
+ measure: (_measurer, s) => systemSize(s),
82
+ layout: (box, s, children) => systemLayout(box, s, children, polarMap),
83
+ plane: (box, s) => systemOpenPlane(box, s, polarMap),
84
+ render: (ctx, s) => drawSystem(ctx, s, systemMap(ctx.size, s, polarMap), (map) => polarFurniture(map, s)),
85
+ });
86
+
87
+ export type PolarPlane = NodeOf<typeof PolarPlane>;
88
+
89
+ function polarMap(area: Extents, s: PolarValues): CoordinateMap {
90
+ const width = area.maxX - area.minX;
91
+ const height = area.maxY - area.minY;
92
+ // The outer ring fits the shorter side, less the room its angles are written in; units are square.
93
+ const reach = Math.max(1, Math.min(width, height) / 2 - (s.labels ? s.labelSize * LABEL_ROOM : 0));
94
+ const unit = reach / Math.max(s.radius, 1e-9);
95
+ return cartesianMap({
96
+ xRange: [-width / 2 / unit, width / 2 / unit],
97
+ yRange: [-height / 2 / unit, height / 2 / unit],
98
+ area,
99
+ });
100
+ }
101
+
102
+ function polarFurniture(map: CoordinateMap, s: PolarValues): Graphics2D[] {
103
+ const stroke = s.stroke as StrokeResolved[];
104
+ const grid = s.gridStroke as StrokeResolved[];
105
+ const { start, end, radius } = s;
106
+ const centre = map.toPoint(0, 0);
107
+ const reach = map.toPoint(radius, 0).x - centre.x;
108
+ if (!(reach > 0)) return [];
109
+ const at = (r: number, degrees: number) => {
110
+ const angle = (degrees * Math.PI) / 180;
111
+ return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));
112
+ };
113
+ const ring = (g: Graphics2D, r: number): Graphics2D => {
114
+ const size = (map.toPoint(r, 0).x - centre.x) * 2;
115
+ return g.ellipse({ x: centre.x, y: centre.y, width: size, height: size, start, end });
116
+ };
117
+
118
+ const parts: Graphics2D[] = [];
119
+ const marks = ticksFor([0, radius], s.ringStep, reach);
120
+ const rings = marks.values.filter((r) => r > 0 && r < radius * (1 - 1e-9));
121
+ const count = Math.round(s.spokes);
122
+ const turns = Array.from({ length: count }, (_, i) => (360 * i) / count);
123
+
124
+ if (grid.length > 0) {
125
+ const inner = new Graphics2D();
126
+ for (const r of rings) ring(inner, r);
127
+ // The four along the axes are drawn with them.
128
+ for (const degrees of turns) {
129
+ if (degrees % 90 !== 0) inner.line({ points: [centre, at(radius, degrees)], radius: 0, start, end });
130
+ }
131
+ if (rings.length > 0 || turns.some((degrees) => degrees % 90 !== 0)) parts.push(inner.stroke(grid));
132
+ }
133
+ if (stroke.length > 0) {
134
+ parts.push(
135
+ ring(new Graphics2D(), radius)
136
+ .line({ points: [at(radius, 180), at(radius, 0)], radius: 0, start, end })
137
+ .line({ points: [at(radius, 270), at(radius, 90)], radius: 0, start, end })
138
+ .stroke(stroke),
139
+ );
140
+ }
141
+ if (!s.labels) return parts;
142
+
143
+ const size = s.labelSize;
144
+ const labels: Label[] = [];
145
+ for (const r of [...rings, radius]) {
146
+ const p = map.toPoint(r, 0);
147
+ labels.push({ text: formatTick(r, marks.step), at: { x: p.x - size * 0.2, y: p.y - size * 0.95 }, align: "right" });
148
+ }
149
+ for (const degrees of turns) {
150
+ const p = at(radius, degrees);
151
+ const cos = Math.cos((degrees * Math.PI) / 180);
152
+ const sin = Math.sin((degrees * Math.PI) / 180);
153
+ labels.push({
154
+ text: s.angleUnit === "degrees" ? `${formatTick(degrees, 1)}°` : radians(degrees),
155
+ at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },
156
+ align: cos > 0.3 ? "left" : cos < -0.3 ? "right" : "center",
157
+ });
158
+ }
159
+ parts.push(...drawLabels(labels, { fontSize: size, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));
160
+ return parts;
161
+ }
162
+
163
+ /** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */
164
+ function radians(degrees: number): string {
165
+ if (degrees === 0) return "0";
166
+ let numerator = Math.round(degrees);
167
+ let denominator = 180;
168
+ for (let a = numerator, b = denominator; ; [a, b] = [b, a % b]) {
169
+ if (b === 0) {
170
+ numerator /= a;
171
+ denominator /= a;
172
+ break;
173
+ }
174
+ }
175
+ const top = numerator === 1 ? "π" : `${numerator}π`;
176
+ return denominator === 1 ? top : `${top}/${denominator}`;
177
+ }