@johnmorrisdotca/wakusei-planets 0.72.0 → 0.74.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.
@@ -0,0 +1,81 @@
1
+ // The hero above a moon page's tabs: the planet's edge, and its main moons in an arc, farthest at the top. Disc sizes follow the moons' own diameters, squeezed so a small moon stays visible. No DOM.
2
+ import { BODIES, ringReach } from "../facts.js";
3
+ /** The moons in the hero's arc, farthest from the planet first. Jupiter's four are the Galileans. Saturn's seven are the large named moons. */
4
+ export const HERO_ARC = {
5
+ jupiter: ["callisto", "ganymede", "europa", "io"],
6
+ saturn: ["iapetus", "titan", "rhea", "dione", "tethys", "enceladus", "mimas"],
7
+ uranus: ["oberon", "titania", "umbriel", "ariel", "miranda"],
8
+ neptune: ["nereid", "triton", "proteus", "larissa"],
9
+ };
10
+ /** A second, smaller row: the named moons the package draws that are not in the arc. Saturn's list is the small moons of the reference; Methone is not drawn here. None of these has a photo map. */
11
+ export const HERO_SMALL = {
12
+ jupiter: ["thebe", "amalthea"],
13
+ saturn: ["pan", "atlas", "prometheus", "pandora", "janus", "epimetheus", "hyperion", "telesto", "calypso", "helene"],
14
+ uranus: [],
15
+ neptune: [],
16
+ };
17
+ /** Where the painted face is turned, in degrees, so the familiar side of the planet meets the moons. Jupiter's longitude is the package's best-known side, turned so the Great Red Spot sits in the visible half. Saturn's pitch looks over the pole: the near half of the rings, the one drawn in front of the globe, then crosses the lower part of the globe. A negative pitch puts that half on the upper globe and the far half, which the globe hides, on the lower. */
18
+ export const HERO_POSE = {
19
+ jupiter: { meridian: 70, tilt: 14 },
20
+ saturn: { meridian: 30, tilt: 26.73, pitch: 22 },
21
+ uranus: { meridian: 10, tilt: 16 },
22
+ neptune: { meridian: 20, tilt: 16 },
23
+ };
24
+ /**
25
+ * How far a hero planet is zoomed. A tight portrait fits the rings, and Jupiter's faint rings would shrink the globe to a third of the frame, so Jupiter is zoomed until the globe fills it. Saturn's rings are the picture, and stay at 1.
26
+ */
27
+ export function heroZoom(host) {
28
+ if (host !== "jupiter")
29
+ return 1;
30
+ return Math.max(1.06, ringReach(BODIES[host]) * 1.04);
31
+ }
32
+ /** The hero's moons for one planet, farthest first, in the arc from the upper left down toward the planet's limb. A moon that is not drawn is left out. */
33
+ export function heroMoons(cards, host, lang) {
34
+ const byId = new Map(cards.map((card) => [card.id, card]));
35
+ const chosen = HERO_ARC[host].flatMap((id) => {
36
+ const card = byId.get(id);
37
+ return card === undefined ? [] : [card];
38
+ });
39
+ const max = Math.max(1, ...chosen.map((card) => card.radiusKm));
40
+ const count = chosen.length;
41
+ const largest = count <= 4 ? 132 : count <= 5 ? 120 : 112;
42
+ return chosen.map((card, index) => {
43
+ const even = count <= 1 ? 0 : index / (count - 1);
44
+ // Saturn's first two discs are the large ones. A shared step sets Iapetus on Titan, so the first step is longer.
45
+ const t = host === "saturn" && count > 2 ? (index === 0 ? 0 : 0.34 + 0.66 * ((index - 1) / (count - 2))) : even;
46
+ const share = card.radiusKm / max;
47
+ return {
48
+ id: card.id,
49
+ name: lang === "ja" ? card.name.ja : card.name.en,
50
+ px: Math.max(64, Math.round(largest * share)),
51
+ left: Math.round((16 + even * 12) * 10) / 10,
52
+ top: Math.round((10 + t * 62) * 10) / 10,
53
+ };
54
+ });
55
+ }
56
+ /** The second row, in list order. Disc sizes follow diameter, with a floor so a small rock stays a disc. Every one is marked estimated: the package has no photo map for these. */
57
+ export function heroSmall(cards, host, lang) {
58
+ const byId = new Map(cards.map((card) => [card.id, card]));
59
+ const chosen = HERO_SMALL[host].flatMap((id) => {
60
+ const card = byId.get(id);
61
+ return card === undefined ? [] : [card];
62
+ });
63
+ const max = Math.max(1, ...chosen.map((card) => card.radiusKm));
64
+ return chosen.map((card) => ({
65
+ id: card.id,
66
+ name: `${lang === "ja" ? card.name.ja : card.name.en}*`,
67
+ px: Math.round(28 * Math.max(0.45, card.radiusKm / max)),
68
+ left: 0,
69
+ top: 0,
70
+ }));
71
+ }
72
+ /** The same moons as outline circles at their true diameters, the largest 56 pixels across. */
73
+ export function heroScale(cards, host) {
74
+ const byId = new Map(cards.map((card) => [card.id, card]));
75
+ const chosen = [...HERO_ARC[host], ...HERO_SMALL[host]].flatMap((id) => {
76
+ const card = byId.get(id);
77
+ return card === undefined ? [] : [card];
78
+ });
79
+ const max = Math.max(1, ...chosen.map((card) => card.radiusKm));
80
+ return chosen.map((card) => ({ id: card.id, diameterKm: card.radiusKm * 2, px: Math.max(4, Math.round(56 * (card.radiusKm / max))) }));
81
+ }
@@ -55,6 +55,12 @@ export declare const MOON_PAGE_WORDS: {
55
55
  readonly table_note: "≈ marks a size worked out from the moon's brightness, not measured. — means no source gives it. The place of discovery is known here only for the moons drawn in full, which are in bold.";
56
56
  readonly credits: "Every number on this page is the package's own, worked out when the page was built: the moons, their orbits, sizes and discoveries from NASA/JPL's moon pages and Horizons, read on {fetched}, and the places of discovery from the IAU Gazetteer.";
57
57
  readonly short: "{total} moons · {named} named · {retrograde} go the other way";
58
+ readonly hero_moons: "Main moons";
59
+ readonly full_screen: "Full screen";
60
+ readonly leave_full_screen: "Leave full screen";
61
+ readonly hero_fact: "{name}: {diameter} km across, {distance} km from {planet}. Found {found}.";
62
+ readonly hero_estimated: "* shape or size estimated";
63
+ readonly hero_scale: "The circles are the true sizes. The moons above are drawn large enough to see.";
58
64
  };
