@johnmorrisdotca/wakusei-planets 0.28.0 → 0.31.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 (56) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/NOTICE.md +20 -0
  3. package/README.md +61 -16
  4. package/dist/embed.d.ts +64 -0
  5. package/dist/embed.js +66 -0
  6. package/dist/index.d.ts +4 -1
  7. package/dist/index.js +4 -1
  8. package/dist/lineup/data.d.ts +160 -0
  9. package/dist/lineup/data.js +303 -0
  10. package/dist/lineup/element.d.ts +99 -0
  11. package/dist/lineup/element.js +782 -0
  12. package/dist/lineup/labels.d.ts +141 -0
  13. package/dist/lineup/labels.js +155 -0
  14. package/dist/lineup/layout.d.ts +174 -0
  15. package/dist/lineup/layout.js +162 -0
  16. package/dist/lineup/scene3d.d.ts +47 -0
  17. package/dist/lineup/scene3d.js +155 -0
  18. package/dist/portrait/element.d.ts +5 -2
  19. package/dist/portrait/element.js +57 -6
  20. package/dist/portrait/scene3d.d.ts +13 -0
  21. package/dist/portrait/scene3d.js +21 -2
  22. package/dist/scene/body.d.ts +3 -1
  23. package/dist/scene/body.js +2 -1
  24. package/dist/scene/detail.d.ts +8 -2
  25. package/dist/scene/detail.js +56 -28
  26. package/dist/scene/painter.d.ts +32 -0
  27. package/dist/scene/painter.js +94 -10
  28. package/dist/scene/textures.d.ts +4 -2
  29. package/dist/scene/textures.js +2 -0
  30. package/dist/scene/tiles.d.ts +46 -0
  31. package/dist/scene/tiles.js +165 -19
  32. package/dist/space/arrows.d.ts +87 -0
  33. package/dist/space/arrows.js +117 -0
  34. package/dist/space/beside.d.ts +74 -0
  35. package/dist/space/beside.js +76 -0
  36. package/dist/space/bodies.d.ts +83 -0
  37. package/dist/space/bodies.js +93 -0
  38. package/dist/space/clock.d.ts +31 -0
  39. package/dist/space/clock.js +45 -0
  40. package/dist/space/element.d.ts +98 -15
  41. package/dist/space/element.js +320 -63
  42. package/dist/space/frame.d.ts +45 -2
  43. package/dist/space/frame.js +56 -4
  44. package/dist/space/index.d.ts +6 -1
  45. package/dist/space/index.js +6 -1
  46. package/dist/space/labels.d.ts +52 -0
  47. package/dist/space/labels.js +40 -0
  48. package/dist/space/scale.d.ts +5 -5
  49. package/dist/space/scale.js +10 -4
  50. package/dist/space/scene.d.ts +50 -9
  51. package/dist/space/scene.js +313 -36
  52. package/dist/space/spin.d.ts +37 -0
  53. package/dist/space/spin.js +29 -0
  54. package/dist/version.d.ts +1 -1
  55. package/dist/version.js +1 -1
  56. package/package.json +8 -1
@@ -1,3 +1,4 @@
1
+ import { type DwarfId } from "../facts.ts";
1
2
  import { type Vec3 } from "../vec.ts";
2
3
  /**
3
4
  * A position or direction as `[x, y, z]` in the scene's axes: J2000 equatorial, x to the vernal equinox, y north.
@@ -44,6 +45,29 @@ export declare const AU_IN_EARTH_RADII: number;
44
45
  * ```
45
46
  */
