@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
@@ -35,6 +35,8 @@ export interface BesideInput {
35
35
  yaw: number;
36
36
  /** Degrees the camera opens further off that line (a drag down the view is 60). */
37
37
  tilt: number;
38
+ /** The planet's own north pole in the scene's axes (a unit vector): the picture's up is this laid across the line of sight. The scene's +y when not given. */
39
+ north?: Vec3;
38
40
  }
39
41
  /**
40
42
  * The camera `besideMoon` works out: where it is, which way it looks and its up, its vertical field of view in degrees, how far it is from the moon, and the angle in degrees between the moon and the planet as the camera sees them.
@@ -58,7 +60,8 @@ export interface BesideCamera {
58
60
  /**
59
61
  * The camera for a view from near a moon with its planet still in view: beyond the moon on the side away from the planet and a little off the line to it, so the moon is large in the foreground and the planet is behind it,
60
62
  * at the angular size it really has from there. The camera sits on the Sun's side of that line where it can, so the moon shows a lit face. It opens off the line, from 25 degrees, until the two discs no longer touch
61
- * (with 2 degrees to spare), turns the picture so the planet is to one side of the moon, and widens the field of view until both fit the view's narrower side.
63
+ * (with 2 degrees to spare), keeps the planet's own north pole up (laid across the line of sight, so the equator and any rings stay level whatever the date), and widens the field of view until both discs fit the view.
64
+ * Where the Sun lies near the line from the planet through the moon, the camera goes round over the planet's north side a little at a time, rather than hopping to the Sun's other side from one moment to the next.
62
65
  *
63
66
  * @param input - The places and sizes, the view's shape, and the zoom, yaw and tilt.
64
67
  * @returns The camera.
@@ -13,12 +13,23 @@ import { add, cross, dot, length, RAD, scale, unit } from "../vec.js";
13
13
  export const BESIDE_RADII = 5.8;
14
14
  /** The angle off the line from the planet through the moon, in degrees, the camera first tries; it opens wider until the planet clears the moon. */
15
15
  const FIRST_ANGLE = 25;
16
+ /**
17
+ * Inside this (the sine of about 20 degrees) of the Sun lying on the line from the planet through the moon, the camera's side is pushed towards the planet's north side, more the nearer the Sun is to the line (a cosine ramp), so the
18
+ * camera goes round over the top a little at a time rather than hopping to the Sun's other side. One moment is still sharp, as any rule from the Sun's place alone must have one: a Sun about 11 degrees south of the
19
+ * moon's orbit as the moon crosses the line; the moons of Jupiter, whose Sun is always within 3 degrees of their orbits, never meet it.
20
+ */
21
+ const SIDE_BLEND = 0.35;
22
+ /** Inside this (the sine of 10 degrees) of looking along the planet's pole, the up blends towards the scene's +y laid across the line of sight: there is little north left to lay. */
23
+ const POLE_CONE = Math.sin(10 * RAD);
16
24
  const angleBetween = (a, b) => Math.acos(Math.max(-1, Math.min(1, dot(unit(a), unit(b))))) / RAD;
17
25
  const minus = (a, b) => add(a, scale(b, -1));
