@johnmorrisdotca/wakusei-planets 0.31.0 → 0.33.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 (73) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/NOTICE.md +16 -1
  3. package/README.md +60 -5
  4. package/dist/bodies/all.d.ts +1 -0
  5. package/dist/bodies/all.js +1 -0
  6. package/dist/bodies/minor.d.ts +1 -0
  7. package/dist/bodies/minor.js +16 -0
  8. package/dist/data/minor.d.ts +3 -0
  9. package/dist/data/minor.js +7 -0
  10. package/dist/data/tables.d.ts +4 -2
  11. package/dist/data/tables.js +1 -1
  12. package/dist/data-door.d.ts +357 -0
  13. package/dist/data-door.js +393 -0
  14. package/dist/door/book.d.ts +133 -0
  15. package/dist/door/book.js +256 -0
  16. package/dist/door/host.d.ts +30 -0
  17. package/dist/door/host.js +44 -0
  18. package/dist/door/index.d.ts +6 -0
  19. package/dist/door/index.js +10 -0
  20. package/dist/door/map.d.ts +152 -0
  21. package/dist/door/map.js +162 -0
  22. package/dist/door/own.d.ts +36 -0
  23. package/dist/door/own.js +86 -0
  24. package/dist/door/points.d.ts +61 -0
  25. package/dist/door/points.js +175 -0
  26. package/dist/door/small-bodies.d.ts +157 -0
  27. package/dist/door/small-bodies.js +148 -0
  28. package/dist/element.d.ts +21 -0
  29. package/dist/element.js +85 -6
  30. package/dist/embed.d.ts +1 -1
  31. package/dist/embed.js +3 -3
  32. package/dist/ephemeris.d.ts +7 -7
  33. package/dist/ephemeris.js +36 -13
  34. package/dist/facts.d.ts +28 -4
  35. package/dist/facts.js +24 -2
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.js +1 -1
  38. package/dist/nearest.js +6 -4
  39. package/dist/scene/body.d.ts +4 -1
  40. package/dist/scene/body.js +2 -1
  41. package/dist/scene/detail.d.ts +29 -12
  42. package/dist/scene/detail.js +217 -135
  43. package/dist/scene/painter.d.ts +3 -0
  44. package/dist/scene/painter.js +7 -4
  45. package/dist/scene/textures.d.ts +9 -2
  46. package/dist/scene/textures.js +17 -0
  47. package/dist/space/arrows.d.ts +29 -3
  48. package/dist/space/arrows.js +38 -6
  49. package/dist/space/bodies.d.ts +6 -6
  50. package/dist/space/bodies.js +6 -6
  51. package/dist/space/element.d.ts +28 -0
  52. package/dist/space/element.js +74 -6
  53. package/dist/space/frame.d.ts +28 -3
  54. package/dist/space/frame.js +40 -4
  55. package/dist/space/index.d.ts +2 -2
  56. package/dist/space/index.js +2 -2
  57. package/dist/space/scale.d.ts +4 -4
  58. package/dist/space/scale.js +8 -2
  59. package/dist/space/scene.d.ts +12 -2
  60. package/dist/space/scene.js +43 -14
  61. package/dist/stops.d.ts +1 -1
  62. package/dist/stops.js +4 -1
  63. package/dist/tables/all.d.ts +1 -0
  64. package/dist/tables/all.js +1 -0
  65. package/dist/tables/lazy.d.ts +5 -0
  66. package/dist/tables/lazy.js +12 -0
  67. package/dist/tables/minor.d.ts +1 -0
  68. package/dist/tables/minor.js +317 -0
  69. package/dist/textures/vesta-1024.webp +0 -0
  70. package/dist/textures/vesta-512.webp +0 -0
  71. package/dist/version.d.ts +1 -1
  72. package/dist/version.js +1 -1
  73. package/package.json +17 -2
@@ -1,8 +1,9 @@
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";
4
+ import { DWARF_IDS, MINOR_IDS } from "../facts.js";
5
5
  import { DWARF_ELEMENTS } from "../data/dwarf.js";
6
+ import { MINOR_ELEMENTS } from "../data/minor.js";
6
7
  import { OBLIQUITY, RAD } from "../vec.js";
7
8
  import { earthPosition } from "../theory.js";