46
47
  export declare const SPACE_PLANETS: readonly ["mercury", "venus", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"];
48
+ /**
49
+ * The dwarf planets besides Pluto that the space view places: Ceres, Orcus, Haumea, Quaoar, Makemake, Gonggong, Eris and Sedna.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { SPACE_DWARFS } from "@johnmorrisdotca/wakusei-planets/space";
54
+ *
55
+ * console.log(SPACE_DWARFS.join(", "));
56
+ * ```
57
+ */
58
+ export declare const SPACE_DWARFS: readonly ["ceres", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris", "sedna"];
59
+ /**
60
+ * One of the dwarf planets in `SPACE_DWARFS`.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * import { planetOrbit, type SpaceDwarf } from "@johnmorrisdotca/wakusei-planets/space";
65
+ *
66
+ * const dwarf: SpaceDwarf = "eris";
67
+ * console.log(planetOrbit(dwarf, Date.UTC(2026, 10, 2), 8).length);
68
+ * ```
69
+ */
70
+ export type SpaceDwarf = DwarfId;
47
71
  /**
48
72
  * One of the planets in `SPACE_PLANETS`.
49
73
  *
@@ -72,6 +96,8 @@ export interface SpaceFrame {
72
96
  sun: Vec3;
73
97
  moon: Vec3;
74
98
  planets: Record<SpacePlanet, Vec3>;
99
+ /** The dwarf planets besides Pluto, from their osculating elements (good for a few years either side of 2026). */
100
+ dwarfs: Record<SpaceDwarf, Vec3>;
75
101
  }
76
102
  /**
77
103
  * The state of the sky at `ms`: the Sun, the Moon and eight planets as seen from the Earth's centre, worked out by this package's own models in a fraction of a millisecond.
@@ -136,7 +162,7 @@ export declare function createTrack(initialStepMs?: number): {
136
162
  /**
137
163
  * The path a planet or the Earth takes round the Sun, as `count + 1` points round one trip from where the planet is at `ms`, from the Sun, in astronomical units and the scene's axes.
138
164
  *
139
- * @param id - The planet or `earth`.
165
+ * @param id - The planet, the dwarf planet or `earth`.
140
166
  * @param ms - The moment the path starts at, in milliseconds since the Unix epoch.
141
167
  * @param count - How many segments to cut the trip into.
142
168
  * @returns `count + 1` points; the last is near the first.
@@ -149,4 +175,21 @@ export declare function createTrack(initialStepMs?: number): {
149
175
  * console.log(points.length);
150
176
  * ```
151
177
  */
152
- export declare function planetOrbit(id: SpacePlanet | "earth", ms: number, count?: number): Vec3[];
178
+ export declare function planetOrbit(id: SpacePlanet | SpaceDwarf | "earth", ms: number, count?: number): Vec3[];
179
+ /**
180
+ * The path the Moon takes round the Earth, as `count + 1` points round one sidereal month from where the Moon is at `ms`, from the Earth's centre, in astronomical units and the scene's axes. The first
181
+ * point is the Moon's own place at `ms` and the last is the first again, so the line is closed and passes through the Moon.
182
+ *
183
+ * @param ms - The moment the path starts at, in milliseconds since the Unix epoch.
184
+ * @param count - How many segments to cut the month into.
185
+ * @returns `count + 1` points; the last is the first.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * import { moonOrbit } from "@johnmorrisdotca/wakusei-planets/space";
190
+ *
191
+ * const ring = moonOrbit(Date.UTC(2026, 10, 2), 48);
192
+ * console.log(ring.length, Math.hypot(...ring[0]!).toFixed(4));
193
+ * ```
194
+ */
195
+ export declare function moonOrbit(ms: number, count?: number): Vec3[];
@@ -1,6 +1,8 @@
1
1
  // Where the Sun, the Moon and the planets are, as seen from the centre of the Earth, for any date, from this package's own models (VSOP87B planets, the Pluto table, ELP2000 Moon).
2
2
  // Positions are geometric (no aberration or nutation, about 20 arc-seconds), in the painter's axes: J2000 equatorial, x to the vernal equinox, y north. Pure: no DOM, no three.js.
3
3
  import { heliocentric, moonGeocentric } from "../ephemeris.js";
4
+ import { DWARF_IDS } from "../facts.js";
5
+ import { DWARF_ELEMENTS } from "../data/dwarf.js";
4
6
  import { OBLIQUITY, RAD } from "../vec.js";
5
7
  import { earthPosition } from "../theory.js";
6
8
  import { DAY_MS } from "../clock.js";
@@ -39,6 +41,17 @@ export const AU_IN_EARTH_RADII = AU_KM / EARTH_RADIUS_KM;
39
41
  * ```
40
42
  */
41
43
  export const SPACE_PLANETS = ["mercury", "venus", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"];
44
+ /**
45
+ * The dwarf planets besides Pluto that the space view places: Ceres, Orcus, Haumea, Quaoar, Makemake, Gonggong, Eris and Sedna.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { SPACE_DWARFS } from "@johnmorrisdotca/wakusei-planets/space";
50
+ *
51
+ * console.log(SPACE_DWARFS.join(", "));
52
+ * ```
53
+ */
54
+ export const SPACE_DWARFS = DWARF_IDS;
42
55
  /** An ecliptic J2000 vector in the scene's axes (equatorial J2000, y north). */
43
56
  const scene = (v) => {
44
57
  const c = Math.cos(OBLIQUITY * RAD);
@@ -66,8 +79,13 @@ export function frameAt(ms) {
66
79
  const h = heliocentric(id, ms);
67
80
  planets[id] = scene([h[0] - earth[0], h[1] - earth[1], h[2] - earth[2]]);
68
81
  }
82
+ const dwarfs = {};
83
+ for (const id of SPACE_DWARFS) {
84
+ const h = heliocentric(id, ms);
85
+ dwarfs[id] = scene([h[0] - earth[0], h[1] - earth[1], h[2] - earth[2]]);
86
+ }
69
87
  const moon = moonGeocentric(ms);
70
- return { ms, sun: scene([-earth[0], -earth[1], -earth[2]]), moon: scene([moon[0] / AU_KM, moon[1] / AU_KM, moon[2] / AU_KM]), planets };
88
+ return { ms, sun: scene([-earth[0], -earth[1], -earth[2]]), moon: scene([moon[0] / AU_KM, moon[1] / AU_KM, moon[2] / AU_KM]), planets, dwarfs };
71
89
  }
72
90
  const lerp3 = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
73
91
  /**
@@ -91,7 +109,10 @@ export function blend(a, b, t) {
91
109
  const planets = {};
92
110
  for (const id of SPACE_PLANETS)
93
111
  planets[id] = lerp3(a.planets[id], b.planets[id], t);
94
- return { ms: a.ms + (b.ms - a.ms) * t, sun: lerp3(a.sun, b.sun, t), moon: lerp3(a.moon, b.moon, t), planets };
112
+ const dwarfs = {};
113
+ for (const id of SPACE_DWARFS)
114
+ dwarfs[id] = lerp3(a.dwarfs[id], b.dwarfs[id], t);
115
+ return { ms: a.ms + (b.ms - a.ms) * t, sun: lerp3(a.sun, b.sun, t), moon: lerp3(a.moon, b.moon, t), planets, dwarfs };
95
116
  }
96
117
  /**
97
118
  * Answers for any moment from two real ones: `at(ms)` works out a frame only when `ms` leaves the span the last two answers cover, and then looks `stepMs` ahead, so playing
@@ -144,11 +165,15 @@ export function createTrack(initialStepMs = 1000) {
144
165
  },
145
166
  };
146
167
  }
147
- const PERIOD_DAYS = { mercury: 87.97, venus: 224.7, earth: 365.256, mars: 686.98, jupiter: 4332.6, saturn: 10_759, uranus: 30_688, neptune: 60_182, pluto: 90_560 };
168
+ const PERIOD_DAYS = {
169
+ mercury: 87.97, venus: 224.7, earth: 365.256, mars: 686.98, jupiter: 4332.6, saturn: 10_759, uranus: 30_688, neptune: 60_182, pluto: 90_560,
170
+ // a dwarf planet's own: a full turn of its mean motion
171
+ ...Object.fromEntries(SPACE_DWARFS.map((id) => [id, 360 / DWARF_ELEMENTS[id].n])),
172
+ };
148
173
  /**
149
174
  * The path a planet or the Earth takes round the Sun, as `count + 1` points round one trip from where the planet is at `ms`, from the Sun, in astronomical units and the scene's axes.
150
175
  *
151
- * @param id - The planet or `earth`.
176
+ * @param id - The planet, the dwarf planet or `earth`.
152
177
  * @param ms - The moment the path starts at, in milliseconds since the Unix epoch.
153
178
  * @param count - How many segments to cut the trip into.
154
179
  * @returns `count + 1` points; the last is near the first.
@@ -167,3 +192,30 @@ export function planetOrbit(id, ms, count = 96) {
167
192
  points.push(scene(heliocentric(id, ms + (i / count) * PERIOD_DAYS[id] * DAY_MS)));
168
193
  return points;
169
194
  }
195
+ /** The Moon's sidereal month, in days: the time it takes to go once round the Earth against the stars. */
196
+ const MOON_MONTH_DAYS = 27.321661;
197
+ /**
198
+ * The path the Moon takes round the Earth, as `count + 1` points round one sidereal month from where the Moon is at `ms`, from the Earth's centre, in astronomical units and the scene's axes. The first
199
+ * point is the Moon's own place at `ms` and the last is the first again, so the line is closed and passes through the Moon.
200
+ *
201
+ * @param ms - The moment the path starts at, in milliseconds since the Unix epoch.
202
+ * @param count - How many segments to cut the month into.
203
+ * @returns `count + 1` points; the last is the first.
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * import { moonOrbit } from "@johnmorrisdotca/wakusei-planets/space";
208
+ *
209
+ * const ring = moonOrbit(Date.UTC(2026, 10, 2), 48);
210
+ * console.log(ring.length, Math.hypot(...ring[0]!).toFixed(4));
211
+ * ```
212
+ */
213
+ export function moonOrbit(ms, count = 96) {
214
+ const points = [];
215
+ for (let i = 0; i < count; i += 1) {
216
+ const m = moonGeocentric(ms + (i / count) * MOON_MONTH_DAYS * DAY_MS);
217
+ points.push(scene([m[0] / AU_KM, m[1] / AU_KM, m[2] / AU_KM]));
218
+ }
219
+ points.push(points[0]);
220
+ return points;
221
+ }
@@ -1,4 +1,9 @@
1
- export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, planetOrbit, SPACE_PLANETS, type SpaceFrame, type SpacePlanet, type SpaceVec3 } from "./frame.ts";
1
+ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_PLANETS, type SpaceDwarf, type SpaceFrame, type SpacePlanet, type SpaceVec3 } from "./frame.ts";
2
2
  export { compress, MOON_COMPRESSED, moonDistance, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
3
3
  export { groundDirection } from "./aim.ts";
4
4
  export { RIDE_FOV, ridePose, type RideInput, type RideLook, type RidePose } from "./ride.ts";
5
+ export { chooseLabels, LABEL_GAP, type LabelBox } from "./labels.ts";
6
+ export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, type SpaceKind } from "./bodies.ts";
7
+ export { besideMoon, BESIDE_RADII, type BesideCamera, type BesideInput } from "./beside.ts";
8
+ export { ARROWS_PER_ORBIT, arrowSites, chevron, spinArrow, type OrbitArrow } from "./arrows.ts";
9
+ export { spinAxis, type SpinAxis } from "./spin.ts";
@@ -1,5 +1,10 @@
1
1
  // The space view's pure parts: where the bodies are (this package's own models), the two scales and, for riding along, where a camera looks. They import on a server. The element is `@johnmorrisdotca/wakusei-planets/space/element`.
