Files
NODEDC_MISSION_CORE/apps/control-station/test/sceneClip.test.mjs
T

30 lines
1.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {build} from 'esbuild';
const result=await build({entryPoints:[new URL('../src/core/simulation/sceneClip.ts',import.meta.url).pathname],bundle:true,write:false,platform:'node',format:'esm'});
const {sceneClipBounds,sceneClipValue,sceneClipRange,sceneClipLabel}=await import('data:text/javascript;base64,'+Buffer.from(result.outputFiles[0].contents).toString('base64'));
test('Gaussian clipping covers visual and collision extents with at least a 500 m ceiling',()=>{
assert.deepEqual(sceneClipBounds([-51.4623,210.4],[-30,77.72065000000002]),[-52,500]);
assert.deepEqual(sceneClipBounds([-60.3,912.7],null),[-61,913]);
assert.deepEqual(sceneClipBounds([5,80],[-75.2,1000.1]),[-76,1001]);
});
test('native rounded maximum disables clipping and returning to a finite height clips again',()=>{
const oldBounds=[-51.4623,77.72065000000002];
assert.ok(77.72065 < oldBounds[1]);
assert.equal(sceneClipValue(77.72065,oldBounds),Infinity);
assert.equal(sceneClipValue(76.4288206,oldBounds),76.4288206);
const bounds=sceneClipBounds([-51.4623,210.4],oldBounds);
assert.deepEqual([40,500,40,500].map(v=>sceneClipValue(v,bounds)),[40,Infinity,40,Infinity]);
});
test('stored open ends and out-of-range legacy values agree with the slider',()=>{
const bounds=[-33,500];
assert.deepEqual(sceneClipRange([null,null],bounds),bounds);
assert.deepEqual(sceneClipRange([-100,900],bounds),bounds);
assert.deepEqual(sceneClipRange([-20,null],bounds),[-20,500]);
assert.deepEqual(sceneClipRange([null,120],bounds),[-33,120]);
assert.equal(sceneClipLabel(-33,bounds),'−∞');
assert.equal(sceneClipLabel(500,bounds),'+∞');
assert.equal(sceneClipLabel(-20,bounds),'-20.0 м');
});