oldtown-geometry.mjs 1.3 KB

1234567891011121314151617181920212223242526
  1. import * as turf from '@turf/turf'
  2. export function candidateFootprint({ lon, lat, width, depth, heading }) {
  3. const cosLat = Math.cos((lat * Math.PI) / 180)
  4. const dx = (Math.cos(heading) * width) / 111320
  5. const dy = (Math.sin(heading) * width) / (111320 * cosLat)
  6. const ex = (-Math.sin(heading) * depth) / (111320 * cosLat)
  7. const ey = (Math.cos(heading) * depth) / 111320
  8. return turf.polygon([[
  9. [lon - dx / 2 - ex / 2, lat - dy / 2 - ey / 2],
  10. [lon + dx / 2 - ex / 2, lat + dy / 2 - ey / 2],
  11. [lon + dx / 2 + ex / 2, lat + dy / 2 + ey / 2],
  12. [lon - dx / 2 + ex / 2, lat - dy / 2 + ey / 2],
  13. [lon - dx / 2 - ex / 2, lat - dy / 2 - ey / 2],
  14. ]])
  15. }
  16. export function isSafeOldTownPlacement(footprint, { mask, roads, water, existing, modeled, accepted }) {
  17. if (!turf.booleanWithin(footprint, mask)) return false
  18. if (roads.some(road => turf.booleanIntersects(footprint, road))) return false
  19. if (water.some(polygon => turf.booleanIntersects(footprint, polygon))) return false
  20. if (existing.some(building => turf.booleanIntersects(footprint, building))) return false
  21. if (modeled.some(building => turf.booleanIntersects(footprint, building))) return false
  22. if (accepted.some(building => turf.booleanIntersects(footprint, building))) return false
  23. return true
  24. }