8
9
  import { DAY_MS } from "../clock.js";
@@ -52,6 +53,17 @@ export const SPACE_PLANETS = ["mercury", "venus", "mars", "jupiter", "saturn", "
52
53
  * ```
53
54
  */
54
55
  export const SPACE_DWARFS = DWARF_IDS;
56
+ /**
57
+ * The minor bodies the space view places: the asteroids Vesta and Pallas, the centaurs Chiron and Pholus and Halley's comet.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * import { SPACE_MINORS } from "@johnmorrisdotca/wakusei-planets/space";
62
+ *
63
+ * console.log(SPACE_MINORS.join(", "));
64
+ * ```
65
+ */
66
+ export const SPACE_MINORS = MINOR_IDS;
55
67
  /** An ecliptic J2000 vector in the scene's axes (equatorial J2000, y north). */
56
68
  const scene = (v) => {
57
69
  const c = Math.cos(OBLIQUITY * RAD);
@@ -84,8 +96,13 @@ export function frameAt(ms) {
84
96
  const h = heliocentric(id, ms);
85
97
  dwarfs[id] = scene([h[0] - earth[0], h[1] - earth[1], h[2] - earth[2]]);
86
98
  }
99
+ const minors = {};
100
+ for (const id of SPACE_MINORS) {
101
+ const h = heliocentric(id, ms);
102
+ minors[id] = scene([h[0] - earth[0], h[1] - earth[1], h[2] - earth[2]]);
103
+ }
87
104
  const moon = moonGeocentric(ms);
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 };
105
+ 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, minors };
89
106
  }
90
107
  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];
91
108
  /**
@@ -112,7 +129,10 @@ export function blend(a, b, t) {
112
129
  const dwarfs = {};
113
130
  for (const id of SPACE_DWARFS)
114
131
  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 };
132
+ const minors = {};
133
+ for (const id of SPACE_MINORS)
134
+ minors[id] = lerp3(a.minors[id], b.minors[id], t);
135
+ 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, minors };
116
136
  }
117
137
  /**
118
138
  * 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
@@ -169,11 +189,12 @@ const PERIOD_DAYS = {
169
189
  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
190
  // a dwarf planet's own: a full turn of its mean motion
171
191
  ...Object.fromEntries(SPACE_DWARFS.map((id) => [id, 360 / DWARF_ELEMENTS[id].n])),
192
+ ...Object.fromEntries(SPACE_MINORS.map((id) => [id, 360 / MINOR_ELEMENTS[id].n])),
172
193
  };
173
194
  /**
174
195
  * 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.
175
196
  *
176
- * @param id - The planet, the dwarf planet or `earth`.
197
+ * @param id - The planet, the dwarf planet, the minor body or `earth`.
177
198
  * @param ms - The moment the path starts at, in milliseconds since the Unix epoch.
178
199
  * @param count - How many segments to cut the trip into.
179
200
  * @returns `count + 1` points; the last is near the first.
@@ -188,6 +209,21 @@ const PERIOD_DAYS = {
188
209
  */
189
210
  export function planetOrbit(id, ms, count = 96) {
190
211
  const points = [];
212
+ const minor = SPACE_MINORS.includes(id) ? MINOR_ELEMENTS[id] : SPACE_DWARFS.includes(id) ? DWARF_ELEMENTS[id] : undefined;
213
+ if (minor !== undefined && minor.e > 0.15) {
214
+ // a long ellipse (Halley's, Pholus's, Sedna's, Eris's) is cut at equal steps of the eccentric anomaly, not of time: cut in time, the sharp turn near the Sun is one straight stroke with corners, and the slow far side most of the points
215
+ const e = minor.e;
216
+ const m0 = ((minor.m + (minor.n * (ms - minor.epoch)) / DAY_MS) * Math.PI) / 180;
217
+ let e0 = m0;
218
+ for (let k = 0; k < 40; k += 1)
219
+ e0 -= (e0 - e * Math.sin(e0) - m0) / (1 - e * Math.cos(e0));
220
+ const mean = (anomaly) => anomaly - e * Math.sin(anomaly);
221
+ for (let i = 0; i <= count; i += 1) {
222
+ const anomaly = e0 + (i / count) * 2 * Math.PI;
223
+ points.push(scene(heliocentric(id, ms + ((mean(anomaly) - mean(e0)) / ((minor.n * Math.PI) / 180)) * DAY_MS)));
224
+ }
225
+ return points;
226
+ }
191
227
  for (let i = 0; i <= count; i += 1)
192
228
  points.push(scene(heliocentric(id, ms + (i / count) * PERIOD_DAYS[id] * DAY_MS)));
193
229
  return points;
@@ -1,9 +1,9 @@
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";
1
+ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS, type SpaceDwarf, type SpaceFrame, type SpaceMinor, 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
5
  export { chooseLabels, LABEL_GAP, type LabelBox } from "./labels.ts";
6
6
  export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, type SpaceKind } from "./bodies.ts";