59
65
  readonly ja: {
60
66
  readonly tabs: "表示";
@@ -111,5 +117,11 @@ export declare const MOON_PAGE_WORDS: {
111
117
  readonly table_note: "≈ は、測定ではなく衛星の明るさから見積もった大きさです。— は、資料に値がないことを表します。発見した場所は、くわしく描いている衛星(太字)だけにあります。";
112
118
  readonly credits: "このページの数字はすべて、ページを作ったときにパッケージのデータから計算したものです。衛星の軌道・大きさ・発見は NASA/JPL の衛星のページと Horizons({fetched}に読み込み)から、発見した場所は IAU 惑星地名辞典からです。";
113
119
  readonly short: "衛星{total}個・名前つき{named}個・反対向き{retrograde}個";
120
+ readonly hero_moons: "主な衛星";
121
+ readonly full_screen: "全画面";
122
+ readonly leave_full_screen: "全画面をやめる";
123
+ readonly hero_fact: "{name}:直径 {diameter} km、{planet}から {distance} km。発見は{found}。";
124
+ readonly hero_estimated: "* 形や大きさは推定";
125
+ readonly hero_scale: "円が実際の大きさです。上の衛星は見える大きさに描いています。";
114
126
  };
115
127
  };
@@ -56,6 +56,12 @@ export const MOON_PAGE_WORDS = {
56
56
  table_note: "≈ marks a size worked out from the moon's brightness, not measured. — means no source gives it. The place of discovery is known here only for the moons drawn in full, which are in bold.",
57
57
  credits: "Every number on this page is the package's own, worked out when the page was built: the moons, their orbits, sizes and discoveries from NASA/JPL's moon pages and Horizons, read on {fetched}, and the places of discovery from the IAU Gazetteer.",
58
58
  short: "{total} moons · {named} named · {retrograde} go the other way",
59
+ hero_moons: "Main moons",
60
+ full_screen: "Full screen",
61
+ leave_full_screen: "Leave full screen",
62
+ hero_fact: "{name}: {diameter} km across, {distance} km from {planet}. Found {found}.",
63
+ hero_estimated: "* shape or size estimated",
64
+ hero_scale: "The circles are the true sizes. The moons above are drawn large enough to see.",
59
65
  },
60
66
  ja: {
61
67
  tabs: "表示",
@@ -112,5 +118,11 @@ export const MOON_PAGE_WORDS = {
112
118
  table_note: "≈ は、測定ではなく衛星の明るさから見積もった大きさです。— は、資料に値がないことを表します。発見した場所は、くわしく描いている衛星(太字)だけにあります。",
113
119
  credits: "このページの数字はすべて、ページを作ったときにパッケージのデータから計算したものです。衛星の軌道・大きさ・発見は NASA/JPL の衛星のページと Horizons({fetched}に読み込み)から、発見した場所は IAU 惑星地名辞典からです。",
114
120
  short: "衛星{total}個・名前つき{named}個・反対向き{retrograde}個",
121
+ hero_moons: "主な衛星",
122
+ full_screen: "全画面",
123
+ leave_full_screen: "全画面をやめる",
124
+ hero_fact: "{name}:直径 {diameter} km、{planet}から {distance} km。発見は{found}。",
125
+ hero_estimated: "* 形や大きさは推定",
126
+ hero_scale: "円が実際の大きさです。上の衛星は見える大きさに描いています。",
115
127
  },
116
128
  };
@@ -285,7 +285,7 @@ export interface Preset {
285
285
  scene: Portrait;
286
286
  }