2
- export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, planetOrbit, SPACE_PLANETS } from "./frame.js";
2
+ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_PLANETS } from "./frame.js";
3
3
  export { compress, MOON_COMPRESSED, moonDistance, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition } from "./scale.js";
4
4
  export { groundDirection } from "./aim.js";
5
5
  export { RIDE_FOV, ridePose } from "./ride.js";
6
+ export { chooseLabels, LABEL_GAP } from "./labels.js";
7
+ export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf } from "./bodies.js";
8
+ export { besideMoon, BESIDE_RADII } from "./beside.js";
9
+ export { ARROWS_PER_ORBIT, arrowSites, chevron, spinArrow } from "./arrows.js";
10
+ export { spinAxis } from "./spin.js";
@@ -0,0 +1,52 @@
1
+ /**
2
+ * A name waiting for a place: its box on the screen in CSS pixels and how sure its place is (lower is surer).
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import type { LabelBox } from "@johnmorrisdotca/wakusei-planets/space";
7
+ *
8
+ * const box: LabelBox = { id: "mars", x: 120, y: 80, width: 44, height: 16, rank: 2, size: 6 };
9
+ * console.log(box.id, box.rank);
10
+ * ```
11
+ */
12
+ export interface LabelBox {
13
+ id: string;
14
+ x: number;
15
+ y: number;
16
+ width: number;
17
+ height: number;
18
+ /** 0 is the surest: the body looked at, then the Sun, a planet, a dwarf planet, a moon. */
19
+ rank: number;
20
+ /** Breaks a tie of rank: the bigger body on the screen wins. */
21
+ size: number;
22
+ }
23
+ /**
24
+ * The room kept between two names, in CSS pixels, so they never touch.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { LABEL_GAP } from "@johnmorrisdotca/wakusei-planets/space";
29
+ *
30
+ * console.log(LABEL_GAP);
31
+ * ```
32
+ */
33
+ export declare const LABEL_GAP = 3;
34
+ /**
35
+ * The names to show from those that want a place: the surest first, and each kept only if it does not touch one already kept. A moon gives way to its planet and a planet to the Sun, because their ranks say so.
36
+ *
37
+ * @param boxes - The names with their boxes and ranks.
38
+ * @param gap - The room to keep between two names, in CSS pixels.
39
+ * @returns The ids to show.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import { chooseLabels } from "@johnmorrisdotca/wakusei-planets/space";
44
+ *
45
+ * const shown = chooseLabels([
46
+ * { id: "earth", x: 10, y: 10, width: 40, height: 16, rank: 1, size: 20 },
47
+ * { id: "moon", x: 30, y: 12, width: 40, height: 16, rank: 3, size: 5 },
48
+ * ]);
49
+ * console.log([...shown]);
50
+ * ```
51
+ */
52
+ export declare function chooseLabels(boxes: readonly LabelBox[], gap?: number): Set<string>;
@@ -0,0 +1,40 @@
1
+ // Which names of the space view are shown: no two overlap. The nearer to the middle of things a body is in rank (the Sun, then a planet, then a dwarf planet, then a moon), the surer its name; a name that would cover
2
+ // a stronger one is left out. Pure: boxes in, the ids shown out.
3
+ /**
4
+ * The room kept between two names, in CSS pixels, so they never touch.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { LABEL_GAP } from "@johnmorrisdotca/wakusei-planets/space";
9
+ *
10
+ * console.log(LABEL_GAP);
11
+ * ```
12
+ */
13
+ export const LABEL_GAP = 3;
14
+ const crosses = (a, b, gap) => a.x < b.x + b.width + gap && b.x < a.x + a.width + gap && a.y < b.y + b.height + gap && b.y < a.y + a.height + gap;
15
+ /**
16
+ * The names to show from those that want a place: the surest first, and each kept only if it does not touch one already kept. A moon gives way to its planet and a planet to the Sun, because their ranks say so.
17
+ *
18
+ * @param boxes - The names with their boxes and ranks.
19
+ * @param gap - The room to keep between two names, in CSS pixels.
20
+ * @returns The ids to show.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { chooseLabels } from "@johnmorrisdotca/wakusei-planets/space";
25
+ *
26
+ * const shown = chooseLabels([
27
+ * { id: "earth", x: 10, y: 10, width: 40, height: 16, rank: 1, size: 20 },
28
+ * { id: "moon", x: 30, y: 12, width: 40, height: 16, rank: 3, size: 5 },
29
+ * ]);
30
+ * console.log([...shown]);
31
+ * ```
32
+ */
33
+ export function chooseLabels(boxes, gap = LABEL_GAP) {
34
+ const order = [...boxes].sort((a, b) => a.rank - b.rank || b.size - a.size || (a.id < b.id ? -1 : 1));
35
+ const kept = [];
36
+ for (const box of order)
37
+ if (!kept.some((other) => crosses(box, other, gap)))
38
+ kept.push(box);
39
+ return new Set(kept.map((box) => box.id));
40
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Vec3 } from "../vec.ts";
2
- import { type SpaceFrame, type SpacePlanet } from "./frame.ts";
2
+ import { type SpaceDwarf, type SpaceFrame, type SpacePlanet } from "./frame.ts";
3
3
  /**
4
4
  * The scale the space view is drawn in: `compressed` squeezes the distances so the Moon, the Sun and Neptune fit one view, and `true` keeps the real ones.
5
5
  *
@@ -109,11 +109,11 @@ export declare function placeSun(mode: ScaleMode, geo: Vec3): Vec3;
109
109
  * ```
110
110
  */
