import test from 'node:test' import assert from 'node:assert/strict' import { polygon, lineString, featureCollection } from '@turf/turf' import { candidateFootprint, isSafeOldTownPlacement } from './oldtown-geometry.mjs' const mask = polygon([[[0,0],[.01,0],[.01,.01],[0,.01],[0,0]]]) const at = (lon, lat, width=8, depth=7) => ({lon,lat,width,depth,heading:0}) test('rejects a rotated candidate footprint crossing the residential mask edge', () => { const footprint = candidateFootprint(at(.00999,.005,30,12)) assert.equal(isSafeOldTownPlacement(footprint,{mask,roads:[],water:[],existing:[],modeled:[],accepted:[]}),false) }) test('rejects a footprint intersecting an existing building even if its center lies outside', () => { const footprint = candidateFootprint(at(.005,.005,16,8)) const existing = polygon([[[.00505,.00498],[.00512,.00498],[.00512,.00502],[.00505,.00502],[.00505,.00498]]]) assert.equal(isSafeOldTownPlacement(footprint,{mask,roads:[],water:[],existing:[existing],modeled:[],accepted:[]}),false) }) test('rejects collision with a previously accepted procedural footprint', () => { const first = candidateFootprint(at(.005,.005,10,8)) const second = candidateFootprint(at(.00504,.005,10,8)) assert.equal(isSafeOldTownPlacement(second,{mask,roads:[],water:[],existing:[],modeled:[],accepted:[first]}),false) }) test('rejects roads, waterways and already-modeled regular-estate roofs', () => { const footprint = candidateFootprint(at(.005,.005)) const road = lineString([[.004,.005],[.006,.005]]) const water = polygon([[[.004,.004],[.006,.004],[.006,.006],[.004,.006],[.004,.004]]]) for (const options of [ {roads:[road]}, {water:[water]}, {modeled:[water]}, ]) assert.equal(isSafeOldTownPlacement(footprint,{mask,roads:[],water:[],existing:[],modeled:[],accepted:[],...options}),false) }) test('accepts a non-overlapping candidate inside a valid residential mask', () => { const footprint = candidateFootprint(at(.005,.005)) assert.equal(isSafeOldTownPlacement(footprint,{mask,roads:[],water:[],existing:[],modeled:[],accepted:[]}),true) })