287
287
  /**
288
- * Ready-made scenes to start from: a family photo of the Sun and the planets, the gas giants to scale, Jupiter and the Galileans, the Earth and the Moon to scale (size and distance), Mars and its moons at their true distance, and the inner planets round the Sun.
288
+ * Ready-made scenes to start from: a family photo of the Sun and the planets, the gas giants to scale, Jupiter and the Galileans, the Earth and the Moon to scale (size and distance), Mars and its moons at their true distance, the inner planets round the Sun, a giant planet's edge with its main moons in an arc, and every drawn moon beside its planet.
289
289
  *
290
290
  * @example
291
291
  * ```ts
@@ -692,8 +692,85 @@ export function decodeScene(text) {
692
692
  return p;
693
693
  }
694
694
  const fromList = (ids, change = {}) => ids.reduce((p, id) => addBody(p, id), { ...defaultPortrait(), ...change });
695
+ /** The poster arc, farthest from the planet first. These are the moons the package draws. */
696
+ const POSTER_ARC = {
697
+ jupiter: ["callisto", "ganymede", "europa", "io"],
698
+ saturn: ["iapetus", "titan", "rhea", "dione", "tethys", "enceladus", "mimas"],
699
+ uranus: ["oberon", "titania", "umbriel", "ariel", "miranda"],
700
+ neptune: ["nereid", "triton", "proteus"],
701
+ };
702
+ /** The turn that puts the familiar face toward the moons. Saturn looks over the pole so the near half of the rings crosses the lower globe. */
703
+ const POSTER_POSE = {
704
+ jupiter: { spin: 70, tilt: 14 },
705
+ saturn: { spin: 30, tilt: 26.73, pitch: 22 },
706
+ uranus: { spin: 10, tilt: 16 },
707
+ neptune: { spin: 20, tilt: 16 },
708
+ };
709
+ /** A manual scene of one poster: the planet large at the right, its main moons in an arc, farthest at the top. Saturn's first step is longer, so Iapetus sits clear of Titan. */
710
+ function posterEdge(host) {
711
+ const moons = POSTER_ARC[host];
712
+ const aspect = 16 / 9;
713
+ const count = moons.length;
714
+ const sized = sizesFor(moons, "readable");
715
+ const moonScale = (count <= 4 ? 0.2 : 0.13) / Math.max(...sized);
716
+ const pose = POSTER_POSE[host];
717
+ const planetR = host === "jupiter" ? 0.72 : 0.82 / reachOf(host);
718
+ const planet = {
719
+ body: host,
720
+ x: aspect * 0.92 - planetR * 0.15,
721
+ y: 0,
722
+ r: planetR,
723
+ spin: pose.spin,
724
+ tilt: pose.tilt,
725
+ turn: 0,
726
+ ...(pose.pitch !== undefined ? { pitch: pose.pitch } : {}),
727
+ };
728
+ let y = 0.78;
729
+ let previous = 0;
730
+ const items = [
731
+ planet,
732
+ ...moons.map((id, index) => {
733
+ const even = count <= 1 ? 0 : index / (count - 1);
734
+ const r = sized[index] * moonScale;
735
+ if (index > 0)
736
+ y -= previous + r + (host === "saturn" && index === 1 ? 0.16 : 0.04);
737
+ previous = r;
738
+ return { body: id, x: -aspect + (0.16 + even * 0.14) * 2 * aspect, y, r, spin: BODIES[id].showLon ?? 0, turn: 0 };
739
+ }),
740
+ ];
741
+ return { ...defaultPortrait(), items, layout: "manual", arrange: "arc", scale: "readable", moons: "manual", orbits: false, labels: true, aspect, camera: { x: 0, y: 0, h: 1 } };
742
+ }
743
+ /** A manual scene of the groups poster: each giant planet with the moons the package draws, in a row beside it. */
744
+ function posterGroups() {
745
+ const hosts = ["jupiter", "saturn", "uranus", "neptune"];
746
+ const aspect = 16 / 9;
747
+ const rows = hosts.map((host) => {
748
+ const ids = [host, ...[...MOONS_OF[host]].sort(byDistance)];
749
+ const sized = sizesFor(ids, "readable");
750
+ const scale = 0.22 / Math.max(...sized);
751
+ return ids.map((id, index) => {
752
+ const r = Math.max(0.04, sized[index] * scale);
753
+ return { id, r, span: r * (id === "saturn" ? reachOf(id) : 1.15) };
754
+ });
755
+ });
756
+ const gap = 0.1;
757
+ const heights = rows.map((row) => Math.max(...row.map((body) => body.span)) * 2);
758
+ let yCursor = heights.reduce((sum, height) => sum + height, 0) / 2 + (gap * (rows.length - 1)) / 2;
759
+ const items = [];
760
+ rows.forEach((row, index) => {
761
+ const y = yCursor - heights[index] / 2;
762
+ yCursor -= heights[index] + gap;
763
+ let x = 0;
764
+ row.forEach((body, place) => {
765
+ x += body.span;
766
+ items.push({ body: body.id, x, y, r: body.r, spin: BODIES[body.id].showLon ?? 0, turn: 0 });
767
+ x += body.span + (place === 0 ? 0.12 : 0.04);
768
+ });
769
+ });
770
+ return fitAll({ ...defaultPortrait(), items, layout: "manual", arrange: "row", scale: "readable", moons: "manual", orbits: false, labels: false, aspect, camera: { x: 0, y: 0, h: 1 } });
771
+ }
695
772
  /**
696
- * Ready-made scenes to start from: a family photo of the Sun and the planets, the gas giants to scale, Jupiter and the Galileans, the Earth and the Moon to scale (size and distance), Mars and its moons at their true distance, and the inner planets round the Sun.
773
+ * Ready-made scenes to start from: a family photo of the Sun and the planets, the gas giants to scale, Jupiter and the Galileans, the Earth and the Moon to scale (size and distance), Mars and its moons at their true distance, the inner planets round the Sun, a giant planet's edge with its main moons in an arc, and every drawn moon beside its planet.
697
774
  *
698
775
  * @example
699
776
  * ```ts
@@ -709,4 +786,9 @@ export const PRESETS = [
709
786
  { id: "earthmoon", name: { en: "Earth and Moon to scale", ja: "地球と月 (大きさと距離の比)" }, scene: fromList(["earth", "moon"], { arrange: "orbit", scale: "true", moons: "auto", orbits: true }) },
710
787
  { id: "marsmoons", name: { en: "Mars and its moons at true distance", ja: "火星と衛星 (本当の距離)" }, scene: fromList(["mars", "phobos", "deimos"], { arrange: "orbit", scale: "readable", moons: "auto", orbits: true }) },
711
788
  { id: "orrery", name: { en: "The inner planets round the Sun", ja: "太陽と内側の惑星 (本当の距離)" }, scene: fromList(["sun", "mercury", "venus", "earth", "mars"], { arrange: "orbit", scale: "readable", moons: "auto", orbits: true, bg: "black" }) },
789
+ { id: "jupiter-edge", name: { en: "Jupiter's edge", ja: "木星の縁" }, scene: posterEdge("jupiter") },
790
+ { id: "saturn-edge", name: { en: "Saturn's edge", ja: "土星の縁" }, scene: posterEdge("saturn") },
791
+ { id: "uranus-edge", name: { en: "Uranus's edge", ja: "天王星の縁" }, scene: posterEdge("uranus") },
792
+ { id: "neptune-edge", name: { en: "Neptune's edge", ja: "海王星の縁" }, scene: posterEdge("neptune") },
793
+ { id: "moons-by-planet", name: { en: "Moons beside their planet", ja: "惑星のそばの衛星" }, scene: posterGroups() },
712
794
  ];
@@ -64,6 +64,8 @@ export interface BodyItemOptions {
64
64
  facts?: BodyFacts;
65
65
  /** What the renderer keeps this body's materials under, instead of `id`: a star's key, so two stars do not share a program. */
