@johnmorrisdotca/wakusei-planets 0.69.0 → 0.70.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 +46 -0
- package/NOTICE.md +29 -1
- package/README.md +7 -7
- package/dist/bodies/moons-jupiter.js +2 -0
- package/dist/bodies/moons-mars.js +2 -2
- package/dist/bodies/moons-neptune.js +2 -1
- package/dist/bodies/moons-pluto.js +2 -2
- package/dist/bodies/moons-saturn.js +14 -2
- package/dist/data/discovery.js +225 -0
- package/dist/data/moon-catalogue.js +15 -15
- package/dist/data/orbits.js +15 -0
- package/dist/data/shapes/amalthea.d.ts +2 -0
- package/dist/data/shapes/amalthea.js +1 -0
- package/dist/data/shapes/atlas.d.ts +2 -0
- package/dist/data/shapes/atlas.js +1 -0
- package/dist/data/shapes/calypso.d.ts +2 -0
- package/dist/data/shapes/calypso.js +1 -0
- package/dist/data/shapes/daphnis.d.ts +2 -0
- package/dist/data/shapes/daphnis.js +1 -0
- package/dist/data/shapes/deimos.d.ts +2 -0
- package/dist/data/shapes/deimos.js +1 -0
- package/dist/data/shapes/epimetheus.d.ts +2 -0
- package/dist/data/shapes/epimetheus.js +1 -0
- package/dist/data/shapes/helene.d.ts +2 -0
- package/dist/data/shapes/helene.js +1 -0
- package/dist/data/shapes/hydra.d.ts +2 -0
- package/dist/data/shapes/hydra.js +1 -0
- package/dist/data/shapes/hyperion.d.ts +2 -0
- package/dist/data/shapes/hyperion.js +1 -0
- package/dist/data/shapes/janus.d.ts +2 -0
- package/dist/data/shapes/janus.js +1 -0
- package/dist/data/shapes/larissa.d.ts +2 -0
- package/dist/data/shapes/larissa.js +1 -0
- package/dist/data/shapes/nix.d.ts +2 -0
- package/dist/data/shapes/nix.js +1 -0
- package/dist/data/shapes/pan.d.ts +2 -0
- package/dist/data/shapes/pan.js +1 -0
- package/dist/data/shapes/pandora.d.ts +2 -0
- package/dist/data/shapes/pandora.js +1 -0
- package/dist/data/shapes/phobos.d.ts +2 -0
- package/dist/data/shapes/phobos.js +1 -0
- package/dist/data/shapes/phoebe.d.ts +2 -0
- package/dist/data/shapes/phoebe.js +1 -0
- package/dist/data/shapes/prometheus.d.ts +2 -0
- package/dist/data/shapes/prometheus.js +1 -0
- package/dist/data/shapes/proteus.d.ts +2 -0
- package/dist/data/shapes/proteus.js +1 -0
- package/dist/data/shapes/telesto.d.ts +2 -0
- package/dist/data/shapes/telesto.js +1 -0
- package/dist/data/shapes/thebe.d.ts +2 -0
- package/dist/data/shapes/thebe.js +1 -0
- package/dist/discovery.d.ts +1 -1
- package/dist/earth-places.d.ts +7 -6
- package/dist/earth-places.js +11 -8
- package/dist/facts.d.ts +21 -4
- package/dist/facts.js +71 -38
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/moon-catalogue.d.ts +1 -1
- package/dist/nearest.js +2 -0
- package/dist/picture-credits.js +3 -0
- package/dist/scene/body-places.js +4 -5
- package/dist/scene/body.js +10 -5
- package/dist/scene/earth-places.d.ts +110 -2
- package/dist/scene/earth-places.js +149 -9
- package/dist/scene/glsl.d.ts +2 -2
- package/dist/scene/glsl.js +11 -0
- package/dist/scene/look.d.ts +7 -0
- package/dist/scene/look.js +1 -0
- package/dist/scene/painter.js +18 -3
- package/dist/scene/recipes.js +6 -2
- package/dist/scene/rings.js +11 -2
- package/dist/scene/shape.d.ts +50 -0
- package/dist/scene/shape.js +110 -0
- package/dist/shape-basis.d.ts +43 -0
- package/dist/shape-basis.js +45 -0
- package/dist/space/all-moons.d.ts +6 -1
- package/dist/space/all-moons.js +5 -1
- package/dist/space/element.d.ts +28 -3
- package/dist/space/element.js +169 -40
- package/dist/space/orbit-lines.d.ts +66 -0
- package/dist/space/orbit-lines.js +118 -0
- package/dist/space/scale.d.ts +1 -1
- package/dist/space/scale.js +20 -5
- package/dist/space/scene.d.ts +8 -0
- package/dist/space/scene.js +116 -9
- package/dist/stops.js +12 -0
- package/dist/surface/element.js +3 -3
- package/dist/surface/glsl.d.ts +2 -2
- package/dist/surface/glsl.js +15 -3
- package/dist/surface/height.d.ts +7 -0
- package/dist/surface/height.js +10 -0
- package/dist/textures/deimos-1024.webp +0 -0
- package/dist/textures/deimos-512.webp +0 -0
- package/dist/textures/phobos-1024.webp +0 -0
- package/dist/textures/phobos-512.webp +0 -0
- package/dist/textures/phoebe-1024.webp +0 -0
- package/dist/textures/phoebe-512.webp +0 -0
- package/package.json +1 -1
package/dist/space/element.js
CHANGED
|
@@ -25,11 +25,12 @@ import { besideMoon } from "./beside.js";
|
|
|
25
25
|
import { SUN_REGIONS } from "./regions.js";
|
|
26
26
|
import { travelArrival } from "./travel.js";
|
|
27
27
|
import { controlsFor, readFrame } from "./hold.js";
|
|
28
|
+
import { nearestLine } from "./orbit-lines.js";
|
|
28
29
|
import { catalogueMoonIdOf, catalogueMoonKey, hostsShowingAll, MOON_HOSTS, moonSourceOf, readMoonColors, readMoonsChoice, readMoonsOf } from "./moon-settings.js";
|
|
29
30
|
import { findPlace, PLACE_BODIES } from "../places.js";
|
|
30
31
|
import { marksToShow, pointUnder, readPlaceLayers, readSurfaceNames, spotView } from "../place-marks.js";
|
|
31
32
|
import { createPlaceLayer, onPlacesLoader, placesLoader } from "../scene/place-layer.js";
|
|
32
|
-
import { createEarthPlaceLayer, EARTH_PLACE_MARKS, EARTH_PLACES_FROM_PX, earthPlacesLayout, onEarthPlacesLayout, readEarthPlaceLook } from "../scene/earth-places.js";
|
|
33
|
+
import { createEarthPlaceLayer, earthPlaceClick, EARTH_PLACE_MARKS, EARTH_PLACES_FROM_PX, earthPlacesLayout, inMarkOrder, onEarthPlacesLayout, readEarthPlaceLayers, readEarthPlaceLook, shownEarthPlaces } from "../scene/earth-places.js";
|
|
33
34
|
import { layBodyPlaces, bodiesOf, readBodyPlacesWith } from "../scene/body-places.js";
|
|
34
35
|
import { cross, dot, length, sub, unit } from "../vec.js";
|
|
35
36
|
import { createSpaceItem, FIT_DISTANCE, framedOf, heldAim, moonScaleFor, newSpaceModel, SPACE_BODIES } from "./scene.js";
|
|
@@ -37,6 +38,8 @@ import { paintLengthOf, paintSwathOf } from "../paint/trail.js";
|
|
|
37
38
|
export { setPlacesLoader } from "../scene/place-layer.js";
|
|
38
39
|
export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS } from "../scene/earth-places.js";
|
|
39
40
|
export { setThreeLoader, SPACE_BODIES };
|
|
41
|
+
/** The small moons that came with their real shapes (Amalthea, Thebe, Saturn's small moons, Hyperion, Phoebe, Larissa): too small to be a companion that frames a move to their planet, so a move to Jupiter still keeps Io or another of the four and takes the side it always took. */
|
|
42
|
+
const SMALL_MOONS = new Set(["amalthea", "thebe", "pan", "daphnis", "atlas", "prometheus", "pandora", "epimetheus", "janus", "telesto", "calypso", "helene", "hyperion", "phoebe", "larissa"]);
|
|
40
43
|
/** The words the view says on itself for the scale in use. A page in another language gives its own with `scaleNames`. */
|
|
41
44
|
const SCALE_WORDS = {
|
|
42
45
|
en: { true: "True distances", compressed: "Distances squeezed to fit" },
|
|
@@ -111,9 +114,12 @@ const readBody = (value) => {
|
|
|
111
114
|
* 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.
|
|
112
115
|
*/
|
|
113
116
|
const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3.6, tiltMax: 90 };
|
|
114
|
-
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[data-flip]{display:flex;flex-direction:row-reverse}.sp-label[data-flip]::before{margin:0 -2px 1px 5px}.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[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{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,.sp-arrow{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}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}.sp-note{position:absolute;left:10px;right:10px;top:28px;max-width:44em;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.92;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-note[hidden],.sp-oort[hidden]{display:none}.sp-oort{position:absolute;left:0;top:0;margin:0;padding:0;font:italic 12px/16px system-ui,-apple-system,sans-serif;color:#aeb8e6;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none;transition:opacity .35s ease}.sp-oort[data-covered]{opacity:0}@media (prefers-reduced-motion:reduce){.sp-oort{transition:none}}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p><p class="sp-region" id="region" part="region" role="status" hidden></p><p class="sp-note" part="note" role="status" hidden></p><p class="sp-oort" part="oort" hidden></p>`;
|
|
117
|
+
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[data-flip]{display:flex;flex-direction:row-reverse}.sp-label[data-flip]::before{margin:0 -2px 1px 5px}.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[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{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,.sp-arrow{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}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}.sp-note{position:absolute;left:10px;right:10px;top:28px;max-width:44em;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.92;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-note[hidden],.sp-oort[hidden]{display:none}.sp-oort{position:absolute;left:0;top:0;margin:0;padding:0;font:italic 12px/16px system-ui,-apple-system,sans-serif;color:#aeb8e6;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none;transition:opacity .35s ease}.sp-oort[data-covered]{opacity:0}@media (prefers-reduced-motion:reduce){.sp-oort{transition:none}}.sp-line{position:absolute;inset:0;width:100%;height:100%;overflow:hidden;pointer-events:none}.sp-line[hidden],.sp-linename[hidden]{display:none}.sp-line path{fill:none;stroke-width:2;stroke-linejoin:round;stroke-linecap:round}.sp-linename{position:absolute;left:0;top:0;margin:0;padding:0;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}</style><div id="stage"></div><svg class="sp-line" part="line" aria-hidden="true" hidden><path/></svg><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p><p class="sp-region" id="region" part="region" role="status" hidden></p><p class="sp-note" part="note" role="status" hidden></p><p class="sp-oort" part="oort" hidden></p><p class="sp-linename" part="line-name" hidden></p>`;
|
|
115
118
|
/** A dot of a moon of the catalogue answers a press within this many CSS pixels: smaller than a body's, so a crowd of dots can be told apart, and more than the dot is wide. */
|
|
116
119
|
const MOON_DOT_HIT_PX = 9;
|
|
120
|
+
/** How near an orbit line must be to the pointer to be lit by it, and to a press (a finger is less exact), in CSS pixels. */
|
|
121
|
+
const LINE_HIT_PX = 6;
|
|
122
|
+
const LINE_TOUCH_PX = 8;
|
|
117
123
|
const orbiterLines = (value) => (value === "chosen" || value === "none" ? value : "all");
|
|
118
124
|
/**
|
|
119
125
|
* 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`
|
|
@@ -148,7 +154,7 @@ const orbiterLines = (value) => (value === "chosen" || value === "none" ? value
|
|
|
148
154
|
* ```
|
|
149
155
|
*/
|
|
150
156
|
export class WakuseiSpace extends HTMLElement {
|
|
151
|
-
static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "spacecraft", "orbiters", "asteroids", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "help-place", "places", "surface-names", "site-flags", "earth-places", "earth-places-look", "body-places", "all-moons", "moons", "moons-of", "moon-colors", "far-opacity", "transition", "pace", "frame", "pair-with", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
|
|
157
|
+
static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "spacecraft", "orbiters", "asteroids", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "help-place", "places", "surface-names", "site-flags", "earth-places", "earth-places-look", "earth-place-layers", "body-places", "all-moons", "moons", "moons-of", "moon-colors", "far-opacity", "transition", "pace", "frame", "pair-with", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
|
|
152
158
|
#model = newSpaceModel();
|
|
153
159
|
#moons = "major";
|
|
154
160
|
#moonsOf = {};
|
|
@@ -174,6 +180,8 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
174
180
|
#scaleLine;
|
|
175
181
|
#noteLine;
|
|
176
182
|
#oortLabel;
|
|
183
|
+
#lineLayer;
|
|
184
|
+
#lineName;
|
|
177
185
|
/** The belt the camera is flying through, and the point it flies on (the ride's target, to know the ride is still this one). */
|
|
178
186
|
#flight = null;
|
|
179
187
|
#spacing = new Map();
|
|
@@ -267,6 +275,8 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
267
275
|
this.#regionLine = root.getElementById("region");
|
|
268
276
|
this.#noteLine = root.querySelector(".sp-note");
|
|
269
277
|
this.#oortLabel = root.querySelector(".sp-oort");
|
|
278
|
+
this.#lineLayer = root.querySelector(".sp-line");
|
|
279
|
+
this.#lineName = root.querySelector(".sp-linename");
|
|
270
280
|
this.#nameScale();
|
|
271
281
|
this.#showRegion();
|
|
272
282
|
this.#pool.clear();
|
|
@@ -358,6 +368,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
358
368
|
window.removeEventListener("pointercancel", this.#lift, true);
|
|
359
369
|
if (this.#hovered !== null)
|
|
360
370
|
this.#hover(null, this.#hoverBy);
|
|
371
|
+
this.#lineKey = null;
|
|
361
372
|
clearTimeout(this.#sightTimer);
|
|
362
373
|
this.#sightTimer = undefined;
|
|
363
374
|
this.removeEventListener("wheel", this.#wheel, { capture: true });
|
|
@@ -461,9 +472,9 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
461
472
|
this.#relabel();
|
|
462
473
|
if (name === "places" || name === "site-flags" || name === "lang" || name === "surface-names")
|
|
463
474
|
this.#markSurface();
|
|
464
|
-
if (name === "earth-places" || name === "earth-places-look")
|
|
475
|
+
if (name === "earth-places" || name === "earth-places-look" || name === "earth-place-layers")
|
|
465
476
|
this.#askEarthPlaces();
|
|
466
|
-
if (name === "body-places" || name === "earth-places-look")
|
|
477
|
+
if (name === "body-places" || name === "earth-places-look" || name === "earth-place-layers")
|
|
467
478
|
this.#askBodyPlaces();
|
|
468
479
|
}
|
|
469
480
|
/**
|
|
@@ -549,9 +560,37 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
549
560
|
else
|
|
550
561
|
this.setAttribute("earth-places-look", look);
|
|
551
562
|
}
|
|
552
|
-
/**
|
|
563
|
+
/**
|
|
564
|
+
* Which layers of places are shown (the attribute `earth-place-layers`, a JSON object of a layer's name to true or false), for `earthPlaces` and `bodyPlaces` alike: a place whose `layer` is named `false` is left out, with its name, and cannot be pressed; any other place,
|
|
565
|
+
* and any layer not named, is shown. The page hands over every place once and switches the layers, instead of building a list for each switch. Setting the property writes the attribute; an empty object takes it away. `earthPlacesShown.hidden` counts the places left out.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* ```ts no-run
|
|
569
|
+
* import "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
570
|
+
* import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
571
|
+
*
|
|
572
|
+
* const space = document.querySelector<WakuseiSpace>("wakusei-space")!;
|
|
573
|
+
* space.earthPlaceLayers = { harbours: false };
|
|
574
|
+
* space.setEarthPlaceLayer("harbours", true);
|
|
575
|
+
* ```
|
|
576
|
+
*/
|
|
577
|
+
get earthPlaceLayers() {
|
|
578
|
+
return readEarthPlaceLayers(this.getAttribute("earth-place-layers"));
|
|
579
|
+
}
|
|
580
|
+
set earthPlaceLayers(layers) {
|
|
581
|
+
if (layers === null || Object.keys(layers).length === 0)
|
|
582
|
+
this.removeAttribute("earth-place-layers");
|
|
583
|
+
else
|
|
584
|
+
this.setAttribute("earth-place-layers", JSON.stringify(layers));
|
|
585
|
+
}
|
|
586
|
+
/** Show or hide one layer of places and leave the others as they are: `earthPlaceLayers` with that layer changed. */
|
|
587
|
+
setEarthPlaceLayer(name, shown) {
|
|
588
|
+
this.earthPlaceLayers = { ...this.earthPlaceLayers, [name]: shown };
|
|
589
|
+
}
|
|
590
|
+
/** The markers laid on the Earth now, as the last draw left them: each place's id and kind, where its foot is in CSS pixels from the view's top left and whether its name is drawn; `omitted` counts the places in sight beyond the first `EARTH_PLACE_MARKS`, and `hidden` the places left out because their layer is off. */
|
|
553
591
|
get earthPlacesShown() {
|
|
554
|
-
|
|
592
|
+
const all = this.#readEarthPlaces();
|
|
593
|
+
return { marks: this.#earthLayer?.shown ?? [], omitted: this.#earthOmitted, hidden: all.length - shownEarthPlaces(all, this.earthPlaceLayers).length };
|
|
555
594
|
}
|
|
556
595
|
/**
|
|
557
596
|
* The places laid on the bodies other than the Earth wherever the camera looks, drawn as the Earth's are (`earthPlaces`): a list of `{ body, id, lon, lat, label, kind, color }`, `body` being `moon`, `mars`, `ceres` and so on (an entry for `earth` is not drawn:
|
|
@@ -578,9 +617,10 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
578
617
|
else
|
|
579
618
|
this.setAttribute("body-places", JSON.stringify(list));
|
|
580
619
|
}
|
|
581
|
-
/** The markers laid on the other bodies now, as the last draw left them: each place's body, id and kind, where its foot is in CSS pixels from the view's top left and whether its name is drawn; `omitted` counts the places in sight beyond the first `EARTH_PLACE_MARKS
|
|
620
|
+
/** The markers laid on the other bodies now, as the last draw left them: each place's body, id and kind, where its foot is in CSS pixels from the view's top left and whether its name is drawn; `omitted` counts the places in sight beyond the first `EARTH_PLACE_MARKS`, and `hidden` the places left out because their layer is off. */
|
|
582
621
|
get bodyPlacesShown() {
|
|
583
|
-
|
|
622
|
+
const all = this.#readBodyPlaces();
|
|
623
|
+
return { marks: (this.#bodyLayer?.shown ?? []), omitted: this.#bodyOmitted, hidden: all.length - shownEarthPlaces(all, this.earthPlaceLayers).length };
|
|
584
624
|
}
|
|
585
625
|
/**
|
|
586
626
|
* Go to a place on a body: the view glides to the body (as `goTo` does), or on the body looked at turns round it, and the camera comes to rest straight above the place. The place is an id (`mars/perseverance`) or an English or Japanese name, on the body looked at
|
|
@@ -752,9 +792,8 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
752
792
|
return [];
|
|
753
793
|
if (this.#earthList?.text === text)
|
|
754
794
|
return this.#earthList.list;
|
|
755
|
-
// the places that matter most first: where the reader is, then the rest in the order given
|
|
756
|
-
const
|
|
757
|
-
const ordered = [...list.filter((place) => place.kind === "here"), ...list.filter((place) => place.kind !== "here")];
|
|
795
|
+
// the places that matter most first: where the reader is, then the rest in the order given, then those whose name is low
|
|
796
|
+
const ordered = inMarkOrder(using.read(text));
|
|
758
797
|
this.#earthList = { text, list: ordered };
|
|
759
798
|
return ordered;
|
|
760
799
|
}
|
|
@@ -785,10 +824,10 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
785
824
|
return clear();
|
|
786
825
|
if (surface === null || root === null || using === undefined || !this.hasAttribute("earth-places") || !(surface.radiusPx >= EARTH_PLACES_FROM_PX))
|
|
787
826
|
return clear();
|
|
788
|
-
const places = this.#readEarthPlaces();
|
|
827
|
+
const places = shownEarthPlaces(this.#readEarthPlaces(), this.earthPlaceLayers);
|
|
789
828
|
if (places.length === 0)
|
|
790
829
|
return clear();
|
|
791
|
-
this.#earthLayer ??= createEarthPlaceLayer(root, { press: (mark, event) => this.#pressBeam("earth", mark, event) });
|
|
830
|
+
this.#earthLayer ??= createEarthPlaceLayer(root, { press: (mark, event, place) => this.#pressBeam("earth", mark, event, place) });
|
|
792
831
|
const layer = this.#earthLayer;
|
|
793
832
|
const facts = BODIES.earth;
|
|
794
833
|
const scale = [1, 1 - facts.flattening, 1];
|
|
@@ -847,10 +886,10 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
847
886
|
};
|
|
848
887
|
if (root === null || using === undefined || !this.hasAttribute("body-places") || this.#bodySurfaces.length === 0)
|
|
849
888
|
return clear();
|
|
850
|
-
const places = this.#readBodyPlaces();
|
|
889
|
+
const places = shownEarthPlaces(this.#readBodyPlaces(), this.earthPlaceLayers);
|
|
851
890
|
if (places.length === 0)
|
|
852
891
|
return clear();
|
|
853
|
-
this.#bodyLayer ??= createEarthPlaceLayer(root, { press: (mark, event) => this.#pressBeam(mark.body ?? "", mark, event) });
|
|
892
|
+
this.#bodyLayer ??= createEarthPlaceLayer(root, { press: (mark, event, place) => this.#pressBeam(mark.body ?? "", mark, event, place) });
|
|
854
893
|
const layer = this.#bodyLayer;
|
|
855
894
|
const look = this.earthPlacesLook;
|
|
856
895
|
const laid = layBodyPlaces(places, this.#bodySurfaces, using, look, {
|
|
@@ -862,9 +901,14 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
862
901
|
this.#bodyOmitted = laid.omitted;
|
|
863
902
|
layer.set(laid.places, laid.layout, look);
|
|
864
903
|
}
|
|
865
|
-
/**
|
|
866
|
-
|
|
904
|
+
/**
|
|
905
|
+
* A press on a beam's name or foot ring: the event `wakusei-place-click`, `{ body, id, kind, layer, label, lon, lat, x, y }` (chikyu-earth's `chikyu-place-click` with the body; `x` and `y` are the press), and `wakusei-body-place`, `{ body, id, kind, x, y }` with the mark's foot
|
|
906
|
+
* (the same for the Earth's places, `body: "earth"`). The page decides what it does; the body under the press is not pressed as well.
|
|
907
|
+
*/
|
|
908
|
+
#pressBeam(body, mark, event, place) {
|
|
867
909
|
this.#beamPress = event;
|
|
910
|
+
const box = this.getBoundingClientRect();
|
|
911
|
+
this.dispatchEvent(new CustomEvent("wakusei-place-click", { detail: earthPlaceClick(body, place, event.clientX - box.left, event.clientY - box.top), bubbles: true, composed: true }));
|
|
868
912
|
this.dispatchEvent(new CustomEvent("wakusei-body-place", { detail: { body, id: mark.id, kind: mark.kind, x: mark.x, y: mark.y }, bubbles: true, composed: true }));
|
|
869
913
|
}
|
|
870
914
|
async #loadMarks(body) {
|
|
@@ -1955,7 +1999,8 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1955
1999
|
if (host !== undefined)
|
|
1956
2000
|
add(host, 1);
|
|
1957
2001
|
for (const moon of MOONS_OF[id] ?? [])
|
|
1958
|
-
|
|
2002
|
+
if (!SMALL_MOONS.has(moon))
|
|
2003
|
+
add(moon, 1);
|
|
1959
2004
|
if (this.#arrivedFrom !== null)
|
|
1960
2005
|
add(this.#arrivedFrom, 2);
|
|
1961
2006
|
const here = this.#site(id).at;
|
|
@@ -2491,7 +2536,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
2491
2536
|
ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null },
|
|
2492
2537
|
travelling: this.#model.travelling === null ? null : { ...this.#model.travelling },
|
|
2493
2538
|
region: this.#model.region === null ? null : { id: this.#model.region, name: this.#regionName(this.#model.region), reach: this.#model.regionDrawn?.reach ?? 0, distance: this.#model.regionDrawn?.distance ?? 0 },
|
|
2494
|
-
orbits: { drawn: [...this.#model.rings.drawn], miss: { ...this.#model.rings.miss }, hidden: [...this.#model.rings.hidden], faded: [...this.#model.rings.faded] },
|
|
2539
|
+
orbits: { drawn: [...this.#model.rings.drawn], miss: { ...this.#model.rings.miss }, hidden: [...this.#model.rings.hidden], faded: [...this.#model.rings.faded], fade: { ...this.#model.rings.fade } },
|
|
2495
2540
|
arrows: Object.fromEntries(Object.entries(this.#model.arrows).map(([id, list]) => [id, list.map((a) => ({ position: [...a.position], direction: [...a.direction] }))])),
|
|
2496
2541
|
arrowPx: this.#model.arrowPx,
|
|
2497
2542
|
help: this.#model.helpDrawn ? { body: this.#model.helpDrawn.body, axis: [...this.#model.helpDrawn.axis], pole: [...this.#model.helpDrawn.pole], retrograde: this.#model.helpDrawn.retrograde, arcTurn: [...this.#model.helpDrawn.arcTurn] } : null,
|
|
@@ -2672,6 +2717,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
2672
2717
|
ring.style.transform = `translate(${Math.round(places[id].x)}px,${Math.round(places[id].y)}px)`;
|
|
2673
2718
|
}
|
|
2674
2719
|
this.#placeArrows(places);
|
|
2720
|
+
this.#followLine();
|
|
2675
2721
|
this.#markFar();
|
|
2676
2722
|
// the names written on the body keep off the names and dots just placed
|
|
2677
2723
|
this.#markSurface();
|
|
@@ -2730,7 +2776,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
2730
2776
|
this.dispatchEvent(new CustomEvent("wakusei-body-hover", { detail: this.#moonDetail(id), bubbles: true, composed: true }));
|
|
2731
2777
|
else if (id !== null && this.#isAsteroid(id))
|
|
2732
2778
|
this.dispatchEvent(new CustomEvent("wakusei-body-hover", { detail: { id: asteroidIdOf(id), name: this.#nameOf(id), kind: "small-body" }, bubbles: true, composed: true }));
|
|
2733
|
-
else if (id !== null && (id === "roadster" || this.#model.craftIds.includes(id)))
|
|
2779
|
+
else if (id !== null && (id === "roadster" || this.#model.craftIds.includes(id) || this.#model.orbiterSet?.ids.includes(id) === true))
|
|
2734
2780
|
this.dispatchEvent(new CustomEvent("wakusei-body-hover", { detail: { id, name: this.#nameOf(id), kind: "spacecraft" }, bubbles: true, composed: true }));
|
|
2735
2781
|
else if (id !== null)
|
|
2736
2782
|
this.dispatchEvent(new CustomEvent("wakusei-body-hover", { detail: { ...this.bodyInfo(id), system: systemOf(id) }, bubbles: true, composed: true }));
|
|
@@ -2780,12 +2826,87 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
2780
2826
|
return;
|
|
2781
2827
|
if (this.#hoverBy === "focus" && this.#hovered !== null)
|
|
2782
2828
|
return;
|
|
2783
|
-
this
|
|
2829
|
+
const rect = this.getBoundingClientRect();
|
|
2830
|
+
const x = event.clientX - rect.left;
|
|
2831
|
+
const y = event.clientY - rect.top;
|
|
2832
|
+
// a body is under the pointer before a line is; with the names off nothing is lit
|
|
2833
|
+
const body = this.#bodyAt(x, y);
|
|
2834
|
+
const line = body === null && this.#model.labels && this.#model.orbits ? this.#lineAt(x, y, false) : null;
|
|
2835
|
+
this.#hover(body ?? line?.id ?? null, "pointer");
|
|
2836
|
+
this.#lightLine(line, x, y);
|
|
2784
2837
|
};
|
|
2785
2838
|
#leave = (event) => {
|
|
2786
|
-
if (event.pointerType !== "touch" && this.#hoverBy === "pointer")
|
|
2839
|
+
if (event.pointerType !== "touch" && this.#hoverBy === "pointer") {
|
|
2787
2840
|
this.#hover(null, "pointer");
|
|
2841
|
+
this.#lightLine(null);
|
|
2842
|
+
}
|
|
2788
2843
|
};
|
|
2844
|
+
// --- the orbit line under the pointer ----------------------------------------------------------------------------------------------------------------
|
|
2845
|
+
/** The key of the orbit line lit by the pointer, which is the key of its body, or null. */
|
|
2846
|
+
#lineKey = null;
|
|
2847
|
+
#lineNameWidth = 0;
|
|
2848
|
+
/** The orbit line nearest a point of the element, in CSS pixels, within the reach of a pointer or of a finger. Worked out when asked, never at a draw. */
|
|
2849
|
+
#lineAt(x, y, touch) {
|
|
2850
|
+
return nearestLine(this.#model.orbitPaths(), { x, y }, touch ? LINE_TOUCH_PX : LINE_HIT_PX);
|
|
2851
|
+
}
|
|
2852
|
+
/**
|
|
2853
|
+
* Light an orbit line: its path in full strength over the picture, in a layer of the view's own, so that lighting a line draws nothing; and the name of its body beside the pointer. `null` puts both away.
|
|
2854
|
+
* The lit line is kept up with the pictures that follow (`#followLine`).
|
|
2855
|
+
*/
|
|
2856
|
+
#lightLine(line, x = 0, y = 0) {
|
|
2857
|
+
const layer = this.#lineLayer;
|
|
2858
|
+
const name = this.#lineName;
|
|
2859
|
+
if (layer === undefined || name === undefined)
|
|
2860
|
+
return;
|
|
2861
|
+
if (line === null) {
|
|
2862
|
+
this.#lineKey = null;
|
|
2863
|
+
if (!layer.hasAttribute("hidden"))
|
|
2864
|
+
layer.setAttribute("hidden", "");
|
|
2865
|
+
if (!name.hidden)
|
|
2866
|
+
name.hidden = true;
|
|
2867
|
+
return;
|
|
2868
|
+
}
|
|
2869
|
+
if (line.id !== this.#lineKey) {
|
|
2870
|
+
this.#lineKey = line.id;
|
|
2871
|
+
layer.removeAttribute("hidden");
|
|
2872
|
+
layer.querySelector("path").setAttribute("stroke", line.colour);
|
|
2873
|
+
name.textContent = this.#nameOf(line.id);
|
|
2874
|
+
name.hidden = false;
|
|
2875
|
+
this.#lineNameWidth = name.offsetWidth;
|
|
2876
|
+
}
|
|
2877
|
+
this.#drawLine(line);
|
|
2878
|
+
// beside the pointer, on the side that stays inside the view
|
|
2879
|
+
const left = x + 14 + this.#lineNameWidth > this.clientWidth ? x - 14 - this.#lineNameWidth : x + 14;
|
|
2880
|
+
name.style.transform = `translate(${Math.round(Math.max(0, left))}px,${Math.round(Math.max(0, y - 20))}px)`;
|
|
2881
|
+
}
|
|
2882
|
+
/** The line's points as the path of the lit layer: a gap where the line is behind the camera. */
|
|
2883
|
+
#drawLine(line) {
|
|
2884
|
+
let d = "";
|
|
2885
|
+
let drawing = false;
|
|
2886
|
+
for (let i = 0; i + 1 < line.xy.length; i += 2) {
|
|
2887
|
+
const x = line.xy[i];
|
|
2888
|
+
if (x !== x) {
|
|
2889
|
+
drawing = false;
|
|
2890
|
+
continue;
|
|
2891
|
+
}
|
|
2892
|
+
d += `${drawing ? "L" : "M"}${x.toFixed(1)} ${line.xy[i + 1].toFixed(1)}`;
|
|
2893
|
+
drawing = true;
|
|
2894
|
+
}
|
|
2895
|
+
this.#lineLayer.querySelector("path").setAttribute("d", d);
|
|
2896
|
+
}
|
|
2897
|
+
/** After a draw: the lit line is where the draw put it, or gone (its body's line is no longer drawn). Only the lit line is worked out. */
|
|
2898
|
+
#followLine() {
|
|
2899
|
+
if (this.#lineKey === null)
|
|
2900
|
+
return;
|
|
2901
|
+
const line = this.#model.orbitPaths(this.#lineKey)[0];
|
|
2902
|
+
if (line === undefined) {
|
|
2903
|
+
if (this.#hovered === this.#lineKey)
|
|
2904
|
+
this.#hover(null, "pointer");
|
|
2905
|
+
this.#lightLine(null);
|
|
2906
|
+
}
|
|
2907
|
+
else
|
|
2908
|
+
this.#drawLine(line);
|
|
2909
|
+
}
|
|
2789
2910
|
#labelBlur = (event) => {
|
|
2790
2911
|
const next = event.relatedTarget;
|
|
2791
2912
|
if (this.#hoverBy === "focus" && !(next && this.#labelBox?.contains(next)))
|
|
@@ -2990,9 +3111,17 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
2990
3111
|
return;
|
|
2991
3112
|
const rect = this.getBoundingClientRect();
|
|
2992
3113
|
// the one hit test the hover uses: a body's disc (14 pixels at least) or, failing that, a drawn name's box, so a press on a name picks its body
|
|
2993
|
-
const
|
|
2994
|
-
|
|
3114
|
+
const x = event.clientX - rect.left;
|
|
3115
|
+
const y = event.clientY - rect.top;
|
|
3116
|
+
const best = this.#bodyAt(x, y, true);
|
|
3117
|
+
if (best) {
|
|
2995
3118
|
this.#press(best);
|
|
3119
|
+
return;
|
|
3120
|
+
}
|
|
3121
|
+
// failing a body, an orbit line is a press on its body; Ctrl or Command goes there at once
|
|
3122
|
+
const line = this.#model.orbits ? this.#lineAt(x, y, event.pointerType === "touch") : null;
|
|
3123
|
+
if (line !== null)
|
|
3124
|
+
this.#press(line.id, event.ctrlKey || event.metaKey);
|
|
2996
3125
|
};
|
|
2997
3126
|
#labelClick = (event) => {
|
|
2998
3127
|
const target = event.target;
|
|
@@ -3011,22 +3140,22 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
3011
3140
|
};
|
|
3012
3141
|
/**
|
|
3013
3142
|
* 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
|
|
3014
|
-
* the middle of the view (`goTo`), unless it already is, so a press never sends the view anywhere else.
|
|
3143
|
+
* the middle of the view (`goTo`), unless it already is, so a press never sends the view anywhere else. With `teleport` (Ctrl or Command held on an orbit line) the press selects and goes there at once, without the glide.
|
|
3015
3144
|
*/
|
|
3016
|
-
#press(id) {
|
|
3145
|
+
#press(id, teleport = false) {
|
|
3017
3146
|
if (this.#catalogueMoon(id) !== undefined) {
|
|
3018
3147
|
// a moon of the catalogue is no body of the package: the press says which one, in the body event and in an event of its own; the first press selects it, and a second makes its planet the middle of the view
|
|
3019
3148
|
const detail = this.#moonDetail(id);
|
|
3020
3149
|
this.dispatchEvent(new CustomEvent("wakusei-body-click", { detail, bubbles: true, composed: true }));
|
|
3021
3150
|
this.dispatchEvent(new CustomEvent("wakusei-moon-click", { detail, bubbles: true, composed: true }));
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
return;
|
|
3151
|
+
const first = this.#selected !== id;
|
|
3152
|
+
if (first) {
|
|
3153
|
+
this.#selected = id;
|
|
3154
|
+
this.dispatchEvent(new CustomEvent("wakusei-body-select", { detail, bubbles: true, composed: true }));
|
|
3027
3155
|
}
|
|
3028
|
-
|
|
3029
|
-
|
|
3156
|
+
const host = detail.host;
|
|
3157
|
+
if ((!first || teleport) && canCentre(host) && this.#model.focus !== host)
|
|
3158
|
+
this.goTo(host, teleport ? { smooth: false } : {});
|
|
3030
3159
|
return;
|
|
3031
3160
|
}
|
|
3032
3161
|
// the Roadster and the orbiters are no bodies of the package: a press on such a name says so and goes nowhere
|
|
@@ -3044,13 +3173,13 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
3044
3173
|
return;
|
|
3045
3174
|
}
|
|
3046
3175
|
this.dispatchEvent(new CustomEvent("wakusei-body-click", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3176
|
+
const first = this.#selected !== id;
|
|
3177
|
+
if (first) {
|
|
3178
|
+
this.#selected = id;
|
|
3179
|
+
this.dispatchEvent(new CustomEvent("wakusei-body-select", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
|
|
3051
3180
|
}
|
|
3052
|
-
this.#
|
|
3053
|
-
|
|
3181
|
+
if ((!first || teleport) && canCentre(id) && this.#model.focus !== id)
|
|
3182
|
+
this.goTo(id, teleport ? { smooth: false } : {});
|
|
3054
3183
|
}
|
|
3055
3184
|
#labelFocus = (event) => {
|
|
3056
3185
|
const id = event.target?.dataset?.["body"];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Up to this many lines drawn, none is made fainter for the crowd. */
|
|
2
|
+
export declare const FEW_LINES = 12;
|
|
3
|
+
/** The least share of its opacity a line keeps, however many are drawn and however far out the view is. */
|
|
4
|
+
export declare const LEAST_KEEP = 0.15;
|
|
5
|
+
/** The view is "near" at this many radii of the body it looks at, and "far out" at the second: the share of opacity falls between them on a log scale (the Earth and the Moon from a few hundred radii, the inner planets from the Sun a thousand, the whole system from the Earth a million). */
|
|
6
|
+
export declare const NEAR_RADII = 30;
|
|
7
|
+
export declare const FAR_RADII = 30000;
|
|
8
|
+
/** How much of a line's opacity the farthest view takes away. */
|
|
9
|
+
export declare const FAR_LOSS = 0.5;
|
|
10
|
+
/**
|
|
11
|
+
* How far out the view is: 0 within `NEAR_RADII` of the body it looks at, 1 from `FAR_RADII`, and the log of the distance between.
|
|
12
|
+
*
|
|
13
|
+
* @param radii - The camera's distance from the body looked at, in that body's radii.
|
|
14
|
+
* @returns A number from 0 to 1.
|
|
15
|
+
*/
|
|
16
|
+
export declare function outnessOf(radii: number): number;
|
|
17
|
+
/**
|
|
18
|
+
* The share of its opacity an orbit line keeps: all of it while few lines are drawn and the view is near, less as more are drawn (by the square root of how many times over `FEW_LINES` they are) and as the view goes out, never under `LEAST_KEEP`.
|
|
19
|
+
*
|
|
20
|
+
* @param input - `crowd`, how many lines are drawn, and `outness`, from `outnessOf`.
|
|
21
|
+
* @returns The share, from `LEAST_KEEP` to 1.
|
|
22
|
+
*/
|
|
23
|
+
export declare function lineKeep(input: {
|
|
24
|
+
crowd: number;
|
|
25
|
+
outness: number;
|
|
26
|
+
}): number;
|
|
27
|
+
/**
|
|
28
|
+
* The opacity to draw an orbit line at.
|
|
29
|
+
*
|
|
30
|
+
* @param input - `base`, the opacity the kind of line has when it is alone, and what `lineKeep` takes.
|
|
31
|
+
* @returns The opacity, from `base * LEAST_KEEP` to `base`.
|
|
32
|
+
*/
|
|
33
|
+
export declare const lineAlpha: (input: {
|
|
34
|
+
base: number;
|
|
35
|
+
crowd: number;
|
|
36
|
+
outness: number;
|
|
37
|
+
}) => number;
|
|
38
|
+
/** An orbit line as the screen shows it: `xy` is its points as x, y, x, y in CSS pixels, with NaN, NaN where the line is behind the camera (the line is broken there). */
|
|
39
|
+
export interface ScreenLine {
|
|
40
|
+
/** The view's key of the body the line is of (`moon`, `mars`, a catalogue moon's key, a craft's id). */
|
|
41
|
+
id: string;
|
|
42
|
+
/** `#rrggbb`. */
|
|
43
|
+
colour: string;
|
|
44
|
+
xy: ArrayLike<number>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* How many lines have some of their length in the picture: a line counts when one of its segments has the box it lies in over the picture (a long segment that only crosses a corner counts too).
|
|
48
|
+
*
|
|
49
|
+
* @param lines - The lines, in CSS pixels.
|
|
50
|
+
* @param width - The picture's width, in CSS pixels.
|
|
51
|
+
* @param height - The picture's height.
|
|
52
|
+
* @returns The number of lines in the picture.
|
|
53
|
+
*/
|
|
54
|
+
export declare function linesInView(lines: readonly ScreenLine[], width: number, height: number): number;
|
|
55
|
+
/**
|
|
56
|
+
* The line nearest a point of the screen, within a distance. Each line is first measured by the box its points lie in (the box grown by the distance), and only a line the point is in the box of has its segments measured.
|
|
57
|
+
*
|
|
58
|
+
* @param lines - The lines on the screen.
|
|
59
|
+
* @param pointer - The point, in CSS pixels.
|
|
60
|
+
* @param tolerance - The farthest a line may be from the point, in CSS pixels.
|
|
61
|
+
* @returns The nearest line, or `null` when none is within the distance.
|
|
62
|
+
*/
|
|
63
|
+
export declare function nearestLine(lines: readonly ScreenLine[], pointer: {
|
|
64
|
+
x: number;
|
|
65
|
+
y: number;
|
|
66
|
+
}, tolerance: number): ScreenLine | null;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// How faint the space view draws its orbit lines, and which line is under the pointer. Pure: no DOM, no clock, no three.js.
|
|
2
|
+
/** Up to this many lines drawn, none is made fainter for the crowd. */
|
|
3
|
+
export const FEW_LINES = 12;
|
|
4
|
+
/** The least share of its opacity a line keeps, however many are drawn and however far out the view is. */
|
|
5
|
+
export const LEAST_KEEP = 0.15;
|
|
6
|
+
/** The view is "near" at this many radii of the body it looks at, and "far out" at the second: the share of opacity falls between them on a log scale (the Earth and the Moon from a few hundred radii, the inner planets from the Sun a thousand, the whole system from the Earth a million). */
|
|
7
|
+
export const NEAR_RADII = 30;
|
|
8
|
+
export const FAR_RADII = 30_000;
|
|
9
|
+
/** How much of a line's opacity the farthest view takes away. */
|
|
10
|
+
export const FAR_LOSS = 0.5;
|
|
11
|
+
/**
|
|
12
|
+
* How far out the view is: 0 within `NEAR_RADII` of the body it looks at, 1 from `FAR_RADII`, and the log of the distance between.
|
|
13
|
+
*
|
|
14
|
+
* @param radii - The camera's distance from the body looked at, in that body's radii.
|
|
15
|
+
* @returns A number from 0 to 1.
|
|
16
|
+
*/
|
|
17
|
+
export function outnessOf(radii) {
|
|
18
|
+
if (!(radii > NEAR_RADII))
|
|
19
|
+
return 0;
|
|
20
|
+
return Math.min(1, Math.log(radii / NEAR_RADII) / Math.log(FAR_RADII / NEAR_RADII));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The share of its opacity an orbit line keeps: all of it while few lines are drawn and the view is near, less as more are drawn (by the square root of how many times over `FEW_LINES` they are) and as the view goes out, never under `LEAST_KEEP`.
|
|
24
|
+
*
|
|
25
|
+
* @param input - `crowd`, how many lines are drawn, and `outness`, from `outnessOf`.
|
|
26
|
+
* @returns The share, from `LEAST_KEEP` to 1.
|
|
27
|
+
*/
|
|
28
|
+
export function lineKeep(input) {
|
|
29
|
+
const crowded = input.crowd > FEW_LINES ? Math.sqrt(FEW_LINES / input.crowd) : 1;
|
|
30
|
+
const far = 1 - FAR_LOSS * Math.max(0, Math.min(1, input.outness));
|
|
31
|
+
return Math.max(LEAST_KEEP, crowded * far);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The opacity to draw an orbit line at.
|
|
35
|
+
*
|
|
36
|
+
* @param input - `base`, the opacity the kind of line has when it is alone, and what `lineKeep` takes.
|
|
37
|
+
* @returns The opacity, from `base * LEAST_KEEP` to `base`.
|
|
38
|
+
*/
|
|
39
|
+
export const lineAlpha = (input) => input.base * lineKeep(input);
|
|
40
|
+
/**
|
|
41
|
+
* How many lines have some of their length in the picture: a line counts when one of its segments has the box it lies in over the picture (a long segment that only crosses a corner counts too).
|
|
42
|
+
*
|
|
43
|
+
* @param lines - The lines, in CSS pixels.
|
|
44
|
+
* @param width - The picture's width, in CSS pixels.
|
|
45
|
+
* @param height - The picture's height.
|
|
46
|
+
* @returns The number of lines in the picture.
|
|
47
|
+
*/
|
|
48
|
+
export function linesInView(lines, width, height) {
|
|
49
|
+
let count = 0;
|
|
50
|
+
for (const line of lines) {
|
|
51
|
+
const p = line.xy;
|
|
52
|
+
for (let i = 0; i + 3 < p.length; i += 2) {
|
|
53
|
+
const ax = p[i];
|
|
54
|
+
const bx = p[i + 2];
|
|
55
|
+
if (ax !== ax || bx !== bx)
|
|
56
|
+
continue;
|
|
57
|
+
const ay = p[i + 1];
|
|
58
|
+
const by = p[i + 3];
|
|
59
|
+
if (Math.max(ax, bx) >= 0 && Math.min(ax, bx) <= width && Math.max(ay, by) >= 0 && Math.min(ay, by) <= height) {
|
|
60
|
+
count += 1;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return count;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The line nearest a point of the screen, within a distance. Each line is first measured by the box its points lie in (the box grown by the distance), and only a line the point is in the box of has its segments measured.
|
|
69
|
+
*
|
|
70
|
+
* @param lines - The lines on the screen.
|
|
71
|
+
* @param pointer - The point, in CSS pixels.
|
|
72
|
+
* @param tolerance - The farthest a line may be from the point, in CSS pixels.
|
|
73
|
+
* @returns The nearest line, or `null` when none is within the distance.
|
|
74
|
+
*/
|
|
75
|
+
export function nearestLine(lines, pointer, tolerance) {
|
|
76
|
+
const { x, y } = pointer;
|
|
77
|
+
let best = null;
|
|
78
|
+
let bestD = tolerance;
|
|
79
|
+
for (const line of lines) {
|
|
80
|
+
const p = line.xy;
|
|
81
|
+
let minX = Infinity;
|
|
82
|
+
let minY = Infinity;
|
|
83
|
+
let maxX = -Infinity;
|
|
84
|
+
let maxY = -Infinity;
|
|
85
|
+
for (let i = 0; i + 1 < p.length; i += 2) {
|
|
86
|
+
const px = p[i];
|
|
87
|
+
const py = p[i + 1];
|
|
88
|
+
if (px < minX)
|
|
89
|
+
minX = px;
|
|
90
|
+
if (px > maxX)
|
|
91
|
+
maxX = px;
|
|
92
|
+
if (py < minY)
|
|
93
|
+
minY = py;
|
|
94
|
+
if (py > maxY)
|
|
95
|
+
maxY = py;
|
|
96
|
+
}
|
|
97
|
+
if (x < minX - bestD || x > maxX + bestD || y < minY - bestD || y > maxY + bestD)
|
|
98
|
+
continue;
|
|
99
|
+
for (let i = 0; i + 3 < p.length; i += 2) {
|
|
100
|
+
const ax = p[i];
|
|
101
|
+
const ay = p[i + 1];
|
|
102
|
+
const bx = p[i + 2];
|
|
103
|
+
const by = p[i + 3];
|
|
104
|
+
if (ax !== ax || bx !== bx)
|
|
105
|
+
continue;
|
|
106
|
+
const dx = bx - ax;
|
|
107
|
+
const dy = by - ay;
|
|
108
|
+
const length = dx * dx + dy * dy;
|
|
109
|
+
const t = length === 0 ? 0 : Math.max(0, Math.min(1, ((x - ax) * dx + (y - ay) * dy) / length));
|
|
110
|
+
const d = Math.hypot(x - (ax + t * dx), y - (ay + t * dy));
|
|
111
|
+
if (d <= bestD) {
|
|
112
|
+
best = line;
|
|
113
|
+
bestD = d;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return best;
|
|
118
|
+
}
|
package/dist/space/scale.d.ts
CHANGED
|
@@ -126,7 +126,7 @@ type BaseBody = "sun" | "earth" | "moon" | SpacePlanet | SpaceDwarf | SpaceMinor
|
|
|
126
126
|
*/
|
|
127
127
|
export declare function radiusIn(id: "sun" | "earth" | "moon" | SpacePlanet | SpaceDwarf | SpaceMinor, mode: ScaleMode): number;
|
|
128
128
|
/**
|
|
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
|
|
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 (but never inside the planet's rings: a moon that really goes through them is drawn just outside), until the farthest of the planet's moons would
|
|
130
130
|
* reach across the gap to the next planet's orbit; then every moon is drawn nearer, the farthest at about a third of the gap and the nearer ones in the order they are, so no moon's orbit crosses another planet's,
|
|
131
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.
|
|
132
132
|
*
|