Files
gods-eye-view/src/data/aircraftRecession.test.mjs
T
Sameh Khamis 0ab31d4fb8 The renderer seam: clicks go to the newest tool, recession and display groups through the contract, drawing at parity with Cesium
- Clicks: when two tools want the globe's clicks, the newest takes them and the older is told and turns itself off; a click is decided when it arrives, and ambient selection fires only when no tool holds the pointer. The "map is busy" paths and their strings are removed.
- Recession: the limb fade is shared (src/render/recession.js) and reaches icon and model sets through SetSpec.recede; tuning applies on the next frame.
- Display panel groups are published through src/ui/displayGroups.js; the Weather group and src/viewWeather.js are removed.
- Draw port: a set whose icons only move is moved in place, and models that did not change are not restyled each frame, so moving fleets cost what they did when drawn directly; an untinted, fully opaque model is drawn without a colour.
- Conformance: input.lease.lost checks the new lease inside onLost and reports a throwing onLost; draw.sets.recede covers model sets.
- QA scripts read the renderer host instead of internals the seam replaced.
2026-11-15 17:03:09 -08:00

121 lines
4.9 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import {
DEFAULT_AIRCRAFT_RECESSION_PARAMS,
aircraftRecessionFactors,
applyAircraftModelTreatment,
cameraLimbDistanceM,
aircraftTreatmentAlpha,
} from './aircraftRecession.js';
const params = { ...DEFAULT_AIRCRAFT_RECESSION_PARAMS };
const cameraHeightM = 1_000_000;
const limb = cameraLimbDistanceM(cameraHeightM, params.earthRadiusM);
test('aircraft recession is a no-op below the limb-relative start threshold', () => {
assert.deepEqual(
aircraftRecessionFactors({ cameraDistanceM: limb * 0.49, cameraHeightM }, params),
{ scale: 1, alpha: 1, limbRatio: 0.49 },
);
assert.deepEqual(
aircraftRecessionFactors({ cameraDistanceM: limb * 0.5, cameraHeightM }, params),
{ scale: 1, alpha: 1, limbRatio: 0.5 },
);
});
test('aircraft recession reaches the tunable scale and haze floors at the limb', () => {
const atLimb = aircraftRecessionFactors({ cameraDistanceM: limb, cameraHeightM }, params);
assert.ok(Math.abs(atLimb.scale - 0.45) < 1e-12);
assert.ok(Math.abs(atLimb.alpha - 0.35) < 1e-12);
const beyond = aircraftRecessionFactors({ cameraDistanceM: limb * 1.2, cameraHeightM }, params);
assert.ok(Math.abs(beyond.scale - 0.45) < 1e-12);
assert.ok(Math.abs(beyond.alpha - 0.35) < 1e-12);
});
test('aircraft recession is a globe-view no-op instead of a global distance fade', () => {
assert.deepEqual(
aircraftRecessionFactors({ cameraDistanceM: 20_000_000, cameraHeightM: 5_000_000 }, params),
{ scale: 1, alpha: 1, limbRatio: null },
);
});
test('globe-view transition eases to identity without a threshold pop', () => {
let prior = null;
for (let height = 3_500_000; height <= 4_500_000; height += 50_000) {
const atLimbDistance = cameraLimbDistanceM(height, params.earthRadiusM);
const current = aircraftRecessionFactors({
cameraDistanceM: atLimbDistance,
cameraHeightM: height,
}, params);
if (prior) {
assert.ok(Math.abs(current.alpha - prior.alpha) <= 0.05, `${height}: alpha pop`);
assert.ok(Math.abs(current.scale - prior.scale) <= 0.05, `${height}: scale pop`);
}
prior = current;
}
const start = aircraftRecessionFactors({
cameraDistanceM: cameraLimbDistanceM(3_500_000, params.earthRadiusM),
cameraHeightM: 3_500_000,
}, params);
const end = aircraftRecessionFactors({
cameraDistanceM: cameraLimbDistanceM(4_500_000, params.earthRadiusM),
cameraHeightM: 4_500_000,
}, params);
assert.ok(Math.abs(start.scale - params.scaleFloor) < 1e-12);
assert.ok(Math.abs(start.alpha - params.alphaFloor) < 1e-12);
assert.deepEqual(end, { scale: 1, alpha: 1, limbRatio: null });
});
test('combined focus and haze product is clamped at the composed alpha floor', () => {
const alpha = aircraftTreatmentAlpha({
baseAlpha: 1,
focusFactor: 0.25,
cameraDistanceM: limb,
cameraHeightM,
params,
});
assert.equal(alpha, 0.2);
});
test('ambient model presentation receives composed alpha without changing blend semantics', () => {
const model = { color: { alpha: 1 }, colorBlendAmount: 0.9 };
const color = { withAlpha: (alpha) => ({ alpha, rgb: 'amber' }) };
assert.equal(applyAircraftModelTreatment({ model, baseColor: color, alpha: 0.2, params }), 1);
assert.deepEqual(model.color, { alpha: 0.2, rgb: 'amber' });
assert.equal(model.colorBlendAmount, 0.9);
assert.equal(applyAircraftModelTreatment({ model, baseColor: color, alpha: 0.2, params }), 0);
});
test('model hue changes at constant alpha, then clears without redundant writes', () => {
const color = (red,green,blue) => ({red,green,blue,withAlpha(alpha){return {red,green,blue,alpha};}});
const model = {color:color(1,1,1).withAlpha(0.65)};
assert.equal(applyAircraftModelTreatment({model,baseColor:color(1,0.2,0.2),alpha:0.65}),1);
assert.equal(model.color.green,0.2);
assert.equal(model.color.alpha,0.65);
assert.equal(applyAircraftModelTreatment({model,baseColor:color(1,0.2,0.2),alpha:0.65}),0);
assert.equal(applyAircraftModelTreatment({model,baseColor:color(1,1,1),alpha:0.65}),1);
assert.equal(model.color.green,1);
});
test('the aircraft sets recede by the tuning: one object until it changes', async () => {
const {
aircraftRecedeSpec,
setAircraftRecessionParams,
resetAircraftRecessionParams,
} = await import('./aircraftRecession.js');
const { RECEDE_DEFAULTS } = await import('../render/recession.js');
resetAircraftRecessionParams();
const first = aircraftRecedeSpec();
assert.deepEqual(first, { ...RECEDE_DEFAULTS });
assert.equal(aircraftRecedeSpec(), first);
setAircraftRecessionParams({ scaleFloor: 0.6, globeViewHeightM: 4_000_000 });
const tuned = aircraftRecedeSpec();
assert.notEqual(tuned, first);
assert.equal(tuned.scaleFloor, 0.6);
assert.equal(tuned.globeViewBlendEndM, 4_000_000);
assert.equal('writeEpsilon' in tuned, false);
resetAircraftRecessionParams();
assert.deepEqual(aircraftRecedeSpec(), first);
});