diff --git a/TODO.md b/TODO.md index 5aac0233..2fdffba7 100644 --- a/TODO.md +++ b/TODO.md @@ -1973,8 +1973,7 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]). Geschoss und Raum vom Wirt, Dach = aussen; Nummern zählen nur Geschosse, nicht Schnitte/Ansichten); Löschen eines Dachs/einer Decke (und eines Geschosses mit Decken) löscht deren Fenster im selben Undo-Schritt. Geprüft: Rust-/vitest-Tests, CLI-Liste/-Schnitt/-Ansicht/-Grundriss angesehen (Linux). Offen: Griffe nicht - in Schnitt/Ansicht, Verschieben über die Dachfläche hinaus lässt das Fenster verschwinden (kein Wirt an der - Stelle), nicht in der Tauri-App geprüft. (4.11.: „Alles wählen“ nimmt Dach-/Deckenfenster des Geschosses mit.) + in Schnitt/Ansicht, nicht in der Tauri-App geprüft. (4.11.: „Alles wählen“ nimmt Dach-/Deckenfenster des Geschosses mit; Ziehen der Mitte bleibt auf der Dach-/Deckenfläche, `clampInside`.) - ✅ **[71] U-Wert aus dem Schichtaufbau** (SIA 180 / EN ISO 6946). (30.10.) Kern `u_value.rs`: R = Rsi + Σ d/λ + Rse (λ je Bauteil `Component.lambda`, [100]); Wand waagrecht 0.13/0.04, Dach aufwärts 0.10/0.04, Decke abwärts 0.17/0.04 (Decke: oben → unten, Aussenseite unten); hinterlüftete Schicht (Standard-Luftschicht oder Name mit diff --git a/src/plan/surfaceOpening.clamp.test.ts b/src/plan/surfaceOpening.clamp.test.ts new file mode 100644 index 00000000..12ea5347 --- /dev/null +++ b/src/plan/surfaceOpening.clamp.test.ts @@ -0,0 +1,17 @@ +// [103] Dachfenster bleiben beim Ziehen auf der Dachfläche (`clampInside`). +import { describe, expect, it } from "vitest"; +import { clampInside } from "./surfaceOpening"; + +const sq = [{ x: 0, y: 0 }, { x: 4, y: 0 }, { x: 4, y: 3 }, { x: 0, y: 3 }]; + +describe("clampInside", () => { + it("innen: unverändert", () => { + expect(clampInside({ x: 1, y: 1 }, sq)).toEqual({ x: 1, y: 1 }); + }); + it("aussen: auf den Rand, leicht nach innen", () => { + const q = clampInside({ x: 6, y: 1.5 }, sq); + expect(q.x).toBeLessThan(4); + expect(q.x).toBeGreaterThan(3.9); + expect(q.y).toBeCloseTo(1.5, 1); + }); +}); diff --git a/src/plan/surfaceOpening.ts b/src/plan/surfaceOpening.ts index bd01969d..1e4657b9 100644 --- a/src/plan/surfaceOpening.ts +++ b/src/plan/surfaceOpening.ts @@ -49,10 +49,12 @@ export function surfaceOpeningGripPatch( info: SurfaceOpeningInfo, index: number, pt: P, + hostOutline?: readonly P[], ): { hostPoint?: P; width?: number; height?: number } | null { const c = info.center; const d = { x: pt.x - c[0], y: pt.y - c[1] }; - if (index === 0) return { hostPoint: { x: pt.x, y: pt.y } }; + // Mitte: auf der Dach-/Deckenfläche bleiben (ausserhalb verschwände das Fenster mangels Wirt). + if (index === 0) return { hostPoint: hostOutline && hostOutline.length >= 3 ? clampInside(pt, hostOutline) : { x: pt.x, y: pt.y } }; const axis = index === 1 ? info.ew : info.eh; const l2 = axis[0] * axis[0] + axis[1] * axis[1]; if (!(l2 > 1e-9)) return null; @@ -61,3 +63,27 @@ export function surfaceOpeningGripPatch( const r = Math.round(v * 1000) / 1000; return index === 1 ? { width: r } : { height: r }; } + +/** Punkt im Umriss lassen: ausserhalb → nächster Randpunkt, 5 cm nach innen gerückt (zum Schwerpunkt der Ecken). */ +export function clampInside(pt: P, ring: readonly P[]): P { + let inside = false; + for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) { + const a = ring[i], b = ring[j]; + if (a.y > pt.y !== b.y > pt.y && pt.x < ((b.x - a.x) * (pt.y - a.y)) / (b.y - a.y) + a.x) inside = !inside; + } + if (inside) return { x: pt.x, y: pt.y }; + let best = { x: ring[0].x, y: ring[0].y }; + let bestD = Infinity; + 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 l2 = dx * dx + dy * dy; + const t = l2 > 0 ? Math.max(0, Math.min(1, ((pt.x - a.x) * dx + (pt.y - a.y) * dy) / l2)) : 0; + const q = { x: a.x + dx * t, y: a.y + dy * t }; + const dd = (q.x - pt.x) ** 2 + (q.y - pt.y) ** 2; + if (dd < bestD) { bestD = dd; best = q; } + } + const cx = ring.reduce((s, q) => s + q.x, 0) / ring.length, cy = ring.reduce((s, q) => s + q.y, 0) / ring.length; + const l = Math.hypot(cx - best.x, cy - best.y); + return l > 0.05 ? { x: best.x + ((cx - best.x) / l) * 0.05, y: best.y + ((cy - best.y) / l) * 0.05 } : best; +} diff --git a/src/state/useGripEditing.ts b/src/state/useGripEditing.ts index 76805a2d..c30d34b7 100644 --- a/src/state/useGripEditing.ts +++ b/src/state/useGripEditing.ts @@ -909,7 +909,10 @@ export function useGripEditing(opts: { const op = (project.openings ?? []).find((o) => o.id === selectedOpeningId); if (op && (op.hostRoofId || op.hostCeilingId)) { const info = op.locked ? null : surfaceOpeningInfo(project, op.id); - const patch = info && surfaceOpeningGripPatch(info, index, pt); + const outline = op.hostRoofId + ? (project.roofs ?? []).find((r) => r.id === op.hostRoofId)?.outline + : (project.ceilings ?? []).find((c) => c.id === op.hostCeilingId)?.outline; + const patch = info && surfaceOpeningGripPatch(info, index, pt, outline); if (patch) updateOpening(op.id, patch); return; }