26
+ /** The part of `v` square to the unit vector `along`. */
27
+ const across = (v, along) => minus(v, scale(along, dot(v, along)));
18
28
  /**
19
29
  * The camera for a view from near a moon with its planet still in view: beyond the moon on the side away from the planet and a little off the line to it, so the moon is large in the foreground and the planet is behind it,
20
30
  * at the angular size it really has from there. The camera sits on the Sun's side of that line where it can, so the moon shows a lit face. It opens off the line, from 25 degrees, until the two discs no longer touch
21
- * (with 2 degrees to spare), turns the picture so the planet is to one side of the moon, and widens the field of view until both fit the view's narrower side.
31
+ * (with 2 degrees to spare), keeps the planet's own north pole up (laid across the line of sight, so the equator and any rings stay level whatever the date), and widens the field of view until both discs fit the view.
32
+ * Where the Sun lies near the line from the planet through the moon, the camera goes round over the planet's north side a little at a time, rather than hopping to the Sun's other side from one moment to the next.
22
33
  *
23
34
  * @param input - The places and sizes, the view's shape, and the zoom, yaw and tilt.
24
35
  * @returns The camera.
@@ -35,7 +46,16 @@ export function besideMoon(input) {
35
46
  const { moon, moonRadius, host, hostRadius } = input;
36
47
  const away = unit(minus(moon, host));
37
48
  const toSun = unit(minus(input.sun, moon));
38
- let side = minus(toSun, scale(away, dot(toSun, away)));
49
+ const north = unit(input.north ?? [0, 1, 0]);
50
+ // the side the camera opens to: the Sun's, so the moon shows a lit face; as the moon crosses the line from the Sun through its planet that side swings round, the faster the nearer the Sun is to the line,
51
+ // so over the last degrees it is pushed towards the planet's north side and the camera goes round over the top a little at a time (the push is 0 at the edge of the band and 1 on the line)
52
+ let side = across(toSun, away);
53
+ const over = (1 - Math.cos((Math.PI * Math.max(0, SIDE_BLEND - length(side))) / SIDE_BLEND)) / 2;
54
+ const northSide = across(north, away);
55
+ if (over > 0 && length(northSide) > 1e-3)
56
+ side = add(side, scale(unit(northSide), over));
57
+ if (length(side) < 1e-3)
58
+ side = cross(away, north);
39
59
  if (length(side) < 1e-3)
40
60
  side = cross(away, [0, 1, 0]);
41
61
  if (length(side) < 1e-3)
@@ -66,11 +86,32 @@ export function besideMoon(input) {
66
86
  // look between the two, and turn the picture so the planet is to the side of the moon, not above or below it
67
87
  const forward = unit(add(toMoon, toHost));
68
88
  const shift = minus(toHost, toMoon);
69
- const across = unit(minus(shift, scale(forward, dot(shift, forward))));
70
- const up = unit(cross(across, forward));
89
+ // north is up, always: the planet's own pole laid across the line of sight, so the picture is never rolled by where the Sun or the moon happens to be, and the planet's equator and rings stay level; a regular
90
+ // moon keeps the camera near the planet's equator, so the pole stays near square to the line of sight. A camera looking nearly along the pole (an odd inclined moon) has little north to lay, and blends to
91
+ // the scene's +y laid across; looking along both, it takes the side the planet is on
92
+ let up = across(north, forward);
93
+ const poleward = Math.max(0, POLE_CONE - length(up)) / POLE_CONE;
94
+ if (poleward > 0) {
95
+ // the +y part is laid the way the pole's part already leans (-y when they would oppose), so the two never cancel and up never collapses inside the cone
96
+ const y = across([0, 1, 0], forward);
97
+ if (length(y) > 1e-6)
98
+ up = add(up, scale(unit(y), dot(up, y) < 0 ? -poleward : poleward));
99
+ }
100
+ if (length(up) < 1e-6)
101
+ up = cross(unit(across(shift, forward)), forward);
102
+ up = unit(up);
71
103
  // both discs fit: the half-angle from the middle to the far edge of each, across and up
72
- const reach = Math.max(angleBetween(forward, toMoon) + moonHalf(position), angleBetween(forward, toHost) + hostHalf(position)) + 3;
73
- const half = Math.max(Math.tan(reach * RAD) / Math.min(1.6, Math.max(0.3, input.aspect)), Math.tan((moonHalf(position) + 3) * RAD));
104
+ // both discs fit, whichever way they lie now that north is up: the view must reach each disc's far edge across (over the aspect) and up, with a little room
105
+ const right = unit(cross(forward, up));
106
+ const need = (direction, halfAngle) => {
107
+ const z = Math.max(1e-9, dot(direction, forward));
108
+ const marginTan = Math.tan((halfAngle + 3) * RAD);
109
+ return { across: Math.abs(dot(direction, right)) / z + marginTan, up: Math.abs(dot(direction, up)) / z + marginTan };
110
+ };
111
+ const moonNeed = need(toMoon, moonHalf(position));
112
+ const hostNeed = need(toHost, hostHalf(position));
113
+ const aspect = Math.min(1.6, Math.max(0.3, input.aspect));
114
+ const half = Math.max(moonNeed.up, hostNeed.up, moonNeed.across / aspect, hostNeed.across / aspect, Math.tan((moonHalf(position) + 3) * RAD));
74
115
  const fov = Math.min(110, Math.max(35, 2 * Math.atan(half) / RAD));
75
116
  return { position, forward, up, fov, distance, separation: spot.separation };
76
117
  }
@@ -0,0 +1,102 @@
1
+ import type { BodyPlace } from "./scene.ts";
2
+ /**
3
+ * A placed body as the covering test sees it: where it is on the screen (CSS pixels), its radius there, and how far it is from the camera (any unit, the same for all).
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import type { CoverEntry } from "@johnmorrisdotca/wakusei-planets/space";
8
+ *
9
+ * const earth: CoverEntry = { id: "earth", x: 300, y: 300, r: 120, distance: 4 };
10
+ * console.log(earth.r);
11
+ * ```
12
+ */
13
+ export interface CoverEntry {
14
+ id: string;
15
+ x: number;
16
+ y: number;
17
+ r: number;
18
+ distance: number;
19
+ }
20
+ /**
21
+ * A disc narrower than this many CSS pixels of radius covers nothing: a dot hides no name.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { COVER_MIN_PX } from "@johnmorrisdotca/wakusei-planets/space";
26
+ *
27
+ * console.log(COVER_MIN_PX);
28
+ * ```
29
+ */
30
+ export declare const COVER_MIN_PX = 6;
31
+ /**
32
+ * Which body, if any, covers each: the nearest body whose disc on the screen holds the body's place and which is nearer the camera than it is. A body is never covered by itself, nor by a disc
33
+ * narrower than `COVER_MIN_PX`.
34
+ *
35
+ * @param entries - The placed bodies.
36
+ * @returns For each covered body's id, the id of the body covering it.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { coveredBy } from "@johnmorrisdotca/wakusei-planets/space";
41
+ *
42
+ * const behind = coveredBy([
43
+ * { id: "earth", x: 300, y: 300, r: 120, distance: 4 },
44
+ * { id: "uranus", x: 340, y: 280, r: 1, distance: 60_000 },
45
+ * { id: "moon", x: 80, y: 300, r: 30, distance: 3 },
46
+ * ]);
47
+ * console.log(JSON.stringify([...behind]));
48
+ * ```
49
+ */
50
+ export declare function coveredBy(entries: readonly CoverEntry[]): Map<string, string>;
51
+ /**
52
+ * One quiet arrow: outside the covering body's disc, on the side nearest the bodies behind it, pointing in behind it, with the surest of them named and the rest counted.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import type { CoverArrow } from "@johnmorrisdotca/wakusei-planets/space";
57
+ *
58
+ * const arrow: CoverArrow = { cover: "earth", lead: "uranus", bodies: ["uranus", "ariel"], x: 426, y: 280, angle: 180 };
59
+ * console.log(arrow.bodies.length);
60
+ * ```
61
+ */
62
+ export interface CoverArrow {
63
+ /** The body whose disc covers them. */
64
+ cover: string;
65
+ /** The surest of the bodies behind (the lowest rank): the arrow is named for it and a press goes to it. */
66
+ lead: string;
67
+ /** Every body behind, the lead first. */
68
+ bodies: string[];
69
+ /** Where the arrow's tip sits, in CSS pixels in the box: just outside the disc's edge. */
70
+ x: number;
71
+ y: number;
72
+ /** The way the arrow points, in degrees clockwise from pointing right: into the disc, towards the bodies behind it. */
73
+ angle: number;
74
+ }
75
+ /**
76
+ * How far outside the disc's edge the arrow's tip sits, in CSS pixels.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * import { COVER_ARROW_GAP } from "@johnmorrisdotca/wakusei-planets/space";
81
+ *
82
+ * console.log(COVER_ARROW_GAP);
83
+ * ```
84
+ */
85
+ export declare const COVER_ARROW_GAP = 6;
86
+ /**
87
+ * The arrows for the bodies behind others: one for each covering body, placed on its edge on the side nearest the surest body behind it, pointing in. Bodies behind the same disc share the arrow,
88
+ * the lead named and the others counted by the host.
89
+ *
90
+ * @param places - Where each body is on the screen, with `behind` set for a covered one (from `coveredBy`), or `null` for one off the screen.
91
+ * @param rank - How sure a body's name is (lower is surer): the lead of a group.
92
+ * @returns The arrows, in the order of their covering bodies' ids.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * import { coverArrows } from "@johnmorrisdotca/wakusei-planets/space";
97
+ *
98
+ * const arrows = coverArrows({ earth: { x: 300, y: 300, r: 120 }, uranus: { x: 340, y: 280, r: 1, behind: "earth" }, ariel: { x: 342, y: 281, r: 0.1, behind: "earth" } }, (id) => (id === "uranus" ? 2 : 4));
99
+ * console.log(JSON.stringify(arrows.map((a) => [a.lead, a.bodies.length, Math.round(a.x), Math.round(a.y), Math.round(a.angle)])));
100
+ * ```
101
+ */
102
+ export declare function coverArrows(places: Readonly<Record<string, BodyPlace | null>>, rank: (id: string) => number): CoverArrow[];
@@ -0,0 +1,98 @@
1
+ /**
2
+ * A disc narrower than this many CSS pixels of radius covers nothing: a dot hides no name.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { COVER_MIN_PX } from "@johnmorrisdotca/wakusei-planets/space";
7
+ *
8
+ * console.log(COVER_MIN_PX);
9
+ * ```
10
+ */
11
+ export const COVER_MIN_PX = 6;
12
+ /**
13
+ * Which body, if any, covers each: the nearest body whose disc on the screen holds the body's place and which is nearer the camera than it is. A body is never covered by itself, nor by a disc
14
+ * narrower than `COVER_MIN_PX`.
15
+ *
16
+ * @param entries - The placed bodies.
17
+ * @returns For each covered body's id, the id of the body covering it.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { coveredBy } from "@johnmorrisdotca/wakusei-planets/space";
22
+ *
23
+ * const behind = coveredBy([
24
+ * { id: "earth", x: 300, y: 300, r: 120, distance: 4 },
25
+ * { id: "uranus", x: 340, y: 280, r: 1, distance: 60_000 },
26
+ * { id: "moon", x: 80, y: 300, r: 30, distance: 3 },
27
+ * ]);
28
+ * console.log(JSON.stringify([...behind]));
29
+ * ```
30
+ */
31
+ export function coveredBy(entries) {
32
+ const behind = new Map();
33
+ for (const body of entries) {
34
+ let cover;
35
+ for (const other of entries) {
36
+ if (other === body || other.r < COVER_MIN_PX || other.distance >= body.distance)
37
+ continue;
38
+ if (Math.hypot(body.x - other.x, body.y - other.y) >= other.r)
39
+ continue;
40
+ if (cover === undefined || other.distance < cover.distance)
41
+ cover = other;
42
+ }
43
+ if (cover !== undefined)
44
+ behind.set(body.id, cover.id);
45
+ }
46
+ return behind;
47
+ }
48
+ /**
49
+ * How far outside the disc's edge the arrow's tip sits, in CSS pixels.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { COVER_ARROW_GAP } from "@johnmorrisdotca/wakusei-planets/space";
54
+ *
55
+ * console.log(COVER_ARROW_GAP);
56
+ * ```
57
+ */
58
+ export const COVER_ARROW_GAP = 6;
59
+ /**
60
+ * The arrows for the bodies behind others: one for each covering body, placed on its edge on the side nearest the surest body behind it, pointing in. Bodies behind the same disc share the arrow,
61
+ * the lead named and the others counted by the host.
62
+ *
63
+ * @param places - Where each body is on the screen, with `behind` set for a covered one (from `coveredBy`), or `null` for one off the screen.
64
+ * @param rank - How sure a body's name is (lower is surer): the lead of a group.
65
+ * @returns The arrows, in the order of their covering bodies' ids.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * import { coverArrows } from "@johnmorrisdotca/wakusei-planets/space";
70
+ *
71
+ * const arrows = coverArrows({ earth: { x: 300, y: 300, r: 120 }, uranus: { x: 340, y: 280, r: 1, behind: "earth" }, ariel: { x: 342, y: 281, r: 0.1, behind: "earth" } }, (id) => (id === "uranus" ? 2 : 4));
72
+ * console.log(JSON.stringify(arrows.map((a) => [a.lead, a.bodies.length, Math.round(a.x), Math.round(a.y), Math.round(a.angle)])));
73
+ * ```
74
+ */
75
+ export function coverArrows(places, rank) {
76
+ const groups = new Map();
77
+ for (const [id, at] of Object.entries(places)) {
78
+ if (at === null || at.behind === undefined || places[at.behind] === null || places[at.behind] === undefined)
79
+ continue;
80
+ const list = groups.get(at.behind) ?? [];
81
+ list.push(id);
82
+ groups.set(at.behind, list);
83
+ }
84
+ const arrows = [];
85
+ for (const cover of [...groups.keys()].sort()) {
86
+ const bodies = groups.get(cover).sort((a, b) => rank(a) - rank(b) || (a < b ? -1 : 1));
87
+ const lead = bodies[0];
88
+ const disc = places[cover];
89
+ const at = places[lead];
90
+ const dx = at.x - disc.x;
91
+ const dy = at.y - disc.y;
92
+ const length = Math.hypot(dx, dy);
93
+ const [ux, uy] = length < 1e-6 ? [1, 0] : [dx / length, dy / length];
94
+ const reach = disc.r + COVER_ARROW_GAP;
95
+ arrows.push({ cover, lead, bodies, x: disc.x + ux * reach, y: disc.y + uy * reach, angle: (Math.atan2(-uy, -ux) * 180) / Math.PI });
96
+ }
97
+ return arrows;
98
+ }
@@ -9,6 +9,8 @@ import { setThreeLoader } from "../scene/shared.ts";
9
9
  import { type SpacePlanet } from "./frame.ts";
