oldtown-geometry.test.mjs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { polygon, lineString, featureCollection } from '@turf/turf'
  4. import { candidateFootprint, isSafeOldTownPlacement } from './oldtown-geometry.mjs'
  5. const mask = polygon([[[0,0],[.01,0],[.01,.01],[0,.01],[0,0]]])
  6. const at = (lon, lat, width=8, depth=7) => ({lon,lat,width,depth,heading:0})
  7. test('rejects a rotated candidate footprint crossing the residential mask edge', () => {
  8. const footprint = candidateFootprint(at(.00999,.005,30,12))
  9. assert.equal(isSafeOldTownPlacement(footprint,{mask,roads:[],water:[],existing:[],modeled:[],accepted:[]}),false)
  10. })
  11. test('rejects a footprint intersecting an existing building even if its center lies outside', () => {
  12. const footprint = candidateFootprint(at(.005,.005,16,8))
  13. const existing = polygon([[[.00505,.00498],[.00512,.00498],[.00512,.00502],[.00505,.00502],[.00505,.00498]]])
  14. assert.equal(isSafeOldTownPlacement(footprint,{mask,roads:[],water:[],existing:[existing],modeled:[],accepted:[]}),false)
  15. })
  16. test('rejects collision with a previously accepted procedural footprint', () => {
  17. const first = candidateFootprint(at(.005,.005,10,8))
  18. const second = candidateFootprint(at(.00504,.005,10,8))
  19. assert.equal(isSafeOldTownPlacement(second,{mask,roads:[],water:[],existing:[],modeled:[],accepted:[first]}),false)
  20. })
  21. test('rejects roads, waterways and already-modeled regular-estate roofs', () => {
  22. const footprint = candidateFootprint(at(.005,.005))
  23. const road = lineString([[.004,.005],[.006,.005]])
  24. const water = polygon([[[.004,.004],[.006,.004],[.006,.006],[.004,.006],[.004,.004]]])
  25. for (const options of [
  26. {roads:[road]},
  27. {water:[water]},
  28. {modeled:[water]},
  29. ]) assert.equal(isSafeOldTownPlacement(footprint,{mask,roads:[],water:[],existing:[],modeled:[],accepted:[],...options}),false)
  30. })
  31. test('accepts a non-overlapping candidate inside a valid residential mask', () => {
  32. const footprint = candidateFootprint(at(.005,.005))
  33. assert.equal(isSafeOldTownPlacement(footprint,{mask,roads:[],water:[],existing:[],modeled:[],accepted:[]}),true)
  34. })