@johnmorrisdotca/wakusei-planets 0.34.0 → 0.36.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 (215) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/NOTICE.md +64 -0
  3. package/README.md +21 -3
  4. package/dist/approaches.d.ts +276 -0
  5. package/dist/approaches.js +255 -0
  6. package/dist/asteroids.d.ts +397 -0
  7. package/dist/asteroids.js +338 -0
  8. package/dist/comets.d.ts +316 -0
  9. package/dist/comets.js +404 -0
  10. package/dist/craft/bepicolombo.d.ts +1 -0
  11. package/dist/craft/bepicolombo.js +923 -0
  12. package/dist/craft/europaclipper.d.ts +1 -0
  13. package/dist/craft/europaclipper.js +342 -0
  14. package/dist/craft/hayabusa2.d.ts +1 -0
  15. package/dist/craft/hayabusa2.js +73 -0
  16. package/dist/craft/juice.d.ts +1 -0
  17. package/dist/craft/juice.js +40 -0
  18. package/dist/craft/lucy.d.ts +1 -0
  19. package/dist/craft/lucy.js +42 -0
  20. package/dist/craft/osirisapex.d.ts +1 -0
  21. package/dist/craft/osirisapex.js +69 -0
  22. package/dist/craft/psyche.d.ts +1 -0
  23. package/dist/craft/psyche.js +30 -0
  24. package/dist/craft/solarorbiter.d.ts +1 -0
  25. package/dist/craft/solarorbiter.js +94 -0
  26. package/dist/data/approaches.d.ts +17 -0
  27. package/dist/data/approaches.js +4192 -0
  28. package/dist/data/asteroids.d.ts +3 -0
  29. package/dist/data/asteroids.js +107 -0
  30. package/dist/data/comets.d.ts +2 -0
  31. package/dist/data/comets.js +36 -0
  32. package/dist/data/orbiters.d.ts +368 -0
  33. package/dist/data/orbiters.js +370 -0
  34. package/dist/data/places-67p.d.ts +27 -0
  35. package/dist/data/places-67p.js +2 -0
  36. package/dist/data/places-ariel.d.ts +602 -0
  37. package/dist/data/places-ariel.js +27 -0
  38. package/dist/data/places-bennu.d.ts +25 -0
  39. package/dist/data/places-bennu.js +2 -0
  40. package/dist/data/places-callisto.d.ts +3547 -0
  41. package/dist/data/places-callisto.js +155 -0
  42. package/dist/data/places-ceres.d.ts +3436 -0
  43. package/dist/data/places-ceres.js +150 -0
  44. package/dist/data/places-charon.d.ts +349 -0
  45. package/dist/data/places-charon.js +16 -0
  46. package/dist/data/places-dimorphos.d.ts +23 -0
  47. package/dist/data/places-dimorphos.js +2 -0
  48. package/dist/data/places-dione.d.ts +2258 -0
  49. package/dist/data/places-dione.js +99 -0
  50. package/dist/data/places-enceladus.d.ts +2009 -0
  51. package/dist/data/places-enceladus.js +88 -0
  52. package/dist/data/places-eros.d.ts +26 -0
  53. package/dist/data/places-eros.js +2 -0
  54. package/dist/data/places-europa.d.ts +2977 -0
  55. package/dist/data/places-europa.js +130 -0
  56. package/dist/data/places-ganymede.d.ts +4518 -0
  57. package/dist/data/places-ganymede.js +197 -0
  58. package/dist/data/places-iapetus.d.ts +1616 -0
  59. package/dist/data/places-iapetus.js +71 -0
  60. package/dist/data/places-io.d.ts +6012 -0
  61. package/dist/data/places-io.js +262 -0
  62. package/dist/data/places-jupiter.d.ts +46 -0
  63. package/dist/data/places-jupiter.js +3 -0
  64. package/dist/data/places-mars.d.ts +20701 -0
  65. package/dist/data/places-mars.js +942 -0
  66. package/dist/data/places-mercury.d.ts +9256 -0
  67. package/dist/data/places-mercury.js +403 -0
  68. package/dist/data/places-mimas.d.ts +968 -0
  69. package/dist/data/places-mimas.js +43 -0
  70. package/dist/data/places-miranda.d.ts +419 -0
  71. package/dist/data/places-miranda.js +19 -0
  72. package/dist/data/places-moon.d.ts +18849 -0
  73. package/dist/data/places-moon.js +861 -0
  74. package/dist/data/places-oberon.d.ts +235 -0
  75. package/dist/data/places-oberon.js +11 -0
  76. package/dist/data/places-pluto.d.ts +1687 -0
  77. package/dist/data/places-pluto.js +74 -0
  78. package/dist/data/places-rhea.d.ts +3317 -0
  79. package/dist/data/places-rhea.js +145 -0
  80. package/dist/data/places-ryugu.d.ts +87 -0
  81. package/dist/data/places-ryugu.js +5 -0
  82. package/dist/data/places-saturn.d.ts +25 -0
  83. package/dist/data/places-saturn.js +2 -0
  84. package/dist/data/places-tempel-1.d.ts +25 -0
  85. package/dist/data/places-tempel-1.js +2 -0
  86. package/dist/data/places-tethys.d.ts +1222 -0
  87. package/dist/data/places-tethys.js +54 -0
  88. package/dist/data/places-titan.d.ts +7031 -0
  89. package/dist/data/places-titan.js +306 -0
  90. package/dist/data/places-titania.d.ts +418 -0
  91. package/dist/data/places-titania.js +19 -0
  92. package/dist/data/places-triton.d.ts +1457 -0
  93. package/dist/data/places-triton.js +64 -0
  94. package/dist/data/places-umbriel.d.ts +303 -0
  95. package/dist/data/places-umbriel.js +14 -0
  96. package/dist/data/places-venus.d.ts +9290 -0
  97. package/dist/data/places-venus.js +405 -0
  98. package/dist/data/places-vesta.d.ts +2444 -0
  99. package/dist/data/places-vesta.js +107 -0
  100. package/dist/data/roadster.d.ts +8 -0
  101. package/dist/data/roadster.js +686 -0
  102. package/dist/element.js +17 -3
  103. package/dist/orbiter-facts.d.ts +480 -0
  104. package/dist/orbiter-facts.js +189 -0
  105. package/dist/orbiters.d.ts +256 -0
  106. package/dist/orbiters.js +275 -0
  107. package/dist/places/67p.d.ts +13 -0
  108. package/dist/places/67p.js +14 -0
  109. package/dist/places/ariel.d.ts +13 -0
  110. package/dist/places/ariel.js +14 -0
  111. package/dist/places/bennu.d.ts +13 -0
  112. package/dist/places/bennu.js +14 -0
  113. package/dist/places/callisto.d.ts +13 -0
  114. package/dist/places/callisto.js +14 -0
  115. package/dist/places/ceres.d.ts +13 -0
  116. package/dist/places/ceres.js +14 -0
  117. package/dist/places/charon.d.ts +13 -0
  118. package/dist/places/charon.js +14 -0
  119. package/dist/places/dimorphos.d.ts +13 -0
  120. package/dist/places/dimorphos.js +14 -0
  121. package/dist/places/dione.d.ts +13 -0
  122. package/dist/places/dione.js +14 -0
  123. package/dist/places/enceladus.d.ts +13 -0
  124. package/dist/places/enceladus.js +14 -0
  125. package/dist/places/eros.d.ts +13 -0
  126. package/dist/places/eros.js +14 -0
  127. package/dist/places/europa.d.ts +13 -0
  128. package/dist/places/europa.js +14 -0
  129. package/dist/places/ganymede.d.ts +13 -0
  130. package/dist/places/ganymede.js +14 -0
  131. package/dist/places/iapetus.d.ts +13 -0
  132. package/dist/places/iapetus.js +14 -0
  133. package/dist/places/io.d.ts +13 -0
  134. package/dist/places/io.js +14 -0
  135. package/dist/places/jupiter.d.ts +13 -0
  136. package/dist/places/jupiter.js +14 -0
  137. package/dist/places/mars.d.ts +12 -0
  138. package/dist/places/mars.js +13 -0
  139. package/dist/places/mercury.d.ts +13 -0
  140. package/dist/places/mercury.js +14 -0
  141. package/dist/places/mimas.d.ts +13 -0
  142. package/dist/places/mimas.js +14 -0
  143. package/dist/places/miranda.d.ts +13 -0
  144. package/dist/places/miranda.js +14 -0
  145. package/dist/places/moon.d.ts +12 -0
  146. package/dist/places/moon.js +13 -0
  147. package/dist/places/oberon.d.ts +13 -0
  148. package/dist/places/oberon.js +14 -0
  149. package/dist/places/pluto.d.ts +13 -0
  150. package/dist/places/pluto.js +14 -0
  151. package/dist/places/rhea.d.ts +13 -0
  152. package/dist/places/rhea.js +14 -0
  153. package/dist/places/ryugu.d.ts +13 -0
  154. package/dist/places/ryugu.js +14 -0
  155. package/dist/places/saturn.d.ts +13 -0
  156. package/dist/places/saturn.js +14 -0
  157. package/dist/places/tempel-1.d.ts +13 -0
  158. package/dist/places/tempel-1.js +14 -0
  159. package/dist/places/tethys.d.ts +13 -0
  160. package/dist/places/tethys.js +14 -0
  161. package/dist/places/titan.d.ts +13 -0
  162. package/dist/places/titan.js +14 -0
  163. package/dist/places/titania.d.ts +13 -0
  164. package/dist/places/titania.js +14 -0
  165. package/dist/places/triton.d.ts +13 -0
  166. package/dist/places/triton.js +14 -0
  167. package/dist/places/umbriel.d.ts +13 -0
  168. package/dist/places/umbriel.js +14 -0
  169. package/dist/places/venus.d.ts +13 -0
  170. package/dist/places/venus.js +14 -0
  171. package/dist/places/vesta.d.ts +13 -0
  172. package/dist/places/vesta.js +14 -0
  173. package/dist/places.d.ts +354 -0
  174. package/dist/places.js +357 -0
  175. package/dist/plan/element.d.ts +52 -0
  176. package/dist/plan/element.js +258 -0
  177. package/dist/plan/index.d.ts +2 -0
  178. package/dist/plan/index.js +2 -0
  179. package/dist/plan/layout.d.ts +230 -0
  180. package/dist/plan/layout.js +229 -0
  181. package/dist/plan/svg.d.ts +125 -0
  182. package/dist/plan/svg.js +185 -0
  183. package/dist/roadster.d.ts +415 -0
  184. package/dist/roadster.js +496 -0
  185. package/dist/scene/body.js +10 -9
  186. package/dist/scene/painter.d.ts +1 -1
  187. package/dist/scene/painter.js +23 -7
  188. package/dist/scene/textures.d.ts +2 -2
  189. package/dist/space/beside.d.ts +4 -1
  190. package/dist/space/beside.js +47 -6
  191. package/dist/space/covered.d.ts +102 -0
  192. package/dist/space/covered.js +98 -0
  193. package/dist/space/element.d.ts +101 -5
  194. package/dist/space/element.js +474 -30
  195. package/dist/space/frame.d.ts +14 -0
  196. package/dist/space/frame.js +16 -0
  197. package/dist/space/index.d.ts +4 -1
  198. package/dist/space/index.js +4 -1
  199. package/dist/space/regions.d.ts +111 -0
  200. package/dist/space/regions.js +84 -0
  201. package/dist/space/scale.d.ts +2 -1
  202. package/dist/space/scale.js +13 -2
  203. package/dist/space/scene.d.ts +109 -8
  204. package/dist/space/scene.js +313 -37
  205. package/dist/space/travel.d.ts +256 -0
  206. package/dist/space/travel.js +597 -0
  207. package/dist/spacecraft-facts.d.ts +4 -4
  208. package/dist/spacecraft-facts.js +158 -3
  209. package/dist/spacecraft.d.ts +69 -2
  210. package/dist/spacecraft.js +45 -2
  211. package/dist/textures/mimas-1024.webp +0 -0
  212. package/dist/textures/mimas-512.webp +0 -0
  213. package/dist/version.d.ts +1 -1
  214. package/dist/version.js +1 -1
  215. package/package.json +208 -1
