@johnmorrisdotca/wakusei-planets 0.36.0 → 0.37.1
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 +14 -0
- package/NOTICE.md +15 -1
- package/README.md +5 -4
- package/dist/data/moon-catalogue.d.ts +31 -0
- package/dist/data/moon-catalogue.js +471 -0
- package/dist/data/places-planned.d.ts +3 -0
- package/dist/data/places-planned.js +51 -0
- package/dist/element.d.ts +28 -0
- package/dist/element.js +178 -2
- package/dist/moon-catalogue.d.ts +296 -0
- package/dist/moon-catalogue.js +234 -0
- package/dist/place-marks.d.ts +182 -0
- package/dist/place-marks.js +194 -0
- package/dist/places/mars.d.ts +1 -1
- package/dist/places/mars.js +4 -2
- package/dist/places/moon.d.ts +1 -1
- package/dist/places/moon.js +4 -2
- package/dist/places.d.ts +4 -2
- package/dist/places.js +2 -0
- package/dist/scene/place-layer.d.ts +68 -0
- package/dist/scene/place-layer.js +213 -0
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/all-moons.d.ts +30 -0
- package/dist/space/all-moons.js +61 -0
- package/dist/space/bodies.d.ts +18 -0
- package/dist/space/bodies.js +18 -0
- package/dist/space/element.d.ts +102 -2
- package/dist/space/element.js +415 -7
- package/dist/space/index.d.ts +2 -1
- package/dist/space/index.js +2 -1
- package/dist/space/scene.d.ts +32 -0
- package/dist/space/scene.js +44 -0
- package/dist/space/sight.d.ts +106 -0
- package/dist/space/sight.js +84 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +8 -2
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { Place, PlaceKind } from "./places.ts";
|
|
2
|
+
import { type Vec3 } from "./vec.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The layers of places a view can show, each switched on by itself: `landing` (the crewed landings, the landers and the rovers), `crash` (the crash, impact and atmospheric-entry sites), `planned` (announced landings) and `feature`
|
|
5
|
+
* (the named features of the surface).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { PLACE_LAYERS } from "@johnmorrisdotca/wakusei-planets/places";
|
|
10
|
+
*
|
|
11
|
+
* console.log(PLACE_LAYERS.join(" "));
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const PLACE_LAYERS: readonly ["landing", "crash", "planned", "feature"];
|
|
15
|
+
/**
|
|
16
|
+
* One layer of places.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import type { PlaceLayer } from "@johnmorrisdotca/wakusei-planets/places";
|
|
21
|
+
*
|
|
22
|
+
* const layer: PlaceLayer = "landing";
|
|
23
|
+
* console.log(layer);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export type PlaceLayer = (typeof PLACE_LAYERS)[number];
|
|
27
|
+
/**
|
|
28
|
+
* The layer a kind of place is shown in.
|
|
29
|
+
*
|
|
30
|
+
* @param kind - The place's kind.
|
|
31
|
+
* @returns Its layer.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { layerOf } from "@johnmorrisdotca/wakusei-planets/places";
|
|
36
|
+
*
|
|
37
|
+
* console.log(layerOf("rover"), layerOf("impact"), layerOf("feature"));
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function layerOf(kind: PlaceKind): PlaceLayer;
|
|
41
|
+
/**
|
|
42
|
+
* The layers an attribute asks for: a list of layer names with spaces or commas between (`"landing crash"`), `all` (or an empty value) for every layer, and `none` or `off` for none. Unknown words are left out.
|
|
43
|
+
*
|
|
44
|
+
* @param value - The attribute's value, or `null` when it is absent (no layers).
|
|
45
|
+
* @returns The layers, in `PLACE_LAYERS` order.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { readPlaceLayers } from "@johnmorrisdotca/wakusei-planets/places";
|
|
50
|
+
*
|
|
51
|
+
* console.log(readPlaceLayers("crash, landing"), readPlaceLayers(""), readPlaceLayers(null));
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function readPlaceLayers(value: string | null): PlaceLayer[];
|
|
55
|
+
/**
|
|
56
|
+
* A body as a view draws it, for laying marks over it: its centre and radius in the scene's units, its axes there (`pole` north, `meridian` towards longitude 0 on the equator), the stretch of its globe along each
|
|
57
|
+
* (east, pole, meridian: 1, 1, 1 for a sphere), where the viewer is (`eye`, a point, for a camera with perspective; `toward`, a direction, for one without), the projection of a point in the scene to CSS pixels
|
|
58
|
+
* (`null` when it cannot be drawn), the view's size in CSS pixels, and the body's radius on the screen in CSS pixels.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import type { SurfaceView } from "@johnmorrisdotca/wakusei-planets/places";
|
|
63
|
+
*
|
|
64
|
+
* const view: SurfaceView = { 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 };
|
|
65
|
+
* console.log(view.radiusPx);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export interface SurfaceView {
|
|
69
|
+
centre: Vec3;
|
|
70
|
+
radius: number;
|
|
71
|
+
pole: Vec3;
|
|
72
|
+
meridian: Vec3;
|
|
73
|
+
scale: Vec3;
|
|
74
|
+
eye?: Vec3;
|
|
75
|
+
toward?: Vec3;
|
|
76
|
+
project(point: Vec3): {
|
|
77
|
+
x: number;
|
|
78
|
+
y: number;
|
|
79
|
+
} | null;
|
|
80
|
+
width: number;
|
|
81
|
+
height: number;
|
|
82
|
+
radiusPx: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A place's point on the body's surface in the scene, and the outward normal there: the planetocentric latitude and east longitude laid along the body's own axes onto its ellipsoid.
|
|
86
|
+
*
|
|
87
|
+
* @param view - The body as drawn.
|
|
88
|
+
* @param lat - Planetocentric latitude, degrees.
|
|
89
|
+
* @param lon - East longitude, degrees.
|
|
90
|
+
* @returns The point and the unit normal.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { surfacePoint } from "@johnmorrisdotca/wakusei-planets/places";
|
|
95
|
+
*
|
|
96
|
+
* const view = { centre: [0, 0, 0] as [number, number, number], radius: 2, pole: [0, 1, 0] as [number, number, number], meridian: [0, 0, 1] as [number, number, number], scale: [1, 1, 1] as [number, number, number], project: () => null, width: 1, height: 1, radiusPx: 1 };
|
|
97
|
+
* console.log(surfacePoint(view, 0, 90).point.map((n) => n.toFixed(1)).join(", "));
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function surfacePoint(view: SurfaceView, lat: number, lon: number): {
|
|
101
|
+
point: Vec3;
|
|
102
|
+
normal: Vec3;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* One mark to lay over the view: the place, its layer, and where it is in CSS pixels from the view's top left.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import type { PlaceMark } from "@johnmorrisdotca/wakusei-planets/places";
|
|
110
|
+
*
|
|
111
|
+
* const mark: Pick<PlaceMark, "layer" | "x" | "y"> = { layer: "landing", x: 120, y: 80 };
|
|
112
|
+
* console.log(mark.layer);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export interface PlaceMark {
|
|
116
|
+
place: Place;
|
|
117
|
+
layer: PlaceLayer;
|
|
118
|
+
x: number;
|
|
119
|
+
y: number;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The rules that keep the marks quiet, in CSS pixels: nothing is marked on a body under `fromPx` of radius on the screen; a named feature is marked once it is `featureFromPx` across (a famous one at any size);
|
|
123
|
+
* no two marks are closer than `gapPx` (the one chosen first keeps its place); and a body gets one mark for every `sharePx` of its radius, 8 at least and `most` at most.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { MARK_RULES } from "@johnmorrisdotca/wakusei-planets/places";
|
|
128
|
+
*
|
|
129
|
+
* console.log(MARK_RULES.gapPx, MARK_RULES.most);
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare const MARK_RULES: {
|
|
133
|
+
readonly fromPx: 40;
|
|
134
|
+
readonly featureFromPx: 14;
|
|
135
|
+
readonly gapPx: 12;
|
|
136
|
+
readonly sharePx: 4;
|
|
137
|
+
readonly most: 60;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* The marks to lay over a body: the places of the layers asked for that face the viewer (not too near the edge of the disc, where they would crowd), are inside the view, and are not crowded out by a mark
|
|
141
|
+
* that comes first. The visited sites come first, the famous before the rest, then the named features by size, and a feature is marked only once it is big enough on the screen to show (`MARK_RULES`;
|
|
142
|
+
* any famous one). Nothing is marked on a body too small on the screen, and a small body gets fewer marks than a big one.
|
|
143
|
+
*
|
|
144
|
+
* @param places - The body's list.
|
|
145
|
+
* @param layers - The layers to show.
|
|
146
|
+
* @param view - The body as drawn.
|
|
147
|
+
* @param radiusKm - The body's radius in kilometres, to tell a feature's size on the screen.
|
|
148
|
+
* @returns The marks, in the order they were chosen.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* import { placeMarks } from "@johnmorrisdotca/wakusei-planets/places";
|
|
153
|
+
* import { PLACES_MOON } from "@johnmorrisdotca/wakusei-planets/places/moon";
|
|
154
|
+
*
|
|
155
|
+
* const view = { centre: [0, 0, 0] as [number, number, number], radius: 1, pole: [0, 1, 0] as [number, number, number], meridian: [0, 0, 1] as [number, number, number], scale: [1, 1, 1] as [number, number, number], toward: [0, 0, 1] as [number, number, number],
|
|
156
|
+
* project: (p: [number, number, number]) => ({ x: 200 + p[0] * 180, y: 200 - p[1] * 180 }), width: 400, height: 400, radiusPx: 180 };
|
|
157
|
+
* console.log(placeMarks(PLACES_MOON, ["landing"], view, 1737.4).slice(0, 3).map((mark) => mark.place.name.en));
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function placeMarks(places: readonly Place[], layers: readonly PlaceLayer[], view: SurfaceView, radiusKm: number): PlaceMark[];
|
|
161
|
+
/**
|
|
162
|
+
* The turn of a body that brings a place to the middle of the disc, for a view that is turned by a yaw about the body's pole and then a tilt about the screen's x axis, looking along -z (the `<wakusei-body>` view):
|
|
163
|
+
* the yaw and the tilt in degrees. Where the pole is tipped so far that no yaw puts the place in the plane the tilt turns, it comes as near as it can.
|
|
164
|
+
*
|
|
165
|
+
* @param pole - The body's north pole in the view before the turn.
|
|
166
|
+
* @param meridian - Its longitude 0 on the equator.
|
|
167
|
+
* @param lat - The place's latitude, degrees.
|
|
168
|
+
* @param lon - Its east longitude, degrees.
|
|
169
|
+
* @returns `{ yaw, tilt }`: the yaw about the pole, and the turn about the x axis (positive brings the place's y down to the middle).
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* import { turnToPlace } from "@johnmorrisdotca/wakusei-planets/places";
|
|
174
|
+
*
|
|
175
|
+
* const turn = turnToPlace([0, 1, 0], [0, 0, 1], 0, 90);
|
|
176
|
+
* console.log(turn.yaw.toFixed(0), turn.tilt.toFixed(0));
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare function turnToPlace(pole: Vec3, meridian: Vec3, lat: number, lon: number): {
|
|
180
|
+
yaw: number;
|
|
181
|
+
tilt: number;
|
|
182
|
+
};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { dot } from "./vec.js";
|
|
2
|
+
/**
|
|
3
|
+
* The layers of places a view can show, each switched on by itself: `landing` (the crewed landings, the landers and the rovers), `crash` (the crash, impact and atmospheric-entry sites), `planned` (announced landings) and `feature`
|
|
4
|
+
* (the named features of the surface).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { PLACE_LAYERS } from "@johnmorrisdotca/wakusei-planets/places";
|
|
9
|
+
*
|
|
10
|
+
* console.log(PLACE_LAYERS.join(" "));
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export const PLACE_LAYERS = ["landing", "crash", "planned", "feature"];
|
|
14
|
+
/**
|
|
15
|
+
* The layer a kind of place is shown in.
|
|
16
|
+
*
|
|
17
|
+
* @param kind - The place's kind.
|
|
18
|
+
* @returns Its layer.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { layerOf } from "@johnmorrisdotca/wakusei-planets/places";
|
|
23
|
+
*
|
|
24
|
+
* console.log(layerOf("rover"), layerOf("impact"), layerOf("feature"));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function layerOf(kind) {
|
|
28
|
+
return kind === "crewed" || kind === "landing" || kind === "rover" ? "landing" : kind === "crash" || kind === "impact" || kind === "entry" ? "crash" : kind === "planned" ? "planned" : "feature";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The layers an attribute asks for: a list of layer names with spaces or commas between (`"landing crash"`), `all` (or an empty value) for every layer, and `none` or `off` for none. Unknown words are left out.
|
|
32
|
+
*
|
|
33
|
+
* @param value - The attribute's value, or `null` when it is absent (no layers).
|
|
34
|
+
* @returns The layers, in `PLACE_LAYERS` order.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { readPlaceLayers } from "@johnmorrisdotca/wakusei-planets/places";
|
|
39
|
+
*
|
|
40
|
+
* console.log(readPlaceLayers("crash, landing"), readPlaceLayers(""), readPlaceLayers(null));
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function readPlaceLayers(value) {
|
|
44
|
+
if (value === null)
|
|
45
|
+
return [];
|
|
46
|
+
const words = value.toLowerCase().split(/[\s,]+/).filter((word) => word !== "");
|
|
47
|
+
if (words.length === 0 || words.includes("all") || words.includes("on"))
|
|
48
|
+
return [...PLACE_LAYERS];
|
|
49
|
+
return PLACE_LAYERS.filter((layer) => words.includes(layer));
|
|
50
|
+
}
|
|
51
|
+
const RAD = Math.PI / 180;
|
|
52
|
+
/**
|
|
53
|
+
* A place's point on the body's surface in the scene, and the outward normal there: the planetocentric latitude and east longitude laid along the body's own axes onto its ellipsoid.
|
|
54
|
+
*
|
|
55
|
+
* @param view - The body as drawn.
|
|
56
|
+
* @param lat - Planetocentric latitude, degrees.
|
|
57
|
+
* @param lon - East longitude, degrees.
|
|
58
|
+
* @returns The point and the unit normal.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { surfacePoint } from "@johnmorrisdotca/wakusei-planets/places";
|
|
63
|
+
*
|
|
64
|
+
* const view = { centre: [0, 0, 0] as [number, number, number], radius: 2, pole: [0, 1, 0] as [number, number, number], meridian: [0, 0, 1] as [number, number, number], scale: [1, 1, 1] as [number, number, number], project: () => null, width: 1, height: 1, radiusPx: 1 };
|
|
65
|
+
* console.log(surfacePoint(view, 0, 90).point.map((n) => n.toFixed(1)).join(", "));
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function surfacePoint(view, lat, lon) {
|
|
69
|
+
const { pole: p, meridian: m, scale: s } = view;
|
|
70
|
+
const e = [p[1] * m[2] - p[2] * m[1], p[2] * m[0] - p[0] * m[2], p[0] * m[1] - p[1] * m[0]];
|
|
71
|
+
// the direction in the body's own frame (east, pole, meridian), stretched onto the ellipsoid along that direction: planetocentric, so the point is where that line from the centre meets the surface
|
|
72
|
+
const ux = Math.cos(lat * RAD) * Math.sin(lon * RAD);
|
|
73
|
+
const uy = Math.sin(lat * RAD);
|
|
74
|
+
const uz = Math.cos(lat * RAD) * Math.cos(lon * RAD);
|
|
75
|
+
const k = 1 / Math.hypot(ux / s[0], uy / s[1], uz / s[2]);
|
|
76
|
+
const [lx, ly, lz] = [ux * k, uy * k, uz * k];
|
|
77
|
+
const r = view.radius;
|
|
78
|
+
const point = [view.centre[0] + r * (e[0] * lx + p[0] * ly + m[0] * lz), view.centre[1] + r * (e[1] * lx + p[1] * ly + m[1] * lz), view.centre[2] + r * (e[2] * lx + p[2] * ly + m[2] * lz)];
|
|
79
|
+
const [nx, ny, nz] = [lx / (s[0] * s[0]), ly / (s[1] * s[1]), lz / (s[2] * s[2])];
|
|
80
|
+
const n = [e[0] * nx + p[0] * ny + m[0] * nz, e[1] * nx + p[1] * ny + m[1] * nz, e[2] * nx + p[2] * ny + m[2] * nz];
|
|
81
|
+
const len = Math.hypot(n[0], n[1], n[2]) || 1;
|
|
82
|
+
return { point, normal: [n[0] / len, n[1] / len, n[2] / len] };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The rules that keep the marks quiet, in CSS pixels: nothing is marked on a body under `fromPx` of radius on the screen; a named feature is marked once it is `featureFromPx` across (a famous one at any size);
|
|
86
|
+
* no two marks are closer than `gapPx` (the one chosen first keeps its place); and a body gets one mark for every `sharePx` of its radius, 8 at least and `most` at most.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* import { MARK_RULES } from "@johnmorrisdotca/wakusei-planets/places";
|
|
91
|
+
*
|
|
92
|
+
* console.log(MARK_RULES.gapPx, MARK_RULES.most);
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export const MARK_RULES = { fromPx: 40, featureFromPx: 14, gapPx: 12, sharePx: 4, most: 60 };
|
|
96
|
+
/**
|
|
97
|
+
* The marks to lay over a body: the places of the layers asked for that face the viewer (not too near the edge of the disc, where they would crowd), are inside the view, and are not crowded out by a mark
|
|
98
|
+
* that comes first. The visited sites come first, the famous before the rest, then the named features by size, and a feature is marked only once it is big enough on the screen to show (`MARK_RULES`;
|
|
99
|
+
* any famous one). Nothing is marked on a body too small on the screen, and a small body gets fewer marks than a big one.
|
|
100
|
+
*
|
|
101
|
+
* @param places - The body's list.
|
|
102
|
+
* @param layers - The layers to show.
|
|
103
|
+
* @param view - The body as drawn.
|
|
104
|
+
* @param radiusKm - The body's radius in kilometres, to tell a feature's size on the screen.
|
|
105
|
+
* @returns The marks, in the order they were chosen.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { placeMarks } from "@johnmorrisdotca/wakusei-planets/places";
|
|
110
|
+
* import { PLACES_MOON } from "@johnmorrisdotca/wakusei-planets/places/moon";
|
|
111
|
+
*
|
|
112
|
+
* const view = { centre: [0, 0, 0] as [number, number, number], radius: 1, pole: [0, 1, 0] as [number, number, number], meridian: [0, 0, 1] as [number, number, number], scale: [1, 1, 1] as [number, number, number], toward: [0, 0, 1] as [number, number, number],
|
|
113
|
+
* project: (p: [number, number, number]) => ({ x: 200 + p[0] * 180, y: 200 - p[1] * 180 }), width: 400, height: 400, radiusPx: 180 };
|
|
114
|
+
* console.log(placeMarks(PLACES_MOON, ["landing"], view, 1737.4).slice(0, 3).map((mark) => mark.place.name.en));
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export function placeMarks(places, layers, view, radiusKm) {
|
|
118
|
+
if (layers.length === 0 || !(view.radiusPx >= MARK_RULES.fromPx))
|
|
119
|
+
return [];
|
|
120
|
+
const wanted = [];
|
|
121
|
+
for (const place of places) {
|
|
122
|
+
const layer = layerOf(place.kind);
|
|
123
|
+
if (!layers.includes(layer))
|
|
124
|
+
continue;
|
|
125
|
+
if (layer === "feature" && place.famous !== true && ((place.feature?.diameterKm ?? 0) / radiusKm) * view.radiusPx < MARK_RULES.featureFromPx)
|
|
126
|
+
continue;
|
|
127
|
+
wanted.push(place);
|
|
128
|
+
}
|
|
129
|
+
const rank = (place) => (place.kind === "feature" ? 2 : 0) + (place.famous === true ? 0 : 1);
|
|
130
|
+
wanted.sort((a, b) => rank(a) - rank(b) || (b.feature?.diameterKm ?? 0) - (a.feature?.diameterKm ?? 0));
|
|
131
|
+
const most = Math.max(8, Math.min(MARK_RULES.most, Math.round(view.radiusPx / MARK_RULES.sharePx)));
|
|
132
|
+
const out = [];
|
|
133
|
+
for (const place of wanted) {
|
|
134
|
+
if (out.length >= most)
|
|
135
|
+
break;
|
|
136
|
+
const { point, normal } = surfacePoint(view, place.lat, place.lon);
|
|
137
|
+
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]);
|
|
138
|
+
const len = Math.hypot(sight[0], sight[1], sight[2]) || 1;
|
|
139
|
+
// a little short of the limb: a mark seen edge-on is a crowd of dots on the rim, and the surface there is a sliver
|
|
140
|
+
if (dot(normal, sight) / len < 0.12)
|
|
141
|
+
continue;
|
|
142
|
+
const at = view.project(point);
|
|
143
|
+
if (at === null || at.x < 0 || at.y < 0 || at.x > view.width || at.y > view.height)
|
|
144
|
+
continue;
|
|
145
|
+
if (out.some((mark) => Math.hypot(mark.x - at.x, mark.y - at.y) < MARK_RULES.gapPx))
|
|
146
|
+
continue;
|
|
147
|
+
out.push({ place, layer: layerOf(place.kind), x: at.x, y: at.y });
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The turn of a body that brings a place to the middle of the disc, for a view that is turned by a yaw about the body's pole and then a tilt about the screen's x axis, looking along -z (the `<wakusei-body>` view):
|
|
153
|
+
* the yaw and the tilt in degrees. Where the pole is tipped so far that no yaw puts the place in the plane the tilt turns, it comes as near as it can.
|
|
154
|
+
*
|
|
155
|
+
* @param pole - The body's north pole in the view before the turn.
|
|
156
|
+
* @param meridian - Its longitude 0 on the equator.
|
|
157
|
+
* @param lat - The place's latitude, degrees.
|
|
158
|
+
* @param lon - Its east longitude, degrees.
|
|
159
|
+
* @returns `{ yaw, tilt }`: the yaw about the pole, and the turn about the x axis (positive brings the place's y down to the middle).
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* import { turnToPlace } from "@johnmorrisdotca/wakusei-planets/places";
|
|
164
|
+
*
|
|
165
|
+
* const turn = turnToPlace([0, 1, 0], [0, 0, 1], 0, 90);
|
|
166
|
+
* console.log(turn.yaw.toFixed(0), turn.tilt.toFixed(0));
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export function turnToPlace(pole, meridian, lat, lon) {
|
|
170
|
+
const e = [pole[1] * meridian[2] - pole[2] * meridian[1], pole[2] * meridian[0] - pole[0] * meridian[2], pole[0] * meridian[1] - pole[1] * meridian[0]];
|
|
171
|
+
const c = Math.cos(lat * RAD);
|
|
172
|
+
const d = [0, 1, 2].map((i) => c * Math.cos(lon * RAD) * meridian[i] + c * Math.sin(lon * RAD) * e[i] + Math.sin(lat * RAD) * pole[i]);
|
|
173
|
+
// turning d about the pole by `yaw` (Rodrigues): x = A cos + B sin + C. Choose the yaw that makes x zero and leaves the place on the near side.
|
|
174
|
+
const pd = dot(pole, d);
|
|
175
|
+
const A = d[0] - pole[0] * pd;
|
|
176
|
+
const B = pole[1] * d[2] - pole[2] * d[1];
|
|
177
|
+
const C = pole[0] * pd;
|
|
178
|
+
const R = Math.hypot(A, B) || 1e-12;
|
|
179
|
+
const phi = Math.atan2(B, A);
|
|
180
|
+
const spread = Math.acos(Math.max(-1, Math.min(1, -C / R)));
|
|
181
|
+
const turned = (yaw) => {
|
|
182
|
+
const cs = Math.cos(yaw);
|
|
183
|
+
const sn = Math.sin(yaw);
|
|
184
|
+
const k = pole;
|
|
185
|
+
const kv = [k[1] * d[2] - k[2] * d[1], k[2] * d[0] - k[0] * d[2], k[0] * d[1] - k[1] * d[0]];
|
|
186
|
+
return [d[0] * cs + kv[0] * sn + k[0] * pd * (1 - cs), d[1] * cs + kv[1] * sn + k[1] * pd * (1 - cs), d[2] * cs + kv[2] * sn + k[2] * pd * (1 - cs)];
|
|
187
|
+
};
|
|
188
|
+
const a = turned(phi + spread);
|
|
189
|
+
const b = turned(phi - spread);
|
|
190
|
+
const [yaw, d1] = a[2] >= b[2] ? [phi + spread, a] : [phi - spread, b];
|
|
191
|
+
const tilt = Math.atan2(d1[1], d1[2]);
|
|
192
|
+
const wrap = (deg) => ((((deg + 180) % 360) + 360) % 360) - 180;
|
|
193
|
+
return { yaw: wrap(yaw / RAD), tilt: tilt / RAD };
|
|
194
|
+
}
|
package/dist/places/mars.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Place } from "../places.ts";
|
|
2
2
|
/**
|
|
3
|
-
* Every place on the Mars the package knows: the sites first, by date, then the named features by size. A place's `kind` says what it is (`placesOfKind` from `/places` picks by it).
|
|
3
|
+
* Every place on the Mars the package knows: the sites first, by date, then the planned landings, then the named features by size. A place's `kind` says what it is (`placesOfKind` from `/places` picks by it).
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```ts
|
package/dist/places/mars.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// The places on the Mars: landing, rover, crash and impact sites, and the named features, as one list. See `/places` for the record's shape and the lookups.
|
|
2
2
|
import { PLACES_MARS as DATA } from "../data/places-mars.js";
|
|
3
|
+
import { PLANNED_MARS } from "../data/places-planned.js";
|
|
4
|
+
const ALL = DATA;
|
|
3
5
|
/**
|
|
4
|
-
* Every place on the Mars the package knows: the sites first, by date, then the named features by size. A place's `kind` says what it is (`placesOfKind` from `/places` picks by it).
|
|
6
|
+
* Every place on the Mars the package knows: the sites first, by date, then the planned landings, then the named features by size. A place's `kind` says what it is (`placesOfKind` from `/places` picks by it).
|
|
5
7
|
*
|
|
6
8
|
* @example
|
|
7
9
|
* ```ts
|
|
@@ -10,4 +12,4 @@ import { PLACES_MARS as DATA } from "../data/places-mars.js";
|
|
|
10
12
|
* console.log(PLACES_MARS.length, "places;", PLACES_MARS.filter((place) => place.kind === "landing").length, "landings");
|
|
11
13
|
* ```
|
|
12
14
|
*/
|
|
13
|
-
export const PLACES_MARS =
|
|
15
|
+
export const PLACES_MARS = [...ALL.filter((place) => place.kind !== "feature"), ...PLANNED_MARS, ...ALL.filter((place) => place.kind === "feature")];
|
package/dist/places/moon.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Place } from "../places.ts";
|
|
2
2
|
/**
|
|
3
|
-
* Every place on the Moon the package knows: the sites first, by date, then the named features by size. A place's `kind` says what it is (`placesOfKind` from `/places` picks by it).
|
|
3
|
+
* Every place on the Moon the package knows: the sites first, by date, then the planned landings, then the named features by size. A place's `kind` says what it is (`placesOfKind` from `/places` picks by it).
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```ts
|
package/dist/places/moon.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// The places on the Moon: landing, rover, crash and impact sites, and the named features, as one list. See `/places` for the record's shape and the lookups.
|
|
2
2
|
import { PLACES_MOON as DATA } from "../data/places-moon.js";
|
|
3
|
+
import { PLANNED_MOON } from "../data/places-planned.js";
|
|
4
|
+
const ALL = DATA;
|
|
3
5
|
/**
|
|
4
|
-
* Every place on the Moon the package knows: the sites first, by date, then the named features by size. A place's `kind` says what it is (`placesOfKind` from `/places` picks by it).
|
|
6
|
+
* Every place on the Moon the package knows: the sites first, by date, then the planned landings, then the named features by size. A place's `kind` says what it is (`placesOfKind` from `/places` picks by it).
|
|
5
7
|
*
|
|
6
8
|
* @example
|
|
7
9
|
* ```ts
|
|
@@ -10,4 +12,4 @@ import { PLACES_MOON as DATA } from "../data/places-moon.js";
|
|
|
10
12
|
* console.log(PLACES_MOON.length, "places;", PLACES_MOON.filter((place) => place.kind === "landing").length, "landings");
|
|
11
13
|
* ```
|
|
12
14
|
*/
|
|
13
|
-
export const PLACES_MOON =
|
|
15
|
+
export const PLACES_MOON = [...ALL.filter((place) => place.kind !== "feature"), ...PLANNED_MOON, ...ALL.filter((place) => place.kind === "feature")];
|
package/dist/places.d.ts
CHANGED
|
@@ -1,6 +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
5
|
/**
|
|
5
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
|
|
6
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.
|
|
@@ -72,15 +73,16 @@ export interface Place {
|
|
|
72
73
|
diameterKm: number;
|
|
73
74
|
approved: string;
|
|
74
75
|
};
|
|
75
|
-
/** For a planned landing: the announced date, its state, and the date the announcement was read. */
|
|
76
|
+
/** For a planned landing: the announced date (a year, or a year and month, as the page gives it), whether that date is the `launch` or the `landing`, its state (`slipped` where the agency's own pages have moved it later), and the date the announcement was read. */
|
|
76
77
|
planned?: {
|
|
77
78
|
date: string;
|
|
79
|
+
dateOf: "launch" | "landing";
|
|
78
80
|
status: "announced" | "slipped" | "cancelled";
|
|
79
81
|
read: string;
|
|
80
82
|
};
|
|
81
83
|
/** Where the record comes from, and the date that source's file was read. */
|
|
82
84
|
source: {
|
|
83
|
-
id: "iau-gazetteer" | "gcat-landercat" | "nssdca" | "pds-ode" | "nasa-mars24" | "agency" | "nasa-ntrs" | "pds-atmospheres" | "paper";
|
|
85
|
+
id: "iau-gazetteer" | "gcat-landercat" | "nssdca" | "pds-ode" | "nasa-mars24" | "agency" | "nasa-ntrs" | "pds-atmospheres" | "paper" | "announcement";
|
|
84
86
|
read: string;
|
|
85
87
|
latitude?: "planetocentric" | "converted" | "not stated";
|
|
86
88
|
/** The page or paper a position was typed from, where it is not one of the tables above. */
|
package/dist/places.js
CHANGED
|
@@ -5,6 +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
9
|
/**
|
|
9
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,
|
|
10
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).
|
|
@@ -25,6 +26,7 @@ export const PLACES_CREDITS = [
|
|
|
25
26
|
{ id: "agency", line: "NASA mission and Photojournal pages (the address is in each record's source.url)", licence: "US government work", url: "https://www.nasa.gov/nasa-brand-center/images-and-media/" },
|
|
26
27
|
{ id: "nasa-ntrs", line: "Basilevsky and Weitz 1992, The geology of the Venera/Vega landing sites, NASA Technical Reports Server", licence: "public use permitted (NTRS)", url: "https://ntrs.nasa.gov/citations/19930005108" },
|
|
27
28
|
{ id: "pds-atmospheres", line: "NASA Planetary Data System, Planetary Atmospheres Node, Pioneer Venus summary", licence: "US government work", url: "https://pds-atmospheres.nmsu.edu/data_and_services/atmospheres_data/PIONEER_Venus/venus_cp.html" },
|
|
29
|
+
{ id: "announcement", line: "the agency's or operator's own announcement of a planned landing (the address is in each record's source.url; the position is the IAU Gazetteer's centre of the named site)", licence: "facts (a date and a site's name) typed by hand; no text copied", url: "https://planetarynames.wr.usgs.gov/" },
|
|
28
30
|
{ id: "paper", line: "the published paper named in the record's source.url (Daly et al. 2023; Nagdimunov et al. 2014; Hoang et al. 2020)", licence: "coordinates (facts) typed from the papers, none of whose text, figures or tables is copied; Daly et al. 2023 is CC BY 4.0, credited", url: "https://doi.org/10.1038/s41586-023-05810-5" },
|
|
29
31
|
];
|
|
30
32
|
/**
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Place, PlaceBody } from "../places.ts";
|
|
2
|
+
import type { PlaceLayer, PlaceMark } from "../place-marks.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The short line under a place's name: what it is and when (a site's year, a planned landing's announced year, a feature's kind and size), in English or Japanese.
|
|
5
|
+
*
|
|
6
|
+
* @param place - The place.
|
|
7
|
+
* @param lang - `en` or `ja`.
|
|
8
|
+
* @returns The line.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts no-run
|
|
12
|
+
* import { placeLine } from "@johnmorrisdotca/wakusei-planets/element";
|
|
13
|
+
*
|
|
14
|
+
* console.log(placeLine({ id: "moon/x", kind: "crewed", name: { en: "X", ja: "X" }, lat: 0, lon: 0, date: "1969-07-20T20:17Z", source: { id: "nssdca", read: "2026-11-11" } }, "en"));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function placeLine(place: Place, lang: "en" | "ja"): string;
|
|
18
|
+
type PlacesLoader = (body: PlaceBody) => Promise<readonly Place[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Give the views the lists of places, for the marks of the `places` attribute: `loadPlaces` from `/places`, which fetches each body's table as a chunk of its own the first time it is asked for, or a function of your own
|
|
21
|
+
* that returns a body's list. The views hold no table themselves, so a page that never marks a place never carries one; until this is called a view marks nothing. Views already on the page lay their marks at once.
|
|
22
|
+
*
|
|
23
|
+
* @param load - A body's list of places, for a body of `PLACE_BODIES`.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts no-run
|
|
27
|
+
* import { setPlacesLoader } from "@johnmorrisdotca/wakusei-planets/element";
|
|
28
|
+
* import { loadPlaces } from "@johnmorrisdotca/wakusei-planets/places";
|
|
29
|
+
*
|
|
30
|
+
* setPlacesLoader(loadPlaces);
|
|
31
|
+
* document.querySelector("wakusei-body")!.setAttribute("places", "landing crash");
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function setPlacesLoader(load: PlacesLoader): void;
|
|
35
|
+
/** The loader `setPlacesLoader` was given, if any. */
|
|
36
|
+
export declare const placesLoader: () => PlacesLoader | undefined;
|
|
37
|
+
/** Hear `setPlacesLoader`; returns the call that stops it. */
|
|
38
|
+
export declare function onPlacesLoader(heard: () => void): () => void;
|
|
39
|
+
/** The marks over one view. */
|
|
40
|
+
export interface PlaceLayerView {
|
|
41
|
+
/** Lay these marks, moving the ones already there, adding the new and taking away the rest. */
|
|
42
|
+
set(marks: readonly PlaceMark[]): void;
|
|
43
|
+
/** Take every mark away. */
|
|
44
|
+
clear(): void;
|
|
45
|
+
/** The marks laid now: the place's id, its layer and where it is, in CSS pixels. */
|
|
46
|
+
readonly shown: readonly {
|
|
47
|
+
id: string;
|
|
48
|
+
layer: PlaceLayer;
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
}[];
|
|
52
|
+
dispose(): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Make the layer of marks inside a view's shadow root, above its picture. `pick` is called for a click or Enter on a mark, with the place and where its mark is.
|
|
56
|
+
*
|
|
57
|
+
* @param root - The view's shadow root.
|
|
58
|
+
* @param options - `lang` reads the view's language at the time a tip is shown; `pick` hears a chosen place.
|
|
59
|
+
* @returns The layer.
|
|
60
|
+
*/
|
|
61
|
+
export declare function createPlaceLayer(root: ShadowRoot, options: {
|
|
62
|
+
lang(): "en" | "ja";
|
|
63
|
+
pick(place: Place, at: {
|
|
64
|
+
x: number;
|
|
65
|
+
y: number;
|
|
66
|
+
}): void;
|
|
67
|
+
}): PlaceLayerView;
|
|
68
|
+
export {};
|