@johnmorrisdotca/wakusei-planets 0.62.0 → 0.64.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 +39 -1
- package/README.md +4 -3
- package/dist/asteroids.d.ts +15 -1
- package/dist/asteroids.js +28 -0
- package/dist/door/made.d.ts +4 -0
- package/dist/door/made.js +10 -0
- package/dist/door/own.d.ts +1 -4
- package/dist/door/own.js +1 -9
- package/dist/element.js +19 -22
- 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/scene/tumble.d.ts +13 -0
- package/dist/scene/tumble.js +34 -0
- package/dist/sky/events.d.ts +2 -0
- package/dist/sky/events.js +3 -2
- package/dist/sky.d.ts +561 -0
- package/dist/sky.js +522 -0
- package/dist/space/asteroid-ids.d.ts +8 -0
- package/dist/space/asteroid-ids.js +19 -0
- package/dist/space/element.d.ts +63 -6
- package/dist/space/element.js +208 -26
- package/dist/space/scene.d.ts +32 -0
- package/dist/space/scene.js +36 -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/element.d.ts +1 -1
- package/dist/surface/element.js +4 -2
- package/package.json +15 -1
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import type { BodyId } from "../facts.ts";
|
|
2
|
+
/**
|
|
3
|
+
* 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).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { PROJECTIONS } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
8
|
+
*
|
|
9
|
+
* console.log(PROJECTIONS.join(", "));
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const PROJECTIONS: readonly ["equirectangular", "mercator", "sinusoidal", "mollweide", "azimuthal"];
|
|
13
|
+
/**
|
|
14
|
+
* One of `PROJECTIONS`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import type { ProjectionId } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
19
|
+
*
|
|
20
|
+
* const id: ProjectionId = "mollweide";
|
|
21
|
+
* console.log(id);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type ProjectionId = (typeof PROJECTIONS)[number];
|
|
25
|
+
/**
|
|
26
|
+
* The point a map is centred on, in degrees. Longitude centres every projection; latitude only turns the azimuthal one (the others keep the equator across the middle).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import type { MapCentre } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
31
|
+
*
|
|
32
|
+
* const northPole: MapCentre = { lon: 0, lat: 90 };
|
|
33
|
+
* console.log(northPole.lat);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export interface MapCentre {
|
|
37
|
+
lon: number;
|
|
38
|
+
lat: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The furthest north or south the Mercator map goes, in degrees: where it becomes a square.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { MERCATOR_LIMIT } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
46
|
+
*
|
|
47
|
+
* console.log(MERCATOR_LIMIT.toFixed(5));
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const MERCATOR_LIMIT: number;
|
|
51
|
+
/**
|
|
52
|
+
* Whether a name is one of the projections.
|
|
53
|
+
*
|
|
54
|
+
* @param value - Any value.
|
|
55
|
+
* @returns True for a name in `PROJECTIONS`.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { isProjection } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
60
|
+
*
|
|
61
|
+
* console.log(isProjection("mollweide"), isProjection("robinson"));
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare const isProjection: (value: unknown) => value is ProjectionId;
|
|
65
|
+
/**
|
|
66
|
+
* How far the map reaches from its middle, in radii: the half width and half height of the box that holds it.
|
|
67
|
+
*
|
|
68
|
+
* @param id - The projection.
|
|
69
|
+
* @returns `halfWidth` and `halfHeight`.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { mapExtent } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
74
|
+
*
|
|
75
|
+
* console.log(mapExtent("mollweide"), mapExtent("azimuthal"));
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function mapExtent(id: ProjectionId): {
|
|
79
|
+
halfWidth: number;
|
|
80
|
+
halfHeight: number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* 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.
|
|
84
|
+
*
|
|
85
|
+
* @param id - The projection.
|
|
86
|
+
* @param lon - Degrees east.
|
|
87
|
+
* @param lat - Degrees north.
|
|
88
|
+
* @param centre - The point in the middle; the Greenwich-like prime meridian on the equator when left out.
|
|
89
|
+
* @returns `x` and `y`.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { projectMap } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
94
|
+
*
|
|
95
|
+
* console.log(projectMap("mollweide", 90, 45), projectMap("azimuthal", 0, 90, { lon: 0, lat: 90 }));
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function projectMap(id: ProjectionId, lon: number, lat: number, centre?: MapCentre): {
|
|
99
|
+
x: number;
|
|
100
|
+
y: number;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* The longitude and latitude at a point of the map: the opposite of `projectMap`.
|
|
104
|
+
*
|
|
105
|
+
* @param id - The projection.
|
|
106
|
+
* @param x - Radii east of the middle.
|
|
107
|
+
* @param y - Radii north of the middle.
|
|
108
|
+
* @param centre - The point in the middle.
|
|
109
|
+
* @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).
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { unprojectMap } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
114
|
+
*
|
|
115
|
+
* console.log(unprojectMap("sinusoidal", 0, 0), unprojectMap("mollweide", 2.8, 1.4));
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function unprojectMap(id: ProjectionId, x: number, y: number, centre?: MapCentre): {
|
|
119
|
+
lon: number;
|
|
120
|
+
lat: number;
|
|
121
|
+
} | null;
|
|
122
|
+
/**
|
|
123
|
+
* One line of the graticule or the outline: points in radii, drawn in order; a graticule line that has to leave the map is several of these.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* import type { MapLine } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
128
|
+
*
|
|
129
|
+
* const line: MapLine = [{ x: 0, y: 0 }, { x: 1, y: 1 }];
|
|
130
|
+
* console.log(line.length);
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export type MapLine = {
|
|
134
|
+
x: number;
|
|
135
|
+
y: number;
|
|
136
|
+
}[];
|
|
137
|
+
/**
|
|
138
|
+
* One graticule line: a meridian or a parallel, with its value in degrees and the pieces to draw (a line the map has to cut is more than one).
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* import type { GraticuleLine } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
143
|
+
*
|
|
144
|
+
* const line: GraticuleLine = { kind: "parallel", value: 0, lines: [[{ x: -3.14, y: 0 }, { x: 3.14, y: 0 }]] };
|
|
145
|
+
* console.log(line.kind);
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export interface GraticuleLine {
|
|
149
|
+
kind: "meridian" | "parallel";
|
|
150
|
+
/** Degrees: the longitude of a meridian, the latitude of a parallel. */
|
|
151
|
+
value: number;
|
|
152
|
+
lines: MapLine[];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 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.
|
|
156
|
+
*
|
|
157
|
+
* @param id - The projection.
|
|
158
|
+
* @param step - Degrees between lines, 5 to 90 (30 when left out).
|
|
159
|
+
* @param centre - The point in the middle.
|
|
160
|
+
* @returns The lines, the equator and the prime meridian among them.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* import { graticule } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
165
|
+
*
|
|
166
|
+
* const lines = graticule("mollweide", 30);
|
|
167
|
+
* console.log(lines.filter((l) => l.kind === "meridian").length, lines.filter((l) => l.kind === "parallel").length);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function graticule(id: ProjectionId, step?: number, centre?: MapCentre): GraticuleLine[];
|
|
171
|
+
/**
|
|
172
|
+
* The edge of the map as one closed line, for a frame: the rectangle, the square, the leaf, the ellipse or the disc.
|
|
173
|
+
*
|
|
174
|
+
* @param id - The projection.
|
|
175
|
+
* @returns The points, the first repeated at the end.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* import { mapOutline } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
180
|
+
*
|
|
181
|
+
* console.log(mapOutline("sinusoidal").length > 100);
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
export declare function mapOutline(id: ProjectionId): MapLine;
|
|
185
|
+
/**
|
|
186
|
+
* How the map sits in a box: pixels for one radius and the box's middle, with `zoom` (1 fits the whole map).
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* import type { MapFit } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
191
|
+
*
|
|
192
|
+
* const fit: MapFit = { scale: 100, cx: 400, cy: 200 };
|
|
193
|
+
* console.log(fit.scale);
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export interface MapFit {
|
|
197
|
+
scale: number;
|
|
198
|
+
cx: number;
|
|
199
|
+
cy: number;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Fit a projection into a box so the whole map shows, with a margin of a few pixels.
|
|
203
|
+
*
|
|
204
|
+
* @param id - The projection.
|
|
205
|
+
* @param width - Box width in pixels.
|
|
206
|
+
* @param height - Box height in pixels.
|
|
207
|
+
* @param zoom - 1 or more; the map is held to its middle.
|
|
208
|
+
* @returns The scale and the middle.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts
|
|
212
|
+
* import { fitMap } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
213
|
+
*
|
|
214
|
+
* console.log(fitMap("mollweide", 800, 400));
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export declare function fitMap(id: ProjectionId, width: number, height: number, zoom?: number): MapFit;
|
|
218
|
+
/**
|
|
219
|
+
* A point of the map in pixels of the box (y grows down).
|
|
220
|
+
*
|
|
221
|
+
* @param fit - From `fitMap`.
|
|
222
|
+
* @param point - A point in radii.
|
|
223
|
+
* @returns `x` and `y` in pixels.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* import { fitMap, mapPixels, projectMap } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
228
|
+
*
|
|
229
|
+
* console.log(mapPixels(fitMap("mercator", 400, 400), projectMap("mercator", 10, 20)));
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
export declare const mapPixels: (fit: MapFit, point: {
|
|
233
|
+
x: number;
|
|
234
|
+
y: number;
|
|
235
|
+
}) => {
|
|
236
|
+
x: number;
|
|
237
|
+
y: number;
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* 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.
|
|
241
|
+
*
|
|
242
|
+
* @param id - The projection.
|
|
243
|
+
* @param body - A body with a pole and spin (a planet, dwarf planet or moon; the Sun has none).
|
|
244
|
+
* @param ms - Milliseconds since 1970 (UTC).
|
|
245
|
+
* @param centre - The point in the middle.
|
|
246
|
+
* @returns The point on the map in radii, and the place on the body.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* import { mapSun } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
251
|
+
*
|
|
252
|
+
* const sun = mapSun("equirectangular", "moon", Date.UTC(1969, 6, 20, 20, 17, 40));
|
|
253
|
+
* console.log(sun.lat.toFixed(0), sun.lon.toFixed(0));
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
export declare function mapSun(id: ProjectionId, body: BodyId, ms: number, centre?: MapCentre): {
|
|
257
|
+
x: number;
|
|
258
|
+
y: number;
|
|
259
|
+
lon: number;
|
|
260
|
+
lat: number;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* A picture as pixels: its size and RGBA bytes, row by row from the top, as `ImageData` holds them.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* import type { MapPixels } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
268
|
+
*
|
|
269
|
+
* const one: MapPixels = { width: 1, height: 1, data: new Uint8ClampedArray([255, 0, 0, 255]) };
|
|
270
|
+
* console.log(one.width);
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
export interface MapPixels {
|
|
274
|
+
width: number;
|
|
275
|
+
height: number;
|
|
276
|
+
data: ArrayLike<number>;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* 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.
|
|
280
|
+
*
|
|
281
|
+
* @param source - The painted map.
|
|
282
|
+
* @param id - The projection.
|
|
283
|
+
* @param width - Answer width in pixels.
|
|
284
|
+
* @param height - Answer height in pixels.
|
|
285
|
+
* @param options - `centre` (the middle) and `zoom` (1 fits the whole map).
|
|
286
|
+
* @returns RGBA bytes, `width` by `height`.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* import { resampleMap } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
291
|
+
*
|
|
292
|
+
* const grey = { width: 2, height: 1, data: [0, 0, 0, 255, 255, 255, 255, 255] };
|
|
293
|
+
* const out = resampleMap(grey, "equirectangular", 4, 2);
|
|
294
|
+
* console.log(out.length);
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
export declare function resampleMap(source: MapPixels, id: ProjectionId, width: number, height: number, options?: {
|
|
298
|
+
centre?: MapCentre;
|
|
299
|
+
zoom?: number;
|
|
300
|
+
}): Uint8ClampedArray;
|