Merge Analyse-Module nach Rust (Schatten, Baurecht, Aussenbemassung, Kennzahlen); TODO.md [K1]/[K2] nachgefuehrt, CLAUDE.md: hoechstens 2 Agents, Modell je Aufgabe

CLI-Gegenprobe identisch: Parzelle 320 m2, zulaessig 66 m2, Verstoss 2.296 m2, Sonnenhoehe auf 6 Stellen.

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-27 21:29:15 +00:00
commit d9daed7c47
19 files changed
+1548 -387

No files matched your search

+48 -151
View File
@@ -8,11 +8,11 @@
// schiefe Wände fehlen in den Ketten. Ergebnis sind gewöhnliche Bemassungen (Drawing2D), danach
// frei bearbeitbar.
import * as polygonClipping from "./polygonBool";
import type { Pair, Polygon as PcPolygon } from "./polygonBool";
import type { Drawing2D, Project, Vec2, Wall } from "../model/types";
import type { Drawing2D, Project, Wall } from "../model/types";
import { getWallType, wallTypeThickness } from "../model/types";
import { openingJambs } from "./opening";
import { core } from "../engine/coreWasm";
import { FlatReader, FlatWriter } from "./coreFlat";
export type DimSide = "south" | "east" | "north" | "west";
export type DimChain = "openings" | "steps" | "total";
@@ -23,85 +23,22 @@ export interface AutoDimension {
drawing: Drawing2D;
}
/** Aussennormalen der Seiten (Modell: x = Ost, y = Nord). */
const SIDES: { side: DimSide; n: Vec2 }[] = [
{ side: "south", n: { x: 0, y: -1 } },
{ side: "east", n: { x: 1, y: 0 } },
{ side: "north", n: { x: 0, y: 1 } },
{ side: "west", n: { x: -1, y: 0 } },
];
/** Reihenfolge wie im Rust-Kern (`auto_dimensions.rs`: SIDES, CHAIN_*). */
const SIDES: DimSide[] = ["south", "east", "north", "west"];
const CHAINS: DimChain[] = ["openings", "steps", "total"];
const EPS = 1e-6;
const dot = (a: Vec2, b: Vec2) => a.x * b.x + a.y * b.y;
/** Abstand der Ketten von der äussersten Kante in Papier-mm (1:100 → 1.0 / 1.7 / 2.4 m). */
const CHAIN_MM = { openings: 10, steps: 17, total: 24 } as const;
function wallRect(w: Wall, t: number, extStart: number, extEnd: number): Vec2[] {
const dx = w.end.x - w.start.x, dy = w.end.y - w.start.y;
const len = Math.hypot(dx, dy);
const ux = dx / len, uy = dy / len;
const nx = -uy * (t / 2), ny = ux * (t / 2);
const a = { x: w.start.x - ux * extStart, y: w.start.y - uy * extStart };
const b = { x: w.end.x + ux * extEnd, y: w.end.y + uy * extEnd };
return [
{ x: a.x + nx, y: a.y + ny }, { x: b.x + nx, y: b.y + ny },
{ x: b.x - nx, y: b.y - ny }, { x: a.x - nx, y: a.y - ny },
];
}
/** Liegt `p` auf einer anderen Wandachse (Ende oder dazwischen)? Dann ist das Wandende verbunden. */
function connected(p: Vec2, self: Wall, walls: Wall[]): boolean {
for (const o of walls) {
if (o === self) continue;
const dx = o.end.x - o.start.x, dy = o.end.y - o.start.y;
const l2 = dx * dx + dy * dy;
if (l2 < EPS) continue;
const t = Math.max(0, Math.min(1, ((p.x - o.start.x) * dx + (p.y - o.start.y) * dy) / l2));
if (Math.hypot(o.start.x + t * dx - p.x, o.start.y + t * dy - p.y) < 1e-3) return true;
function thicknessOf(project: Project, w: Wall): number {
try {
return wallTypeThickness(getWallType(project, w));
} catch {
return 0.3; // verwaister Wandtyp
}
return false;
}
/** Aussenringe der vereinigten Wand-Grundfläche (gegen den Uhrzeigersinn). */
function outerRings(project: Project, walls: Wall[]): Vec2[][] {
const parts: PcPolygon[] = [];
for (const w of walls) {
if (Math.hypot(w.end.x - w.start.x, w.end.y - w.start.y) < EPS) continue;
let t = 0.3;
try {
t = wallTypeThickness(getWallType(project, w));
} catch {
/* verwaister Wandtyp */
}
const r = wallRect(w, t, connected(w.start, w, walls) ? t / 2 : 0, connected(w.end, w, walls) ? t / 2 : 0);
parts.push([[...r.map((p): Pair => [p.x, p.y]), [r[0].x, r[0].y]]]);
}
if (parts.length === 0) return [];
const rings: Vec2[][] = [];
for (const poly of polygonClipping.union(parts[0], ...parts.slice(1))) {
const ring = poly[0].slice(0, -1).map(([x, y]) => ({ x, y }));
let a = 0;
for (let i = 0; i < ring.length; i++) {
const p = ring[i], q = ring[(i + 1) % ring.length];
a += p.x * q.y - q.x * p.y;
}
rings.push(a < 0 ? ring.reverse() : ring);
}
return rings;
}
/** Werte zusammenfassen, die näher als 1 mm beieinander liegen (sortiert). */
function uniqueSorted(vals: number[]): number[] {
const s = vals.slice().sort((a, b) => a - b);
const out: number[] = [];
for (const v of s) if (out.length === 0 || v - out[out.length - 1] > 1e-3) out.push(v);
return out;
}
/**
* Erzeugt die Aussenbemassung eines Geschosses. `scaleDenominator` bestimmt den Abstand der
* Ketten (Papier-mm → Modell-Meter), `categoryCode` die Ebene der neuen Bemassungen.
* Ketten (Papier-mm → Modell-Meter), `categoryCode` die Ebene der neuen Bemassungen. Die Ketten
* rechnet der Rust-Kern aus Wandachsen/-dicken und Öffnungs-Leibungen.
*/
export function autoExteriorDimensions(
project: Project,
@@ -111,82 +48,42 @@ export function autoExteriorDimensions(
idPrefix = "autodim",
): AutoDimension[] {
const walls = project.walls.filter((w) => w.floorId === floorId);
const rings = outerRings(project, walls);
if (rings.length === 0) return [];
const toM = (mm: number) => (mm / 1000) * scaleDenominator;
if (walls.length === 0) return [];
const ww = new FlatWriter().num(walls.length);
for (const w of walls) ww.num(w.start.x, w.start.y, w.end.x, w.end.y, thicknessOf(project, w));
const index = new Map<string, number>();
walls.forEach((w, i) => index.has(w.id) || index.set(w.id, i));
const ow = new FlatWriter();
const count = ow.slot();
let nOpenings = 0;
for (const o of project.openings ?? []) {
const i = index.get(o.hostWallId);
if (i === undefined) continue;
const j = openingJambs(walls[i], o);
if (!j) continue;
ow.num(i, j.jambStart.x, j.jambStart.y, j.jambEnd.x, j.jambEnd.y);
nOpenings++;
}
ow.set(count, nOpenings);
const rd = new FlatReader(core().autodim_chains(ww.done(), ow.done(), scaleDenominator));
const out: AutoDimension[] = [];
for (const { side, n } of SIDES) {
// Laufrichtung so, dass die linke Normale = Aussennormale ist (positiver Abstand = aussen).
const u: Vec2 = { x: n.y, y: -n.x };
let sMax = -Infinity, tMin = Infinity, tMax = -Infinity;
const corners: number[] = [];
// Kanten, die nach `n` schauen: Aussennormale (rechte Normale eines CCW-Rings) ≈ n.
const faces: { s: number; t0: number; t1: number }[] = [];
for (const ring of rings) {
for (const p of ring) {
sMax = Math.max(sMax, dot(p, n));
tMin = Math.min(tMin, dot(p, u));
tMax = Math.max(tMax, dot(p, u));
}
for (let i = 0; i < ring.length; i++) {
const a = ring[i], b = ring[(i + 1) % ring.length];
const dx = b.x - a.x, dy = b.y - a.y;
const len = Math.hypot(dx, dy);
if (len < EPS) continue;
const outward = { x: dy / len, y: -dx / len };
if (dot(outward, n) < 1 - 1e-6) continue; // nur achsparallele, nach n schauende Kanten
const ta = dot(a, u), tb = dot(b, u);
faces.push({ s: dot(a, n), t0: Math.min(ta, tb), t1: Math.max(ta, tb) });
corners.push(ta, tb);
}
}
if (faces.length === 0) continue;
// Öffnungen in Wänden, deren Aussenseite auf einer dieser Kanten liegt.
const jambs: number[] = [];
for (const o of project.openings ?? []) {
const w = walls.find((x) => x.id === o.hostWallId);
if (!w) continue;
const dx = w.end.x - w.start.x, dy = w.end.y - w.start.y;
const len = Math.hypot(dx, dy);
if (len < EPS || Math.abs(dot({ x: dx / len, y: dy / len }, n)) > 1e-6) continue; // Wand quer zu n
let t = 0.3;
try {
t = wallTypeThickness(getWallType(project, w));
} catch {
/* verwaister Wandtyp */
}
const outerS = dot(w.start, n) + t / 2;
const j = openingJambs(w, o);
if (!j) continue;
const ja = dot(j.jambStart, u), jb = dot(j.jambEnd, u);
const onFace = faces.some((f) => Math.abs(f.s - outerS) < 1e-3 && Math.min(ja, jb) >= f.t0 - 1e-3 && Math.max(ja, jb) <= f.t1 + 1e-3);
if (onFace) jambs.push(ja, jb);
}
const chains: { chain: DimChain; ts: number[] }[] = [];
const total = [tMin, tMax];
const steps = uniqueSorted(corners);
if (jambs.length > 0) chains.push({ chain: "openings", ts: uniqueSorted([...steps, ...jambs]) });
if (steps.length > 2) chains.push({ chain: "steps", ts: steps });
chains.push({ chain: "total", ts: total });
for (const { chain, ts } of chains) {
if (ts.length < 2) continue;
const pts = ts.map((t) => ({ x: u.x * t + n.x * sMax, y: u.y * t + n.y * sMax }));
out.push({
side,
chain,
drawing: {
id: `${idPrefix}-${floorId}-${side}-${chain}`,
type: "drawing2d",
levelId: floorId,
categoryCode,
geom: { shape: "dimension", pts, offset: toM(CHAIN_MM[chain]) },
} as Drawing2D,
});
}
for (let n = rd.count(); n > 0; n--) {
const side = SIDES[rd.num()];
const chain = CHAINS[rd.num()];
const offset = rd.num();
const pts = rd.ring();
out.push({
side,
chain,
drawing: {
id: `${idPrefix}-${floorId}-${side}-${chain}`,
type: "drawing2d",
levelId: floorId,
categoryCode,
geom: { shape: "dimension", pts, offset },
} as Drawing2D,
});
}
return out;
}
+94
View File
@@ -0,0 +1,94 @@
// Flache Puffer für den Rust-Kern (`src-tauri/core`): Schreiben/Lesen von Zahlen, Punktringen und
// Mehrfach-Polygonen (`flat.rs`: `[nPoly, (nRing, (nPkt, x, y, …)…)…]`, Ringe offen). Punkte als
// `Vec2`; Aufbau je Kern-Funktion steht bei der Rust-Bindung (`src-tauri/core/src/web/*.rs`).
import type { Vec2 } from "../model/types";
/** Mehrfach-Polygon: `[polygon][ring]`, Ring 0 aussen, weitere Löcher; Ringe offen. */
export type FlatPolygons = Vec2[][][];
export class FlatWriter {
private buf: number[] = [];
num(...v: number[]): this {
for (const x of v) this.buf.push(x);
return this;
}
/** Platz für eine erst später bekannte Zahl (z. B. Anzahl); Wert mit `set` nachtragen. */
slot(): number {
this.buf.push(0);
return this.buf.length - 1;
}
set(slot: number, v: number): this {
this.buf[slot] = v;
return this;
}
/** Nur die Punkte: `x0, y0, x1, y1, …`. */
pts(pts: readonly Vec2[]): this {
for (const p of pts) this.buf.push(p.x, p.y);
return this;
}
/** Anzahl, dann die Punkte. */
ring(pts: readonly Vec2[]): this {
this.buf.push(pts.length);
return this.pts(pts);
}
/** Mehrfach-Polygon in `flat`-Kodierung. */
polygons(polys: FlatPolygons): this {
this.buf.push(polys.length);
for (const poly of polys) {
this.buf.push(poly.length);
for (const r of poly) this.ring(r);
}
return this;
}
done(): Float64Array {
return Float64Array.from(this.buf);
}
}
/** Liest Zahlen der Reihe nach; fehlende Werte → NaN bzw. Anzahl 0. */
export class FlatReader {
private i = 0;
constructor(private readonly buf: Float64Array) {}
num(): number {
return this.i < this.buf.length ? this.buf[this.i++] : Number.NaN;
}
count(): number {
const n = this.num();
return Number.isInteger(n) && n > 0 ? n : 0;
}
pts(n: number): Vec2[] {
const out: Vec2[] = [];
for (let k = 0; k < n; k++) out.push({ x: this.num(), y: this.num() });
return out;
}
ring(): Vec2[] {
return this.pts(this.count());
}
polygons(): FlatPolygons {
const out: FlatPolygons = [];
for (let p = this.count(); p > 0; p--) {
const poly: Vec2[][] = [];
for (let r = this.count(); r > 0; r--) poly.push(this.ring());
out.push(poly);
}
return out;
}
}
/** `x0, y0, x1, y1, …` → Punkte. */
export function pointsOf(buf: Float64Array): Vec2[] {
return new FlatReader(buf).pts(buf.length >> 1);
}