@johnmorrisdotca/wakusei-planets 0.37.2 → 0.39.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 +20 -0
- package/NOTICE.md +14 -3
- package/README.md +6 -4
- package/dist/belts/data.d.ts +2 -0
- package/dist/belts/data.js +12 -0
- package/dist/belts/index.d.ts +270 -0
- package/dist/belts/index.js +308 -0
- package/dist/belts/totals.d.ts +43 -0
- package/dist/belts/totals.js +25 -0
- package/dist/data/orbiters.d.ts +221 -199
- package/dist/data/orbiters.js +288 -200
- package/dist/data-door.d.ts +2 -0
- package/dist/data-door.js +4 -2
- package/dist/door/own.js +4 -2
- package/dist/door/points.d.ts +14 -5
- package/dist/door/points.js +78 -27
- package/dist/earth-places.d.ts +40 -0
- package/dist/earth-places.js +47 -0
- package/dist/embed.d.ts +4 -1
- package/dist/embed.js +21 -10
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/orbiter-facts.d.ts +61 -4
- package/dist/orbiter-facts.js +17 -3
- package/dist/orbiters.d.ts +122 -2
- package/dist/orbiters.js +205 -3
- package/dist/picture-credits.d.ts +78 -0
- package/dist/picture-credits.js +120 -0
- package/dist/place-marks.d.ts +76 -0
- package/dist/place-marks.js +66 -0
- package/dist/places.d.ts +1 -1
- package/dist/places.js +1 -1
- package/dist/scene/earth-places.d.ts +190 -0
- package/dist/scene/earth-places.js +190 -0
- package/dist/scene/painter.d.ts +11 -0
- package/dist/scene/painter.js +30 -2
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +74 -3
- package/dist/space/element.js +293 -8
- package/dist/space/ride.d.ts +4 -4
- package/dist/space/ride.js +10 -3
- package/dist/space/scene.d.ts +44 -2
- package/dist/space/scene.js +139 -11
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +15 -2
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Which body's surface picture comes from which source, written from the rows of NOTICE.md (the "Surface pictures" table). Pure: no DOM, no three.js.
|
|
2
|
+
// A page that shows a body names only that body's row. The English credit is the table's credit column, unchanged; the Japanese says the same fact.
|
|
3
|
+
import { BODIES } from "./facts.js";
|
|
4
|
+
const cc = (id, en, ja, changesEn, changesJa, also) => ({
|
|
5
|
+
id,
|
|
6
|
+
licence: "CC BY 4.0",
|
|
7
|
+
credit: { en, ja },
|
|
8
|
+
changes: { en: changesEn, ja: changesJa },
|
|
9
|
+
...(also === undefined ? {} : { also: { en: also.en, ja: also.ja } }),
|
|
10
|
+
});
|
|
11
|
+
const pd = (id, en, ja) => ({ id, licence: "Public domain", credit: { en, ja } });
|
|
12
|
+
/**
|
|
13
|
+
* The surface picture of every body that has one, in the order of the table in `NOTICE.md`. A body with no row is drawn from numbers and has no picture to credit.
|
|
14
|
+
* The English of a CC BY 4.0 row is that table's credit column. Jupiter and Uranus keep the authors' own attribution sentences, including the spelling of the name.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { PICTURE_CREDITS } from "@johnmorrisdotca/wakusei-planets";
|
|
19
|
+
*
|
|
20
|
+
* console.log(PICTURE_CREDITS.filter((row) => row.licence === "CC BY 4.0").map((row) => row.id).join(","));
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const PICTURE_CREDITS = [
|
|
24
|
+
cc("mercury", "Shady Tex and Solar System Scope", "Shady TexとSolar System Scope", "Natural grey, resized to 512, 1024 and 2048. The normal map is not used.", "自然な灰色にし、512、1024、2048に縮小しました。法線マップは使っていません。"),
|
|
25
|
+
cc("venus", "Solar System Scope", "Solar System Scope", "Equirectangular surface map, resized to 512, 1024 and 2048.", "正距円筒図法の表面の地図を、512、1024、2048に縮小しました。"),
|
|
26
|
+
pd("mars", "NASA / Jet Propulsion Lab / USGS", "NASA / Jet Propulsion Lab / USGS"),
|
|
27
|
+
cc("jupiter", 'This work is based on "Jupiter" (https://sketchfab.com/3d-models/jupiter-6380860bdb4247b98b30643615c3afab) by Nestaeric (https://sketchfab.com/Nestaeric) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)', "Nestaeric(https://sketchfab.com/Nestaeric)による「Jupiter」(https://sketchfab.com/3d-models/jupiter-6380860bdb4247b98b30643615c3afab)をもとにしています。ライセンスは CC-BY-4.0(http://creativecommons.org/licenses/by/4.0/)です", "The band half of the texture, with the Great Red Spot and turbulent detail, resized to 512, 1024 and 2048.", "大赤斑と細かい乱れのある帯の半分を使い、512、1024、2048に縮小しました。"),
|
|
28
|
+
cc("saturn", "Solar System Scope; pole caps by Nestaeric", "Solar System Scope。極の冠はNestaeric", "The bands are Solar System Scope's map. The last 20 degrees at each pole are reprojected from Nestaeric's caps, and the north cap has the hexagon.", "縞はSolar System Scopeの地図です。両極の端の20度はNestaericの冠を張り直し、北の冠には六角形があります。", {
|
|
29
|
+
en: "Rings: NASA / JPL / Space Science Institute (public domain).",
|
|
30
|
+
ja: "環:NASA / JPL / Space Science Institute(パブリックドメイン)。",
|
|
31
|
+
}),
|
|
32
|
+
cc("uranus", 'This work is based on "Uranus" (https://sketchfab.com/3d-models/uranus-0009a69dbace44608c0bd09af9ba20db) by NestaEric (https://sketchfab.com/Nestaeric) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)', "NestaEric(https://sketchfab.com/Nestaeric)による「Uranus」(https://sketchfab.com/3d-models/uranus-0009a69dbace44608c0bd09af9ba20db)をもとにしています。ライセンスは CC-BY-4.0(http://creativecommons.org/licenses/by/4.0/)です", "The band half of the texture, which has a bright spot, resized to 512, 1024 and 2048.", "明るい斑のある帯の半分を使い、512、1024、2048に縮小しました。"),
|
|
33
|
+
cc("neptune", "Solar System Scope", "Solar System Scope", "Equirectangular map, resized to 512, 1024 and 2048.", "正距円筒図法の地図を、512、1024、2048に縮小しました。"),
|
|
34
|
+
pd("pluto", "NASA / Johns Hopkins University Applied Physics Laboratory / Southwest Research Institute", "NASA / Johns Hopkins University Applied Physics Laboratory / Southwest Research Institute"),
|
|
35
|
+
cc("sun", "Solar System Scope", "Solar System Scope", "Equirectangular map, resized to 512, 1024 and 2048.", "正距円筒図法の地図を、512、1024、2048に縮小しました。"),
|
|
36
|
+
pd("moon", "NASA's Scientific Visualization Studio (Ernie Wright, Noah Petro); Lunar Reconnaissance Orbiter Camera", "NASA Scientific Visualization Studio(Ernie Wright、Noah Petro)、Lunar Reconnaissance Orbiter Camera"),
|
|
37
|
+
pd("io", "NASA / JPL (Galileo SSI and Voyager images); the file page names no author", "NASA / JPL(Galileo SSIとVoyagerの画像)。ファイルのページに作者の名はありません"),
|
|
38
|
+
pd("europa", "U.S. Geological Survey / Planetary Data System / Tammy Becker", "U.S. Geological Survey / Planetary Data System / Tammy Becker"),
|
|
39
|
+
pd("ganymede", "USGS", "USGS"),
|
|
40
|
+
pd("callisto", "USGS", "USGS"),
|
|
41
|
+
pd("titan", "NASA / JPL / Space Science Institute", "NASA / JPL / Space Science Institute"),
|
|
42
|
+
pd("earth", "NASA Earth Observatory (Reto Stockli), Blue Marble", "NASA Earth Observatory(Reto Stockli)、Blue Marble"),
|
|
43
|
+
pd("rhea", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute"),
|
|
44
|
+
pd("enceladus", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute"),
|
|
45
|
+
pd("mimas", "NASA/JPL/Space Science Institute", "NASA/JPL/Space Science Institute"),
|
|
46
|
+
pd("ceres", "NASA/JPL-Caltech/UCLA/MPS/DLR/IDA", "NASA/JPL-Caltech/UCLA/MPS/DLR/IDA"),
|
|
47
|
+
pd("vesta", "NASA/JPL-Caltech/UCLA/MPS/DLR/IDA (as the file page gives it; hosted by the USGS Astrogeology Science Center's Gazetteer of Planetary Nomenclature)", "NASA/JPL-Caltech/UCLA/MPS/DLR/IDA(ファイルのページの表記。USGS Astrogeology Science CenterのGazetteer of Planetary Nomenclatureが公開)"),
|
|
48
|
+
pd("tethys", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute"),
|
|
49
|
+
pd("dione", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute"),
|
|
50
|
+
pd("iapetus", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute"),
|
|
51
|
+
pd("triton", "NASA/JPL-Caltech/Lunar & Planetary Institute (Paul Schenk; Voyager 2 images)", "NASA/JPL-Caltech/Lunar & Planetary Institute(Paul Schenk、Voyager 2の画像)"),
|
|
52
|
+
pd("charon", "NASA/Johns Hopkins University Applied Physics Laboratory/Southwest Research Institute (via the IAU)", "NASA/Johns Hopkins University Applied Physics Laboratory/Southwest Research Institute(IAU経由)"),
|
|
53
|
+
];
|
|
54
|
+
const BY_ID = new Map(PICTURE_CREDITS.map((row) => [row.id, row]));
|
|
55
|
+
/**
|
|
56
|
+
* The credit for Mercury's finer map tiles. Their detail is a public-domain map, and their colour is the 2048 picture, which is CC BY 4.0, so the tiles carry that credit too.
|
|
57
|
+
* The words are the Mercury row of `NOTICE.md`'s "Finer map tiles" table.
|
|
58
|
+
*
|
|
59
|
+
* @param lang - `en` or `ja`.
|
|
60
|
+
* @returns The one sentence.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { mercuryTilesCredit } from "@johnmorrisdotca/wakusei-planets";
|
|
65
|
+
*
|
|
66
|
+
* console.log(mercuryTilesCredit("en").includes("CC BY 4.0"));
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function mercuryTilesCredit(lang) {
|
|
70
|
+
return lang === "ja"
|
|
71
|
+
? "水星の細かい地図のタイルの色は、2048の絵(Solar System Scopeの地図、CC BY 4.0)の色です。タイルもその出典を持ちます。"
|
|
72
|
+
: "The colour of Mercury's finer map tiles is the 2048 picture's (Solar System Scope's map, CC BY 4.0), so these tiles carry that credit too.";
|
|
73
|
+
}
|
|
74
|
+
const phrase = (row, lang) => {
|
|
75
|
+
const name = BODIES[row.id].name[lang];
|
|
76
|
+
if (lang === "ja") {
|
|
77
|
+
const licence = row.licence === "CC BY 4.0" ? "CC BY 4.0" : "パブリックドメイン";
|
|
78
|
+
const changes = row.changes === undefined ? "" : `変更:${row.changes.ja}`;
|
|
79
|
+
const also = row.also === undefined ? "" : row.also.ja;
|
|
80
|
+
return `${name}:${row.credit.ja}(${licence})。${changes}${also}`;
|
|
81
|
+
}
|
|
82
|
+
const licence = row.licence === "CC BY 4.0" ? "CC BY 4.0" : "public domain";
|
|
83
|
+
const changes = row.changes === undefined ? "" : ` Changes made: ${row.changes.en}`;
|
|
84
|
+
const also = row.also === undefined ? "" : ` ${row.also.en}`;
|
|
85
|
+
return `${name}: ${row.credit.en} (${licence}).${changes}${also}`;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The credit line for the surface pictures of the named bodies, in one language. A name is a body id in any case (`Jupiter`, `moon`). A body with no picture is left out.
|
|
89
|
+
* Only the named bodies are credited: Jupiter names Nestaeric and CC BY 4.0, and the Moon and Mars, whose maps are public domain, name no CC BY 4.0 source.
|
|
90
|
+
* An empty list, or a list of bodies with no pictures, is an empty string.
|
|
91
|
+
*
|
|
92
|
+
* @param bodies - The bodies a page is showing.
|
|
93
|
+
* @param lang - `en` or `ja`.
|
|
94
|
+
* @returns The line, or `""` when none of the bodies has a picture.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { picturesCredit } from "@johnmorrisdotca/wakusei-planets";
|
|
99
|
+
*
|
|
100
|
+
* console.log(picturesCredit(["Jupiter"], "en").includes("Nestaeric"));
|
|
101
|
+
* console.log(picturesCredit(["Moon", "Mars"], "en").includes("CC BY") === false);
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export function picturesCredit(bodies, lang) {
|
|
105
|
+
const seen = new Set();
|
|
106
|
+
const rows = [];
|
|
107
|
+
for (const name of bodies) {
|
|
108
|
+
const id = name.toLowerCase();
|
|
109
|
+
if (seen.has(id))
|
|
110
|
+
continue;
|
|
111
|
+
seen.add(id);
|
|
112
|
+
const row = BY_ID.get(id);
|
|
113
|
+
if (row !== undefined)
|
|
114
|
+
rows.push(row);
|
|
115
|
+
}
|
|
116
|
+
if (rows.length === 0)
|
|
117
|
+
return "";
|
|
118
|
+
const head = lang === "ja" ? "表面の地図:" : "Surface pictures: ";
|
|
119
|
+
return head + rows.map((row) => phrase(row, lang)).join(lang === "ja" ? "" : " ");
|
|
120
|
+
}
|
package/dist/place-marks.d.ts
CHANGED
|
@@ -180,3 +180,79 @@ export declare function turnToPlace(pole: Vec3, meridian: Vec3, lat: number, lon
|
|
|
180
180
|
yaw: number;
|
|
181
181
|
tilt: number;
|
|
182
182
|
};
|
|
183
|
+
/**
|
|
184
|
+
* A point of a body's surface as one picture shows it: where it falls (CSS pixels in the view), which way straight up from the ground there points on the screen (`upX`, `upY`: a direction whose length is how much of an upright
|
|
185
|
+
* stick the reader sees, 0 looking straight down on it and 1 seeing it side on) and `facing`, the cosine between the ground's upright and the way to the camera (above 0 it faces the reader, at or below it is on the far side).
|
|
186
|
+
* The shape is chikyu-earth's `SurfacePoint`, so its `layoutPlaces` reads it as it is.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* import type { SurfaceSpot } from "@johnmorrisdotca/wakusei-planets/places";
|
|
191
|
+
*
|
|
192
|
+
* const middle: SurfaceSpot = { x: 160, y: 160, upX: 0, upY: 0, facing: 1 };
|
|
193
|
+
* console.log(middle.facing);
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export interface SurfaceSpot {
|
|
197
|
+
x: number;
|
|
198
|
+
y: number;
|
|
199
|
+
upX: number;
|
|
200
|
+
upY: number;
|
|
201
|
+
facing: number;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* A picture of a body for places to be laid on by someone else's layout: its size and a way to find a point of its surface in it. The shape is chikyu-earth's `PlaceView`.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* import type { SpotView } from "@johnmorrisdotca/wakusei-planets/places";
|
|
209
|
+
*
|
|
210
|
+
* const view: SpotView = { width: 320, height: 320, radius: 100, at: (lon, lat, out) => ((out.x = 160 + lon), (out.y = 160 - lat), (out.upX = 0), (out.upY = 0), (out.facing = 1), true) };
|
|
211
|
+
* console.log(view.width);
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export interface SpotView {
|
|
215
|
+
width: number;
|
|
216
|
+
height: number;
|
|
217
|
+
/** The body's radius in the picture, in CSS pixels. */
|
|
218
|
+
radius: number;
|
|
219
|
+
/** Find a longitude and latitude in the picture, writing it to `out`; false when it cannot be drawn. */
|
|
220
|
+
at(lon: number, lat: number, out: SurfaceSpot): boolean;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* A body as a view draws it, made into a picture places can be laid on: for each longitude and latitude, where it falls, which way is up from the ground there and whether it faces the reader. Works with the
|
|
224
|
+
* perspective of the camera (`eye`) or without it (`toward`), on the body's own ellipsoid, so a tipped, turned or flattened body is right. A point the projection cannot place gives `false`.
|
|
225
|
+
*
|
|
226
|
+
* @param view - The body as drawn.
|
|
227
|
+
* @returns The picture, for a layout such as chikyu-earth's `layoutPlaces`.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* import { spotView } from "@johnmorrisdotca/wakusei-planets/places";
|
|
232
|
+
*
|
|
233
|
+
* const view = spotView({ centre: [0, 0, 0], radius: 1, pole: [0, 1, 0], meridian: [0, 0, 1], scale: [1, 1, 1], toward: [0, 0, 1], project: (p) => ({ x: 160 + p[0] * 100, y: 160 - p[1] * 100 }), width: 320, height: 320, radiusPx: 100 });
|
|
234
|
+
* const spot = { x: 0, y: 0, upX: 0, upY: 0, facing: 0 };
|
|
235
|
+
* view.at(0, 0, spot);
|
|
236
|
+
* console.log(Math.round(spot.x), Math.round(spot.y), spot.facing);
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
export declare function spotView(view: SurfaceView): SpotView;
|
|
240
|
+
/**
|
|
241
|
+
* The longitude and latitude, in degrees, of the point of a body's surface that lies in a direction from its centre in the scene (the Sun's, for the `sun` of a layout that dims the night), from the body's axes.
|
|
242
|
+
*
|
|
243
|
+
* @param direction - The direction from the body's centre, in the scene.
|
|
244
|
+
* @param pole - The body's north pole.
|
|
245
|
+
* @param meridian - Its longitude 0 on the equator.
|
|
246
|
+
* @returns The point, `{ lon, lat }`.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* import { pointUnder } from "@johnmorrisdotca/wakusei-planets/places";
|
|
251
|
+
*
|
|
252
|
+
* console.log(pointUnder([1, 0, 0], [0, 1, 0], [0, 0, 1])); // longitude 90 east on the equator
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
export declare function pointUnder(direction: Vec3, pole: Vec3, meridian: Vec3): {
|
|
256
|
+
lon: number;
|
|
257
|
+
lat: number;
|
|
258
|
+
};
|
package/dist/place-marks.js
CHANGED
|
@@ -192,3 +192,69 @@ export function turnToPlace(pole, meridian, lat, lon) {
|
|
|
192
192
|
const wrap = (deg) => ((((deg + 180) % 360) + 360) % 360) - 180;
|
|
193
193
|
return { yaw: wrap(yaw / RAD), tilt: tilt / RAD };
|
|
194
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* A body as a view draws it, made into a picture places can be laid on: for each longitude and latitude, where it falls, which way is up from the ground there and whether it faces the reader. Works with the
|
|
197
|
+
* perspective of the camera (`eye`) or without it (`toward`), on the body's own ellipsoid, so a tipped, turned or flattened body is right. A point the projection cannot place gives `false`.
|
|
198
|
+
*
|
|
199
|
+
* @param view - The body as drawn.
|
|
200
|
+
* @returns The picture, for a layout such as chikyu-earth's `layoutPlaces`.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* import { spotView } from "@johnmorrisdotca/wakusei-planets/places";
|
|
205
|
+
*
|
|
206
|
+
* const view = spotView({ centre: [0, 0, 0], radius: 1, pole: [0, 1, 0], meridian: [0, 0, 1], scale: [1, 1, 1], toward: [0, 0, 1], project: (p) => ({ x: 160 + p[0] * 100, y: 160 - p[1] * 100 }), width: 320, height: 320, radiusPx: 100 });
|
|
207
|
+
* const spot = { x: 0, y: 0, upX: 0, upY: 0, facing: 0 };
|
|
208
|
+
* view.at(0, 0, spot);
|
|
209
|
+
* console.log(Math.round(spot.x), Math.round(spot.y), spot.facing);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export function spotView(view) {
|
|
213
|
+
return {
|
|
214
|
+
width: view.width,
|
|
215
|
+
height: view.height,
|
|
216
|
+
radius: view.radiusPx,
|
|
217
|
+
at(lon, lat, out) {
|
|
218
|
+
const { point, normal } = surfacePoint(view, lat, lon);
|
|
219
|
+
const sight = view.eye !== undefined ? [view.eye[0] - point[0], view.eye[1] - point[1], view.eye[2] - point[2]] : (view.toward ?? [0, 0, 1]);
|
|
220
|
+
const facing = dot(normal, sight) / (Math.hypot(sight[0], sight[1], sight[2]) || 1);
|
|
221
|
+
const foot = view.project(point);
|
|
222
|
+
if (foot === null)
|
|
223
|
+
return false;
|
|
224
|
+
// the upright is found by projecting a point a little way out along the normal: its direction on the screen, its length how much of the stick is seen side on
|
|
225
|
+
const reach = view.radius * 0.05;
|
|
226
|
+
const top = view.project([point[0] + normal[0] * reach, point[1] + normal[1] * reach, point[2] + normal[2] * reach]);
|
|
227
|
+
const dx = top === null ? 0 : top.x - foot.x;
|
|
228
|
+
const dy = top === null ? 0 : top.y - foot.y;
|
|
229
|
+
const length = Math.hypot(dx, dy);
|
|
230
|
+
const side = Math.sqrt(Math.max(0, 1 - facing * facing));
|
|
231
|
+
out.x = foot.x;
|
|
232
|
+
out.y = foot.y;
|
|
233
|
+
out.upX = length > 1e-6 ? (dx / length) * side : 0;
|
|
234
|
+
out.upY = length > 1e-6 ? (dy / length) * side : 0;
|
|
235
|
+
out.facing = facing;
|
|
236
|
+
return true;
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The longitude and latitude, in degrees, of the point of a body's surface that lies in a direction from its centre in the scene (the Sun's, for the `sun` of a layout that dims the night), from the body's axes.
|
|
242
|
+
*
|
|
243
|
+
* @param direction - The direction from the body's centre, in the scene.
|
|
244
|
+
* @param pole - The body's north pole.
|
|
245
|
+
* @param meridian - Its longitude 0 on the equator.
|
|
246
|
+
* @returns The point, `{ lon, lat }`.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* import { pointUnder } from "@johnmorrisdotca/wakusei-planets/places";
|
|
251
|
+
*
|
|
252
|
+
* console.log(pointUnder([1, 0, 0], [0, 1, 0], [0, 0, 1])); // longitude 90 east on the equator
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
export function pointUnder(direction, pole, meridian) {
|
|
256
|
+
const east = [pole[1] * meridian[2] - pole[2] * meridian[1], pole[2] * meridian[0] - pole[0] * meridian[2], pole[0] * meridian[1] - pole[1] * meridian[0]];
|
|
257
|
+
const len = Math.hypot(direction[0], direction[1], direction[2]) || 1;
|
|
258
|
+
const s = [direction[0] / len, direction[1] / len, direction[2] / len];
|
|
259
|
+
return { lon: Math.atan2(dot(s, east), dot(s, meridian)) / RAD, lat: Math.asin(Math.max(-1, Math.min(1, dot(s, pole)))) / RAD };
|
|
260
|
+
}
|
package/dist/places.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type BodyId } from "./facts.ts";
|
|
2
2
|
import { type When } from "./when.ts";
|
|
3
3
|
export type { When } from "./when.ts";
|
|
4
|
-
export { layerOf, MARK_RULES, PLACE_LAYERS, placeMarks, readPlaceLayers, surfacePoint, turnToPlace, type PlaceLayer, type PlaceMark, type SurfaceView } from "./place-marks.ts";
|
|
4
|
+
export { layerOf, MARK_RULES, PLACE_LAYERS, placeMarks, pointUnder, readPlaceLayers, spotView, surfacePoint, turnToPlace, type PlaceLayer, type PlaceMark, type SpotView, type SurfaceSpot, type SurfaceView } from "./place-marks.ts";
|
|
5
5
|
/**
|
|
6
6
|
* What a place is: a `crewed` landing (an Apollo lunar module), a `landing` (a lander that worked after touchdown), a `rover` that drove there, a `crash` (a craft that hit the surface and was lost, by accident or at the end of its mission), an
|
|
7
7
|
* `impact` (a craft sent to hit it on purpose), an `entry` (a probe or orbiter lost in the atmosphere of Venus, Jupiter or Saturn: no surface was reached or none is there), a `planned` landing (announced, not flown) or a named `feature` of the surface.
|
package/dist/places.js
CHANGED
|
@@ -5,7 +5,7 @@ import { apparent } from "./ephemeris.js";
|
|
|
5
5
|
import { BODIES } from "./facts.js";
|
|
6
6
|
import { cross, dot } from "./vec.js";
|
|
7
7
|
import { moment } from "./when.js";
|
|
8
|
-
export { layerOf, MARK_RULES, PLACE_LAYERS, placeMarks, readPlaceLayers, surfacePoint, turnToPlace } from "./place-marks.js";
|
|
8
|
+
export { layerOf, MARK_RULES, PLACE_LAYERS, placeMarks, pointUnder, readPlaceLayers, spotView, surfacePoint, turnToPlace } from "./place-marks.js";
|
|
9
9
|
/**
|
|
10
10
|
* The credit a page that shows places owes each source, one row for every `source.id` the tables use: the line to print, the licence or terms it rests on and the address. The lander catalogue's is a condition of its licence (CC BY 4.0: "data from GCAT (J. McDowell,
|
|
11
11
|
* planet4589.org/space/gcat)"); the others are US government works, credited as their owners ask, and the papers' coordinates are facts (each record's `source.url` names the paper).
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { SpotView } from "../place-marks.ts";
|
|
2
|
+
/**
|
|
3
|
+
* What a place is to the reader: `here` (where they are, drawn tall and bright) or `favourite` (a place they keep, drawn shorter and quieter).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { EarthPlaceKind } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
8
|
+
*
|
|
9
|
+
* const kind: EarthPlaceKind = "here";
|
|
10
|
+
* console.log(kind);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export type EarthPlaceKind = "here" | "favourite";
|
|
14
|
+
/**
|
|
15
|
+
* One place for the `earth-places` attribute or the `earthPlaces` property of `<wakusei-space>`: the same record chikyu-earth's `places` takes.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import type { EarthPlace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
20
|
+
*
|
|
21
|
+
* const places: EarthPlace[] = [
|
|
22
|
+
* { id: "me", lon: -79.4, lat: 43.7, label: "You are here", kind: "here" },
|
|
23
|
+
* { id: "tokyo", lon: 139.69, lat: 35.69, label: "Tokyo" },
|
|
24
|
+
* ];
|
|
25
|
+
* console.log(places.length);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export interface EarthPlace {
|
|
29
|
+
/** Your own unique name for it. */
|
|
30
|
+
id: string;
|
|
31
|
+
/** Degrees east, -180 to 180. */
|
|
32
|
+
lon: number;
|
|
33
|
+
/** Degrees north, -90 to 90. */
|
|
34
|
+
lat: number;
|
|
35
|
+
/** Shown beside the marker when there is room. */
|
|
36
|
+
label?: string;
|
|
37
|
+
/** `here` or `favourite` (the default). */
|
|
38
|
+
kind?: EarthPlaceKind;
|
|
39
|
+
/** A CSS colour for this place alone: a hex colour, `rgb()` or `hsl()` with numbers, or a colour's name. */
|
|
40
|
+
color?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* How a place is drawn: `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring lying on the ground).
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { EARTH_PLACE_LOOKS, type EarthPlaceLook } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
48
|
+
*
|
|
49
|
+
* const look: EarthPlaceLook = "pin";
|
|
50
|
+
* console.log(EARTH_PLACE_LOOKS.includes(look));
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export type EarthPlaceLook = "beam" | "pin" | "ring";
|
|
54
|
+
/**
|
|
55
|
+
* Every look a place can have, the default first.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { EARTH_PLACE_LOOKS } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
60
|
+
*
|
|
61
|
+
* console.log(EARTH_PLACE_LOOKS.join(", "));
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare const EARTH_PLACE_LOOKS: readonly EarthPlaceLook[];
|
|
65
|
+
/**
|
|
66
|
+
* The most markers the Earth carries at once: the first this many places in sight, `here` first and then in the order given. The rest are counted in `earthPlacesShown().omitted`.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { EARTH_PLACE_MARKS } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
71
|
+
*
|
|
72
|
+
* console.log(EARTH_PLACE_MARKS); // 32
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare const EARTH_PLACE_MARKS = 32;
|
|
76
|
+
/** Nothing is laid on an Earth under this many CSS pixels of radius: a marker the size of the planet is not a marker. */
|
|
77
|
+
export declare const EARTH_PLACES_FROM_PX = 40;
|
|
78
|
+
/** Where one place's marker goes: the foot on the ground, the top of the stick, the ring's turn, how flat it is and its radius, and how strongly it shows. The shape of chikyu-earth's `PlaceShape`. */
|
|
79
|
+
export interface EarthPlaceShape {
|
|
80
|
+
/** Index into the places given. */
|
|
81
|
+
index: number;
|
|
82
|
+
x: number;
|
|
83
|
+
y: number;
|
|
84
|
+
tipX: number;
|
|
85
|
+
tipY: number;
|
|
86
|
+
angle: number;
|
|
87
|
+
length: number;
|
|
88
|
+
ringAngle: number;
|
|
89
|
+
squash: number;
|
|
90
|
+
ring: number;
|
|
91
|
+
opacity: number;
|
|
92
|
+
/** 0 by day, 1 in full night. */
|
|
93
|
+
night: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The markers and names of a set of places in one picture. The shape of chikyu-earth's `PlaceLayout`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import type { EarthPlaceLayout } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
101
|
+
*
|
|
102
|
+
* const none: EarthPlaceLayout = { shapes: [], labels: [] };
|
|
103
|
+
* console.log(none.shapes.length);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export interface EarthPlaceLayout {
|
|
107
|
+
shapes: EarthPlaceShape[];
|
|
108
|
+
labels: {
|
|
109
|
+
index: number;
|
|
110
|
+
left: number;
|
|
111
|
+
top: number;
|
|
112
|
+
}[];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* What a layout may be told: the size of each name as it is drawn, boxes in use by other names, the most names, and where the Sun is overhead.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* import type { EarthPlaceLayoutOptions } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
120
|
+
*
|
|
121
|
+
* const options: EarthPlaceLayoutOptions = { size: () => ({ width: 60, height: 18 }), maxLabels: 8, sun: { lon: 0, lat: 0 } };
|
|
122
|
+
* console.log(options.maxLabels);
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export interface EarthPlaceLayoutOptions {
|
|
126
|
+
size?: (place: EarthPlace, index: number) => {
|
|
127
|
+
width: number;
|
|
128
|
+
height: number;
|
|
129
|
+
} | null;
|
|
130
|
+
taken?: readonly {
|
|
131
|
+
left: number;
|
|
132
|
+
top: number;
|
|
133
|
+
width: number;
|
|
134
|
+
height: number;
|
|
135
|
+
}[];
|
|
136
|
+
maxLabels?: number;
|
|
137
|
+
sun?: {
|
|
138
|
+
lon: number;
|
|
139
|
+
lat: number;
|
|
140
|
+
} | null;
|
|
141
|
+
}
|
|
142
|
+
/** The two things `@johnmorrisdotca/wakusei-planets/earth-places` hands the views: reading the attribute, and laying places on a picture. Both are chikyu-earth's. */
|
|
143
|
+
export interface EarthPlacesLayout {
|
|
144
|
+
read(value: string | null | undefined): EarthPlace[];
|
|
145
|
+
layout(places: readonly EarthPlace[], view: SpotView, look: EarthPlaceLook, options?: EarthPlaceLayoutOptions): EarthPlaceLayout;
|
|
146
|
+
}
|
|
147
|
+
/** Give the views the layout of places (what importing `@johnmorrisdotca/wakusei-planets/earth-places` does). Views already on the page lay their places at once. */
|
|
148
|
+
export declare function setEarthPlacesLayout(using: EarthPlacesLayout): void;
|
|
149
|
+
/** The layout `setEarthPlacesLayout` was given, if any. */
|
|
150
|
+
export declare const earthPlacesLayout: () => EarthPlacesLayout | undefined;
|
|
151
|
+
/** Hear `setEarthPlacesLayout`; returns the call that stops it. */
|
|
152
|
+
export declare function onEarthPlacesLayout(heard: () => void): () => void;
|
|
153
|
+
/** The look an attribute asks for: `beam`, `pin` or `ring`; anything else is `beam`. */
|
|
154
|
+
export declare const readEarthPlaceLook: (value: string | null) => EarthPlaceLook;
|
|
155
|
+
/**
|
|
156
|
+
* What the layer drew at the last layout, for one place: its id, its kind, where its foot is (CSS pixels from the view's top left) and whether its name was drawn.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* import type { EarthPlaceMark } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
161
|
+
*
|
|
162
|
+
* const mark: EarthPlaceMark = { id: "me", kind: "here", x: 210, y: 210, named: true };
|
|
163
|
+
* console.log(mark.named);
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export interface EarthPlaceMark {
|
|
167
|
+
id: string;
|
|
168
|
+
kind: EarthPlaceKind;
|
|
169
|
+
x: number;
|
|
170
|
+
y: number;
|
|
171
|
+
named: boolean;
|
|
172
|
+
}
|
|
173
|
+
/** The markers over one view. */
|
|
174
|
+
export interface EarthPlaceLayerView {
|
|
175
|
+
/** Draw the markers of a layout, moving the ones already there and hiding the rest. */
|
|
176
|
+
set(places: readonly EarthPlace[], layout: EarthPlaceLayout, look: EarthPlaceLook): void;
|
|
177
|
+
/** Hide every marker. */
|
|
178
|
+
clear(): void;
|
|
179
|
+
/** How wide a name is when drawn, in CSS pixels, in the font the layer's CSS gives it (padding included). */
|
|
180
|
+
width(text: string): number;
|
|
181
|
+
readonly shown: readonly EarthPlaceMark[];
|
|
182
|
+
dispose(): void;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Make the layer of markers inside a view's shadow root, above its picture. It holds a handful of elements made once and kept; a draw only writes the numbers that changed.
|
|
186
|
+
*
|
|
187
|
+
* @param root - The view's shadow root.
|
|
188
|
+
* @returns The layer.
|
|
189
|
+
*/
|
|
190
|
+
export declare function createEarthPlaceLayer(root: ShadowRoot): EarthPlaceLayerView;
|