diff --git a/src/app/features/galaxy-system/galaxy-system-scene.component.spec.ts b/src/app/features/galaxy-system/galaxy-system-scene.component.spec.ts index d093944..58c7cd8 100644 --- a/src/app/features/galaxy-system/galaxy-system-scene.component.spec.ts +++ b/src/app/features/galaxy-system/galaxy-system-scene.component.spec.ts @@ -1010,7 +1010,7 @@ describe('GalaxySystemSceneComponent camera-flight transitions', () => { expectColour(scene.starTint.value, blackbodyColor(2900)); const light = scene.systemRenderer.object.children.find((child): child is THREE.PointLight => child instanceof THREE.PointLight)!; expectColour(light.color, blackbodyColor(2900, SOLAR_EFFECTIVE_TEMPERATURE_K)); - expect(scene.hudReadouts().find((readout) => readout.label === 'Luminosity')).toEqual({ label: 'Luminosity', value: '0.002 L☉' }); + expect(scene.hudReadouts().find((readout) => readout.label === 'Luminosity')).toEqual({ label: 'Luminosity', value: '0.0015 L☉' }); expect(scene.hudReadouts().find((readout) => readout.label === 'Radius')?.value).toBe('0.141 solar radii'); }); diff --git a/src/app/features/galaxy-system/star-readouts.spec.ts b/src/app/features/galaxy-system/star-readouts.spec.ts index 2fffbcb..1176833 100644 --- a/src/app/features/galaxy-system/star-readouts.spec.ts +++ b/src/app/features/galaxy-system/star-readouts.spec.ts @@ -96,7 +96,7 @@ describe('starReadouts', () => { it('marks a derived luminosity so, and a published one not', () => { const surface = { radiusSolar: null, radiusDerived: true, temperatureK: null }; expect(starReadouts(HYG_STAR, { ...surface, luminositySolar: 25.4, luminosityDerived: true }).find((readout) => readout.label === 'Luminosity')).toEqual({ label: 'Luminosity', value: '25.40 L☉', derived: true }); - expect(starReadouts(PLACED_BY_GAIA, { ...surface, luminositySolar: 0.00151, luminosityDerived: false }).find((readout) => readout.label === 'Luminosity')).toEqual({ label: 'Luminosity', value: '0.002 L☉' }); + expect(starReadouts(PLACED_BY_GAIA, { ...surface, luminositySolar: 0.00151, luminosityDerived: false }).find((readout) => readout.label === 'Luminosity')).toEqual({ label: 'Luminosity', value: '0.0015 L☉' }); expect(starReadouts(HYG_STAR, { ...surface, luminositySolar: null, luminosityDerived: true }).some((readout) => readout.label === 'Luminosity')).toBe(false); }); }); diff --git a/src/app/shared/format/quantity.spec.ts b/src/app/shared/format/quantity.spec.ts index 94d334b..1e4137f 100644 --- a/src/app/shared/format/quantity.spec.ts +++ b/src/app/shared/format/quantity.spec.ts @@ -103,7 +103,11 @@ describe('formatTemperature and formatDensity', () => { describe('formatLuminosity', () => { it('stays decimal across the ordinary range', () => { expect(formatLuminosity(1)).toBe('1.00 L☉'); - expect(formatLuminosity(0.0017)).toBe('0.002 L☉'); + expect(formatLuminosity(0.0017)).toBe('0.0017 L☉'); + // Proxima's archive figure, which three decimals read as 0.002, a third over. + expect(formatLuminosity(0.0015100106)).toBe('0.0015 L☉'); + expect(formatLuminosity(0.0523)).toBe('0.052 L☉'); + expect(formatLuminosity(0.523)).toBe('0.523 L☉'); }); it('goes to powers of ten at the extremes', () => { diff --git a/src/app/shared/format/quantity.ts b/src/app/shared/format/quantity.ts index 6eb36a4..8179595 100644 --- a/src/app/shared/format/quantity.ts +++ b/src/app/shared/format/quantity.ts @@ -96,13 +96,18 @@ export function formatDensity(gramsPerCm3: number): string { return `${gramsPerCm3.toFixed(2)} g/cm³`; } -/** Bolometric luminosity in solar units, which spans many orders of magnitude. */ +/** + * Bolometric luminosity in solar units, which spans many orders of magnitude. Two figures below a + * hundredth, as in the ×10ⁿ form below a thousandth: three decimals left one there, and Proxima's + * archive luminosity, 1.51×10⁻³ L☉, read 0.002, a third over; 23 of the 4 440 hosts the archive + * gives one for read more than 10 % off it. + */ export function formatLuminosity(solar: number): string { if (solar >= 1000 || (solar > 0 && solar < 0.001)) { const exponent = Math.floor(Math.log10(solar)); return `${(solar / Math.pow(10, exponent)).toFixed(1)}×10${superscript(exponent)} L☉`; } - return `${solar.toFixed(solar < 1 ? 3 : 2)} L☉`; + return `${solar < 0.01 ? solar.toPrecision(2) : solar.toFixed(solar < 1 ? 3 : 2)} L☉`; } function superscript(value: number): string {