[64][59][62][61] Schattenstudie im Grundriss mit Zeitregler, Kennzahlenleiste mit Parzelle und Raumprogramm-Editor

- Project.sunStudy (Zeitpunkt UTC, Schalter): Boden-Schatten zuunterst im Geschoss naechst +-0.00
  (plan/generatePlan/sunShadow.ts), Hoefe als Loecher (shadowPolygons liefert Ringe, withoutHoles zerlegt)
- Lage-Panel: Schalter, Datum, Merkdaten 21.3./21.6./21.12., Zeitregler in Ortszeit, Sonnenstand
- Flaechenbilanz-Panel: Kennzahlenleiste GF/aGF/GV/AZ/UeZ, Parzellenflaeche, Raumprogramm bearbeiten mit Status
- checkRoomProgram: leerer Name trifft keine Raeume mehr; Status im Toast uebersetzt
- Doc-Kommentar von DrawingLevel wieder am richtigen Interface

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-27 19:54:17 +00:00
1 parent 9867baa090
commit 0c84c50669
19 files changed
+702 -18

No files matched your search

+10
View File
@@ -72,3 +72,13 @@ describe("checkRoomProgram", () => {
expect(r.extra.map((e) => e.name)).toEqual(["Keller"]);
});
});
describe("checkRoomProgram mit unfertiger Zeile", () => {
it("leerer Name zieht keine Räume an sich", () => {
const n = (sampleProject.rooms ?? []).length;
const c = checkRoomProgram({ ...sampleProject, roomProgram: [{ name: " ", area: 10 }] });
expect(c.rows[0].status).toBe("fehlt");
expect(c.rows[0].count).toBe(0);
expect(c.extra.length).toBe(n);
});
});
+2 -1
View File
@@ -105,7 +105,8 @@ export function checkRoomProgram(project: Project): ProgramCheck {
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));
// Leerer Name (Zeile im Editor noch unfertig) trifft nichts — „" wäre Präfix jedes Raums.
const hits = rooms.filter((r) => n !== "" && !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);
+31 -1
View File
@@ -1,5 +1,7 @@
import { describe, expect, it } from "vitest";
import { sunPosition, shadowOfPrism, shadowPolygons } from "./sun";
import { sunPosition, shadowOfPrism, shadowPolygons, withoutHoles } from "./sun";
import { polygonArea } from "../geometry/roomArea";
import type { Vec2 } from "../model/types";
import { sampleProject } from "../model/sampleProject";
describe("sunPosition", () => {
@@ -36,3 +38,31 @@ describe("Schatten", () => {
expect(shadowPolygons(sampleProject, { azimuth: 200, elevation: -3 })).toEqual([]);
});
});
describe("Schatten mit Hof", () => {
// Quadratischer Ring (aussen 20 m, Hof 10 m) als Polygon mit Loch.
const ring = (x0: number, y0: number, s: number): Vec2[] => [
{ x: x0, y: y0 }, { x: x0 + s, y: y0 }, { x: x0 + s, y: y0 + s }, { x: x0, y: y0 + s },
];
const courtyard = [ring(0, 0, 20), ring(5, 5, 10).reverse()];
it("lochfreie Teile haben dieselbe Fläche wie Aussenring minus Hof", () => {
const parts = withoutHoles(courtyard);
expect(parts.length).toBeGreaterThan(1);
const sum = parts.reduce((s, p) => s + Math.abs(polygonArea(p)), 0);
expect(sum).toBeCloseTo(400 - 100, 6);
// Kein Teil enthält den Hofmittelpunkt.
for (const p of parts) {
const xs = p.map((q) => q.x);
const ys = p.map((q) => q.y);
const inside = Math.min(...xs) < 10 && Math.max(...xs) > 10 && Math.min(...ys) < 10 && Math.max(...ys) > 10;
expect(inside && Math.abs(polygonArea(p)) > 150).toBe(false);
}
});
it("ohne Loch bleibt das Polygon unverändert", () => {
expect(withoutHoles([ring(0, 0, 3)])).toEqual([ring(0, 0, 3)]);
});
it("Projekt-Schatten: erster Ring je Polygon ist der Aussenring", () => {
const polys = shadowPolygons(sampleProject, { azimuth: 200, elevation: 30 });
for (const p of polys) expect(p[0].length).toBeGreaterThanOrEqual(3);
});
});
+41 -4
View File
@@ -89,8 +89,11 @@ export function shadowOfPrism(footprint: Vec2[], zBottom: number, zTop: number,
return hull(pts);
}
/** Vereinigter Schatten aller Wände, Körper und Dächer als Polygone (Aussenring + Löcher je Eintrag). */
export function shadowPolygons(project: Project, sun: SunPosition): Vec2[][] {
/** Ein Schatten-Polygon: `[0]` Aussenring, weitere Ringe sind Löcher (Höfe). Ringe offen (ohne Wiederholung des Startpunkts). */
export type ShadowPolygon = Vec2[][];
/** Vereinigter Schatten aller Wände, Körper und Dächer (leer bei Nacht). */
export function shadowPolygons(project: Project, sun: SunPosition): ShadowPolygon[] {
if (shadowShift(sun) === null) return [];
const parts: Vec2[][] = [];
for (const w of project.walls) {
@@ -138,8 +141,42 @@ export function shadowPolygons(project: Project, sun: SunPosition): Vec2[][] {
.map((p) => [[...p.map((q): Pair => [q.x, q.y]), [p[0].x, p[0].y] as Pair]]);
if (polys.length === 0) return [];
const union = polygonClipping.union(polys[0], ...polys.slice(1));
// Pro Teilpolygon nur der Aussenring (Löcher eines Schattens sind Hofflächen: bewusst mitgeben).
return union.map((poly) => poly.map((ring) => ring.slice(0, -1).map(([x, y]) => ({ x, y }))));
}
/**
* Zerlegt ein Polygon mit Löchern in lochfreie Teile gleicher Gesamtfläche (für Ausgaben, die
* nur einfache Polygone füllen, z. B. das Plan-Primitiv). Jedes Loch wird von einer senkrechten
* Schnittlinie durch seinen Mittelpunkt geteilt; in den Streifen dazwischen berührt jeder
* Lochrest den Streifenrand und ist damit kein Loch mehr.
*/
export function withoutHoles(poly: ShadowPolygon): Vec2[][] {
const outer = poly[0];
if (!outer || outer.length < 3) return [];
if (poly.length === 1) return [outer];
const toPc = (ring: Vec2[]): Pair[] => [...ring.map((q): Pair => [q.x, q.y]), [ring[0].x, ring[0].y]];
const pc: PcPolygon = poly.filter((r) => r.length >= 3).map(toPc);
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
for (const p of outer) {
minX = Math.min(minX, p.x); maxX = Math.max(maxX, p.x);
minY = Math.min(minY, p.y); maxY = Math.max(maxY, p.y);
}
const cuts = poly
.slice(1)
.filter((r) => r.length >= 3)
.map((r) => {
const xs = r.map((p) => p.x);
return (Math.min(...xs) + Math.max(...xs)) / 2;
})
.sort((a, b) => a - b);
const xs = [minX - 1, ...cuts, maxX + 1];
const out: Vec2[][] = [];
for (const poly of union) for (const ring of poly) out.push(ring.slice(0, -1).map(([x, y]) => ({ x, y })));
for (let i = 0; i + 1 < xs.length; i++) {
if (xs[i + 1] - xs[i] < 1e-9) continue;
const slab: PcPolygon = [[[xs[i], minY - 1], [xs[i + 1], minY - 1], [xs[i + 1], maxY + 1], [xs[i], maxY + 1], [xs[i], minY - 1]]];
for (const piece of polygonClipping.intersection(pc, slab)) {
if (piece[0].length >= 4) out.push(piece[0].slice(0, -1).map(([x, y]) => ({ x, y })));
}
}
return out;
}