[41][61][62][70] Kennzahlen (GF/aGF je Geschoss, GV aus Koerpern, AZ/UEZ mit Parzelle) und Raumprogramm-Pruefung; Menue, CLI kennzahlen; Tests

This commit is contained in:
karim committed 2026-10-27 20:16:45 +01:00
1 parent 460509424e
commit b2a1d58191
10 files changed
+259 -4

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
import { describe, expect, it } from "vitest";
import { sampleProject } from "../model/sampleProject";
import type { Project } from "../model/types";
import { computeKennzahlen, checkRoomProgram, solidVolume } from "./kennzahlen";
const sq = (x: number, y: number, s: number) => [
{ x, y }, { x: x + s, y }, { x: x + s, y: y + s }, { x, y: y + s },
];
describe("solidVolume", () => {
it("Prisma, Kegelstumpf (taper) und Kreis", () => {
const base = { id: "s", type: "extrudedSolid" as const, levelId: "eg", points: sq(0, 0, 2), height: 3 };
expect(solidVolume(base)).toBeCloseTo(12, 9);
expect(solidVolume({ ...base, taper: 1 })).toBeCloseTo(4, 9); // Pyramide = A·h/3
const r = { ...base, circle: { center: { x: 0, y: 0 }, r: 1 } };
expect(solidVolume(r)).toBeCloseTo(Math.PI * 3, 9);
});
});
describe("computeKennzahlen", () => {
const rooms = (p: Project) => p.rooms ?? [];
it("GF/aGF je Geschoss aus Räumen und Summe", () => {
const k = computeKennzahlen(sampleProject);
const total = rooms(sampleProject).reduce((s, r) => s + Math.abs(areaOf(r.boundary)), 0);
expect(k.gf).toBeCloseTo(total, 6);
expect(k.levels.reduce((s, l) => s + l.gf, 0)).toBeCloseTo(k.gf, 6);
});
it("Ziffern nur mit Parzellenfläche", () => {
expect(computeKennzahlen(sampleProject).az).toBeNull();
const k = computeKennzahlen({ ...sampleProject, parcelArea: 1000 });
expect(k.az).toBeCloseTo(k.agf / 1000, 9);
});
it("Gebäudevolumen aus freien Körpern, Abzugskörper zählen negativ nicht mit", () => {
const p: Project = {
...sampleProject,
extrudedSolids: [
{ id: "a", type: "extrudedSolid", levelId: sampleProject.drawingLevels[0].id, points: sq(0, 0, 10), height: 3 } as never,
{ id: "b", type: "extrudedSolid", levelId: sampleProject.drawingLevels[0].id, points: sq(0, 0, 1), height: 3, operation: "subtract" } as never,
],
};
const k = computeKennzahlen(p);
expect(k.gv).toBeCloseTo(300 - 3, 6);
});
});
function areaOf(pts: { x: number; y: number }[]) {
let a = 0;
for (let i = 0; i < pts.length; i++) { const q = pts[(i + 1) % pts.length]; a += pts[i].x * q.y - q.x * pts[i].y; }
return a / 2;
}
describe("checkRoomProgram", () => {
it("meldet fehlend, zu klein, zu gross und überzählig", () => {
const p: Project = {
...sampleProject,
rooms: [
{ ...(sampleProject.rooms ?? [])[0], id: "r1", name: "Wohnen", boundary: sq(0, 0, 5) },
{ ...(sampleProject.rooms ?? [])[0], id: "r2", name: "Bad", boundary: sq(10, 0, 2) },
{ ...(sampleProject.rooms ?? [])[0], id: "r3", name: "Keller", boundary: sq(20, 0, 2) },
],
roomProgram: [
{ name: "Wohnen", area: 30 },
{ name: "Bad", area: 4 },
{ name: "Büro", area: 12 },
],
};
const r = checkRoomProgram(p);
const by = Object.fromEntries(r.rows.map((x) => [x.name, x]));
expect(by.Wohnen.status).toBe("zu klein"); // 25 < 30
expect(by.Bad.status).toBe("ok");
expect(by["Büro"].status).toBe("fehlt");
expect(r.extra.map((e) => e.name)).toEqual(["Keller"]);
});
});
+123
View File
@@ -0,0 +1,123 @@
// Kennzahlen und Raumprogramm-Prüfung (Wettbewerbswerkzeug, [41]/[61]/[62]/[70]).
//
// • Flächen je Geschoss aus den Räumen (SIA 416: GF, NGF/aGF), Summe über das Gebäude.
// • Gebäudevolumen (GV) aus den freien Körpern (Massenmodell); Abzugskörper zählen nicht mit,
// ihr Volumen wird abgezogen.
// • Ausnützungs-/Überbauungsziffer nur mit `project.parcelArea`.
// • Raumprogramm (`project.roomProgram`, Soll) gegen die gezeichneten Räume.
// Alles rein und ohne Wasm — exakt für Prismen/Kegelstümpfe/Kreise, Näherung sonst (Fasen/Rundungen).
import type { ExtrudedSolid, Project } from "../model/types";
import { balance, polygonArea } from "../geometry/roomArea";
import type { SiaCategory } from "../geometry/roomArea";
export interface LevelKennzahlen {
levelId: string;
name: string;
/** Geschossfläche (SIA 416 GF) aus den Räumen. */
gf: number;
/** Anrechenbare Fläche ≈ Nettogeschossfläche NGF (NF + VF + FF). */
agf: number;
rooms: number;
}
export interface Kennzahlen {
levels: LevelKennzahlen[];
gf: number;
agf: number;
/** Gebäudevolumen aus den freien Körpern (m³), Abzugskörper abgezogen. */
gv: number;
/** Bebaute Fläche ≈ GF des untersten Geschosses (m²). */
footprint: number;
/** Ausnützungsziffer aGF / Parzelle; `null` ohne Parzellenfläche. */
az: number | null;
/** Überbauungsziffer bebaute Fläche / Parzelle; `null` ohne Parzellenfläche. */
uez: number | null;
}
/** Volumen eines Extrusionskörpers (m³): Prisma, Kegel(stumpf) über `taper`, Kreis. */
export function solidVolume(s: ExtrudedSolid): number {
const area = s.circle ? Math.PI * s.circle.r * s.circle.r : polygonArea(s.points);
const t = Math.min(1, Math.max(0, s.taper ?? 0));
const k = 1 - t; // Massstab der Deckfläche
return (area * s.height * (1 + k + k * k)) / 3;
}
const finite = (n: number): number => (Number.isFinite(n) ? n : 0);
export function computeKennzahlen(project: Project): Kennzahlen {
const floors = project.drawingLevels
.filter((l) => l.kind === "floor")
.slice()
.sort((a, b) => (a.baseElevation ?? 0) - (b.baseElevation ?? 0));
const rooms = project.rooms ?? [];
const levels: LevelKennzahlen[] = floors.map((l) => {
const mine = rooms.filter((r) => r.floorId === l.id);
const b = balance(mine.map((r) => ({ category: r.siaCategory as SiaCategory, area: finite(polygonArea(r.boundary)) })));
return { levelId: l.id, name: l.name, gf: b.byKey.GF, agf: b.byKey.NGF, rooms: mine.length };
});
const gf = levels.reduce((s, l) => s + l.gf, 0);
const agf = levels.reduce((s, l) => s + l.agf, 0);
let gv = 0;
for (const s of project.extrudedSolids ?? []) {
const v = finite(solidVolume(s));
gv += s.operation === "subtract" ? -v : v;
}
const footprint = levels.find((l) => l.gf > 0)?.gf ?? 0;
const parcel = project.parcelArea && project.parcelArea > 0 ? project.parcelArea : null;
return {
levels,
gf,
agf,
gv: Math.max(0, gv),
footprint,
az: parcel ? agf / parcel : null,
uez: parcel ? footprint / parcel : null,
};
}
export type ProgramStatus = "ok" | "zu klein" | "zu gross" | "fehlt" | "zu wenige" | "zu viele";
export interface ProgramRowResult {
name: string;
targetArea: number;
targetCount: number;
/** Gefundene Räume (Anzahl, Gesamtfläche). */
count: number;
area: number;
status: ProgramStatus;
}
export interface ProgramCheck {
rows: ProgramRowResult[];
/** Räume im Modell, die keiner Programmzeile zugeordnet sind. */
extra: Array<{ id: string; name: string; area: number }>;
}
/** Toleranz der Flächenprüfung (relativ zur Soll-Fläche). */
const AREA_TOL = 0.1;
const norm = (s: string) => s.trim().toLowerCase();
/** Prüft das Raumprogramm: Räume werden über den Namen (Präfix, ohne Gross-/Kleinschreibung) zugeordnet. */
export function checkRoomProgram(project: Project): ProgramCheck {
const rooms = (project.rooms ?? []).map((r) => ({ id: r.id, name: r.name, cat: r.siaCategory, area: finite(polygonArea(r.boundary)) }));
const used = new Set<string>();
const rows: ProgramRowResult[] = (project.roomProgram ?? []).map((row) => {
const n = norm(row.name);
const hits = rooms.filter((r) => !used.has(r.id) && norm(r.name).startsWith(n) && (!row.siaCategory || r.cat === row.siaCategory));
hits.forEach((h) => used.add(h.id));
const targetCount = Math.max(1, row.count ?? 1);
const area = hits.reduce((s, h) => s + h.area, 0);
const target = row.area * targetCount;
let status: ProgramStatus;
if (hits.length === 0) status = "fehlt";
else if (hits.length < targetCount) status = "zu wenige";
else if (hits.length > targetCount) status = "zu viele";
else if (area < target * (1 - AREA_TOL)) status = "zu klein";
else if (area > target * (1 + AREA_TOL)) status = "zu gross";
else status = "ok";
return { name: row.name, targetArea: row.area, targetCount, count: hits.length, area, status };
});
return { rows, extra: rooms.filter((r) => !used.has(r.id)).map((r) => ({ id: r.id, name: r.name, area: r.area })) };
}