Integrate infrastructure preparation and qualified map delivery with local scenes. Add semantic editing, object provenance, survey caching and operator scene tools.
32 lines
2.6 KiB
JavaScript
32 lines
2.6 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import {readFileSync} from "node:fs";
|
|
import {test} from "node:test";
|
|
import ts from "typescript";
|
|
const moduleURL=(s)=>`data:text/javascript;base64,${Buffer.from(ts.transpileModule(s,{compilerOptions:{module:ts.ModuleKind.ESNext}}).outputText).toString("base64")}`;
|
|
const read=n=>readFileSync(new URL(`../src/core/simulation/${n}.ts`,import.meta.url),"utf8");
|
|
const policy=moduleURL(read("semanticFeaturePolicy"));
|
|
const vector=moduleURL(read("semanticVector").replace('"./semanticFeaturePolicy"',JSON.stringify(policy)));
|
|
const {regionOperation}=await import(moduleURL(read("semanticArea").replace('"./semanticVector"',JSON.stringify(vector)).replace('"polygon-clipping"',JSON.stringify(import.meta.resolve("polygon-clipping")))));
|
|
const {curveControlScale,curveControlPoint,moveCurveControl}=await import(moduleURL(read("semanticCurveControls")));
|
|
const ring=(x,y,w,h,z=2)=>[[x,y,z],[x+w,y,z],[x+w,y+h,z],[x,y+h,z],[x,y,z]];
|
|
const area={id:"area",properties:{class:"pedestrian_area"},geometry:{type:"Polygon",coordinates:[ring(0,0,10,10),ring(2,2,2,2)]}};
|
|
const size=r=>Math.abs(r.slice(1).reduce((a,p,i)=>a+r[i][0]*p[1]-p[0]*r[i][1],0)/2);
|
|
const total=polys=>polys.reduce((s,p)=>s+size(p[0])-p.slice(1).reduce((s,r)=>s+size(r),0),0);
|
|
test("region fill closes existing holes and cut splits without losing parts or source heights",()=>{
|
|
const original=JSON.stringify(area);
|
|
const filled=regionOperation(area,ring(1,1,4,4),"union");assert.equal(total(filled.polygons),100);assert.equal(filled.polygons[0].length,1);
|
|
const split=regionOperation(area,ring(5,-1,1,12),"difference");assert.equal(split.polygons.length,2);assert.equal(total(split.polygons),86);
|
|
assert.equal(JSON.stringify(area),original);assert.ok(split.polygons.flat(2).every(p=>p[2]===2));
|
|
assert.throws(()=>regionOperation(undefined,ring(0,0,1,1),"difference"));
|
|
assert.equal(total(regionOperation(undefined,ring(0,0,1,1),"union").polygons),1);
|
|
});
|
|
test("curve handles remain visible on dense contours without altering physical coordinates; drag has no jump",()=>{
|
|
const nodes=[0,1,2].map(i=>({point:[i*.03,0,2],incoming:[-.01,0],outgoing:[.01,0]}));
|
|
const input=JSON.stringify(nodes),project=p=>p.map(v=>v*10),scale=curveControlScale(nodes,1,false,project);
|
|
const p=curveControlPoint(nodes[1],"outgoing",scale);
|
|
assert.ok(Math.abs((p[0]-.03)*10-36)<1e-9);assert.equal(JSON.stringify(nodes),input);
|
|
assert.deepEqual(moveCurveControl(nodes[1].outgoing,[9,8],[9,8],scale),nodes[1].outgoing);
|
|
const shifted=moveCurveControl(nodes[1].outgoing,[9,8],[10,10],scale);
|
|
assert.ok(Math.abs((shifted[0]-.01)*scale-1)<1e-9);assert.equal(shifted[1]*scale,2);
|
|
});
|