@@ -124,6 +124,20 @@ export interface SpaceFrame {
124
124
  /** The minor bodies: Vesta, Pallas, Chiron, Pholus and Halley's comet, from tables fitted to Horizons (outside their years, from osculating elements). */
125
125
  minors: Record<SpaceMinor, Vec3>;
126
126
  }
127
+ /**
128
+ * An ecliptic J2000 vector in the scene's axes (equatorial J2000, y north): what `frameAt` does to every heliocentric place, for a place of your own (the Roadster's, from `/roadster`).
129
+ *
130
+ * @param v - A vector in ecliptic J2000 axes.
131
+ * @returns The same vector in the scene's axes.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * import { eclipticToScene } from "@johnmorrisdotca/wakusei-planets/space";
136
+ *
137
+ * console.log(eclipticToScene([0, 1, 0]).map((n) => n.toFixed(3)).join(", "));
138
+ * ```
139
+ */
140
+ export declare function eclipticToScene(v: Vec3): Vec3;
127
141
  /**
128
142
  * 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.
129
143
  *
@@ -64,6 +64,22 @@ export const SPACE_DWARFS = DWARF_IDS;
64
64
  * ```
65
65
  */
66
66
  export const SPACE_MINORS = MINOR_IDS;
67
+ /**
68
+ * An ecliptic J2000 vector in the scene's axes (equatorial J2000, y north): what `frameAt` does to every heliocentric place, for a place of your own (the Roadster's, from `/roadster`).
69
+ *
70
+ * @param v - A vector in ecliptic J2000 axes.
71
+ * @returns The same vector in the scene's axes.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import { eclipticToScene } from "@johnmorrisdotca/wakusei-planets/space";
76
+ *
77
+ * console.log(eclipticToScene([0, 1, 0]).map((n) => n.toFixed(3)).join(", "));
78
+ * ```
79
+ */
80
+ export function eclipticToScene(v) {
81
+ return scene(v);
82
+ }
67
83
  /** An ecliptic J2000 vector in the scene's axes (equatorial J2000, y north). */