66
66
  assetKey?: string;
67
+ /** A coarse globe for an estimated rock: 48 by 24 on a large picture, 24 by 12 on a card, 12 by 6 when it is small. A page may hold every moon of a planet. */
68
+ coarse?: boolean;
67
69
  look: "realistic" | "painted";
68
70
  /** A key that changes whenever the picture would: the renderer keeps one still for each key. */
69
71
  key: string;
@@ -46,6 +46,13 @@ export function makeBodyMaterial(T, look, painted) {
46
46
  uRingOn: { value: 0 },
47
47
  uRingTex: { value: null },
48
48
  uMap: { value: null },
49
+ ...(look.rock === undefined
50
+ ? {}
51
+ : {
52
+ uRockSeed: { value: look.rock.seed },
53
+ uRockDark: { value: new T.Vector3(...look.rock.dark) },
54
+ uRockLight: { value: new T.Vector3(...look.rock.light) },
55
+ }),
49
56
  },
50
57
  });
51
58
  }
@@ -72,8 +79,11 @@ export function createBodyItem(options) {
72
79
  const wantPainted = (options.look === "painted" || look.mapped === true) && look.painted !== undefined;
73
80
  // a moon with a published shape model is the globe moved to its radii (its table is a chunk of its own, waited for here), and then needs no stretching to an ellipsoid
74
81
  const shapeTable = look.shape === undefined ? undefined : await look.shape().catch(() => undefined);
75
- // a big picture gets a globe of 192 by 96 steps (as the unshaped sphere has), a tile or a card one of 96 by 48: a page can hold a dozen moons, and the arrays of a globe stay in the page
76
- const grid = Math.min(width, height) >= 300 ? { lon: 192, lat: 96 } : { lon: 96, lat: 48 };
82
+ // a big picture gets a globe of 192 by 96 steps (as the unshaped sphere has), a tile or a card one of 96 by 48: a page can hold a dozen moons, and the arrays of a globe stay in the page.
83
+ // an estimated rock is coarser: 48 by 24 on a large picture, 24 by 12 on a card, 12 by 6 when it is small, so a page can hold every moon of Jupiter
84
+ const grid = options.coarse === true
85
+ ? (Math.min(width, height) >= 280 ? { lon: 48, lat: 24 } : Math.min(width, height) >= 140 ? { lon: 24, lat: 12 } : { lon: 12, lat: 6 })
86
+ : (Math.min(width, height) >= 300 ? { lon: 192, lat: 96 } : { lon: 96, lat: 48 });
77
87
  const geometry = shapeTable === undefined ? assets.acquire("wk:sphere", () => new T.SphereGeometry(1, 192, 96), (g) => g.dispose()) : assets.acquire(`wk:shape:${held}:${grid.lon}`, () => shapeGeometry(T, shapeTable, facts.radiusKm, grid), (g) => g.dispose());
78
88
  const shader = assets.acquire(`wk:body:${held}:r`, () => makeBodyMaterial(T, look, false), (m) => m.dispose());
79
89
  const paintedMaterial = wantPainted ? assets.acquire(`wk:body:${held}:p`, () => makeBodyMaterial(T, look, true), (m) => m.dispose()) : undefined;
@@ -136,8 +146,8 @@ export function createBodyItem(options) {
136
146
  ringTexture = assets.acquire(`wk:ringtex:${ringKey}`, () => {
137
147
  if (photoTexture !== undefined) {
138
148
  photoTexture.magFilter = T.LinearFilter;
139
- photoTexture.minFilter = T.LinearFilter;
140
- photoTexture.generateMipmaps = false;
149
+ photoTexture.minFilter = 1008; // LinearMipmapLinearFilter: the ring is drawn smaller than its picture, and a linear sample of the full picture stair-steps the edges
150
+ photoTexture.generateMipmaps = true;
141
151
  photoTexture.wrapS = T.ClampToEdgeWrapping;
142
152
  photoTexture.colorSpace = T.NoColorSpace;
143
153
  return photoTexture;
@@ -0,0 +1,57 @@
1
+ import { type BodyFacts, type HostId } from "../facts.ts";
2
+ import type { BodyLook } from "./look.ts";
3
+ import { type ShapeTable } from "./shape.ts";
4
+ /** Where a catalogue radius comes from. `derived` was worked out from the brightness. `unknown` means the catalogue gives no size, and the rock is drawn at 1 km so the poster still has a picture. */
5
+ export type EstimatedSize = "measured" | "sheet" | "derived" | "unknown";
6
+ /** The colour class of an albedo. Unknown is neutral grey. */
7
+ export type AlbedoTone = "dark" | "mid" | "bright" | "grey";
8
+ /** One estimated rock, ready for `<wakusei-body>`. */
9
+ export interface EstimatedRock {
10
+ id: string;
11
+ host: HostId;
12
+ label: string;
13
+ /** The mean radius in kilometres. 1 when the catalogue gives no size. */
14
+ radiusKm: number;
15
+ sizeFrom: EstimatedSize;
16
+ albedo: number | null;
17
+ tone: AlbedoTone;
18
+ /** The flat colour of the line drawing, `#rrggbb`. */
19
+ colour: string;
20
+ /** The seed of the shape and of the craters. The same id has the same seed. */
21
+ seed: number;
22
+ facts: BodyFacts;
23
+ look: BodyLook;
24
+ /** The words under the picture: the shape is always a guess, and a derived or unknown size says so. */
25
+ note: {
26
+ en: string;
27
+ ja: string;
28
+ };
29
+ /** The short line drawn on the picture: the catalogue name and a star. The longer `note` is the accessible name. */
30
+ line: {
31
+ en: string;
32
+ ja: string;
33
+ };
34
+ /** One line for a picture that shows estimated moons: what the star means. */
35
+ legend: {
36
+ en: string;
37
+ ja: string;
38
+ };
39
+ /** The guessed shape. The same object every time for this rock. */
40
+ table: ShapeTable;
41
+ }
42
+ /**
43
+ * One surface shader for every estimated rock. `uRockSeed`, `uRockDark` and `uRockLight` are that moon's own, set on its material, so the page compiles this once.
44
+ */
45
+ export declare const ESTIMATED_SURFACE = "\nuniform float uRockSeed;\nuniform vec3 uRockDark;\nuniform vec3 uRockLight;\nvec4 surface(vec3 p) {\n float h1 = craters(p, 3.0, 0.85, uRockSeed);\n float h2 = craters(p, 8.0, 0.55, uRockSeed + 7.0) * 0.6;\n float h3 = craters(p, 18.0, 0.40, uRockSeed + 3.0) * 0.3;\n float h = h1 + h2 + h3;\n float hr = h1 * reliefShare(p, 3.0) + h2 * reliefShare(p, 8.0) + h3 * reliefShare(p, 18.0);\n float tone = fbm(p * 2.4 + uRockSeed);\n vec3 col = mix(uRockDark, uRockLight, smoothstep(0.25, 0.75, tone));\n col *= 1.0 + 0.9 * h;\n return vec4(col, hr);\n}";
46
+ /** The albedo class: dark under 0.08, mid under 0.25, bright from there, and grey when the albedo is unknown. */
47
+ export declare function albedoTone(albedo: number | null): AlbedoTone;
48
+ /** How far the longest radius is past the shortest. A potato is well above 1; a globe is near 1. */
49
+ export declare function rockSpread(seed: number, radiusKm: number): number;
50
+ /**
51
+ * The estimated rock for a catalogue id, a name or a designation (`himalia`, `Himalia`, `S/2003 J 18`). `null` for a body the package draws in full, and for a name that is not a moon.
52
+ *
53
+ * @param query - The catalogue id, name or designation.
54
+ * @returns The rock, or `null`.
55
+ */
56
+ export declare function estimatedRock(query: string): EstimatedRock | null;
57
+ export declare function estimatedRockLine(rock: EstimatedRock, size: number): string;
@@ -0,0 +1,293 @@
1
+ // An irregular moon the package does not draw in full: a coarse rock, sized from the catalogue, coloured from its albedo, with a shape guessed from its id.
2
+ // The same id always builds the same rock. A full moon (one in the body's table) is not one of these. Nothing here draws; the element asks.
3
+ import { BODIES } from "../facts.js";
4
+ import { ESTIMATED_MOONS } from "../data/estimated-moons.js";
5
+ import { shapeRadii } from "./shape.js";
6
+ const SIZES = ["measured", "sheet", "derived", "unknown"];
7
+ const TONES = {
8
+ grey: { colour: "#6e7278", dark: [0.28, 0.29, 0.31], light: [0.46, 0.48, 0.51] },
9
+ dark: { colour: "#3a342e", dark: [0.08, 0.07, 0.06], light: [0.2, 0.18, 0.16] },
10
+ mid: { colour: "#8a8174", dark: [0.38, 0.34, 0.28], light: [0.62, 0.58, 0.5] },
11
+ bright: { colour: "#d5d8dc", dark: [0.72, 0.74, 0.77], light: [0.94, 0.95, 0.97] },
12
+ };
13
+ /**
14
+ * One surface shader for every estimated rock. `uRockSeed`, `uRockDark` and `uRockLight` are that moon's own, set on its material, so the page compiles this once.
15
+ */
16
+ export const ESTIMATED_SURFACE = `
17
+ uniform float uRockSeed;
18
+ uniform vec3 uRockDark;
19
+ uniform vec3 uRockLight;
20
+ vec4 surface(vec3 p) {
21
+ float h1 = craters(p, 3.0, 0.85, uRockSeed);
22
+ float h2 = craters(p, 8.0, 0.55, uRockSeed + 7.0) * 0.6;
23
+ float h3 = craters(p, 18.0, 0.40, uRockSeed + 3.0) * 0.3;
24
+ float h = h1 + h2 + h3;
25
+ float hr = h1 * reliefShare(p, 3.0) + h2 * reliefShare(p, 8.0) + h3 * reliefShare(p, 18.0);
26
+ float tone = fbm(p * 2.4 + uRockSeed);
27
+ vec3 col = mix(uRockDark, uRockLight, smoothstep(0.25, 0.75, tone));
28
+ col *= 1.0 + 0.9 * h;
29
+ return vec4(col, hr);
30
+ }`;
31
+ /** The albedo class: dark under 0.08, mid under 0.25, bright from there, and grey when the albedo is unknown. */
32
+ export function albedoTone(albedo) {
33
+ if (albedo === null || !Number.isFinite(albedo))
34
+ return "grey";
35
+ if (albedo < 0.08)
36
+ return "dark";
37
+ if (albedo < 0.25)
38
+ return "mid";
39
+ return "bright";
40
+ }
41
+ const plain = (value) => value.toLowerCase().normalize("NFKD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]/g, "");
42
+ function hashId(id) {
43
+ let h = 2166136261;
44
+ for (let i = 0; i < id.length; i += 1) {
45
+ h ^= id.charCodeAt(i);
46
+ h = Math.imul(h, 16777619);
47
+ }
48
+ return h >>> 0;
49
+ }
50
+ function hash01(seed, i, salt) {
51
+ let h = Math.imul(seed ^ Math.imul(i + 1, 0x9e3779b1), 0x85ebca6b) ^ Math.imul(salt, 0xc2b2ae35);
52
+ h = Math.imul(h ^ (h >>> 16), 0x7feb352d);
53
+ h = Math.imul(h ^ (h >>> 15), 0x846ca68b);
54
+ return ((h ^ (h >>> 16)) >>> 0) / 4294967296;
55
+ }
56
+ /** A lump in about -1 to 1, the same for the same seed and direction. */
57
+ function noise(seed, x, y, z) {
58
+ let n = 0;
59
+ let w = 0;
60
+ for (let i = 0; i < 4; i += 1) {
61
+ const cx = hash01(seed, i, 1) * 2 - 1;
62
+ const cy = hash01(seed, i, 2) * 2 - 1;
63
+ const cz = hash01(seed, i, 3) * 2 - 1;
64
+ const amp = 0.55 + hash01(seed, i, 4);
65
+ n += (amp * (x * cx + y * cy + z * cz)) / (Math.hypot(cx, cy, cz) || 1);
66
+ w += amp;
67
+ }
68
+ return n / w;
69
+ }
70
+ const clampLump = (value) => Math.min(1.7, Math.max(0.45, value));
71
+ /** Turn a direction by this rock's seed, so the long axis does not point the same way on every moon. */
72
+ function spin(seed, x, y, z) {
73
+ const yaw = hash01(seed, 8, 31) * Math.PI * 2;
74
+ const pitch = (hash01(seed, 9, 32) - 0.5) * Math.PI;
75
+ const roll = hash01(seed, 10, 33) * Math.PI * 2;
76
+ const cy = Math.cos(yaw);
77
+ const sy = Math.sin(yaw);
78
+ const x1 = cy * x + sy * z;
79
+ const z1 = -sy * x + cy * z;
80
+ const cp = Math.cos(pitch);
81
+ const sp = Math.sin(pitch);
82
+ const y2 = cp * y - sp * z1;
83
+ const z2 = sp * y + cp * z1;
84
+ const cr = Math.cos(roll);
85
+ const sr = Math.sin(roll);
86
+ return [cr * x1 - sr * y2, sr * x1 + cr * y2, z2];
87
+ }
88
+ /** How round the rock is: 0 is a potato (under 100 km), 1 is a globe (200 km and up), and the sizes between blend. */
89
+ function roundness(radiusKm) {
90
+ if (radiusKm >= 200)
91
+ return 1;
92
+ if (radiusKm <= 100)
93
+ return 0;
94
+ return (radiusKm - 100) / 100;
95
+ }
96
+ /**
97
+ * The three axes, longest first. A small moon is about 1 : 0.6–0.9 : 0.5–0.8, from its seed. A large one is 1 : 1 : 1.
98
+ */
99
+ function axesOf(seed, radiusKm) {
100
+ const round = roundness(radiusKm);
101
+ const b0 = 0.6 + 0.3 * hash01(seed, 1, 21);
102
+ const c0 = 0.5 + 0.3 * hash01(seed, 2, 22);
103
+ const b = Math.max(b0, c0);
104
+ const c = Math.min(b0, c0);
105
+ return [1, b + (1 - b) * round, c + (1 - c) * round];
106
+ }
107
+ /** The radius of an ellipsoid in a direction, as a fraction of its longest axis. */
108
+ function ellipsoid(x, y, z, axes) {
109
+ const t = (x * x) / (axes[0] * axes[0]) + (y * y) / (axes[1] * axes[1]) + (z * z) / (axes[2] * axes[2]);
110
+ return t > 0 ? 1 / Math.sqrt(t) : 1;
111
+ }
112
+ /**
113
+ * A table of radii whose mean is `radiusKm`. A small moon is elongated, a large one nearly round, and both carry the same lumps. The poles are one radius each.
114
+ * The steps fit in 16 bits: the unit is chosen from twelve times the radius, which covers a potato's gap between neighbours.
115
+ */
116
+ function shapeOf(seed, radiusKm) {
117
+ const lon = 16;
118
+ const lat = 8;
119
+ const rows = lat + 1;
120
+ const axes = axesOf(seed, radiusKm);
121
+ const lump = 0.35 * (1 - roundness(radiusKm));
122
+ const raw = [];
123
+ const at = (x, y, z) => {
124
+ const [rx, ry, rz] = spin(seed, x, y, z);
125
+ return clampLump(1 + lump * noise(seed, rx, ry, rz)) * ellipsoid(rx, ry, rz, axes);
126
+ };
127
+ for (let row = 0; row < rows; row += 1) {
128
+ const phi = (Math.PI * row) / lat;
129
+ const st = Math.sin(phi);
130
+ const z = Math.cos(phi);
131
+ const pole = row === 0 || row === lat ? at(0, 0, row === 0 ? 1 : -1) : undefined;
132
+ for (let column = 0; column < lon; column += 1) {
133
+ if (pole !== undefined) {
134
+ raw.push(pole);
135
+ continue;
136
+ }
137
+ const theta = (2 * Math.PI * column) / lon;
138
+ raw.push(at(st * Math.cos(theta), st * Math.sin(theta), z));
139
+ }
140
+ }
141
+ const mean = raw.reduce((sum, value) => sum + value, 0) / raw.length;
142
+ const km = raw.map((value) => (value / mean) * radiusKm);
143
+ const unit = Math.max(1, Math.floor(30000 / (12 * radiusKm + 1)));
144
+ const whole = km.map((value) => Math.round(value * unit));
145
+ const steps = new Int16Array(lon * rows);
146
+ for (let row = 0; row < rows; row += 1) {
147
+ for (let column = 0; column < lon; column += 1) {
148
+ const i = row * lon + column;
149
+ const above = row > 0 ? whole[i - lon] : 0;
150
+ const left = column > 0 ? whole[i - 1] : 0;
151
+ const aboveLeft = row > 0 && column > 0 ? whole[i - lon - 1] : 0;
152
+ const predicted = column === 0 ? above : row === 0 ? left : left + above - aboveLeft;
153
+ steps[i] = whole[i] - predicted;
154
+ }
155
+ }
156
+ const bytes = new Uint8Array(steps.buffer, steps.byteOffset, steps.byteLength);
157
+ let binary = "";
158
+ for (const byte of bytes)
159
+ binary += String.fromCharCode(byte);
160
+ return { lon, lat, unit, steps: btoa(binary) };
161
+ }
162
+ /** How far the longest radius is past the shortest. A potato is well above 1; a globe is near 1. */
163
+ export function rockSpread(seed, radiusKm) {
164
+ const radii = shapeRadii(shapeOf(seed, radiusKm));
165
+ let low = Number.POSITIVE_INFINITY;
166
+ let high = 0;
167
+ for (const radius of radii) {
168
+ if (radius < low)
169
+ low = radius;
170
+ if (radius > high)
171
+ high = radius;
172
+ }
173
+ return high / low;
174
+ }
175
+ function notes(size) {
176
+ if (size === "derived")
177
+ return { en: "Shape estimated. Size estimated from brightness.", ja: "形は推定。大きさは明るさからの推定" };
178
+ if (size === "unknown")
179
+ return { en: "Shape estimated. Size unknown.", ja: "形は推定。大きさは不明" };
180
+ return { en: "Shape estimated.", ja: "形は推定" };
181
+ }
182
+ let byKey;
183
+ function index() {
184
+ if (byKey !== undefined)
185
+ return byKey;
186
+ byKey = new Map();
187
+ for (const row of ESTIMATED_MOONS)
188
+ byKey.set(plain(row[2]), row);
189
+ for (const row of ESTIMATED_MOONS)
190
+ byKey.set(plain(row[0]), row);
191
+ return byKey;
192
+ }
193
+ const cache = new Map();
194
+ function build(row) {
195
+ const [id, hostName, label, tenths, sizeCode, albedoThousandths] = row;
196
+ const host = hostName;
197
+ const sizeFrom = SIZES[sizeCode];
198
+ const radiusKm = tenths > 0 ? tenths / 10 : 1;
199
+ const albedo = albedoThousandths < 0 ? null : albedoThousandths / 1000;
200
+ const tone = albedoTone(albedo);
201
+ const paint = TONES[tone];
202
+ const seed = hashId(id);
203
+ const table = shapeOf(seed, radiusKm);
204
+ const facts = {
205
+ id: host,
206
+ kind: "moon",
207
+ parent: host,
208
+ name: { en: label, ja: label },
209
+ radiusKm,
210
+ flattening: 0,
211
+ tiltDeg: 0,
212
+ pole: { ra: hash01(seed, 3, 41) * 360, dec: 30 + hash01(seed, 4, 42) * 60 },
213
+ prime: { w0: hash01(seed, 5, 43) * 360, rate: 360 },
214
+ rotationHours: 24,
215
+ colour: paint.colour,
216
+ };
217
+ const look = {
218
+ id: host,
219
+ surface: ESTIMATED_SURFACE,
220
+ relief: 0.85,
221
+ ambient: 0.08,
222
+ wrap: 0.08,
223
+ detail: { amount: 0.2, stretch: 1 },
224
+ rock: { seed: (seed % 10000) / 100, dark: paint.dark, light: paint.light },
225
+ shape: () => Promise.resolve(table),
226
+ };
227
+ return { id, host, label, radiusKm, sizeFrom, albedo, tone, colour: paint.colour, seed, facts, look, note: notes(sizeFrom), line: { en: `${label}*`, ja: `${label}*` }, legend: { en: "* shape or size estimated", ja: "* 形や大きさは推定" }, table };
228
+ }
229
+ /**
230
+ * The estimated rock for a catalogue id, a name or a designation (`himalia`, `Himalia`, `S/2003 J 18`). `null` for a body the package draws in full, and for a name that is not a moon.
231
+ *
232
+ * @param query - The catalogue id, name or designation.
233
+ * @returns The rock, or `null`.
234
+ */
235
+ export function estimatedRock(query) {
236
+ const key = plain(query);
237
+ if (key === "" || key in BODIES)
238
+ return null;
239
+ const row = index().get(key);
240
+ if (row === undefined)
241
+ return null;
242
+ let rock = cache.get(row[0]);
243
+ if (rock === undefined) {
244
+ rock = build(row);
245
+ cache.set(row[0], rock);
246
+ }
247
+ return rock;
248
+ }
249
+ /**
250
+ * The line drawing of an estimated rock: a smooth outline of its guessed shape, lighter on one side. Not a body's line drawing.
251
+ *
252
+ * @param rock - The rock.
253
+ * @param size - The picture's width in pixels.
254
+ * @returns The SVG.
255
+ */
256
+ const shade = (hex, toward, amount) => {
257
+ const n = Number.parseInt(hex.slice(1), 16);
258
+ const channel = (shift) => {
259
+ const value = (n >> shift) & 255;
260
+ return Math.round(value + (toward - value) * amount);
261
+ };
262
+ return `#${((channel(16) << 16) | (channel(8) << 8) | channel(0)).toString(16).padStart(6, "0")}`;
263
+ };
264
+ export function estimatedRockLine(rock, size) {
265
+ const span = Math.max(32, Math.round(size));
266
+ const radii = shapeRadii(rock.table);
267
+ const row = rock.table.lat / 2;
268
+ const lon = rock.table.lon;
269
+ const steps = 96;
270
+ const cx = span / 2;
271
+ const cy = span / 2;
272
+ const reach = span * 0.36;
273
+ const radiusAt = (t) => {
274
+ const x = (((t % 1) + 1) % 1) * lon;
275
+ const i = Math.floor(x) % lon;
276
+ const f = x - Math.floor(x);
277
+ const smooth = f * f * (3 - 2 * f);
278
+ const a = radii[row * lon + i] / rock.radiusKm;
279
+ const b = radii[row * lon + ((i + 1) % lon)] / rock.radiusKm;
280
+ return a + (b - a) * smooth;
281
+ };
282
+ let d = "";
283
+ for (let k = 0; k < steps; k += 1) {
284
+ const t = k / steps;
285
+ const radius = radiusAt(t);
286
+ const theta = 2 * Math.PI * t;
287
+ const x = cx + Math.cos(theta) * reach * radius;
288
+ const y = cy + Math.sin(theta) * reach * radius;
289
+ d += `${k === 0 ? "M" : "L"}${x.toFixed(1)} ${y.toFixed(1)}`;
290
+ }
291
+ const id = `rock-${rock.id}`;
292
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${span} ${span}" role="presentation"><defs><radialGradient id="${id}" cx="36%" cy="32%" r="78%"><stop offset="0" stop-color="${shade(rock.colour, 255, 0.45)}"/><stop offset="1" stop-color="${shade(rock.colour, 0, 0.5)}"/></radialGradient></defs><path d="${d}Z" fill="url(#${id})"/></svg>`;
293
+ }
@@ -105,6 +105,15 @@ export interface BodyLook {
105
105
  * ellipsoid of `axesKm`. Until it arrives the ellipsoid is drawn.
106
106
  */
107
107
  shape?: () => Promise<ShapeTable>;
108
+ /**
109
+ * An estimated rock shares one surface shader. These uniforms are that moon's own: a seed so the craters differ, and the dark and light colours of its albedo class.
110
+ * Only a look whose `surface` reads `uRockSeed`, `uRockDark` and `uRockLight` sets this.
111
+ */
112
+ rock?: {
113
+ seed: number;
114
+ dark: readonly [number, number, number];
115
+ light: readonly [number, number, number];
116
+ };
108
117
  /** Draw the painted map in the realistic look too: for a body with no honest drawing from numbers (the Earth's continents). */
109
118
  mapped?: boolean;
110
119
  }