From 9afa9204b49ef274dafce6025a32ef5724c93422 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 04:25:02 +0000 Subject: [PATCH 1/2] =?UTF-8?q?[63]=20Profilverst=C3=B6sse=20im=20Grundris?= =?UTF-8?q?s=20(schw=C3=A4cheres=20Rot=20wie=20Grenzabstands-Verst=C3=B6ss?= =?UTF-8?q?e)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/core/src/plan/extras.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src-tauri/core/src/plan/extras.rs b/src-tauri/core/src/plan/extras.rs index a2c2b069..1e5e6b0b 100644 --- a/src-tauri/core/src/plan/extras.rs +++ b/src-tauri/core/src/plan/extras.rs @@ -19,6 +19,8 @@ pub const SITE_PARCEL_CLS: &str = "site-parcel"; pub const SITE_ALLOWED_CLS: &str = "site-allowed"; pub const SITE_VIOLATION_FILL: &str = "#d0342c"; const SITE_VIOLATION_OPACITY: f64 = 0.45; +/// Profilverstösse ([63]): gleiches Rot, schwächer gefüllt (Bauteil ragt über das Gebäudeprofil). +const SITE_PROFILE_OPACITY: f64 = 0.25; const PARCEL_COLOR: &str = "#1f6f3f"; const ALLOWED_COLOR: &str = "#2b5fae"; const PARCEL_DASH: [f64; 4] = [6.0, 1.5, 0.5, 1.5]; @@ -150,6 +152,12 @@ pub fn site_and_shadow(p: &Project, floor: &str, when_ms: Option) -> (Vec<( violations.push(flat_polygon(ring_pts(&ring), SITE_VIOLATION_FILL, SITE_VIOLATION_OPACITY)); } } + for poly in &check.profile_violations { + let rings: Vec> = poly.iter().map(|r| r.iter().map(|q| [q.x, q.y]).collect()).collect(); + for ring in crate::sun::without_holes(&rings) { + violations.push(flat_polygon(ring_pts(&ring), SITE_VIOLATION_FILL, SITE_PROFILE_OPACITY)); + } + } } (under, violations) } @@ -508,6 +516,25 @@ mod tests { serde_json::from_str(include_str!("../../tests/fixtures/sample_project.json")).unwrap() } + /// [63] Profilverstösse erscheinen im Grundriss (schwächeres Rot); ohne Profil nichts. + #[test] + fn profilverstoesse_im_grundriss() { + let mut p = sample(); + let floor = ground_floor_id(&p).unwrap().to_string(); + let rules = |extra: serde_json::Value| { + let mut v = serde_json::json!({"parcel": [{"x": -1, "y": -1}, {"x": 6, "y": -1}, {"x": 6, "y": 5}, {"x": -1, "y": 5}], "defaultSetback": 0.0}); + v.as_object_mut().unwrap().extend(extra.as_object().unwrap().clone()); + serde_json::from_value(v).unwrap() + }; + p.site_rules = Some(rules(serde_json::json!({}))); + let n0 = site_and_shadow(&p, &floor, None).1.len(); + p.site_rules = Some(rules(serde_json::json!({"profileAngle": 10.0, "profileHeight": 0.01}))); + let c = crate::site_rules::check_project(&p).unwrap(); + assert!(c.profile_exceeded); + let n1 = site_and_shadow(&p, &floor, None).1.len(); + assert!(n1 > n0, "{n0} {n1}"); + } + #[test] fn strichstaerken_faktor() { let mut on = sample(); From c288dd31f1d95f09d50b75974b335229c74e7bd7 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 04:30:23 +0000 Subject: [PATCH 2/2] =?UTF-8?q?[77]=20Objekt-Info:=20Fl=C3=A4che=20geschlo?= =?UTF-8?q?ssener=202D-Formen=20(B=C3=B6gen=20exakt,=20abz=C3=BCglich=20L?= =?UTF-8?q?=C3=B6cher)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 9 ++-- src-tauri/core/src/selection_info.rs | 64 ++++++++++++++++++++++++++++ src/i18n/de.ts | 1 + src/i18n/en.ts | 1 + src/panels/ObjectInfoPanel.tsx | 6 +++ src/state/selectionInfo.test.ts | 2 + src/state/selectionInfo.ts | 2 + 7 files changed, 82 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index d73e7fa9..adca46d7 100644 --- a/TODO.md +++ b/TODO.md @@ -1749,8 +1749,9 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]). Punkte (Wandkronen, Körper-Deckel, Dachflächen/Giebel, Kanten ≤ 1 m abgetastet), Verstoss = ganzes Bauteil (`profileExceeded`/`profileViolations`, im 3D rot vom tiefsten Profilpunkt bis Oberkante — Näherung, kein Volumen); Hülle im 3D mit Profil-Oberseite (adaptiv verfeinert, Knicke auf ≤ 0.25 m genähert), gedeckelt durch Gesamthöhe. - Wände als Vorsprung markierbar (`Wall.siteProjection`, Erker; Tiefe + Anteil). Offen: Hülle im 3D nur im - Linux-Container gebaut, nicht angesehen (WebGPU/macOS); Profilverstösse nicht im Grundriss gezeichnet; Profil gilt + Wände als Vorsprung markierbar (`Wall.siteProjection`, Erker; Tiefe + Anteil). 5.11.: Profilverstösse im Grundriss + (`plan/extras.rs`, wie Grenzabstands-Verstösse in der Verstoss-Gruppe, gleiches Rot, schwächer gefüllt; Test). Offen: Hülle im 3D nur im + Linux-Container gebaut, nicht angesehen (WebGPU/macOS); Profil gilt an allen Kanten (nicht je Kante wählbar), Fassaden-/Gesamthöhe nach IVHB nicht getrennt; Höhenkurven fehlen; Anteil grob über Ausdehnung längs der Grenze. - ◐ **[64]+[59] Sonnenstand und Schatten.** (27.10.) Schatten im Grundriss mit Zeitregler (Lage-Panel), @@ -1849,7 +1850,9 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]). verschieben", Geo-Verschiebung und Wand-Begrenzung nehmen `holes` mit. 4.11. Griffe: Loch-Ecken sind Eckgriffe (Index ab 2n, hinter den Bogen-Griffen; bestehende Indizes unverändert). Auflösen liefert zusätzlich die Lochkanten als Linien. Verrunden/Fasen behalten die Löcher; Versetzen, Bruch, Teilen, Trimmen/Verlängern und Verbinden bauen neue Ketten und lassen `holes` bewusst weg (Kopie ohne Löcher, kein - Panic). Offen: Fläche in der Objekt-Info (gibt es für Polylinien nicht); nicht in der App geklickt. + Panic). 5.11. Objekt-Info zeigt die Fläche (m², nur lesen) geschlossener Rechtecke, Kreise, Ellipsen und Polylinien + (Bögen aus `bulge` exakt als Kreissegmente, abzüglich `holes`; `selection_info.rs::geom_area`, Tests Rust + vitest; + Splines ohne). Offen: nicht in der App geklickt. - ✅ **[78] Autotext im Plankopf.** Titelblock löst Projekt/Blatt/Massstab/Datum auf; Plannummer laufend oder `Layout.planNumber` (27.10.). - ◐ **[79] Publikationssätze.** (30.10.) Modell (Rust, optional): `Project.publishSets` (`PublishSet`: Layouts in Reihenfolge, diff --git a/src-tauri/core/src/selection_info.rs b/src-tauri/core/src/selection_info.rs index 3fc897fa..9a73e26a 100644 --- a/src-tauri/core/src/selection_info.rs +++ b/src-tauri/core/src/selection_info.rs @@ -1106,6 +1106,48 @@ fn is_closed_geom(g: &Value) -> bool { } } +/// Fläche einer geschlossenen 2D-Form in m² ([77]): Rechteck, Kreis, Ellipse, Polylinie (Bögen aus +/// `bulge` exakt als Kreissegmente, abzüglich `holes`); sonst `None` (Spline u. a.). +fn geom_area(g: &Value) -> Option { + let p = |k: &str| xy(g.get(k).unwrap_or(&Value::Null)); + let shoelace = |pts: &[(f64, f64)]| -> f64 { + let n = pts.len(); + (0..n).map(|i| (pts[i].0 * pts[(i + 1) % n].1 - pts[(i + 1) % n].0 * pts[i].1) / 2.0).sum() + }; + let a = match str_of(field(g, "shape"))? { + "rect" => { + let (a, b) = (p("min"), p("max")); + ((b.0 - a.0) * (b.1 - a.1)).abs() + } + "circle" => std::f64::consts::PI * num_of(field(g, "r")).powi(2), + "ellipse" => std::f64::consts::PI * (num_of(field(g, "rx")) * num_of(field(g, "ry"))).abs(), + "polyline" if truthy(field(g, "closed")) => { + let pts = pts_of(field(g, "pts")); + if pts.len() < 3 { + return None; + } + let bulge = arr(field(g, "bulge")).iter().map(|v| num_of(Some(v))).collect::>(); + let mut signed = shoelace(&pts); + for (i, b) in bulge.iter().enumerate().take(pts.len()) { + if b.abs() < 1e-9 { + continue; + } + let (u, v) = (pts[i], pts[(i + 1) % pts.len()]); + let c = hypot2(v.0 - u.0, v.1 - u.1); + let theta: f64 = 4.0 * jsnum::atan2(*b, 1.0); + let r = c / (2.0 * jsnum::sin(theta / 2.0).abs()); + // Kreissegment zwischen Sehne und Bogen; Bogen links der Sehne (b > 0) ergibt eine im Uhrzeigersinn + // durchlaufene Schleife, wirkt also gegen die Ring-Orientierung (CCW positiv). + signed -= (r * r / 2.0) * (theta.abs() - jsnum::sin(theta.abs())) * b.signum(); + } + let holes: f64 = arr(field(g, "holes")).iter().map(|h| shoelace(&pts_of(Some(h))).abs()).sum(); + signed.abs() - holes + } + _ => return None, + }; + (a.is_finite() && a >= 0.0).then_some(a) +} + /// Bounding-Box einer 2D-Form (`geomBBox`, auch für Ausrichten/Verteilen). pub fn geom_bbox(g: &Value) -> [f64; 4] { let p = |k: &str| xy(g.get(k).unwrap_or(&Value::Null)); @@ -1223,6 +1265,7 @@ fn drawing_selection(root: &Map, d: &Value) -> J { .raw("strokeWeightSource", d, "strokeWeightSource") .o("hatchSource", pick("hatchSource")) .v("closed", Value::Bool(closed)) + .o("area", geom_area(g).map(js_num)) .v("isImage", Value::Bool(is_image)) .o("opacity", if is_image { Some(nn(field(g, "opacity")).cloned().unwrap_or_else(|| Value::from(1u64))) } else { field(d, "opacity").cloned() }) .v("bbox", bbox_value(geom_bbox(g))) @@ -1265,6 +1308,27 @@ mod tests { derive(&Lookup::plain(r), &serde_json::from_value(a).unwrap()).map(|j| serde_json::from_str(&j.into_string()).unwrap()) } + /// [77] Fläche geschlossener 2D-Formen: Bögen exakt, Löcher abgezogen, offene Formen ohne Wert. + #[test] + fn flaeche_geschlossener_formen() { + let sq = json!([{"x": 0, "y": 0}, {"x": 4, "y": 0}, {"x": 4, "y": 4}, {"x": 0, "y": 4}]); + let a = |g: Value| geom_area(&g); + assert_eq!(a(json!({"shape": "rect", "min": {"x": 1, "y": 1}, "max": {"x": 3, "y": 4}})), Some(6.0)); + assert!((a(json!({"shape": "circle", "center": {"x": 0, "y": 0}, "r": 2})).unwrap() - 4.0 * std::f64::consts::PI).abs() < 1e-12); + assert!((a(json!({"shape": "ellipse", "center": {"x": 0, "y": 0}, "rx": 2, "ry": 1, "rotation": 0})).unwrap() - 2.0 * std::f64::consts::PI).abs() < 1e-12); + assert_eq!(a(json!({"shape": "polyline", "closed": true, "pts": sq})), Some(16.0)); + assert_eq!(a(json!({"shape": "polyline", "closed": false, "pts": sq})), None); + let hole = json!([{"x": 1, "y": 1}, {"x": 1, "y": 3}, {"x": 3, "y": 3}, {"x": 3, "y": 1}]); + assert_eq!(a(json!({"shape": "polyline", "closed": true, "pts": sq, "holes": [hole]})), Some(12.0)); + // Halbkreis-Bogen (bulge 1) über der Sehne (0,0)-(2,0) + Gegenseite gerade: Fläche = Dreieck + Halbkreis. + let tri = json!([{"x": 0, "y": 0}, {"x": 2, "y": 0}, {"x": 1, "y": -1}]); + let g = json!({"shape": "polyline", "closed": true, "pts": tri, "bulge": [1.0, 0.0, 0.0]}); + // Dreieck ist CW (Fläche 1); Bogen links der Sehne a→b liegt ausserhalb ⇒ 1 + π/2 (r = 1); gleiches CCW mit bulge -1. + assert!((a(g.clone()).unwrap() - (1.0 + std::f64::consts::FRAC_PI_2)).abs() < 1e-9); + let ccw = json!({"shape": "polyline", "closed": true, "pts": [{"x": 0, "y": 0}, {"x": 2, "y": 0}, {"x": 1, "y": 1}], "bulge": [-1.0, 0.0, 0.0]}); + assert!((a(ccw).unwrap() - (1.0 + std::f64::consts::FRAC_PI_2)).abs() < 1e-9); + } + #[test] fn wand_mit_typ_volumen_und_fuge() { let r = root(json!({ diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 7b67e79b..5036f989 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -591,6 +591,7 @@ export const de = { "objinfo.ceiling.openings": "Aussparungen", "objinfo.ceiling.removeOpening": "Aussparung entfernen", "objinfo.ceiling.area": "Fläche", + "objinfo.drawing.area": "Fläche", "objinfo.ceiling.anchorFloor": "Gebunden", "objinfo.ceiling.anchorCustom": "Eigene", // ── Öffnungs-Attribute (Object-Info-Panel) ────────────────────────────── diff --git a/src/i18n/en.ts b/src/i18n/en.ts index abe0043e..fb1ce97e 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -590,6 +590,7 @@ export const en: Record = { "objinfo.ceiling.openings": "Openings", "objinfo.ceiling.removeOpening": "Remove opening", "objinfo.ceiling.area": "Area", + "objinfo.drawing.area": "Area", "objinfo.ceiling.anchorFloor": "Bound", "objinfo.ceiling.anchorCustom": "Custom", // ── Opening attributes (object info panel) ────────────────────────────── diff --git a/src/panels/ObjectInfoPanel.tsx b/src/panels/ObjectInfoPanel.tsx index db18d5e6..871203c4 100644 --- a/src/panels/ObjectInfoPanel.tsx +++ b/src/panels/ObjectInfoPanel.tsx @@ -287,6 +287,12 @@ export function ObjectInfoPanel() { onCommit={(v) => host.onSetDrawingTextPaperHeight(v)} /> )} + {sel.kind === "drawing2d" && sel.area !== undefined && ( +
+ {t("objinfo.drawing.area")} + {sel.area.toFixed(2)} m² +
+ )} {drawingShape === "circle" && ( { expect(l.bbox).toEqual({ minX: 0, minY: -2, maxX: 3, maxY: 0 }); const r = deriveSelection(p, { drawings: ["r"] })!; expect(r.closed).toBe(true); + expect(r.area).toBe(3); + expect(l.area).toBeUndefined(); expect(r.fillHatchId).toBe("h"); expect(r.effectiveHatchId).toBe("h"); expect(deriveSelection(p, { drawings: ["nix"] })).toBeNull(); diff --git a/src/state/selectionInfo.ts b/src/state/selectionInfo.ts index f56126a3..a6c73556 100644 --- a/src/state/selectionInfo.ts +++ b/src/state/selectionInfo.ts @@ -457,6 +457,8 @@ export interface SelectionInfo { effectiveHatchId?: string | null; /** Ob die Form geschlossen ist (rect/circle/closed polyline) — nur Drawing2D. */ closed?: boolean; + /** Fläche in m² (geschlossene Form: rect/circle/ellipse/Polylinie inkl. Bögen, netto ohne Löcher) — nur Drawing2D. */ + area?: number; /** * Ob das Element ein Bild ist (Drawing2D `{shape:"image"}`, Layout- * Annotation `kind:"image"` ODER Kontext-Objekt `type:"image"`) — steuert