68
84
  const scene = (v) => {
69
85
  const c = Math.cos(OBLIQUITY * RAD);
@@ -1,4 +1,4 @@
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";
1
+ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, eclipticToScene, 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";
@@ -7,3 +7,6 @@ export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, type SpaceKind } from
7
7
  export { besideMoon, BESIDE_RADII, type BesideCamera, type BesideInput } from "./beside.ts";
8
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";
10
+ export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, type CoverArrow, type CoverEntry } from "./covered.ts";
11
+ export { TRAVEL_CLEARANCE, travelArrival, travelPlan, travelPose, type TravelBody, type TravelInput, type TravelKind, type TravelPlan, type TravelSample, type TravelSight, type TravelView } from "./travel.ts";
12
+ export { regionOrbits, regionView, SUN_REGIONS, type SunRegion } from "./regions.ts";
@@ -1,5 +1,5 @@
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_MINORS, SPACE_PLANETS } from "./frame.js";
2
+ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, eclipticToScene, 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";
@@ -8,3 +8,6 @@ export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf } from "./bodies.js";
8
8
  export { besideMoon, BESIDE_RADII } from "./beside.js";
9
9
  export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, spinArrow } from "./arrows.js";
10
10
  export { spinAxis } from "./spin.js";
11
+ export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy } from "./covered.js";
12
+ export { TRAVEL_CLEARANCE, travelArrival, travelPlan, travelPose } from "./travel.js";
13
+ export { regionOrbits, regionView, SUN_REGIONS } from "./regions.js";
@@ -0,0 +1,111 @@
1
+ import type { Vec3 } from "../vec.ts";
2
+ import { type ScaleMode } from "./scale.ts";
3
+ import type { TravelView } from "./travel.ts";
4
+ /**
5
+ * The stages a view steps out through from the Sun, nearest first: each has an `id`, a name in English and Japanese for a button or a step, and the bodies whose orbits make it. The inner planets are Mercury
6
+ * to Mars; the asteroid belt is Vesta, Ceres and Pallas, whose orbits reach its outer edge; the outer planets are Jupiter to Neptune; the Kuiper belt is Pluto and the dwarf planets out to Eris; the whole
7
+ * system is every orbit the space view draws, Sedna's and Halley's among them.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { SUN_REGIONS } from "@johnmorrisdotca/wakusei-planets/space";
12
+ *
13
+ * console.log(SUN_REGIONS.map((region) => `${region.id}: ${region.name.en} / ${region.name.ja}`).join("\n"));
14
+ * ```
15
+ */
16
+ export declare const SUN_REGIONS: readonly [{
17
+ readonly id: "inner-planets";
18
+ readonly name: {
19
+ readonly en: "Inner planets";
20
+ readonly ja: "内太陽系";
21
+ };
22
+ readonly bodies: readonly ["mercury", "venus", "earth", "mars"];
23
+ }, {
24
+ readonly id: "asteroid-belt";
25
+ readonly name: {
26
+ readonly en: "Asteroid belt";
27
+ readonly ja: "小惑星帯";
28
+ };
29
+ readonly bodies: readonly ["vesta", "ceres", "pallas"];
30
+ }, {
31
+ readonly id: "outer-planets";
32
+ readonly name: {
33
+ readonly en: "Outer planets";
34
+ readonly ja: "外太陽系";
35
+ };
36
+ readonly bodies: readonly ["jupiter", "saturn", "uranus", "neptune"];
37
+ }, {
38
+ readonly id: "kuiper-belt";
39
+ readonly name: {
40
+ readonly en: "Kuiper belt";
41
+ readonly ja: "カイパーベルト";
42
+ };
43
+ readonly bodies: readonly ["pluto", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris"];
44
+ }, {
45
+ readonly id: "whole-system";
46
+ readonly name: {
47
+ readonly en: "Whole solar system";
48
+ readonly ja: "太陽系全体";
49
+ };
50
+ readonly bodies: readonly ["earth", "mercury", "venus", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto", "ceres", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris", "sedna", "vesta", "pallas", "chiron", "pholus", "halley"];
51
+ }];
52
+ /**
53
+ * The `id` of one of the stages in `SUN_REGIONS`.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import type { SunRegion } from "@johnmorrisdotca/wakusei-planets/space";
58
+ *
59
+ * const stage: SunRegion = "asteroid-belt";
60
+ * console.log(stage);
61
+ * ```
62
+ */
63
+ export type SunRegion = (typeof SUN_REGIONS)[number]["id"];
64
+ /**
65
+ * The orbit lines of a stage as the space view draws them at `ms`: one line of points for each of its bodies, in the scene's unit (Earth radii from the Earth's centre) for the scale asked, from `planetOrbit`
66
+ * and the same mapping that places the bodies.
67
+ *
68
+ * @param region - The stage's `id`.
69
+ * @param mode - The scale.
70
+ * @param ms - The moment, in milliseconds since the Unix epoch.
71
+ * @param count - How many segments each orbit is cut into.
72
+ * @returns One line for each body of the stage.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * import { regionOrbits } from "@johnmorrisdotca/wakusei-planets/space";
77
+ *
78
+ * const lines = regionOrbits("inner-planets", "compressed", Date.UTC(2026, 10, 11));
79
+ * console.log(lines.length, lines[0]!.length);
80
+ * ```
81
+ */
82
+ export declare function regionOrbits(region: SunRegion, mode: ScaleMode, ms: number, count?: number): Vec3[][];
83
+ /**
84
+ * The view that fits a region: the camera looks at `centre` along `forward` with `up` up (pass the view's own, so stepping out or in does not swing the picture), from the nearest distance at which every point
85
+ * of `orbits` is inside the picture with `margin` of its half width and height to spare (0.9 when left out). `reach` is how far the farthest point is from the centre: give it to the `TravelBody` of the
86
+ * centre so `travelPose` makes the move a straight pull back or push in.
87
+ *
88
+ * @param input - The centre's place, the orbit lines, the picture's width over its height, the direction to look along and its up, and optionally the field of view in degrees (35) and the margin.
89
+ * @returns The camera, and the region's `reach`.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { frameAt, placeSun, regionOrbits, regionView } from "@johnmorrisdotca/wakusei-planets/space";
94
+ *
95
+ * const ms = Date.UTC(2026, 10, 11);
96
+ * const sun = placeSun("compressed", frameAt(ms).sun);
97
+ * const view = regionView({ centre: sun, orbits: regionOrbits("outer-planets", "compressed", ms), aspect: 16 / 9, forward: [0, -0.6, -0.8], up: [0, 0.8, -0.6] });
98
+ * console.log(view.reach.toFixed(0), view.fov);
99
+ * ```
100
+ */
101
+ export declare function regionView(input: {
102
+ centre: Vec3;
103
+ orbits: readonly (readonly Vec3[])[];
104
+ aspect: number;
105
+ forward: Vec3;
106
+ up: Vec3;
107
+ fov?: number;
108
+ margin?: number;
109
+ }): TravelView & {
110
+ reach: number;
111
+ };
@@ -0,0 +1,84 @@
1
+ import { cross, dot, length, sub, unit } from "../vec.js";
2
+ import { frameAt, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
3
+ import { placeAround, placeSun } from "./scale.js";
4
+ /**
5
+ * The stages a view steps out through from the Sun, nearest first: each has an `id`, a name in English and Japanese for a button or a step, and the bodies whose orbits make it. The inner planets are Mercury
6
+ * to Mars; the asteroid belt is Vesta, Ceres and Pallas, whose orbits reach its outer edge; the outer planets are Jupiter to Neptune; the Kuiper belt is Pluto and the dwarf planets out to Eris; the whole
7
+ * system is every orbit the space view draws, Sedna's and Halley's among them.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { SUN_REGIONS } from "@johnmorrisdotca/wakusei-planets/space";
12
+ *
13
+ * console.log(SUN_REGIONS.map((region) => `${region.id}: ${region.name.en} / ${region.name.ja}`).join("\n"));
14
+ * ```
15
+ */
16
+ export const SUN_REGIONS = [
17
+ { id: "inner-planets", name: { en: "Inner planets", ja: "内太陽系" }, bodies: ["mercury", "venus", "earth", "mars"] },
18
+ { id: "asteroid-belt", name: { en: "Asteroid belt", ja: "小惑星帯" }, bodies: ["vesta", "ceres", "pallas"] },
19
+ { id: "outer-planets", name: { en: "Outer planets", ja: "外太陽系" }, bodies: ["jupiter", "saturn", "uranus", "neptune"] },
20
+ { id: "kuiper-belt", name: { en: "Kuiper belt", ja: "カイパーベルト" }, bodies: ["pluto", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris"] },
21
+ { id: "whole-system", name: { en: "Whole solar system", ja: "太陽系全体" }, bodies: ["earth", ...SPACE_PLANETS, ...SPACE_DWARFS, ...SPACE_MINORS] },
22
+ ];
23
+ /**
24
+ * The orbit lines of a stage as the space view draws them at `ms`: one line of points for each of its bodies, in the scene's unit (Earth radii from the Earth's centre) for the scale asked, from `planetOrbit`
25
+ * and the same mapping that places the bodies.
26
+ *
27
+ * @param region - The stage's `id`.
28
+ * @param mode - The scale.
29
+ * @param ms - The moment, in milliseconds since the Unix epoch.
30
+ * @param count - How many segments each orbit is cut into.
31
+ * @returns One line for each body of the stage.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { regionOrbits } from "@johnmorrisdotca/wakusei-planets/space";
36
+ *
37
+ * const lines = regionOrbits("inner-planets", "compressed", Date.UTC(2026, 10, 11));
38
+ * console.log(lines.length, lines[0]!.length);
39
+ * ```
40
+ */
41
+ export function regionOrbits(region, mode, ms, count = 96) {
42
+ const sun = placeSun(mode, frameAt(ms).sun);
43
+ const bodies = SUN_REGIONS.find((entry) => entry.id === region).bodies;
44
+ return bodies.map((id) => planetOrbit(id, ms, count).map((p) => placeAround(mode, sun, p)));
45
+ }
46
+ /**
47
+ * The view that fits a region: the camera looks at `centre` along `forward` with `up` up (pass the view's own, so stepping out or in does not swing the picture), from the nearest distance at which every point
48
+ * of `orbits` is inside the picture with `margin` of its half width and height to spare (0.9 when left out). `reach` is how far the farthest point is from the centre: give it to the `TravelBody` of the
49
+ * centre so `travelPose` makes the move a straight pull back or push in.
50
+ *
51
+ * @param input - The centre's place, the orbit lines, the picture's width over its height, the direction to look along and its up, and optionally the field of view in degrees (35) and the margin.
52
+ * @returns The camera, and the region's `reach`.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { frameAt, placeSun, regionOrbits, regionView } from "@johnmorrisdotca/wakusei-planets/space";
57
+ *
58
+ * const ms = Date.UTC(2026, 10, 11);
59
+ * const sun = placeSun("compressed", frameAt(ms).sun);
60
+ * const view = regionView({ centre: sun, orbits: regionOrbits("outer-planets", "compressed", ms), aspect: 16 / 9, forward: [0, -0.6, -0.8], up: [0, 0.8, -0.6] });
61
+ * console.log(view.reach.toFixed(0), view.fov);
62
+ * ```
63
+ */
64
+ export function regionView(input) {
65
+ const forward = unit(input.forward);
66
+ const lifted = sub(input.up, [forward[0] * dot(input.up, forward), forward[1] * dot(input.up, forward), forward[2] * dot(input.up, forward)]);
67
+ const up = unit(length(lifted) < 1e-9 ? cross(Math.abs(forward[1]) < 0.9 ? cross(forward, [0, 1, 0]) : cross(forward, [1, 0, 0]), forward) : lifted);
68
+ const right = cross(forward, up);
69
+ const fov = input.fov ?? 35;
70
+ const margin = input.margin ?? 0.9;
71
+ const tv = Math.tan((fov / 2) * (Math.PI / 180)) * margin;
72
+ const th = tv * Math.max(1e-3, input.aspect);
73
+ let distance = 0;
74
+ let reach = 0;
75
+ for (const line of input.orbits) {
76
+ for (const point of line) {
77
+ const v = sub(point, input.centre);
78
+ reach = Math.max(reach, length(v));
79
+ // the camera is `distance` back along the line of sight: the point is inside when its offset across and up is within the frame at its depth
80
+ distance = Math.max(distance, Math.abs(dot(v, right)) / th - dot(v, forward), Math.abs(dot(v, up)) / tv - dot(v, forward));
81
+ }
82
+ }
83
+ return { position: [input.centre[0] - forward[0] * distance, input.centre[1] - forward[1] * distance, input.centre[2] - forward[2] * distance], forward, up, fov, reach };
84
+ }
@@ -127,7 +127,8 @@ type BaseBody = "sun" | "earth" | "moon" | SpacePlanet | SpaceDwarf | SpaceMinor
127
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
- * 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.
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,
131
+ * and none is drawn nearer than 1.5 radii or inside the planet's rings (Mimas stays outside Saturn's, Proteus outside Neptune's), so a camera at a moon is never in the ring plane.
131
132
  *
132
133
  * @param mode - The scale.
133
134
  * @param host - The planet or dwarf planet the moon goes round.
@@ -176,7 +176,8 @@ function reachOf(host) {
176
176
  }
177
177
  /**
178
178
  * 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
179
- * 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.
179
+ * 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,
180
+ * and none is drawn nearer than 1.5 radii or inside the planet's rings (Mimas stays outside Saturn's, Proteus outside Neptune's), so a camera at a moon is never in the ring plane.
180
181
  *
181
182
  * @param mode - The scale.
182
183
  * @param host - The planet or dwarf planet the moon goes round.
@@ -198,7 +199,17 @@ export function moonDistance(mode, host, distance) {
198
199
  const space = room(host);
199
200
  if (reach === 0 || reach * radius <= space)
200
201
  return distance;
201
- return Math.min(distance, (space * Math.sqrt(distance / reach)) / radius);
202
+ // from the nearest a moon may be drawn (clear of the globe and its rings) out to the room's edge, in the order the moons are: a moon drawn in the ring plane, or inside the globe, put the camera riding beside it in the rings
203
+ const near = nearestOf(host);
204
+ const far = Math.max(space / radius, near * 1.6);
205
+ return Math.min(distance, near + (far - near) * Math.sqrt(distance / reach));
206
+ }
207
+ /** The nearest a moon is drawn to its planet in a compressed view, in the planet's radii: outside the globe, and outside its rings with a little room, so the moon never sits in the ring plane. */
208
+ function nearestOf(host) {
209
+ const facts = BODIES[host];
210
+ const bands = facts.rings ?? [];
211
+ const ringEdge = bands.length === 0 ? 0 : Math.max(...bands.map((band) => band.to)) / facts.radiusKm;
212
+ return Math.max(1.5, ringEdge * 1.15);
202
213
  }
203
214
  /**
204
215
  * 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
@@ -10,6 +10,8 @@ import { type OrbitArrow } from "./arrows.ts";
10
10
  import { type SpaceFrame, type SpaceVec3 } from "./frame.ts";
11
11
  import { type RideLook } from "./ride.ts";
12
12
  import { type ScaleMode } from "./scale.ts";
13
+ import { type SunRegion } from "./regions.ts";
14
+ import { type TravelInput, type TravelKind, type TravelPlan } from "./travel.ts";
13
15
  /** The parts of three.js the space view uses: the bodies' and a perspective camera. */
14
16
  export type SpaceThree = ThreeParts & Pick<typeof THREE, "PerspectiveCamera">;
15
17
  /** The camera's distance, in radii of the body it looks at, at which that body fills the view at zoom 1. */
@@ -97,6 +99,34 @@ export interface CameraPose {
97
99
  fov: number;
98
100
  valid: boolean;
99
101
  }
102
+ /** The Roadster's path as the view needs it: from `/roadster`, loaded only when the Roadster is shown. */
103
+ export interface RoadsterPath {
104
+ /** Where the car is at a moment, in au from the Sun, ecliptic J2000 axes. */
105
+ positionAu(ms: number): Vec3;
106
+ /** The span the path covers, in milliseconds since 1970. */
107
+ record: {
108
+ start: number;
109
+ end: number;
110
+ };
111
+ /** The car's name, in English and Japanese. */
112
+ name: {
113
+ en: string;
114
+ ja: string;
115
+ };
116
+ }
117
+ /** The orbiters as the view needs them: from `/orbiters`, loaded only when they are shown. */
118
+ export interface OrbiterSet {
119
+ ids: readonly string[];
120
+ centre(id: string): "moon" | "mars";
121
+ /** Kilometres from the body's centre, ecliptic J2000; `null` for a craft with no path. */
122
+ position(id: string, ms: number): Vec3 | null;
123
+ path(id: string, ms: number, points: number): Vec3[];
124
+ status(id: string, ms: number): "tracked" | "predicted" | "modelled" | "none";
125
+ name(id: string): {
126
+ en: string;
127
+ ja: string;
128
+ };
129
+ }
100
130
  export interface SpaceModel {
101
131
  /** Moment shown, milliseconds since the epoch. */
102
132
  time: number;
@@ -121,6 +151,8 @@ export interface SpaceModel {
121
151
  labels: boolean;
122
152
  /** Milliseconds of game time one second of wall time covers (the ephemeris is looked up once per such span). */
123
153
  stepMs: number;
154
+ /** Game seconds for each second of wall time, with its sign (0 when the clock holds): the places a move is worked out for are those the clock reaches by its end. */
155
+ speed: number;
124
156
  /** 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). */
125
157
  focus: BodyId;
126
158
  light: SpaceLight;
@@ -155,8 +187,27 @@ export interface SpaceModel {
155
187
  arrows: Record<string, OrbitArrow[]>;
156
188
  /** Help mode: draw, on the body looked at, the axis it turns about and a curved arrow showing which way it turns. */
157
189
  help: boolean;
190
+ /** Help mode draws its lines whole over the globe (`true`); by default they have depth against the body they are on, so the axis shows only outside the globe and the part of the arrow behind it is hidden. */
191
+ helpThrough: boolean;
158
192
  /** How many arrowheads each orbit line carries: 0 to `MAX_ARROWS_PER_ORBIT`, two by default. */
159
193
  arrowCount: number;
194
+ /** Show the spacecraft in orbit round the Moon and Mars: a dot each on its orbit line, named, once its body is big enough on the screen. Off by default; their paths are loaded when first shown. */
195
+ orbiters: boolean;
196
+ orbiterSet: OrbiterSet | null;
197
+ /** The orbiters at the last draw: how many were drawn, and each drawn one's status. */
198
+ orbitersDrawn: {
199
+ count: number;
200
+ status: Record<string, "tracked" | "predicted" | "modelled" | "none">;
201
+ };
202
+ /** Show Starman and the Roadster: a small marked body on its orbit line, named. Off by default; its path is loaded when it is first shown. */
203
+ roadster: boolean;
204
+ roadsterPath: RoadsterPath | null;
205
+ /** What the Roadster drew at the last draw: whether it was drawn (shown, its path in, and the moment within the record), its place in Earth radii from the Earth's centre, and its radius on the screen. */
206
+ roadsterDrawn: {
207
+ shown: boolean;
208
+ position: [number, number, number] | null;
209
+ radiusPx: number;
210
+ };
160
211
  /** The name written on each body's globe, or null for none; `labelVersion` goes up whenever it (or the language) changes, so each body is told once. */
161
212
  label: PaintLabel | null;
162
213
  labelVersion: number;
@@ -201,26 +252,72 @@ export interface SpaceModel {
201
252
  camera: {
202
253
  position: [number, number, number];
203
254
  fov: number;
255
+ /** The picture's up in the scene's axes (y is the Earth's north): beside a moon it is the planet's own pole laid across the line of sight. */
256
+ up: [number, number, number];
257
+ /** Which way the camera looks, a unit vector in the scene's axes. */
258
+ forward: [number, number, number];
204
259
  };
205
260
  /** The body or point the camera rides along with, or null. */
206
261
  ride: RideState | null;
207
262
  /** Set at each draw: the target of the ride could not be placed, so the ordinary camera was used. */
208
263
  rideLost: boolean;
209
- /** A camera move in progress from where the last draw left it: when it began (ms of the page's clock), how long it takes. */
210
- transition: {
211
- start: number;
264
+ /** A camera move in progress from where the last draw left the camera to the view set up for the new target: see `SpaceTransition`. */
265
+ transition: SpaceTransition | null;
266
+ /** What the move is doing at this draw, or null when the camera is still: the kind and path of the move, its stage, how far along it is (0 to 1), its length, and whether the body left and the one gone to are in the picture. */
267
+ travelling: {
268
+ kind: Exclude<TravelKind, "auto">;
269
+ path: TravelPlan["path"];
270
+ stage: "turn" | "travel" | "arrive";
271
+ progress: number;
212
272
  duration: number;
213
- from: {
214
- p: SpaceVec3;
215
- q: [number, number, number, number];
216
- fov: number;
217
- };
273
+ leaving: boolean;
274
+ destination: boolean;
275
+ } | null;
276
+ /** The stage out from the Sun the view is framed on (`SUN_REGIONS`), or null for an ordinary view of the body looked at. */
277
+ region: SunRegion | null;
278
+ /** The region as the last draw framed it: how far out it reaches from the Sun and how far the camera stood back, in Earth radii. */
279
+ regionDrawn: {
280
+ id: SunRegion;
281
+ reach: number;
282
+ distance: number;
218
283
  } | null;
219
284
  pose: CameraPose;
220
285
  /** Pixels a game-second that riding makes things move on the screen (0 when not riding): the draw rate follows it. */
221
286
  rideMotion: number;
222
287
  ratio(): number;
223
288
  }
289
+ /**
290
+ * A camera move from one view to the next, as the element asks for it: when it began (ms of the page's clock), the length a page asked for (0 to take the plan's own), the pace, the kind of move, where the
291
+ * last draw left the camera, and the body being left and the one gone to (for the path to keep in the picture; null when unknown). The scene builds the path at the move's first draw (`input`, `plan`), from
292
+ * that camera to the view it has just set up for the new target, and then draws `travelPose` of it until the move is over.
293
+ *
294
+ * @example
295
+ * ```ts no-run
296
+ * import type { SpaceTransition } from "@johnmorrisdotca/wakusei-planets/space/scene";
297
+ *
298
+ * const describe = (move: SpaceTransition): string => `${move.kind} from ${move.leaving ?? "?"} to ${move.destination ?? "?"}`;
299
+ * console.log(typeof describe);
300
+ * ```
301
+ */
302
+ export interface SpaceTransition {
303
+ start: number;
304
+ duration: number;
305
+ pace: number;
306
+ kind: TravelKind;
307
+ from: {
308
+ p: SpaceVec3;
309
+ q: [number, number, number, number];
310
+ fov: number;
311
+ };
312
+ leaving: BodyId | null;
313
+ destination: BodyId | null;
314
+ /** How far the region being left reached from the Sun, when the move leaves a stage out from the Sun (a straight push in or pull back then). */
315
+ leavingReach: number;
316
+ input: TravelInput | null;
317
+ plan: TravelPlan | null;
318
+ /** The scene's origin (the place of the body looked at) when the path was worked out: the path is in places relative to it. */
319
+ origin: Vec3;
320
+ }
224
321
  export declare const newSpaceModel: () => SpaceModel;
225
322
  /**
226
323
  * Where a body is on the screen: its centre and its apparent radius, in CSS pixels in the box.
@@ -237,6 +334,10 @@ export interface BodyPlace {
237
334
  x: number;
238
335
  y: number;
239
336
  r: number;
337
+ /** True while the body's name is drawn on its globe (`body-label` on, and the body big enough): the floating name beside it gives way. */
338
+ named?: boolean;
339
+ /** The id of the nearer body whose disc covers this body's place on the screen, when one does. */
340
+ behind?: string;
240
341
  }
241
342
  export interface SpaceDeps {
242
343
  painter: () => WakuseiPainter;