111
111
  export declare function placeAround(mode: ScaleMode, sun: Vec3, helio: Vec3): Vec3;
112
- type BaseBody = "sun" | "earth" | "moon" | SpacePlanet;
112
+ type BaseBody = "sun" | "earth" | "moon" | SpacePlanet | SpaceDwarf;
113
113
  /**
114
114
  * A body's radius in Earth radii: the real one, or one large enough to see in a compressed view.
115
115
  *
116
- * @param id - The Sun, the Earth, the Moon or a planet.
116
+ * @param id - The Sun, the Earth, the Moon, a planet or a dwarf planet.
117
117
  * @param mode - The scale.
118
118
  * @returns The radius to draw it at, in Earth radii.
119
119
  *
@@ -124,7 +124,7 @@ type BaseBody = "sun" | "earth" | "moon" | SpacePlanet;
124
124
  * console.log(radiusIn("moon", "true").toFixed(3), radiusIn("moon", "compressed"));
125
125
  * ```
126
126
  */
127
- export declare function radiusIn(id: "sun" | "earth" | "moon" | SpacePlanet, mode: ScaleMode): number;
127
+ export declare function radiusIn(id: "sun" | "earth" | "moon" | SpacePlanet | SpaceDwarf, mode: ScaleMode): number;
128
128
  /**
129
129
  * How far from its planet a moon is drawn, in the planet's radii, when it is really `distance` radii away. True: as it is. Compressed: the same, until the farthest of the planet's moons would
130
130
  * reach across the gap to the next planet's orbit; then every moon is drawn nearer, the farthest at about a third of the gap and the nearer ones in the order they are, so no moon's orbit crosses another planet's.
@@ -141,7 +141,7 @@ export declare function radiusIn(id: "sun" | "earth" | "moon" | SpacePlanet, mod
141
141
  * console.log(moonDistance("compressed", "neptune", 222).toFixed(1));
142
142
  * ```
143
143
  */
