@johnmorrisdotca/wakusei-planets 0.65.0 → 0.67.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 +29 -0
- package/NOTICE.md +7 -0
- package/README.md +3 -3
- package/dist/body-physics.d.ts +114 -0
- package/dist/body-physics.js +162 -0
- package/dist/data/discovery.d.ts +3 -0
- package/dist/data/discovery.js +719 -0
- package/dist/data/moon-catalogue.d.ts +4 -2
- package/dist/data/moon-catalogue.js +468 -468
- package/dist/data/moon-osculating.d.ts +6 -0
- package/dist/data/moon-osculating.js +401 -0
- package/dist/discovery.d.ts +118 -0
- package/dist/discovery.js +67 -0
- package/dist/facts.js +1 -1
- package/dist/moon-catalogue.d.ts +88 -2
- package/dist/moon-catalogue.js +94 -14
- package/dist/plan/element.d.ts +7 -1
- package/dist/plan/element.js +44 -28
- package/dist/plan/layout.d.ts +7 -0
- package/dist/plan/layout.js +7 -5
- package/dist/plan/svg.js +2 -1
- package/dist/space/element.d.ts +24 -0
- package/dist/space/element.js +79 -10
- package/dist/space/index.d.ts +1 -1
- package/dist/space/index.js +1 -1
- package/dist/space/labels.d.ts +116 -2
- package/dist/space/labels.js +107 -8
- package/dist/space/scene.d.ts +2 -0
- package/dist/space/scene.js +31 -23
- package/dist/space/travel.d.ts +2 -2
- package/dist/space/travel.js +2 -2
- package/dist/surface/element.d.ts +8 -0
- package/dist/surface/element.js +70 -15
- package/dist/surface/glide.d.ts +27 -0
- package/dist/surface/glide.js +43 -0
- package/dist/surface/glsl.d.ts +3 -3
- package/dist/surface/glsl.js +2 -1
- package/dist/surface/landing.d.ts +33 -0
- package/dist/surface/landing.js +26 -0
- package/package.json +11 -1
package/dist/space/element.js
CHANGED
|
@@ -6,7 +6,7 @@ import { arrowCount, readHelpPlace } from "./arrows.js";
|
|
|
6
6
|
import { createGameClock } from "./clock.js";
|
|
7
7
|
import { bodyKindOf, findBody, hopFrom, hostOf, HOP_ORDER, systemOf } from "./bodies.js";
|
|
8
8
|
import { sightChanged, sightOf, withinMargin } from "./sight.js";
|
|
9
|
-
import {
|
|
9
|
+
import { craftRank, craftSize, LABEL_GAP, nameAlternates, nameSpot, placeLabels } from "./labels.js";
|
|
10
10
|
import { coverArrows, coverOf } from "./covered.js";
|
|
11
11
|
import { createPainter, picturesPending } from "../scene/painter.js";
|
|
12
12
|
import { NAME_LABEL_ATTRIBUTES, readNameLabel } from "../scene/name-label.js";
|
|
@@ -160,6 +160,9 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
160
160
|
#pool = new Map();
|
|
161
161
|
#places;
|
|
162
162
|
#names = {};
|
|
163
|
+
#keepOut = [];
|
|
164
|
+
#favourites = new Set();
|
|
165
|
+
#short = {};
|
|
163
166
|
#selected = null;
|
|
164
167
|
#scaleNames = {};
|
|
165
168
|
#rings = new Map();
|
|
@@ -279,6 +282,9 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
279
282
|
this.#door.announce();
|
|
280
283
|
this.#announceFrame();
|
|
281
284
|
},
|
|
285
|
+
onPlaces: (places) => {
|
|
286
|
+
this.#places = places;
|
|
287
|
+
},
|
|
282
288
|
onSight: (bodies, frame) => this.#see(bodies, frame),
|
|
283
289
|
wantSight: () => this.#sightAsked || this.#sightListeners.size > 0,
|
|
284
290
|
onSurface: (surface) => {
|
|
@@ -1935,6 +1941,43 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1935
1941
|
for (const [id, button] of this.#pool)
|
|
1936
1942
|
this.#nameLabel(button, id);
|
|
1937
1943
|
}
|
|
1944
|
+
/**
|
|
1945
|
+
* The short words written beside a craft's dot when its full name is long (`{ juice: { en: "JUICE", ja: "ジュース" }, webb: "Webb" }`): a text for every language, or an object with the `en` and `ja` words. A craft left out is written in full. The craft's
|
|
1946
|
+
* name for a card, a press, an event and a screen reader stays the full one; only the written label is short. The package ships none: a page hands the table it wants (MODULES-1535).
|
|
1947
|
+
*/
|
|
1948
|
+
get labelShort() {
|
|
1949
|
+
return { ...this.#short };
|
|
1950
|
+
}
|
|
1951
|
+
set labelShort(value) {
|
|
1952
|
+
this.#short = { ...value };
|
|
1953
|
+
for (const [id, button] of this.#pool)
|
|
1954
|
+
this.#nameLabel(button, id);
|
|
1955
|
+
if (this.#places)
|
|
1956
|
+
this.#placeLabels(this.#places);
|
|
1957
|
+
}
|
|
1958
|
+
/**
|
|
1959
|
+
* The rectangles of the view the names are kept out of, in the element's own box in CSS pixels (`[{ x, y, w, h }]`): the page's bar, its notices, its strip. A name that would lie under one goes round its dot or is left out; the dot stays.
|
|
1960
|
+
* Craft names move round their dot first; every name respects them. An empty list (the default) keeps nothing out.
|
|
1961
|
+
*/
|
|
1962
|
+
get keepOut() {
|
|
1963
|
+
return this.#keepOut.map((one) => ({ ...one }));
|
|
1964
|
+
}
|
|
1965
|
+
set keepOut(value) {
|
|
1966
|
+
this.#keepOut = (Array.isArray(value) ? value : []).filter((one) => one !== null && typeof one === "object" && [one.x, one.y, one.w, one.h].every((n) => Number.isFinite(n))).map((one) => ({ x: one.x, y: one.y, w: one.w, h: one.h }));
|
|
1967
|
+
if (this.#places)
|
|
1968
|
+
this.#placeLabels(this.#places);
|
|
1969
|
+
}
|
|
1970
|
+
/**
|
|
1971
|
+
* The ids of the craft the page favourites: their names come before the other craft's when two touch (the craft chosen comes first of all). A body's name always comes before any craft's.
|
|
1972
|
+
*/
|
|
1973
|
+
get favourites() {
|
|
1974
|
+
return [...this.#favourites];
|
|
1975
|
+
}
|
|
1976
|
+
set favourites(value) {
|
|
1977
|
+
this.#favourites = new Set(Array.isArray(value) ? value.map((id) => String(id).toLowerCase()) : []);
|
|
1978
|
+
if (this.#places)
|
|
1979
|
+
this.#placeLabels(this.#places);
|
|
1980
|
+
}
|
|
1938
1981
|
/** What a screen reader hears after a body's name: "choose to look at it" by default, or the page's own words. */
|
|
1939
1982
|
get bodyHint() {
|
|
1940
1983
|
return this.#hint;
|
|
@@ -2367,6 +2410,9 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
2367
2410
|
button.type = "button";
|
|
2368
2411
|
button.className = "sp-label";
|
|
2369
2412
|
button.dataset["body"] = id;
|
|
2413
|
+
// a craft's name is marked, so a page's styles (and a test) can tell it from a body's
|
|
2414
|
+
if (this.#model.craftIds.includes(id))
|
|
2415
|
+
button.dataset["craft"] = "";
|
|
2370
2416
|
this.#nameLabel(button, id);
|
|
2371
2417
|
box.append(button);
|
|
2372
2418
|
this.#pool.set(id, button);
|
|
@@ -2393,18 +2439,30 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
2393
2439
|
if (covered)
|
|
2394
2440
|
continue;
|
|
2395
2441
|
spots.set(id, { x, y, small: at.r < RING_BELOW_PX, carried, flipped });
|
|
2396
|
-
if (
|
|
2442
|
+
if (carried)
|
|
2443
|
+
continue;
|
|
2444
|
+
if (this.#model.craftIds.includes(id)) {
|
|
2445
|
+
// a craft's name comes after every body's: the craft chosen first, then a favourite, then the nearer to the body in view; it goes round its dot before it gives way
|
|
2446
|
+
const middle = places[this.#model.focus] ?? { x: frame.width / 2, y: frame.height / 2 };
|
|
2447
|
+
const chosen = this.#selected === id || this.#hovered === id || this.#model.companion === id;
|
|
2448
|
+
wanted.push({ id, x, y, width, height: 16, rank: craftRank({ chosen, favourite: this.#favourites.has(id) }), size: craftSize(Math.hypot(at.x - middle.x, at.y - middle.y)), alternates: nameAlternates(at, { width, height: 16 }, frame) });
|
|
2449
|
+
}
|
|
2450
|
+
else
|
|
2397
2451
|
wanted.push({ id, x, y, width, height: 16, rank: this.#rank(id), size: at.r });
|
|
2398
2452
|
}
|
|
2399
|
-
// no two names overlap: a moon gives way to its planet
|
|
2400
|
-
const
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2453
|
+
// no two names overlap and none lies under a keep-out rectangle: a moon gives way to its planet, a planet to the Sun, and every craft to every body
|
|
2454
|
+
const placed = placeLabels(wanted, LABEL_GAP, this.#keepOut);
|
|
2455
|
+
const shown = new Set(placed.keys());
|
|
2456
|
+
for (const [id, spot] of placed) {
|
|
2457
|
+
const was = spots.get(id);
|
|
2458
|
+
// a craft's name that went round its dot is on the left of it, or above or below
|
|
2459
|
+
const moved = was.x !== spot.x || was.y !== spot.y;
|
|
2460
|
+
spots.set(id, { ...was, x: spot.x, y: spot.y, flipped: moved ? spot.x + 1 < places[id].x : was.flipped });
|
|
2461
|
+
}
|
|
2404
2462
|
const companion = this.#model.companion;
|
|
2405
|
-
if (companion !== null && spots.has(companion))
|
|
2463
|
+
if (companion !== null && spots.has(companion) && !this.#model.craftIds.includes(companion))
|
|
2406
2464
|
shown.add(companion);
|
|
2407
|
-
this.#nameBoxes = wanted.filter((one) => shown.has(one.id));
|
|
2465
|
+
this.#nameBoxes = wanted.filter((one) => shown.has(one.id)).map((one) => ({ ...one, ...(placed.get(one.id) ?? {}) }));
|
|
2408
2466
|
for (const id of ids) {
|
|
2409
2467
|
const label = this.#pool.get(id);
|
|
2410
2468
|
const ring = this.#rings.get(id);
|
|
@@ -2668,10 +2726,21 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
2668
2726
|
}
|
|
2669
2727
|
#nameLabel(button, id) {
|
|
2670
2728
|
const text = this.#nameOf(id);
|
|
2671
|
-
|
|
2729
|
+
// a craft with a short label is written short and named in full for a screen reader
|
|
2730
|
+
button.textContent = this.#shortOf(id) ?? text;
|
|
2672
2731
|
this.#widths.delete(button);
|
|
2673
2732
|
button.setAttribute("aria-label", `${text}: ${this.#hint}`);
|
|
2674
2733
|
}
|
|
2734
|
+
/** The short words the page gave a craft, in the language shown, else its text for every language, else nothing. */
|
|
2735
|
+
#shortOf(id) {
|
|
2736
|
+
if (!this.#model.craftIds.includes(id))
|
|
2737
|
+
return undefined;
|
|
2738
|
+
const given = this.#short[id];
|
|
2739
|
+
if (given === undefined)
|
|
2740
|
+
return undefined;
|
|
2741
|
+
const words = typeof given === "string" ? given : given[this.getAttribute("lang") === "ja" ? "ja" : "en"] ?? given.en ?? given.ja;
|
|
2742
|
+
return words !== undefined && words.trim() !== "" ? words : undefined;
|
|
2743
|
+
}
|
|
2675
2744
|
/** True for the full-screen mode (the `immersive` attribute): the element fills its box in any shape, a plain wheel zooms instead of scrolling the page, and a touch drag turns the view instead of scrolling it. */
|
|
2676
2745
|
get immersive() {
|
|
2677
2746
|
return this.hasAttribute("immersive");
|
package/dist/space/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, eclipticToScene
|
|
|
2
2
|
export { compress, MOON_COMPRESSED, moonDistance, moonSizeFactor, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
3
3
|
export { groundDirection } from "./aim.ts";
|
|
4
4
|
export { RIDE_FOV, ridePose, type RideInput, type RideLook, type RidePose } from "./ride.ts";
|
|
5
|
-
export { chooseLabels, LABEL_GAP, nameSpot, type LabelBox } from "./labels.ts";
|
|
5
|
+
export { chooseLabels, craftRank, craftSize, LABEL_GAP, nameAlternates, nameSpot, placeLabels, type KeepOut, type LabelBox } from "./labels.ts";
|
|
6
6
|
export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, systemOf, type SpaceKind } from "./bodies.ts";
|
|
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, helpSpin, readHelpPlace, spinArrow, type HelpPlace, type OrbitArrow } from "./arrows.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, eclipticToScene
|
|
|
3
3
|
export { compress, MOON_COMPRESSED, moonDistance, moonSizeFactor, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
4
4
|
export { groundDirection } from "./aim.js";
|
|
5
5
|
export { RIDE_FOV, ridePose } from "./ride.js";
|
|
6
|
-
export { chooseLabels, LABEL_GAP, nameSpot } from "./labels.js";
|
|
6
|
+
export { chooseLabels, craftRank, craftSize, LABEL_GAP, nameAlternates, nameSpot, placeLabels } from "./labels.js";
|
|
7
7
|
export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, systemOf } 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, helpSpin, readHelpPlace, spinArrow } from "./arrows.js";
|
package/dist/space/labels.d.ts
CHANGED
|
@@ -19,6 +19,28 @@ export interface LabelBox {
|
|
|
19
19
|
rank: number;
|
|
20
20
|
/** Breaks a tie of rank: the bigger body on the screen wins. */
|
|
21
21
|
size: number;
|
|
22
|
+
/** Other places for the name, tried in this order when `x` and `y` are taken: a craft's name moves round its dot before it gives way. */
|
|
23
|
+
alternates?: readonly {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
}[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A rectangle of the view the names are kept out of, in the view's own box coordinates in CSS pixels: the page's bar, its notices, its strip. A name that would lie under one is moved, or left out; the dot stays.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import type { KeepOut } from "@johnmorrisdotca/wakusei-planets/space";
|
|
34
|
+
*
|
|
35
|
+
* const bar: KeepOut = { x: 0, y: 270, w: 400, h: 30 };
|
|
36
|
+
* console.log(bar.y + bar.h);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export interface KeepOut {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
w: number;
|
|
43
|
+
h: number;
|
|
22
44
|
}
|
|
23
45
|
/**
|
|
24
46
|
* The room kept between two names, in CSS pixels, so they never touch.
|
|
@@ -32,10 +54,40 @@ export interface LabelBox {
|
|
|
32
54
|
*/
|
|
33
55
|
export declare const LABEL_GAP = 3;
|
|
34
56
|
/**
|
|
35
|
-
*
|
|
57
|
+
* Where each name that gets a place goes: the surest first, and each in the first of its places (its own, then its `alternates`) that touches no name already placed and no rectangle of `keepOut`; a name with no such place is left out.
|
|
58
|
+
* A moon gives way to its planet and a planet to the Sun, because their ranks say so, and a craft's name to every body's.
|
|
59
|
+
*
|
|
60
|
+
* @param boxes - The names with their boxes, ranks and other places to try.
|
|
61
|
+
* @param gap - The room to keep between two names, in CSS pixels.
|
|
62
|
+
* @param keepOut - The rectangles the names are kept out of (the page's bar and notices), in the view's coordinates.
|
|
63
|
+
* @returns The place of each name shown, by id.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { placeLabels } from "@johnmorrisdotca/wakusei-planets/space";
|
|
68
|
+
*
|
|
69
|
+
* const placed = placeLabels(
|
|
70
|
+
* [
|
|
71
|
+
* { id: "earth", x: 10, y: 10, width: 40, height: 16, rank: 1, size: 20 },
|
|
72
|
+
* { id: "juice", x: 30, y: 12, width: 40, height: 16, rank: 5, size: 1, alternates: [{ x: 30, y: 40 }] },
|
|
73
|
+
* ],
|
|
74
|
+
* 3,
|
|
75
|
+
* [{ x: 0, y: 270, w: 400, h: 30 }],
|
|
76
|
+
* );
|
|
77
|
+
* console.log([...placed]);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function placeLabels(boxes: readonly LabelBox[], gap?: number, keepOut?: readonly KeepOut[]): Map<string, {
|
|
81
|
+
x: number;
|
|
82
|
+
y: number;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* The names to show from those that want a place: the surest first, and each kept only if it does not touch one already kept (or a rectangle of `keepOut`). A moon gives way to its planet and a planet to the Sun, because their ranks say so.
|
|
86
|
+
* The same as `placeLabels`, for the ids alone.
|
|
36
87
|
*
|
|
37
88
|
* @param boxes - The names with their boxes and ranks.
|
|
38
89
|
* @param gap - The room to keep between two names, in CSS pixels.
|
|
90
|
+
* @param keepOut - The rectangles the names are kept out of, in the view's coordinates.
|
|
39
91
|
* @returns The ids to show.
|
|
40
92
|
*
|
|
41
93
|
* @example
|
|
@@ -49,7 +101,7 @@ export declare const LABEL_GAP = 3;
|
|
|
49
101
|
* console.log([...shown]);
|
|
50
102
|
* ```
|
|
51
103
|
*/
|
|
52
|
-
export declare function chooseLabels(boxes: readonly LabelBox[], gap?: number): Set<string>;
|
|
104
|
+
export declare function chooseLabels(boxes: readonly LabelBox[], gap?: number, keepOut?: readonly KeepOut[]): Set<string>;
|
|
53
105
|
/**
|
|
54
106
|
* Where a floating name goes: beside its body's dot, and kept inside the view (MODULES-1144). It starts to the right of the dot, at `max(4, min(r, 40))` pixels from its middle and 8 pixels above it. A name that would run past the right edge goes to the dot's left side instead (`flipped`); one that fits on neither side is held against the edge, and a name past the top or the bottom is held inside. A body whose dot is itself outside the view keeps its name where it falls, since the view cuts it with the body.
|
|
55
107
|
*
|
|
@@ -82,3 +134,65 @@ export declare function nameSpot(dot: {
|
|
|
82
134
|
y: number;
|
|
83
135
|
flipped: boolean;
|
|
84
136
|
};
|
|
137
|
+
/**
|
|
138
|
+
* The rank of a craft's name among the names of the space view: after every body's (a moon is 4), so a body's name always wins over a craft's. The craft the view is about (chosen) is surest, then a favourite, then the rest,
|
|
139
|
+
* and among those of one rank the one nearer the body in view wins (`craftSize`).
|
|
140
|
+
*
|
|
141
|
+
* @param craft - Whether the craft is the one chosen (the one the view is on, or pressed), and whether it is a favourite.
|
|
142
|
+
* @returns The rank: 5 for the chosen craft, 6 for a favourite, 7 for any other.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* import { craftRank } from "@johnmorrisdotca/wakusei-planets/space";
|
|
147
|
+
*
|
|
148
|
+
* console.log(craftRank({ chosen: false, favourite: true }), craftRank({ chosen: false, favourite: false }));
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function craftRank(craft: {
|
|
152
|
+
chosen: boolean;
|
|
153
|
+
favourite: boolean;
|
|
154
|
+
}): number;
|
|
155
|
+
/**
|
|
156
|
+
* The size that breaks a tie between two craft of one rank: the nearer one, in CSS pixels from the middle of the body in view, is the bigger and its name wins.
|
|
157
|
+
*
|
|
158
|
+
* @param pixels - The craft's distance on the screen from the body in view, in CSS pixels.
|
|
159
|
+
* @returns A number that falls as the craft goes further.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* import { craftSize } from "@johnmorrisdotca/wakusei-planets/space";
|
|
164
|
+
*
|
|
165
|
+
* console.log(craftSize(10) > craftSize(300));
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function craftSize(pixels: number): number;
|
|
169
|
+
/**
|
|
170
|
+
* Other places for a craft's name round its dot when the first is taken: to the left, above and below, each inside the view. The first place is `nameSpot`'s.
|
|
171
|
+
*
|
|
172
|
+
* @param dot - The craft's place on the screen in CSS pixels: its middle and its radius.
|
|
173
|
+
* @param size - The name's width and height in CSS pixels.
|
|
174
|
+
* @param frame - The view's width and height in CSS pixels.
|
|
175
|
+
* @returns The places to try after the first, in order.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* import { nameAlternates } from "@johnmorrisdotca/wakusei-planets/space";
|
|
180
|
+
*
|
|
181
|
+
* const others = nameAlternates({ x: 200, y: 150, r: 2 }, { width: 60, height: 16 }, { width: 400, height: 300 });
|
|
182
|
+
* console.log(others.length);
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export declare function nameAlternates(dot: {
|
|
186
|
+
x: number;
|
|
187
|
+
y: number;
|
|
188
|
+
r: number;
|
|
189
|
+
}, size: {
|
|
190
|
+
width: number;
|
|
191
|
+
height: number;
|
|
192
|
+
}, frame: {
|
|
193
|
+
width: number;
|
|
194
|
+
height: number;
|
|
195
|
+
}): {
|
|
196
|
+
x: number;
|
|
197
|
+
y: number;
|
|
198
|
+
}[];
|
package/dist/space/labels.js
CHANGED
|
@@ -12,11 +12,54 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export const LABEL_GAP = 3;
|
|
14
14
|
const crosses = (a, b, gap) => a.x < b.x + b.width + gap && b.x < a.x + a.width + gap && a.y < b.y + b.height + gap && b.y < a.y + a.height + gap;
|
|
15
|
+
const hits = (box, area, gap) => box.x < area.x + area.w + gap && area.x < box.x + box.width + gap && box.y < area.y + area.h + gap && area.y < box.y + box.height + gap;
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
+
* Where each name that gets a place goes: the surest first, and each in the first of its places (its own, then its `alternates`) that touches no name already placed and no rectangle of `keepOut`; a name with no such place is left out.
|
|
18
|
+
* A moon gives way to its planet and a planet to the Sun, because their ranks say so, and a craft's name to every body's.
|
|
19
|
+
*
|
|
20
|
+
* @param boxes - The names with their boxes, ranks and other places to try.
|
|
21
|
+
* @param gap - The room to keep between two names, in CSS pixels.
|
|
22
|
+
* @param keepOut - The rectangles the names are kept out of (the page's bar and notices), in the view's coordinates.
|
|
23
|
+
* @returns The place of each name shown, by id.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { placeLabels } from "@johnmorrisdotca/wakusei-planets/space";
|
|
28
|
+
*
|
|
29
|
+
* const placed = placeLabels(
|
|
30
|
+
* [
|
|
31
|
+
* { id: "earth", x: 10, y: 10, width: 40, height: 16, rank: 1, size: 20 },
|
|
32
|
+
* { id: "juice", x: 30, y: 12, width: 40, height: 16, rank: 5, size: 1, alternates: [{ x: 30, y: 40 }] },
|
|
33
|
+
* ],
|
|
34
|
+
* 3,
|
|
35
|
+
* [{ x: 0, y: 270, w: 400, h: 30 }],
|
|
36
|
+
* );
|
|
37
|
+
* console.log([...placed]);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function placeLabels(boxes, gap = LABEL_GAP, keepOut = []) {
|
|
41
|
+
const order = [...boxes].sort((a, b) => a.rank - b.rank || b.size - a.size || (a.id < b.id ? -1 : 1));
|
|
42
|
+
const kept = [];
|
|
43
|
+
const placed = new Map();
|
|
44
|
+
for (const box of order) {
|
|
45
|
+
for (const spot of [{ x: box.x, y: box.y }, ...(box.alternates ?? [])]) {
|
|
46
|
+
const at = { ...box, x: spot.x, y: spot.y };
|
|
47
|
+
if (keepOut.some((area) => hits(at, area, 0)) || kept.some((other) => crosses(at, other, gap)))
|
|
48
|
+
continue;
|
|
49
|
+
kept.push(at);
|
|
50
|
+
placed.set(box.id, spot);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return placed;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The names to show from those that want a place: the surest first, and each kept only if it does not touch one already kept (or a rectangle of `keepOut`). A moon gives way to its planet and a planet to the Sun, because their ranks say so.
|
|
58
|
+
* The same as `placeLabels`, for the ids alone.
|
|
17
59
|
*
|
|
18
60
|
* @param boxes - The names with their boxes and ranks.
|
|
19
61
|
* @param gap - The room to keep between two names, in CSS pixels.
|
|
62
|
+
* @param keepOut - The rectangles the names are kept out of, in the view's coordinates.
|
|
20
63
|
* @returns The ids to show.
|
|
21
64
|
*
|
|
22
65
|
* @example
|
|
@@ -30,13 +73,8 @@ const crosses = (a, b, gap) => a.x < b.x + b.width + gap && b.x < a.x + a.width
|
|
|
30
73
|
* console.log([...shown]);
|
|
31
74
|
* ```
|
|
32
75
|
*/
|
|
33
|
-
export function chooseLabels(boxes, gap = LABEL_GAP) {
|
|
34
|
-
|
|
35
|
-
const kept = [];
|
|
36
|
-
for (const box of order)
|
|
37
|
-
if (!kept.some((other) => crosses(box, other, gap)))
|
|
38
|
-
kept.push(box);
|
|
39
|
-
return new Set(kept.map((box) => box.id));
|
|
76
|
+
export function chooseLabels(boxes, gap = LABEL_GAP, keepOut = []) {
|
|
77
|
+
return new Set(placeLabels(boxes, gap, keepOut).keys());
|
|
40
78
|
}
|
|
41
79
|
/**
|
|
42
80
|
* Where a floating name goes: beside its body's dot, and kept inside the view (MODULES-1144). It starts to the right of the dot, at `max(4, min(r, 40))` pixels from its middle and 8 pixels above it. A name that would run past the right edge goes to the dot's left side instead (`flipped`); one that fits on neither side is held against the edge, and a name past the top or the bottom is held inside. A body whose dot is itself outside the view keeps its name where it falls, since the view cuts it with the body.
|
|
@@ -77,3 +115,64 @@ export function nameSpot(dot, size, frame) {
|
|
|
77
115
|
y = Math.max(0, Math.min(y, frame.height - size.height));
|
|
78
116
|
return { x, y, flipped };
|
|
79
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* The rank of a craft's name among the names of the space view: after every body's (a moon is 4), so a body's name always wins over a craft's. The craft the view is about (chosen) is surest, then a favourite, then the rest,
|
|
120
|
+
* and among those of one rank the one nearer the body in view wins (`craftSize`).
|
|
121
|
+
*
|
|
122
|
+
* @param craft - Whether the craft is the one chosen (the one the view is on, or pressed), and whether it is a favourite.
|
|
123
|
+
* @returns The rank: 5 for the chosen craft, 6 for a favourite, 7 for any other.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { craftRank } from "@johnmorrisdotca/wakusei-planets/space";
|
|
128
|
+
*
|
|
129
|
+
* console.log(craftRank({ chosen: false, favourite: true }), craftRank({ chosen: false, favourite: false }));
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export function craftRank(craft) {
|
|
133
|
+
return craft.chosen ? 5 : craft.favourite ? 6 : 7;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The size that breaks a tie between two craft of one rank: the nearer one, in CSS pixels from the middle of the body in view, is the bigger and its name wins.
|
|
137
|
+
*
|
|
138
|
+
* @param pixels - The craft's distance on the screen from the body in view, in CSS pixels.
|
|
139
|
+
* @returns A number that falls as the craft goes further.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { craftSize } from "@johnmorrisdotca/wakusei-planets/space";
|
|
144
|
+
*
|
|
145
|
+
* console.log(craftSize(10) > craftSize(300));
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export function craftSize(pixels) {
|
|
149
|
+
return 1000 / (1 + Math.max(0, pixels));
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Other places for a craft's name round its dot when the first is taken: to the left, above and below, each inside the view. The first place is `nameSpot`'s.
|
|
153
|
+
*
|
|
154
|
+
* @param dot - The craft's place on the screen in CSS pixels: its middle and its radius.
|
|
155
|
+
* @param size - The name's width and height in CSS pixels.
|
|
156
|
+
* @param frame - The view's width and height in CSS pixels.
|
|
157
|
+
* @returns The places to try after the first, in order.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* import { nameAlternates } from "@johnmorrisdotca/wakusei-planets/space";
|
|
162
|
+
*
|
|
163
|
+
* const others = nameAlternates({ x: 200, y: 150, r: 2 }, { width: 60, height: 16 }, { width: 400, height: 300 });
|
|
164
|
+
* console.log(others.length);
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export function nameAlternates(dot, size, frame) {
|
|
168
|
+
const gap = Math.max(4, Math.min(dot.r, 40));
|
|
169
|
+
const inside = (x, y) => ({
|
|
170
|
+
x: frame.width > 0 ? Math.max(0, Math.min(Math.round(x), frame.width - size.width)) : Math.round(x),
|
|
171
|
+
y: frame.height > 0 ? Math.max(0, Math.min(Math.round(y), frame.height - size.height)) : Math.round(y),
|
|
172
|
+
});
|
|
173
|
+
return [
|
|
174
|
+
inside(dot.x - gap - size.width, dot.y - 8),
|
|
175
|
+
inside(dot.x - size.width / 2, dot.y - gap - size.height),
|
|
176
|
+
inside(dot.x - size.width / 2, dot.y + gap),
|
|
177
|
+
];
|
|
178
|
+
}
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -480,6 +480,8 @@ export interface SpaceDeps {
|
|
|
480
480
|
advance?: () => void;
|
|
481
481
|
/** Where each body is on the screen, in CSS pixels in the box, or null when it is behind the camera. Called at each draw. */
|
|
482
482
|
onLabels?: (places: Record<string, BodyPlace | null>) => void;
|
|
483
|
+
/** The places of the bodies at this draw while the names are off (`onLabels` is called with them while they are on): `placeOf` reads them. */
|
|
484
|
+
onPlaces?: (places: Record<string, BodyPlace | null>) => void;
|
|
483
485
|
/** What the camera sees of each body at each draw, by id: the Sun, the planets and the other bodies of `SPACE_BODIES`, the moons of the body looked at, and any other moon drawn; with the picture's size and the point straight ahead of the camera. Not the body the camera rides on. */
|
|
484
486
|
onSight?: (bodies: Record<string, SightInput>, frame: {
|
|
485
487
|
width: number;
|
package/dist/space/scene.js
CHANGED
|
@@ -1303,7 +1303,7 @@ export function createSpaceItem(model, deps) {
|
|
|
1303
1303
|
}
|
|
1304
1304
|
else if (model.asteroidsDrawn.placed !== 0)
|
|
1305
1305
|
model.asteroidsDrawn = { placed: 0, named: 0, ms: 0 };
|
|
1306
|
-
if (deps.onLabels
|
|
1306
|
+
if (deps.onLabels) {
|
|
1307
1307
|
const places = { ...moonPlaces };
|
|
1308
1308
|
for (const id of SPACE_BODIES) {
|
|
1309
1309
|
const at = id === hiddenBody || (rideFrom && id === rideFrom.around) ? null : labelFor(pos[id]);
|
|
@@ -1337,29 +1337,37 @@ export function createSpaceItem(model, deps) {
|
|
|
1337
1337
|
if (spot)
|
|
1338
1338
|
moonDistances[craft.id] = Math.hypot(craft.at[0] - camera.position.x, craft.at[1] - camera.position.y, craft.at[2] - camera.position.z);
|
|
1339
1339
|
}
|
|
1340
|
-
// a
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1340
|
+
// with the names off the places are still made, for a page that asks `placeOf`; the discs that hide one name behind a nearer body are worked out with the names only
|
|
1341
|
+
if (model.labels) {
|
|
1342
|
+
// a body behind another: its place is inside a nearer body's disc
|
|
1343
|
+
const entries = [];
|
|
1344
|
+
for (const [id, at] of Object.entries(places)) {
|
|
1345
|
+
if (at === null)
|
|
1346
|
+
continue;
|
|
1347
|
+
const distance = SPACE_BODIES.includes(id) ? Math.hypot(pos[id][0] - camera.position.x, pos[id][1] - camera.position.y, pos[id][2] - camera.position.z) : moonDistances[id];
|
|
1348
|
+
if (distance !== undefined)
|
|
1349
|
+
entries.push({ id, x: at.x, y: at.y, r: at.r, distance });
|
|
1350
|
+
}
|
|
1351
|
+
for (const [id, cover] of coveredBy(entries))
|
|
1352
|
+
places[id].behind = cover;
|
|
1353
|
+
// a point of the scene that a page labels (a belt's name at its anchor) is hidden by the same discs
|
|
1354
|
+
model.discs = entries;
|
|
1355
|
+
model.coverAt = (point) => {
|
|
1356
|
+
// in front of the camera, whatever the far plane cuts: a belt's name is labelled far beyond what is drawn
|
|
1357
|
+
projected.set(point[0] - origin[0], point[1] - origin[1], point[2] - origin[2]).applyMatrix4(camera.matrixWorldInverse);
|
|
1358
|
+
if (!(projected.z < 0))
|
|
1359
|
+
return null;
|
|
1360
|
+
const distance = Math.hypot(projected.x, projected.y, projected.z);
|
|
1361
|
+
projected.applyMatrix4(camera.projectionMatrix);
|
|
1362
|
+
return coverOf({ x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, distance }, entries);
|
|
1363
|
+
};
|
|
1364
|
+
deps.onLabels(places);
|
|
1365
|
+
}
|
|
1366
|
+
else {
|
|
1367
|
+
model.discs = [];
|
|
1368
|
+
model.coverAt = () => null;
|
|
1369
|
+
deps.onPlaces?.(places);
|
|
1348
1370
|
}
|
|
1349
|
-
for (const [id, cover] of coveredBy(entries))
|
|
1350
|
-
places[id].behind = cover;
|
|
1351
|
-
// a point of the scene that a page labels (a belt's name at its anchor) is hidden by the same discs
|
|
1352
|
-
model.discs = entries;
|
|
1353
|
-
model.coverAt = (point) => {
|
|
1354
|
-
// in front of the camera, whatever the far plane cuts: a belt's name is labelled far beyond what is drawn
|
|
1355
|
-
projected.set(point[0] - origin[0], point[1] - origin[1], point[2] - origin[2]).applyMatrix4(camera.matrixWorldInverse);
|
|
1356
|
-
if (!(projected.z < 0))
|
|
1357
|
-
return null;
|
|
1358
|
-
const distance = Math.hypot(projected.x, projected.y, projected.z);
|
|
1359
|
-
projected.applyMatrix4(camera.projectionMatrix);
|
|
1360
|
-
return coverOf({ x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, distance }, entries);
|
|
1361
|
-
};
|
|
1362
|
-
deps.onLabels(places);
|
|
1363
1371
|
}
|
|
1364
1372
|
else {
|
|
1365
1373
|
model.discs = [];
|
package/dist/space/travel.d.ts
CHANGED
|
@@ -213,7 +213,7 @@ export interface Faults {
|
|
|
213
213
|
pace: number;
|
|
214
214
|
/** Samples with the planet circled out of the picture (not a fault: it breaks a tie). */
|
|
215
215
|
planet: number;
|
|
216
|
-
/** Samples of the turn with the body left (and the planet circled, if there is one) out of the picture: the turn holds it
|
|
216
|
+
/** Samples of the turn before the way on starts with the body left (and the planet circled, if there is one) out of the picture: the turn holds it. Once the way on has started (the overlap) the picture needs one of the two bodies, which is `empty`. */
|
|
217
217
|
held: number;
|
|
218
218
|
}
|
|
219
219
|
export declare const total: (f: Faults) => number;
|
|
@@ -246,7 +246,7 @@ export declare const betterThan: (now: Faults, was: Faults) => boolean;
|
|
|
246
246
|
export declare function travelPlan(input: TravelInput): TravelPlan;
|
|
247
247
|
/**
|
|
248
248
|
* The camera at the moment `t` of a move, from 0 (the first view) to 1 (the last view), with where the two bodies are in the picture. The same input and moment always give the same camera. The default move,
|
|
249
|
-
* `turn-travel`, never shows an empty picture between two framed views: the body being left (or the planet circled) is held in the picture through the turn, and the destination from the end of the turn on,
|
|
249
|
+
* `turn-travel`, never shows an empty picture between two framed views: the body being left (or the planet circled) is held in the picture through the turn until the way on starts, one of the two bodies is in it while the two overlap, and the destination from the end of the turn on,
|
|
250
250
|
* where it only grows; the look direction turns one way only; no place is nearer a body than `TRAVEL_CLEARANCE`. `direct` and `look-back` are a straight eased glide and promise only the clearance. `cut`, or
|
|
251
251
|
* `reduced`, gives the last view for every `t` above 0.
|
|
252
252
|
*
|
package/dist/space/travel.js
CHANGED
|
@@ -924,7 +924,7 @@ function faultsOf(route) {
|
|
|
924
924
|
faults.empty += 1;
|
|
925
925
|
if (s.around !== undefined && !s.around.inside)
|
|
926
926
|
faults.planet += 1;
|
|
927
|
-
if (i / 240 < route.
|
|
927
|
+
if (i / 240 < route.legStart && !s.leaving.inside && !(s.around?.inside === true))
|
|
928
928
|
faults.held += 1;
|
|
929
929
|
if (i >= afterTurn && !s.destination.inside)
|
|
930
930
|
faults.lost += 1;
|
|
@@ -1230,7 +1230,7 @@ export function travelPlan(input) {
|
|
|
1230
1230
|
}
|
|
1231
1231
|
/**
|
|
1232
1232
|
* The camera at the moment `t` of a move, from 0 (the first view) to 1 (the last view), with where the two bodies are in the picture. The same input and moment always give the same camera. The default move,
|
|
1233
|
-
* `turn-travel`, never shows an empty picture between two framed views: the body being left (or the planet circled) is held in the picture through the turn, and the destination from the end of the turn on,
|
|
1233
|
+
* `turn-travel`, never shows an empty picture between two framed views: the body being left (or the planet circled) is held in the picture through the turn until the way on starts, one of the two bodies is in it while the two overlap, and the destination from the end of the turn on,
|
|
1234
1234
|
* where it only grows; the look direction turns one way only; no place is nearer a body than `TRAVEL_CLEARANCE`. `direct` and `look-back` are a straight eased glide and promise only the clearance. `cut`, or
|
|
1235
1235
|
* `reduced`, gives the last view for every `t` above 0.
|
|
1236
1236
|
*
|
|
@@ -77,6 +77,7 @@ export declare class WakuseiSurface extends HTMLElement {
|
|
|
77
77
|
renderer: SharedRenderer<ThreeParts>["stats"] | undefined;
|
|
78
78
|
mesh: SurfaceScene["mesh"] | undefined;
|
|
79
79
|
quality: string;
|
|
80
|
+
gliding: boolean;
|
|
80
81
|
scale: number;
|
|
81
82
|
scaled: number;
|
|
82
83
|
landing: {
|
|
@@ -91,6 +92,13 @@ export declare class WakuseiSurface extends HTMLElement {
|
|
|
91
92
|
rocks: number;
|
|
92
93
|
vehicleDrawn: boolean;
|
|
93
94
|
};
|
|
95
|
+
/** Where the camera was in the last draw: the eye (metres east and north of the site, and its height) and the look; during a move it is the pose on the way, not where the view will end. `undefined` before the first draw. */
|
|
96
|
+
get camera(): {
|
|
97
|
+
east: number;
|
|
98
|
+
north: number;
|
|
99
|
+
up: number;
|
|
100
|
+
look: Look;
|
|
101
|
+
} | undefined;
|
|
94
102
|
connectedCallback(): void;
|
|
95
103
|
disconnectedCallback(): void;
|
|
96
104
|
attributeChangedCallback(name: string): void;
|