Integrate infrastructure preparation and qualified map delivery with local scenes. Add semantic editing, object provenance, survey caching and operator scene tools.
27 lines
2.2 KiB
JavaScript
27 lines
2.2 KiB
JavaScript
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;i<g.indices.length;i+=3){const p=g.indices.slice(i,i+3).map(k=>g.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;i<g.indices.length;i+=3){const p=g.indices.slice(i,i+3).map(k=>g.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);
|
|
});
|