144
- export declare function moonDistance(mode: ScaleMode, host: SpacePlanet, distance: number): number;
144
+ export declare function moonDistance(mode: ScaleMode, host: SpacePlanet | SpaceDwarf, distance: number): number;
145
145
  /**
146
146
  * Where every body of the view is, in Earth radii from the Earth's centre, at one moment: the Earth at the centre, the Moon, the Sun and the planets. The same mapping places
147
147
  * the bodies and the lines of their orbits (`orbitLine`), so a body is always on its own orbit.
@@ -3,7 +3,7 @@
3
3
  import { BODIES, MOONS_OF } from "../facts.js";
4
4
  import { meanSunAu } from "../ephemeris.js";
5
5
  import { moonOffset } from "../scene/orient.js";
6
- import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM } from "./frame.js";
6
+ import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, SPACE_DWARFS } from "./frame.js";
7
7
  const MOON_AU = 0.00257;
8
8
  /**
9
9
  * The Moon's distance in a compressed view, in Earth radii (the true one is about 60). It is well inside the gap between the Earth's orbit and the next one in.
@@ -121,12 +121,14 @@ export function placeAround(mode, sun, helio) {
121
121
  const d = (SUN_COMPRESSED * l ** SPREAD) / l;
122
122
  return [sun[0] + helio[0] * d, sun[1] + helio[1] * d, sun[2] + helio[2] * d];
123
123
  }
124
- /** The sizes a compressed view gives bodies large enough to see, in Earth radii. */
125
- const COMPRESSED_RADIUS = { sun: 5, earth: 1, moon: 0.9, mercury: 0.5, venus: 0.8, mars: 0.6, jupiter: 1.8, saturn: 1.6, uranus: 1.0, neptune: 1.0, pluto: 0.4 };
124
+ /** The sizes a compressed view gives bodies large enough to see, in Earth radii. The Moon is at its true size beside the Earth (0.273 of it), so it never looks as big as the Earth. */
125
+ const COMPRESSED_RADIUS = { sun: 5, earth: 1, moon: 0.273, mercury: 0.5, venus: 0.8, mars: 0.6, jupiter: 1.8, saturn: 1.6, uranus: 1.0, neptune: 1.0, pluto: 0.4 };
126
+ /** A dwarf planet in a compressed view: its true size or this, whichever is the larger, in Earth radii. */
127
+ const COMPRESSED_DWARF = 0.3;
126
128
  /**
127
129
  * A body's radius in Earth radii: the real one, or one large enough to see in a compressed view.
128
130
  *
129
- * @param id - The Sun, the Earth, the Moon or a planet.
131
+ * @param id - The Sun, the Earth, the Moon, a planet or a dwarf planet.
130
132
  * @param mode - The scale.
131
133
  * @returns The radius to draw it at, in Earth radii.
132
134
  *
@@ -138,6 +140,8 @@ const COMPRESSED_RADIUS = { sun: 5, earth: 1, moon: 0.9, mercury: 0.5, venus: 0.
138
140
  * ```
139
141
  */
