@johnmorrisdotca/wakusei-planets 0.32.0 → 0.34.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 +16 -0
- package/NOTICE.md +15 -1
- package/README.md +11 -5
- package/dist/bodies/all.d.ts +1 -0
- package/dist/bodies/all.js +1 -0
- package/dist/bodies/minor.d.ts +1 -0
- package/dist/bodies/minor.js +16 -0
- package/dist/data/minor.d.ts +3 -0
- package/dist/data/minor.js +7 -0
- package/dist/data/tables.d.ts +4 -2
- package/dist/data/tables.js +1 -1
- package/dist/element.d.ts +10 -1
- package/dist/element.js +36 -6
- package/dist/embed.d.ts +1 -1
- package/dist/embed.js +3 -3
- package/dist/ephemeris.d.ts +7 -7
- package/dist/ephemeris.js +36 -13
- package/dist/facts.d.ts +28 -4
- package/dist/facts.js +24 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/nearest.js +6 -4
- package/dist/scene/body.d.ts +13 -2
- package/dist/scene/body.js +35 -0
- package/dist/scene/name-label.d.ts +116 -0
- package/dist/scene/name-label.js +232 -0
- package/dist/scene/painter.d.ts +29 -0
- package/dist/scene/painter.js +36 -0
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/arrows.d.ts +29 -3
- package/dist/space/arrows.js +38 -6
- package/dist/space/bodies.d.ts +6 -6
- package/dist/space/bodies.js +6 -6
- package/dist/space/element.d.ts +20 -0
- package/dist/space/element.js +44 -4
- package/dist/space/frame.d.ts +28 -3
- package/dist/space/frame.js +40 -4
- package/dist/space/index.d.ts +2 -2
- package/dist/space/index.js +2 -2
- package/dist/space/scale.d.ts +4 -4
- package/dist/space/scale.js +8 -2
- package/dist/space/scene.d.ts +17 -3
- package/dist/space/scene.js +36 -17
- package/dist/stops.d.ts +1 -1
- package/dist/stops.js +4 -1
- package/dist/tables/all.d.ts +1 -0
- package/dist/tables/all.js +1 -0
- package/dist/tables/lazy.d.ts +5 -0
- package/dist/tables/lazy.js +12 -0
- package/dist/tables/minor.d.ts +1 -0
- package/dist/tables/minor.js +317 -0
- package/dist/textures/vesta-1024.webp +0 -0
- package/dist/textures/vesta-512.webp +0 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +12 -2
package/dist/ephemeris.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { ORBITS } from "./data/orbits.js";
|
|
6
6
|
import { moonTheoryOf, planetSeriesOf } from "./data/theories.js";
|
|
7
7
|
import { DWARF_ELEMENTS } from "./data/dwarf.js";
|
|
8
|
+
import { MINOR_ELEMENTS } from "./data/minor.js";
|
|
8
9
|
import { tableOf } from "./data/tables.js";
|
|
9
10
|
import { PLUTO, PLUTO_SEGMENT_MS, PLUTO_START } from "./data/pluto.js";
|
|
10
11
|
import { VSOP87 } from "./data/vsop.js";
|
|
@@ -41,7 +42,8 @@ export function kepler(meanAnomaly, e) {
|
|
|
41
42
|
m -= 2 * Math.PI;
|
|
42
43
|
if (m < -Math.PI)
|
|
43
44
|
m += 2 * Math.PI;
|
|
44
|
-
|
|
45
|
+
// from the mean anomaly itself for a gentle orbit, and for a long one from a place on the same side of the orbit (Newton's method started at pi goes astray for a negative mean anomaly, which put Sedna's far side in the wrong places)
|
|
46
|
+
let E = e < 0.8 ? m : m + 0.85 * e * Math.sign(Math.sin(m) || 1);
|
|
45
47
|
for (let i = 0; i < 12; i += 1) {
|
|
46
48
|
const d = (E - e * Math.sin(E) - m) / (1 - e * Math.cos(E));
|
|
47
49
|
E -= d;
|
|
@@ -51,13 +53,34 @@ export function kepler(meanAnomaly, e) {
|
|
|
51
53
|
return E;
|
|
52
54
|
}
|
|
53
55
|
const PLUTO_TABLE = { start: PLUTO_START, segment: PLUTO_SEGMENT_MS, worst: 0.14637, segments: PLUTO };
|
|
56
|
+
/** Which segment of a table holds a moment, where it starts (milliseconds from the table's start) and how long it is; `undefined` outside the table. A table with `edges` has segments of unequal length, found by bisection. */
|
|
57
|
+
function segmentAt(table, terrestrialMs) {
|
|
58
|
+
const since = terrestrialMs - table.start;
|
|
59
|
+
const edges = table.edges;
|
|
60
|
+
if (edges === undefined) {
|
|
61
|
+
const index = Math.floor(since / table.segment);
|
|
62
|
+
return table.segments[index] === undefined ? undefined : { index, from: index * table.segment, length: table.segment };
|
|
63
|
+
}
|
|
64
|
+
if (!(since >= edges[0]) || since >= edges[edges.length - 1])
|
|
65
|
+
return undefined;
|
|
66
|
+
let lo = 0;
|
|
67
|
+
let hi = edges.length - 2;
|
|
68
|
+
while (lo < hi) {
|
|
69
|
+
const mid = (lo + hi + 1) >> 1;
|
|
70
|
+
if (edges[mid] <= since)
|
|
71
|
+
lo = mid;
|
|
72
|
+
else
|
|
73
|
+
hi = mid - 1;
|
|
74
|
+
}
|
|
75
|
+
return { index: lo, from: edges[lo], length: edges[lo + 1] - edges[lo] };
|
|
76
|
+
}
|
|
54
77
|
/** A position from a Chebyshev table, as x, y, z in au, or undefined outside the years it covers. */
|
|
55
78
|
function fittedPosition(table, terrestrialMs) {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
if (coefficients === undefined)
|
|
79
|
+
const found = segmentAt(table, terrestrialMs);
|
|
80
|
+
if (found === undefined)
|
|
59
81
|
return undefined;
|
|
60
|
-
const
|
|
82
|
+
const coefficients = table.segments[found.index];
|
|
83
|
+
const x = (2 * (terrestrialMs - table.start - found.from)) / found.length - 1;
|
|
61
84
|
const at = (axis) => {
|
|
62
85
|
let b1 = 0;
|
|
63
86
|
let b2 = 0;
|
|
@@ -72,7 +95,7 @@ function fittedPosition(table, terrestrialMs) {
|
|
|
72
95
|
}
|
|
73
96
|
/** Same table priority and TT segment coverage for positions and model information. */
|
|
74
97
|
function fittedTableAt(planet, tt) {
|
|
75
|
-
const covers = (table) =>
|
|
98
|
+
const covers = (table) => segmentAt(table, tt) !== undefined;
|
|
76
99
|
if (planet === "pluto" && covers(PLUTO_TABLE))
|
|
77
100
|
return PLUTO_TABLE;
|
|
78
101
|
const registered = tableOf(planet);
|
|
@@ -107,7 +130,7 @@ function barycentreFromSun(terrestrialMs) {
|
|
|
107
130
|
}
|
|
108
131
|
/**
|
|
109
132
|
* A planet's or dwarf planet's position in the Sun's frame (J2000 ecliptic, astronomical units) at a time: Mercury to Neptune from the VSOP87B series, and Pluto and the other dwarf planets from tables fitted to Horizons (each within a few arc-seconds or better, see the accuracy guide; outside a table's years a dwarf planet falls back to the osculating elements of one epoch from JPL's Small-Body Database).
|
|
110
|
-
* @param planet - The planet's
|
|
133
|
+
* @param planet - The planet's, dwarf planet's or minor body's name.
|
|
111
134
|
* @param ms - The instant, in milliseconds since 1970 (UTC).
|
|
112
135
|
* @returns The position as x, y, z in au.
|
|
113
136
|
*
|
|
@@ -140,9 +163,9 @@ export function heliocentric(planet, ms) {
|
|
|
140
163
|
let node;
|
|
141
164
|
let w;
|
|
142
165
|
let E;
|
|
143
|
-
const dwarf = DWARF_ELEMENTS[planet];
|
|
166
|
+
const dwarf = DWARF_ELEMENTS[planet] ?? MINOR_ELEMENTS[planet];
|
|
144
167
|
if (dwarf !== undefined) {
|
|
145
|
-
// a dwarf planet: the osculating elements of one epoch, run as a plain ellipse (good for years either side of it)
|
|
168
|
+
// a dwarf planet or a minor body: the osculating elements of one epoch, run as a plain ellipse (good for years either side of it)
|
|
146
169
|
a = dwarf.a;
|
|
147
170
|
e = dwarf.e;
|
|
148
171
|
I = dwarf.i * RAD;
|
|
@@ -195,11 +218,11 @@ export function heliocentricModel(planet, ms) {
|
|
|
195
218
|
const table = fittedTableAt(planet, tt);
|
|
196
219
|
return table !== undefined
|
|
197
220
|
? { theory: "chebyshev", worstArcseconds: table.worst }
|
|
198
|
-
: { theory: planet in DWARF_ELEMENTS ? "osculating-elements" : "approximate-elements", worstArcseconds: null };
|
|
221
|
+
: { theory: planet in DWARF_ELEMENTS || planet in MINOR_ELEMENTS ? "osculating-elements" : "approximate-elements", worstArcseconds: null };
|
|
199
222
|
}
|
|
200
223
|
/**
|
|
201
|
-
* Mean distance from the Sun, in astronomical units: a planet's semi-major axis at J2000, or a dwarf planet's semi-major axis at the epoch of its elements.
|
|
202
|
-
* @param id - A planet or a
|
|
224
|
+
* Mean distance from the Sun, in astronomical units: a planet's semi-major axis at J2000, or a dwarf planet's or minor body's semi-major axis at the epoch of its elements.
|
|
225
|
+
* @param id - A planet, a dwarf planet or a minor body.
|
|
203
226
|
* @returns The semi-major axis in au.
|
|
204
227
|
*
|
|
205
228
|
* @example
|
|
@@ -210,7 +233,7 @@ export function heliocentricModel(planet, ms) {
|
|
|
210
233
|
* ```
|
|
211
234
|
*/
|
|
212
235
|
export function meanSunAu(id) {
|
|
213
|
-
const dwarf = DWARF_ELEMENTS[id];
|
|
236
|
+
const dwarf = DWARF_ELEMENTS[id] ?? MINOR_ELEMENTS[id];
|
|
214
237
|
return dwarf !== undefined ? dwarf.a : ELEMENTS[id][0];
|
|
215
238
|
}
|
|
216
239
|
/** The north pole of a body as a J2000 ecliptic unit vector. */
|
package/dist/facts.d.ts
CHANGED
|
@@ -20,6 +20,17 @@ export declare const PLANET_IDS: readonly ["mercury", "venus", "earth", "mars",
|
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
export declare const DWARF_IDS: readonly ["ceres", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris", "sedna"];
|
|
23
|
+
/**
|
|
24
|
+
* The minor bodies beyond the dwarf planets that the package knows by name: the asteroids Vesta and Pallas, the centaurs Chiron and Pholus and Halley's comet, nearest the Sun first by the size of their orbits (Halley's, a long ellipse, last).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { MINOR_IDS } from "@johnmorrisdotca/wakusei-planets";
|
|
29
|
+
*
|
|
30
|
+
* console.log(MINOR_IDS.join(", "));
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const MINOR_IDS: readonly ["vesta", "pallas", "chiron", "pholus", "halley"];
|
|
23
34
|
/**
|
|
24
35
|
* The moons the package draws, by planet or dwarf planet.
|
|
25
36
|
*
|
|
@@ -66,6 +77,18 @@ export type PlanetId = (typeof PLANET_IDS)[number];
|
|
|
66
77
|
* ```
|
|
67
78
|
*/
|
|
68
79
|
export type DwarfId = (typeof DWARF_IDS)[number];
|
|
80
|
+
/**
|
|
81
|
+
* The name of a minor body: `vesta`, `pallas`, `chiron`, `pholus` or `halley`.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { MINOR_IDS, type MinorId } from "@johnmorrisdotca/wakusei-planets";
|
|
86
|
+
*
|
|
87
|
+
* const id: MinorId = MINOR_IDS[4];
|
|
88
|
+
* console.log(id);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export type MinorId = (typeof MINOR_IDS)[number];
|
|
69
92
|
/**
|
|
70
93
|
* A body a moon can go round: a planet, Pluto or another dwarf planet.
|
|
71
94
|
*
|
|
@@ -91,7 +114,7 @@ export type HostId = PlanetId | DwarfId;
|
|
|
91
114
|
*/
|
|
92
115
|
export type MoonId = (typeof MOONS_OF)[keyof typeof MOONS_OF][number];
|
|
93
116
|
/**
|
|
94
|
-
* The name of a body: `sun`, a planet, a dwarf planet or a moon.
|
|
117
|
+
* The name of a body: `sun`, a planet, a dwarf planet, a minor body or a moon.
|
|
95
118
|
*
|
|
96
119
|
* @example
|
|
97
120
|
* ```ts
|
|
@@ -101,7 +124,7 @@ export type MoonId = (typeof MOONS_OF)[keyof typeof MOONS_OF][number];
|
|
|
101
124
|
* console.log(lineSvg(id, { size: 64 }).length > 100);
|
|
102
125
|
* ```
|
|
103
126
|
*/
|
|
104
|
-
export type BodyId = "sun" | PlanetId | DwarfId | MoonId;
|
|
127
|
+
export type BodyId = "sun" | PlanetId | DwarfId | MinorId | MoonId;
|
|
105
128
|
/**
|
|
106
129
|
* How a body is drawn: `line` (an outline drawing), `realistic` and `painted` (a real surface map; `painted` is the same maps), or `illustrated` (shaded from the numbers, not a default).
|
|
107
130
|
*
|
|
@@ -176,7 +199,8 @@ export type Feature = {
|
|
|
176
199
|
*/
|
|
177
200
|
export interface BodyFacts {
|
|
178
201
|
id: BodyId;
|
|
179
|
-
|
|
202
|
+
/** What it is: a star, a planet, a dwarf planet, a moon, or one of the minor bodies: an `asteroid`, a `centaur` (between Jupiter and Neptune) or a `comet`. */
|
|
203
|
+
kind: "star" | "planet" | "dwarf-planet" | "moon" | "asteroid" | "centaur" | "comet";
|
|
180
204
|
/** The planet or dwarf planet a moon goes round. */
|
|
181
205
|
parent?: HostId;
|
|
182
206
|
name: {
|
|
@@ -224,7 +248,7 @@ export interface BodyFacts {
|
|
|
224
248
|
*/
|
|
225
249
|
export declare const BODIES: Readonly<Record<BodyId, BodyFacts>>;
|
|
226
250
|
/**
|
|
227
|
-
* Every body's name: the Sun, the planets outward, the dwarf planets, then the moons of each.
|
|
251
|
+
* Every body's name: the Sun, the planets outward, the dwarf planets, the minor bodies, then the moons of each.
|
|
228
252
|
*
|
|
229
253
|
* @example
|
|
230
254
|
* ```ts
|
package/dist/facts.js
CHANGED
|
@@ -22,6 +22,17 @@ export const PLANET_IDS = ["mercury", "venus", "earth", "mars", "jupiter", "satu
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export const DWARF_IDS = ["ceres", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris", "sedna"];
|
|
25
|
+
/**
|
|
26
|
+
* The minor bodies beyond the dwarf planets that the package knows by name: the asteroids Vesta and Pallas, the centaurs Chiron and Pholus and Halley's comet, nearest the Sun first by the size of their orbits (Halley's, a long ellipse, last).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { MINOR_IDS } from "@johnmorrisdotca/wakusei-planets";
|
|
31
|
+
*
|
|
32
|
+
* console.log(MINOR_IDS.join(", "));
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export const MINOR_IDS = ["vesta", "pallas", "chiron", "pholus", "halley"];
|
|
25
36
|
/**
|
|
26
37
|
* The moons the package draws, by planet or dwarf planet.
|
|
27
38
|
*
|
|
@@ -172,6 +183,17 @@ export const BODIES = {
|
|
|
172
183
|
gonggong: f("gonggong", "dwarf-planet", "Gonggong", "ゴンゴン", 615, 0, 0, 255.383, 36.831, 0, 385.7, 22.4, "#9c4f3b", { features: dots([[-50, 10, 9], [60, -25, 8], [140, 30, 7]]) }),
|
|
173
184
|
eris: f("eris", "dwarf-planet", "Eris", "エリス", 1163, 0, 78.22, 36.17, 44.51, 0, 22.805163, 378.8616, "#e8e4dc", { features: [{ kind: "band", lat: 0 }, ...dots([[-30, 30, 8], [80, -20, 9]])] }),
|
|
174
185
|
sedna: f("sedna", "dwarf-planet", "Sedna", "セドナ", 453, 0, 0, 297.062, 74.71, 0, 840.95, 10.273, "#9a3f2b", { features: dots([[-40, 20, 9], [70, -30, 8], [150, 10, 7]]) }),
|
|
186
|
+
// The minor bodies. Vesta: Park et al. 2025 (Nature Astronomy, JPL SBDB), pole and rotation from the same; Pallas: Marsset et al. 2020 (shape), Carry et al. 2010 (pole, rotation); Chiron and Pholus: JPL SBDB (diameters
|
|
187
|
+
// from occultation and thermal measurements) with the pole estimated along the orbit's; Halley: Keller et al. 1987 (the nucleus), the pole estimated along the orbit's and no spin drawn. See NOTICE.md.
|
|
188
|
+
vesta: f("vesta", "asteroid", "Vesta", "ベスタ", 261.385, 0, 27.4, 309.0611, 42.2324, 285.39, 1617.33312922, 5.3421276322, "#aaa397", {
|
|
189
|
+
axesKm: [284.62, 277.24, 226.33],
|
|
190
|
+
showLon: 301,
|
|
191
|
+
features: [{ kind: "circle", lon: 301, lat: -75, radius: 50 }, { kind: "band", lat: -10 }, { kind: "band", lat: -22 }, ...dots([[60, 25, 9], [140, 5, 7], [-100, 30, 8], [-40, -20, 6]])],
|
|
192
|
+
}),
|
|
193
|
+
pallas: f("pallas", "asteroid", "Pallas", "パラス", 256.5, 0, 83.6, 33, -3, 0, 1105.8, 7.8132214, "#85878a", { axesKm: [284, 266, 224], features: dots([[-60, 20, 12], [50, -25, 10], [130, 30, 9], [-130, -30, 8], [10, 55, 7]]) }),
|
|
194
|
+
chiron: f("chiron", "centaur", "Chiron", "ケイロン", 83, 0, 0, 258.793, 72.317, 0, 1460, 5.918, "#8d8e90", { features: dots([[-50, 20, 14], [70, -25, 12], [150, 30, 10], [-120, -35, 9]]) }),
|
|
195
|
+
pholus: f("pholus", "centaur", "Pholus", "ポルス", 95, 0, 0, 334.495, 66.246, 0, 865.73, 9.98, "#8e4b36", { features: dots([[-60, 15, 14], [40, -30, 12], [130, 25, 10], [-130, -20, 9]]) }),
|
|
196
|
+
halley: f("halley", "comet", "Halley", "ハレー彗星", 5.5, 0, 0, 41.795, -69.39, 0, 0, 0, "#44403d", { axesKm: [7.45, 4.1, 4.1], features: [...dots([[-40, 20, 16], [60, -15, 12], [130, 30, 10]]), { kind: "line", points: [[-120, -5], [-80, 8], [-30, -4], [20, 10], [80, 0]] }] }),
|
|
175
197
|
moon: f("moon", "moon", "Moon", "月", 1737.4, 0.0012, 6.68, 269.9949, 66.5392, 38.3213, 13.17635815, 655.728, "#b8b5ae", {
|
|
176
198
|
parent: "earth",
|
|
177
199
|
synchronous: true,
|
|
@@ -216,7 +238,7 @@ export const BODIES = {
|
|
|
216
238
|
dysnomia: f("dysnomia", "moon", "Dysnomia", "ディスノミア", 308, 0, 0, 36.17, 44.51, 0, 22.805163, 378.8616, "#5a5856", { parent: "eris", synchronous: true, features: dots([[-60, 20, 10], [50, -25, 9], [140, 30, 8]]) }),
|
|
217
239
|
};
|
|
218
240
|
/**
|
|
219
|
-
* Every body's name: the Sun, the planets outward, the dwarf planets, then the moons of each.
|
|
241
|
+
* Every body's name: the Sun, the planets outward, the dwarf planets, the minor bodies, then the moons of each.
|
|
220
242
|
*
|
|
221
243
|
* @example
|
|
222
244
|
* ```ts
|
|
@@ -225,7 +247,7 @@ export const BODIES = {
|
|
|
225
247
|
* console.log(BODY_IDS.length, BODY_IDS[0]);
|
|
226
248
|
* ```
|
|
227
249
|
*/
|
|
228
|
-
export const BODY_IDS = ["sun", ...PLANET_IDS, ...DWARF_IDS, ...Object.values(MOONS_OF).flat()];
|
|
250
|
+
export const BODY_IDS = ["sun", ...PLANET_IDS, ...DWARF_IDS, ...MINOR_IDS, ...Object.values(MOONS_OF).flat()];
|
|
229
251
|
/** A body's polar radius as a fraction of its equatorial radius. */
|
|
230
252
|
export const polarRatio = (facts) => 1 - facts.flattening;
|
|
231
253
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BODIES, BODY_IDS, DWARF_IDS, MOONS_OF, PLANET_IDS, ringReach, type BodyFacts, type BodyId, type DwarfId, type Feature, type HostId, type Look, type MoonId, type PlanetId, type RingBand } from "./facts.ts";
|
|
1
|
+
export { BODIES, BODY_IDS, DWARF_IDS, MINOR_IDS, MOONS_OF, PLANET_IDS, ringReach, type BodyFacts, type BodyId, type DwarfId, type Feature, type HostId, type Look, type MinorId, type MoonId, type PlanetId, type RingBand } from "./facts.ts";
|
|
2
2
|
export { apparent, heliocentric, heliocentricModel, meanSunAu, moonGeocentric, orbitPath, system, type Apparent, type MoonPlace, type Pose, type System } from "./ephemeris.ts";
|
|
3
3
|
export { JOURNEY_STOPS, journeyStop, stopPlaceAu, type JourneyStop } from "./stops.ts";
|
|
4
4
|
export { drawnTilt, portrait, type PortraitOptions } from "./pose.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BODIES, BODY_IDS, DWARF_IDS, MOONS_OF, PLANET_IDS, ringReach } from "./facts.js";
|
|
1
|
+
export { BODIES, BODY_IDS, DWARF_IDS, MINOR_IDS, MOONS_OF, PLANET_IDS, ringReach } from "./facts.js";
|
|
2
2
|
export { apparent, heliocentric, heliocentricModel, meanSunAu, moonGeocentric, orbitPath, system } from "./ephemeris.js";
|
|
3
3
|
export { JOURNEY_STOPS, journeyStop, stopPlaceAu } from "./stops.js";
|
|
4
4
|
export { drawnTilt, portrait } from "./pose.js";
|
package/dist/nearest.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Which bodies are nearest to a body on a date, and when two bodies come closest over a span: for the Sun, the planets, the dwarf planets and the moons, by the angle between them in the sky of an observer
|
|
1
|
+
// Which bodies are nearest to a body on a date, and when two bodies come closest over a span: for the Sun, the planets, the dwarf planets, the minor bodies and the moons, by the angle between them in the sky of an observer
|
|
2
2
|
// or by the distance between them in space. The positions are this package's own (heliocentric, ephemeris.ts): a sky angle is astrometric (the Earth's or the observer's place at the date, the body's place when
|
|
3
3
|
// its light left, no aberration or light bending), a distance is the geometry at one instant. Each result carries the accuracy the theories are held to (docs/guides/accuracy.md). Pure: no DOM, no three.js.
|
|
4
4
|
import { heliocentric, heliocentricModel, meanSunAu, moonVector } from "./ephemeris.js";
|
|
@@ -14,12 +14,14 @@ const AU_KM = 149_597_870.7;
|
|
|
14
14
|
const LIGHT_SECONDS_PER_AU = 499.004784;
|
|
15
15
|
const DAY_MS = 86_400_000;
|
|
16
16
|
const ARCSECONDS_PER_RADIAN = 206_264.806;
|
|
17
|
-
const KINDS = ["star", "planet", "dwarf-planet", "moon"];
|
|
17
|
+
const KINDS = ["star", "planet", "dwarf-planet", "moon", "asteroid", "centaur", "comet"];
|
|
18
18
|
/** The worst direction error from the Sun in arc-seconds over 60 dates from 1800 to 2200, as the accuracy guide holds each planet to. */
|
|
19
19
|
const PLANET_ARCSECONDS = { mercury: 4.5, venus: 2.6, earth: 4, mars: 6, jupiter: 3.6, saturn: 5.7, uranus: 5, neptune: 3.4, pluto: 0.2 };
|
|
20
20
|
/** The same for a dwarf planet inside its fitted table's years. */
|
|
21
21
|
const DWARF_ARCSECONDS = { ceres: 0.3, orcus: 0.1, haumea: 0.1, quaoar: 0.15, makemake: 0.15, gonggong: 0.1, eris: 0.1, sedna: 0.1 };
|
|
22
|
-
/**
|
|
22
|
+
/** The same for a minor body inside its fitted table's years: the worst of the held-back samples of each fit (scripts/make-minor-data.py), rounded up. */
|
|
23
|
+
const MINOR_ARCSECONDS = { vesta: 1, pallas: 1, chiron: 0.6, pholus: 0.7, halley: 1 };
|
|
24
|
+
/** A dwarf planet or minor body outside its table's years runs on the osculating elements of one epoch, and Pluto outside 1800 to 2200 on JPL's approximate elements. */
|
|
23
25
|
const OSCULATING_ARCSECONDS = 3600;
|
|
24
26
|
const APPROXIMATE_ARCSECONDS = 120;
|
|
25
27
|
/** The worst direction error from the planet in degrees over 60 dates, for the Moon and each moon; a moon the accuracy guide does not measure is given 5 degrees. */
|
|
@@ -104,7 +106,7 @@ function separation(by, a, b) {
|
|
|
104
106
|
}
|
|
105
107
|
function hostErrorKm(host, ms) {
|
|
106
108
|
const model = heliocentricModel(host, ms);
|
|
107
|
-
const arcseconds = model.theory === "vsop87b" ? PLANET_ARCSECONDS[host] : model.theory === "chebyshev" ? (PLANET_ARCSECONDS[host] ?? DWARF_ARCSECONDS[host]) : model.theory === "osculating-elements" ? OSCULATING_ARCSECONDS : APPROXIMATE_ARCSECONDS;
|
|
109
|
+
const arcseconds = model.theory === "vsop87b" ? PLANET_ARCSECONDS[host] : model.theory === "chebyshev" ? (PLANET_ARCSECONDS[host] ?? DWARF_ARCSECONDS[host] ?? MINOR_ARCSECONDS[host]) : model.theory === "osculating-elements" ? OSCULATING_ARCSECONDS : APPROXIMATE_ARCSECONDS;
|
|
108
110
|
return length(heliocentric(host, ms)) * AU_KM * Math.tan(arcseconds / ARCSECONDS_PER_RADIAN);
|
|
109
111
|
}
|
|
110
112
|
/** The independent parts of how far a body's place may be off, kilometres: the planet it goes round (which its moons share) and its own part. */
|
package/dist/scene/body.d.ts
CHANGED
|
@@ -7,9 +7,10 @@ import type { SourceBook } from "../door/book.ts";
|
|
|
7
7
|
import type { BodyMapSource } from "../door/map.ts";
|
|
8
8
|
import { type DetailStats } from "./detail.ts";
|
|
9
9
|
import type { TileLevel } from "./tiles.ts";
|
|
10
|
+
import { type NameLabelOptions } from "./name-label.ts";
|
|
10
11
|
export { fallbackLook } from "./fallback.ts";
|
|
11
|
-
/** The parts of three.js the bodies use: a page may hand over a module with only these (see `setThreeLoader`). */
|
|
12
|
-
export type ThreeParts = Pick<typeof THREE, "AdditiveBlending" | "BufferAttribute" | "BufferGeometry" | "ClampToEdgeWrapping" | "DataTexture" | "DoubleSide" | "Group" | "Line" | "LineBasicMaterial" | "LineSegments" | "LinearFilter" | "Mesh" | "NoColorSpace" | "OrthographicCamera" | "PlaneGeometry" | "RepeatWrapping" | "RGBAFormat" | "RingGeometry" | "Scene" | "ShaderMaterial" | "SphereGeometry" | "TextureLoader" | "Vector2" | "Vector3" | "WebGLRenderer"
|
|
12
|
+
/** The parts of three.js the bodies use: a page may hand over a module with only these (see `setThreeLoader`). `CanvasTexture`, `SRGBColorSpace` and `NormalBlending` are needed only for a name written on a body (`body-label`). */
|
|
13
|
+
export type ThreeParts = Pick<typeof THREE, "AdditiveBlending" | "BufferAttribute" | "BufferGeometry" | "ClampToEdgeWrapping" | "DataTexture" | "DoubleSide" | "Group" | "Line" | "LineBasicMaterial" | "LineSegments" | "LinearFilter" | "Mesh" | "NoColorSpace" | "OrthographicCamera" | "PlaneGeometry" | "RepeatWrapping" | "RGBAFormat" | "RingGeometry" | "Scene" | "ShaderMaterial" | "SphereGeometry" | "TextureLoader" | "Vector2" | "Vector3" | "WebGLRenderer"> & Partial<Pick<typeof THREE, "CanvasTexture" | "SRGBColorSpace" | "NormalBlending">>;
|
|
13
14
|
/** One moon in a system view: its place in planet radii (viewer's frame) and the points of its orbit, if they changed. */
|
|
14
15
|
export interface MoonDraw {
|
|
15
16
|
id: BodyId;
|
|
@@ -34,6 +35,10 @@ export interface SceneState {
|
|
|
34
35
|
minMoonPx?: number;
|
|
35
36
|
/** The colour of the orbit lines, `#rrggbb`. */
|
|
36
37
|
orbitColour?: string;
|
|
38
|
+
/** The body's name written on its globe: the text and the look, or none. */
|
|
39
|
+
label?: ({
|
|
40
|
+
text: string;
|
|
41
|
+
} & NameLabelOptions) | null;
|
|
37
42
|
}
|
|
38
43
|
/** The scene the shared renderer draws, with the one call that moves it. */
|
|
39
44
|
export interface BodyScene extends Scene3D {
|
|
@@ -43,6 +48,12 @@ export interface BodyScene extends Scene3D {
|
|
|
43
48
|
readonly painted: boolean;
|
|
44
49
|
/** The window of finer map on the body, or `undefined` for a body with none (a glowing one, or one with no painted map). */
|
|
45
50
|
readonly detail: DetailStats | undefined;
|
|
51
|
+
/** The name on the globe now: whether it is drawn (made, its font in, and the body big enough), its text, and its turn about the pole in radians (for `facing`); `null` for none. */
|
|
52
|
+
readonly label: {
|
|
53
|
+
shown: boolean;
|
|
54
|
+
text: string;
|
|
55
|
+
turn: number;
|
|
56
|
+
} | null;
|
|
46
57
|
}
|
|
47
58
|
export interface BodyItemOptions {
|
|
48
59
|
id: BodyId;
|
package/dist/scene/body.js
CHANGED
|
@@ -8,6 +8,7 @@ import { fallbackLook } from "./fallback.js";
|
|
|
8
8
|
import { writeBasis } from "./basis.js";
|
|
9
9
|
import { loadImage } from "./textures.js";
|
|
10
10
|
import { ringStrip } from "./rings.js";
|
|
11
|
+
import { createNameLabel, nameLabelKey } from "./name-label.js";
|
|
11
12
|
export { fallbackLook } from "./fallback.js";
|
|
12
13
|
/** The shader material of a body: its surface code with the look's lighting and glow uniforms. A star made from numbers is drawn with it too (the size line-up). */
|
|
13
14
|
export function makeBodyMaterial(T, look, painted) {
|
|
@@ -353,6 +354,30 @@ export function createBodyItem(options) {
|
|
|
353
354
|
}
|
|
354
355
|
}
|
|
355
356
|
};
|
|
357
|
+
// the name on the globe: a child of the mesh, so it turns with the body
|
|
358
|
+
let label;
|
|
359
|
+
let labelKey = "";
|
|
360
|
+
const syncLabel = (state) => {
|
|
361
|
+
const key = state.label ? nameLabelKey(state.label.text, state.label) : "";
|
|
362
|
+
if (key === labelKey)
|
|
363
|
+
return;
|
|
364
|
+
labelKey = key;
|
|
365
|
+
if (!state.label) {
|
|
366
|
+
if (label !== undefined) {
|
|
367
|
+
mesh.remove(label.object);
|
|
368
|
+
label.dispose();
|
|
369
|
+
label = undefined;
|
|
370
|
+
}
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const { text, ...rest } = state.label;
|
|
374
|
+
if (label === undefined) {
|
|
375
|
+
label = createNameLabel(T, text, rest, look.emissive === true, () => options.redraw());
|
|
376
|
+
mesh.add(label.object);
|
|
377
|
+
}
|
|
378
|
+
else
|
|
379
|
+
label.set(text, rest);
|
|
380
|
+
};
|
|
356
381
|
const light = new T.Vector3();
|
|
357
382
|
const pole = new T.Vector3();
|
|
358
383
|
const apply = (state) => {
|
|
@@ -360,6 +385,7 @@ export function createBodyItem(options) {
|
|
|
360
385
|
orient(state);
|
|
361
386
|
frame(state);
|
|
362
387
|
place(state);
|
|
388
|
+
syncLabel(state);
|
|
363
389
|
light.set(...state.pose.light);
|
|
364
390
|
if (ringHalves !== undefined) {
|
|
365
391
|
pole.set(...state.pose.pole);
|
|
@@ -400,6 +426,9 @@ export function createBodyItem(options) {
|
|
|
400
426
|
glow.scale.setScalar(1);
|
|
401
427
|
}
|
|
402
428
|
requestSharperTexture(state);
|
|
429
|
+
// the disc's radius on the screen in CSS pixels: the short side's half at zoom 1 over the extent
|
|
430
|
+
if (label !== undefined)
|
|
431
|
+
label.update(camera, ((aspect >= 1 ? viewHeight : viewWidth) / 2) * (state.zoom / state.extent), state.pose.light);
|
|
403
432
|
if (detail !== undefined && textureWidth > 0) {
|
|
404
433
|
const east = cross(state.pose.pole, state.pose.meridian);
|
|
405
434
|
const ax = facts.axesKm;
|
|
@@ -421,6 +450,10 @@ export function createBodyItem(options) {
|
|
|
421
450
|
get detail() {
|
|
422
451
|
return detail?.stats;
|
|
423
452
|
},
|
|
453
|
+
get label() {
|
|
454
|
+
const inner = label?.object.children[0];
|
|
455
|
+
return label === undefined || latest.label === undefined || latest.label === null ? null : { shown: label.ready && inner !== undefined && inner.visible, text: latest.label.text, turn: inner?.rotation.y ?? 0 };
|
|
456
|
+
},
|
|
424
457
|
resize(w, h) {
|
|
425
458
|
viewWidth = w;
|
|
426
459
|
viewHeight = h;
|
|
@@ -438,6 +471,8 @@ export function createBodyItem(options) {
|
|
|
438
471
|
windowUniforms.uDetail.value = null;
|
|
439
472
|
}
|
|
440
473
|
detail?.dispose();
|
|
474
|
+
label?.dispose();
|
|
475
|
+
label = undefined;
|
|
441
476
|
for (const o of orbitLines.values())
|
|
442
477
|
o.line.geometry.dispose();
|
|
443
478
|
orbitMaterial.dispose();
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type BodyLabelLook, type BodyLabelRepeat, type BodyLabelSize } from "@johnmorrisdotca/kazoku-ui/body-label";
|
|
2
|
+
import type * as THREE from "three";
|
|
3
|
+
import type { ThreeParts } from "./body.ts";
|
|
4
|
+
import type { Vec3 } from "../vec.ts";
|
|
5
|
+
/**
|
|
6
|
+
* The name written on a body's globe: the family's `bodyLabel` property. `look` is the one setting with no default: `painted` (pale letters over the surface), `etched` (the letters lighten the surface), `outline`
|
|
7
|
+
* (the letters' edges) or `burned` (darker letters). The rest fall back to the family's: half strength, the name once, on the equator, turning with the body, in Michroma. The text is the body's own name
|
|
8
|
+
* in the element's language (`EARTH`, `地球`), so it is not a setting here.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts no-run
|
|
12
|
+
* import type { NameLabelOptions } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
13
|
+
*
|
|
14
|
+
* const label: NameLabelOptions = { look: "painted", strength: 0.5, repeat: "both", latitude: 0, facing: false };
|
|
15
|
+
* console.log(label.look);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export interface NameLabelOptions {
|
|
19
|
+
look: BodyLabelLook;
|
|
20
|
+
/** How strongly it shows, 0 to 1. Default 0.5. */
|
|
21
|
+
strength?: number;
|
|
22
|
+
/** `once`, `both` (two, on opposite sides, so one is always in view) or `around` (as many as fit). Default `once`. */
|
|
23
|
+
repeat?: BodyLabelRepeat;
|
|
24
|
+
/** The band's latitude in degrees: 0 is the equator; 55 or -55 is near a pole. Default 0. */
|
|
25
|
+
latitude?: number;
|
|
26
|
+
/** True: the name keeps facing the reader while the body turns under it. Default false. */
|
|
27
|
+
facing?: boolean;
|
|
28
|
+
/** A CSS font family the page has loaded. Default Michroma, which the label fetches itself (64 kB, once). */
|
|
29
|
+
font?: string;
|
|
30
|
+
/** The family for letters `font` has none of, such as Japanese (`"Noto Sans JP"`). Default the page's sans. */
|
|
31
|
+
fallbackFont?: string;
|
|
32
|
+
/** `small`, `medium` or `large`. Default `medium`. */
|
|
33
|
+
size?: BodyLabelSize;
|
|
34
|
+
/** No label while the body is drawn smaller than this many CSS pixels in radius. Default 24. */
|
|
35
|
+
minRadiusPx?: number;
|
|
36
|
+
}
|
|
37
|
+
/** The family's standard attribute names, as `readNameLabel` reads them. */
|
|
38
|
+
export declare const NAME_LABEL_ATTRIBUTES: readonly ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font"];
|
|
39
|
+
/**
|
|
40
|
+
* The label the family's attributes ask for (`body-label="painted"` and the six beside it), or `null` when `body-label` is absent or not a look.
|
|
41
|
+
*
|
|
42
|
+
* @param el - Anything with `getAttribute` and `hasAttribute`: the element.
|
|
43
|
+
* @returns The options, or `null` for no label.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts no-run
|
|
47
|
+
* import { readNameLabel } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
48
|
+
*
|
|
49
|
+
* const el = document.querySelector("wakusei-body")!;
|
|
50
|
+
* el.setAttribute("body-label", "etched");
|
|
51
|
+
* console.log(readNameLabel(el)?.look);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function readNameLabel(el: {
|
|
55
|
+
getAttribute(name: string): string | null;
|
|
56
|
+
hasAttribute(name: string): boolean;
|
|
57
|
+
}): NameLabelOptions | null;
|
|
58
|
+
/**
|
|
59
|
+
* The text written for a body: its English name in capitals (the family's look), or its Japanese name as it is.
|
|
60
|
+
*
|
|
61
|
+
* @param name - The body's names, as `BODIES[id].name` holds them.
|
|
62
|
+
* @param lang - `en` (the default) or `ja`.
|
|
63
|
+
* @returns The text to write.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { BODIES } from "@johnmorrisdotca/wakusei-planets";
|
|
68
|
+
* import { nameLabelText } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
69
|
+
*
|
|
70
|
+
* console.log(nameLabelText(BODIES.earth.name, "en"), nameLabelText(BODIES.earth.name, "ja"));
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function nameLabelText(name: {
|
|
74
|
+
en: string;
|
|
75
|
+
ja: string;
|
|
76
|
+
}, lang?: "en" | "ja"): string;
|
|
77
|
+
/** One string that changes whenever the label would be made differently (the text and every setting): for a host that keeps a still for each state. */
|
|
78
|
+
export declare function nameLabelKey(text: string, options: NameLabelOptions | null | undefined): string;
|
|
79
|
+
/** The parts of three.js the label needs beyond the bodies': a page that hands over a subset without them gets no label, and a warning once. */
|
|
80
|
+
export type LabelParts = Pick<typeof THREE, "CanvasTexture" | "SRGBColorSpace" | "NormalBlending">;
|
|
81
|
+
/** What `createNameLabel` returns: the group to add to the body's mesh, and the calls the host makes. */
|
|
82
|
+
export interface NameLabel {
|
|
83
|
+
/** Add it to the body's turning mesh (a radius-1 sphere whose +z is longitude 0). */
|
|
84
|
+
readonly object: THREE.Group;
|
|
85
|
+
/** True once the name is drawn in its font: the host draws its view again when `onReady` is called. */
|
|
86
|
+
readonly ready: boolean;
|
|
87
|
+
/** Before each draw: the camera (for `facing`; left out, the name faces +z), the body's radius on the screen in CSS pixels, and the direction to the light in the scene's axes. Returns true when it hid, showed or turned the name. */
|
|
88
|
+
update(camera: THREE.Camera | undefined, radiusPx: number, light: Vec3): boolean;
|
|
89
|
+
/** New settings or text; the texture is drawn again only when it must be. */
|
|
90
|
+
set(text: string, options: NameLabelOptions): void;
|
|
91
|
+
dispose(): void;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Where Michroma is fetched from, for a page whose bundler does not carry kazoku-ui's font file along with its module (the label looks for it next to the module, `fonts/Michroma-Regular.ttf`). Call it before the
|
|
95
|
+
* first name is written. A page that sets `body-label-font` to a font of its own needs nothing here.
|
|
96
|
+
*
|
|
97
|
+
* @param url - The address of `Michroma-Regular.ttf`, with its `OFL.txt` beside it.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts no-run
|
|
101
|
+
* import { setBodyLabelFontUrl } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
102
|
+
*
|
|
103
|
+
* setBodyLabelFontUrl("/fonts/Michroma-Regular.ttf");
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function setBodyLabelFontUrl(url: string | URL): void;
|
|
107
|
+
/**
|
|
108
|
+
* Make a body's name label. The group is empty until the font is in (at once when it is already loaded); `onReady` is called when the name is drawn, so the host can draw its view again.
|
|
109
|
+
*
|
|
110
|
+
* @param T - The three.js module the bodies use. Without `CanvasTexture`, `SRGBColorSpace` and `NormalBlending` there is no label, and a warning once.
|
|
111
|
+
* @param text - The name as it is written.
|
|
112
|
+
* @param options - The look and the rest.
|
|
113
|
+
* @param emissive - The body glows (the Sun): the name is lit fully, from no direction.
|
|
114
|
+
* @param onReady - Called when the name is drawn, and again when a new font is in.
|
|
115
|
+
*/
|
|
116
|
+
export declare function createNameLabel(T: ThreeParts, text: string, options: NameLabelOptions, emissive: boolean, onReady: () => void): NameLabel;
|