7
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";
8
+ export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, spinArrow, type OrbitArrow } from "./arrows.ts";
9
9
  export { spinAxis, type SpinAxis } from "./spin.ts";
@@ -1,10 +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, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_PLANETS } from "./frame.js";
2
+ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, 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
6
  export { chooseLabels, LABEL_GAP } from "./labels.js";
7
7
  export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf } from "./bodies.js";
8
8
  export { besideMoon, BESIDE_RADII } from "./beside.js";
9
- export { ARROWS_PER_ORBIT, arrowSites, chevron, spinArrow } from "./arrows.js";
9
+ export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, spinArrow } from "./arrows.js";
10
10
  export { spinAxis } from "./spin.js";
@@ -1,5 +1,5 @@
1
1
  import type { Vec3 } from "../vec.ts";
2
- import { type SpaceDwarf, type SpaceFrame, type SpacePlanet } from "./frame.ts";
2
+ import { type SpaceDwarf, type SpaceFrame, type SpaceMinor, 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 | SpaceDwarf;
112
+ type BaseBody = "sun" | "earth" | "moon" | SpacePlanet | SpaceDwarf | SpaceMinor;
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, a planet or a dwarf planet.
116
+ * @param id - The Sun, the Earth, the Moon, a planet, a dwarf planet or a minor body.
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 | SpaceDwarf;
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 | SpaceDwarf, mode: ScaleMode): number;
127
+ export declare function radiusIn(id: "sun" | "earth" | "moon" | SpacePlanet | SpaceDwarf | SpaceMinor, 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.
@@ -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, SPACE_DWARFS } from "./frame.js";
6
+ import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, SPACE_DWARFS, SPACE_MINORS } 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.
@@ -125,10 +125,12 @@ export function placeAround(mode, sun, helio) {
125
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
126
  /** A dwarf planet in a compressed view: its true size or this, whichever is the larger, in Earth radii. */
127
127
  const COMPRESSED_DWARF = 0.3;
128
+ /** A minor body in a compressed view: its true size or this, whichever is the larger, in Earth radii (a speck beside a dwarf planet). */
129
+ const COMPRESSED_MINOR = 0.2;
128
130
  /**
129
131
  * A body's radius in Earth radii: the real one, or one large enough to see in a compressed view.
130
132
  *
131
- * @param id - The Sun, the Earth, the Moon, a planet or a dwarf planet.
133
+ * @param id - The Sun, the Earth, the Moon, a planet, a dwarf planet or a minor body.
132
134
  * @param mode - The scale.
133
135
  * @returns The radius to draw it at, in Earth radii.
134
136
  *
@@ -140,6 +142,8 @@ const COMPRESSED_DWARF = 0.3;
140
142
  * ```
141
143
  */
142
144
  export function radiusIn(id, mode) {
145
+ if (SPACE_MINORS.includes(id))
146
+ return mode === "true" ? BODIES[id].radiusKm / EARTH_RADIUS_KM : Math.max(COMPRESSED_MINOR, BODIES[id].radiusKm / EARTH_RADIUS_KM);
143
147
  if (SPACE_DWARFS.includes(id))
144
148
  return mode === "true" ? BODIES[id].radiusKm / EARTH_RADIUS_KM : Math.max(COMPRESSED_DWARF, BODIES[id].radiusKm / EARTH_RADIUS_KM);
145
149
  return mode === "true" ? BODIES[id].radiusKm / EARTH_RADIUS_KM : COMPRESSED_RADIUS[id];
@@ -220,6 +224,8 @@ export function placeBodies(mode, frame) {
220
224
  all[id] = placeAround(mode, sun, helio(geo));
221
225
  for (const [id, geo] of Object.entries(frame.dwarfs))
222
226
  all[id] = placeAround(mode, sun, helio(geo));
227
+ for (const [id, geo] of Object.entries(frame.minors))
228
+ all[id] = placeAround(mode, sun, helio(geo));
223
229
  return all;
224
230
  }
225
231
  /**
@@ -2,6 +2,7 @@ import type * as THREE from "three";
2
2
  import type { Item3D } from "@johnmorrisdotca/kazoku-ui/renderer";
3
3
  import { type BodyId, type MoonId } from "../facts.ts";
4
4
  import type { ThreeParts } from "../scene/body.ts";
5
+ import type { SourceBook } from "../door/book.ts";
5
6
  import { type WakuseiPainter } from "../scene/painter.ts";
6
7
  import "../bodies/all.ts";
7
8
  import type { Vec3 } from "../vec.ts";
@@ -14,7 +15,7 @@ export type SpaceThree = ThreeParts & Pick<typeof THREE, "PerspectiveCamera">;
14
15
  /** The camera's distance, in radii of the body it looks at, at which that body fills the view at zoom 1. */
15
16
  export declare const FIT_DISTANCE = 4.1;
16
17
  /**
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.
18
+ * The twenty-four bodies the space view places, names and lets a reader choose: the Earth, the Sun, the Moon, the seven other planets, Pluto, the eight other dwarf planets and the five minor bodies (Vesta, Pallas, Chiron, Pholus and Halley). The moons of the planets and of the dwarf planets are placed round their hosts.
18
19
  *
19
20
  * @example
20
21
  * ```ts no-run
@@ -23,7 +24,7 @@ export declare const FIT_DISTANCE = 4.1;
23
24
  * console.log(SPACE_BODIES.join(", "));
24
25
  * ```
25
26
  */
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"];
27
+ 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", "vesta", "pallas", "chiron", "pholus", "halley"];
27
28
  /**
28
29
  * One of the bodies in `SPACE_BODIES`, by the package's usual lower-case name.
29
30
  *
@@ -154,6 +155,8 @@ export interface SpaceModel {
154
155
  arrows: Record<string, OrbitArrow[]>;
155
156
  /** Help mode: draw, on the body looked at, the axis it turns about and a curved arrow showing which way it turns. */
156
157
  help: boolean;
158
+ /** How many arrowheads each orbit line carries: 0 to `MAX_ARROWS_PER_ORBIT`, two by default. */
159
+ arrowCount: number;
157
160
  /** 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
161
  arrowPx: number;
159
162
  /** 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). */
@@ -164,6 +167,11 @@ export interface SpaceModel {
164
167
  retrograde: boolean;
165
168
  arcTurn: Vec3;
166
169
  } | null;
170
+ /** The data door at the last draw: how many small bodies are in the one instanced draw, and how many tiles or marks each source gave (by id): the credits. */
171
+ door: {
172
+ points: number;
173
+ used: Record<string, number>;
174
+ };
167
175
  /** How many frames the ephemeris has worked out. */
168
176
  lookups: number;
169
177
  /** Pixels a game-second moves things on the screen (the fastest turning body in sight): the draw rate follows it. */
@@ -220,6 +228,8 @@ export interface BodyPlace {
220
228
  }
221
229
  export interface SpaceDeps {
222
230
  painter: () => WakuseiPainter;
231
+ /** The view's sources (the data door): small bodies are drawn as points from it. Left out, none are. */
232
+ book?: SourceBook;
223
233
  cap: () => number;
224
234
  invalidate: () => void;
225
235
  /** 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. */
@@ -1,13 +1,15 @@
1
1
  import { BODIES, MOONS_OF } from "../facts.js";
2
+ import { createSmallBodyPoints } from "../door/points.js";
3
+ import { toTerrestrialTime } from "../clock.js";
2
4
  import { moonOffset } from "../scene/orient.js";
3
5
  import {} from "../scene/painter.js";
4
6
  import "../bodies/all.js";
5
7
  import { groundDirection } from "./aim.js";
6
8
  import { hostOf } from "./bodies.js";
7
- import { arrowSites, ARROWS_PER_ORBIT, chevron, spinArrow } from "./arrows.js";
9
+ import { arrowSites, ARROWS_PER_ORBIT, chevron, MAX_ARROWS_PER_ORBIT, spinArrow } from "./arrows.js";
8
10
  import { besideMoon } from "./beside.js";
9
11
  import { spinAxis } from "./spin.js";
10
- import { createTrack, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_PLANETS } from "./frame.js";
12
+ import { createTrack, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
11
13
  import { ridePose } from "./ride.js";
12
14
  import { moonDistance, orbitLine, placeBodies, placeMoon, radiusIn } from "./scale.js";
13
15
  const RAD = Math.PI / 180;
@@ -15,8 +17,8 @@ const RAD = Math.PI / 180;
15
17
  export const FIT_DISTANCE = 4.1;
16
18
  const FOV = 35;
17
19
  const ORBIT_POINTS = 96;
18
- const ORBIT_BODIES = ["earth", ...SPACE_PLANETS, ...SPACE_DWARFS, "moon"];
19
- /** A dwarf planet is drawn once it is this many CSS pixels across its radius, or when it is the body looked at: Sedna at true scale is never anything but a speck, and its picture is not made for it. */
20
+ const ORBIT_BODIES = ["earth", ...SPACE_PLANETS, ...SPACE_DWARFS, ...SPACE_MINORS, "moon"];
21
+ /** A dwarf planet or a minor body is drawn once it is this many CSS pixels across its radius, or when it is the body looked at: Sedna at true scale is never anything but a speck, and its picture is not made for it. */
20
22
  const DWARF_MIN_PX = 0.4;
21
23
  /** A colour as three numbers from 0 to 1, from `#rrggbb`. */
22
24
  const rgb = (hex) => [parseInt(hex.slice(1, 3), 16) / 255, parseInt(hex.slice(3, 5), 16) / 255, parseInt(hex.slice(5, 7), 16) / 255];
@@ -36,7 +38,7 @@ const MOON_MIN_SYSTEM_PX = 30;
36
38
  /** A moon that has been out of sight this long is let go (its pictures too). */
37
39
  const MOON_KEEP_MS = 4000;
38
40
  /**
39
- * 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.
41
+ * The twenty-four bodies the space view places, names and lets a reader choose: the Earth, the Sun, the Moon, the seven other planets, Pluto, the eight other dwarf planets and the five minor bodies (Vesta, Pallas, Chiron, Pholus and Halley). The moons of the planets and of the dwarf planets are placed round their hosts.
40
42
  *
41
43
  * @example
42
44
  * ```ts no-run
@@ -45,7 +47,7 @@ const MOON_KEEP_MS = 4000;
45
47
  * console.log(SPACE_BODIES.join(", "));
46
48
  * ```
47
49
  */
48
- export const SPACE_BODIES = ["earth", "sun", "moon", ...SPACE_PLANETS, ...SPACE_DWARFS];
50
+ export const SPACE_BODIES = ["earth", "sun", "moon", ...SPACE_PLANETS, ...SPACE_DWARFS, ...SPACE_MINORS];
49
51
  export const newSpaceModel = () => ({
50
52
  time: Date.now(),
51
53
  mode: "true",
@@ -65,7 +67,9 @@ export const newSpaceModel = () => ({
65
67
  arrows: {},
66
68
  help: false,
67
69
  arrowPx: 0,
70
+ arrowCount: ARROWS_PER_ORBIT,
68
71
  helpDrawn: null,
72
+ door: { points: 0, used: {} },
69
73
  lookups: 0,
70
74
  motion: 0,
71
75
  drawnView: null,
@@ -107,6 +111,11 @@ export function createSpaceItem(model, deps) {
107
111
  const track = createTrack(model.stepMs);
108
112
  let trackStep = model.stepMs;
109
113
  const scene = new three.Scene();
114
+ // the small bodies of the record sources, in one instanced draw (a page's own subset of three needs the two instanced classes for it)
115
+ const points = deps.book !== undefined && typeof three.InstancedBufferGeometry === "function" ? createSmallBodyPoints(three) : undefined;
116
+ if (points !== undefined)
117
+ scene.add(points.object);
118
+ let pointsVersion = -1;
110
119
  const camera = new three.PerspectiveCamera(FOV, width / Math.max(1, height), 0.05, 1000);
111
120
  const target = new three.Vector3();
112
121
  const projected = new three.Vector3();
@@ -163,7 +172,7 @@ export function createSpaceItem(model, deps) {
163
172
  orbits.set(id, { line, positions, colours, faded: false, samples: [], epoch: Number.NaN });
164
173
  }
165
174
  // the arrowheads of every orbit line: two strokes each, in the colour of the line, in one object; and the help mode's axis and curved arrow in another (drawn over the body, not hidden by it)
166
- const ARROW_VERTICES = ORBIT_BODIES.length * ARROWS_PER_ORBIT * 4;
175
+ const ARROW_VERTICES = ORBIT_BODIES.length * MAX_ARROWS_PER_ORBIT * 4;
167
176
  const arrowPositions = new Float32Array(ARROW_VERTICES * 3);
168
177
  const arrowColours = new Float32Array(ARROW_VERTICES * 3);
169
178
  const arrowGeometry = new three.BufferGeometry();
@@ -174,8 +183,8 @@ export function createSpaceItem(model, deps) {
174
183
  scene.add(arrowLines);
175
184
  ORBIT_BODIES.forEach((id, k) => {
176
185
  const c = rgb(id === "earth" ? "#6aa8ff" : id === "moon" ? "#c5cdd9" : BODIES[id].colour);
177
- for (let v = 0; v < ARROWS_PER_ORBIT * 4; v += 1)
178
- arrowColours.set(c, (k * ARROWS_PER_ORBIT * 4 + v) * 3);
186
+ for (let v = 0; v < MAX_ARROWS_PER_ORBIT * 4; v += 1)
187
+ arrowColours.set(c, (k * MAX_ARROWS_PER_ORBIT * 4 + v) * 3);
179
188
  });
180
189
  const HELP_SEGMENTS = 28;
181
190
  const HELP_VERTICES = (1 + HELP_SEGMENTS + 2) * 2;
@@ -246,7 +255,7 @@ export function createSpaceItem(model, deps) {
246
255
  placed[id] = minus(placed[id], origin);
247
256
  return placed;
248
257
  };
249
- const toSunOf = (id) => unit(minus(frame.sun, id === "earth" ? [0, 0, 0] : id === "moon" ? frame.moon : id === "sun" ? [0, 0, 0] : SPACE_DWARFS.includes(id) ? frame.dwarfs[id] : frame.planets[id]));
258
+ const toSunOf = (id) => unit(minus(frame.sun, id === "earth" ? [0, 0, 0] : id === "moon" ? frame.moon : id === "sun" ? [0, 0, 0] : SPACE_DWARFS.includes(id) ? frame.dwarfs[id] : SPACE_MINORS.includes(id) ? frame.minors[id] : frame.planets[id]));
250
259
  // riding along: the camera sits at a moving point and looks at the body it goes round (a moon over its planet, a point over any body). The point's place and way of going are in radii of
251
260
  // that body, from its centre; the body is drawn at `centre` with the radius `unitWorld`, so the same numbers place the camera in the scene.
252
261
  model.rideLost = false;
@@ -444,8 +453,8 @@ export function createSpaceItem(model, deps) {
444
453
  let paintedBodies = 0;
445
454
  for (const id of SPACE_BODIES) {
446
455
  const slot = slotOf(id);
447
- // a dwarf planet too small to see is not made, and one that was made but has shrunk away is hidden
448
- const unseen = SPACE_DWARFS.includes(id) && px[id] < DWARF_MIN_PX && focus !== id && model.focus !== id && hostOf(model.focus) !== id;
456
+ // a dwarf planet or minor body too small to see is not made, and one that was made but has shrunk away is hidden
457
+ const unseen = (SPACE_DWARFS.includes(id) || SPACE_MINORS.includes(id)) && px[id] < DWARF_MIN_PX && focus !== id && model.focus !== id && hostOf(model.focus) !== id;
449
458
  if (unseen) {
450
459
  if (slot.drawing)
451
460
  slot.drawing.object.visible = false;
@@ -466,6 +475,15 @@ export function createSpaceItem(model, deps) {
466
475
  drawing.update({ toSun, ms: model.time, radiusPx: px[id], view: { camera, width: size.width, height: size.height } });
467
476
  }
468
477
  model.painted.bodies = paintedBodies;
478
+ if (points !== undefined && deps.book !== undefined) {
479
+ if (pointsVersion !== deps.book.version) {
480
+ pointsVersion = deps.book.version;
481
+ points.set(deps.book.smallBodies());
482
+ }
483
+ const ratio = model.ratio();
484
+ points.update({ jd: toTerrestrialTime(model.time) / 86_400_000 + 2_440_587.5, mode, sun: sunPos, width: size.width * ratio, height: size.height * ratio, ratio });
485
+ model.door.points = points.count;
486
+ }
469
487
  // the orbits round the Sun, placed by the same mapping as the bodies
470
488
  const drawnRings = [];
471
489
  const hiddenRings = [];
@@ -533,7 +551,7 @@ export function createSpaceItem(model, deps) {
533
551
  const line = [];
534
552
  for (let i = 0; i <= ORBIT_POINTS; i += 1)
535
553
  line.push([o.positions[i * 3], o.positions[i * 3 + 1], o.positions[i * 3 + 2]]);
536
- const sites = arrowSites(line);
554
+ const sites = arrowSites(line, model.arrowCount);
537
555
  arrowsNow[id] = sites;
538
556
  sites.forEach((site, j) => {
539
557
  // an arrow on the faded part of a line goes with it
@@ -542,7 +560,7 @@ export function createSpaceItem(model, deps) {
542
560
  const head = chevron(site.position, site.direction, camRight, camUp, ARROW_PX * pixel(site.position));
543
561
  if (!head)
544
562
  return;
545
- const base = (k * ARROWS_PER_ORBIT + j) * 4 * 3;
563
+ const base = (k * MAX_ARROWS_PER_ORBIT + j) * 4 * 3;
546
564
  arrowPositions.set([...head[0], ...head[1], ...head[0], ...head[2]], base);
547
565
  if (measured === 0) {
548
566
  const tip = labelFor(head[0]);
@@ -666,6 +684,16 @@ export function createSpaceItem(model, deps) {
666
684
  tiles.shown = Math.max(tiles.shown ?? 0, stats.shown);
667
685
  }
668
686
  model.tiles = tiles;
687
+ const used = {};
688
+ for (const painting of [...[...slots.values()].map((slot) => slot.drawing), ...[...moonSlots.values()].map((held) => held.slot.drawing)]) {
689
+ const shown = painting?.tiles;
690
+ if (shown?.source !== undefined)
691
+ used[shown.source.id] = (used[shown.source.id] ?? 0) + shown.used;
692
+ }
693
+ if (points !== undefined && deps.book !== undefined && points.count > 0)
694
+ for (const [id, read] of deps.book.recordReads())
695
+ used[id] = read.records.length;
696
+ model.door.used = used;
669
697
  if (deps.onLabels && model.labels) {
670
698
  const places = { ...moonPlaces };
671
699
  for (const id of SPACE_BODIES) {
@@ -684,6 +712,7 @@ export function createSpaceItem(model, deps) {
684
712
  size = { width: w, height: h };
685
713
  },
686
714
  dispose() {
715
+ points?.dispose();
687
716
  if (releaseTimer !== undefined)
688
717
  clearTimeout(releaseTimer);
689
718
  ended = true;
package/dist/stops.d.ts CHANGED
@@ -32,7 +32,7 @@ export interface JourneyStop {
32
32
  escapeKmS: number | null;
33
33
  }
34
34
  /**
35
- * Every body, in the same order as `BODY_IDS`: the Sun, the planets, the dwarf planets, then the moons.
35
+ * Every body, in the same order as `BODY_IDS`: the Sun, the planets, the dwarf planets, the minor bodies, then the moons.
36
36
  *
37
37
  * @example
38
38
  * ```ts
package/dist/stops.js CHANGED
@@ -4,6 +4,7 @@
4
4
  // (https://nssdc.gsfc.nasa.gov/planetary/factsheet/) for the Sun (132,712 × 10^6), Mercury (0.022032 × 10^6) and Venus (0.32486 × 10^6).
5
5
  // Ceres, Eris, Makemake and Haumea: the mass on JPL "Planetary Physical Parameters" (https://ssd.jpl.nasa.gov/planets/phys_par.html)
6
6
  // times the CODATA 2018 G that page names. Escape speeds for the Sun and those planets are the speeds those pages print.
7
+ // Vesta (17.2882844) and Pallas (13.63): the GM of JPL's Small-Body Database (https://ssd-api.jpl.nasa.gov/sbdb.api, read 2026-11-10), from Park et al. 2025 and Vernazza et al. 2021.
7
8
  // A moon's escape speed is sqrt(2 GM / radius) from this package's radius. Nereid, and the dwarf planets and moons
8
9
  // whose pages do not print a mass, are left empty.
9
10
  import { heliocentric, meanSunAu, moonVector } from "./ephemeris.js";
@@ -30,6 +31,8 @@ const GM = {
30
31
  eris: mass(16_600e18),
31
32
  makemake: mass(3_100e18),
32
33
  haumea: mass(4_006e18),
34
+ vesta: 17.2882844,
35
+ pallas: 13.63,
33
36
  moon: 4_902.8,
34
37
  phobos: 0.0007087,
35
38
  deimos: 0.0000962,
@@ -89,7 +92,7 @@ const stopOf = (id) => {
89
92
  };
90
93
  };
91
94
  /**
92
- * Every body, in the same order as `BODY_IDS`: the Sun, the planets, the dwarf planets, then the moons.
95
+ * Every body, in the same order as `BODY_IDS`: the Sun, the planets, the dwarf planets, the minor bodies, then the moons.
93
96
  *
94
97
  * @example
95
98
  * ```ts
@@ -1,4 +1,5 @@
1
1
  import "./ceres.ts";
2
2
  import "./dwarfs.ts";
3
+ import "./minor.ts";
3
4
  import "./galilean.ts";
4
5
  import "./saturn-moons.ts";
@@ -1,4 +1,5 @@
1
1
  import "./ceres.js";
2
2
  import "./dwarfs.js";
3
+ import "./minor.js";
3
4
  import "./galilean.js";
4
5
  import "./saturn-moons.js";
@@ -1,2 +1,7 @@
1
1
  /** Fetch the theory for a planet's moons: resolves true for the one call that fetched it, false when it was already asked for or loaded, there is none for that planet, or it could not be fetched. */
2
2
  export declare function loadMoonTheory(planet: string): Promise<boolean>;
3
+ /**
4
+ * Fetch the fitted tables of the minor bodies (Vesta, Pallas, Chiron, Pholus, Halley: about 48 kB gzipped) when a picture of one of them is dated: resolves true for the one call that fetched them, false when they were already asked for
5
+ * or loaded, or could not be fetched. Until they arrive a minor body is placed from its osculating elements.
6
+ */
7
+ export declare function loadMinorTables(): Promise<boolean>;
@@ -1,5 +1,6 @@
1
1
  // Loads a planet's moon theory when a picture asks for its moons, so a page that shows one planet does not carry Jupiter's and Saturn's theories. A bundler with code splitting makes each a chunk of its own.
2
2
  import { moonTheoryOf } from "../data/theories.js";
3
+ import { tableOf } from "../data/tables.js";
3
4
  const LOADERS = {
4
5
  jupiter: { moon: "io", load: () => import("./galilean.js") },
5
6
  saturn: { moon: "mimas", load: () => import("./saturn-moons.js") },
@@ -13,3 +14,14 @@ export function loadMoonTheory(planet) {
13
14
  asked.add(planet);
14
15
  return loader.load().then(() => true, () => false);
15
16
  }
17
+ let askedMinor = false;
18
+ /**
19
+ * Fetch the fitted tables of the minor bodies (Vesta, Pallas, Chiron, Pholus, Halley: about 48 kB gzipped) when a picture of one of them is dated: resolves true for the one call that fetched them, false when they were already asked for
20
+ * or loaded, or could not be fetched. Until they arrive a minor body is placed from its osculating elements.
21
+ */
22
+ export function loadMinorTables() {
23
+ if (askedMinor || tableOf("vesta") !== undefined)
24
+ return Promise.resolve(false);
25
+ askedMinor = true;
26
+ return import("./minor.js").then(() => true, () => false);
27
+ }
@@ -0,0 +1 @@
1
+ export {};