@johnmorrisdotca/wakusei-planets 0.59.0 → 0.61.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 (43) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/NOTICE.md +9 -0
  3. package/README.md +31 -3
  4. package/dist/bodies/earth.js +22 -1
  5. package/dist/data/places-moon.d.ts +12 -9
  6. package/dist/data/places-moon.js +3 -3
  7. package/dist/element.d.ts +1 -1
  8. package/dist/flat/bodies.d.ts +122 -0
  9. package/dist/flat/bodies.js +115 -0
  10. package/dist/flat/define.d.ts +3 -0
  11. package/dist/flat/define.js +6 -0
  12. package/dist/flat/element.d.ts +145 -0
  13. package/dist/flat/element.js +1614 -0
  14. package/dist/flat/geometry.d.ts +127 -0
  15. package/dist/flat/geometry.js +121 -0
  16. package/dist/flat/index.d.ts +5 -0
  17. package/dist/flat/index.js +6 -0
  18. package/dist/flat/scene.d.ts +152 -0
  19. package/dist/flat/scene.js +195 -0
  20. package/dist/flat/system-define.d.ts +3 -0
  21. package/dist/flat/system-define.js +6 -0
  22. package/dist/flat/system-element.d.ts +133 -0
  23. package/dist/flat/system-element.js +1435 -0
  24. package/dist/flat/system-words.d.ts +28 -0
  25. package/dist/flat/system-words.js +102 -0
  26. package/dist/flat/system.d.ts +440 -0
  27. package/dist/flat/system.js +521 -0
  28. package/dist/flat/words.d.ts +55 -0
  29. package/dist/flat/words.js +133 -0
  30. package/dist/space/travel.js +36 -5
  31. package/dist/surface/drive.d.ts +5 -2
  32. package/dist/surface/drive.js +13 -15
  33. package/dist/surface/element.d.ts +38 -1
  34. package/dist/surface/element.js +144 -14
  35. package/dist/surface/index.d.ts +1 -0
  36. package/dist/surface/index.js +1 -0
  37. package/dist/surface/model.d.ts +54 -0
  38. package/dist/surface/model.js +147 -0
  39. package/dist/surface/rig.d.ts +125 -0
  40. package/dist/surface/rig.js +107 -0
  41. package/dist/surface/scene.d.ts +3 -0
  42. package/dist/surface/scene.js +22 -1
  43. package/package.json +38 -2
