Integrate infrastructure preparation and qualified map delivery with local scenes. Add semantic editing, object provenance, survey caching and operator scene tools.
37 lines
3.0 KiB
JavaScript
37 lines
3.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import {readFileSync} from "node:fs";
|
|
import {test} from "node:test";
|
|
import ts from "typescript";
|
|
const code=ts.transpileModule(readFileSync(new URL("../src/core/simulation/urbanMap.ts",import.meta.url),"utf8"),{compilerOptions:{module:ts.ModuleKind.ESNext}}).outputText;
|
|
const {ALL_URBAN_CLASSES,availableUrbanClasses,visibleUrbanMap,urbanPaths,loadUrbanMap,urbanExtent}=await import(`data:text/javascript;base64,${Buffer.from(code).toString("base64")}`);
|
|
const classes=["road_boundary","pedestrian_area","pedestrian_boundary","building_facade","road_marking"];
|
|
const map={schema_version:"missioncore.urban-map/v3",source:{world_sha256:"source"},features:classes.map((c,i)=>({id:String(i),properties:{class:c},geometry:{type:"LineString",coordinates:[[0,0,0],[1,1,1]]}}))};
|
|
test("legend classes independently hide boundaries and fills without losing choices or geometry",()=>{
|
|
assert.equal(visibleUrbanMap(map,ALL_URBAN_CLASSES).features.length,5);
|
|
assert.equal(visibleUrbanMap(map,[]).features.length,0);
|
|
assert.deepEqual(visibleUrbanMap(map,["pedestrian_area"]).features.map(f=>f.properties.class),["pedestrian_area"]);
|
|
assert.deepEqual(visibleUrbanMap(map,["pedestrian_boundary"]).features.map(f=>f.properties.class),["pedestrian_boundary"]);
|
|
assert.strictEqual(visibleUrbanMap(map,["building_facade"]).features[0],map.features[3]);
|
|
assert.equal(availableUrbanClasses(map).length,5);
|
|
const withRejected={...map,features:[...map.features,{...map.features[0],properties:{class:"curb",review_status:"rejected"}}]};
|
|
assert.equal(availableUrbanClasses(withRejected).includes("curb"),false);
|
|
assert.equal(visibleUrbanMap(withRejected,["curb"]).features.length,0);
|
|
});
|
|
test("rejected observations stay hidden and holes/open lines retain their paths",()=>{
|
|
assert.deepEqual(urbanPaths({...map.features[0],properties:{review_status:"rejected"}}),[]);
|
|
assert.deepEqual(urbanPaths(map.features[0]),[map.features[0].geometry.coordinates]);
|
|
const rings=[[[0,0,0],[1,0,0],[0,1,0],[0,0,0]],[[.2,.2,0],[.3,.2,0],[.2,.3,0],[.2,.2,0]]];
|
|
assert.strictEqual(urbanPaths({properties:{},geometry:{type:"Polygon",coordinates:rings}}),rings);
|
|
});
|
|
test("v3 loads only for the exact selected Gaussian revision",async()=>{
|
|
const original=globalThis.fetch;globalThis.fetch=async()=>({ok:true,status:200,json:async()=>map});
|
|
try {assert.strictEqual(await loadUrbanMap("world","source",new AbortController().signal),map);await assert.rejects(loadUrbanMap("world","different",new AbortController().signal));}
|
|
finally {globalThis.fetch=original;}
|
|
});
|
|
|
|
test("infrastructure framing works without waypoints and ignores rejected outliers",()=>{
|
|
const features=[{...map.features[0],geometry:{type:"LineString",coordinates:[[-12,4,-2],[35,80,6]]}},{...map.features[1],properties:{review_status:"rejected"},geometry:{type:"LineString",coordinates:[[900,900,900],[999,999,999]]}}];
|
|
assert.deepEqual(urbanExtent({...map,features}),[[-12,4,-2],[35,80,6]]);
|
|
assert.deepEqual(urbanExtent({...map,features:[]}),[]);
|
|
});
|