import assert from "node:assert/strict"; import {readFileSync} from "node:fs"; import {test} from "node:test"; import ts from "typescript"; let code=ts.transpileModule(readFileSync(new URL("../src/core/simulation/urbanSurface.ts",import.meta.url),"utf8"),{compilerOptions:{module:ts.ModuleKind.ESNext}}).outputText; code=code.replace('from "three"',`from ${JSON.stringify(import.meta.resolve('three'))}`); const {urbanSurface}=await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`); const ring=[[0,0,2],[8,0,2.8],[8,6,3.4],[0,6,2.6],[0,0,2]]; const hole=[[2,2,2.4],[4,2,2.6],[4,4,2.8],[2,4,2.6],[2,2,2.4]]; const feature={properties:{class:'pedestrian_area',height_projection:{method:'test'},review_status:'unreviewed'},geometry:{type:'Polygon',coordinates:[ring,hole]}}; test('ground coverage triangulation preserves hole, area, source heights and input',()=>{ const before=JSON.stringify(feature),g=urbanSurface(feature);assert.equal(JSON.stringify(feature),before);assert.deepEqual(g.positions,[...ring.slice(0,-1),...hole.slice(0,-1)].flat());let area=0; for(let i=0;ig.positions.slice(k*3,k*3+3));area+=Math.abs((p[1][0]-p[0][0])*(p[2][1]-p[0][1])-(p[2][0]-p[0][0])*(p[1][1]-p[0][1]))/2;const c=[0,1].map(k=>p.reduce((s,x)=>s+x[k],0)/3);assert.ok(!(c[0]>2&&c[0]<4&&c[1]>2&&c[1]<4));} assert.equal(area,44); }); test('physical boundaries and unqualified heights never become filled ground',()=>{ assert.equal(urbanSurface({...feature,properties:{class:'pedestrian_boundary',height_projection:{}}}),null); assert.equal(urbanSurface({...feature,properties:{class:'pedestrian_area'}}),null); assert.equal(urbanSurface({...feature,properties:{...feature.properties,review_status:'rejected'}}),null); }); test('concave pedestrian outline stays concave',()=>{ const coords=[[0,0,0],[4,0,0],[4,1,0],[1,1,0],[1,4,0],[0,4,0],[0,0,0]]; const g=urbanSurface({...feature,geometry:{type:'Polygon',coordinates:[coords]}});let area=0; for(let i=0;ig.positions.slice(k*3,k*3+3));area+=Math.abs((p[1][0]-p[0][0])*(p[2][1]-p[0][1])-(p[2][0]-p[0][0])*(p[1][1]-p[0][1]))/2;} assert.equal(area,7); });