@johnmorrisdotca/wakusei-planets 0.62.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 +12 -1
- package/README.md +3 -3
- 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/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/package.json +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,12 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.63.0] - 2026-11-17
|
|
6
|
+
|
|
7
|
+
- **A drop-in for suncalc 2.1 and 1.9: both flags, default exports, a guide** (MODULES-535). `getTimes` and `getMoonTimes` in `/suncalc` now give `alwaysUp` and `alwaysDown` both, one `true` and one `false`, on a day without a sunrise or without a Moon rise and set, as suncalc 2 does (before, only the true one was there). `/suncalc` and `/suncalc/legacy` each have a default export holding the same functions and the same `times` array, for code written `import SunCalc from "suncalc"`. A new guide, "Replacing suncalc" (English and Japanese), has the one-line import change, every function side by side, the three conventions people trip on, the differences kept on purpose, the measured limits, and suncalc3's extras listed and not built. `test/suncalc-grid.test.ts` runs every function against suncalc 2.1.2 and suncalc 1.9.0 (dev-only) on fourteen places (both hemispheres, both polar circles, 78 degrees north and south) by eleven days from 1900 to 2100 by three times of day; `test/docs-replacing-suncalc.test.ts` runs the guide's examples. The API snapshot was updated for the two default exports.
|
|
8
|
+
|
|
9
|
+
- **The ephemeris package survey, as a record** (MODULES-531). `docs/design/ephemeris-survey.md` lists each surveyed package with its licence line read on its own GitHub page on 2026-11-17 (MIT, Apache-2.0, AGPL-3.0, GPL), what it holds and how accurate it claims to be, and what is still open. Two facts of the first survey were corrected (vsop87 is about 2.3 MB, not 7; the ephemeris package says GPL v2 on its repo).
|
|
10
|
+
|
|
11
|
+
- **"Coming from suncalc 1.x or suncalc2" in the `/suncalc` guide, EN and JA** (MODULES-537). The one-line import change, radians to degrees and south to north azimuth side by side with a run that shows both, the day rule of the legacy `getTimes` and `getMoonTimes`, and a plain list of what suncalc3 adds (suncalc-ts adds nothing). The licence and fork findings are in `docs/design/suncalc-forks.md`. No code changed.
|
|
12
|
+
|
|
13
|
+
- **Fact sheets: `/fact-sheets`** (MODULES-529, first slice). `factSheet("mars")` gives, for the Sun, the eight planets and Pluto, the radius and mean distance in km and miles (and au), the sidereal year in Earth days, the rotation in hours and whether it is retrograde, the number of known moons and the date it was read (the `/moon-catalogue` count), NASA's own page, and a short description in our own words in English and Japanese. New guide, English and Japanese, with tested examples. A new entry point, so the API snapshot and the size baseline have a new line. Not in this slice: the definitions of planet, dwarf planet, moon, asteroid, comet, meteoroid, meteor and meteorite (held back until the IAU texts are checked against the originals), meteor showers (the IMO table's reuse terms must be read first) and a demo page.
|
|
14
|
+
|
|
15
|
+
- **Map projections for the painted maps** (MODULES-546, the pure side and the demo; no new dependency). `@johnmorrisdotca/wakusei-planets/flat` gains `PROJECTIONS` (`equirectangular`, `mercator`, `sinusoidal`, `mollweide`, `azimuthal`), `projectMap` and `unprojectMap` (radii from the middle of the map; `null` outside the leaf, the ellipse or the disc), `graticule` (lines of longitude and latitude cut where they would cross the map, none at a pole on Mercator, which stops at 85.05 degrees), `mapOutline`, `fitMap`, `mapPixels`, `mapSun` (the sub-solar point on the map, for any body with a pole and spin) and `resampleMap` (a body's equirectangular painted map redrawn in a projection: smooth between pixels, wrapping at the seam, holding at the poles, transparent outside the shape), with `isProjection`, `MERCATOR_LIMIT` and the types. The flat page of the demo has a panel, "Any body, in a projection": the 25 bodies with a painted map, the five projections, the grid (off, 30 or 15 degrees), the middle longitude and, on the disc, latitude, and a ring where the Sun is overhead; it draws only when something changes. English and Japanese in "Flat maps of the Moon and Mars" and the demo. Tests: `test/flat-projections.test.ts` (round trips about three centres, the poles, the shapes' areas, the grid's cuts, the seam), `e2e/flat-projections.demo.ts` and `examples/flat/projections.mjs`. Not done: `<wakusei-flat projection="...">` itself (its pans, picks and ground tracks read the plain map).
|
|
16
|
+
|
|
5
17
|
## [0.62.0] - 2026-11-17
|
|
6
18
|
|
|
7
19
|
- **Standing on Mars, and at six more sites: Perseverance, Curiosity, Apollo 15, Apollo 16, Chang'e 3 and Chang'e 4** (MODULES-1482, part 2; John Morris, 2026-11-17). `SURFACE_SITES` now has seven sites and `SurfaceSite.body` is `"moon" | "mars"`; the new `ground` is `"measured"` (Apollo 17, as before) or `"flat"`, and `gravity` is the body's surface gravity (`MOON_GRAVITY` 1.62, `MARS_GRAVITY` 3.71 m/s2). `<wakusei-surface site="perseverance">` and `land(space, "perseverance")` (also `curiosity`, `apollo-15`, `apollo-16`, `chang-e-3`, `chang-e-4`) work; the seven records in `LANDING_SITES` carry `stand`, and a test pins each to the standing view's point, place and landing moment. **The ground at the six new sites is a flat stand-in until a height model is added** ("ground: flat stand-in until a DTM is added", in the page's line and in `manifest.accuracy`): flat at the site's datum, made in memory by `flatTerrain` and `flatManifest` with nothing fetched, and with no relief, no made craters and no made rocks (`detail` is ignored there), so no relief is faked. The height data would be a download (HiRISE or CTX models for Mars, LROC or LOLA for the Moon) and is not here. **Real for the place and time**: the Sun's direction and size from the package's own ephemeris (`standSky`, `localFrame` takes a body; on Mars the Sun is about a third of a degree across), the gravity (the driven rover's slope and free fall, `driveStep`'s new last argument, and the thrown dust, `DustField.step`'s), and the Moon's black sky with its Earth. **Chosen, not measured**: Mars's sky, a butterscotch day sky with a pale blue glow round a low Sun, black at night after a long twilight (`marsAir`, drawn by a new sky pass in the shader; NASA's page says the sky is hazy and reddish from suspended dust), and the ground's reddish tone; the Earth is not drawn from Mars. New exports of `/surface`: `standSky`, `marsAir`, `flatTerrain`, `flatManifest`, `MOON_GRAVITY`, `MARS_GRAVITY` and the types `StandSky`, `SkyAir` and `Rgb`; `TerrainManifest.body` is `"moon" | "mars"`. Tests: `test/surface-sites.test.ts` and `e2e/surface-sites.demo.ts` (no tiles asked for, the flat line, a butterscotch sky over a reddish ground on Mars and a black sky over a grey ground on the Moon, nothing drawn at rest). Guide: "Standing on the Moon and Mars", in both languages. **Not here yet**: the measured ground of any of them, and the rover models at the new sites (`drive-model` takes the GLB as before).
|
|
8
20
|
|
|
9
21
|
- **Belt filters and size tiers** (MODULES-558, part). `filterBeltBodies(bodies, { belts, hMax, hMin, status, part })`, `beltStatus(name)` (provisional, numbered or named), `beltPart(body, jd, jupiterLongitude)` (the main belt's inner, middle and outer parts, the Trojans' L4 and L5 camps, plutinos and detached bodies), `BELT_TIERS` and `beltTiers(bodies)` (how many bodies of each size tier are carried, against how many the database knows). All from the rows already carried: no new data. Still open on the ticket: discovery facts and pictures (need files fetched), the embed and the builder.
|
|
10
|
-
|
|
11
22
|
## [0.61.0] - 2026-11-17
|
|
12
23
|
|
|
13
24
|
- **IM-2's three rovers stand on Athena, east of the prime meridian** (MODULES-1402; John Morris, 2026-11-17). GCAT's lander catalogue has the whole IM-2 landing at 84.7906 S, 29.1957 W; NASA's table, which the places take, puts Athena at 29.1957 E, but GRACE, MAPP and Yaoki, which NASA's table does not list, kept the catalogue's point on the far side of the prime meridian. `scripts/make-places-data.py` now moves a rover the catalogue puts at its lander's own point with the lander whenever a better source moves the lander more than 0.05 degree and has no position of its own for the rover; the rovers keep the catalogue's figure in `gcatPosition`. No other rover on the Moon or Mars disagrees with its lander, and a test pins both.
|
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Wakusei Planets runs in the browser of a phone, a tablet or a computer: nothing
|
|
|
19
19
|
|
|
20
20
|
<p align="center"><img alt="The demo on a desk: Saturn in the painted look, turning in the big view, with the page's links to the portrait builder, the colouring sheets, the space view, the star page and the size line-up above it, and the choice of body and its moons below" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-desk.webp" width="620"> <img alt="The same page on a phone: the same links in rows, and Saturn in the painted look below them" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-phone.webp" width="200"></p>
|
|
21
21
|
|
|
22
|
-
<p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.
|
|
22
|
+
<p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.63.0/docs/images/lineup-desk.png" width="640"></p>
|
|
23
23
|
|
|
24
24
|
## Who it is for
|
|
25
25
|
|
|
@@ -412,7 +412,7 @@ The tiles of every body share one 48 MB budget, six loads at a time for a source
|
|
|
412
412
|
|
|
413
413
|
## The portrait builder
|
|
414
414
|
|
|
415
|
-
<p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.
|
|
415
|
+
<p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.63.0/docs/images/portrait-family.png" width="640"></p>
|
|
416
416
|
|
|
417
417
|
[The portrait builder](https://johnmorrisdotca.github.io/wakusei-planets/portrait.html) puts any bodies in one picture: drag them, size them, turn them, order them front to back, arrange them in a row, an arc, a grid or at true orbit distance (true or readable sizes, a planet's moons round it in orbit order), light them from one direction, and take the code, a PNG or an SVG. The scene is kept in the address, and every body is drawn in one WebGL scene, so the page holds one WebGL context. [The portrait builder](docs/guides/portrait-builder.md) is its guide.
|
|
418
418
|
|
|
@@ -567,7 +567,7 @@ BODIES.pluto.kind; // "dwarf-planet"
|
|
|
567
567
|
|
|
568
568
|
If this package helps a paper, a talk or a class, please cite it as software. GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA; in plain text:
|
|
569
569
|
|
|
570
|
-
> Morris, J. (2026). *Wakusei Planets* (version 0.
|
|
570
|
+
> Morris, J. (2026). *Wakusei Planets* (version 0.63.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
|
|
571
571
|
|
|
572
572
|
Cite the version you used (`npm ls @johnmorrisdotca/wakusei-planets`), and cite the sources of the numbers you use as well: [NOTICE.md](NOTICE.md) names each one, with the paper or the page it was read from (the IAU working group's report for sizes and poles, VSOP87B, ELP2000-82B, L1.2 and TASS1.7 for positions, and NASA's JPL Horizons for the fits and the spacecraft).
|
|
573
573
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bodies that have a fact sheet: the Sun, the eight planets and Pluto.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { FACT_SHEET_IDS } from "@johnmorrisdotca/wakusei-planets/fact-sheets";
|
|
7
|
+
*
|
|
8
|
+
* console.log(FACT_SHEET_IDS.join(", "));
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare const FACT_SHEET_IDS: readonly ["sun", "mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"];
|
|
12
|
+
/**
|
|
13
|
+
* The name of a body that has a fact sheet.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { FACT_SHEET_IDS, type FactSheetId } from "@johnmorrisdotca/wakusei-planets/fact-sheets";
|
|
18
|
+
*
|
|
19
|
+
* const id: FactSheetId = FACT_SHEET_IDS[3];
|
|
20
|
+
* console.log(id);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export type FactSheetId = (typeof FACT_SHEET_IDS)[number];
|
|
24
|
+
/**
|
|
25
|
+
* A number in kilometres and in miles.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { factSheet, type Length } from "@johnmorrisdotca/wakusei-planets/fact-sheets";
|
|
30
|
+
*
|
|
31
|
+
* const radius: Length = factSheet("earth").radius;
|
|
32
|
+
* console.log(Math.round(radius.km), Math.round(radius.miles));
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export interface Length {
|
|
36
|
+
km: number;
|
|
37
|
+
miles: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A fact sheet: what a page about a body usually says, as data.
|
|
41
|
+
*
|
|
42
|
+
* `radius` is the equatorial radius. `distanceFromSun` is the mean distance (zero for the Sun). `yearDays` is the sidereal year in Earth days (the time to go once round the Sun; `null` for the Sun) and
|
|
43
|
+
* `rotationHours` the time to turn once on its axis against the stars (so it is not the length of a solar day: Venus's sidereal rotation is longer than its year's solar day), with `retrograde` true for a body
|
|
44
|
+
* that turns backwards (Venus, Uranus and Pluto). `knownMoons` is the number of moons known on `moonsReadOn` (a date: the count moves as moons are found). `nasaPage` is NASA's own page about the body.
|
|
45
|
+
* `description` is a short description in our own words.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { factSheet, type FactSheet } from "@johnmorrisdotca/wakusei-planets/fact-sheets";
|
|
50
|
+
*
|
|
51
|
+
* const mars: FactSheet = factSheet("mars");
|
|
52
|
+
* console.log(mars.name.en, mars.knownMoons, mars.nasaPage);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export interface FactSheet {
|
|
56
|
+
id: FactSheetId;
|
|
57
|
+
name: {
|
|
58
|
+
en: string;
|
|
59
|
+
ja: string;
|
|
60
|
+
};
|
|
61
|
+
kind: "star" | "planet" | "dwarf-planet";
|
|
62
|
+
radius: Length;
|
|
63
|
+
distanceFromSun: Length & {
|
|
64
|
+
au: number;
|
|
65
|
+
};
|
|
66
|
+
yearDays: number | null;
|
|
67
|
+
rotationHours: number;
|
|
68
|
+
retrograde: boolean;
|
|
69
|
+
knownMoons: number;
|
|
70
|
+
moonsReadOn: string;
|
|
71
|
+
nasaPage: string;
|
|
72
|
+
description: {
|
|
73
|
+
en: string;
|
|
74
|
+
ja: string;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The date the moon counts were read from JPL's planetary satellite page, the same read as `/moon-catalogue`'s `MOON_CATALOGUE_FETCHED`.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { MOONS_READ_ON } from "@johnmorrisdotca/wakusei-planets/fact-sheets";
|
|
83
|
+
*
|
|
84
|
+
* console.log("moon counts read on", MOONS_READ_ON);
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare const MOONS_READ_ON = "2026-11-11";
|
|
88
|
+
/**
|
|
89
|
+
* The fact sheet of the Sun, a planet or Pluto.
|
|
90
|
+
*
|
|
91
|
+
* @param id - `"sun"`, `"mercury"` to `"neptune"`, or `"pluto"`.
|
|
92
|
+
* @returns The sheet (a new object each call).
|
|
93
|
+
* @throws {RangeError} For an id that has no fact sheet, naming it.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { factSheet } from "@johnmorrisdotca/wakusei-planets/fact-sheets";
|
|
98
|
+
*
|
|
99
|
+
* const venus = factSheet("venus");
|
|
100
|
+
* console.log(venus.yearDays, venus.retrograde, venus.description.en);
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function factSheet(id: FactSheetId): FactSheet;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// A fact sheet for the Sun, the eight planets and Pluto, as plain data.
|
|
2
|
+
// Every number is the package's own (radius and rotation from the IAU working group's report, the distance from JPL's approximate elements) or a published figure with its source named here: the sidereal
|
|
3
|
+
// year from NASA's planetary fact sheets (https://nssdc.gsfc.nasa.gov/planetary/factsheet/, read 2026-11-17), the moon counts from JPL's planetary satellite page (read 2026-11-11, the same read as `/moon-catalogue`),
|
|
4
|
+
// the page links to NASA's own page for each body (each fetched 2026-11-17). The descriptions are written here in our own words; no text of NASA's, the IAU's or an encyclopedia's is copied.
|
|
5
|
+
// Pure: no DOM, no clock reads, no three.js.
|
|
6
|
+
import { BODIES } from "./facts.js";
|
|
7
|
+
import { journeyStop } from "./stops.js";
|
|
8
|
+
const KM_PER_MILE = 1.609344;
|
|
9
|
+
const AU_KM = 149_597_870.7;
|
|
10
|
+
/**
|
|
11
|
+
* The bodies that have a fact sheet: the Sun, the eight planets and Pluto.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { FACT_SHEET_IDS } from "@johnmorrisdotca/wakusei-planets/fact-sheets";
|
|
16
|
+
*
|
|
17
|
+
* console.log(FACT_SHEET_IDS.join(", "));
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const FACT_SHEET_IDS = ["sun", "mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"];
|
|
21
|
+
/**
|
|
22
|
+
* The date the moon counts were read from JPL's planetary satellite page, the same read as `/moon-catalogue`'s `MOON_CATALOGUE_FETCHED`.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { MOONS_READ_ON } from "@johnmorrisdotca/wakusei-planets/fact-sheets";
|
|
27
|
+
*
|
|
28
|
+
* console.log("moon counts read on", MOONS_READ_ON);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const MOONS_READ_ON = "2026-11-11";
|
|
32
|
+
// The sidereal year in Earth days, NASA planetary fact sheets (orbital period).
|
|
33
|
+
const YEAR_DAYS = {
|
|
34
|
+
mercury: 87.969,
|
|
35
|
+
venus: 224.701,
|
|
36
|
+
earth: 365.256,
|
|
37
|
+
mars: 686.98,
|
|
38
|
+
jupiter: 4332.589,
|
|
39
|
+
saturn: 10759.22,
|
|
40
|
+
uranus: 30685.4,
|
|
41
|
+
neptune: 60189,
|
|
42
|
+
pluto: 90560,
|
|
43
|
+
};
|
|
44
|
+
// The known moons on MOONS_READ_ON (JPL's planetary satellite page); a test holds these to `/moon-catalogue`.
|
|
45
|
+
const MOONS = { sun: 0, mercury: 0, venus: 0, earth: 1, mars: 2, jupiter: 115, saturn: 293, uranus: 29, neptune: 16, pluto: 5 };
|
|
46
|
+
const NASA = {
|
|
47
|
+
sun: "https://science.nasa.gov/sun/",
|
|
48
|
+
mercury: "https://science.nasa.gov/mercury/",
|
|
49
|
+
venus: "https://science.nasa.gov/venus/",
|
|
50
|
+
earth: "https://science.nasa.gov/earth/",
|
|
51
|
+
mars: "https://science.nasa.gov/mars/",
|
|
52
|
+
jupiter: "https://science.nasa.gov/jupiter/",
|
|
53
|
+
saturn: "https://science.nasa.gov/saturn/",
|
|
54
|
+
uranus: "https://science.nasa.gov/uranus/",
|
|
55
|
+
neptune: "https://science.nasa.gov/neptune/",
|
|
56
|
+
pluto: "https://science.nasa.gov/dwarf-planets/pluto/",
|
|
57
|
+
};
|
|
58
|
+
const DESCRIPTION = {
|
|
59
|
+
sun: {
|
|
60
|
+
en: "The star at the centre of the solar system. It holds almost all of the system's mass and its light and heat keep every planet going.",
|
|
61
|
+
ja: "太陽系の中心にある恒星です。太陽系の質量のほぼすべてを占め、その光と熱がすべての惑星を支えています。",
|
|
62
|
+
},
|
|
63
|
+
mercury: {
|
|
64
|
+
en: "The smallest planet and the nearest to the Sun. It is a dry, cratered rock with almost no air, so its days are scorching and its nights bitterly cold.",
|
|
65
|
+
ja: "いちばん小さく、太陽にいちばん近い惑星です。クレーターだらけの乾いた岩の星で、空気がほとんどないため、昼は灼熱、夜は極寒になります。",
|
|
66
|
+
},
|
|
67
|
+
venus: {
|
|
68
|
+
en: "A rocky planet almost the size of the Earth, wrapped in thick clouds and a heavy carbon dioxide atmosphere that makes it the hottest planet. It turns backwards, very slowly.",
|
|
69
|
+
ja: "地球とほぼ同じ大きさの岩の惑星です。厚い雲と二酸化炭素の濃い大気に包まれ、惑星の中でいちばん高温です。とてもゆっくり、逆向きに自転します。",
|
|
70
|
+
},
|
|
71
|
+
earth: {
|
|
72
|
+
en: "Our home, the only place known to have life. It is the one planet with liquid water on its surface, and it has one large Moon.",
|
|
73
|
+
ja: "私たちの住む星で、生命が確認されている唯一の場所です。表面に液体の水がある唯一の惑星で、大きな衛星を1つ持っています。",
|
|
74
|
+
},
|
|
75
|
+
mars: {
|
|
76
|
+
en: "A cold, dry, rusty-red desert planet with a thin air of carbon dioxide, the tallest volcano known and two small moons. Robots have explored its surface for decades.",
|
|
77
|
+
ja: "二酸化炭素の薄い大気を持つ、冷たく乾いた赤さび色の砂漠の惑星です。知られている中で最も高い火山と、2つの小さな衛星があります。何十年も前からロボットが地表を調べています。",
|
|
78
|
+
},
|
|
79
|
+
jupiter: {
|
|
80
|
+
en: "The largest planet, a giant ball of hydrogen and helium with bands of cloud and a storm bigger than the Earth that has raged for centuries. It has a faint ring and a great many moons.",
|
|
81
|
+
ja: "最大の惑星で、水素とヘリウムでできた巨大なガスの球です。雲の縞模様と、何百年も続く地球より大きな嵐があります。かすかな環と、たくさんの衛星を持っています。",
|
|
82
|
+
},
|
|
83
|
+
saturn: {
|
|
84
|
+
en: "A giant planet of hydrogen and helium, famous for its wide, bright rings of ice. It is light enough that it would float in a big enough bath, and it has more known moons than any other planet.",
|
|
85
|
+
ja: "水素とヘリウムでできた巨大な惑星で、氷でできた広く明るい環で知られています。密度が水より小さく、十分に大きなお風呂があれば浮かぶほどです。知られている衛星の数は惑星の中でいちばん多いです。",
|
|
86
|
+
},
|
|
87
|
+
uranus: {
|
|
88
|
+
en: "A cold blue-green giant that spins on its side, as if rolling round the Sun. Its air of hydrogen, helium and methane gives it its colour, and it has faint rings and many moons.",
|
|
89
|
+
ja: "冷たい青緑色の巨大な惑星で、横倒しになって、転がるように太陽のまわりを回ります。水素、ヘリウム、メタンの大気がその色を生みます。かすかな環と多くの衛星があります。",
|
|
90
|
+
},
|
|
91
|
+
neptune: {
|
|
92
|
+
en: "The farthest planet from the Sun, a deep blue giant with the fastest winds known on any planet. It takes about 165 years to go once round the Sun and has faint rings and many moons.",
|
|
93
|
+
ja: "太陽からいちばん遠い惑星で、濃い青色の巨大な惑星です。知られている中で最も速い風が吹きます。太陽を1周するのに約165年かかり、かすかな環と多くの衛星があります。",
|
|
94
|
+
},
|
|
95
|
+
pluto: {
|
|
96
|
+
en: "A small, icy dwarf planet in the Kuiper belt beyond Neptune, with a heart-shaped bright plain, a thin air that freezes and falls as snow when it moves away from the Sun, and five known moons.",
|
|
97
|
+
ja: "海王星より外側のカイパーベルトにある、小さく氷でできた準惑星です。ハート形の明るい平原があり、薄い大気は太陽から遠ざかると凍って雪になります。知られている衛星は5つです。",
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* The fact sheet of the Sun, a planet or Pluto.
|
|
102
|
+
*
|
|
103
|
+
* @param id - `"sun"`, `"mercury"` to `"neptune"`, or `"pluto"`.
|
|
104
|
+
* @returns The sheet (a new object each call).
|
|
105
|
+
* @throws {RangeError} For an id that has no fact sheet, naming it.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { factSheet } from "@johnmorrisdotca/wakusei-planets/fact-sheets";
|
|
110
|
+
*
|
|
111
|
+
* const venus = factSheet("venus");
|
|
112
|
+
* console.log(venus.yearDays, venus.retrograde, venus.description.en);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export function factSheet(id) {
|
|
116
|
+
if (!FACT_SHEET_IDS.includes(id))
|
|
117
|
+
throw new RangeError(`There is no fact sheet for "${String(id)}"; it has one for ${FACT_SHEET_IDS.join(", ")}.`);
|
|
118
|
+
const facts = BODIES[id];
|
|
119
|
+
const au = id === "sun" ? 0 : journeyStop(id).sunAu;
|
|
120
|
+
const km = (value) => ({ km: value, miles: value / KM_PER_MILE });
|
|
121
|
+
return {
|
|
122
|
+
id,
|
|
123
|
+
name: { ...facts.name },
|
|
124
|
+
kind: facts.kind === "star" ? "star" : facts.kind === "dwarf-planet" ? "dwarf-planet" : "planet",
|
|
125
|
+
radius: km(facts.radiusKm),
|
|
126
|
+
distanceFromSun: { ...km(au * AU_KM), au },
|
|
127
|
+
yearDays: id === "sun" ? null : YEAR_DAYS[id],
|
|
128
|
+
rotationHours: Math.abs(facts.rotationHours),
|
|
129
|
+
retrograde: facts.rotationHours < 0,
|
|
130
|
+
knownMoons: MOONS[id],
|
|
131
|
+
moonsReadOn: MOONS_READ_ON,
|
|
132
|
+
nasaPage: NASA[id],
|
|
133
|
+
description: { ...DESCRIPTION[id] },
|
|
134
|
+
};
|
|
135
|
+
}
|
package/dist/flat/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { FLAT_BODIES, ORBITER_COLOURS, flatBody, isFlatBody, orbiterColour, orbiterName, type FlatBodyId, type FlatBodyInfo } from "./bodies.ts";
|
|
2
2
|
export { MAX_ZOOM, clampView, pixelsPerDegree, projectFlat, unprojectFlat, wrapLongitude, zoomAbout, type FlatView } from "./geometry.ts";
|
|
3
|
+
export { MERCATOR_LIMIT, PROJECTIONS, fitMap, graticule, isProjection, mapExtent, mapOutline, mapPixels, mapSun, projectMap, resampleMap, unprojectMap, type GraticuleLine, type MapCentre, type MapFit, type MapLine, type MapPixels, type ProjectionId } from "./projections.ts";
|
|
3
4
|
export { circleOutline, flatOrbiter, flatSun, flatTrack, hasPath, shadeNight, trackPieces, type FlatOrbiter } from "./scene.ts";
|
|
4
5
|
export { FLAT_WORDS, coordinateText, say, type FlatLang } from "./words.ts";
|
|
5
6
|
export type { FlatPick, WakuseiFlat } from "./element.ts";
|
package/dist/flat/index.js
CHANGED
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
// The element itself is in `@johnmorrisdotca/wakusei-planets/flat/define`, which registers `<wakusei-flat>`.
|
|
3
3
|
export { FLAT_BODIES, ORBITER_COLOURS, flatBody, isFlatBody, orbiterColour, orbiterName } from "./bodies.js";
|
|
4
4
|
export { MAX_ZOOM, clampView, pixelsPerDegree, projectFlat, unprojectFlat, wrapLongitude, zoomAbout } from "./geometry.js";
|
|
5
|
+
export { MERCATOR_LIMIT, PROJECTIONS, fitMap, graticule, isProjection, mapExtent, mapOutline, mapPixels, mapSun, projectMap, resampleMap, unprojectMap } from "./projections.js";
|
|
5
6
|
export { circleOutline, flatOrbiter, flatSun, flatTrack, hasPath, shadeNight, trackPieces } from "./scene.js";
|
|
6
7
|
export { FLAT_WORDS, coordinateText, say } from "./words.js";
|
|
@@ -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;
|
|
@@ -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/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/wakusei-planets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0",
|
|
4
4
|
"description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"planets",
|
|
@@ -236,6 +236,11 @@
|
|
|
236
236
|
"import": "./dist/spacecraft.js",
|
|
237
237
|
"default": "./dist/spacecraft.js"
|
|
238
238
|
},
|
|
239
|
+
"./fact-sheets": {
|
|
240
|
+
"types": "./dist/fact-sheets.d.ts",
|
|
241
|
+
"import": "./dist/fact-sheets.js",
|
|
242
|
+
"default": "./dist/fact-sheets.js"
|
|
243
|
+
},
|
|
239
244
|
"./roadster": {
|
|
240
245
|
"types": "./dist/roadster.d.ts",
|
|
241
246
|
"import": "./dist/roadster.js",
|