10
10
  import { type ScaleMode } from "./scale.ts";
11
11
  import type { RideLook } from "./ride.ts";
12
+ import { type SunRegion } from "./regions.ts";
13
+ import { type TravelKind } from "./travel.ts";
12
14
  import { SPACE_BODIES, type BodyPlace, type RidePoint, type RideState, type RideTarget, type SpaceBody, type SpaceLight } from "./scene.ts";
13
15
  export { setThreeLoader, SPACE_BODIES, type RidePoint, type RideTarget, type SpaceBody, type SpaceLight };
14
16
  /** Where a body is on the screen, in CSS pixels in the element: its centre and its radius. */
@@ -80,6 +82,10 @@ export interface RideOptions {
80
82
  distanceKm?: number;
81
83
  around?: SpaceBody;
82
84
  smooth?: boolean;
85
+ /** How the camera moves there: the view's `transition` by default. */
86
+ transition?: TravelKind;
87
+ /** How long the move takes, in milliseconds: the plan's own length by default. */
88
+ duration?: number;
83
89
  }
84
90
  /**
85
91
  * What the camera is riding along with now: the target, the body it goes round, how (`from` or `follow`), where it looks, and the distance kept for a point.
@@ -158,6 +164,43 @@ export declare class WakuseiSpace extends HTMLElement {
158
164
  set scaleNames(value: Partial<Record<ScaleMode, string>>);
159
165
  get labels(): boolean;
160
166
  set labels(value: boolean);
167
+ /**
168
+ * How the camera moves from one view to the next: `turn-travel` (the default: turn beside the body being left until the next is in the picture, then travel to it, never an empty frame), `direct` (a straight
169
+ * eased glide), `look-back` (straight, watching the body left until the end), `auto` (`turn-travel`), `cut` (no move). The attribute `transition` says the same; `goTo` and `ride` take one for a single move. A
170
+ * reader who asked for reduced motion always gets `cut`.
171
+ */
172
+ get transition(): TravelKind;
173
+ set transition(value: TravelKind);
174
+ /** How slow the moves are: the plan's own length times this (1 by default; 2 is twice as slow). The attribute `pace` says the same; `goTo` and `ride` take `duration` in milliseconds for a single move instead. */
175
+ get pace(): number;
176
+ set pace(value: number);
177
+ /** The stage out from the Sun the view is framed on (`inner-planets`, `asteroid-belt`, `outer-planets`, `kuiper-belt`, `whole-system`), or null for a view of a body. */
178
+ get region(): SunRegion | null;
179
+ /**
180
+ * Show the spacecraft in orbit round the Moon and Mars (the attribute `orbiters`; off by default): each a small dot where `/orbiters` puts it on the date shown, scaled with its body, on its orbit line, with its
181
+ * name beside it in the page's language, once the body is at least 24 CSS pixels in radius on the screen. A modelled or predicted path is drawn dim; a craft with no path is not drawn. The paths (a 9 kB module)
182
+ * are loaded the first time they are shown. `stats.orbiters` says what was drawn and each one's status.
183
+ */
184
+ get orbiters(): boolean;
185
+ set orbiters(value: boolean);
186
+ /**
187
+ * Show Starman and the Tesla Roadster (the attribute `roadster`; off by default): a small marked body where `/roadster` puts the car on the date shown, on its orbit line (about one trip round the Sun), with its name
188
+ * (`Starman`, `スターマン`) beside it, from the launch in 2018 to the end of 2035. Its path (a 20 kB table) is loaded the first time it is shown, and never when it is not. `stats.roadster` says what was drawn.
189
+ */
190
+ get roadster(): boolean;
191
+ set roadster(value: boolean);
192
+ /**
193
+ * What a body behind another gets (the attribute `covered`): `name` (the default) draws its floating name and ring over the nearer body's disc as always; `arrow` draws instead one small quiet arrow just outside the
194
+ * disc's edge on the side nearest the hidden body, pointing in behind it, with the surest hidden body's name beside it and the others counted (`Uranus +4`); a press on it goes to that body. The arrow goes as the body comes out.
195
+ */
196
+ get covered(): "name" | "arrow";
197
+ set covered(value: "name" | "arrow");
198
+ /**
199
+ * Keep a body's floating name and dot while its name is drawn on its globe (the attribute `labels-always`; off by default). Off, a body that carries its drawn name (`body-label` on, and the body at least 24 CSS pixels in
200
+ * radius) fades its floating name and dot out, and they fade back when it shrinks below that; bodies with no drawn name keep their floating names.
201
+ */
202
+ get labelsAlways(): boolean;
203
+ set labelsAlways(value: boolean);
161
204
  get orbits(): boolean;
