@johnmorrisdotca/chikyu-earth 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 +12 -0
- package/README.md +1 -1
- package/dist/element.js +1 -1
- package/dist/realistic/earth.js +1 -1
- package/dist/realistic/element.d.ts +19 -0
- package/dist/realistic/element.js +27 -2
- package/dist/realistic/index.d.ts +1 -0
- package/dist/sky/cover.d.ts +48 -0
- package/dist/sky/cover.js +100 -0
- package/dist/sky/culture-lines.d.ts +56 -0
- package/dist/sky/culture-lines.js +82 -0
- package/dist/sky/figure-pick.d.ts +75 -0
- package/dist/sky/figure-pick.js +200 -0
- package/dist/sky/host.d.ts +17 -1
- package/dist/sky/host.js +633 -59
- package/dist/sky/keep-clear.d.ts +63 -0
- package/dist/sky/keep-clear.js +55 -0
- package/dist/space/element.d.ts +24 -3
- package/dist/space/element.js +30 -3
- package/dist/space/index.d.ts +1 -1
- package/dist/space/index.js +1 -1
- package/dist/space/satellite-model.d.ts +22 -0
- package/dist/space/satellite-model.js +38 -0
- package/dist/space/scene.d.ts +5 -2
- package/dist/space/scene.js +38 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.35.0 - 2026-11-12
|
|
6
|
+
|
|
7
|
+
- **The figures follow a sky culture** (MODULES-1125). `constellation-culture` is `iau` (the 88, the default), `western`, `japanese` (the 88 by their Japanese names, then the traditional figures such as Subaru, the Pleiades) or `chinese`; the lines, the hovered and picked figure and its name follow it, and the events carry `id`, `kind` and `culture`. The value is exactly what the page sets (a Japanese page keeps the IAU's figures unless it says `japanese`); an unknown value is `iau` with one warning. Each culture's data is a dynamic import of its own, fetched only when asked for. hoshi-stars' `createFigureLines` takes no culture yet, so the lines of a culture are laid out here from `figures(culture)`.
|
|
8
|
+
- **Say which constellation was picked, reveal its name on hover, and an option to name every constellation** (MODULES-1108). A mouse resting on a figure (its lines, or inside it) lights it and fades its name in at the middle of the part of it that is on the picture, inside the frame, off the Earth and clear of the star names; a click or tap picks it and the name stays until another pick or a click on empty sky, `Escape` or the property set to `null` (`C` and `Shift`+`C` pick with the keyboard). `chikyu-constellation-hover` and `chikyu-constellation-pick` are sent with `{ abbreviation, name, english, japanese, culture }` (`null` when let go), and `constellation` reads or sets the pick. The name sat above the figure's whole box, which includes the part off the picture, so a figure that ran off the top had its name left near its bottom. `constellation-names` (off by default) writes every figure's name in view, quieter than the star names, in the page's language, with no overlap. The hit test runs once a frame at most, only after the pointer has moved, and the layer is drawn again only when the hovered figure changes. A pick is read out by a visually hidden polite live region (a hover is not). A pick set before a sky culture has arrived is kept until it has.
|
|
9
|
+
- **A page can mark places where the sky's names must not go** (MODULES-1124). `<chikyu-space>` and `<chikyu-earth-realistic>` take `keepClear` (a list of rectangles in the element's pixels, or of page elements) and the attribute `keep-clear` (a CSS selector). A star name that touches one is left out, a star whose point is in one is not named, and the picked constellation's name moves clear of it; the lines are still drawn. The boxes are read when the list changes or the page is resized or scrolled (the names are laid out again at the next frame, once however many events), never at each frame.
|
|
10
|
+
- **Ride above a satellite** (MODULES-1138). `ride(ref, { view: "above" })` puts the camera on the line from the Earth's centre through the satellite, `distanceKm` over the zoom above it, looking straight down at it with the way it is going at the top of the picture. The satellite stays in the middle while the clock moves it and the Earth turns beneath; a drag turns the picture about it and tips the camera back or ahead of it; the zoom changes the height; a satellite model is drawn there as in the follow view. It glides from and to the other views (a jump for reduced motion) and draws as the follow view does. `aboveAxes` gives the camera's place and top. The demo has an "Above it" button and the address `rview=above`.
|
|
11
|
+
|
|
12
|
+
## 0.34.1 - 2026-11-11
|
|
13
|
+
|
|
14
|
+
- **The sky is behind the Earth: constellation lines no longer cross it** (MODULES-1103). The lines were drawn over the Earth's disc (in a ride, across the whole globe). Each line is now cut exactly at the Earth's edge, the air's rim included, in the picture's own camera, in the space view and in a ride at any height, on the day side and the night side. A star whose point, ring or name box touches the Earth, the Moon or the Sun has its name and ring left out (a name only partly on the Earth was shown before), and the figure under the pointer is not lit over the Earth.
|
|
15
|
+
- **The element is its own stacking context** (MODULES-1104). `<chikyu-earth>`, `<chikyu-earth-realistic>` and `<chikyu-space>` are each their own stacking context (`isolation: isolate`), so nothing inside the element (the sky's labels, its lines, its markers) takes part in the page's own stacking: it paints as one piece, where the element sits in the page.
|
|
16
|
+
|
|
5
17
|
## 0.34.0 - 2026-11-11
|
|
6
18
|
|
|
7
19
|
- **You are here, and places on the Earth** (MODULES-927). `<chikyu-space>` and `<chikyu-earth-realistic>` take `places`, a list of `{ id, lon, lat, label, kind }` (attribute as JSON, or property), and draw each as a marker standing out of the ground: it turns with the Earth, is hidden on the far side, fades at the edge and keeps its size in pixels at any zoom. `kind: "here"` is the reader's place (taller, brighter, a quiet pulse at its foot); a `favourite` is quieter. `places-look` is `beam` (the default), `pin` or `ring`; colours come from `--chikyu-place-here` and `--chikyu-place-favourite`. Names sit at the top of the markers, `here` first, measured in the page's font and never over one another or the bodies' names. Nothing is drawn again at rest: the places are laid out with the picture, and the pulse is a CSS animation, stopped out of sight and for a reader who asked for less motion. `stats.places` says how many are drawn and named. The package never asks for the reader's place and stores or sends nothing; `nearby` (in `/markers`, with `readPlaces`, `cleanPlaces`, `orthoView` and `layoutPlaces`) rounds a place to about 10 km before a page draws or keeps it. `placeLabels` takes boxes already used by another layer. The demo has "Show where I am" (asked only on the press, rounded, never put in the address) and the three looks. New guide: "You are here, and places on the Earth".
|
package/README.md
CHANGED
|
@@ -590,7 +590,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
|
|
|
590
590
|
|
|
591
591
|
## How to cite
|
|
592
592
|
|
|
593
|
-
> Morris, J. (2026). *Chikyu Earth* (version 0.
|
|
593
|
+
> Morris, J. (2026). *Chikyu Earth* (version 0.35.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
|
|
594
594
|
|
|
595
595
|
GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
|
|
596
596
|
|
package/dist/element.js
CHANGED
|
@@ -21,7 +21,7 @@ const LIVE_MS = 1000 / 30;
|
|
|
21
21
|
const AUTO_MS = 1000;
|
|
22
22
|
/** Tilt to the poles; zoom from a tenth of Fit, which leaves the whole globe small in the view, to 20 times: the outlines are Natural Earth 1:110m, and past about 20 times their straight segments are longer than the view is wide. */
|
|
23
23
|
const LIMITS = { tiltMax: 90, zoomMin: 0.1, zoomMax: 20 };
|
|
24
|
-
const STYLE = ":host{display:block;position:relative}.holder svg{display:block;width:100%;height:auto}.overlay{position:absolute;inset:0;pointer-events:none;transform-origin:50% 50%}";
|
|
24
|
+
const STYLE = ":host{display:block;position:relative;isolation:isolate}.holder svg{display:block;width:100%;height:auto}.overlay{position:absolute;inset:0;pointer-events:none;transform-origin:50% 50%}";
|
|
25
25
|
/**
|
|
26
26
|
* The `<chikyu-earth>` custom element: the line globe, drawn as SVG in its shadow root. Importing this entry point registers the tag once. It takes the attributes `size` (pixels, 320 by default), `center` (`"lon,lat"`; wins over the browser's location), `look` (`line` or `thick`; `style` is the older name for it, and a framework that reads `style` as CSS cannot use it) and `graticule`, and a shared view controller's camera through `setView`.
|
|
27
27
|
* It carries kazoku-ui's controls itself: a drag turns it, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused, from a tenth of Fit to 20 times. `controls="none"` turns them off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`.
|
package/dist/realistic/earth.js
CHANGED
|
@@ -244,7 +244,7 @@ export function createEarthItem(model, deps) {
|
|
|
244
244
|
deps.onSky({
|
|
245
245
|
width: size.width,
|
|
246
246
|
height: size.height,
|
|
247
|
-
discs: [{ x: cx, y: cy, radius }],
|
|
247
|
+
discs: [{ x: cx, y: cy, radius: radius * airTop(model.airThickness) }],
|
|
248
248
|
project(rightAscension, declination, out) {
|
|
249
249
|
const r = rightAscension * RAD;
|
|
250
250
|
const d = declination * RAD;
|
|
@@ -5,6 +5,7 @@ import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/type
|
|
|
5
5
|
import { type SatelliteStyle } from "../space/satellite-layer.ts";
|
|
6
6
|
import type { Credit, DataSource } from "../data-door.ts";
|
|
7
7
|
import { type BodyLabelSettings } from "./body-label.ts";
|
|
8
|
+
import type { SkyKeepClear } from "../sky/keep-clear.ts";
|
|
8
9
|
import type { SkyLabelStyle } from "../sky/style.ts";
|
|
9
10
|
import { type Place, type PlaceLook } from "../markers/places.ts";
|
|
10
11
|
import { type CityNamesStyle } from "../cities/host.ts";
|
|
@@ -143,6 +144,20 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
143
144
|
*/
|
|
144
145
|
get skyStyle(): Partial<SkyLabelStyle>;
|
|
145
146
|
set skyStyle(value: Partial<SkyLabelStyle>);
|
|
147
|
+
/**
|
|
148
|
+
* The constellation that is picked, by its IAU abbreviation (`Ori`), or `null`. A reader picks one by a click or a tap on its lines or inside its figure (and with the key `C`, or `Shift`+`C` for the previous, while the element has the focus); a click on empty sky, or `Escape`, lets it go. The picked figure's lines are lit and its name is
|
|
149
|
+
* shown at the middle of the part of it in view, until another is picked or it is let go. A page sets the property to pick one itself, which sends no event. `chikyu-constellation-pick` is sent at each pick of the reader's, with `detail` `{ abbreviation, id, name, english, japanese, kind, culture }` (`culture` is `iau` unless `constellation-culture` names another), and `null` when it is let go; `chikyu-constellation-hover` is sent the same way as a mouse rests on a figure and leaves it.
|
|
150
|
+
* Needs `constellation-lines` set. `constellation-culture` (`iau` by default, `western`, `japanese` or `chinese`; each is fetched only when asked for, and the value is exactly what the page sets) makes the figures, the pick and the names those of that sky culture. The attribute `constellation-names` (off by default) writes the name of every figure in view at the middle of the part of it that is on the picture, quieter than the star names and clear of them, of the Earth, the Moon, the Sun, the places and satellites named, and of the places kept clear (`keepClear`).
|
|
151
|
+
*/
|
|
152
|
+
get constellation(): string | null;
|
|
153
|
+
set constellation(value: string | null);
|
|
154
|
+
/**
|
|
155
|
+
* Places on the picture where the sky's names must not go: a page's own text laid over the element, say. Each is a rectangle in the element's own CSS pixels from its top left (`{ x, y, width, height }`), or an element of the page whose box is read. A star name whose box touches
|
|
156
|
+
* one is left out, and so is a star whose point is in one (the next star is named instead); the picked constellation's name is moved clear of it. The lines are still drawn. The boxes are read when the list changes, when the page or an element is resized or scrolled, and not at each frame: a
|
|
157
|
+
* page that moves its text without resizing it sets the property again. The attribute `keep-clear` takes a CSS selector for the same (`keep-clear=".hero h1, .hero .lead"`). Nothing is redrawn at rest.
|
|
158
|
+
*/
|
|
159
|
+
get keepClear(): SkyKeepClear[];
|
|
160
|
+
set keepClear(value: readonly SkyKeepClear[] | null);
|
|
146
161
|
/**
|
|
147
162
|
* Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
|
|
148
163
|
* (the default: quieter). Each stands up out of the ground, turns with the Earth, is hidden on its far side and keeps its size in pixels at any zoom. Names go at the top, `here` first, and never overlap
|
|
@@ -253,6 +268,10 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
253
268
|
names: number;
|
|
254
269
|
figures: number;
|
|
255
270
|
picked: string | null;
|
|
271
|
+
pick: string | null;
|
|
272
|
+
hover: string | null;
|
|
273
|
+
constellations: number;
|
|
274
|
+
culture: string;
|
|
256
275
|
renders: number;
|
|
257
276
|
lang: string;
|
|
258
277
|
stars: {
|
|
@@ -23,7 +23,7 @@ import { createGate, frameCap } from "./gate.js";
|
|
|
23
23
|
import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
|
|
24
24
|
export { setSharedRenderer, setThreeLoader };
|
|
25
25
|
import { MAX_TEXTURE, TIERS } from "./tiers.js";
|
|
26
|
-
const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative}: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,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}" + PLACE_STYLE + SKY_STYLE + CITY_NAMES_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
|
|
26
|
+
const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative;isolation:isolate}: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,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}" + PLACE_STYLE + SKY_STYLE + CITY_NAMES_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
|
|
27
27
|
const RAD = Math.PI / 180;
|
|
28
28
|
/** The Sun and the clouds are re-placed this often at real time: 15 degrees an hour is 0.25 degree a minute. */
|
|
29
29
|
const LIVE_TICK_MS = 60_000;
|
|
@@ -172,6 +172,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
172
172
|
/** The names of the stars and the constellation lines (`star-names`, `constellation-lines`), and the look of the names. */
|
|
173
173
|
#sky;
|
|
174
174
|
#skyStyle = {};
|
|
175
|
+
#keepClear = [];
|
|
175
176
|
#airNote;
|
|
176
177
|
#onContext = (state) => {
|
|
177
178
|
if (state === "unavailable")
|
|
@@ -214,6 +215,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
214
215
|
loadFont: loadMichroma,
|
|
215
216
|
});
|
|
216
217
|
this.#sky.setStyle(this.#skyStyle);
|
|
218
|
+
this.#sky.setKeepClear(this.#keepClear);
|
|
217
219
|
this.#placeLayer = createPlaceLayer(root.getElementById("places"));
|
|
218
220
|
this.#placeList = readPlaces(this.getAttribute("places"));
|
|
219
221
|
this.#placeLayer.set(this.#placeList);
|
|
@@ -478,6 +480,29 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
478
480
|
this.#skyStyle = { ...value };
|
|
479
481
|
this.#sky?.setStyle(this.#skyStyle);
|
|
480
482
|
}
|
|
483
|
+
/**
|
|
484
|
+
* The constellation that is picked, by its IAU abbreviation (`Ori`), or `null`. A reader picks one by a click or a tap on its lines or inside its figure (and with the key `C`, or `Shift`+`C` for the previous, while the element has the focus); a click on empty sky, or `Escape`, lets it go. The picked figure's lines are lit and its name is
|
|
485
|
+
* shown at the middle of the part of it in view, until another is picked or it is let go. A page sets the property to pick one itself, which sends no event. `chikyu-constellation-pick` is sent at each pick of the reader's, with `detail` `{ abbreviation, id, name, english, japanese, kind, culture }` (`culture` is `iau` unless `constellation-culture` names another), and `null` when it is let go; `chikyu-constellation-hover` is sent the same way as a mouse rests on a figure and leaves it.
|
|
486
|
+
* Needs `constellation-lines` set. `constellation-culture` (`iau` by default, `western`, `japanese` or `chinese`; each is fetched only when asked for, and the value is exactly what the page sets) makes the figures, the pick and the names those of that sky culture. The attribute `constellation-names` (off by default) writes the name of every figure in view at the middle of the part of it that is on the picture, quieter than the star names and clear of them, of the Earth, the Moon, the Sun, the places and satellites named, and of the places kept clear (`keepClear`).
|
|
487
|
+
*/
|
|
488
|
+
get constellation() {
|
|
489
|
+
return this.#sky?.picked ?? null;
|
|
490
|
+
}
|
|
491
|
+
set constellation(value) {
|
|
492
|
+
this.#sky?.pick(value);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Places on the picture where the sky's names must not go: a page's own text laid over the element, say. Each is a rectangle in the element's own CSS pixels from its top left (`{ x, y, width, height }`), or an element of the page whose box is read. A star name whose box touches
|
|
496
|
+
* one is left out, and so is a star whose point is in one (the next star is named instead); the picked constellation's name is moved clear of it. The lines are still drawn. The boxes are read when the list changes, when the page or an element is resized or scrolled, and not at each frame: a
|
|
497
|
+
* page that moves its text without resizing it sets the property again. The attribute `keep-clear` takes a CSS selector for the same (`keep-clear=".hero h1, .hero .lead"`). Nothing is redrawn at rest.
|
|
498
|
+
*/
|
|
499
|
+
get keepClear() {
|
|
500
|
+
return [...this.#keepClear];
|
|
501
|
+
}
|
|
502
|
+
set keepClear(value) {
|
|
503
|
+
this.#keepClear = value ? [...value] : [];
|
|
504
|
+
this.#sky?.setKeepClear(this.#keepClear);
|
|
505
|
+
}
|
|
481
506
|
/**
|
|
482
507
|
* Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
|
|
483
508
|
* (the default: quieter). Each stands up out of the ground, turns with the Earth, is hidden on its far side and keeps its size in pixels at any zoom. Names go at the top, `here` first, and never overlap
|
|
@@ -713,7 +738,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
713
738
|
assets: { entries: stats?.assets.entries ?? 0, refs: stats?.assets.refs ?? 0 },
|
|
714
739
|
meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
|
|
715
740
|
bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
|
|
716
|
-
sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, renders: 0, lang: "", stars: [] },
|
|
741
|
+
sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, pick: null, hover: null, constellations: 0, culture: "iau", renders: 0, lang: "", stars: [] },
|
|
717
742
|
places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0 }) },
|
|
718
743
|
cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
|
|
719
744
|
};
|
|
@@ -9,5 +9,6 @@ export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, loadMichroma, setB
|
|
|
9
9
|
export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness, type AirSamples } from "./air.ts";
|
|
10
10
|
export { AIR_NOTE } from "./air-note.ts";
|
|
11
11
|
export type { SkyLabelStyle } from "../sky/style.ts";
|
|
12
|
+
export type { SkyKeepClear } from "../sky/keep-clear.ts";
|
|
12
13
|
export { CITY_NAMES_DEFAULT, CITY_NAMES_MAX, TIER_RADIUS, cityNameText, cityRank, cityTiersFor, layoutCities, nameWidth, readCityNames, type CityFrame, type CityLayoutOptions, type CityName, type CityNameTier, type NamedCity } from "../cities/geometry.ts";
|
|
13
14
|
export { CITY_NAMES_ATTRIBUTES, type CityNamesStyle } from "../cities/host.ts";
|
package/dist/sky/cover.d.ts
CHANGED
|
@@ -25,3 +25,51 @@ export declare function coverBody(position: readonly number[], camera: readonly
|
|
|
25
25
|
* @returns True where the ray meets a body.
|
|
26
26
|
*/
|
|
27
27
|
export declare function covers(bodies: readonly CoverBody[], x: number, y: number, z: number): boolean;
|
|
28
|
+
/** What `pathOutside` draws with: a canvas's context. */
|
|
29
|
+
export interface Path {
|
|
30
|
+
moveTo(x: number, y: number): void;
|
|
31
|
+
lineTo(x: number, y: number): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Adds a segment to the path, less the part of it a body covers. What a body covers of the picture is convex (a disc, or an ellipse towards the edges of a wide view), so a line meets it once at most: the segment is walked in short steps, and where one step
|
|
35
|
+
* is covered and the next is not, the edge between them is found by halving. Nothing is made; the path takes the pieces.
|
|
36
|
+
*
|
|
37
|
+
* @param path - The path to add the pieces to (a canvas's context).
|
|
38
|
+
* @param x0 - The segment's start, x.
|
|
39
|
+
* @param y0 - The start, y.
|
|
40
|
+
* @param x1 - The end, x.
|
|
41
|
+
* @param y1 - The end, y.
|
|
42
|
+
* @param covered - Whether a body covers a point of the picture, or `undefined` where none does.
|
|
43
|
+
* @param inset - How far, in pixels, a piece is held back from the edge it is cut at: half the line's width and its round end, so the stroke stays off the body.
|
|
44
|
+
*/
|
|
45
|
+
export declare function pathOutside(path: Path, x0: number, y0: number, x1: number, y1: number, covered: ((x: number, y: number) => boolean) | undefined, inset?: number): void;
|
|
46
|
+
/**
|
|
47
|
+
* Whether any part of a label is on a body: the corners and the middle of the name's edges, the star's own point and eight points of the ring round it, and the end of its leader.
|
|
48
|
+
*
|
|
49
|
+
* @param covered - Whether a body covers a point of the picture.
|
|
50
|
+
* @param left - The name's box, from the picture's top left.
|
|
51
|
+
* @param top - The box's top.
|
|
52
|
+
* @param right - The box's right.
|
|
53
|
+
* @param bottom - The box's bottom.
|
|
54
|
+
* @param label - The star's label, for its point, ring and leader.
|
|
55
|
+
* @returns True where some part is over a body.
|
|
56
|
+
*/
|
|
57
|
+
export declare function touches(covered: (x: number, y: number) => boolean, left: number, top: number, right: number, bottom: number, label: {
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
ring: number;
|
|
61
|
+
leader?: boolean;
|
|
62
|
+
leaderX1: number;
|
|
63
|
+
leaderY1: number;
|
|
64
|
+
}): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Whether any part of a box is on a body: its corners and the middle of its edges.
|
|
67
|
+
*
|
|
68
|
+
* @param covered - Whether a body covers a point of the picture.
|
|
69
|
+
* @param left - The box's left.
|
|
70
|
+
* @param top - The top.
|
|
71
|
+
* @param right - The right.
|
|
72
|
+
* @param bottom - The bottom.
|
|
73
|
+
* @returns True where some part is over a body.
|
|
74
|
+
*/
|
|
75
|
+
export declare function boxCovered(covered: (x: number, y: number) => boolean, left: number, top: number, right: number, bottom: number): boolean;
|
package/dist/sky/cover.js
CHANGED
|
@@ -30,3 +30,103 @@ export function covers(bodies, x, y, z) {
|
|
|
30
30
|
return true;
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
|
+
/** How far apart, in pixels, a line is tested for the cover: a line that dips under the edge of a body for less is not seen to (at the edge of a large body, a chord of this length is less than a pixel deep). */
|
|
34
|
+
const CLIP_STEP = 6;
|
|
35
|
+
/** How many times the edge of a body is halved to find where a line meets it: 6 narrows a step to a tenth of a pixel. */
|
|
36
|
+
const CLIP_HALVINGS = 6;
|
|
37
|
+
/**
|
|
38
|
+
* Adds a segment to the path, less the part of it a body covers. What a body covers of the picture is convex (a disc, or an ellipse towards the edges of a wide view), so a line meets it once at most: the segment is walked in short steps, and where one step
|
|
39
|
+
* is covered and the next is not, the edge between them is found by halving. Nothing is made; the path takes the pieces.
|
|
40
|
+
*
|
|
41
|
+
* @param path - The path to add the pieces to (a canvas's context).
|
|
42
|
+
* @param x0 - The segment's start, x.
|
|
43
|
+
* @param y0 - The start, y.
|
|
44
|
+
* @param x1 - The end, x.
|
|
45
|
+
* @param y1 - The end, y.
|
|
46
|
+
* @param covered - Whether a body covers a point of the picture, or `undefined` where none does.
|
|
47
|
+
* @param inset - How far, in pixels, a piece is held back from the edge it is cut at: half the line's width and its round end, so the stroke stays off the body.
|
|
48
|
+
*/
|
|
49
|
+
export function pathOutside(path, x0, y0, x1, y1, covered, inset = 0) {
|
|
50
|
+
if (!covered) {
|
|
51
|
+
path.moveTo(x0, y0);
|
|
52
|
+
path.lineTo(x1, y1);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const dx = x1 - x0;
|
|
56
|
+
const dy = y1 - y0;
|
|
57
|
+
const length = Math.hypot(dx, dy);
|
|
58
|
+
const steps = Math.max(1, Math.ceil(length / CLIP_STEP));
|
|
59
|
+
const back = length > 0 ? inset / length : 0;
|
|
60
|
+
let hidden = covered(x0, y0);
|
|
61
|
+
/** Where the piece being walked began along the segment (0 to 1), or -1 while it is under a body. */
|
|
62
|
+
let from = hidden ? -1 : 0;
|
|
63
|
+
let before = 0;
|
|
64
|
+
for (let i = 1; i <= steps; i += 1) {
|
|
65
|
+
const t = i / steps;
|
|
66
|
+
const now = covered(x0 + dx * t, y0 + dy * t);
|
|
67
|
+
if (now !== hidden) {
|
|
68
|
+
// the edge lies between `before` and `t`: `seen` is the side outside the body
|
|
69
|
+
let seen = hidden ? t : before;
|
|
70
|
+
let under = hidden ? before : t;
|
|
71
|
+
for (let h = 0; h < CLIP_HALVINGS; h += 1) {
|
|
72
|
+
const mid = (seen + under) / 2;
|
|
73
|
+
if (covered(x0 + dx * mid, y0 + dy * mid))
|
|
74
|
+
under = mid;
|
|
75
|
+
else
|
|
76
|
+
seen = mid;
|
|
77
|
+
}
|
|
78
|
+
if (now) {
|
|
79
|
+
const end = Math.max(from, seen - back);
|
|
80
|
+
path.moveTo(x0 + dx * from, y0 + dy * from);
|
|
81
|
+
path.lineTo(x0 + dx * end, y0 + dy * end);
|
|
82
|
+
from = -1;
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
from = Math.min(1, seen + back);
|
|
86
|
+
hidden = now;
|
|
87
|
+
}
|
|
88
|
+
before = t;
|
|
89
|
+
}
|
|
90
|
+
if (!hidden && from <= 1) {
|
|
91
|
+
path.moveTo(x0 + dx * from, y0 + dy * from);
|
|
92
|
+
path.lineTo(x1, y1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Whether any part of a label is on a body: the corners and the middle of the name's edges, the star's own point and eight points of the ring round it, and the end of its leader.
|
|
97
|
+
*
|
|
98
|
+
* @param covered - Whether a body covers a point of the picture.
|
|
99
|
+
* @param left - The name's box, from the picture's top left.
|
|
100
|
+
* @param top - The box's top.
|
|
101
|
+
* @param right - The box's right.
|
|
102
|
+
* @param bottom - The box's bottom.
|
|
103
|
+
* @param label - The star's label, for its point, ring and leader.
|
|
104
|
+
* @returns True where some part is over a body.
|
|
105
|
+
*/
|
|
106
|
+
export function touches(covered, left, top, right, bottom, label) {
|
|
107
|
+
if (boxCovered(covered, left, top, right, bottom))
|
|
108
|
+
return true;
|
|
109
|
+
if (covered(label.x, label.y))
|
|
110
|
+
return true;
|
|
111
|
+
// the ring is drawn a pixel wide and round: eight points of it, a pixel out
|
|
112
|
+
const ring = label.ring + 1;
|
|
113
|
+
const diagonal = ring * 0.7071;
|
|
114
|
+
if (label.ring > 0 && (covered(label.x - ring, label.y) || covered(label.x + ring, label.y) || covered(label.x, label.y - ring) || covered(label.x, label.y + ring) || covered(label.x - diagonal, label.y - diagonal) || covered(label.x + diagonal, label.y - diagonal) || covered(label.x - diagonal, label.y + diagonal) || covered(label.x + diagonal, label.y + diagonal)))
|
|
115
|
+
return true;
|
|
116
|
+
return Boolean(label.leader) && covered(label.leaderX1, label.leaderY1);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Whether any part of a box is on a body: its corners and the middle of its edges.
|
|
120
|
+
*
|
|
121
|
+
* @param covered - Whether a body covers a point of the picture.
|
|
122
|
+
* @param left - The box's left.
|
|
123
|
+
* @param top - The top.
|
|
124
|
+
* @param right - The right.
|
|
125
|
+
* @param bottom - The bottom.
|
|
126
|
+
* @returns True where some part is over a body.
|
|
127
|
+
*/
|
|
128
|
+
export function boxCovered(covered, left, top, right, bottom) {
|
|
129
|
+
const middle = (left + right) / 2;
|
|
130
|
+
const centre = (top + bottom) / 2;
|
|
131
|
+
return covered(left, top) || covered(middle, top) || covered(right, top) || covered(left, bottom) || covered(middle, bottom) || covered(right, bottom) || covered(left, centre) || covered(right, centre);
|
|
132
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { LabelStyle } from "@johnmorrisdotca/hoshi-stars/sky-labels";
|
|
2
|
+
/** A star's place in the sky, in degrees. */
|
|
3
|
+
export interface SkyPoint {
|
|
4
|
+
rightAscension: number;
|
|
5
|
+
declination: number;
|
|
6
|
+
}
|
|
7
|
+
/** A figure of a culture as lines: its key and the pairs of stars its lines join (hoshi-stars' `CultureFigure`, to the part used here). */
|
|
8
|
+
export interface CultureFigureLines {
|
|
9
|
+
id: string;
|
|
10
|
+
segments: ReadonlyArray<readonly [SkyPoint, SkyPoint]>;
|
|
11
|
+
}
|
|
12
|
+
/** One figure on the screen: where its lines are in `segments`, and its box. */
|
|
13
|
+
export interface OnScreen {
|
|
14
|
+
abbreviation: string;
|
|
15
|
+
start: number;
|
|
16
|
+
end: number;
|
|
17
|
+
left: number;
|
|
18
|
+
top: number;
|
|
19
|
+
right: number;
|
|
20
|
+
bottom: number;
|
|
21
|
+
x: number;
|
|
22
|
+
}
|
|
23
|
+
/** What the sky layer needs of a set of figure lines: those of hoshi-stars' `FigureLines` and of `createCultureLines`. */
|
|
24
|
+
export interface Lines {
|
|
25
|
+
readonly settings: Readonly<{
|
|
26
|
+
strength?: number;
|
|
27
|
+
reach?: number;
|
|
28
|
+
}>;
|
|
29
|
+
readonly style: LabelStyle;
|
|
30
|
+
readonly segments: ArrayLike<number>;
|
|
31
|
+
readonly count: number;
|
|
32
|
+
readonly figures: readonly OnScreen[];
|
|
33
|
+
opacityOf(figure: OnScreen): number;
|
|
34
|
+
update(project: (rightAscension: number, declination: number, out: {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
}) => boolean, view: {
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
}, avoid?: unknown): number;
|
|
41
|
+
set(next: {
|
|
42
|
+
strength?: number;
|
|
43
|
+
lang?: unknown;
|
|
44
|
+
style?: Partial<LabelStyle>;
|
|
45
|
+
}): void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The lines of the figures of a culture.
|
|
49
|
+
*
|
|
50
|
+
* @param figures - The culture's figures, from hoshi-stars' `figures(culture)`.
|
|
51
|
+
* @param strength - How strong the lines are when not lit, 0 to 1.
|
|
52
|
+
* @param styleOf - Makes a label style (hoshi-stars' `labelStyle`) from a partial one.
|
|
53
|
+
* @param style - The look of the names, a partial `LabelStyle`.
|
|
54
|
+
* @returns The lines.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createCultureLines(figures: readonly CultureFigureLines[], strength: number, styleOf: (style?: Partial<LabelStyle>) => LabelStyle, style?: Partial<LabelStyle>): Lines;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lines of the figures of a culture.
|
|
3
|
+
*
|
|
4
|
+
* @param figures - The culture's figures, from hoshi-stars' `figures(culture)`.
|
|
5
|
+
* @param strength - How strong the lines are when not lit, 0 to 1.
|
|
6
|
+
* @param styleOf - Makes a label style (hoshi-stars' `labelStyle`) from a partial one.
|
|
7
|
+
* @param style - The look of the names, a partial `LabelStyle`.
|
|
8
|
+
* @returns The lines.
|
|
9
|
+
*/
|
|
10
|
+
export function createCultureLines(figures, strength, styleOf, style) {
|
|
11
|
+
let total = 0;
|
|
12
|
+
for (const figure of figures)
|
|
13
|
+
total += figure.segments.length;
|
|
14
|
+
const segments = new Float32Array(total * 4);
|
|
15
|
+
const onScreen = figures.map((figure) => ({ abbreviation: figure.id, start: 0, end: 0, left: 0, top: 0, right: 0, bottom: 0, x: 0 }));
|
|
16
|
+
const a = { x: 0, y: 0 };
|
|
17
|
+
const b = { x: 0, y: 0 };
|
|
18
|
+
let current = Object.freeze({ strength });
|
|
19
|
+
let look = styleOf(style);
|
|
20
|
+
let count = 0;
|
|
21
|
+
return {
|
|
22
|
+
get settings() {
|
|
23
|
+
return current;
|
|
24
|
+
},
|
|
25
|
+
get style() {
|
|
26
|
+
return look;
|
|
27
|
+
},
|
|
28
|
+
segments,
|
|
29
|
+
get count() {
|
|
30
|
+
return count;
|
|
31
|
+
},
|
|
32
|
+
figures: onScreen,
|
|
33
|
+
opacityOf() {
|
|
34
|
+
return current.strength ?? 0;
|
|
35
|
+
},
|
|
36
|
+
set(next) {
|
|
37
|
+
current = Object.freeze({ ...current, strength: Math.max(0, Math.min(1, next.strength ?? current.strength ?? 0)) });
|
|
38
|
+
look = styleOf(next.style);
|
|
39
|
+
},
|
|
40
|
+
update(project, view) {
|
|
41
|
+
count = 0;
|
|
42
|
+
for (let i = 0; i < figures.length; i += 1) {
|
|
43
|
+
const out = onScreen[i];
|
|
44
|
+
out.start = count;
|
|
45
|
+
let left = Number.POSITIVE_INFINITY;
|
|
46
|
+
let top = Number.POSITIVE_INFINITY;
|
|
47
|
+
let right = Number.NEGATIVE_INFINITY;
|
|
48
|
+
let bottom = Number.NEGATIVE_INFINITY;
|
|
49
|
+
if ((current.strength ?? 0) > 0) {
|
|
50
|
+
const pairs = figures[i].segments;
|
|
51
|
+
for (let k = 0; k < pairs.length; k += 1) {
|
|
52
|
+
const from = pairs[k][0];
|
|
53
|
+
const to = pairs[k][1];
|
|
54
|
+
if (!project(from.rightAscension, from.declination, a) || !project(to.rightAscension, to.declination, b))
|
|
55
|
+
continue;
|
|
56
|
+
if ((a.x < 0 && b.x < 0) || (a.x > view.width && b.x > view.width) || (a.y < 0 && b.y < 0) || (a.y > view.height && b.y > view.height))
|
|
57
|
+
continue;
|
|
58
|
+
const at = count * 4;
|
|
59
|
+
segments[at] = a.x;
|
|
60
|
+
segments[at + 1] = a.y;
|
|
61
|
+
segments[at + 2] = b.x;
|
|
62
|
+
segments[at + 3] = b.y;
|
|
63
|
+
count += 1;
|
|
64
|
+
left = Math.min(left, a.x, b.x);
|
|
65
|
+
right = Math.max(right, a.x, b.x);
|
|
66
|
+
top = Math.min(top, a.y, b.y);
|
|
67
|
+
bottom = Math.max(bottom, a.y, b.y);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
out.end = count;
|
|
71
|
+
if (out.end > out.start) {
|
|
72
|
+
out.left = left;
|
|
73
|
+
out.right = right;
|
|
74
|
+
out.top = top;
|
|
75
|
+
out.bottom = bottom;
|
|
76
|
+
out.x = Math.max(0, Math.min(view.width, (left + right) / 2));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return count;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** A list of segments, four numbers each: where one starts and where it ends. */
|
|
2
|
+
export type SegmentList = ArrayLike<number>;
|
|
3
|
+
/**
|
|
4
|
+
* The squared distance from a point to the nearest segment of a figure.
|
|
5
|
+
*
|
|
6
|
+
* @param segments - The segments, four numbers each.
|
|
7
|
+
* @param start - The figure's first segment.
|
|
8
|
+
* @param end - One past its last.
|
|
9
|
+
* @param x - The point, x.
|
|
10
|
+
* @param y - The point, y.
|
|
11
|
+
* @returns The squared distance to the nearest, or infinity where the figure has none.
|
|
12
|
+
*/
|
|
13
|
+
export declare function nearestSegment(segments: SegmentList, start: number, end: number, x: number, y: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* The convex hull of a figure's segment ends (Andrew's monotone chain), as x y pairs: made once for a figure and kept while the picture holds, then asked of with `areaInHull` at each pointer.
|
|
16
|
+
*
|
|
17
|
+
* @param segments - The segments, four numbers each.
|
|
18
|
+
* @param start - The figure's first segment.
|
|
19
|
+
* @param end - One past its last.
|
|
20
|
+
* @returns The hull's corners, x then y for each, round the figure.
|
|
21
|
+
*/
|
|
22
|
+
export declare function hullOf(segments: SegmentList, start: number, end: number): number[];
|
|
23
|
+
/**
|
|
24
|
+
* The area of the convex hull of a figure when a point is inside it, or -1 when it is not. A pointer inside a figure (not only on its lines) picks it; where figures overlap, the smaller hull is the one meant.
|
|
25
|
+
*
|
|
26
|
+
* @param segments - The segments, four numbers each.
|
|
27
|
+
* @param start - The figure's first segment.
|
|
28
|
+
* @param end - One past its last.
|
|
29
|
+
* @param x - The point, x.
|
|
30
|
+
* @param y - The point, y.
|
|
31
|
+
* @returns The hull's area where the point is inside it, else -1.
|
|
32
|
+
*/
|
|
33
|
+
export declare function hullAreaAround(segments: SegmentList, start: number, end: number, x: number, y: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* The area of a hull when a point is inside it, or -1 when it is not (and for a hull with fewer than three corners).
|
|
36
|
+
*
|
|
37
|
+
* @param h - The hull, from `hullOf`.
|
|
38
|
+
* @param x - The point, x.
|
|
39
|
+
* @param y - The point, y.
|
|
40
|
+
* @returns The area where the point is inside, else -1.
|
|
41
|
+
*/
|
|
42
|
+
export declare function areaInHull(h: readonly number[], x: number, y: number): number;
|
|
43
|
+
/**
|
|
44
|
+
* The visual middle of the part of a figure that is on the picture: the middle of its lines, each counted by its length, taken only where they are inside the picture and not under a body or a place kept clear. Pieces outside the picture, and the parts of a figure that run off it, count for nothing.
|
|
45
|
+
*
|
|
46
|
+
* @param segments - The segments, four numbers each.
|
|
47
|
+
* @param start - The figure's first segment.
|
|
48
|
+
* @param end - One past its last.
|
|
49
|
+
* @param width - The picture's width.
|
|
50
|
+
* @param height - The picture's height.
|
|
51
|
+
* @param blocked - Whether a point of the picture is on a body or in a place kept clear, or `undefined` where none is.
|
|
52
|
+
* @param out - Where to write the middle.
|
|
53
|
+
* @returns True where any of the figure is in view, with `out` written.
|
|
54
|
+
*/
|
|
55
|
+
export declare function visibleCentre(segments: SegmentList, start: number, end: number, width: number, height: number, blocked: ((x: number, y: number) => boolean) | undefined, out: {
|
|
56
|
+
x: number;
|
|
57
|
+
y: number;
|
|
58
|
+
}): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Where a box goes: its middle at a point, or the nearest place round the point where it is inside the picture and `free` says it can stand.
|
|
61
|
+
*
|
|
62
|
+
* @param x - The wanted middle, x.
|
|
63
|
+
* @param y - The wanted middle, y.
|
|
64
|
+
* @param w - The box's width.
|
|
65
|
+
* @param h - The box's height.
|
|
66
|
+
* @param width - The picture's width.
|
|
67
|
+
* @param height - The picture's height.
|
|
68
|
+
* @param free - Whether a box (left, top, right, bottom) may stand there.
|
|
69
|
+
* @param out - Where to write the middle of the place found.
|
|
70
|
+
* @returns True where a place was found.
|
|
71
|
+
*/
|
|
72
|
+
export declare function placeBox(x: number, y: number, w: number, h: number, width: number, height: number, free: (l: number, t: number, r: number, b: number) => boolean, out: {
|
|
73
|
+
x: number;
|
|
74
|
+
y: number;
|
|
75
|
+
}): boolean;
|