Integrate infrastructure preparation and qualified map delivery with local scenes. Add semantic editing, object provenance, survey caching and operator scene tools.
79 lines
5.2 KiB
JavaScript
79 lines
5.2 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import { test } from 'node:test';
|
|
import ts from 'typescript';
|
|
async function source(name) {
|
|
const code=ts.transpileModule(readFileSync(new URL(`../src/core/simulation/${name}.ts`,import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.ESNext}}).outputText;
|
|
return import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
|
|
}
|
|
const {normalizePlannerPreferences,DEFAULT_PLANNER_PREFERENCES,axisWorldLength}=await source('plannerPreferences');
|
|
const {zoomDisplacement}=await source('editorZoom');
|
|
test('preferences survive round trip, validate old/corrupt storage and clamp physical dimensions',()=>{
|
|
const value={...DEFAULT_PLANNER_PREFERENCES,waypoint:{...DEFAULT_PLANNER_PREFERENCES.waypoint,diameter:.8,height:3,color:'#00aaff',opacity:.5,frequency:0}};
|
|
assert.deepEqual(normalizePlannerPreferences(JSON.parse(JSON.stringify(value))),value);
|
|
assert.deepEqual(normalizePlannerPreferences(null),DEFAULT_PLANNER_PREFERENCES);
|
|
const invalid=normalizePlannerPreferences({pivot:{x:'url(x)',opacity:99},waypoint:{height:-9,diameter:NaN}});
|
|
assert.equal(invalid.pivot.x,DEFAULT_PLANNER_PREFERENCES.pivot.x);
|
|
assert.equal(invalid.pivot.opacity,1);assert.equal(invalid.waypoint.height,.2);assert.equal(invalid.waypoint.diameter,.35);
|
|
});
|
|
test('perspective projection preserves gizmo pixels at different depths and viewport heights',()=>{
|
|
for(const depth of [1,10,500])for(const height of [500,900,1600]) {
|
|
const projected=axisWorldLength(depth,height,105)/(2*depth*Math.tan(Math.PI/6))*height;
|
|
assert.ok(Math.abs(projected-105)<1e-8);
|
|
}
|
|
});
|
|
test('far zoom takes proportional steps and equal reverse wheel deltas return to original distance',()=>{
|
|
for(const depth of [2,20,200,2000]) {
|
|
const next=depth-zoomDisplacement(depth,80);
|
|
assert.ok(next>depth);
|
|
const restored=next-zoomDisplacement(next,-80);
|
|
assert.ok(Math.abs(restored-depth)<1e-8);
|
|
assert.ok(zoomDisplacement(depth,-80)>depth*.1);
|
|
}
|
|
});
|
|
const {waypointHit}=await source('waypointHit');
|
|
test('waypoint picks complete sides, caps and a camera inside the beam at any physical size',()=>{
|
|
for(const radius of [.025,.5,1.5])for(const height of [.2,5,50]) {
|
|
assert.notEqual(waypointHit([radius*.9,height*.9,5],[0,0,-1],[0,0,0],radius,height),null);
|
|
assert.notEqual(waypointHit([radius*.9,height+1,0],[0,-1,0],[0,0,0],radius,height),null);
|
|
assert.notEqual(waypointHit([0,height/2,0],[0,0,1],[0,0,0],radius,height),null);
|
|
assert.equal(waypointHit([radius*1.1,height/2,5],[0,0,-1],[0,0,0],radius,height),null);
|
|
}
|
|
});
|
|
test('world-size centroid preference migrates to independent pixel size; emission is bounded',()=>{
|
|
const prefs=normalizePlannerPreferences({navigation:{centroidDiameter:5},waypoint:{emission:20,emissionColor:'invalid'}});
|
|
assert.equal(prefs.navigation.centroidPixels,14);
|
|
assert.equal(prefs.waypoint.emission,5);
|
|
for(const depth of [1,30,300]) {
|
|
const pixels=axisWorldLength(depth,720,prefs.navigation.centroidPixels)/(2*depth*Math.tan(Math.PI/6))*720;
|
|
assert.ok(Math.abs(pixels-14)<1e-8);
|
|
}
|
|
});
|
|
|
|
test('toolbar preferences migrate old storage and preserve all four placements and valid sizes',()=>{
|
|
assert.deepEqual(normalizePlannerPreferences({pivot:{}}).toolbar,DEFAULT_PLANNER_PREFERENCES.toolbar);
|
|
for(const placement of ['left','right','top','bottom']){
|
|
const p=normalizePlannerPreferences({toolbar:{placement,minSize:40,maxSize:20,lensCount:4,hideDelay:500,gap:3,autoHide:false}}).toolbar;
|
|
assert.equal(p.placement,placement);assert.equal(p.maxSize,40);assert.equal(p.lensCount,5);assert.equal(p.hideDelay,500);assert.equal(p.autoHide,false);
|
|
}
|
|
const p=normalizePlannerPreferences({toolbar:{placement:'oops',hideDelay:Infinity,minSize:NaN,background:'url(x)'}}).toolbar;
|
|
assert.deepEqual(p,DEFAULT_PLANNER_PREFERENCES.toolbar);
|
|
});
|
|
|
|
const {normalizeSimulationLayout,DEFAULT_SIMULATION_LAYOUT,normalizeSceneView}=await source('simulationLayout');
|
|
test('layout keeps global modes/projection/layers while transient editing state cannot enter storage',()=>{
|
|
for(const mode of ['view','semantic','planning'])for(const projection of ['orthographic','perspective']){
|
|
const value={...DEFAULT_SIMULATION_LAYOUT,mode,projection,layers:['road_boundary','road_marking'],visible:{model:true,user:true},axis:'xz'};
|
|
assert.deepEqual(normalizeSimulationLayout(JSON.parse(JSON.stringify(value))),value);
|
|
}
|
|
assert.deepEqual(normalizeSimulationLayout({mode:'oops',projection:'oops'}),DEFAULT_SIMULATION_LAYOUT);
|
|
assert.deepEqual(normalizeSimulationLayout({layers:[]}).layers,[]);
|
|
assert.deepEqual(normalizeSimulationLayout({layers:['road_boundary','oops','road_boundary'],selection:['unsafe'],operations:[{}]}).layers,['road_boundary']);
|
|
assert.equal('operations' in normalizeSimulationLayout({operations:[{}]}),false);
|
|
});
|
|
test('camera snapshots preserve pose and unbounded slice, and reject malformed storage',()=>{
|
|
const view={position:[1,2,3],quaternion:[0,0,0,1],anchor:[4,5,6],projection:'orthographic',span:20,clip:[null,500]};
|
|
assert.deepEqual(normalizeSceneView(JSON.parse(JSON.stringify(view))),view);
|
|
for(const bad of [{...view,quaternion:[1,1,1,1]},{...view,clip:[10,1]},{...view,span:Infinity},{...view,position:[NaN,0,0]}])assert.equal(normalizeSceneView(bad),null);
|
|
});
|