import type { Building, Ring } from './types' type Num = number | string | null | undefined export function mkBuilding( cp: Num, use: Num, flats: Num, floors: Num, area: Num, done: number | null | undefined, rings: Ring[], ): Building { let x0 = 1e18, y0 = 1e18, x1 = -1e18, y1 = -1e18 for (const r of rings) for (const p of r) { if (p[0] < x0) x0 = p[0] if (p[0] > x1) x1 = p[0] if (p[1] < y0) y0 = p[1] if (p[1] > y1) y1 = p[1] } const year = done != null && isFinite(done) ? new Date(done).getUTCFullYear() : null return { cp: (cp || '').toString().trim(), use: use == null ? 0 : +use, flats: flats == null ? null : +flats, floors: floors == null ? null : +floors, area: area == null ? null : +area, year, rings, bb: [x0, y0, x1, y1], cat: 'other', sc: 'other', } }