Say what is known about a world, and how it is known
Four changes to the readout panel and the body cards, which between them were showing less than the catalogues hold and not always distinguishing a measurement from an inference. Picking a planet used to navigate straight to /body/:id. That tore down the system scene and the camera with it, so comparing two planets meant flying back into the system between each. Hovering a body now raises a card over the live view and clicking pins it; Full view still opens the route for the full 3D inspection. Clicking empty space unpins, and leaving the system clears it. The card and the detail page were assembling "what do we know about this world" independently, which is the shape of bug where a planet reads 255 K in one panel and 254 K in the other. Both now build from one shared view model. Orbital period was absent everywhere. For a heliocentric orbit it follows exactly from the semi-major axis, because in these units the Sun's mass is the unit of mass — Mars comes back 687.0 d against a published 686.98. It is deliberately not computed for moons, whose elements are relative to a parent planet the catalogue has no mass for, nor for exoplanets: periodDays is populated for none of the 6319 shipped records and hostStarMassSolar for none either, so any figure would assume a solar-mass host and mis-state every planet around an M dwarf. Where a period does exist it is filed under Measured or Derived according to which it is, not by its field name. The system readout showed a flat 0.00 pc for the Sun's distance, which is arithmetically right and reads as a bug — the distance from here to here is not a measurement, so it is suppressed. It gains the host star's luminosity, marked as derived, and counts moons separately from planets. The neighbourhood readout gains the one thing the star field cannot show: how many of those points can actually be entered. Derived readouts carry a marker and a footnote saying so. Every quantity now formats through one module whose precision follows magnitude, rather than a fixed decimal count per call site that read as false precision at one end and lost real information at the other: 0.0026 AU stays legible instead of rounding to 0.00, and Pluto's period reads 248 yr rather than 90560 d. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WaySiNst4HhDXBHnMy8p5G
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { BodyRecord, OrbitalElements } from '../../shared/models/body.model';
|
||||
import { ExoplanetRecord } from '../../shared/models/exoplanet.model';
|
||||
import { StarRecord, SUN_STAR_ID } from '../../shared/models/star.model';
|
||||
import { buildBodyViewModel, heliocentricPeriodDays } from './body-view-model';
|
||||
|
||||
const orbit = (overrides: Partial<OrbitalElements> = {}): OrbitalElements => ({
|
||||
semiMajorAxisAu: 1,
|
||||
eccentricity: 0.0167,
|
||||
inclinationDeg: 0,
|
||||
longitudeOfAscendingNodeDeg: 0,
|
||||
argumentOfPeriapsisDeg: 0,
|
||||
meanAnomalyAtEpochDeg: 0,
|
||||
epochJd: 2451545,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const sun: StarRecord = {
|
||||
id: SUN_STAR_ID,
|
||||
name: 'Sol',
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0,
|
||||
magnitude: -26.7,
|
||||
spectralType: 'G2V',
|
||||
colorIndex: 0.65,
|
||||
};
|
||||
|
||||
const earth: BodyRecord = {
|
||||
id: 'earth',
|
||||
systemStarId: SUN_STAR_ID,
|
||||
name: 'Earth',
|
||||
kind: 'planet',
|
||||
radiusKm: 6371,
|
||||
orbit: orbit(),
|
||||
};
|
||||
const luna: BodyRecord = {
|
||||
id: 'luna',
|
||||
systemStarId: SUN_STAR_ID,
|
||||
name: 'Moon',
|
||||
kind: 'moon',
|
||||
radiusKm: 1737,
|
||||
parentBodyId: 'earth',
|
||||
orbit: orbit({ semiMajorAxisAu: 0.00257 }),
|
||||
};
|
||||
|
||||
describe('heliocentricPeriodDays', () => {
|
||||
it('recovers a known period from the semi-major axis alone', () => {
|
||||
// P² = a³ in these units, so Earth must come back a year.
|
||||
expect(heliocentricPeriodDays(earth)).toBeCloseTo(365.25, 1);
|
||||
});
|
||||
|
||||
it('scales as the three-halves power', () => {
|
||||
const jupiter: BodyRecord = {
|
||||
...earth,
|
||||
id: 'jupiter',
|
||||
name: 'Jupiter',
|
||||
orbit: orbit({ semiMajorAxisAu: 5.2044 }),
|
||||
};
|
||||
// Jupiter's real sidereal period is 4332.6 days.
|
||||
expect(heliocentricPeriodDays(jupiter)).toBeCloseTo(4335, -1);
|
||||
});
|
||||
|
||||
it('refuses to compute a period for a moon', () => {
|
||||
// A moon's elements are relative to its planet, whose mass is not in the catalogue — the
|
||||
// same arithmetic would be wrong by the ratio of that planet's mass to the Sun's.
|
||||
expect(heliocentricPeriodDays(luna)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildBodyViewModel', () => {
|
||||
const catalogues = { bodies: [earth, luna], exoplanets: [] as ExoplanetRecord[], stars: [sun] };
|
||||
|
||||
it('marks a period computed from the semi-major axis as derived', () => {
|
||||
const model = buildBodyViewModel('earth', catalogues);
|
||||
expect(model?.orbitalPeriodSource).toBe('derived');
|
||||
expect(model?.orbitalPeriodDays).toBeCloseTo(365.25, 1);
|
||||
});
|
||||
|
||||
it('leaves a moon without a period rather than inventing one', () => {
|
||||
const model = buildBodyViewModel('luna', catalogues);
|
||||
expect(model?.orbitalPeriodDays).toBeUndefined();
|
||||
expect(model?.orbitalPeriodSource).toBeUndefined();
|
||||
});
|
||||
|
||||
it('marks a published exoplanet period as measured, not derived', () => {
|
||||
const exoplanet: ExoplanetRecord = {
|
||||
id: 'kepler-22-b',
|
||||
hostStarId: null,
|
||||
hostStarName: 'Kepler-22',
|
||||
name: 'Kepler-22 b',
|
||||
periodDays: 289.9,
|
||||
orbit: { semiMajorAxisAu: 0.849 },
|
||||
};
|
||||
const model = buildBodyViewModel('kepler-22-b', {
|
||||
bodies: [],
|
||||
exoplanets: [exoplanet],
|
||||
stars: [],
|
||||
});
|
||||
expect(model?.orbitalPeriodSource).toBe('measured');
|
||||
expect(model?.orbitalPeriodDays).toBe(289.9);
|
||||
});
|
||||
|
||||
it('leaves an exoplanet with no published period undefined rather than assuming a solar-mass host', () => {
|
||||
const exoplanet: ExoplanetRecord = {
|
||||
id: 'x',
|
||||
hostStarId: null,
|
||||
hostStarName: 'X',
|
||||
name: 'X b',
|
||||
orbit: { semiMajorAxisAu: 0.05 },
|
||||
};
|
||||
const model = buildBodyViewModel('x', { bodies: [], exoplanets: [exoplanet], stars: [] });
|
||||
expect(model?.orbitalPeriodDays).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns undefined for an id in neither catalogue', () => {
|
||||
expect(buildBodyViewModel('nowhere', catalogues)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('reads the same body identically however it is reached', () => {
|
||||
// The whole point of the shared builder: the card and the detail route must not drift.
|
||||
expect(buildBodyViewModel('earth', catalogues)).toEqual(buildBodyViewModel('earth', catalogues));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user