@johnmorrisdotca/wakusei-planets 0.59.0 → 0.60.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 +4 -0
- package/README.md +16 -3
- package/dist/flat/bodies.d.ts +122 -0
- package/dist/flat/bodies.js +115 -0
- package/dist/flat/define.d.ts +3 -0
- package/dist/flat/define.js +6 -0
- package/dist/flat/element.d.ts +145 -0
- package/dist/flat/element.js +1614 -0
- package/dist/flat/geometry.d.ts +127 -0
- package/dist/flat/geometry.js +121 -0
- package/dist/flat/index.d.ts +5 -0
- package/dist/flat/index.js +6 -0
- package/dist/flat/scene.d.ts +152 -0
- package/dist/flat/scene.js +195 -0
- package/dist/flat/words.d.ts +55 -0
- package/dist/flat/words.js +133 -0
- package/package.json +13 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Longitude brought into -180 up to (not including) 180.
|
|
3
|
+
*
|
|
4
|
+
* @param lon - Degrees.
|
|
5
|
+
* @returns The same direction, wrapped.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { wrapLongitude } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
10
|
+
*
|
|
11
|
+
* console.log(wrapLongitude(190), wrapLongitude(-181), wrapLongitude(180));
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const wrapLongitude: (lon: number) => number;
|
|
15
|
+
/**
|
|
16
|
+
* How the flat map sits in its box: the box's size in pixels, the longitude and latitude under its middle, and the zoom (1 shows the whole world, up to 8).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import type { FlatView } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
21
|
+
*
|
|
22
|
+
* const view: FlatView = { width: 800, height: 400, centerLon: 0, centerLat: 0, zoom: 1 };
|
|
23
|
+
* console.log(view.zoom);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export interface FlatView {
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
centerLon: number;
|
|
30
|
+
centerLat: number;
|
|
31
|
+
zoom: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The furthest the map zooms in: 8 times the whole-world view.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { MAX_ZOOM } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
39
|
+
*
|
|
40
|
+
* console.log(MAX_ZOOM);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare const MAX_ZOOM = 8;
|
|
44
|
+
/**
|
|
45
|
+
* Pixels for one degree: the world fills the box, as wide as it is, or as tall as it is when the box is taller than 2 to 1, so a phone's box is filled and the map wraps round its sides.
|
|
46
|
+
*
|
|
47
|
+
* @param view - The view.
|
|
48
|
+
* @returns Pixels a degree, of longitude or latitude (they are the same on this map).
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { pixelsPerDegree } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
53
|
+
*
|
|
54
|
+
* console.log(pixelsPerDegree({ width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 }), pixelsPerDegree({ width: 390, height: 520, centerLon: 0, centerLat: 0, zoom: 1 }).toFixed(2));
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare const pixelsPerDegree: (view: FlatView) => number;
|
|
58
|
+
/**
|
|
59
|
+
* Where a longitude and latitude fall in the box, in pixels from its top left. The longitude is taken the short way round from the middle, so a place wraps cleanly at the map's edges.
|
|
60
|
+
*
|
|
61
|
+
* @param view - The view.
|
|
62
|
+
* @param lon - Degrees east.
|
|
63
|
+
* @param lat - Degrees north.
|
|
64
|
+
* @returns `x` and `y` in pixels.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { projectFlat } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
69
|
+
*
|
|
70
|
+
* const view = { width: 720, height: 360, centerLon: 155, centerLat: 0, zoom: 1 };
|
|
71
|
+
* console.log(projectFlat(view, 139.7, 35.7), projectFlat(view, -170, 0));
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function projectFlat(view: FlatView, lon: number, lat: number): {
|
|
75
|
+
x: number;
|
|
76
|
+
y: number;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* The longitude and latitude at a point of the box: the opposite of `projectFlat`. The latitude is not limited to the map (a point above the top gives more than 90).
|
|
80
|
+
*
|
|
81
|
+
* @param view - The view.
|
|
82
|
+
* @param x - Pixels from the left.
|
|
83
|
+
* @param y - Pixels from the top.
|
|
84
|
+
* @returns `lon` in -180 up to 180 and `lat`.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { unprojectFlat } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
89
|
+
*
|
|
90
|
+
* console.log(unprojectFlat({ width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 }, 360, 180));
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function unprojectFlat(view: FlatView, x: number, y: number): {
|
|
94
|
+
lon: number;
|
|
95
|
+
lat: number;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* The view kept inside what the map can show: the zoom between 1 and 8, the longitude wrapped, and the middle's latitude so that the poles are never further in than the box's edges.
|
|
99
|
+
*
|
|
100
|
+
* @param view - The view asked for.
|
|
101
|
+
* @returns The view to use.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { clampView } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
106
|
+
*
|
|
107
|
+
* console.log(clampView({ width: 720, height: 360, centerLon: 200, centerLat: 40, zoom: 1 }));
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare function clampView(view: FlatView): FlatView;
|
|
111
|
+
/**
|
|
112
|
+
* Zoom by a factor about a point of the box, so the place under that point stays under it.
|
|
113
|
+
*
|
|
114
|
+
* @param view - The view.
|
|
115
|
+
* @param factor - Above 1 zooms in.
|
|
116
|
+
* @param x - Pixels from the left; the middle when left out.
|
|
117
|
+
* @param y - Pixels from the top; the middle when left out.
|
|
118
|
+
* @returns The new view, clamped.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* import { zoomAbout } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
123
|
+
*
|
|
124
|
+
* console.log(zoomAbout({ width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 }, 2, 540, 90).zoom);
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function zoomAbout(view: FlatView, factor: number, x?: number, y?: number): FlatView;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// The flat map's own geometry: an equirectangular (plate carree) map of a body that wraps round it. The same functions, with the same names and numbers, as chikyu-earth's flat map, so one page can swap bodies behind one control. Pure: numbers in, numbers out.
|
|
2
|
+
/**
|
|
3
|
+
* Longitude brought into -180 up to (not including) 180.
|
|
4
|
+
*
|
|
5
|
+
* @param lon - Degrees.
|
|
6
|
+
* @returns The same direction, wrapped.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { wrapLongitude } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
11
|
+
*
|
|
12
|
+
* console.log(wrapLongitude(190), wrapLongitude(-181), wrapLongitude(180));
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const wrapLongitude = (lon) => ((((lon + 180) % 360) + 360) % 360) - 180;
|
|
16
|
+
/**
|
|
17
|
+
* The furthest the map zooms in: 8 times the whole-world view.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { MAX_ZOOM } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
22
|
+
*
|
|
23
|
+
* console.log(MAX_ZOOM);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const MAX_ZOOM = 8;
|
|
27
|
+
/**
|
|
28
|
+
* Pixels for one degree: the world fills the box, as wide as it is, or as tall as it is when the box is taller than 2 to 1, so a phone's box is filled and the map wraps round its sides.
|
|
29
|
+
*
|
|
30
|
+
* @param view - The view.
|
|
31
|
+
* @returns Pixels a degree, of longitude or latitude (they are the same on this map).
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { pixelsPerDegree } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
36
|
+
*
|
|
37
|
+
* console.log(pixelsPerDegree({ width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 }), pixelsPerDegree({ width: 390, height: 520, centerLon: 0, centerLat: 0, zoom: 1 }).toFixed(2));
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export const pixelsPerDegree = (view) => Math.max(view.width / 360, view.height / 180) * view.zoom;
|
|
41
|
+
/**
|
|
42
|
+
* Where a longitude and latitude fall in the box, in pixels from its top left. The longitude is taken the short way round from the middle, so a place wraps cleanly at the map's edges.
|
|
43
|
+
*
|
|
44
|
+
* @param view - The view.
|
|
45
|
+
* @param lon - Degrees east.
|
|
46
|
+
* @param lat - Degrees north.
|
|
47
|
+
* @returns `x` and `y` in pixels.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { projectFlat } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
52
|
+
*
|
|
53
|
+
* const view = { width: 720, height: 360, centerLon: 155, centerLat: 0, zoom: 1 };
|
|
54
|
+
* console.log(projectFlat(view, 139.7, 35.7), projectFlat(view, -170, 0));
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function projectFlat(view, lon, lat) {
|
|
58
|
+
const k = pixelsPerDegree(view);
|
|
59
|
+
return { x: view.width / 2 + wrapLongitude(lon - view.centerLon) * k, y: view.height / 2 - (lat - view.centerLat) * k };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The longitude and latitude at a point of the box: the opposite of `projectFlat`. The latitude is not limited to the map (a point above the top gives more than 90).
|
|
63
|
+
*
|
|
64
|
+
* @param view - The view.
|
|
65
|
+
* @param x - Pixels from the left.
|
|
66
|
+
* @param y - Pixels from the top.
|
|
67
|
+
* @returns `lon` in -180 up to 180 and `lat`.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { unprojectFlat } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
72
|
+
*
|
|
73
|
+
* console.log(unprojectFlat({ width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 }, 360, 180));
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export function unprojectFlat(view, x, y) {
|
|
77
|
+
const k = pixelsPerDegree(view);
|
|
78
|
+
return { lon: wrapLongitude(view.centerLon + (x - view.width / 2) / k), lat: view.centerLat - (y - view.height / 2) / k };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The view kept inside what the map can show: the zoom between 1 and 8, the longitude wrapped, and the middle's latitude so that the poles are never further in than the box's edges.
|
|
82
|
+
*
|
|
83
|
+
* @param view - The view asked for.
|
|
84
|
+
* @returns The view to use.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { clampView } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
89
|
+
*
|
|
90
|
+
* console.log(clampView({ width: 720, height: 360, centerLon: 200, centerLat: 40, zoom: 1 }));
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export function clampView(view) {
|
|
94
|
+
const zoom = Math.min(MAX_ZOOM, Math.max(1, Number.isFinite(view.zoom) ? view.zoom : 1));
|
|
95
|
+
const next = { ...view, zoom, centerLon: wrapLongitude(Number.isFinite(view.centerLon) ? view.centerLon : 0) };
|
|
96
|
+
const limit = Math.max(0, 90 - view.height / 2 / pixelsPerDegree(next));
|
|
97
|
+
next.centerLat = Math.min(limit, Math.max(-limit, Number.isFinite(view.centerLat) ? view.centerLat : 0));
|
|
98
|
+
return next;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Zoom by a factor about a point of the box, so the place under that point stays under it.
|
|
102
|
+
*
|
|
103
|
+
* @param view - The view.
|
|
104
|
+
* @param factor - Above 1 zooms in.
|
|
105
|
+
* @param x - Pixels from the left; the middle when left out.
|
|
106
|
+
* @param y - Pixels from the top; the middle when left out.
|
|
107
|
+
* @returns The new view, clamped.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { zoomAbout } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
112
|
+
*
|
|
113
|
+
* console.log(zoomAbout({ width: 720, height: 360, centerLon: 0, centerLat: 0, zoom: 1 }, 2, 540, 90).zoom);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export function zoomAbout(view, factor, x = view.width / 2, y = view.height / 2) {
|
|
117
|
+
const at = unprojectFlat(view, x, y);
|
|
118
|
+
const zoom = Math.min(MAX_ZOOM, Math.max(1, view.zoom * factor));
|
|
119
|
+
const k = pixelsPerDegree({ ...view, zoom });
|
|
120
|
+
return clampView({ ...view, zoom, centerLon: at.lon - (x - view.width / 2) / k, centerLat: at.lat + (y - view.height / 2) / k });
|
|
121
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { FLAT_BODIES, ORBITER_COLOURS, flatBody, isFlatBody, orbiterColour, orbiterName, type FlatBodyId, type FlatBodyInfo } from "./bodies.ts";
|
|
2
|
+
export { MAX_ZOOM, clampView, pixelsPerDegree, projectFlat, unprojectFlat, wrapLongitude, zoomAbout, type FlatView } from "./geometry.ts";
|
|
3
|
+
export { circleOutline, flatOrbiter, flatSun, flatTrack, hasPath, shadeNight, trackPieces, type FlatOrbiter } from "./scene.ts";
|
|
4
|
+
export { FLAT_WORDS, coordinateText, say, type FlatLang } from "./words.ts";
|
|
5
|
+
export type { FlatPick, WakuseiFlat } from "./element.ts";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The flat map's pure parts and the element's types (`@johnmorrisdotca/wakusei-planets/flat`): the map's geometry, the bodies it draws, the Sun, the orbiters over the ground, the night's shading, coverage circles and ground tracks, and the words. They import on a server and need no browser.
|
|
2
|
+
// The element itself is in `@johnmorrisdotca/wakusei-planets/flat/define`, which registers `<wakusei-flat>`.
|
|
3
|
+
export { FLAT_BODIES, ORBITER_COLOURS, flatBody, isFlatBody, orbiterColour, orbiterName } from "./bodies.js";
|
|
4
|
+
export { MAX_ZOOM, clampView, pixelsPerDegree, projectFlat, unprojectFlat, wrapLongitude, zoomAbout } from "./geometry.js";
|
|
5
|
+
export { circleOutline, flatOrbiter, flatSun, flatTrack, hasPath, shadeNight, trackPieces } from "./scene.js";
|
|
6
|
+
export { FLAT_WORDS, coordinateText, say } from "./words.js";
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { type GroundPoint } from "../ground-track.ts";
|
|
2
|
+
import { type OrbiterId, type OrbiterStatus } from "../orbiters.ts";
|
|
3
|
+
import { type FlatBodyId } from "./bodies.ts";
|
|
4
|
+
import { type FlatView } from "./geometry.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Where the Sun is overhead on a body: latitude and east longitude in degrees, from the package's own ephemeris and the body's IAU pole and prime meridian. The longitude is in -180 up to 180, like the map's.
|
|
7
|
+
*
|
|
8
|
+
* @param body - `moon` or `mars`.
|
|
9
|
+
* @param ms - Milliseconds since 1970 (UTC).
|
|
10
|
+
* @returns The point.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { flatSun } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
15
|
+
*
|
|
16
|
+
* const sun = flatSun("moon", Date.UTC(1969, 6, 20, 20, 17, 40));
|
|
17
|
+
* console.log(sun.lon.toFixed(0), "east: the Sun is low in the east at Tranquility Base");
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function flatSun(body: FlatBodyId, ms: number): GroundPoint;
|
|
21
|
+
/**
|
|
22
|
+
* One orbiter as the flat map shows it at a moment.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { flatOrbiter, type FlatOrbiter } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
27
|
+
*
|
|
28
|
+
* const lro: FlatOrbiter = flatOrbiter("lro", Date.UTC(2026, 10, 12))!;
|
|
29
|
+
* console.log(lro.status, lro.dim);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export interface FlatOrbiter {
|
|
33
|
+
id: OrbiterId;
|
|
34
|
+
/** The point on the ground under it: degrees, longitude in -180 up to 180. */
|
|
35
|
+
lat: number;
|
|
36
|
+
lon: number;
|
|
37
|
+
/** Its height above the surface in kilometres. */
|
|
38
|
+
altitudeKm: number;
|
|
39
|
+
/** Where its path comes from at this moment (`orbiterStatus`): `tracked`, `predicted` or `modelled`. */
|
|
40
|
+
status: Exclude<OrbiterStatus, "none">;
|
|
41
|
+
/** True when its position is approximate and the map should draw it faint (`orbiterDim`). */
|
|
42
|
+
dim: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Where an orbiter is over the ground at a moment, with its height and how sure its place is. `undefined` for a craft with no public path (Tianwen-1, CAPSTONE), which the map does not draw.
|
|
46
|
+
*
|
|
47
|
+
* @param id - The orbiter.
|
|
48
|
+
* @param ms - Milliseconds since 1970 (UTC).
|
|
49
|
+
* @returns The orbiter, or `undefined`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { flatOrbiter } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
54
|
+
*
|
|
55
|
+
* console.log(flatOrbiter("mro", Date.UTC(2026, 10, 12))?.altitudeKm.toFixed(0), flatOrbiter("tianwen-1", Date.UTC(2026, 10, 12)));
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function flatOrbiter(id: OrbiterId, ms: number): FlatOrbiter | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Whether an orbiter has a path the map can draw at all.
|
|
61
|
+
*
|
|
62
|
+
* @param id - The orbiter.
|
|
63
|
+
* @returns False for Tianwen-1 and CAPSTONE.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { hasPath } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
68
|
+
*
|
|
69
|
+
* console.log(hasPath("lro"), hasPath("tianwen-1"));
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const hasPath: (id: OrbiterId) => boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Shade the night side into a grid of pixels: for each cell of a `columns` by `rows` grid laid over the view (each cell `cell` pixels of the box on a side), the alpha of the night's colour, from how far the Sun is below the horizon there.
|
|
75
|
+
* Full night is `twilightDeg` below the horizon and the shading is gone a quarter of that above it, so the Moon's edge is sharp and Mars's soft. The cell's longitude wraps round the body, so a map wider than the world is shaded the same at both copies.
|
|
76
|
+
*
|
|
77
|
+
* @param out - The grid, 4 bytes a cell (red, green, blue, alpha), filled in.
|
|
78
|
+
* @param columns - Cells across.
|
|
79
|
+
* @param rows - Cells down.
|
|
80
|
+
* @param cell - The cell's side in pixels of the view.
|
|
81
|
+
* @param view - The map's view.
|
|
82
|
+
* @param sun - Where the Sun is overhead.
|
|
83
|
+
* @param body - `moon` or `mars`: the night's colour and the twilight's width.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* import { shadeNight } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
88
|
+
*
|
|
89
|
+
* const view = { width: 8, height: 4, centerLon: 0, centerLat: 0, zoom: 1 };
|
|
90
|
+
* const grid = new Uint8ClampedArray(8 * 4 * 4);
|
|
91
|
+
* shadeNight(grid, 8, 4, 1, view, { lat: 0, lon: 0 }, "moon");
|
|
92
|
+
* console.log(grid[3 + 4 * 0] === 0, grid[3 + 4 * 7]! > 150);
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function shadeNight(out: Uint8ClampedArray, columns: number, rows: number, cell: number, view: FlatView, sun: GroundPoint, body: FlatBodyId): void;
|
|
96
|
+
/**
|
|
97
|
+
* The outline of the circle on a body's surface that a craft can see: every point `angleDeg` from the point under it, as longitude and latitude with the longitude carried on without a jump (so it can run past 180 and the map draws
|
|
98
|
+
* the circle again a world to the left and right). The outline's last point is its first again; where the circle holds a pole, `pole` is `1` or `-1` and the last point is a whole turn of longitude from the first.
|
|
99
|
+
*
|
|
100
|
+
* @param lat - Latitude of the centre.
|
|
101
|
+
* @param lon - Longitude of the centre.
|
|
102
|
+
* @param angleDeg - The circle's angular radius at the body's centre, in degrees (`coverageAngleRad` in degrees).
|
|
103
|
+
* @param steps - How many steps round it (there are `steps + 1` points, the last being the first again).
|
|
104
|
+
* @returns The points, and whether a pole is inside.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { circleOutline } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
109
|
+
*
|
|
110
|
+
* const ring = circleOutline(80, 10, 15);
|
|
111
|
+
* console.log(ring.pole, ring.points.length);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function circleOutline(lat: number, lon: number, angleDeg: number, steps?: number): {
|
|
115
|
+
points: [number, number][];
|
|
116
|
+
pole: -1 | 0 | 1;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* An orbiter's ground track for one trip round: half behind it and half ahead, as points with their moments. The package's own `orbiterGroundTrack`, over one period centred on the moment.
|
|
120
|
+
*
|
|
121
|
+
* @param id - The orbiter.
|
|
122
|
+
* @param ms - Milliseconds since 1970 (UTC): the moment the orbiter is at the track's middle.
|
|
123
|
+
* @param points - How many steps round the trip.
|
|
124
|
+
* @returns The points with their longitude in -180 up to 180, or an empty list for a craft with no path.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { flatTrack } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
129
|
+
*
|
|
130
|
+
* const track = flatTrack("lro", Date.UTC(2026, 10, 12), 40);
|
|
131
|
+
* console.log(track.length, track.filter((p) => p.ms <= Date.UTC(2026, 10, 12)).length);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function flatTrack(id: OrbiterId, ms: number, points?: number): {
|
|
135
|
+
lat: number;
|
|
136
|
+
lon: number;
|
|
137
|
+
ms: number;
|
|
138
|
+
}[];
|
|
139
|
+
/**
|
|
140
|
+
* A run of ground points cut into the straight pieces a flat map can draw: each step is split where it crosses the date line or runs over a pole, so no line crosses the whole map.
|
|
141
|
+
*
|
|
142
|
+
* @param points - Points in order, longitude in -180 up to 180.
|
|
143
|
+
* @returns Pieces, each from one point to the next, longitudes within -180 and 180.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* import { trackPieces } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
148
|
+
*
|
|
149
|
+
* console.log(trackPieces([{ lat: 0, lon: 170 }, { lat: 5, lon: -170 }]).length);
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export declare function trackPieces(points: readonly GroundPoint[]): [GroundPoint, GroundPoint][];
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// What the flat map shows at a moment, as numbers: where the Sun is overhead, where each orbiter is over the ground, the shading of the night side, a craft's coverage circle and its ground track cut for a flat map.
|
|
2
|
+
// Pure: no DOM, no clock reads (the moment is always given).
|
|
3
|
+
import { splitTrail } from "../ground-track.js";
|
|
4
|
+
import { orbiterElements, orbiterGround, orbiterGroundTrack, orbiterNumbers, orbiterDim } from "../orbiters.js";
|
|
5
|
+
import { subSolarPoint } from "../places.js";
|
|
6
|
+
import { flatBody } from "./bodies.js";
|
|
7
|
+
import { pixelsPerDegree, wrapLongitude } from "./geometry.js";
|
|
8
|
+
const RAD = Math.PI / 180;
|
|
9
|
+
/**
|
|
10
|
+
* Where the Sun is overhead on a body: latitude and east longitude in degrees, from the package's own ephemeris and the body's IAU pole and prime meridian. The longitude is in -180 up to 180, like the map's.
|
|
11
|
+
*
|
|
12
|
+
* @param body - `moon` or `mars`.
|
|
13
|
+
* @param ms - Milliseconds since 1970 (UTC).
|
|
14
|
+
* @returns The point.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { flatSun } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
19
|
+
*
|
|
20
|
+
* const sun = flatSun("moon", Date.UTC(1969, 6, 20, 20, 17, 40));
|
|
21
|
+
* console.log(sun.lon.toFixed(0), "east: the Sun is low in the east at Tranquility Base");
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function flatSun(body, ms) {
|
|
25
|
+
const sun = subSolarPoint(flatBody(body).id, ms);
|
|
26
|
+
return { lat: sun.lat, lon: wrapLongitude(sun.lon) };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Where an orbiter is over the ground at a moment, with its height and how sure its place is. `undefined` for a craft with no public path (Tianwen-1, CAPSTONE), which the map does not draw.
|
|
30
|
+
*
|
|
31
|
+
* @param id - The orbiter.
|
|
32
|
+
* @param ms - Milliseconds since 1970 (UTC).
|
|
33
|
+
* @returns The orbiter, or `undefined`.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { flatOrbiter } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
38
|
+
*
|
|
39
|
+
* console.log(flatOrbiter("mro", Date.UTC(2026, 10, 12))?.altitudeKm.toFixed(0), flatOrbiter("tianwen-1", Date.UTC(2026, 10, 12)));
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function flatOrbiter(id, ms) {
|
|
43
|
+
const ground = orbiterGround(id, ms);
|
|
44
|
+
const numbers = orbiterNumbers(id, ms);
|
|
45
|
+
if (ground === undefined || numbers === undefined || numbers.status === "none")
|
|
46
|
+
return undefined;
|
|
47
|
+
return { id, lat: ground.lat, lon: wrapLongitude(ground.lon), altitudeKm: numbers.altitudeKm, status: numbers.status, dim: orbiterDim(id, ms) };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Whether an orbiter has a path the map can draw at all.
|
|
51
|
+
*
|
|
52
|
+
* @param id - The orbiter.
|
|
53
|
+
* @returns False for Tianwen-1 and CAPSTONE.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { hasPath } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
58
|
+
*
|
|
59
|
+
* console.log(hasPath("lro"), hasPath("tianwen-1"));
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export const hasPath = (id) => orbiterElements(id) !== undefined;
|
|
63
|
+
/** The shading's smooth step: 0 up to `a`, 1 from `b`, smooth between. */
|
|
64
|
+
const smooth = (a, b, x) => {
|
|
65
|
+
const t = Math.min(1, Math.max(0, (x - a) / (b - a)));
|
|
66
|
+
return t * t * (3 - 2 * t);
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Shade the night side into a grid of pixels: for each cell of a `columns` by `rows` grid laid over the view (each cell `cell` pixels of the box on a side), the alpha of the night's colour, from how far the Sun is below the horizon there.
|
|
70
|
+
* Full night is `twilightDeg` below the horizon and the shading is gone a quarter of that above it, so the Moon's edge is sharp and Mars's soft. The cell's longitude wraps round the body, so a map wider than the world is shaded the same at both copies.
|
|
71
|
+
*
|
|
72
|
+
* @param out - The grid, 4 bytes a cell (red, green, blue, alpha), filled in.
|
|
73
|
+
* @param columns - Cells across.
|
|
74
|
+
* @param rows - Cells down.
|
|
75
|
+
* @param cell - The cell's side in pixels of the view.
|
|
76
|
+
* @param view - The map's view.
|
|
77
|
+
* @param sun - Where the Sun is overhead.
|
|
78
|
+
* @param body - `moon` or `mars`: the night's colour and the twilight's width.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { shadeNight } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
83
|
+
*
|
|
84
|
+
* const view = { width: 8, height: 4, centerLon: 0, centerLat: 0, zoom: 1 };
|
|
85
|
+
* const grid = new Uint8ClampedArray(8 * 4 * 4);
|
|
86
|
+
* shadeNight(grid, 8, 4, 1, view, { lat: 0, lon: 0 }, "moon");
|
|
87
|
+
* console.log(grid[3 + 4 * 0] === 0, grid[3 + 4 * 7]! > 150);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export function shadeNight(out, columns, rows, cell, view, sun, body) {
|
|
91
|
+
const info = flatBody(body);
|
|
92
|
+
const k = pixelsPerDegree(view);
|
|
93
|
+
const sinSun = Math.sin(sun.lat * RAD);
|
|
94
|
+
const cosSun = Math.cos(sun.lat * RAD);
|
|
95
|
+
const cosDelta = new Float64Array(columns);
|
|
96
|
+
for (let c = 0; c < columns; c += 1)
|
|
97
|
+
cosDelta[c] = Math.cos(wrapLongitude(view.centerLon + ((c + 0.5) * cell - view.width / 2) / k - sun.lon) * RAD);
|
|
98
|
+
const [r, g, b, top] = info.night;
|
|
99
|
+
const full = -info.twilightDeg;
|
|
100
|
+
const edge = info.twilightDeg / 4;
|
|
101
|
+
for (let row = 0; row < rows; row += 1) {
|
|
102
|
+
const lat = Math.max(-90, Math.min(90, view.centerLat - ((row + 0.5) * cell - view.height / 2) / k)) * RAD;
|
|
103
|
+
const sinLat = Math.sin(lat);
|
|
104
|
+
const cosLat = Math.cos(lat);
|
|
105
|
+
for (let c = 0; c < columns; c += 1) {
|
|
106
|
+
const elevation = Math.asin(Math.max(-1, Math.min(1, sinSun * sinLat + cosSun * cosLat * cosDelta[c]))) / RAD;
|
|
107
|
+
const at = (row * columns + c) * 4;
|
|
108
|
+
out[at] = r;
|
|
109
|
+
out[at + 1] = g;
|
|
110
|
+
out[at + 2] = b;
|
|
111
|
+
out[at + 3] = Math.round(255 * top * (1 - smooth(full, edge, elevation)));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The outline of the circle on a body's surface that a craft can see: every point `angleDeg` from the point under it, as longitude and latitude with the longitude carried on without a jump (so it can run past 180 and the map draws
|
|
117
|
+
* the circle again a world to the left and right). The outline's last point is its first again; where the circle holds a pole, `pole` is `1` or `-1` and the last point is a whole turn of longitude from the first.
|
|
118
|
+
*
|
|
119
|
+
* @param lat - Latitude of the centre.
|
|
120
|
+
* @param lon - Longitude of the centre.
|
|
121
|
+
* @param angleDeg - The circle's angular radius at the body's centre, in degrees (`coverageAngleRad` in degrees).
|
|
122
|
+
* @param steps - How many steps round it (there are `steps + 1` points, the last being the first again).
|
|
123
|
+
* @returns The points, and whether a pole is inside.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { circleOutline } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
128
|
+
*
|
|
129
|
+
* const ring = circleOutline(80, 10, 15);
|
|
130
|
+
* console.log(ring.pole, ring.points.length);
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export function circleOutline(lat, lon, angleDeg, steps = 72) {
|
|
134
|
+
const theta = Math.min(180, Math.max(0, angleDeg)) * RAD;
|
|
135
|
+
const lat0 = lat * RAD;
|
|
136
|
+
const points = [];
|
|
137
|
+
let previous = lon;
|
|
138
|
+
for (let i = 0; i <= steps; i += 1) {
|
|
139
|
+
const bearing = (2 * Math.PI * i) / steps;
|
|
140
|
+
const phi = Math.asin(Math.max(-1, Math.min(1, Math.sin(lat0) * Math.cos(theta) + Math.cos(lat0) * Math.sin(theta) * Math.cos(bearing))));
|
|
141
|
+
const delta = Math.atan2(Math.sin(bearing) * Math.sin(theta) * Math.cos(lat0), Math.cos(theta) - Math.sin(lat0) * Math.sin(phi)) / RAD;
|
|
142
|
+
let next = lon + delta;
|
|
143
|
+
while (next - previous > 180)
|
|
144
|
+
next -= 360;
|
|
145
|
+
while (next - previous < -180)
|
|
146
|
+
next += 360;
|
|
147
|
+
previous = next;
|
|
148
|
+
points.push([next, phi / RAD]);
|
|
149
|
+
}
|
|
150
|
+
// a circle that holds a pole runs once round the whole of longitude
|
|
151
|
+
const pole = Math.abs(lat) + angleDeg > 90 ? (lat >= 0 ? 1 : -1) : 0;
|
|
152
|
+
return { points, pole };
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* An orbiter's ground track for one trip round: half behind it and half ahead, as points with their moments. The package's own `orbiterGroundTrack`, over one period centred on the moment.
|
|
156
|
+
*
|
|
157
|
+
* @param id - The orbiter.
|
|
158
|
+
* @param ms - Milliseconds since 1970 (UTC): the moment the orbiter is at the track's middle.
|
|
159
|
+
* @param points - How many steps round the trip.
|
|
160
|
+
* @returns The points with their longitude in -180 up to 180, or an empty list for a craft with no path.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* import { flatTrack } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
165
|
+
*
|
|
166
|
+
* const track = flatTrack("lro", Date.UTC(2026, 10, 12), 40);
|
|
167
|
+
* console.log(track.length, track.filter((p) => p.ms <= Date.UTC(2026, 10, 12)).length);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export function flatTrack(id, ms, points = 160) {
|
|
171
|
+
const days = orbiterElements(id)?.periodDays;
|
|
172
|
+
if (days === undefined)
|
|
173
|
+
return [];
|
|
174
|
+
const half = (days * 86_400_000) / 2;
|
|
175
|
+
return orbiterGroundTrack(id, ms - half, ms + half, points).map((p) => ({ lat: p.lat, lon: wrapLongitude(p.lon), ms: p.ms }));
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* A run of ground points cut into the straight pieces a flat map can draw: each step is split where it crosses the date line or runs over a pole, so no line crosses the whole map.
|
|
179
|
+
*
|
|
180
|
+
* @param points - Points in order, longitude in -180 up to 180.
|
|
181
|
+
* @returns Pieces, each from one point to the next, longitudes within -180 and 180.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* import { trackPieces } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
186
|
+
*
|
|
187
|
+
* console.log(trackPieces([{ lat: 0, lon: 170 }, { lat: 5, lon: -170 }]).length);
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export function trackPieces(points) {
|
|
191
|
+
const out = [];
|
|
192
|
+
for (let i = 1; i < points.length; i += 1)
|
|
193
|
+
out.push(...splitTrail(points[i - 1], points[i]));
|
|
194
|
+
return out;
|
|
195
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two languages the flat map's words come in.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { FLAT_WORDS, type FlatLang } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
7
|
+
*
|
|
8
|
+
* const lang: FlatLang = "ja";
|
|
9
|
+
* console.log(FLAT_WORDS[lang].zoomIn);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export type FlatLang = "en" | "ja";
|
|
13
|
+
/**
|
|
14
|
+
* The words the flat map writes, one table for each language: `{body}`, `{name}`, `{altitude}` and the like are filled in. The Japanese is standard, polite Japanese.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { FLAT_WORDS } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
19
|
+
*
|
|
20
|
+
* console.log(FLAT_WORDS.en.footprint, FLAT_WORDS.ja.footprint);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const FLAT_WORDS: Readonly<Record<FlatLang, Readonly<Record<string, string>>>>;
|
|
24
|
+
/**
|
|
25
|
+
* The words with their `{name}` places filled in; a key a language does not have is said in English, and a key neither has comes back as it is.
|
|
26
|
+
*
|
|
27
|
+
* @param lang - `en` or `ja`.
|
|
28
|
+
* @param key - A key of `FLAT_WORDS`.
|
|
29
|
+
* @param values - What goes in the `{...}` places.
|
|
30
|
+
* @returns The sentence.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { say } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
35
|
+
*
|
|
36
|
+
* console.log(say("en", "map", { body: "Mars" }), "|", say("ja", "map", { body: "火星" }));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const say: (lang: FlatLang, key: string, values?: Record<string, string | number>) => string;
|
|
40
|
+
/**
|
|
41
|
+
* A latitude or longitude with its hemisphere, in the language's way: `3.01° S` and `23.47° E`, or `南緯3.01°` and `東経23.47°`.
|
|
42
|
+
*
|
|
43
|
+
* @param lang - `en` or `ja`.
|
|
44
|
+
* @param axis - `lat` or `lon`.
|
|
45
|
+
* @param degrees - Degrees, north and east positive.
|
|
46
|
+
* @returns The text.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { coordinateText } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
51
|
+
*
|
|
52
|
+
* console.log(coordinateText("en", "lat", -3.01), "|", coordinateText("ja", "lon", 23.47));
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function coordinateText(lang: FlatLang, axis: "lat" | "lon", degrees: number): string;
|