@johnmorrisdotca/wakusei-planets 0.61.0 → 0.63.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 +17 -0
- package/README.md +3 -3
- package/dist/belts/filter.d.ts +128 -0
- package/dist/belts/filter.js +117 -0
- package/dist/belts/index.d.ts +2 -0
- package/dist/belts/index.js +1 -0
- package/dist/fact-sheets.d.ts +103 -0
- package/dist/fact-sheets.js +135 -0
- package/dist/flat/index.d.ts +1 -0
- package/dist/flat/index.js +1 -0
- package/dist/flat/projections.d.ts +300 -0
- package/dist/flat/projections.js +414 -0
- package/dist/landing-sites.js +6 -6
- package/dist/sky/events.d.ts +2 -0
- package/dist/sky/events.js +3 -2
- package/dist/suncalc-legacy.d.ts +21 -0
- package/dist/suncalc-legacy.js +13 -0
- package/dist/suncalc.d.ts +21 -0
- package/dist/suncalc.js +23 -8
- package/dist/surface/drive.d.ts +4 -3
- package/dist/surface/drive.js +6 -5
- package/dist/surface/dust.d.ts +2 -1
- package/dist/surface/dust.js +3 -2
- package/dist/surface/element.d.ts +3 -3
- package/dist/surface/element.js +31 -13
- package/dist/surface/flat.d.ts +34 -0
- package/dist/surface/flat.js +63 -0
- package/dist/surface/glsl.d.ts +6 -3
- package/dist/surface/glsl.js +35 -2
- package/dist/surface/height.d.ts +1 -1
- package/dist/surface/index.d.ts +3 -2
- package/dist/surface/index.js +3 -2
- package/dist/surface/land.d.ts +7 -5
- package/dist/surface/land.js +10 -8
- package/dist/surface/scene.d.ts +6 -2
- package/dist/surface/scene.js +41 -4
- package/dist/surface/site.d.ts +32 -3
- package/dist/surface/site.js +99 -2
- package/dist/surface/sky.d.ts +92 -1
- package/dist/surface/sky.js +78 -4
- package/package.json +6 -1
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
// Map projections for the painted maps: the sphere of any body flattened five ways, with the graticule, the outline and the Sun's mark, and a resampler that turns the body's own equirectangular picture into the projected one.
|
|
2
|
+
// Pure: numbers and pixel arrays in, numbers and pixel arrays out. No DOM, no clock reads, no dependency. Every map here is on the unit sphere: x grows east, y grows north, in radii.
|
|
3
|
+
import { subSolarPoint } from "../places.js";
|
|
4
|
+
import { wrapLongitude } from "./geometry.js";
|
|
5
|
+
const RAD = Math.PI / 180;
|
|
6
|
+
const HALF_PI = Math.PI / 2;
|
|
7
|
+
/**
|
|
8
|
+
* The projections: `equirectangular` (the picture as drawn, a degree is a degree both ways), `mercator` (round, angles kept true; it stops at 85.05 degrees because the poles are at infinity), `sinusoidal` (equal area, the parallels keep their true length, the shape is a leaf), `mollweide` (equal area, an ellipse twice as wide as tall) and `azimuthal` (equidistant: the whole sphere as a disc about a chosen point, distances from that point true; the opposite point is the rim).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { PROJECTIONS } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
13
|
+
*
|
|
14
|
+
* console.log(PROJECTIONS.join(", "));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const PROJECTIONS = ["equirectangular", "mercator", "sinusoidal", "mollweide", "azimuthal"];
|
|
18
|
+
/**
|
|
19
|
+
* The furthest north or south the Mercator map goes, in degrees: where it becomes a square.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { MERCATOR_LIMIT } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
24
|
+
*
|
|
25
|
+
* console.log(MERCATOR_LIMIT.toFixed(5));
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export const MERCATOR_LIMIT = (2 * Math.atan(Math.exp(Math.PI)) - HALF_PI) / RAD;
|
|
29
|
+
const NO_CENTRE = { lon: 0, lat: 0 };
|
|
30
|
+
const finite = (n, fallback = 0) => (Number.isFinite(n) ? n : fallback);
|
|
31
|
+
/**
|
|
32
|
+
* Whether a name is one of the projections.
|
|
33
|
+
*
|
|
34
|
+
* @param value - Any value.
|
|
35
|
+
* @returns True for a name in `PROJECTIONS`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { isProjection } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
40
|
+
*
|
|
41
|
+
* console.log(isProjection("mollweide"), isProjection("robinson"));
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export const isProjection = (value) => typeof value === "string" && PROJECTIONS.includes(value);
|
|
45
|
+
/**
|
|
46
|
+
* How far the map reaches from its middle, in radii: the half width and half height of the box that holds it.
|
|
47
|
+
*
|
|
48
|
+
* @param id - The projection.
|
|
49
|
+
* @returns `halfWidth` and `halfHeight`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { mapExtent } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
54
|
+
*
|
|
55
|
+
* console.log(mapExtent("mollweide"), mapExtent("azimuthal"));
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function mapExtent(id) {
|
|
59
|
+
switch (id) {
|
|
60
|
+
case "equirectangular":
|
|
61
|
+
return { halfWidth: Math.PI, halfHeight: HALF_PI };
|
|
62
|
+
case "mercator":
|
|
63
|
+
return { halfWidth: Math.PI, halfHeight: Math.PI };
|
|
64
|
+
case "sinusoidal":
|
|
65
|
+
return { halfWidth: Math.PI, halfHeight: HALF_PI };
|
|
66
|
+
case "mollweide":
|
|
67
|
+
return { halfWidth: 2 * Math.SQRT2, halfHeight: Math.SQRT2 };
|
|
68
|
+
case "azimuthal":
|
|
69
|
+
return { halfWidth: Math.PI, halfHeight: Math.PI };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Mollweide's auxiliary angle: 2t + sin 2t = pi sin(lat), by Newton's method, with the poles set apart (the slope is zero there). */
|
|
73
|
+
function mollweideAngle(lat) {
|
|
74
|
+
if (Math.abs(lat) >= HALF_PI - 1e-9)
|
|
75
|
+
return Math.sign(lat) * HALF_PI;
|
|
76
|
+
const target = Math.PI * Math.sin(lat);
|
|
77
|
+
let t = lat;
|
|
78
|
+
for (let i = 0; i < 50; i += 1) {
|
|
79
|
+
const slope = 2 + 2 * Math.cos(2 * t);
|
|
80
|
+
if (slope < 1e-12)
|
|
81
|
+
break;
|
|
82
|
+
const step = (2 * t + Math.sin(2 * t) - target) / slope;
|
|
83
|
+
t -= step;
|
|
84
|
+
if (Math.abs(step) < 1e-14)
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
return Math.max(-HALF_PI, Math.min(HALF_PI, t));
|
|
88
|
+
}
|
|
89
|
+
/** A place by its longitude from the middle (`dlon`, radians, not wrapped) and latitude (radians) on the four maps that keep the equator across the middle. */
|
|
90
|
+
function across(id, dlon, lat) {
|
|
91
|
+
switch (id) {
|
|
92
|
+
case "equirectangular":
|
|
93
|
+
return { x: dlon, y: lat };
|
|
94
|
+
case "mercator": {
|
|
95
|
+
const limit = MERCATOR_LIMIT * RAD;
|
|
96
|
+
const clamped = Math.max(-limit, Math.min(limit, lat));
|
|
97
|
+
return { x: dlon, y: Math.atanh(Math.sin(clamped)) };
|
|
98
|
+
}
|
|
99
|
+
case "sinusoidal":
|
|
100
|
+
return { x: dlon * Math.cos(lat), y: lat };
|
|
101
|
+
case "mollweide": {
|
|
102
|
+
const t = mollweideAngle(lat);
|
|
103
|
+
return { x: ((2 * Math.SQRT2) / Math.PI) * dlon * Math.cos(t), y: Math.SQRT2 * Math.sin(t) };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** The azimuthal equidistant map about a centre: the angular distance and the bearing round to a point of the disc. At the opposite point the bearing is undefined, so it is the bottom of the rim. */
|
|
108
|
+
function disc(dlon, lat, centreLat) {
|
|
109
|
+
const cosC = Math.max(-1, Math.min(1, Math.sin(centreLat) * Math.sin(lat) + Math.cos(centreLat) * Math.cos(lat) * Math.cos(dlon)));
|
|
110
|
+
const c = Math.acos(cosC);
|
|
111
|
+
const sinC = Math.sin(c);
|
|
112
|
+
if (sinC < 1e-12)
|
|
113
|
+
return c < 1 ? { x: 0, y: 0 } : { x: 0, y: -Math.PI };
|
|
114
|
+
const k = c / sinC;
|
|
115
|
+
return { x: k * Math.cos(lat) * Math.sin(dlon), y: k * (Math.cos(centreLat) * Math.sin(lat) - Math.sin(centreLat) * Math.cos(lat) * Math.cos(dlon)) };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Where a longitude and latitude fall on the map, in radii from its middle (x east, y north). Longitude is taken the short way round from the centre, so a place on the far side of the picture's seam lands at the right edge. Mercator holds a latitude beyond 85.05 degrees at 85.05, so a pole is a place on the top edge, never infinity.
|
|
119
|
+
*
|
|
120
|
+
* @param id - The projection.
|
|
121
|
+
* @param lon - Degrees east.
|
|
122
|
+
* @param lat - Degrees north.
|
|
123
|
+
* @param centre - The point in the middle; the Greenwich-like prime meridian on the equator when left out.
|
|
124
|
+
* @returns `x` and `y`.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { projectMap } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
129
|
+
*
|
|
130
|
+
* console.log(projectMap("mollweide", 90, 45), projectMap("azimuthal", 0, 90, { lon: 0, lat: 90 }));
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export function projectMap(id, lon, lat, centre = NO_CENTRE) {
|
|
134
|
+
const dlon = wrapLongitude(finite(lon) - finite(centre.lon)) * RAD;
|
|
135
|
+
const phi = Math.max(-90, Math.min(90, finite(lat))) * RAD;
|
|
136
|
+
return id === "azimuthal" ? disc(dlon, phi, Math.max(-90, Math.min(90, finite(centre.lat))) * RAD) : across(id, dlon, phi);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The longitude and latitude at a point of the map: the opposite of `projectMap`.
|
|
140
|
+
*
|
|
141
|
+
* @param id - The projection.
|
|
142
|
+
* @param x - Radii east of the middle.
|
|
143
|
+
* @param y - Radii north of the middle.
|
|
144
|
+
* @param centre - The point in the middle.
|
|
145
|
+
* @returns `lon` in -180 up to 180 and `lat`, or `null` when the point is outside the map's shape (beyond the leaf, the ellipse or the disc).
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* import { unprojectMap } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
150
|
+
*
|
|
151
|
+
* console.log(unprojectMap("sinusoidal", 0, 0), unprojectMap("mollweide", 2.8, 1.4));
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export function unprojectMap(id, x, y, centre = NO_CENTRE) {
|
|
155
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
156
|
+
return null;
|
|
157
|
+
const lon0 = finite(centre.lon);
|
|
158
|
+
const done = (dlon, lat) => (Math.abs(dlon) > Math.PI + 1e-9 ? null : { lon: wrapLongitude(lon0 + dlon / RAD), lat: lat / RAD });
|
|
159
|
+
switch (id) {
|
|
160
|
+
case "equirectangular":
|
|
161
|
+
return Math.abs(y) > HALF_PI ? null : done(x, y);
|
|
162
|
+
case "mercator":
|
|
163
|
+
return Math.abs(y) > Math.PI ? null : done(x, 2 * Math.atan(Math.exp(y)) - HALF_PI);
|
|
164
|
+
case "sinusoidal": {
|
|
165
|
+
if (Math.abs(y) > HALF_PI)
|
|
166
|
+
return null;
|
|
167
|
+
const cos = Math.cos(y);
|
|
168
|
+
if (cos < 1e-12)
|
|
169
|
+
return Math.abs(x) < 1e-9 ? done(0, y) : null;
|
|
170
|
+
return done(x / cos, y);
|
|
171
|
+
}
|
|
172
|
+
case "mollweide": {
|
|
173
|
+
if (Math.abs(y) > Math.SQRT2)
|
|
174
|
+
return null;
|
|
175
|
+
const t = Math.asin(Math.max(-1, Math.min(1, y / Math.SQRT2)));
|
|
176
|
+
const lat = Math.asin(Math.max(-1, Math.min(1, (2 * t + Math.sin(2 * t)) / Math.PI)));
|
|
177
|
+
const cos = Math.cos(t);
|
|
178
|
+
if (cos < 1e-12)
|
|
179
|
+
return Math.abs(x) < 1e-9 ? done(0, lat) : null;
|
|
180
|
+
return done((Math.PI * x) / (2 * Math.SQRT2 * cos), lat);
|
|
181
|
+
}
|
|
182
|
+
case "azimuthal": {
|
|
183
|
+
const rho = Math.hypot(x, y);
|
|
184
|
+
if (rho > Math.PI)
|
|
185
|
+
return null;
|
|
186
|
+
const lat0 = Math.max(-90, Math.min(90, finite(centre.lat))) * RAD;
|
|
187
|
+
if (rho < 1e-12)
|
|
188
|
+
return { lon: wrapLongitude(lon0), lat: lat0 / RAD };
|
|
189
|
+
const sinC = Math.sin(rho);
|
|
190
|
+
const cosC = Math.cos(rho);
|
|
191
|
+
const lat = Math.asin(Math.max(-1, Math.min(1, cosC * Math.sin(lat0) + (y * sinC * Math.cos(lat0)) / rho)));
|
|
192
|
+
const dlon = Math.atan2(x * sinC, rho * Math.cos(lat0) * cosC - y * Math.sin(lat0) * sinC);
|
|
193
|
+
return { lon: wrapLongitude(lon0 + dlon / RAD), lat: lat / RAD };
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The lines of longitude and latitude at every `step` degrees, as polylines on the map. The four maps keep a line whole from edge to edge (a meridian on the picture's seam is drawn on both edges); on the azimuthal disc a line is cut where it crosses the rim, so nothing is drawn across the map. The poles on Mercator, where they are at infinity, are not drawn as parallels, and the meridians stop at 85.05 degrees. A parallel at a pole is a point on the sinusoidal and Mollweide maps and is left out.
|
|
199
|
+
*
|
|
200
|
+
* @param id - The projection.
|
|
201
|
+
* @param step - Degrees between lines, 5 to 90 (30 when left out).
|
|
202
|
+
* @param centre - The point in the middle.
|
|
203
|
+
* @returns The lines, the equator and the prime meridian among them.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* import { graticule } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
208
|
+
*
|
|
209
|
+
* const lines = graticule("mollweide", 30);
|
|
210
|
+
* console.log(lines.filter((l) => l.kind === "meridian").length, lines.filter((l) => l.kind === "parallel").length);
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export function graticule(id, step = 30, centre = NO_CENTRE) {
|
|
214
|
+
const every = Math.min(90, Math.max(5, finite(step, 30)));
|
|
215
|
+
const lon0 = finite(centre.lon);
|
|
216
|
+
const lat0 = finite(centre.lat);
|
|
217
|
+
const out = [];
|
|
218
|
+
const sample = 1;
|
|
219
|
+
const latLimit = id === "mercator" ? MERCATOR_LIMIT : 90;
|
|
220
|
+
const cut = (points) => {
|
|
221
|
+
const pieces = [];
|
|
222
|
+
let piece = [];
|
|
223
|
+
let last = null;
|
|
224
|
+
for (const point of points) {
|
|
225
|
+
// a jump of more than a quarter radius between one-degree samples is the rim of the disc, not a line
|
|
226
|
+
if (last !== null && Math.hypot(point.x - last.x, point.y - last.y) > 0.25) {
|
|
227
|
+
if (piece.length > 1)
|
|
228
|
+
pieces.push(piece);
|
|
229
|
+
piece = [];
|
|
230
|
+
}
|
|
231
|
+
piece.push(point);
|
|
232
|
+
last = point;
|
|
233
|
+
}
|
|
234
|
+
if (piece.length > 1)
|
|
235
|
+
pieces.push(piece);
|
|
236
|
+
return pieces;
|
|
237
|
+
};
|
|
238
|
+
// meridians: every multiple of the step across the 360 degrees from the left edge to the right edge of the map
|
|
239
|
+
const first = Math.ceil((lon0 - 180) / every) * every;
|
|
240
|
+
for (let lon = first; lon <= lon0 + 180 + 1e-9; lon += every) {
|
|
241
|
+
const points = [];
|
|
242
|
+
for (let lat = -latLimit; lat <= latLimit + 1e-9; lat += sample) {
|
|
243
|
+
const phi = Math.min(latLimit, lat) * RAD;
|
|
244
|
+
points.push(id === "azimuthal" ? disc(wrapLongitude(lon - lon0) * RAD, phi, lat0 * RAD) : across(id, (lon - lon0) * RAD, phi));
|
|
245
|
+
}
|
|
246
|
+
out.push({ kind: "meridian", value: wrapLongitude(lon), lines: cut(points) });
|
|
247
|
+
}
|
|
248
|
+
// parallels: the equator and every multiple of the step out from it, short of the poles (a point on two of the maps, at infinity on the third)
|
|
249
|
+
const parallel = (lat) => {
|
|
250
|
+
const points = [];
|
|
251
|
+
for (let lon = lon0 - 180; lon <= lon0 + 180 + 1e-9; lon += sample)
|
|
252
|
+
points.push(id === "azimuthal" ? disc(wrapLongitude(lon - lon0) * RAD, lat * RAD, lat0 * RAD) : across(id, (lon - lon0) * RAD, lat * RAD));
|
|
253
|
+
out.push({ kind: "parallel", value: lat, lines: cut(points) });
|
|
254
|
+
};
|
|
255
|
+
parallel(0);
|
|
256
|
+
for (let lat = every; lat < Math.min(90, latLimit) - 1e-9; lat += every) {
|
|
257
|
+
parallel(lat);
|
|
258
|
+
parallel(-lat);
|
|
259
|
+
}
|
|
260
|
+
return out;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* The edge of the map as one closed line, for a frame: the rectangle, the square, the leaf, the ellipse or the disc.
|
|
264
|
+
*
|
|
265
|
+
* @param id - The projection.
|
|
266
|
+
* @returns The points, the first repeated at the end.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* import { mapOutline } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
271
|
+
*
|
|
272
|
+
* console.log(mapOutline("sinusoidal").length > 100);
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
export function mapOutline(id) {
|
|
276
|
+
if (id === "azimuthal") {
|
|
277
|
+
const ring = [];
|
|
278
|
+
for (let a = 0; a < 360; a += 2)
|
|
279
|
+
ring.push({ x: Math.PI * Math.sin(a * RAD), y: Math.PI * Math.cos(a * RAD) });
|
|
280
|
+
ring.push({ ...ring[0] });
|
|
281
|
+
return ring;
|
|
282
|
+
}
|
|
283
|
+
if (id === "equirectangular" || id === "mercator") {
|
|
284
|
+
const { halfWidth, halfHeight } = mapExtent(id);
|
|
285
|
+
return [
|
|
286
|
+
{ x: -halfWidth, y: halfHeight },
|
|
287
|
+
{ x: halfWidth, y: halfHeight },
|
|
288
|
+
{ x: halfWidth, y: -halfHeight },
|
|
289
|
+
{ x: -halfWidth, y: -halfHeight },
|
|
290
|
+
{ x: -halfWidth, y: halfHeight },
|
|
291
|
+
];
|
|
292
|
+
}
|
|
293
|
+
// the leaf and the ellipse: down the east edge, then up the west
|
|
294
|
+
const points = [];
|
|
295
|
+
for (let lat = 90; lat >= -90; lat -= 1)
|
|
296
|
+
points.push(across(id, Math.PI, lat * RAD));
|
|
297
|
+
for (let lat = -90; lat <= 90; lat += 1)
|
|
298
|
+
points.push(across(id, -Math.PI, lat * RAD));
|
|
299
|
+
points.push({ ...points[0] });
|
|
300
|
+
return points;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Fit a projection into a box so the whole map shows, with a margin of a few pixels.
|
|
304
|
+
*
|
|
305
|
+
* @param id - The projection.
|
|
306
|
+
* @param width - Box width in pixels.
|
|
307
|
+
* @param height - Box height in pixels.
|
|
308
|
+
* @param zoom - 1 or more; the map is held to its middle.
|
|
309
|
+
* @returns The scale and the middle.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* import { fitMap } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
314
|
+
*
|
|
315
|
+
* console.log(fitMap("mollweide", 800, 400));
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
export function fitMap(id, width, height, zoom = 1) {
|
|
319
|
+
const { halfWidth, halfHeight } = mapExtent(id);
|
|
320
|
+
const room = 4;
|
|
321
|
+
const scale = Math.max(0, Math.min((width - 2 * room) / (2 * halfWidth), (height - 2 * room) / (2 * halfHeight))) * Math.max(1, finite(zoom, 1));
|
|
322
|
+
return { scale, cx: width / 2, cy: height / 2 };
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* A point of the map in pixels of the box (y grows down).
|
|
326
|
+
*
|
|
327
|
+
* @param fit - From `fitMap`.
|
|
328
|
+
* @param point - A point in radii.
|
|
329
|
+
* @returns `x` and `y` in pixels.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```ts
|
|
333
|
+
* import { fitMap, mapPixels, projectMap } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
334
|
+
*
|
|
335
|
+
* console.log(mapPixels(fitMap("mercator", 400, 400), projectMap("mercator", 10, 20)));
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
export const mapPixels = (fit, point) => ({ x: fit.cx + point.x * fit.scale, y: fit.cy - point.y * fit.scale });
|
|
339
|
+
/**
|
|
340
|
+
* Where the Sun is overhead on a body, as a point of the map: the sub-solar point worked from the body's pole and spin and put through the projection. On a map that does not show that side of the body (the azimuthal disc shows all of it) the point is still found; the mark is on the picture whenever it can be.
|
|
341
|
+
*
|
|
342
|
+
* @param id - The projection.
|
|
343
|
+
* @param body - A body with a pole and spin (a planet, dwarf planet or moon; the Sun has none).
|
|
344
|
+
* @param ms - Milliseconds since 1970 (UTC).
|
|
345
|
+
* @param centre - The point in the middle.
|
|
346
|
+
* @returns The point on the map in radii, and the place on the body.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* import { mapSun } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
351
|
+
*
|
|
352
|
+
* const sun = mapSun("equirectangular", "moon", Date.UTC(1969, 6, 20, 20, 17, 40));
|
|
353
|
+
* console.log(sun.lat.toFixed(0), sun.lon.toFixed(0));
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
export function mapSun(id, body, ms, centre = NO_CENTRE) {
|
|
357
|
+
const sun = subSolarPoint(body, ms);
|
|
358
|
+
const lon = wrapLongitude(sun.lon);
|
|
359
|
+
return { ...projectMap(id, lon, sun.lat, centre), lon, lat: sun.lat };
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Turn a body's painted map (an equirectangular picture, the whole body from -180 to 180 east and 90 to -90 north) into the same body in another projection: for every pixel of the answer the place on the body it shows is found with `unprojectMap` and the colour is read from the picture, smoothly between its pixels, wrapping across the seam and holding at the poles. Pixels outside the map's shape are transparent.
|
|
363
|
+
*
|
|
364
|
+
* @param source - The painted map.
|
|
365
|
+
* @param id - The projection.
|
|
366
|
+
* @param width - Answer width in pixels.
|
|
367
|
+
* @param height - Answer height in pixels.
|
|
368
|
+
* @param options - `centre` (the middle) and `zoom` (1 fits the whole map).
|
|
369
|
+
* @returns RGBA bytes, `width` by `height`.
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```ts
|
|
373
|
+
* import { resampleMap } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
374
|
+
*
|
|
375
|
+
* const grey = { width: 2, height: 1, data: [0, 0, 0, 255, 255, 255, 255, 255] };
|
|
376
|
+
* const out = resampleMap(grey, "equirectangular", 4, 2);
|
|
377
|
+
* console.log(out.length);
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
export function resampleMap(source, id, width, height, options = {}) {
|
|
381
|
+
const w = Math.max(0, Math.floor(width));
|
|
382
|
+
const h = Math.max(0, Math.floor(height));
|
|
383
|
+
const out = new Uint8ClampedArray(w * h * 4);
|
|
384
|
+
if (source.width < 1 || source.height < 1 || w === 0 || h === 0)
|
|
385
|
+
return out;
|
|
386
|
+
const centre = options.centre ?? NO_CENTRE;
|
|
387
|
+
const fit = fitMap(id, w, h, options.zoom);
|
|
388
|
+
const { width: sw, height: sh, data } = source;
|
|
389
|
+
for (let py = 0; py < h; py += 1) {
|
|
390
|
+
for (let px = 0; px < w; px += 1) {
|
|
391
|
+
const at = unprojectMap(id, (px + 0.5 - fit.cx) / fit.scale, (fit.cy - (py + 0.5)) / fit.scale, centre);
|
|
392
|
+
if (at === null)
|
|
393
|
+
continue;
|
|
394
|
+
// the picture's pixel centres are at (i + 0.5) / size of the way across; longitude wraps, latitude holds at the poles
|
|
395
|
+
const u = ((at.lon + 180) / 360) * sw - 0.5;
|
|
396
|
+
const v = Math.max(0, Math.min(sh - 1, ((90 - at.lat) / 180) * sh - 0.5));
|
|
397
|
+
const x0 = Math.floor(u);
|
|
398
|
+
const y0 = Math.floor(v);
|
|
399
|
+
const fx = u - x0;
|
|
400
|
+
const fy = v - y0;
|
|
401
|
+
const xa = ((x0 % sw) + sw) % sw;
|
|
402
|
+
const xb = (((x0 + 1) % sw) + sw) % sw;
|
|
403
|
+
const ya = y0;
|
|
404
|
+
const yb = Math.min(sh - 1, y0 + 1);
|
|
405
|
+
const o = (py * w + px) * 4;
|
|
406
|
+
for (let channel = 0; channel < 4; channel += 1) {
|
|
407
|
+
const top = data[(ya * sw + xa) * 4 + channel] * (1 - fx) + data[(ya * sw + xb) * 4 + channel] * fx;
|
|
408
|
+
const bottom = data[(yb * sw + xa) * 4 + channel] * (1 - fx) + data[(yb * sw + xb) * 4 + channel] * fx;
|
|
409
|
+
out[o + channel] = top * (1 - fy) + bottom * fy;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return out;
|
|
414
|
+
}
|
package/dist/landing-sites.js
CHANGED
|
@@ -107,7 +107,7 @@ export const LANDING_SITES = [
|
|
|
107
107
|
id: "moon/apollo-15", place: "moon/apollo-15-lunar-module", body: "moon", name: { en: "Apollo 15", ja: "アポロ15号" },
|
|
108
108
|
alsoAt: ["moon/apollo-15-lunar-rover"],
|
|
109
109
|
date: "1971-07-30T22:16Z", lat: 26.1324, lon: 3.6333, agency: AGENCY.NASA,
|
|
110
|
-
country: "US",
|
|
110
|
+
country: "US", stand: "apollo-15",
|
|
111
111
|
source: SRC_NASA_MOON, page: `${NSS}1971-063C`,
|
|
112
112
|
},
|
|
113
113
|
{
|
|
@@ -120,7 +120,7 @@ export const LANDING_SITES = [
|
|
|
120
120
|
id: "moon/apollo-16", place: "moon/apollo-16-lunar-module", body: "moon", name: { en: "Apollo 16", ja: "アポロ16号" },
|
|
121
121
|
alsoAt: ["moon/apollo-16-lunar-rover"],
|
|
122
122
|
date: "1972-04-21T02:23Z", lat: -8.9734, lon: 15.5011, agency: AGENCY.NASA,
|
|
123
|
-
country: "US",
|
|
123
|
+
country: "US", stand: "apollo-16",
|
|
124
124
|
source: SRC_NASA_MOON, page: `${NSS}1972-031C`,
|
|
125
125
|
},
|
|
126
126
|
{
|
|
@@ -152,14 +152,14 @@ export const LANDING_SITES = [
|
|
|
152
152
|
id: "moon/chang-e-3", place: "moon/chang-e-3", body: "moon", name: { en: "Chang'e 3", ja: "嫦娥3号" },
|
|
153
153
|
alsoAt: ["moon/yutu"],
|
|
154
154
|
date: "2013-12-14T13:11Z", lat: 44.1214, lon: -19.5117, agency: AGENCY.CNSA,
|
|
155
|
-
country: "CN",
|
|
155
|
+
country: "CN", stand: "chang-e-3",
|
|
156
156
|
source: SRC_NASA_MOON,
|
|
157
157
|
},
|
|
158
158
|
{
|
|
159
159
|
id: "moon/chang-e-4", place: "moon/chang-e-4", body: "moon", name: { en: "Chang'e 4", ja: "嫦娥4号" },
|
|
160
160
|
alsoAt: ["moon/yutu-2"],
|
|
161
161
|
date: "2019-01-03T02:26Z", lat: -45.4561, lon: 177.5885, agency: AGENCY.CNSA,
|
|
162
|
-
country: "CN",
|
|
162
|
+
country: "CN", stand: "chang-e-4",
|
|
163
163
|
source: SRC_NASA_MOON,
|
|
164
164
|
},
|
|
165
165
|
{
|
|
@@ -256,7 +256,7 @@ export const LANDING_SITES = [
|
|
|
256
256
|
id: "mars/curiosity", place: "mars/curiosity", body: "mars", name: { en: "Curiosity", ja: "キュリオシティ" },
|
|
257
257
|
alsoAt: ["mars/curiosity-s-descent-stage"],
|
|
258
258
|
date: "2012-08-06T05:17Z", lat: -4.5895, lon: 137.4417, agency: AGENCY.NASA,
|
|
259
|
-
country: "US",
|
|
259
|
+
country: "US", stand: "curiosity",
|
|
260
260
|
source: SRC_GCAT, checkedAgainst: SRC_ODE, page: `${NSS}2011-070A`,
|
|
261
261
|
},
|
|
262
262
|
{
|
|
@@ -269,7 +269,7 @@ export const LANDING_SITES = [
|
|
|
269
269
|
id: "mars/perseverance", place: "mars/perseverance", body: "mars", name: { en: "Perseverance", ja: "パーシビアランス" },
|
|
270
270
|
alsoAt: ["mars/perseverance-s-descent-stage"],
|
|
271
271
|
date: "2021-02-18T20:43Z", lat: 18.4446, lon: 77.4508, agency: AGENCY.NASA,
|
|
272
|
-
country: "US",
|
|
272
|
+
country: "US", stand: "perseverance",
|
|
273
273
|
source: SRC_GCAT, checkedAgainst: SRC_MARS24, page: `${NSS}2020-052A`,
|
|
274
274
|
},
|
|
275
275
|
{
|
package/dist/sky/events.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface SunDay {
|
|
|
20
20
|
events: Map<string, number | null>;
|
|
21
21
|
alwaysUp: boolean;
|
|
22
22
|
alwaysDown: boolean;
|
|
23
|
+
/** Whether the Sun at solar noon is above the sunrise height: suncalc's rule for which flag to set when `sunrise` is null. */
|
|
24
|
+
noonHigh: boolean;
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* The Sun's day at a place: `utcOffset` in minutes east of UTC picks the local calendar day holding `ms`, and `undefined` the solar day (one solar midnight to the next).
|
package/dist/sky/events.js
CHANGED
|
@@ -112,8 +112,9 @@ export function sunDay(ms, observer, utcOffset, rows) {
|
|
|
112
112
|
const sunrise = events.get("sunrise");
|
|
113
113
|
const sunset = events.get("sunset");
|
|
114
114
|
const none = sunrise === null && sunset === null;
|
|
115
|
-
const
|
|
116
|
-
|
|
115
|
+
const noonHigh = altitude(noon) > -0.833 - dip(height);
|
|
116
|
+
const high = none && noonHigh;
|
|
117
|
+
return { noon, nadir, events, alwaysUp: high, alwaysDown: none && !high, noonHigh };
|
|
117
118
|
}
|
|
118
119
|
/** The Moon between two instants at a place: rise and set (the upper limb at the horizon through 34 arc-minutes of refraction), the upper and lower meridian crossings, and whether it stays up or down. */
|
|
119
120
|
export function moonDay(start, end, observer) {
|
package/dist/suncalc-legacy.d.ts
CHANGED
|
@@ -185,3 +185,24 @@ export declare function getTimes(date: Date | number, lat: number, lng: number,
|
|
|
185
185
|
* ```
|
|
186
186
|
*/
|
|
187
187
|
export declare function getMoonTimes(date: Date | number, lat: number, lng: number, inUTC?: boolean): LegacyMoonTimes;
|
|
188
|
+
/**
|
|
189
|
+
* Every function of this entry as one object, for code written `import SunCalc from "suncalc"` (or `const SunCalc = require("suncalc")`) against suncalc 1.x. `SunCalc.times` is the same array as the named `times`, so `addTime` reaches both.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* import SunCalc from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
194
|
+
*
|
|
195
|
+
* const t = SunCalc.getTimes(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
|
|
196
|
+
* console.log(t.sunrise instanceof Date);
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare const SunCalc: {
|
|
200
|
+
getPosition: typeof getPosition;
|
|
201
|
+
getTimes: typeof getTimes;
|
|
202
|
+
times: [number, string, string][];
|
|
203
|
+
addTime: typeof addTime;
|
|
204
|
+
getMoonPosition: typeof getMoonPosition;
|
|
205
|
+
getMoonIllumination: typeof getMoonIllumination;
|
|
206
|
+
getMoonTimes: typeof getMoonTimes;
|
|
207
|
+
};
|
|
208
|
+
export default SunCalc;
|
package/dist/suncalc-legacy.js
CHANGED
|
@@ -166,3 +166,16 @@ export function getMoonTimes(date, lat, lng, inUTC = false) {
|
|
|
166
166
|
result.alwaysDown = true;
|
|
167
167
|
return result;
|
|
168
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Every function of this entry as one object, for code written `import SunCalc from "suncalc"` (or `const SunCalc = require("suncalc")`) against suncalc 1.x. `SunCalc.times` is the same array as the named `times`, so `addTime` reaches both.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* import SunCalc from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
175
|
+
*
|
|
176
|
+
* const t = SunCalc.getTimes(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
|
|
177
|
+
* console.log(t.sunrise instanceof Date);
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
const SunCalc = { getPosition, getTimes, times, addTime, getMoonPosition, getMoonIllumination, getMoonTimes };
|
|
181
|
+
export default SunCalc;
|
package/dist/suncalc.d.ts
CHANGED
|
@@ -207,3 +207,24 @@ export declare function getTimes(date: Date | number, lat: number, lng: number,
|
|
|
207
207
|
* ```
|
|
208
208
|
*/
|
|
209
209
|
export declare function getMoonTimes(date: Date | number, lat: number, lng: number, utcOffset?: number): MoonTimes;
|
|
210
|
+
/**
|
|
211
|
+
* Every function of this entry as one object, for code written `import SunCalc from "suncalc"`. `SunCalc.times` is the same array as the named `times`, so `addTime` reaches both.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* import SunCalc from "@johnmorrisdotca/wakusei-planets/suncalc";
|
|
216
|
+
*
|
|
217
|
+
* const t = SunCalc.getTimes(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
|
|
218
|
+
* console.log(t.sunrise instanceof Date);
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
declare const SunCalc: {
|
|
222
|
+
getPosition: typeof getPosition;
|
|
223
|
+
getTimes: typeof getTimes;
|
|
224
|
+
times: [number, string, string][];
|
|
225
|
+
addTime: typeof addTime;
|
|
226
|
+
getMoonPosition: typeof getMoonPosition;
|
|
227
|
+
getMoonIllumination: typeof getMoonIllumination;
|
|
228
|
+
getMoonTimes: typeof getMoonTimes;
|
|
229
|
+
};
|
|
230
|
+
export default SunCalc;
|
package/dist/suncalc.js
CHANGED
|
@@ -122,10 +122,11 @@ export function getTimes(date, lat, lng, height = 0, utcOffset) {
|
|
|
122
122
|
const result = { solarNoon: new Date(day.noon), nadir: new Date(day.nadir) };
|
|
123
123
|
for (const [name, at] of day.events)
|
|
124
124
|
result[name] = at === null ? null : new Date(at);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
result.alwaysDown =
|
|
125
|
+
// suncalc's shape: when the Sun does not rise, both flags are there, one true and one false
|
|
126
|
+
if (result.sunrise === null) {
|
|
127
|
+
result.alwaysUp = day.noonHigh;
|
|
128
|
+
result.alwaysDown = !day.noonHigh;
|
|
129
|
+
}
|
|
129
130
|
return result;
|
|
130
131
|
}
|
|
131
132
|
/**
|
|
@@ -159,9 +160,23 @@ export function getMoonTimes(date, lat, lng, utcOffset) {
|
|
|
159
160
|
result.transit = new Date(day.transit);
|
|
160
161
|
if (day.lowerTransit !== null)
|
|
161
162
|
result.lowerTransit = new Date(day.lowerTransit);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
result.alwaysDown =
|
|
163
|
+
// suncalc's shape: on a day with no rise and no set both flags are there, one true and one false
|
|
164
|
+
if (day.rise === null && day.set === null) {
|
|
165
|
+
result.alwaysUp = day.alwaysUp;
|
|
166
|
+
result.alwaysDown = !day.alwaysUp;
|
|
167
|
+
}
|
|
166
168
|
return result;
|
|
167
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Every function of this entry as one object, for code written `import SunCalc from "suncalc"`. `SunCalc.times` is the same array as the named `times`, so `addTime` reaches both.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* import SunCalc from "@johnmorrisdotca/wakusei-planets/suncalc";
|
|
176
|
+
*
|
|
177
|
+
* const t = SunCalc.getTimes(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
|
|
178
|
+
* console.log(t.sunrise instanceof Date);
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
const SunCalc = { getPosition, getTimes, times, addTime, getMoonPosition, getMoonIllumination, getMoonTimes };
|
|
182
|
+
export default SunCalc;
|
package/dist/surface/drive.d.ts
CHANGED
|
@@ -101,8 +101,8 @@ export declare function startDrive(east: number, north: number, heading: number,
|
|
|
101
101
|
/** Where a point of the rover's frame is in the site's plane and height (before the wheels' own turns): the heading, then the pitch, then the roll. */
|
|
102
102
|
export declare function toWorld(state: Pick<DriveState, "east" | "north" | "heading" | "pitch" | "roll" | "y">, p: V3): V3;
|
|
103
103
|
/**
|
|
104
|
-
* One step of driving: the speed follows the throttle (slowed uphill by the
|
|
105
|
-
* back ones the other way), the rover moves, and its height, pitch and roll follow the four places its wheels touch, the height on a spring and in free fall (at
|
|
104
|
+
* One step of driving: the speed follows the throttle (slowed uphill by the body's gravity, stopped by a slope over 25 degrees and by anything in `blocked`), the heading follows the steering (the four wheels steer, the
|
|
105
|
+
* back ones the other way), the rover moves, and its height, pitch and roll follow the four places its wheels touch, the height on a spring and in free fall (at the body's gravity) when the ground drops away.
|
|
106
106
|
*
|
|
107
107
|
* @param state - The rover now.
|
|
108
108
|
* @param input - The throttle and the steering.
|
|
@@ -110,6 +110,7 @@ export declare function toWorld(state: Pick<DriveState, "east" | "north" | "head
|
|
|
110
110
|
* @param ground - The ground's height over the site's ground at a place.
|
|
111
111
|
* @param blocked - True at a place the rover cannot go (a big rock, the lunar module).
|
|
112
112
|
* @param rig - The vehicle's measures (its wheels' places and size); the lunar rover's by default, a model's from `rigOf`.
|
|
113
|
+
* @param gravity - The body's surface gravity in m/s2 (the Moon's 1.62 by default; Mars's is `MARS_GRAVITY`, 3.71): what slows it uphill and what it falls at.
|
|
113
114
|
* @returns The rover a moment later.
|
|
114
115
|
*
|
|
115
116
|
* @example
|
|
@@ -121,7 +122,7 @@ export declare function toWorld(state: Pick<DriveState, "east" | "north" | "head
|
|
|
121
122
|
* console.log(`${rover.north.toFixed(1)} m north after two seconds, at ${rover.speed.toFixed(1)} m/s`);
|
|
122
123
|
* ```
|
|
123
124
|
*/
|
|
124
|
-
export declare function driveStep(state: DriveState, input: DriveInput, dt: number, ground: (east: number, north: number) => number, blocked?: (east: number, north: number) => boolean, rig?: Rig): DriveState;
|
|
125
|
+
export declare function driveStep(state: DriveState, input: DriveInput, dt: number, ground: (east: number, north: number) => number, blocked?: (east: number, north: number) => boolean, rig?: Rig, gravity?: number): DriveState;
|
|
125
126
|
/**
|
|
126
127
|
* The rover's shape as it is now, turned and placed: the parts of `roverParts` with each wheel turned by how far it has rolled and steered (the back wheels the other way), then moved by the rover's heading, pitch, roll
|
|
127
128
|
* and place. Everything is in the site's plane (x east, y up, z north).
|