140
142
  export function radiusIn(id, mode) {
143
+ if (SPACE_DWARFS.includes(id))
144
+ return mode === "true" ? BODIES[id].radiusKm / EARTH_RADIUS_KM : Math.max(COMPRESSED_DWARF, BODIES[id].radiusKm / EARTH_RADIUS_KM);
141
145
  return mode === "true" ? BODIES[id].radiusKm / EARTH_RADIUS_KM : COMPRESSED_RADIUS[id];
142
146
  }
143
147
  /** The planets, nearest the Sun first, whose orbits a moon's orbit must not reach across in a compressed view. */
@@ -214,6 +218,8 @@ export function placeBodies(mode, frame) {
214
218
  const helio = (geo) => [geo[0] - frame.sun[0], geo[1] - frame.sun[1], geo[2] - frame.sun[2]];
215
219
  for (const [id, geo] of Object.entries(frame.planets))
216
220
  all[id] = placeAround(mode, sun, helio(geo));
221
+ for (const [id, geo] of Object.entries(frame.dwarfs))
222
+ all[id] = placeAround(mode, sun, helio(geo));
217
223
  return all;
218
224
  }
219
225
  /**
@@ -1,18 +1,20 @@
1
1
  import type * as THREE from "three";
2
2
  import type { Item3D } from "@johnmorrisdotca/kazoku-ui/renderer";
3
- import { type MoonId } from "../facts.ts";
3
+ import { type BodyId, type MoonId } from "../facts.ts";
4
4
  import type { ThreeParts } from "../scene/body.ts";
5
5
  import { type WakuseiPainter } from "../scene/painter.ts";
6
6
  import "../bodies/all.ts";
7
+ import type { Vec3 } from "../vec.ts";
8
+ import { type OrbitArrow } from "./arrows.ts";
7
9
  import { type SpaceFrame, type SpaceVec3 } from "./frame.ts";
8
10
  import { type RideLook } from "./ride.ts";
9
11
  import { type ScaleMode } from "./scale.ts";
10
12
  /** The parts of three.js the space view uses: the bodies' and a perspective camera. */