@@ -0,0 +1,521 @@
1
+ // The flat solar system, as numbers: a top-down map of the Sun, the planets, the dwarf planets and small bodies, the belts, the comets and our spacecraft (the Tesla Roadster among them), in the ecliptic plane, with distances
2
+ // squeezed by the plan's logarithm or true. The same family as the flat maps (`./index.ts`): the same view and zoom names, the same words. Pure: no DOM, no clock reads (the moment is always given).
3
+ import { smallBodyAt } from "../door/small-bodies.js";
4
+ import { toJulianDate } from "../clock.js";
5
+ import { cometOrbit, cometPosition, listComets } from "../comets.js";
6
+ import { heliocentric } from "../ephemeris.js";
7
+ import { BODIES, DWARF_IDS, MINOR_IDS, PLANET_IDS } from "../facts.js";
8
+ import { planRadius, planSunExtent } from "../plan/layout.js";
9
+ import { planetOrbit } from "../space/frame.js";
10
+ import { SPACECRAFT, SPACECRAFT_IDS, spacecraftPosition } from "../spacecraft.js";
11
+ import { toEcliptic } from "../vec.js";
12
+ import { MAX_ZOOM } from "./geometry.js";
13
+ const AU_KM = 149_597_870.7;
14
+ const DAY = 86_400_000;
15
+ /**
16
+ * The kinds of thing the flat solar system draws, which a page can switch on and off: `planets` (the eight and Pluto), `dwarfs` (the dwarf planets and the named asteroids and centaurs), `belts` (the asteroid belts and the Kuiper belt, as clouds of points), `comets` and `craft`.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { SYSTEM_LAYERS } from "@johnmorrisdotca/wakusei-planets/flat/system";
21
+ *
22
+ * console.log(SYSTEM_LAYERS.join(", "));
23
+ * ```
24
+ */
25
+ export const SYSTEM_LAYERS = ["planets", "dwarfs", "belts", "comets", "craft"];
26
+ /**
27
+ * The furthest the map zooms in: the same 8 times as the flat maps of the Moon and Mars.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { SYSTEM_MAX_ZOOM } from "@johnmorrisdotca/wakusei-planets/flat/system";
32
+ *
33
+ * console.log(SYSTEM_MAX_ZOOM);
34
+ * ```
35
+ */
36
+ export const SYSTEM_MAX_ZOOM = MAX_ZOOM;
37
+ /**
38
+ * The distance, in astronomical units, the squeezed scale treats as near the Sun: the plan's own (`<wakusei-plan>`), so the two maps put a planet in the same place on their radii.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { SYSTEM_INNER } from "@johnmorrisdotca/wakusei-planets/flat/system";
43
+ *
44
+ * console.log(SYSTEM_INNER);
45
+ * ```
46
+ */
47
+ export const SYSTEM_INNER = 0.1;
48
+ /**
49
+ * The reach of the map, the distance at its edge in astronomical units: the smallest of 50, 100, 200, 500, 1,000 and 2,000 that holds `farthest`, or `fixed` where one is asked for.
50
+ *
51
+ * @param farthest - The distance in the plane of the farthest thing that must be inside, in au.
52
+ * @param fixed - A reach the page asked for, in au; used when it is above zero and finite.
53
+ * @returns The distance at the edge, in au.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { systemExtent } from "@johnmorrisdotca/wakusei-planets/flat/system";
58
+ *
59
+ * console.log(systemExtent(49.3), systemExtent(141), systemExtent(141, 30));
60
+ * ```
61
+ */
62
+ export const systemExtent = (farthest, fixed) => (fixed !== undefined && Number.isFinite(fixed) && fixed > 0 ? fixed : planSunExtent(farthest));
63
+ /**
64
+ * Where a place in the ecliptic plane falls on the map's disc: its direction kept, its distance squeezed (`ln(1 + d / 0.1) / ln(1 + edge / 0.1)`, the plan's `planRadius`) or true (`d / edge`). The edge is 1.
65
+ *
66
+ * @param x - Astronomical units toward the March equinox.
67
+ * @param y - Astronomical units a quarter turn on.
68
+ * @param extent - The distance at the edge, in au.
69
+ * @param spacing - `squeezed` or `true`.
70
+ * @returns `x` and `y` in the unit disc, and `r`, the distance from the middle (above 1 beyond the edge).
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * import { squeezeAu } from "@johnmorrisdotca/wakusei-planets/flat/system";
75
+ *
76
+ * const earth = squeezeAu(1, 0, 50, "squeezed");
77
+ * console.log(earth.r.toFixed(2), squeezeAu(1, 0, 50, "true").r.toFixed(2));
78
+ * ```
79
+ */
80
+ export function squeezeAu(x, y, extent, spacing) {
81
+ const d = Math.hypot(x, y);
82
+ if (d === 0)
83
+ return { x: 0, y: 0, r: 0 };
84
+ const r = planRadius(d, extent, spacing, SYSTEM_INNER);
85
+ return { x: (x / d) * r, y: (y / d) * r, r };
86
+ }
87
+ /**
88
+ * The distance in astronomical units that a radius of the disc stands for: the opposite of the squeeze, so a point pressed on the map can be read as a distance.
89
+ *
90
+ * @param r - The distance from the middle in the unit disc.
91
+ * @param extent - The distance at the edge, in au.
92
+ * @param spacing - `squeezed` or `true`.
93
+ * @returns Astronomical units.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * import { radiusAu, squeezeAu } from "@johnmorrisdotca/wakusei-planets/flat/system";
98
+ *
99
+ * console.log(radiusAu(squeezeAu(5.2, 0, 50, "squeezed").r, 50, "squeezed").toFixed(2));
100
+ * ```
101
+ */
102
+ export const radiusAu = (r, extent, spacing) => (spacing === "true" ? r * extent : SYSTEM_INNER * Math.expm1(r * Math.log1p(extent / SYSTEM_INNER)));
103
+ /**
104
+ * Pixels for one unit of the disc: the whole disc fills the box's shorter side at zoom 1.
105
+ *
106
+ * @param view - The view.
107
+ * @returns Pixels to the disc's edge from its middle.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * import { systemScale } from "@johnmorrisdotca/wakusei-planets/flat/system";
112
+ *
113
+ * console.log(systemScale({ width: 800, height: 400, centerX: 0, centerY: 0, zoom: 1 }), systemScale({ width: 800, height: 400, centerX: 0, centerY: 0, zoom: 2 }));
114
+ * ```
115
+ */
116
+ export const systemScale = (view) => (Math.min(view.width, view.height) / 2) * view.zoom * 0.96;
117
+ /**
118
+ * Where a place of the disc falls in the box, in pixels from its top left (y goes up on the map and down on the screen).
119
+ *
120
+ * @param view - The view.
121
+ * @param x - Across the unit disc.
122
+ * @param y - Up the unit disc.
123
+ * @returns `x` and `y` in pixels.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * import { projectSystem } from "@johnmorrisdotca/wakusei-planets/flat/system";
128
+ *
129
+ * console.log(projectSystem({ width: 800, height: 400, centerX: 0, centerY: 0, zoom: 1 }, 0, 0));
130
+ * ```
131
+ */
132
+ export function projectSystem(view, x, y) {
133
+ const k = systemScale(view);
134
+ return { x: view.width / 2 + (x - view.centerX) * k, y: view.height / 2 - (y - view.centerY) * k };
135
+ }
136
+ /**
137
+ * The place of the disc at a point of the box: the opposite of `projectSystem`.
138
+ *
139
+ * @param view - The view.
140
+ * @param px - Pixels from the left.
141
+ * @param py - Pixels from the top.
142
+ * @returns `x` and `y` in the unit disc.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * import { unprojectSystem } from "@johnmorrisdotca/wakusei-planets/flat/system";
147
+ *
148
+ * console.log(unprojectSystem({ width: 800, height: 400, centerX: 0, centerY: 0, zoom: 1 }, 400, 200));
149
+ * ```
150
+ */
151
+ export function unprojectSystem(view, px, py) {
152
+ const k = systemScale(view);
153
+ return { x: view.centerX + (px - view.width / 2) / k, y: view.centerY - (py - view.height / 2) / k };
154
+ }
155
+ /**
156
+ * The view kept inside what the map can show: the zoom between 1 and 8, and the middle never further from the Sun than the disc's edge.
157
+ *
158
+ * @param view - The view asked for.
159
+ * @returns The view to use.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * import { clampSystemView } from "@johnmorrisdotca/wakusei-planets/flat/system";
164
+ *
165
+ * console.log(clampSystemView({ width: 800, height: 400, centerX: 3, centerY: 4, zoom: 20 }));
166
+ * ```
167
+ */
168
+ export function clampSystemView(view) {
169
+ const zoom = Math.min(SYSTEM_MAX_ZOOM, Math.max(1, Number.isFinite(view.zoom) ? view.zoom : 1));
170
+ let x = Number.isFinite(view.centerX) ? view.centerX : 0;
171
+ let y = Number.isFinite(view.centerY) ? view.centerY : 0;
172
+ const d = Math.hypot(x, y);
173
+ if (d > 1) {
174
+ x /= d;
175
+ y /= d;
176
+ }
177
+ return { ...view, zoom, centerX: x, centerY: y };
178
+ }
179
+ /**
180
+ * Zoom by a factor about a point of the box, so the place under that point stays under it (as far as the clamp allows).
181
+ *
182
+ * @param view - The view.
183
+ * @param factor - Above 1 zooms in.
184
+ * @param px - Pixels from the left; the middle when left out.
185
+ * @param py - Pixels from the top; the middle when left out.
186
+ * @returns The new view, clamped.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * import { zoomSystemAbout } from "@johnmorrisdotca/wakusei-planets/flat/system";
191
+ *
192
+ * console.log(zoomSystemAbout({ width: 800, height: 400, centerX: 0, centerY: 0, zoom: 1 }, 2, 600, 100).zoom);
193
+ * ```
194
+ */
195
+ export function zoomSystemAbout(view, factor, px = view.width / 2, py = view.height / 2) {
196
+ const at = unprojectSystem(view, px, py);
197
+ const zoom = Math.min(SYSTEM_MAX_ZOOM, Math.max(1, view.zoom * factor));
198
+ const next = { ...view, zoom };
199
+ const k = systemScale(next);
200
+ return clampSystemView({ ...next, centerX: at.x - (px - view.width / 2) / k, centerY: at.y + (py - view.height / 2) / k });
201
+ }
202
+ /**
203
+ * Distances worth a ring on the map, in astronomical units: the Earth's (1), Jupiter's (5), Saturn's (10), Neptune's (30) and 100.
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * import { SYSTEM_RINGS } from "@johnmorrisdotca/wakusei-planets/flat/system";
208
+ *
209
+ * console.log(SYSTEM_RINGS.join(" "));
210
+ * ```
211
+ */
212
+ export const SYSTEM_RINGS = [1, 5, 10, 30, 100, 500];
213
+ /** The colour each planet is drawn in: artistic, chosen to tell them apart on a dark map. */
214
+ const PLANET_COLOURS = { mercury: "#b8b2a8", venus: "#efd9a7", earth: "#4fa3ff", mars: "#ee6a4b", jupiter: "#e0a96d", saturn: "#ead591", uranus: "#8fe8ec", neptune: "#6b86ff", pluto: "#cdb8a6" };
215
+ /** The craft's colours, in the package's order of craft. */
216
+ const CRAFT_COLOURS = ["#ffd23f", "#4cc9f0", "#6ee7a0", "#a78bfa", "#ff9ecb", "#f4a261", "#b8e986", "#5eead4", "#7aa2ff", "#e879f9", "#fde68a"];
217
+ /**
218
+ * The colour of a mark: a planet's own, a pale grey for the dwarf planets and small bodies, ice blue for a comet and one of a set for each craft; the Tesla Roadster is red.
219
+ *
220
+ * @param id - A planet, dwarf planet, small body, comet or craft id, or `sun`.
221
+ * @param layer - Its layer.
222
+ * @returns A CSS colour.
223
+ *
224
+ * @example
225
+ * ```ts
226
+ * import { systemColour } from "@johnmorrisdotca/wakusei-planets/flat/system";
227
+ *
228
+ * console.log(systemColour("earth", "planets"), systemColour("roadster", "craft"));
229
+ * ```
230
+ */
231
+ export function systemColour(id, layer) {
232
+ if (layer === "sun")
233
+ return "#ffd54f";
234
+ if (layer === "planets")
235
+ return PLANET_COLOURS[id] ?? "#ffffff";
236
+ if (layer === "dwarfs")
237
+ return "#cfd6e0";
238
+ if (layer === "comets")
239
+ return "#9ee6ff";
240
+ if (layer === "belts")
241
+ return "#d9d3c3";
242
+ if (id === "roadster")
243
+ return "#ff3b30";
244
+ const at = SPACECRAFT_IDS.indexOf(id);
245
+ return CRAFT_COLOURS[(at < 0 ? 0 : at) % CRAFT_COLOURS.length];
246
+ }
247
+ /** The names of the minor bodies the map draws as dwarfs-layer marks: Halley is a comet here. */
248
+ const SMALL_BODIES = MINOR_IDS.filter((id) => id !== "halley");
249
+ /** The ids of the planets and of the dwarf layer, in order. */
250
+ const PLANETS = PLANET_IDS;
251
+ const DWARFS = [...DWARF_IDS, ...SMALL_BODIES];
252
+ /**
253
+ * The ids the dwarfs layer draws: the dwarf planets, then Vesta, Pallas, Chiron and Pholus (Halley is among the comets).
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * import { SYSTEM_DWARFS } from "@johnmorrisdotca/wakusei-planets/flat/system";
258
+ *
259
+ * console.log(SYSTEM_DWARFS.join(", "));
260
+ * ```
261
+ */
262
+ export const SYSTEM_DWARFS = DWARFS;
263
+ /**
264
+ * The craft's place at a moment in astronomical units, or `undefined` while its path is not loaded (`loadSpacecraft`) or the moment is outside the record of its path (a craft that has not launched, or whose record has ended).
265
+ *
266
+ * @param id - The craft.
267
+ * @param ms - Milliseconds since 1970 (UTC).
268
+ * @returns The place, or `undefined`.
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * import { loadSpacecraft } from "@johnmorrisdotca/wakusei-planets/spacecraft";
273
+ * import { craftAu } from "@johnmorrisdotca/wakusei-planets/flat/system";
274
+ *
275
+ * await loadSpacecraft("roadster");
276
+ * const car = craftAu("roadster", Date.UTC(2026, 10, 17));
277
+ * console.log(car === undefined ? "not loaded" : Math.hypot(car[0], car[1]).toFixed(1), "au from the Sun");
278
+ * ```
279
+ */
280
+ export function craftAu(id, ms) {
281
+ if (!SPACECRAFT_IDS.includes(id))
282
+ return undefined;
283
+ const craft = SPACECRAFT[id];
284
+ // the Roadster's record is filled in when its path is loaded: 0 until then
285
+ if (craft.record.end === 0 || ms < craft.record.start || ms > craft.record.end)
286
+ return undefined;
287
+ try {
288
+ const p = spacecraftPosition(id, ms);
289
+ return [p[0] / AU_KM, p[1] / AU_KM, p[2] / AU_KM];
290
+ }
291
+ catch {
292
+ return undefined;
293
+ }
294
+ }
295
+ /** A comet's place, or undefined where two-body motion has none. */
296
+ function cometAu(record, ms) {
297
+ try {
298
+ return cometPosition(record, ms);
299
+ }
300
+ catch {
301
+ return undefined;
302
+ }
303
+ }
304
+ /** The places of the planets and of the dwarf layer, in au. */
305
+ function bodyAu(id, ms) {
306
+ return heliocentric(id, ms);
307
+ }
308
+ /**
309
+ * The name of a thing on the map in a language: the Sun, a planet, a dwarf planet or small body, a comet or a craft. The Tesla Roadster is called by its car's name (the mannequin is Starman, in the facts).
310
+ *
311
+ * @param id - The thing's id.
312
+ * @param lang - `en` or `ja`.
313
+ * @returns The name, or the id where there is none.
314
+ *
315
+ * @example
316
+ * ```ts
317
+ * import { systemName } from "@johnmorrisdotca/wakusei-planets/flat/system";
318
+ *
319
+ * console.log(systemName("roadster", "en"), "|", systemName("roadster", "ja"), "|", systemName("halley", "ja"));
320
+ * ```
321
+ */
322
+ export function systemName(id, lang) {
323
+ if (id === "roadster")
324
+ return lang === "ja" ? "テスラ・ロードスター" : "Tesla Roadster";
325
+ if (SPACECRAFT_IDS.includes(id))
326
+ return SPACECRAFT[id].name[lang];
327
+ const comet = listComets().find((one) => one.id === id);
328
+ if (comet)
329
+ return comet.name[lang];
330
+ const body = BODIES[id];
331
+ return body ? body.name[lang] : id;
332
+ }
333
+ /**
334
+ * What every drawn thing is at a moment, with its place on the disc. The planets come from VSOP87B and the fitted tables, the dwarf planets and small bodies from their fitted tables or one epoch's elements, the comets by two-body motion on JPL's elements,
335
+ * and the craft from the Horizons paths, which must be loaded first (`loadSpacecraft`); a craft with no path at that moment is left out. A thing further out than the reach is marked `beyond` and not worth drawing.
336
+ *
337
+ * @param ms - Milliseconds since 1970 (UTC).
338
+ * @param options - The layers, the craft and comets wanted, the reach and the spacing.
339
+ * @returns The Sun first, then the planets, dwarfs, comets and craft.
340
+ *
341
+ * @example
342
+ * ```ts
343
+ * import { systemMarks } from "@johnmorrisdotca/wakusei-planets/flat/system";
344
+ *
345
+ * const marks = systemMarks(Date.UTC(2026, 10, 17), { layers: ["planets", "comets"] });
346
+ * const earth = marks.find((m) => m.id === "earth")!;
347
+ * console.log(marks.length, Math.round((Math.atan2(earth.au[1], earth.au[0]) * 180) / Math.PI), "degrees of ecliptic longitude");
348
+ * ```
349
+ */
350
+ export function systemMarks(ms, options = {}) {
351
+ const layers = new Set(options.layers ?? SYSTEM_LAYERS.filter((one) => one !== "belts"));
352
+ const spacing = options.spacing === "true" ? "true" : "squeezed";
353
+ const raw = [];
354
+ if (layers.has("planets"))
355
+ for (const id of PLANETS)
356
+ raw.push({ id, layer: "planets", kind: "planet", au: bodyAu(id, ms) });
357
+ if (layers.has("dwarfs"))
358
+ for (const id of DWARFS)
359
+ raw.push({ id, layer: "dwarfs", kind: id === "chiron" || id === "pholus" ? "centaur" : id === "vesta" || id === "pallas" ? "asteroid" : "dwarf-planet", au: bodyAu(id, ms) });
360
+ if (layers.has("comets")) {
361
+ const wanted = options.comets;
362
+ for (const record of listComets()) {
363
+ if (wanted !== undefined && !wanted.includes(record.id))
364
+ continue;
365
+ const au = cometAu(record, ms);
366
+ if (au !== undefined)
367
+ raw.push({ id: record.id, layer: "comets", kind: "comet", au });
368
+ }
369
+ }
370
+ if (layers.has("craft")) {
371
+ const wanted = options.craft;
372
+ for (const id of SPACECRAFT_IDS) {
373
+ if (wanted !== undefined && !wanted.includes(id))
374
+ continue;
375
+ const au = craftAu(id, ms);
376
+ if (au !== undefined)
377
+ raw.push({ id, layer: "craft", kind: "spacecraft", au });
378
+ }
379
+ }
380
+ // the reach holds the planets, the dwarf planets and the craft drawn; comets and belts further out than it are left off
381
+ const farthest = Math.max(0, ...raw.filter((one) => one.layer !== "comets").map((one) => Math.hypot(one.au[0], one.au[1])));
382
+ const extent = systemExtent(farthest, options.extent);
383
+ const place = (one) => {
384
+ const at = squeezeAu(one.au[0], one.au[1], extent, spacing);
385
+ return { ...one, planeAu: Math.hypot(one.au[0], one.au[1]), distanceAu: Math.hypot(one.au[0], one.au[1], one.au[2]), x: at.x, y: at.y, beyond: at.r > 1 };
386
+ };
387
+ const sun = { id: "sun", layer: "sun", kind: "star", au: [0, 0, 0], planeAu: 0, distanceAu: 0, x: 0, y: 0, beyond: false };
388
+ return [sun, ...raw.map(place)];
389
+ }
390
+ /**
391
+ * The reach the map stands at for what is drawn: what `systemMarks` used. Worked out the same way, from the planets, the dwarf planets and the craft shown, so the map's scale can be had without placing the marks again.
392
+ *
393
+ * @param marks - The marks from `systemMarks`.
394
+ * @param fixed - A reach the page asked for, in au.
395
+ * @returns The distance at the edge, in au.
396
+ *
397
+ * @example
398
+ * ```ts
399
+ * import { systemMarks, systemReach } from "@johnmorrisdotca/wakusei-planets/flat/system";
400
+ *
401
+ * console.log(systemReach(systemMarks(Date.UTC(2026, 10, 17), { layers: ["planets"] })));
402
+ * ```
403
+ */
404
+ export const systemReach = (marks, fixed) => systemExtent(Math.max(0, ...marks.filter((one) => one.layer !== "comets").map((one) => one.planeAu)), fixed);
405
+ /**
406
+ * Where the bodies of the belts are at a moment, in au in the ecliptic plane: two numbers a body, the Kepler orbit of each one's elements (`beltPositions` without the height, which a view from above does not use).
407
+ *
408
+ * @param bodies - The belt bodies, from `loadBeltBodies`.
409
+ * @param ms - Milliseconds since 1970 (UTC).
410
+ * @param out - A list of `2 * bodies.length` numbers to fill in; made when left out.
411
+ * @returns The list.
412
+ *
413
+ * @example
414
+ * ```ts
415
+ * import { systemBelts } from "@johnmorrisdotca/wakusei-planets/flat/system";
416
+ *
417
+ * const body = { name: "T", a: 2.7, e: 0, i: 0, node: 0, peri: 0, M0: 0, epoch: 2461200.5, H: 9 };
418
+ * console.log(systemBelts([body], Date.UTC(2026, 10, 17))[0]?.toFixed(2));
419
+ * ```
420
+ */
421
+ export function systemBelts(bodies, ms, out = new Float32Array(bodies.length * 2)) {
422
+ const jd = toJulianDate(ms);
423
+ for (let k = 0; k < bodies.length; k += 1) {
424
+ const p = smallBodyAt(bodies[k], jd);
425
+ out[k * 2] = p[0];
426
+ out[k * 2 + 1] = p[1];
427
+ }
428
+ return out;
429
+ }
430
+ const orbitCache = new Map();
431
+ const YEAR = 365.25 * DAY;
432
+ /**
433
+ * The orbit line of a planet, dwarf planet or small body, as points in the ecliptic plane in au: one trip round the Sun from the start of the year the moment is in (a planet's path changes by less than a pixel in a year), kept for that year.
434
+ *
435
+ * @param id - A planet, dwarf planet or small body of the map.
436
+ * @param ms - Milliseconds since 1970 (UTC).
437
+ * @param points - How many steps round it.
438
+ * @returns The points; the last is the first again.
439
+ *
440
+ * @example
441
+ * ```ts
442
+ * import { systemOrbit } from "@johnmorrisdotca/wakusei-planets/flat/system";
443
+ *
444
+ * const line = systemOrbit("earth", Date.UTC(2026, 10, 17));
445
+ * console.log(line.length, Math.hypot(...line[0]!).toFixed(2));
446
+ * ```
447
+ */
448
+ export function systemOrbit(id, ms, points = 96) {
449
+ const bucket = Math.floor(ms / YEAR);
450
+ const key = `${id}|${bucket}|${points}`;
451
+ let found = orbitCache.get(key);
452
+ if (found === undefined) {
453
+ if (orbitCache.size > 300)
454
+ orbitCache.clear();
455
+ // `planetOrbit` answers in the scene's axes (J2000 equatorial, y north): back to the equatorial axes, then the ecliptic
456
+ found = planetOrbit(id, bucket * YEAR, points).map((p) => {
457
+ const e = toEcliptic([p[0], -p[2], p[1]]);
458
+ return [e[0], e[1]];
459
+ });
460
+ orbitCache.set(key, found);
461
+ }
462
+ return found;
463
+ }
464
+ /**
465
+ * A comet's orbit line as points in the ecliptic plane in au, as far out as the reach.
466
+ *
467
+ * @param id - The comet's id.
468
+ * @param reach - The furthest distance to draw, in au.
469
+ * @returns The points.
470
+ *
471
+ * @example
472
+ * ```ts
473
+ * import { systemCometOrbit } from "@johnmorrisdotca/wakusei-planets/flat/system";
474
+ *
475
+ * console.log(systemCometOrbit("halley", 50).length > 20);
476
+ * ```
477
+ */
478
+ export function systemCometOrbit(id, reach) {
479
+ const record = listComets().find((one) => one.id === id);
480
+ if (record === undefined || !(reach > record.q))
481
+ return [];
482
+ const flat = cometOrbit(record, 120, reach);
483
+ const out = [];
484
+ for (let k = 0; k + 2 < flat.length; k += 3)
485
+ out.push([flat[k], flat[k + 1]]);
486
+ return out;
487
+ }
488
+ /**
489
+ * A craft's whole path as points in the ecliptic plane, `count` steps over its record, each with its moment: what the map draws as the craft's track, the part behind the moment dashed and the part ahead solid. `[]` while the path is not loaded.
490
+ *
491
+ * @param id - The craft.
492
+ * @param count - How many steps (from 2).
493
+ * @returns Points with their moments in milliseconds since 1970.
494
+ *
495
+ * @example
496
+ * ```ts
497
+ * import { loadSpacecraft } from "@johnmorrisdotca/wakusei-planets/spacecraft";
498
+ * import { craftPath } from "@johnmorrisdotca/wakusei-planets/flat/system";
499
+ *
500
+ * await loadSpacecraft("roadster");
501
+ * const path = craftPath("roadster", 100);
502
+ * console.log(path.length, new Date(path[0]!.ms).getUTCFullYear(), new Date(path[path.length - 1]!.ms).getUTCFullYear());
503
+ * ```
504
+ */
505
+ export function craftPath(id, count = 300) {
506
+ if (!SPACECRAFT_IDS.includes(id))
507
+ return [];
508
+ const { start, end } = SPACECRAFT[id].record;
509
+ if (end === 0)
510
+ return [];
511
+ const out = [];
512
+ const n = Math.max(2, Math.floor(count));
513
+ for (let k = 0; k <= n; k += 1) {
514
+ const ms = start + ((end - start) * k) / n;
515
+ const p = craftAu(id, ms);
516
+ if (p !== undefined)
517
+ out.push({ x: p[0], y: p[1], ms });
518
+ }
519
+ return out;
520
+ }
521
+ export { SYSTEM_WORDS, saySystem } from "./system-words.js";
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The two languages the flat map's words come in.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { FLAT_WORDS, type FlatLang } from "@johnmorrisdotca/wakusei-planets/flat";
7
+ *
8
+ * const lang: FlatLang = "ja";
9
+ * console.log(FLAT_WORDS[lang].zoomIn);
10
+ * ```
11
+ */
12
+ export type FlatLang = "en" | "ja";
13
+ /**
14
+ * The words the flat map writes, one table for each language: `{body}`, `{name}`, `{altitude}` and the like are filled in. The Japanese is standard, polite Japanese.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { FLAT_WORDS } from "@johnmorrisdotca/wakusei-planets/flat";
19
+ *
20
+ * console.log(FLAT_WORDS.en.footprint, FLAT_WORDS.ja.footprint);
21
+ * ```
22
+ */
23
+ export declare const FLAT_WORDS: Readonly<Record<FlatLang, Readonly<Record<string, string>>>>;
24
+ /**
25
+ * The words with their `{name}` places filled in; a key a language does not have is said in English, and a key neither has comes back as it is.
26
+ *
27
+ * @param lang - `en` or `ja`.
28
+ * @param key - A key of `FLAT_WORDS`.
29
+ * @param values - What goes in the `{...}` places.
30
+ * @returns The sentence.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { say } from "@johnmorrisdotca/wakusei-planets/flat";
35
+ *
36
+ * console.log(say("en", "map", { body: "Mars" }), "|", say("ja", "map", { body: "火星" }));
37
+ * ```
38
+ */
39
+ export declare const say: (lang: FlatLang, key: string, values?: Record<string, string | number>) => string;
40
+ /**
41
+ * A latitude or longitude with its hemisphere, in the language's way: `3.01° S` and `23.47° E`, or `南緯3.01°` and `東経23.47°`.
42
+ *
43
+ * @param lang - `en` or `ja`.
44
+ * @param axis - `lat` or `lon`.
45
+ * @param degrees - Degrees, north and east positive.
46
+ * @returns The text.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * import { coordinateText } from "@johnmorrisdotca/wakusei-planets/flat";
51
+ *
52
+ * console.log(coordinateText("en", "lat", -3.01), "|", coordinateText("ja", "lon", 23.47));
53
+ * ```
54
+ */
55
+ export declare function coordinateText(lang: FlatLang, axis: "lat" | "lon", degrees: number): string;