162
205
  set orbits(value: boolean);
163
206
  /** How many small arrowheads each orbit line carries to show which way the body goes: 2 by default, at most 4, 0 for none (the attribute `arrows` says the same). Anything else is made a whole number in that range. */
@@ -165,10 +208,16 @@ export declare class WakuseiSpace extends HTMLElement {
165
208
  set arrows(value: number);
166
209
  /**
167
210
  * Help mode (the `help` attribute; off by default): on the body looked at, a line along its axis and a curved arrow round it showing which way it spins, by the right-hand rule about the axis it really turns about, so it is
168
- * right for Venus and Uranus, which turn backwards, and for Uranus on its side. It is about learning, so the arrow is drawn over the body.
211
+ * right for Venus and Uranus, which turn backwards, and for Uranus on its side. By default the lines are hidden where the globe covers them (`helpThrough` draws them whole over it).
169
212
  */
170
213
  get help(): boolean;
171
214
  set help(value: boolean);
215
+ /**
216
+ * Whether help mode's lines are drawn whole over the globe, as they were (the attribute `help-through`; off by default). Off, they have depth against the body they are on: the axis runs into the near pole and comes out of the
217
+ * far pole only where that end is not behind the globe, and the part of the curved arrow that passes behind the globe is hidden.
218
+ */
219
+ get helpThrough(): boolean;
220
+ set helpThrough(value: boolean);
172
221
  /** How the bodies are drawn: `realistic` (shaded from the body's real colours and features) or `painted` (public-domain surface maps). */
173
222
  get look(): "realistic" | "painted";
174
223
  set look(value: "realistic" | "painted");
@@ -200,17 +249,34 @@ export declare class WakuseiSpace extends HTMLElement {
200
249
  next: BodyInfo;
201
250
  };
202
251
  /**
203
- * Go to a body: it becomes the middle of the view and the zoom brings it whole into view (`zoom`, 1 by default; a planet's `-moons` preset for its system), gliding there from where the camera is unless `smooth` is
204
- * false or the reader asked for reduced motion. `wakusei-hop` tells the page where it went and where the next and previous hops lead. A name in any case, in English or Japanese, works.
252
+ * Go to a body: it becomes the middle of the view and the zoom brings it whole into view (`zoom`, 1 by default; a planet's `-moons` preset for its system), travelling there from where the camera is (`transition`,
253
+ * the view's own by default; `duration` in milliseconds, the plan's own by default) unless `smooth` is false or the reader asked for reduced motion. The travel arrives from the side it comes from, moved round
254
+ * towards the Sun where that side would show the body mostly dark, so the way in is straight: the controls' yaw and tilt are set to that side. A stage out from the Sun (`inner-planets`, `asteroid-belt`,
255
+ * `outer-planets`, `kuiper-belt`, `whole-system`) is a target too: the Sun is looked at and the camera stands back until the stage's orbits are all in the picture, with the stage's name shown. `wakusei-hop`
256
+ * tells the page where it went and where the next and previous hops lead. A name in any case, in English or Japanese, works.
205
257
  *
206
- * @param target - A body's name (`"saturn"`, `"Saturn"`, `"土星"`).
207
- * @param options - `smooth` (true by default) and `zoom` (1 by default).
258
+ * @param target - A body's name (`"saturn"`, `"Saturn"`, `"土星"`) or a stage's id.
259
+ * @param options - `smooth` (true by default), `zoom` (1 by default), `transition` and `duration`.
208
260
  * @returns Whether the view can go there.
209
261
  */
210
262
  goTo(target: BodyId | string, options?: {
211
263
  smooth?: boolean;
212
264
  zoom?: number;
265
+ transition?: TravelKind;
266
+ duration?: number;
213
267
  }): boolean;
268
+ /** The next stage out from the Sun from where the view is (the first stage from a body), with the same move as `goTo`; null, and nothing done, when the view is already at the widest stage. */
269
+ stepOut(options?: {
270
+ smooth?: boolean;
271
+ transition?: TravelKind;
272
+ duration?: number;
273
+ }): SunRegion | null;
274
+ /** The next stage in towards the Sun from the stage the view is at, or the Sun itself (`"sun"`, zoom 1) from the first stage; null, and nothing done, when the view is not at a stage. */
275
+ stepIn(options?: {
276
+ smooth?: boolean;
277
+ transition?: TravelKind;
278
+ duration?: number;
279
+ }): SunRegion | "sun" | null;
214
280
  /** Go to the next body in the order of `bodyList()` (the Sun, Mercury, Venus, the Earth, the Moon, Mars, Phobos, Deimos, Ceres, Jupiter, its moons, and on), round to the Sun after the last. */
215
281
  next(options?: {
216
282
  smooth?: boolean;
@@ -286,6 +352,8 @@ export declare class WakuseiSpace extends HTMLElement {
286
352
  camera: {
287
353
  position: [number, number, number];
288
354
  fov: number;
355
+ up: [number, number, number];
356
+ forward: [number, number, number];
289
357
  };
290
358
  /** What the painter has made at the last draw: the bodies with a drawing, the moons shown round a planet that is near, and the moons made and not yet let go. */
291
359
  bodies: {
@@ -306,6 +374,23 @@ export declare class WakuseiSpace extends HTMLElement {
306
374
  lost: boolean;
307
375
  gliding: boolean;
308
376
  };
377
+ /** The camera's move at the last draw, or null when it is still: its kind and path, its stage, how far along it is (0 to 1), its length in milliseconds, and whether the body left and the one gone to are in the picture. */
378
+ travelling: {
379
+ kind: string;
380
+ path: string;
381
+ stage: "turn" | "travel" | "arrive";
382
+ progress: number;
383
+ duration: number;
384
+ leaving: boolean;
385
+ destination: boolean;
386
+ } | null;
387
+ /** The stage out from the Sun the view is framed on, or null: its id and name, how far it reaches from the Sun and how far back the camera stands, in Earth radii. */
388
+ region: {
389
+ id: string;
390
+ name: string;
391
+ reach: number;
392
+ distance: number;
393
+ } | null;
309
394
  /** The data door: the small bodies in the one instanced draw, and what the sources have done (tile loads started, failed and refused, bytes held, records read). */
310
395
  door: {
311
396
  points: number;
@@ -341,6 +426,17 @@ export declare class WakuseiSpace extends HTMLElement {
341
426
  turn: number;
342
427
  } | null;
343
428
  };
429
+ /** Starman and the Roadster at the last draw: whether the car was drawn (shown, its path in, the moment within 2018 to 2035), its place in Earth radii from the Earth's centre, and its radius on the screen in CSS pixels. */
430
+ roadster: {
431
+ shown: boolean;
432
+ position: [number, number, number] | null;
433
+ radiusPx: number;
434
+ };
435
+ /** The orbiters at the last draw: how many dots were drawn (their body big enough on the screen), and each drawn craft's status (`tracked`, `predicted`, `modelled`). */
436
+ orbiters: {
437
+ count: number;
438
+ status: Record<string, "tracked" | "predicted" | "modelled" | "none">;
439
+ };
344
440
  };
345
441
  /** Where a body is on the screen now: its centre and radius in CSS pixels in the element, or `null` when it is behind the camera or not drawn. */
346
442
  placeOf(id: BodyId): BodyPlace | null;