11
13
  export type SpaceThree = ThreeParts & Pick<typeof THREE, "PerspectiveCamera">;
12
14
  /** The camera's distance, in radii of the body it looks at, at which that body fills the view at zoom 1. */
13
- export declare const FIT_DISTANCE = 3.4;
15
+ export declare const FIT_DISTANCE = 4.1;
14
16
  /**
15
- * The eleven bodies the space view places, names and lets a reader choose: the Earth, the Sun, the Moon, the seven other planets and Pluto.
17
+ * The nineteen bodies the space view places, names and lets a reader choose: the Earth, the Sun, the Moon, the seven other planets, Pluto and the eight other dwarf planets. The moons of the planets and of the dwarf planets are placed round their hosts.
16
18
  *
17
19
  * @example
18
20
  * ```ts no-run
@@ -21,7 +23,7 @@ export declare const FIT_DISTANCE = 3.4;
21
23
  * console.log(SPACE_BODIES.join(", "));
22
24
  * ```
23
25
  */
24
- export declare const SPACE_BODIES: readonly ["earth", "sun", "moon", "mercury", "venus", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"];
26
+ export declare const SPACE_BODIES: readonly ["earth", "sun", "moon", "mercury", "venus", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto", "ceres", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris", "sedna"];
25
27
  /**
26
28
  * One of the bodies in `SPACE_BODIES`, by the package's usual lower-case name.
27
29
  *
@@ -82,7 +84,7 @@ export interface RideState {
82
84
  /** The body the target goes round: the Earth for a body of the view or a point (unless said), the planet for a moon. */
83
85
  around: SpaceBody;
84
86
  /** `from`: the camera is at the target, looking at the body it goes round. `follow`: the camera keeps a distance from it, looking at it. */
85
- view: "from" | "follow";
87
+ view: "from" | "follow" | "beside";
86
88
  look: RideLook;
87
89
  /** For `follow` a point: how far the camera keeps, in kilometres. */
88
90
  distanceKm: number;
@@ -118,8 +120,8 @@ export interface SpaceModel {
118
120
  labels: boolean;
119
121
  /** Milliseconds of game time one second of wall time covers (the ephemeris is looked up once per such span). */
120
122
  stepMs: number;
121
- /** The body the camera looks at, and (in `zoom`) fills the view with at 1x. */
122
- focus: SpaceBody;
123
+ /** The body the camera looks at, and (in `zoom`) fills the view with at 1x: any body the package knows that the view can place (the eleven of `SPACE_BODIES` and the moons of the planets). */
124
+ focus: BodyId;
123
125
  light: SpaceLight;
124
126
  /** How the painter draws the bodies (`realistic` or `painted`). */
125
127
  look: string;
@@ -135,6 +137,33 @@ export interface SpaceModel {
135
137
  moons: number;
136
138
  held: number;
137
139
  };
140
+ /** What the windows of finer map tiles on the bodies are doing, summed at the last draw: tile fetches made, tiles being fetched, tiles or windows that failed, and the finest level on a body now (`null` for none). */
141
+ tiles: {
142
+ requested: number;
143
+ loading: number;
144
+ failed: number;
145
+ shown: number | null;
146
+ };
147
+ /** The orbit lines drawn at the last draw, and how far each body is from its own line as a fraction of the line's radius (0 when it is on it). */
148
+ rings: {
149
+ drawn: string[];
150
+ miss: Record<string, number>;
151
+ hidden: string[];
152
+ };
153
+ /** The arrowheads on the orbit lines at the last draw, by line: where each is and the way it points. */
154
+ arrows: Record<string, OrbitArrow[]>;
155
+ /** Help mode: draw, on the body looked at, the axis it turns about and a curved arrow showing which way it turns. */
156
+ help: boolean;
157
+ /** How long an arrowhead drawn at the last draw is on the screen, in CSS pixels (measured from its own points), or 0 when none was drawn. */
158
+ arrowPx: number;
159
+ /** What the help arrow drew at the last draw, or null: the body, the axis it spins about (right-hand rule), the north pole, and the axis the drawn arc itself turns about (measured from its points). */
160
+ helpDrawn: {
161
+ body: BodyId;
162
+ axis: Vec3;
163
+ pole: Vec3;
164
+ retrograde: boolean;
165
+ arcTurn: Vec3;
166
+ } | null;
138
167
  /** How many frames the ephemeris has worked out. */
139
168
  lookups: number;
140
169
  /** Pixels a game-second moves things on the screen (the fastest turning body in sight): the draw rate follows it. */
@@ -173,7 +202,17 @@ export interface SpaceModel {
173
202
  ratio(): number;
174
203
  }
175
204
  export declare const newSpaceModel: () => SpaceModel;
176
- /** Where a body is on the screen: its centre and its apparent radius, in CSS pixels in the box. */
205
+ /**
206
+ * Where a body is on the screen: its centre and its apparent radius, in CSS pixels in the box.
207
+ *
208
+ * @example
209
+ * ```ts no-run
210
+ * import type { BodyPlace } from "@johnmorrisdotca/wakusei-planets/space/element";
211
+ *
212
+ * const centre: BodyPlace = { x: 320, y: 200, r: 48 };
213
+ * console.log(centre.r);
214
+ * ```
215
+ */
177
216
  export interface BodyPlace {
178
217
  x: number;
179
218
  y: number;
@@ -183,8 +222,10 @@ export interface SpaceDeps {
183
222
  painter: () => WakuseiPainter;
184
223
  cap: () => number;
185
224
  invalidate: () => void;
225
+ /** Bring the model's time up to the page's clock; called at the start of each draw, so a picture drawn late shows the moment it is drawn at and not the one of the last tick. */
226
+ advance?: () => void;
186
227
  /** Where each body is on the screen, in CSS pixels in the box, or null when it is behind the camera. Called at each draw. */
187
- onLabels?: (places: Record<SpaceBody, BodyPlace | null>) => void;
228
+ onLabels?: (places: Record<string, BodyPlace | null>) => void;
188
229
  /** Called at the end of a draw while the camera is moving from one ride to another, so the next frame is asked for (at the page's frame cap). */
189
230
  onMoving?: () => void;
190
231
  /** The target of the ride could not be placed at this draw. */