@johnmorrisdotca/wakusei-planets 0.34.0 → 0.35.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.
- package/CHANGELOG.md +18 -0
- package/NOTICE.md +48 -0
- package/README.md +21 -3
- package/dist/approaches.d.ts +276 -0
- package/dist/approaches.js +255 -0
- package/dist/asteroids.d.ts +397 -0
- package/dist/asteroids.js +338 -0
- package/dist/comets.d.ts +316 -0
- package/dist/comets.js +404 -0
- package/dist/craft/bepicolombo.d.ts +1 -0
- package/dist/craft/bepicolombo.js +923 -0
- package/dist/craft/europaclipper.d.ts +1 -0
- package/dist/craft/europaclipper.js +342 -0
- package/dist/craft/hayabusa2.d.ts +1 -0
- package/dist/craft/hayabusa2.js +73 -0
- package/dist/craft/juice.d.ts +1 -0
- package/dist/craft/juice.js +40 -0
- package/dist/craft/lucy.d.ts +1 -0
- package/dist/craft/lucy.js +42 -0
- package/dist/craft/osirisapex.d.ts +1 -0
- package/dist/craft/osirisapex.js +69 -0
- package/dist/craft/psyche.d.ts +1 -0
- package/dist/craft/psyche.js +30 -0
- package/dist/craft/solarorbiter.d.ts +1 -0
- package/dist/craft/solarorbiter.js +94 -0
- package/dist/data/approaches.d.ts +17 -0
- package/dist/data/approaches.js +4192 -0
- package/dist/data/asteroids.d.ts +3 -0
- package/dist/data/asteroids.js +107 -0
- package/dist/data/comets.d.ts +2 -0
- package/dist/data/comets.js +36 -0
- package/dist/data/places-67p.d.ts +27 -0
- package/dist/data/places-67p.js +2 -0
- package/dist/data/places-ariel.d.ts +602 -0
- package/dist/data/places-ariel.js +27 -0
- package/dist/data/places-bennu.d.ts +25 -0
- package/dist/data/places-bennu.js +2 -0
- package/dist/data/places-callisto.d.ts +3547 -0
- package/dist/data/places-callisto.js +155 -0
- package/dist/data/places-ceres.d.ts +3436 -0
- package/dist/data/places-ceres.js +150 -0
- package/dist/data/places-charon.d.ts +349 -0
- package/dist/data/places-charon.js +16 -0
- package/dist/data/places-dimorphos.d.ts +23 -0
- package/dist/data/places-dimorphos.js +2 -0
- package/dist/data/places-dione.d.ts +2258 -0
- package/dist/data/places-dione.js +99 -0
- package/dist/data/places-enceladus.d.ts +2009 -0
- package/dist/data/places-enceladus.js +88 -0
- package/dist/data/places-eros.d.ts +26 -0
- package/dist/data/places-eros.js +2 -0
- package/dist/data/places-europa.d.ts +2977 -0
- package/dist/data/places-europa.js +130 -0
- package/dist/data/places-ganymede.d.ts +4518 -0
- package/dist/data/places-ganymede.js +197 -0
- package/dist/data/places-iapetus.d.ts +1616 -0
- package/dist/data/places-iapetus.js +71 -0
- package/dist/data/places-io.d.ts +6012 -0
- package/dist/data/places-io.js +262 -0
- package/dist/data/places-jupiter.d.ts +46 -0
- package/dist/data/places-jupiter.js +3 -0
- package/dist/data/places-mars.d.ts +20701 -0
- package/dist/data/places-mars.js +942 -0
- package/dist/data/places-mercury.d.ts +9256 -0
- package/dist/data/places-mercury.js +403 -0
- package/dist/data/places-mimas.d.ts +968 -0
- package/dist/data/places-mimas.js +43 -0
- package/dist/data/places-miranda.d.ts +419 -0
- package/dist/data/places-miranda.js +19 -0
- package/dist/data/places-moon.d.ts +18849 -0
- package/dist/data/places-moon.js +861 -0
- package/dist/data/places-oberon.d.ts +235 -0
- package/dist/data/places-oberon.js +11 -0
- package/dist/data/places-pluto.d.ts +1687 -0
- package/dist/data/places-pluto.js +74 -0
- package/dist/data/places-rhea.d.ts +3317 -0
- package/dist/data/places-rhea.js +145 -0
- package/dist/data/places-ryugu.d.ts +87 -0
- package/dist/data/places-ryugu.js +5 -0
- package/dist/data/places-saturn.d.ts +25 -0
- package/dist/data/places-saturn.js +2 -0
- package/dist/data/places-tempel-1.d.ts +25 -0
- package/dist/data/places-tempel-1.js +2 -0
- package/dist/data/places-tethys.d.ts +1222 -0
- package/dist/data/places-tethys.js +54 -0
- package/dist/data/places-titan.d.ts +7031 -0
- package/dist/data/places-titan.js +306 -0
- package/dist/data/places-titania.d.ts +418 -0
- package/dist/data/places-titania.js +19 -0
- package/dist/data/places-triton.d.ts +1457 -0
- package/dist/data/places-triton.js +64 -0
- package/dist/data/places-umbriel.d.ts +303 -0
- package/dist/data/places-umbriel.js +14 -0
- package/dist/data/places-venus.d.ts +9290 -0
- package/dist/data/places-venus.js +405 -0
- package/dist/data/places-vesta.d.ts +2444 -0
- package/dist/data/places-vesta.js +107 -0
- package/dist/data/roadster.d.ts +8 -0
- package/dist/data/roadster.js +686 -0
- package/dist/element.js +17 -3
- package/dist/places/67p.d.ts +13 -0
- package/dist/places/67p.js +14 -0
- package/dist/places/ariel.d.ts +13 -0
- package/dist/places/ariel.js +14 -0
- package/dist/places/bennu.d.ts +13 -0
- package/dist/places/bennu.js +14 -0
- package/dist/places/callisto.d.ts +13 -0
- package/dist/places/callisto.js +14 -0
- package/dist/places/ceres.d.ts +13 -0
- package/dist/places/ceres.js +14 -0
- package/dist/places/charon.d.ts +13 -0
- package/dist/places/charon.js +14 -0
- package/dist/places/dimorphos.d.ts +13 -0
- package/dist/places/dimorphos.js +14 -0
- package/dist/places/dione.d.ts +13 -0
- package/dist/places/dione.js +14 -0
- package/dist/places/enceladus.d.ts +13 -0
- package/dist/places/enceladus.js +14 -0
- package/dist/places/eros.d.ts +13 -0
- package/dist/places/eros.js +14 -0
- package/dist/places/europa.d.ts +13 -0
- package/dist/places/europa.js +14 -0
- package/dist/places/ganymede.d.ts +13 -0
- package/dist/places/ganymede.js +14 -0
- package/dist/places/iapetus.d.ts +13 -0
- package/dist/places/iapetus.js +14 -0
- package/dist/places/io.d.ts +13 -0
- package/dist/places/io.js +14 -0
- package/dist/places/jupiter.d.ts +13 -0
- package/dist/places/jupiter.js +14 -0
- package/dist/places/mars.d.ts +12 -0
- package/dist/places/mars.js +13 -0
- package/dist/places/mercury.d.ts +13 -0
- package/dist/places/mercury.js +14 -0
- package/dist/places/mimas.d.ts +13 -0
- package/dist/places/mimas.js +14 -0
- package/dist/places/miranda.d.ts +13 -0
- package/dist/places/miranda.js +14 -0
- package/dist/places/moon.d.ts +12 -0
- package/dist/places/moon.js +13 -0
- package/dist/places/oberon.d.ts +13 -0
- package/dist/places/oberon.js +14 -0
- package/dist/places/pluto.d.ts +13 -0
- package/dist/places/pluto.js +14 -0
- package/dist/places/rhea.d.ts +13 -0
- package/dist/places/rhea.js +14 -0
- package/dist/places/ryugu.d.ts +13 -0
- package/dist/places/ryugu.js +14 -0
- package/dist/places/saturn.d.ts +13 -0
- package/dist/places/saturn.js +14 -0
- package/dist/places/tempel-1.d.ts +13 -0
- package/dist/places/tempel-1.js +14 -0
- package/dist/places/tethys.d.ts +13 -0
- package/dist/places/tethys.js +14 -0
- package/dist/places/titan.d.ts +13 -0
- package/dist/places/titan.js +14 -0
- package/dist/places/titania.d.ts +13 -0
- package/dist/places/titania.js +14 -0
- package/dist/places/triton.d.ts +13 -0
- package/dist/places/triton.js +14 -0
- package/dist/places/umbriel.d.ts +13 -0
- package/dist/places/umbriel.js +14 -0
- package/dist/places/venus.d.ts +13 -0
- package/dist/places/venus.js +14 -0
- package/dist/places/vesta.d.ts +13 -0
- package/dist/places/vesta.js +14 -0
- package/dist/places.d.ts +354 -0
- package/dist/places.js +357 -0
- package/dist/plan/element.d.ts +52 -0
- package/dist/plan/element.js +258 -0
- package/dist/plan/index.d.ts +2 -0
- package/dist/plan/index.js +2 -0
- package/dist/plan/layout.d.ts +230 -0
- package/dist/plan/layout.js +229 -0
- package/dist/plan/svg.d.ts +125 -0
- package/dist/plan/svg.js +185 -0
- package/dist/roadster.d.ts +415 -0
- package/dist/roadster.js +496 -0
- package/dist/scene/body.js +10 -9
- package/dist/scene/painter.d.ts +1 -1
- package/dist/scene/painter.js +23 -7
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/beside.d.ts +4 -1
- package/dist/space/beside.js +47 -6
- package/dist/space/covered.d.ts +102 -0
- package/dist/space/covered.js +98 -0
- package/dist/space/element.d.ts +21 -1
- package/dist/space/element.js +126 -11
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +1 -0
- package/dist/space/scale.d.ts +2 -1
- package/dist/space/scale.js +13 -2
- package/dist/space/scene.d.ts +10 -0
- package/dist/space/scene.js +45 -22
- package/dist/spacecraft-facts.d.ts +4 -4
- package/dist/spacecraft-facts.js +158 -3
- package/dist/spacecraft.d.ts +69 -2
- package/dist/spacecraft.js +45 -2
- package/dist/textures/mimas-1024.webp +0 -0
- package/dist/textures/mimas-512.webp +0 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +203 -1
package/dist/space/beside.d.ts
CHANGED
|
@@ -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),
|
|
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.
|
package/dist/space/beside.js
CHANGED
|
@@ -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),
|
|
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
|
-
|
|
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
|
-
|
|
70
|
-
|
|
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
|
-
|
|
73
|
-
const
|
|
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
|
+
}
|
package/dist/space/element.d.ts
CHANGED
|
@@ -158,6 +158,18 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
158
158
|
set scaleNames(value: Partial<Record<ScaleMode, string>>);
|
|
159
159
|
get labels(): boolean;
|
|
160
160
|
set labels(value: boolean);
|
|
161
|
+
/**
|
|
162
|
+
* 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
|
|
163
|
+
* 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.
|
|
164
|
+
*/
|
|
165
|
+
get covered(): "name" | "arrow";
|
|
166
|
+
set covered(value: "name" | "arrow");
|
|
167
|
+
/**
|
|
168
|
+
* 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
|
|
169
|
+
* 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.
|
|
170
|
+
*/
|
|
171
|
+
get labelsAlways(): boolean;
|
|
172
|
+
set labelsAlways(value: boolean);
|
|
161
173
|
get orbits(): boolean;
|
|
162
174
|
set orbits(value: boolean);
|
|
163
175
|
/** 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 +177,16 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
165
177
|
set arrows(value: number);
|
|
166
178
|
/**
|
|
167
179
|
* 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.
|
|
180
|
+
* 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
181
|
*/
|
|
170
182
|
get help(): boolean;
|
|
171
183
|
set help(value: boolean);
|
|
184
|
+
/**
|
|
185
|
+
* 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
|
|
186
|
+
* 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.
|
|
187
|
+
*/
|
|
188
|
+
get helpThrough(): boolean;
|
|
189
|
+
set helpThrough(value: boolean);
|
|
172
190
|
/** How the bodies are drawn: `realistic` (shaded from the body's real colours and features) or `painted` (public-domain surface maps). */
|
|
173
191
|
get look(): "realistic" | "painted";
|
|
174
192
|
set look(value: "realistic" | "painted");
|
|
@@ -286,6 +304,8 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
286
304
|
camera: {
|
|
287
305
|
position: [number, number, number];
|
|
288
306
|
fov: number;
|
|
307
|
+
up: [number, number, number];
|
|
308
|
+
forward: [number, number, number];
|
|
289
309
|
};
|
|
290
310
|
/** 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
311
|
bodies: {
|
package/dist/space/element.js
CHANGED
|
@@ -6,6 +6,7 @@ import { arrowCount } from "./arrows.js";
|
|
|
6
6
|
import { createGameClock } from "./clock.js";
|
|
7
7
|
import { bodyKindOf, findBody, hopFrom, hostOf, HOP_ORDER } from "./bodies.js";
|
|
8
8
|
import { chooseLabels } from "./labels.js";
|
|
9
|
+
import { coverArrows } from "./covered.js";
|
|
9
10
|
import { createPainter } from "../scene/painter.js";
|
|
10
11
|
import { NAME_LABEL_ATTRIBUTES, readNameLabel } from "../scene/name-label.js";
|
|
11
12
|
import { createDoorHost } from "../door/host.js";
|
|
@@ -56,7 +57,7 @@ const readBody = (value) => {
|
|
|
56
57
|
* 1.05 radii from the surface (`FIT_DISTANCE` over the zoom), so past a zoom of about 3.9 nothing moves; 3.6 is where the finest map tiles of the Earth, Mars and the Moon (16384 pixels round) run out of detail too, so it is the same ceiling for both.
|
|
57
58
|
*/
|
|
58
59
|
const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3.6, tiltMax: 90 };
|
|
59
|
-
const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p>`;
|
|
60
|
+
const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label,.sp-ring{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p>`;
|
|
60
61
|
/**
|
|
61
62
|
* The `<wakusei-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`
|
|
62
63
|
* (`"lon,lat"`), `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `look` (`realistic` or `painted`),
|
|
@@ -86,7 +87,7 @@ const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;ove
|
|
|
86
87
|
* ```
|
|
87
88
|
*/
|
|
88
89
|
export class WakuseiSpace extends HTMLElement {
|
|
89
|
-
static observedAttributes = ["center", "time", "speed", "scale", "labels", "orbits", "help", "look", "light", "lang", "data", "arrows", ...NAME_LABEL_ATTRIBUTES];
|
|
90
|
+
static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", ...NAME_LABEL_ATTRIBUTES];
|
|
90
91
|
#model = newSpaceModel();
|
|
91
92
|
#clock = createGameClock("now", 1);
|
|
92
93
|
#view;
|
|
@@ -133,9 +134,12 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
133
134
|
this.#model.time = this.#clock.time;
|
|
134
135
|
this.#model.mode = this.getAttribute("scale") === "compressed" ? "compressed" : "true";
|
|
135
136
|
this.#model.labels = this.getAttribute("labels") !== "off";
|
|
137
|
+
this.#labelsAlways = this.hasAttribute("labels-always") && this.getAttribute("labels-always") !== "off";
|
|
138
|
+
this.#covered = this.getAttribute("covered") === "arrow" ? "arrow" : "name";
|
|
136
139
|
this.#model.orbits = this.getAttribute("orbits") !== "off";
|
|
137
140
|
this.#model.arrowCount = arrowCount(this.getAttribute("arrows"));
|
|
138
141
|
this.#model.help = this.hasAttribute("help") && this.getAttribute("help") !== "off";
|
|
142
|
+
this.#model.helpThrough = this.hasAttribute("help-through") && this.getAttribute("help-through") !== "off";
|
|
139
143
|
this.#model.look = this.getAttribute("look") === "painted" ? "painted" : "realistic";
|
|
140
144
|
this.#model.light = readLight(this.getAttribute("light"));
|
|
141
145
|
this.#relabel();
|
|
@@ -155,6 +159,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
155
159
|
this.#nameScale();
|
|
156
160
|
this.#pool.clear();
|
|
157
161
|
this.#rings.clear();
|
|
162
|
+
this.#arrows.clear();
|
|
158
163
|
const nav = navigator;
|
|
159
164
|
this.#gate = createGate(1000 / frameCap(30, { deviceMemory: nav.deviceMemory, hardwareConcurrency: nav.hardwareConcurrency }), () => this.#view?.invalidate());
|
|
160
165
|
this.#stage.addEventListener("webglcontextlost", this.#lost, true);
|
|
@@ -221,12 +226,18 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
221
226
|
this.scale = value === "compressed" ? "compressed" : "true";
|
|
222
227
|
else if (name === "labels")
|
|
223
228
|
this.labels = value !== "off";
|
|
229
|
+
else if (name === "labels-always")
|
|
230
|
+
this.labelsAlways = value !== null && value !== "off";
|
|
231
|
+
else if (name === "covered")
|
|
232
|
+
this.covered = value === "arrow" ? "arrow" : "name";
|
|
224
233
|
else if (name === "orbits")
|
|
225
234
|
this.orbits = value !== "off";
|
|
226
235
|
else if (name === "arrows")
|
|
227
236
|
this.arrows = arrowCount(value);
|
|
228
237
|
else if (name === "help")
|
|
229
238
|
this.help = value !== null && value !== "off";
|
|
239
|
+
else if (name === "help-through")
|
|
240
|
+
this.helpThrough = value !== null && value !== "off";
|
|
230
241
|
else if (name === "look")
|
|
231
242
|
this.look = value === "painted" ? "painted" : "realistic";
|
|
232
243
|
else if (name === "light")
|
|
@@ -320,10 +331,37 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
320
331
|
set labels(value) {
|
|
321
332
|
this.#model.labels = value;
|
|
322
333
|
if (!value)
|
|
323
|
-
for (const label of [...this.#pool.values(), ...this.#rings.values()])
|
|
334
|
+
for (const label of [...this.#pool.values(), ...this.#rings.values(), ...this.#arrows.values()])
|
|
324
335
|
label.hidden = true;
|
|
325
336
|
this.#gate?.request();
|
|
326
337
|
}
|
|
338
|
+
#covered = "name";
|
|
339
|
+
#arrows = new Map();
|
|
340
|
+
/**
|
|
341
|
+
* 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
|
|
342
|
+
* 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.
|
|
343
|
+
*/
|
|
344
|
+
get covered() {
|
|
345
|
+
return this.#covered;
|
|
346
|
+
}
|
|
347
|
+
set covered(value) {
|
|
348
|
+
this.#covered = value;
|
|
349
|
+
if (this.#places)
|
|
350
|
+
this.#placeLabels(this.#places);
|
|
351
|
+
}
|
|
352
|
+
#labelsAlways = false;
|
|
353
|
+
/**
|
|
354
|
+
* 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
|
|
355
|
+
* 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.
|
|
356
|
+
*/
|
|
357
|
+
get labelsAlways() {
|
|
358
|
+
return this.#labelsAlways;
|
|
359
|
+
}
|
|
360
|
+
set labelsAlways(value) {
|
|
361
|
+
this.#labelsAlways = value;
|
|
362
|
+
if (this.#places)
|
|
363
|
+
this.#placeLabels(this.#places);
|
|
364
|
+
}
|
|
327
365
|
get orbits() {
|
|
328
366
|
return this.#model.orbits;
|
|
329
367
|
}
|
|
@@ -341,7 +379,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
341
379
|
}
|
|
342
380
|
/**
|
|
343
381
|
* 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
|
|
344
|
-
* right for Venus and Uranus, which turn backwards, and for Uranus on its side.
|
|
382
|
+
* 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).
|
|
345
383
|
*/
|
|
346
384
|
get help() {
|
|
347
385
|
return this.#model.help;
|
|
@@ -350,6 +388,17 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
350
388
|
this.#model.help = value;
|
|
351
389
|
this.#gate?.request();
|
|
352
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* 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
|
|
393
|
+
* 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.
|
|
394
|
+
*/
|
|
395
|
+
get helpThrough() {
|
|
396
|
+
return this.#model.helpThrough;
|
|
397
|
+
}
|
|
398
|
+
set helpThrough(value) {
|
|
399
|
+
this.#model.helpThrough = value;
|
|
400
|
+
this.#gate?.request();
|
|
401
|
+
}
|
|
353
402
|
/** How the bodies are drawn: `realistic` (shaded from the body's real colours and features) or `painted` (public-domain surface maps). */
|
|
354
403
|
get look() {
|
|
355
404
|
return this.#model.look === "painted" ? "painted" : "realistic";
|
|
@@ -658,7 +707,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
658
707
|
assets: { entries: stats?.assets.entries ?? 0, refs: stats?.assets.refs ?? 0 },
|
|
659
708
|
time: this.time,
|
|
660
709
|
lookups: this.#model.lookups,
|
|
661
|
-
camera: { position: [...this.#model.camera.position], fov: this.#model.camera.fov },
|
|
710
|
+
camera: { position: [...this.#model.camera.position], fov: this.#model.camera.fov, up: [...this.#model.camera.up], forward: [...this.#model.camera.forward] },
|
|
662
711
|
bodies: { look: this.#model.look, painted: this.#model.painted.bodies, moons: this.#model.painted.moons, held: this.#model.painted.held },
|
|
663
712
|
tiles: { ...this.#model.tiles },
|
|
664
713
|
door: { points: this.#model.door.points, sources: this.#door.book.stats() },
|
|
@@ -750,8 +799,14 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
750
799
|
continue;
|
|
751
800
|
const x = Math.round(at.x + Math.max(4, Math.min(at.r, 40)));
|
|
752
801
|
const y = Math.round(at.y - 8);
|
|
753
|
-
|
|
754
|
-
|
|
802
|
+
// a body that carries its drawn name gives its floating name up (it fades, and leaves its place to the others) unless the page keeps both; a body behind another gives it up for the arrow
|
|
803
|
+
const carried = at.named === true && !this.#labelsAlways;
|
|
804
|
+
const covered = at.behind !== undefined && this.#covered === "arrow";
|
|
805
|
+
if (covered)
|
|
806
|
+
continue;
|
|
807
|
+
spots.set(id, { x, y, small: at.r < RING_BELOW_PX, carried });
|
|
808
|
+
if (!carried)
|
|
809
|
+
wanted.push({ id, x, y, width: this.#widthOf(label), height: 16, rank: this.#rank(id), size: at.r });
|
|
755
810
|
}
|
|
756
811
|
// no two names overlap: a moon gives way to its planet and a planet to the Sun
|
|
757
812
|
const shown = chooseLabels(wanted);
|
|
@@ -761,15 +816,28 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
761
816
|
if (!label || !ring)
|
|
762
817
|
continue;
|
|
763
818
|
const spot = spots.get(id);
|
|
764
|
-
if (!spot || !shown.has(id)) {
|
|
819
|
+
if (!spot || (!spot.carried && !shown.has(id))) {
|
|
765
820
|
if (!label.hidden)
|
|
766
821
|
label.hidden = true;
|
|
767
822
|
if (!ring.hidden)
|
|
768
823
|
ring.hidden = true;
|
|
824
|
+
// a hidden name forgets its fade, so that when it comes back it fades in rather than popping
|
|
825
|
+
if (label.hasAttribute("data-carried")) {
|
|
826
|
+
label.removeAttribute("data-carried");
|
|
827
|
+
ring.removeAttribute("data-carried");
|
|
828
|
+
label.setAttribute("aria-hidden", "false");
|
|
829
|
+
label.tabIndex = 0;
|
|
830
|
+
}
|
|
769
831
|
continue;
|
|
770
832
|
}
|
|
771
833
|
if (label.hidden)
|
|
772
834
|
label.hidden = false;
|
|
835
|
+
if (label.hasAttribute("data-carried") !== spot.carried) {
|
|
836
|
+
label.toggleAttribute("data-carried", spot.carried);
|
|
837
|
+
ring.toggleAttribute("data-carried", spot.carried);
|
|
838
|
+
label.setAttribute("aria-hidden", String(spot.carried));
|
|
839
|
+
label.tabIndex = spot.carried ? -1 : 0;
|
|
840
|
+
}
|
|
773
841
|
label.style.transform = `translate(${spot.x}px,${spot.y}px)`;
|
|
774
842
|
// a body too small to see is marked: a ring round the place it is, as well as its name
|
|
775
843
|
if (ring.hidden === spot.small)
|
|
@@ -777,6 +845,43 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
777
845
|
if (spot.small)
|
|
778
846
|
ring.style.transform = `translate(${Math.round(places[id].x)}px,${Math.round(places[id].y)}px)`;
|
|
779
847
|
}
|
|
848
|
+
this.#placeArrows(places);
|
|
849
|
+
}
|
|
850
|
+
/** The quiet arrows for the bodies behind others (`covered="arrow"`): one per covering disc, just outside its edge, named for the surest body behind and counting the rest. */
|
|
851
|
+
#placeArrows(places) {
|
|
852
|
+
const box = this.#labelBox;
|
|
853
|
+
if (!box)
|
|
854
|
+
return;
|
|
855
|
+
const arrows = this.#covered === "arrow" && this.#model.labels ? coverArrows(places, (id) => this.#rank(id)) : [];
|
|
856
|
+
const live = new Set();
|
|
857
|
+
for (const arrow of arrows) {
|
|
858
|
+
live.add(arrow.cover);
|
|
859
|
+
let el = this.#arrows.get(arrow.cover);
|
|
860
|
+
if (!el) {
|
|
861
|
+
const button = box.ownerDocument.createElement("button");
|
|
862
|
+
button.type = "button";
|
|
863
|
+
el = button;
|
|
864
|
+
el.className = "sp-arrow";
|
|
865
|
+
el.dataset["cover"] = arrow.cover;
|
|
866
|
+
box.append(el);
|
|
867
|
+
this.#arrows.set(arrow.cover, el);
|
|
868
|
+
}
|
|
869
|
+
const text = arrow.bodies.length > 1 ? `${this.#nameOf(arrow.lead)} +${arrow.bodies.length - 1}` : this.#nameOf(arrow.lead);
|
|
870
|
+
if (el.dataset["body"] !== arrow.lead || el.textContent !== text) {
|
|
871
|
+
el.dataset["body"] = arrow.lead;
|
|
872
|
+
el.textContent = text;
|
|
873
|
+
el.setAttribute("aria-label", `${arrow.bodies.map((id) => this.#nameOf(id)).join(", ")}: ${this.#nameOf(arrow.cover)} ${this.getAttribute("lang") === "ja" ? "の後ろ" : "is in front"}. ${this.#hint}`);
|
|
874
|
+
}
|
|
875
|
+
// the tip sits at the arrow's place and points into the disc; the name hangs off the far side, to the right of the tip for an arrow on the right half of the disc and to the left for one on the left
|
|
876
|
+
const onLeft = Math.cos((arrow.angle * Math.PI) / 180) > 0;
|
|
877
|
+
el.style.setProperty("--turn", `${Math.round(arrow.angle)}deg`);
|
|
878
|
+
el.style.transform = `translate(${Math.round(arrow.x)}px,${Math.round(arrow.y - 8)}px)${onLeft ? " translateX(-100%)" : ""}`;
|
|
879
|
+
if (el.hidden)
|
|
880
|
+
el.hidden = false;
|
|
881
|
+
}
|
|
882
|
+
for (const [cover, el] of this.#arrows)
|
|
883
|
+
if (!live.has(cover) && !el.hidden)
|
|
884
|
+
el.hidden = true;
|
|
780
885
|
}
|
|
781
886
|
/** How sure a body's name is of its place: the body looked at first, then the Sun, the planets, the dwarf planets and minor bodies, and the moons. */
|
|
782
887
|
#rank(id) {
|
|
@@ -871,9 +976,19 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
871
976
|
this.#press(best);
|
|
872
977
|
};
|
|
873
978
|
#labelClick = (event) => {
|
|
874
|
-
const
|
|
875
|
-
|
|
876
|
-
|
|
979
|
+
const target = event.target;
|
|
980
|
+
const id = target?.dataset?.["body"];
|
|
981
|
+
if (!id)
|
|
982
|
+
return;
|
|
983
|
+
// a press on a quiet arrow (a body behind another) goes to that body at once; a press on a name selects it first, as always
|
|
984
|
+
if (target?.dataset?.["cover"] !== undefined) {
|
|
985
|
+
if (canCentre(id))
|
|
986
|
+
this.goTo(id);
|
|
987
|
+
else
|
|
988
|
+
this.#press(id);
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
this.#press(id);
|
|
877
992
|
};
|
|
878
993
|
/**
|
|
879
994
|
* A press on a body or its name. `wakusei-body-click` tells the page every time. The first press on a body selects it (`wakusei-body-select`, for the page's card); a second press on the body that is selected makes it
|
package/dist/space/index.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ 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";
|
package/dist/space/index.js
CHANGED
|
@@ -8,3 +8,4 @@ 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";
|
package/dist/space/scale.d.ts
CHANGED
|
@@ -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.
|