- Move the single-file app into src/ as typed ES modules - Vite for dev server and minified production build (bun run dev / build) - oxfmt/oxlint config; rename useName -> ruianUseName (hooks lint false positive) - Fix horizontal overflow in the sidebar (range input default margin) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
879 B
TypeScript
38 lines
879 B
TypeScript
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',
|
|
}
|
|
}
|