From 401d94acca9864361234266854aa73879d575788 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 30 Oct 2026 03:40:35 +0000 Subject: [PATCH 1/2] =?UTF-8?q?[T2]=20Bogenw=C3=A4nde=20im=20eigenen=20Ker?= =?UTF-8?q?n:=20Wall.bulge,=20Verschneidung=20Bogen/Gerade=20je=20Schicht,?= =?UTF-8?q?=20Grundriss=20gebogen=20(DXF-B=C3=B6gen),=203D/Schnitt/Ansicht?= =?UTF-8?q?=20als=20Sehnen-Teilw=C3=A4nde,=20exakte=20Mengen,=20IFC=20mit?= =?UTF-8?q?=20Kreisachse,=20Wand-Befehl=20=E2=80=9EBogen=E2=80=9C,=20Schei?= =?UTF-8?q?tel-Griff,=20=C3=96ffnungen=20am=20Bogen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 26 +- src-tauri/core/src/cmd_create.rs | 137 +++++- src-tauri/core/src/cmd_draw.rs | 14 +- src-tauri/core/src/cmd_transform.rs | 25 +- src-tauri/core/src/export_schedule.rs | 3 +- src-tauri/core/src/flaechen.rs | 7 +- src-tauri/core/src/grips.rs | 26 +- src-tauri/core/src/ifc_data.rs | 76 +++- src-tauri/core/src/ifc_quantities.rs | 51 +++ src-tauri/core/src/joins.rs | 313 ++++++++++++- src-tauri/core/src/lib.rs | 1 + src-tauri/core/src/mesh_data.rs | 74 ++++ src-tauri/core/src/model/generated.rs | 6 + src-tauri/core/src/model3d.rs | 75 +++- src-tauri/core/src/plan/domains.rs | 44 ++ src-tauri/core/src/plan/elevation.rs | 117 ++++- src-tauri/core/src/plan/prim.rs | 3 + src-tauri/core/src/plan/section.rs | 32 +- src-tauri/core/src/plan/stairs.rs | 1 + src-tauri/core/src/plan/underlay.rs | 2 +- src-tauri/core/src/plan/walls.rs | 226 +++++++++- src-tauri/core/src/plan_buf.rs | 8 +- src-tauri/core/src/plan_elevation.rs | 50 ++- src-tauri/core/src/plan_scene.rs | 3 +- src-tauri/core/src/plan_walls.rs | 2 +- src-tauri/core/src/selection_info.rs | 9 +- src-tauri/core/src/site_rules.rs | 6 +- src-tauri/core/src/snap_model.rs | 21 +- src-tauri/core/src/sun.rs | 5 + src-tauri/core/src/wall_arc.rs | 609 ++++++++++++++++++++++++++ src-tauri/core/src/wall_bands.rs | 5 +- src-tauri/fileio/src/ifc_export.rs | 85 ++++ src/commands/cmds/opening.ts | 12 +- src/commands/cmds/wall.test.ts | 44 ++ src/commands/cmds/wall.ts | 137 ++++-- src/model/types.generated.ts | 6 + src/state/useGripEditing.ts | 13 +- 37 files changed, 2153 insertions(+), 121 deletions(-) create mode 100644 src-tauri/core/src/wall_arc.rs diff --git a/TODO.md b/TODO.md index 1c2e2c12..132f7e80 100644 --- a/TODO.md +++ b/TODO.md @@ -1283,7 +1283,29 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]). - ✅ truck 0.6, B-Rep-Grundkörper, Booleans mit Mesh-Fallback, Transformation, STEP-Export und -Import, Kennwerte, Kollisionsprüfung, `mesh`-Spec. - ○ **[T1] Polyeder-Körper** (`try_attach_plane` → Shell → Solid). · M -- ○ **[T2] Bogenwände** (`tsweep`/`rsweep` mit Kreisbögen). · L +- ◐ **[T2] Bogenwände** (30.10., im eigenen Kern statt truck) · L + Modell `Wall.bulge` (optional; Modell-Bulge wie Polylinien: positiv = Scheitel links der Sehne). Kern + `wall_arc.rs`: Bogen, Abwicklung (`Unroll`), Sehnen-Zerlegung (Pfeil ≤ 1 mm, ≤ 7.5°). **Verschneidung** + (`joins.rs`): L/T/Knoten-T/Mittelspanne Bogen–Gerade und Bogen–Bogen über Kreis/Gerade-Schnitte, Schnittlinie + durch die exakten Flächen-Treffer, materialbewusst je Schicht ([108]: Nah-Putz-Aussparung in Bogenlänge); + tangentialer Übergang (Turm aus Halbkreisen) = radiale Stossfuge ohne Strich; gerade Wände bitgleich wie + bisher. **Grundriss**: die gerade Pipeline rechnet auf der abgewickelten Wand, die Ausgabe wird gebogen + (Punkte auf Schnittlinien rasten exakt ein); Umriss/Fugen als `arc`-Primitive (≤ 90°, `arc` trägt jetzt + `color`) → DXF ARC; Schichtbänder in Winkelstücke geteilt, Schraffur je Stück an der Tangente ausgerichtet + (Entscheid: folgt der Krümmung stückweise, Muster-Phase springt an den Stücken). **Öffnungen**: Lage = + Bogenlänge auf der Achse; Lücke radial durch alle Schichten, Plansymbol gebogen; Einbauteile (3D, Schnitt, + Ansicht, IFC-Füllung) gerade auf der Sehne zwischen den Laibungen (Entscheid). **3D/Schnitt/Ansicht/OBJ**: + Sehnen-Teilwände mit radialen Gehrungen (`chord_walls`, Teilstellen auch an den Laibungen, Teilwände in der + Öffnung = Brüstung/Sturz); Ansicht ohne Facetten-Fugen (Ecken auf der Gehrung, innere Stirnflächen + entfallen). **Mengen** exakt (Bogenlänge, Ringsektor; IFC Qto, Objekt-Info, Bauteilliste). **IFC**: Datensatz + `WALL_ARC` — Körper als Netz, Achse `IfcTrimmedCurve` auf `IfcCircle` (`validate-ifc.py` ohne Befund). + **Befehle**: Wand-Option „Bogen" (Drei-Punkt/Tangential wie Polylinie), Scheitel-Griff, Spiegeln kehrt den + Bulge, Öffnung am Bogen platzieren; Fang, Raum-Erkennung, Schatten, Baurecht, Flächen über den Sehnenzug. + Tests: Rust (Verschneidung, Ringsektor-Volumen/dicht, Grundriss im Kreisring, Ansicht ohne Fugen, IFC, + Befehle), vitest (Wand-Befehl). Geprüft im Linux-Container (CLI-SVG Grundriss/Schnitt/Ansicht, IFC), nicht in + der Tauri-App. Offen: Schichteinzug [106] und Formöffnungen [G3] in Bogenwänden; Wände teilen/trimmen (fehlt + auch für gerade); echte Polar-Schraffur; IFC-Körper als extrudiertes Bogenprofil statt Netz; Griff-Vorschau + zeigt nur die Achse. - ○ **[T3] Wendeltreppe/Wendelfläche** + Handlauf-Sweep. · M - ○ **[T4] Import-Meshes glätten oder kantig** (`add_smooth_normals`). · S - ○ **[T5] Import reparieren** (`put_together_same_attrs`, Healing). · S @@ -1947,7 +1969,7 @@ Ganzes nicht WASM-tauglich (rayon, tempfile, SystemTime) — nur einzelne Module beim Speichern verloren; Panel in den Standard-Dock aufnehmen. · M - ○ **[B6] Wand unter Dach als Prismen zwischen Ebenen** (für [G2]). `walls.rs:413–472, 592–654`. · M - ○ **[B7] Dach-Verschneidung und Gauben in 2.5D** (für [G5]). · M · nach [B2]/[B6]. -- ○ **[B8] Bogenwände, schneller Weg** (für [T2]). · S/M–L +- ✅ **[B8] Bogenwände, schneller Weg** (für [T2]). (30.10.) Sehnen-Zerlegung im Kern statt Sweep, s. [T2]. · S/M–L - ✅ **[B9] Punktwolken-Leser** (für [27]). (28.10.) `src-tauri/fileio/src/pointcloud*.rs` + `web_pointcloud.rs`, TS-Fassade `src/io/pointCloud.ts` (+ `pointCloud.worker.ts`, Web-Worker wie DWG), CLI `pointcloud-info`. Formate: LAS 1.0–1.4 (Punktformate 0–10, eigener Leser), LAZ (Crate `laz` 0.13, Apache-2.0), E57 (Crate diff --git a/src-tauri/core/src/cmd_create.rs b/src-tauri/core/src/cmd_create.rs index 6cd94f34..f0225a3a 100644 --- a/src-tauri/core/src/cmd_create.rs +++ b/src-tauri/core/src/cmd_create.rs @@ -363,22 +363,28 @@ fn wall_ops(root: &Map, v: &Value, ctx: &Ctx, ids: &mut IdGen) -> type_id = id; } } + // Bogen-Modus ([T2]): `segs` je Segment wie bei der Polylinie (gerade, tangential, Durchgangspunkt). + let bulges = crate::cmd_draw::poly_bulges(&pts, arr(v.get("segs"))); let mut walls = Vec::new(); - for w in pts.windows(2) { + for (i, w) in pts.windows(2).enumerate() { let (a, b) = (w[0], w[1]); if seg_len(a, b) < EPS { continue; } - walls.push(obj(vec![ + let mut f = vec![ ("id", s(&ids.next("W"))), ("type", s("wall")), ("floorId", s(ctx.level)), ("categoryCode", s(ctx.cat)), ("start", pv(a)), ("end", pv(b)), - ("wallTypeId", type_id.clone()), - ("height", js_num(height)), - ])); + ]; + if let Some(bl) = bulges.get(i).copied().filter(|b| b.abs() > EPS && b.is_finite()) { + f.push(("bulge", js_num(bl))); + } + f.push(("wallTypeId", type_id.clone())); + f.push(("height", js_num(height))); + walls.push(obj(f)); } if walls.is_empty() { return Vec::new(); @@ -390,11 +396,18 @@ fn wall_ops(root: &Map, v: &Value, ctx: &Ctx, ids: &mut IdGen) -> /// Wand-Vorschau: je Segment das Band (Dicke wie beim Commit) und die Achse. fn wall_preview(root: &Map, v: &Value, ctx: &Ctx, pts: &[V], out: &mut Shapes) { let t = wall_thickness(root, ctx, opt_n(v, "thick")); - for w in pts.windows(2) { + let bulges = crate::cmd_draw::preview_bulges(v, pts); + for (i, w) in pts.windows(2).enumerate() { let (a, b) = (w[0], w[1]); if seg_len(a, b) < EPS { continue; } + // Bogenwand ([T2]): Band als Kreisringsektor, Achse als Bogen. + if let Some((band, axis)) = crate::wall_arc::band_preview(a, b, bulges.get(i).copied(), t) { + out.poly(&band); + out.poly_open(&axis); + continue; + } out.poly(&wall_corners(a, b, t)); out.line(a, b); } @@ -458,8 +471,13 @@ fn floor_walls_flat(root: &Map, level: &str) -> Vec { let tid = field(w, "wallTypeId").and_then(Value::as_str); let wt = types.iter().find(|t| id_of(t) == tid); let (a, b) = (xy(field(w, "start").unwrap_or(&Value::Null)), xy(field(w, "end").unwrap_or(&Value::Null))); - out.extend([a.0, a.1, b.0, b.1, wt.map_or(0.2, type_thickness)]); - n += 1; + let t = wt.map_or(0.2, type_thickness); + // Bogenwand ([T2]): als Sehnenzug. + let pts = crate::wall_arc::axis_polyline(a, b, bulge_of(w), 0.0, t); + for q in pts.windows(2) { + out.extend([q[0].0, q[0].1, q[1].0, q[1].1, t]); + n += 1; + } } out[0] = n as f64; out @@ -652,6 +670,28 @@ fn project_onto_wall(start: V, end: V, p: V) -> (f64, V, f64) { (t * len2.sqrt(), foot, dist) } +/// Bogenwand ([T2]): Bogen aus Achse und Bulge der Anfrage bzw. Wand. +fn arc_of(a: V, b: V, bulge: Option) -> Option { + crate::wall_arc::WallArc::of(to_p(a), to_p(b), bulge) +} + +/// Wie [`project_onto_wall`], bei Bogenwänden auf den Bogen (Abstand = Bogenlänge ab Wandanfang). +fn project_onto_any(start: V, end: V, bulge: Option, p: V) -> (f64, V, f64) { + match arc_of(start, end, bulge) { + Some(a) => { + let (s, _) = a.local(to_p(p)); + let s = jsnum::max(0.0, jsnum::min(s, a.length())); + let f = a.point(s, 0.0); + (s, (f.x, f.y), hypot2(p.0 - f.x, p.1 - f.y)) + } + None => project_onto_wall(start, end, p), + } +} + +fn bulge_of(w: &Value) -> Option { + field(w, "bulge").and_then(Value::as_f64) +} + /// Nächste Wand des Geschosses zum Klickpunkt (innerhalb der Toleranz). fn pick_wall<'a>(root: &'a Map, level: &str, p: V) -> Option<(&'a Value, V, V)> { let mut best: Option<(&Value, V, V, f64)> = None; @@ -660,7 +700,7 @@ fn pick_wall<'a>(root: &'a Map, level: &str, p: V) -> Option<(&'a continue; } let (a, b) = (xy(field(w, "start").unwrap_or(&Value::Null)), xy(field(w, "end").unwrap_or(&Value::Null))); - let (_, _, dist) = project_onto_wall(a, b, p); + let (_, _, dist) = project_onto_any(a, b, bulge_of(w), p); if dist <= WALL_PICK_DIST && best.is_none_or(|x| dist < x.3) { best = Some((w, a, b, dist)); } @@ -671,7 +711,10 @@ fn pick_wall<'a>(root: &'a Map, level: &str, p: V) -> Option<(&'a /// Öffnung in eine Wand (`start`/`end` der Host-Wand beim Picken, `pos` = Abstand vom Wandanfang). fn opening_ops(root: &Map, v: &Value, ctx: &Ctx, ids: &mut IdGen) -> Vec { let (st, en) = (p_of(v, "start"), p_of(v, "end")); - let len = hypot2(en.0 - st.0, en.1 - st.1); + let len = match arc_of(st, en, opt_n(v, "bulge")) { + Some(a) => a.length(), + None => hypot2(en.0 - st.0, en.1 - st.1), + }; let width = jsnum::max(0.1, jsnum::min(n_of(v, "width"), len)); let position = jsnum::max(0.0, jsnum::min(n_of(v, "pos"), jsnum::max(0.0, len - width))); let door = s_of(v, "kind") == "door"; @@ -704,6 +747,40 @@ fn opening_ops(root: &Map, v: &Value, ctx: &Ctx, ids: &mut IdGen) /// `info = [pos, von, ax, ay, bx, by, mx, my]` (Position für den Zustand, HUD/Stützpunkte). fn opening_preview(v: &Value, cursor: Option, out: &mut Shapes, info: &mut Vec) { let (st, en) = (p_of(v, "start"), p_of(v, "end")); + // Bogenwand ([T2]): Lücke und Symbol entlang des Bogens, Position = Bogenlänge. + if let Some(arc) = arc_of(st, en, opt_n(v, "bulge")) { + let len = arc.length(); + let pos = match (opt_n(v, "pos"), cursor) { + (Some(p), _) => p, + (None, Some(c)) => project_onto_any(st, en, opt_n(v, "bulge"), c).0, + (None, None) => 0.0, + }; + let width = n_of(v, "width"); + let from = jsnum::max(0.0, jsnum::min(pos, len)); + let to = jsnum::max(from, jsnum::min(from + width, len)); + let at = |s: f64, n: f64| { + let q = arc.point(s, n); + (q.x, q.y) + }; + let st_pts = arc.stations(from, to, arc.r + 0.15); + let half = 0.15; + let mut band: Vec = st_pts.iter().map(|&s| at(s, half)).collect(); + band.extend(st_pts.iter().rev().map(|&s| at(s, -half))); + out.poly(&band); + let (a, b) = (at(from, 0.0), at(to, 0.0)); + if s_of(v, "kind") == "door" { + let swing = if s_of(v, "side") == "left" { 1.0 } else { -1.0 }; + let dir = if s_of(v, "dir") == "in" { 1.0 } else { -1.0 }; + let (hs, hinge) = if s_of(v, "hinge") == "start" { (from, a) } else { (to, b) }; + let nn = arc.normal(hs); + out.line(hinge, (hinge.0 + nn.x * swing * dir * width, hinge.1 + nn.y * swing * dir * width)); + } else { + out.poly_open(&st_pts.iter().map(|&s| at(s, 0.0)).collect::>()); + } + let m = at((from + to) / 2.0, 0.0); + info.extend([pos, from, a.0, a.1, b.0, b.1, m.0, m.1]); + return; + } let pos = match (opt_n(v, "pos"), cursor) { (Some(p), _) => p, (None, Some(c)) => project_onto_wall(st, en, c).0, @@ -984,7 +1061,13 @@ pub fn query(root: &Map, v: &Value) -> Option match pick_wall(root, level, at) { - Some((w, a, b)) => json!({ "hit": { "id": id_of(w), "start": [js_num(a.0), js_num(a.1)], "end": [js_num(b.0), js_num(b.1)], "t": js_num(project_onto_wall(a, b, at).0) } }), + Some((w, a, b)) => { + let mut hit = json!({ "id": id_of(w), "start": [js_num(a.0), js_num(a.1)], "end": [js_num(b.0), js_num(b.1)], "t": js_num(project_onto_any(a, b, bulge_of(w), at).0) }); + if let Some(bl) = bulge_of(w).filter(|_| arc_of(a, b, bulge_of(w)).is_some()) { + hit["bulge"] = js_num(bl); + } + json!({ "hit": hit }) + } None => json!({ "hit": null }), }, "pickProfile" => json!({ "hit": pick_profile(root, level, at).map_or(Value::Null, profile_json) }), @@ -1072,6 +1155,24 @@ mod tests { v } + /// [T2] Bogen-Modus: Drei-Punkt-Bogen (Durchgangspunkt) und tangential anschliessend; Vorschau als + /// Kreisringsektor. + #[test] + fn bogenwand_drei_punkt_und_tangential() { + let r = root(json!({"wallTypes": [{"id": "WT1", "name": "Beton", "layers": [{"componentId": "c", "thickness": 0.2}]}]})); + // (0,0)→(4,0) durch (2,2): Halbkreis, Scheitel links → Modell-Bulge +1; dann tangential weiter nach (4,-4)? + let o = ops(&r, &req(json!({"cmd": "wall", "pts": [[0, 0], [4, 0], [8, 0]], "segs": [{"x": 2, "y": 2}, 1], "thick": null}))).unwrap(); + let w = items(&o, 0); + let b0 = w[0]["bulge"].as_f64().unwrap(); + assert!((b0 - 1.0).abs() < 1e-9, "{b0}"); + // Tangential an das Ende des Halbkreises (Richtung −y): zweiter Halbkreis mit Scheitel unten (Bulge −1). + let b1 = w[1]["bulge"].as_f64().unwrap(); + assert!((b1 + 1.0).abs() < 1e-9, "{b1}"); + // Gerade Wand ohne `bulge`-Feld. + let o = ops(&r, &req(json!({"cmd": "wall", "pts": [[0, 0], [4, 0]], "segs": [0], "thick": null}))).unwrap(); + assert!(items(&o, 0)[0].get("bulge").is_none()); + } + #[test] fn waende_je_segment_mit_typ_und_hoehe() { let r = root(json!({"wallTypes": [{"id": "WT1", "name": "Beton", "layers": [{"componentId": "c", "thickness": 0.2}]}]})); @@ -1118,6 +1219,20 @@ mod tests { assert!(group_ops(&r, &[], "g").is_empty()); } + /// [T2] Öffnung in der Bogenwand: Picken am Bogen, Position = Bogenlänge, Begrenzung auf die Bogenlänge. + #[test] + fn oeffnung_in_bogenwand() { + // Halbkreis (0,0)→(4,0), Scheitel oben (2,2): Bogenlänge 2π. + let r = root(json!({"walls": [{"id": "w", "floorId": "F1", "start": {"x": 0, "y": 0}, "end": {"x": 4, "y": 0}, "bulge": 1}], "windowTypes": [{"id": "FT"}]})); + let q = query(&r, &json!({"q": "pickWall", "level": "F1", "pt": [2, 2.2]})).unwrap().unwrap(); + assert_eq!(q["hit"]["id"], "w"); + assert!((q["hit"]["t"].as_f64().unwrap() - std::f64::consts::PI).abs() < 1e-9); + assert_eq!(q["hit"]["bulge"], 1); + let o = ops(&r, &req(json!({"cmd": "opening", "wall": "w", "start": [0, 0], "end": [4, 0], "bulge": 1, "kind": "window", "pos": 6.0, "width": 1.2, "height": 1.2, "sill": 0.9}))).unwrap(); + let pos = items(&o, 0)[0]["position"].as_f64().unwrap(); + assert!((pos - (2.0 * std::f64::consts::PI - 1.2)).abs() < 1e-9, "{pos}"); + } + #[test] fn oeffnung_pick_und_vorschau() { let r = root(json!({"walls": [{"id": "w", "floorId": "F1", "start": {"x": 0, "y": 0}, "end": {"x": 6, "y": 0}}], "windowTypes": [{"id": "FT"}]})); diff --git a/src-tauri/core/src/cmd_draw.rs b/src-tauri/core/src/cmd_draw.rs index 79b7053f..ba24e9d6 100644 --- a/src-tauri/core/src/cmd_draw.rs +++ b/src-tauri/core/src/cmd_draw.rs @@ -144,7 +144,7 @@ fn seg_bulge(seg: &Value, prev: V, pt: V, points: &[V], bulges: &[f64]) -> f64 { } /// Bulges der gesetzten Segmente der Reihe nach (jeder Bogen kennt die Richtung seines Vorgängers). -fn poly_bulges(points: &[V], segs: &[Value]) -> Vec { +pub(crate) fn poly_bulges(points: &[V], segs: &[Value]) -> Vec { let mut bulges: Vec = Vec::new(); for i in 1..points.len() { let seg = segs.get(i - 1).unwrap_or(&Value::Null); @@ -176,8 +176,10 @@ fn polyline_ops(v: &Value, ctx: &Ctx, ids: &mut IdGen) -> Vec { add_drawing(v, ctx, ids, obj(g)) } -/// Polylinien-Vorschau: gesetzte Punkte + Cursor (letzter Punkt in `pts`, falls `cursor`), Bogen-Modus. -fn polyline_preview(v: &Value, pts: &[V], out: &mut Shapes) { +/// Bulges je Segment einer Vorschau (Polylinie, Wand): gesetzte Segmente aus `segs`, dazu das lebende +/// Segment zum Cursor (letzter Punkt in `pts`, falls `cursor`) im Bogen-Modus (`arc`, `tangent`, +/// `through`). +pub(crate) fn preview_bulges(v: &Value, pts: &[V]) -> Vec { let has_cursor = b_of(v, "cursor"); let points = if has_cursor && !pts.is_empty() { &pts[..pts.len() - 1] } else { pts }; let bulges = poly_bulges(points, arr(v.get("segs"))); @@ -194,6 +196,12 @@ fn polyline_preview(v: &Value, pts: &[V], out: &mut Shapes) { }; all_b.push(pb); } + all_b +} + +/// Polylinien-Vorschau: gesetzte Punkte + Cursor (letzter Punkt in `pts`, falls `cursor`), Bogen-Modus. +fn polyline_preview(v: &Value, pts: &[V], out: &mut Shapes) { + let all_b = preview_bulges(v, pts); let shown = bulge_points(pts, &all_b, false); if b_of(v, "closed") && pts.len() >= 3 { out.poly(&shown); diff --git a/src-tauri/core/src/cmd_transform.rs b/src-tauri/core/src/cmd_transform.rs index b7f46ab5..b2d293b5 100644 --- a/src-tauri/core/src/cmd_transform.rs +++ b/src-tauri/core/src/cmd_transform.rs @@ -226,7 +226,11 @@ fn with_geom(d: &Value, g: Option) -> Value { // ── Bauteile ───────────────────────────────────────────────────────────────── fn mv_wall(w: &Value, xf: &Xf) -> Value { - with_all(w, vec![("start", xf.pt_of(field(w, "start"))), ("end", xf.pt_of(field(w, "end")))]) + // Bogenwand ([T2]): eine Spiegelung kehrt den Bogen um (Bulge-Vorzeichen hängt an der Laufrichtung). + match field(w, "bulge").and_then(Value::as_f64) { + Some(b) if xf.reverses() => with_all(w, vec![("start", xf.pt_of(field(w, "start"))), ("end", xf.pt_of(field(w, "end"))), ("bulge", js_num(-b))]), + _ => with_all(w, vec![("start", xf.pt_of(field(w, "start"))), ("end", xf.pt_of(field(w, "end")))]), + } } /// Stütze: Einfügepunkt und Profil-Drehung (über einen mit abgebildeten Richtungspunkt). @@ -856,6 +860,12 @@ fn item_preview(root: &Map, kind: Kind, e: &Value, xf: &Xf, out: let (sx, sy) = pt("start"); let (ex, ey) = pt("end"); let (a, b) = (xf.apply(sx, sy), xf.apply(ex, ey)); + let bulge = field(e, "bulge").and_then(Value::as_f64).map(|b| if xf.reverses() { -b } else { b }); + if let Some((band, axis)) = crate::wall_arc::band_preview(a, b, bulge, th) { + s.poly(&band); + s.poly_open(&axis); + return; + } let v = |p: (f64, f64)| crate::model::Vec2 { x: p.0, y: p.1 }; let c = crate::site_rules::wall_corners(v(a), v(b), th); s.poly(&[(c[0][0], c[0][1]), (c[1][0], c[1][1]), (c[2][0], c[2][1]), (c[3][0], c[3][1])]); @@ -988,6 +998,19 @@ mod tests { v.as_object().unwrap().clone() } + /// [T2] Bogenwand: Verschieben/Drehen behalten den Bulge, Spiegeln kehrt ihn um. + #[test] + fn bogenwand_spiegeln_kehrt_bulge() { + let r = root(json!({"walls":[{"id":"a","start":{"x":0,"y":0},"end":{"x":4,"y":0},"bulge":0.5}]})); + let run = |op: &str, pts: Value| { + let req: TransformReq = serde_json::from_value(json!({"sel":{"wallIds":["a"]},"op":op,"pts":pts,"mode":"move","count":1,"stamp":"s"})).unwrap(); + transform_ops(&r, &req)[0].to_json()["entity"].clone() + }; + assert_eq!(run("move", json!([[0, 0], [1, 1]]))["bulge"], json!(0.5)); + assert_eq!(run("rotate", json!([[0, 0], [1, 0], [0, 1]]))["bulge"], json!(0.5)); + assert_eq!(run("mirror", json!([[0, 0], [0, 1]]))["bulge"], json!(-0.5)); + } + #[test] fn verschieben_und_kopieren() { let r = root(json!({"walls":[{"id":"a","start":{"x":0,"y":0},"end":{"x":1,"y":0},"locked":false},{"id":"b","start":{"x":0,"y":0},"end":{"x":1,"y":0},"locked":true}]})); diff --git a/src-tauri/core/src/export_schedule.rs b/src-tauri/core/src/export_schedule.rs index 7bb71a5b..8338acdf 100644 --- a/src-tauri/core/src/export_schedule.rs +++ b/src-tauri/core/src/export_schedule.rs @@ -3,7 +3,6 @@ //! CSV-Ausgabe (RFC 4180, Feldtrenner `;`, Zeilenende CRLF) mit Aggregat je Bauteil-Typ. use crate::js_fmt::to_fixed; -use crate::jsmath::hypot2; use crate::jsnum::round; use crate::model::*; use serde::Serialize; @@ -41,7 +40,7 @@ pub fn schedule_rows(p: &Project) -> Vec { Some(t) => (t.name.clone(), Project::type_thickness(&t.layers)), None => (w.wall_type_id.clone(), 0.0), }; - let length = hypot2(w.end.x - w.start.x, w.end.y - w.start.y); + let length = crate::wall_arc::axis_length(w); rows.push(ScheduleRow { kind: "Wand", id: w.id.clone(), diff --git a/src-tauri/core/src/flaechen.rs b/src-tauri/core/src/flaechen.rs index 05ea643c..d47b3036 100644 --- a/src-tauri/core/src/flaechen.rs +++ b/src-tauri/core/src/flaechen.rs @@ -173,7 +173,12 @@ fn wall_polygons(p: &Project, level_id: &str) -> Vec { .walls .iter() .filter(|w| w.floor_id == level_id) - .map(|w| W { s: [w.start.x, w.start.y], e: [w.end.x, w.end.y], t: finite(p.wall_thickness(w, 0.2)).max(0.0) }) + // Bogenwand ([T2]): als Sehnenzug. + .flat_map(|w| { + let t = finite(p.wall_thickness(w, 0.2)).max(0.0); + let pts = crate::wall_arc::axis_polyline((w.start.x, w.start.y), (w.end.x, w.end.y), w.bulge, 0.0, t); + pts.windows(2).map(|q| W { s: [q[0].0, q[0].1], e: [q[1].0, q[1].1], t }).collect::>() + }) .filter(|w| w.s.iter().chain(w.e.iter()).all(|v| v.is_finite()) && (w.e[0] - w.s[0]).hypot(w.e[1] - w.s[1]) > 1e-9) .collect(); // Abstand eines Punktes zur Strecke. diff --git a/src-tauri/core/src/grips.rs b/src-tauri/core/src/grips.rs index 52f3974d..1122a5b7 100644 --- a/src-tauri/core/src/grips.rs +++ b/src-tauri/core/src/grips.rs @@ -393,7 +393,11 @@ pub fn run(lk: &Lookup, req: &Request) -> Result { let e = xy(field(wall, "end").unwrap_or(&Value::Null)); let (ax, ay, sx, sy) = scale_around(bbox(&[s, e]), w, h, fx, fy); let f = |p: (f64, f64)| pt(ax + (p.0 - ax) * sx, ay + (p.1 - ay) * sy); - Some(with_all(wall, vec![("start", f(s)), ("end", f(e))])) + // Bogenwand: negativer Massstab (Spiegelung) kehrt den Bogen um. + match field(wall, "bulge").and_then(Value::as_f64) { + Some(b) if sx * sy < 0.0 => Some(with_all(wall, vec![("start", f(s)), ("end", f(e)), ("bulge", js_num(-b))])), + _ => Some(with_all(wall, vec![("start", f(s)), ("end", f(e))])), + } }) .into() } @@ -496,6 +500,12 @@ pub fn run(lk: &Lookup, req: &Request) -> Result { // ── Wand ───────────────────────────────────────────────────────────────────── fn wall_grip(w: &Value, index: f64, x: f64, y: f64) -> Value { + // Bogenwand ([T2]): Griff 2 = Bogenscheitel; der Bogen geht durch den gezogenen Punkt. + if index == 2.0 { + let (s, e) = (xy(field(w, "start").unwrap_or(&Value::Null)), xy(field(w, "end").unwrap_or(&Value::Null))); + let b = crate::bulge::from_sagitta_point(s.0, s.1, e.0, e.1, x, y); + return with_opt(w, vec![("bulge", (b.is_finite() && b.abs() > 1e-9).then(|| js_num(b)))]); + } with(w, if index == 0.0 { "start" } else { "end" }, pt(x, y)) } @@ -1249,6 +1259,20 @@ mod tests { assert!(num_of(None).is_nan()); } + /// [T2] Bogenwand: Griff 2 setzt den Scheitel (Bulge), Endpunkt-Griffe behalten ihn; gerade + /// gezogen fällt der Bulge weg. + #[test] + fn bogenwand_scheitel_griff() { + let r = root(json!({"walls": [{"id": "w", "start": {"x": 0, "y": 0}, "end": {"x": 4, "y": 0}, "bulge": 0.5}]})); + let res = run(&Lookup::plain(&r), &rq(json!({"op": "moveGrip", "wallId": "w", "index": 2, "pt": [2, 2]}))).unwrap(); + let e = res.ops[0].to_json()["entity"].clone(); + assert!((e["bulge"].as_f64().unwrap() - 1.0).abs() < 1e-12, "{e}"); + let res = run(&Lookup::plain(&r), &rq(json!({"op": "moveGrip", "wallId": "w", "index": 1, "pt": [5, 0]}))).unwrap(); + assert_eq!(res.ops[0].to_json()["entity"]["bulge"], json!(0.5)); + let res = run(&Lookup::plain(&r), &rq(json!({"op": "moveGrip", "wallId": "w", "index": 2, "pt": [2, 0]}))).unwrap(); + assert!(res.ops[0].to_json()["entity"].get("bulge").is_none()); + } + #[test] fn wand_griff_und_sperre() { let r = root(json!({"walls": [{"id": "w", "start": {"x": 0, "y": 0}, "end": {"x": 1, "y": 0}, "extra": 1}]})); diff --git a/src-tauri/core/src/ifc_data.rs b/src-tauri/core/src/ifc_data.rs index fcafb2eb..20d72549 100644 --- a/src-tauri/core/src/ifc_data.rs +++ b/src-tauri/core/src/ifc_data.rs @@ -47,6 +47,7 @@ const REC_CLASSIFICATION: f64 = 12.0; const REC_ZONE: f64 = 13.0; const REC_ATTACH: f64 = 14.0; const REC_OPENING_SOLID: f64 = 15.0; +const REC_WALL_ARC: f64 = 16.0; /// Toleranz des Kerns (`wall_bands.rs::EPS`) für „Öffnung trifft Band". const BAND_EPS: f64 = 1e-4; @@ -230,6 +231,25 @@ fn axis_rect(wall: &Wall, from: f64, to: f64, n_lo: f64, n_hi: f64) -> Vec vec![add_scaled(a, n, n_lo), add_scaled(b, n, n_lo), add_scaled(b, n, n_hi), add_scaled(a, n, n_hi)] } +/// [T2] Öffnung in der Bogenwand als gerade Ersatzwand (Sehne der Achse zwischen den Laibungen): +/// (Ersatzwand, Intervall 0…Sehne, Querbereich zur Sehne, Einzug je Ende damit der Öffnungskörper +/// auch an den Flächen innerhalb des radialen Lochs bleibt). +fn arc_opening_chord(wall: &Wall, a: &crate::wall_arc::WallArc, c: &Cutout, host: (f64, f64)) -> (Wall, Cutout, (f64, f64), f64, f64) { + let (ps, pe) = (a.point(c.from, 0.0), a.point(c.to, 0.0)); + let mid = a.point((c.from + c.to) / 2.0, 0.0); + let chord = (pe.x - ps.x).hypot(pe.y - ps.y); + let mut vw = wall.clone(); + vw.start = Vec2 { x: ps.x, y: ps.y }; + vw.end = Vec2 { x: pe.x, y: pe.y }; + vw.bulge = None; + let u = normalize(sub(vw.end, vw.start)); + let n = left_normal(u); + let delta = (mid.x - (ps.x + pe.x) / 2.0) * n.x + (mid.y - (ps.y + pe.y) / 2.0) * n.y; + let half_angle = (c.to - c.from) / a.r / 2.0; + let shrink = (host.0.abs().max(host.1.abs()) + delta.abs()) * half_angle.tan(); + (vw, Cutout { from: 0.0, to: chord, z_bottom: c.z_bottom, z_top: c.z_top }, (host.0 + delta, host.1 + delta), shrink.min(chord / 4.0), delta.abs()) +} + /// Sortierung `byFrom` (Anfang, dann Unterkante; NaN gilt als gleich wie in `Array.sort`). fn by_from(p: &[f64; 4], q: &[f64; 4]) -> std::cmp::Ordering { let d = p[0] - q[0]; @@ -684,7 +704,7 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result let cutouts_of = |p: &Project, wall: &Wall| -> Vec<(usize, Cutout)> { let mut out = Vec::new(); let (zb, zt) = p.wall_vertical_extent(wall); - let axis = hypot2(wall.end.x - wall.start.x, wall.end.y - wall.start.y); + let axis = crate::wall_arc::axis_length(wall); for (k, o) in openings.iter().enumerate().filter(|(_, o)| o.host_wall_id == wall.id) { let from = max(0.0, min(o.position, axis)); let to = max(from, min(o.position + o.width, axis)); @@ -708,7 +728,8 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result let plain: Vec = cutouts.iter().map(|x| x.1).collect(); cutouts_by_wall.insert(wall.id.clone(), cutouts); classified.push((format!("wall/{}", wall.id), Kind::Wall, wall.category_code.clone())); - if !bands_match_openings(wall, &bands, &plain) { + // Bogenwand ([T2]): immer als Netz (Sehnen-Körper) mit Kreisbogen-Achse. + if crate::wall_arc::WallArc::of_wall(wall).is_some() || !bands_match_openings(wall, &bands, &plain) { mesh_walls.push(wi); continue; } @@ -763,8 +784,10 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result i += 3; } } - // Formöffnungen ([G3]): Füllkörper zwischen Rechteck-Loch und Umriss gehören zur Wand. - for &(k, c) in cutouts_by_wall.get(&wall.id).map_or(&[][..], |v| v.as_slice()) { + let arc = crate::wall_arc::WallArc::of_wall(wall); + // Formöffnungen ([G3]): Füllkörper zwischen Rechteck-Loch und Umriss gehören zur Wand (nicht bei + // Bogenwänden: dort bleibt das Rechteck-Loch). + for &(k, c) in cutouts_by_wall.get(&wall.id).map_or(&[][..], |v| v.as_slice()).iter().filter(|_| arc.is_none()) { let o = &openings[k]; let Some(poly) = crate::opening_shape::opening_outline(o, c.to - c.from, c.z_top - c.z_bottom) else { continue }; let n = crate::opening_shape::fill_quads(&poly, c.to - c.from, c.z_top - c.z_bottom).len(); @@ -788,19 +811,31 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result let closed = is_watertight(&positions, &indices, 1e-6); let net = closed.then(|| crate::export_flat::mesh_volume(&positions, &indices)); let plain: Vec = cutouts_by_wall.get(&wall.id).map_or_else(Vec::new, |v| v.iter().map(|x| x.1).collect()); - let mut quantities = qty::wall_quantities(wall.start, wall.end, bands, &plain, net); - if net.is_none() { + let total = p.wall_thickness(wall, 0.2); + let ro = crate::joins::reference_offset(model3d::wall_reference(wall), total); + let mut quantities = match &arc { + Some(a) => { + let (zb, zt) = p.wall_vertical_extent(wall); + // Exakt aus dem Kreis statt aus dem Sehnen-Netz. + qty::arc_wall_quantities(a, ro - total / 2.0, ro + total / 2.0, zb, zt, &plain, None) + } + None => qty::wall_quantities(wall.start, wall.end, bands, &plain, net), + }; + if net.is_none() && arc.is_none() { let gross = quantities.iter().find(|x| x.name == "GrossVolume").map_or(f64::NAN, |x| x.value); if let Some(nv) = quantities.iter_mut().find(|x| x.name == "NetVolume") { nv.value = max(0.0, gross - qty::hole_volume(bands)); } } let (name, ty, psets) = wall_ident(&p, wall, quantities); - w_head(&mut f, REC_WALL_MESH, structure, &wall.id, &name); + w_head(&mut f, if arc.is_some() { REC_WALL_ARC } else { REC_WALL_MESH }, structure, &wall.id, &name); w_type(&mut f, ty.as_ref().map(|t| type_ref(t, 0.0, "STANDARD")).as_ref()); w_psets(&mut f, &psets); + if let Some(a) = &arc { + f.nums(&[a.center.x, a.center.y, a.r, a.a0, a.sweep]); + } w_mesh(&mut f, &positions, &indices, closed); - host_extent.insert(wall.id.clone(), cross_extent(wall, bands)); + host_extent.insert(wall.id.clone(), if arc.is_some() { (ro - total / 2.0, ro + total / 2.0) } else { cross_extent(wall, bands) }); } // ── Decken ───────────────────────────────────────────────────────────── @@ -843,8 +878,16 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result for wall in &p.walls { let Some(&host) = host_extent.get(&wall.id) else { continue }; let structure = structure_of(&wall.floor_id); + let arc = crate::wall_arc::WallArc::of_wall(wall); for &(k, c) in cutouts_by_wall.get(&wall.id).map_or(&[][..], |v| v.as_slice()) { let o = &openings[k]; + // Bogenwand ([T2]): Ersatzwand = Sehne zwischen den Laibungen; Öffnungskörper innerhalb des + // (radialen) Lochs, Füllung um den Achsversatz der Sehne verschoben. + let chord = arc.map(|a| arc_opening_chord(wall, &a, &c, host)); + let (wall, c, host, shrink, sag) = match &chord { + Some((vw, vc, vh, e, d)) => (vw, *vc, *vh, *e, *d), + None => (wall, c, host, 0.0, 0.0), + }; let depth = c.z_top - c.z_bottom; if !(depth > 1e-6) { continue; @@ -854,7 +897,7 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result let psets = fill_psets(&p, o, c.to - c.from, depth); let label = crate::plan::walls::opening_label(o); // Formöffnung ([G3]): Öffnungskörper = Umriss quer durch die Wand, Füllung als Netz. - if let Some(poly) = crate::opening_shape::opening_outline(o, c.to - c.from, depth) { + if let Some(poly) = crate::opening_shape::opening_outline(o, c.to - c.from, depth).filter(|_| chord.is_none()) { let u = normalize(sub(wall.end, wall.start)); let ln = left_normal(u); let at = add_scaled(add_scaled(wall.start, u, c.from), ln, host.1 + OPENING_OVERSHOOT); @@ -874,7 +917,8 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result let oid = f.str(&o.id); let lab = f.str(&label); f.nums(&[REC_OPENING, a, structure, oid, if is_door { 1.0 } else { 0.0 }, lab]); - w_pts(&mut f, &axis_rect(wall, c.from, c.to, host.0 - OPENING_OVERSHOOT, host.1 + OPENING_OVERSHOOT)); + let (vlo, vhi) = (host.0 - sag - OPENING_OVERSHOOT, host.1 + sag + OPENING_OVERSHOOT); + w_pts(&mut f, &axis_rect(wall, c.from + shrink, c.to - shrink, vlo, vhi)); f.nums(&[c.z_bottom - base_of(structure), depth, c.to - c.from]); w_fill(&mut f, wall, &c, host, &fill_params(&p, o)); w_psets(&mut f, &psets); @@ -1203,6 +1247,18 @@ mod tests { assert_eq!(f.nums.iter().filter(|v| **v == REC_OPENING_SOLID).count() >= 2, true); } + /// [T2] Bogenwand: Datensatz WALL_ARC mit Kreisachse (Mitte, Radius, Startwinkel, Schwenk). + #[test] + fn bogenwand_als_netz_mit_kreisachse() { + let mut p = sample(); + p.walls[0].bulge = Some(1.0); // W1 (0,0)→(5,0): Halbkreis, Mitte (2.5,0), Uhrzeigersinn + let f = ifc_export_data(&p, &IfcOptions::default()).unwrap(); + let pi = std::f64::consts::PI; + let hit = f.nums.windows(6).any(|w| w[0] == 2.5 && w[1] == 0.0 && (w[2] - 2.5).abs() < 1e-12 && (w[3] - pi).abs() < 1e-12 && (w[4] + pi).abs() < 1e-12); + assert!(hit, "Kreisachse fehlt"); + assert!(f.nums.contains(&REC_WALL_ARC)); + } + #[test] fn beispielprojekt_alle_bauteile() { let opt = IfcOptions { ebkph: true, layer_codes: true, now: 1.0, iso: "2026-10-29T10:00:00".into(), ..Default::default() }; diff --git a/src-tauri/core/src/ifc_quantities.rs b/src-tauri/core/src/ifc_quantities.rs index a0928c13..9aae0071 100644 --- a/src-tauri/core/src/ifc_quantities.rs +++ b/src-tauri/core/src/ifc_quantities.rs @@ -149,6 +149,41 @@ pub fn wall_quantities(start: Vec2, end: Vec2, bands: &[&RWall], cutouts: &[Cuto out } +/// Bogenwand-Basismengen ([T2]) exakt aus der Kreisgeometrie: Length = Bogenlänge der Achse, Width = +/// Dicke, GrossSideArea = Länge × Höhe, GrossVolume = Kreisringsektor (Fläche ½·θ·(R_a² − R_i²) mit den +/// Flächenradien) × Höhe; Öffnungen als Ringsektoren über ihre Bogenlänge auf der Achse. `n_lo`/`n_hi`: +/// Querbereich der Schichten zur Achse; `net_volume` wie bei [`wall_quantities`]. +pub fn arc_wall_quantities(arc: &crate::wall_arc::WallArc, n_lo: f64, n_hi: f64, z_bottom: f64, z_top: f64, cutouts: &[Cutout], net_volume: Option) -> Vec { + let length = arc.length(); + let h = z_top - z_bottom; + let theta = arc.sweep.abs(); + let (r1, r2) = (arc.radius_at(n_lo), arc.radius_at(n_hi)); + // Ringfläche je Bogenlänge auf der Achse: ½·(R_a² − R_i²)/R. + let ring_per_s = (r1 * r1 - r2 * r2).abs() / 2.0 / arc.r; + let mut gross = theta * (r1 * r1 - r2 * r2).abs() / 2.0 * h; + let gross_side = length * h; + let mut cut_side = 0.0; + let mut cut_volume = 0.0; + for c in cutouts { + let z = overlap(c.z_bottom, c.z_top, z_bottom, z_top); + cut_side += (c.to - c.from) * z; + cut_volume += (c.to - c.from) * ring_per_s * z; + } + let net = net_volume.unwrap_or_else(|| max(0.0, gross - cut_volume)); + gross = max(gross, net); + let mut out = vec![len("Length", length), len("Width", n_hi - n_lo)]; + if h > 0.0 { + out.push(len("Height", h)); + } + out.extend([ + area("GrossSideArea", gross_side), + area("NetSideArea", max(0.0, gross_side - cut_side)), + vol("GrossVolume", gross), + vol("NetVolume", net), + ]); + out +} + /// Brutto-Volumen der Löcher in den Bändern (für Netz-Wände ohne dichtes Netz). pub fn hole_volume(bands: &[&RWall]) -> f64 { let mut v = 0.0; @@ -257,6 +292,7 @@ mod tests { cut: None, start_cut: None, end_cut: None, + joint: [false; 2], } } @@ -344,6 +380,21 @@ mod tests { assert!(close(get(&q, "GrossVolume"), 4.0 * 0.3 * 2.5)); } + /// [T2] Bogenwand: Halbkreis R 5, Dicke 0.3, Höhe 2.5, eine Öffnung 1.2 × 1.0. + #[test] + fn bogenwand_mengen_exakt() { + let a = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(0.0, 0.0), kernel2d::Vec2::new(10.0, 0.0), Some(1.0)).unwrap(); + let q = arc_wall_quantities(&a, -0.15, 0.15, 0.0, 2.5, &[Cutout { from: 2.0, to: 3.2, z_bottom: 1.0, z_top: 2.0 }], None); + let pi = std::f64::consts::PI; + assert!(close(get(&q, "Length"), 5.0 * pi)); + assert!(close(get(&q, "Width"), 0.3)); + assert!(close(get(&q, "GrossSideArea"), 5.0 * pi * 2.5)); + assert!(close(get(&q, "NetSideArea"), 5.0 * pi * 2.5 - 1.2)); + // ½·π·(5.15² − 4.85²)·2.5 = π·5·0.3·2.5 + assert!(close(get(&q, "GrossVolume"), pi * 5.0 * 0.3 * 2.5)); + assert!(close(get(&q, "NetVolume"), pi * 5.0 * 0.3 * 2.5 - 1.2 * 0.3 * 1.0)); + } + #[test] fn loch_volumen() { let mut b = band([0.0, 0.0], [4.0, 0.0], 0.3, 0.0, 2.5); diff --git a/src-tauri/core/src/joins.rs b/src-tauri/core/src/joins.rs index 180fff66..9f785bdb 100644 --- a/src-tauri/core/src/joins.rs +++ b/src-tauri/core/src/joins.rs @@ -11,6 +11,7 @@ //! Die Rechenschritte folgen der TS-Fassung Operation für Operation (gleiche Term-Reihenfolge), //! damit das Ergebnis bitgleich bleibt. +use crate::wall_arc::{curve_hits, nearest, Curve, WallArc}; use kernel2d::{add, dot, left_normal, line_intersect, scale, sub, Vec2}; use std::collections::HashMap; @@ -52,6 +53,8 @@ pub struct JoinWall { pub end: Vec2, pub reference: Reference, pub layers: Option>, + /// Bogenwand ([T2], Modell-Bulge); `None` = gerade. + pub bulge: Option, } /// Unendliche Gerade (Stützpunkt + Richtung, nicht normiert). @@ -242,6 +245,71 @@ fn dir_of(w: &JoinWall) -> Vec2 { normalize(sub(w.end, w.start)) } +// ── Bogenwände ([T2]) ─────────────────────────────────────────────────────── +// +// Gerade Wände rechnen unverändert (bitgleich); sobald eine beteiligte Wand ein Bogen ist, werden +// die Flächen als Versatzkurven (Gerade/Kreis) geschnitten und die Schnittlinie als Gerade durch +// die exakten Flächen-Treffer gelegt (Aussen- und Innenecke exakt). + +fn arc_of(w: &JoinWall) -> Option { + WallArc::of(w.start, w.end, w.bulge) +} + +fn is_arc(w: &JoinWall) -> bool { + arc_of(w).is_some() +} + +/// Laufrichtung (start→end) am Ende `e`: Tangente bei Bögen. +fn dir_at(w: &JoinWall, e: End) -> Vec2 { + match arc_of(w) { + None => dir_of(w), + Some(a) => match e { + End::Start => a.tangent(0.0), + End::End => a.tangent(a.length()), + }, + } +} + +/// Versatzkurve `off` (links der Laufrichtung) einer Wand. +fn offset_curve(w: &JoinWall, off: f64) -> Curve { + match arc_of(w) { + None => { + let u = dir_of(w); + Curve::Line(Line { point: add(w.start, scale(left_normal(u), off)), dir: u }) + } + Some(a) => Curve::Circle(a.center, a.radius_at(off)), + } +} + +fn hit_near(a: &Curve, b: &Curve, near: Vec2) -> Option { + nearest(curve_hits(a, b), near) +} + +/// (Achsmass, Querversatz) eines Punkts im Rahmen der Wand. +fn local_of(w: &JoinWall, p: Vec2) -> (f64, f64) { + match arc_of(w) { + None => { + let u = dir_of(w); + (dot(sub(p, w.start), u), dot(sub(p, w.start), left_normal(u))) + } + Some(a) => a.local(p), + } +} + +/// Gerade durch die Treffer der beiden Abzweig-Flächen (`bi`) mit der Versatzkurve `off` der +/// Durchgangswand `ti`, nahe `near`; `None`, wenn eine Fläche sie nicht trifft. +fn chord_cut(walls: &[JoinWall], bi: usize, ti: usize, off: f64, near: Vec2) -> R> { + let tb = thickness(walls, bi)?; + let ob = reference_offset(walls[bi].reference, tb); + let face = offset_curve(&walls[ti], off); + let h1 = hit_near(&offset_curve(&walls[bi], ob + tb / 2.0), &face, near); + let h2 = hit_near(&offset_curve(&walls[bi], ob - tb / 2.0), &face, near); + Ok(match (h1, h2) { + (Some(a), Some(b)) if len(sub(b, a)) > 1e-9 => Some(Line { point: a, dir: sub(b, a) }), + _ => None, + }) +} + fn set_cut(result: &mut [WallCuts], we: WallEnd, cut: Line) { let c = &mut result[we.wall]; match we.end { @@ -308,6 +376,9 @@ pub fn compute_joins(walls: &[JoinWall]) -> Result, JoinError> { /// Aussen mit Aussen, Innen mit Innen — robust auch bei spitzen Winkeln). `None` bei kollinearen /// Achsen. fn miter_line(walls: &[JoinWall], ai: usize, a_end: End, bi: usize) -> R> { + if is_arc(&walls[ai]) || is_arc(&walls[bi]) { + return miter_line_arc(walls, ai, a_end, bi); + } let (a, b) = (&walls[ai], &walls[bi]); let j = point_of(a, a_end); let t_a = thickness(walls, ai)?; @@ -344,11 +415,52 @@ fn miter_line(walls: &[JoinWall], ai: usize, a_end: End, bi: usize) -> R R> { + let (a, b) = (&walls[ai], &walls[bi]); + let j = point_of(a, a_end); + let t_a = thickness(walls, ai)?; + let t_b = thickness(walls, bi)?; + let b_at_start = len(sub(b.start, j)) <= len(sub(b.end, j)); + let b_end = if b_at_start { End::Start } else { End::End }; + let u_a = dir_at(a, a_end); + let u_b = dir_at(b, b_end); + let n_a = left_normal(u_a); + let n_b = left_normal(u_b); + let off_a = reference_offset(a.reference, t_a); + let off_b = reference_offset(b.reference, t_b); + let d_a = if a_end == End::Start { u_a } else { scale(u_a, -1.0) }; + let d_b = if b_at_start { u_b } else { scale(u_b, -1.0) }; + if kernel2d::cross(u_a, u_b).abs() < 1e-6 { + // Tangentialer Übergang: rechtwinklig (radial) stossen, als Schnitt markiert (keine Fuge). + return Ok((dot(d_a, d_b) < 0.0).then_some(Line { point: j, dir: n_a })); + } + let (lb, rb) = (off_b + t_b / 2.0, off_b - t_b / 2.0); + let (b_outer, b_inner) = if dot(n_b, d_a) < 0.0 { (lb, rb) } else { (rb, lb) }; + let a_left_is_outer = dot(n_a, d_b) < 0.0; + let (b_for_left, b_for_right) = if a_left_is_outer { (b_outer, b_inner) } else { (b_inner, b_outer) }; + // Treffer nächst der Tangenten-Schätzung (sonst nächst dem Knoten). + let corner = |oa: f64, ob: f64| -> Option { + let guess = line_intersect(add(j, scale(n_a, oa)), u_a, add(j, scale(n_b, ob)), u_b).filter(|g| len(sub(*g, j)) < 10.0 * (t_a + t_b + 1.0)).unwrap_or(j); + hit_near(&offset_curve(a, oa), &offset_curve(b, ob), guess) + }; + let (Some(c1), Some(c2)) = (corner(off_a + t_a / 2.0, b_for_left), corner(off_a - t_a / 2.0, b_for_right)) else { + return Ok(None); + }; + let dir = sub(c2, c1); + if len(dir) < 1e-9 { + return Ok(None); + } + Ok(Some(Line { point: c1, dir })) +} + /// Fall 1 — T-Knoten: drei Enden im Knoten, zwei davon kollinear (Durchgang). Der Abzweig bekommt /// einen Schnitt an der ihm zugewandten Fläche der Durchgangswand; ohne kollineares Paar bleibt /// der Knoten rechtwinklig. fn apply_t_junction(walls: &[JoinWall], ends: &[WallEnd], result: &mut [WallCuts]) -> R<()> { - let dirs: Vec = ends.iter().map(|e| dir_of(&walls[e.wall])).collect(); + let arcs = ends.iter().any(|e| is_arc(&walls[e.wall])); + let dirs: Vec = ends.iter().map(|e| if arcs { dir_at(&walls[e.wall], e.end) } else { dir_of(&walls[e.wall]) }).collect(); let mut through: Option<(usize, usize)> = None; 'outer: for i in 0..3 { for k in i + 1..3 { @@ -367,14 +479,20 @@ fn apply_t_junction(walls: &[JoinWall], ends: &[WallEnd], result: &mut [WallCuts let j = point_of(through_wall, through_end.end); let t_t = thickness(walls, ti)?; - let u_t = dir_of(through_wall); + let u_t = if arcs { dir_at(through_wall, through_end.end) } else { dir_of(through_wall) }; let n_t = left_normal(u_t); let off_t = reference_offset(through_wall.reference, t_t); - let d_branch = if branch_end.end == End::Start { dir_of(&walls[bi]) } else { scale(dir_of(&walls[bi]), -1.0) }; + let u_branch = if arcs { dir_at(&walls[bi], branch_end.end) } else { dir_of(&walls[bi]) }; + let d_branch = if branch_end.end == End::Start { u_branch } else { scale(u_branch, -1.0) }; let sign = if dot(n_t, d_branch) >= 0.0 { 1.0 } else { -1.0 }; let face_point = add(j, scale(n_t, off_t + sign * (t_t / 2.0))); - let face_cut = Line { point: face_point, dir: u_t }; + let mut face_cut = Line { point: face_point, dir: u_t }; + if arcs { + if let Some(c) = chord_cut(walls, bi, ti, off_t + sign * (t_t / 2.0), face_point)? { + face_cut = c; + } + } set_cut(result, branch_end, face_cut); // Die Durchgangs-Hälften stossen rechtwinklig aneinander; als Schnitt markiert, damit die @@ -455,7 +573,14 @@ fn apply_layer_cuts( } let n_t = left_normal(through_dir); let merge_point = add(axis_point, scale(n_t, off_t + sign * (t_t / 2.0 - near_plaster))); - let merge_cut = Line { point: merge_point, dir: through_dir }; + let mut merge_cut = Line { point: merge_point, dir: through_dir }; + let arcs = is_arc(&walls[bi]) || is_arc(&walls[ti]) || other_half.is_some_and(|o| is_arc(&walls[o])); + if arcs { + if let Some(c) = chord_cut(walls, bi, ti, off_t + sign * (t_t / 2.0 - near_plaster), merge_point)? { + merge_cut = c; + } + } + let merge_point = merge_cut.point; let side_line = merge_cut; // Materialien des Nah-Putzes (Komponenten sind hier alle bekannt, s. Rückgrat-Suche). @@ -492,7 +617,30 @@ fn apply_layer_cuts( } b_off += th; } - if core_hi > core_lo { + if core_hi > core_lo && arcs { + // Bogen: Kern-Kanten als Versatzkurven, Achsmass als Bogenlänge. + let bw = &walls[bi]; + let edge_lo = offset_curve(bw, core_lo); + let edge_hi = offset_curve(bw, core_hi); + for wi in std::iter::once(ti).chain(other_half) { + let w = &walls[wi]; + let off_a = local_of(w, face_cut.point).1; + let off_b = local_of(w, merge_point).1; + let along = |edge: &Curve, off: f64| -> Option { + let hit = hit_near(edge, &offset_curve(w, off), axis_point)?; + Some(local_of(w, hit).0) + }; + let (Some(a_lo), Some(a_hi), Some(b_lo), Some(b_hi)) = (along(&edge_lo, off_a), along(&edge_hi, off_a), along(&edge_lo, off_b), along(&edge_hi, off_b)) else { + continue; + }; + let s = if a_lo <= a_hi { + SpanCutout { from: a_lo, to: a_hi, off_a, off_b, from_b: b_lo, to_b: b_hi } + } else { + SpanCutout { from: a_hi, to: a_lo, off_a, off_b, from_b: b_hi, to_b: b_lo } + }; + result[wi].span_cutouts.push(s); + } + } else if core_hi > core_lo { let bw = &walls[bi]; let n_branch = left_normal(dir_of(bw)); let u_branch = dir_of(bw); @@ -541,6 +689,21 @@ fn apply_mid_span_tee(walls: &[JoinWall], free: WallEnd, result: &mut [WallCuts] if wi == fi { continue; } + if let Some(a) = arc_of(w) { + let (dist_along, perp) = a.local(p); + if dist_along <= END_GAP || dist_along >= a.length() - END_GAP { + continue; + } + let tw = thickness(walls, wi)?; + let dist = perp.abs(); + if dist > tw / 2.0 + TOL { + continue; + } + if best.map_or(true, |b| dist < b.2) { + best = Some((wi, perp, dist, dist_along)); + } + continue; + } let u = dir_of(w); let w_len = len(sub(w.end, w.start)); if w_len < 1e-9 { @@ -562,6 +725,9 @@ fn apply_mid_span_tee(walls: &[JoinWall], free: WallEnd, result: &mut [WallCuts] } } let Some((wi, perp, _, dist_along)) = best else { return Ok(()) }; + if is_arc(&walls[wi]) || is_arc(free_wall) { + return mid_span_tee_arc(walls, free, wi, perp, dist_along, result); + } let w = &walls[wi]; let tw = thickness(walls, wi)?; @@ -589,6 +755,39 @@ fn apply_mid_span_tee(walls: &[JoinWall], free: WallEnd, result: &mut [WallCuts] apply_layer_cuts(walls, result, free, wi, None, face_cut, axis_point, u_w, sign) } +/// [`apply_mid_span_tee`] mit Bogenwand (Durchgang oder freies Ende). +fn mid_span_tee_arc(walls: &[JoinWall], free: WallEnd, wi: usize, perp: f64, dist_along: f64, result: &mut [WallCuts]) -> R<()> { + let w = &walls[wi]; + let tw = thickness(walls, wi)?; + let (u_w, axis_point) = match arc_of(w) { + Some(a) => (a.tangent(dist_along), a.point(dist_along, 0.0)), + None => { + let u = dir_of(w); + (u, add(w.start, scale(u, dist_along))) + } + }; + let n_w = left_normal(u_w); + let off_w = reference_offset(w.reference, tw); + let u_free = dir_at(&walls[free.wall], free.end); + let d_free = if free.end == End::Start { u_free } else { scale(u_free, -1.0) }; + let facing = dot(n_w, d_free); + let sign = if facing.abs() > 1e-6 { + if facing >= 0.0 { + 1.0 + } else { + -1.0 + } + } else if perp >= 0.0 { + 1.0 + } else { + -1.0 + }; + let face_point = add(axis_point, scale(n_w, off_w + sign * (tw / 2.0))); + let face_cut = chord_cut(walls, free.wall, wi, off_w + sign * (tw / 2.0), face_point)?.unwrap_or(Line { point: face_point, dir: u_w }); + set_cut(result, free, face_cut); + apply_layer_cuts(walls, result, free, wi, None, face_cut, axis_point, u_w, sign) +} + // ── Flache Kodierung ───────────────────────────────────────────────────────── // // Wände: [n, (sx, sy, ex, ey, refKind, refValue, typeOk, nLayers, (dicke, bauteil, prio)…)…] @@ -627,7 +826,7 @@ pub fn decode_walls(buf: &[f64]) -> Option> { let priority = if component.is_some() { p } else { f64::NAN }; layers.push(JoinLayer { thickness: t, component, priority }); } - out.push(JoinWall { start: Vec2::new(sx, sy), end: Vec2::new(ex, ey), reference, layers: type_ok.then_some(layers) }); + out.push(JoinWall { start: Vec2::new(sx, sy), end: Vec2::new(ex, ey), reference, layers: type_ok.then_some(layers), bulge: None }); } Some(out) } @@ -727,7 +926,7 @@ mod tests { JoinLayer { thickness: t, component: Some(c), priority: p } } fn wall(s: (f64, f64), e: (f64, f64), layers: Vec) -> JoinWall { - JoinWall { start: Vec2::new(s.0, s.1), end: Vec2::new(e.0, e.1), reference: Reference::Center, layers: Some(layers) } + JoinWall { start: Vec2::new(s.0, s.1), end: Vec2::new(e.0, e.1), reference: Reference::Center, layers: Some(layers), bulge: None } } fn mono(s: (f64, f64), e: (f64, f64), t: f64) -> JoinWall { wall(s, e, vec![layer(t, 0, 10.0)]) @@ -979,4 +1178,102 @@ mod tests { assert_eq!(decode_cuts(&mut r), Some(c)); } } + + // ── Bogenwände ([T2]) ── + + fn arc_wall(s: (f64, f64), e: (f64, f64), b: f64, t: f64) -> JoinWall { + JoinWall { bulge: Some(b), ..mono(s, e, t) } + } + fn on_circle(p: Vec2, c: (f64, f64), r: f64) -> bool { + (len(sub(p, Vec2::new(c.0, c.1))) - r).abs() < 1e-9 + } + fn ends(l: &Line) -> [Vec2; 2] { + [l.point, add(l.point, l.dir)] + } + + #[test] + fn bogen_l_ecke_exakt_auf_flaechen() { + // Gerade (0,0)→(5,0), dann Halbkreis (5,0)→(10,0) mit Scheitel oben (Mitte (7.5,0), r 2.5). + let w = vec![mono((0.0, 0.0), (5.0, 0.0), 0.3), arc_wall((5.0, 0.0), (10.0, 0.0), 1.0, 0.3)]; + let c = compute_joins(&w).unwrap(); + let cut = c[0].end_cut.unwrap(); + assert_eq!(Some(cut), c[1].start_cut); + for p in ends(&cut) { + assert!(close(p.y.abs(), 0.15), "{p:?}"); + assert!(on_circle(p, (7.5, 0.0), 2.35) || on_circle(p, (7.5, 0.0), 2.65), "{p:?}"); + } + // Aussenecke unten rechts, Innenecke oben links. + let [a, b] = ends(&cut); + let (lo, hi) = if a.y < b.y { (a, b) } else { (b, a) }; + assert!(close(lo.x, 7.5 - (2.35f64 * 2.35 - 0.0225).sqrt()) && close(hi.x, 7.5 - (2.65f64 * 2.65 - 0.0225).sqrt())); + } + + #[test] + fn bogen_ring_stoesst_radial_ohne_fuge() { + let w = vec![arc_wall((0.0, 0.0), (10.0, 0.0), 1.0, 0.3), arc_wall((10.0, 0.0), (0.0, 0.0), 1.0, 0.3)]; + let c = compute_joins(&w).unwrap(); + for cut in [c[0].start_cut, c[0].end_cut, c[1].start_cut, c[1].end_cut] { + let cut = cut.expect("radiale Stossfuge"); + assert!(close(cut.dir.y, 0.0) && close(cut.point.y, 0.0)); + } + } + + #[test] + fn gerader_abzweig_auf_bogen_mittelspanne() { + // Halbkreis unten (CCW, Mitte (5,0), r 5); Abzweig vom tiefsten Punkt nach unten. + let w = vec![arc_wall((0.0, 0.0), (10.0, 0.0), -1.0, 0.3), mono((5.0, -5.0), (5.0, -9.0), 0.2)]; + let c = compute_joins(&w).unwrap(); + let cut = c[1].start_cut.unwrap(); + for p in ends(&cut) { + assert!(on_circle(p, (5.0, 0.0), 5.15), "{p:?}"); + assert!(close(p.x - 5.0, 0.1) || close(p.x - 5.0, -0.1)); + } + assert!(c[0].start_cut.is_none() && c[0].end_cut.is_none()); + } + + #[test] + fn bogen_abzweig_auf_gerade_und_t_knoten() { + // Bogen-Abzweig trifft die Mittelspanne einer geraden Wand: Schnitt liegt auf deren Fläche. + let mid = vec![mono((0.0, 0.0), (10.0, 0.0), 0.3), arc_wall((5.0, 0.0), (8.0, 3.0), 0.4, 0.2)]; + let node = vec![mono((0.0, 0.0), (5.0, 0.0), 0.3), mono((5.0, 0.0), (10.0, 0.0), 0.3), arc_wall((5.0, 0.0), (8.0, 3.0), 0.4, 0.2)]; + for w in [mid, node] { + let bi = w.len() - 1; + let c = compute_joins(&w).unwrap(); + let cut = c[bi].start_cut.unwrap(); + let arc = WallArc::of(w[bi].start, w[bi].end, w[bi].bulge).unwrap(); + for p in ends(&cut) { + assert!(close(p.y, 0.15), "{p:?}"); + let (_, n) = arc.local(p); + assert!(close(n.abs(), 0.1), "{n}"); + } + } + } + + #[test] + fn bogen_bogen_ecke_auf_beiden_kreisen() { + // Zwei Viertelbögen, die sich im Punkt (5,0) unter einem Knick treffen. + let b = (std::f64::consts::PI / 8.0).tan(); + let w = vec![arc_wall((0.0, 0.0), (5.0, 0.0), b, 0.25), arc_wall((5.0, 0.0), (8.0, 4.0), 0.2, 0.25)]; + let c = compute_joins(&w).unwrap(); + let cut = c[0].end_cut.unwrap(); + let a0 = WallArc::of(w[0].start, w[0].end, w[0].bulge).unwrap(); + let a1 = WallArc::of(w[1].start, w[1].end, w[1].bulge).unwrap(); + for p in ends(&cut) { + assert!(close(a0.local(p).1.abs(), 0.125) && close(a1.local(p).1.abs(), 0.125), "{p:?}"); + } + } + + #[test] + fn bogen_mehrschichtig_t_mit_nahputz() { + // Mehrschichtiger Bogen-Abzweig auf gerade Aussenwand: Kern läuft bis zur Rückgrat-Fläche, + // Aussparung in der Durchgangswand. + let w = vec![wall((0.0, 0.0), (10.0, 0.0), aw()), JoinWall { bulge: Some(0.3), ..wall((5.0, 0.0), (9.0, 4.0), aw()) }]; + let c = compute_joins(&w).unwrap(); + let lc = c[1].layer_cuts.as_ref().expect("Schicht-Cuts"); + let merge = lc.start[2].unwrap(); + assert!(close(merge.point.y, 0.345 / 2.0 - 0.015) && close(merge.dir.y, 0.0)); + assert_eq!(c[0].span_cutouts.len(), 1); + let s = c[0].span_cutouts[0]; + assert!(s.to > s.from && s.from > 4.5 && s.to < 6.0, "{s:?}"); + } } diff --git a/src-tauri/core/src/lib.rs b/src-tauri/core/src/lib.rs index b03a35da..0273eba4 100644 --- a/src-tauri/core/src/lib.rs +++ b/src-tauri/core/src/lib.rs @@ -25,6 +25,7 @@ pub mod bulge; pub mod stair; pub mod joins; pub mod wall_bands; +pub mod wall_arc; pub mod room_area; pub mod room_boundary; pub mod polygon_holes; diff --git a/src-tauri/core/src/mesh_data.rs b/src-tauri/core/src/mesh_data.rs index e7af16d9..36a2a767 100644 --- a/src-tauri/core/src/mesh_data.rs +++ b/src-tauri/core/src/mesh_data.rs @@ -598,4 +598,78 @@ mod tests { assert!(g.positions.iter().all(|v| v.is_finite())); assert_eq!(g.positions.len(), 12); } + + /// Körper einer Wandliste als (Volumen, alle dicht). + fn bodies(walls: &[RWall]) -> (f64, bool) { + let mut vol = 0.0; + let mut tight = true; + for w in walls { + let mut g = Prim { material: 0.0, positions: vec![], indices: vec![] }; + push_wall_box(&mut g, w); + let idx: Vec = g.indices.iter().map(|&i| i as u32).collect(); + tight &= crate::wall_mesh_cut::is_watertight(&g.positions, &idx, 1e-9); + vol += crate::export_flat::mesh_volume(&g.positions, &idx).abs(); + } + (vol, tight) + } + + fn arc_project() -> Project { + let mut p = sample(); + p.openings = Some(vec![]); + p.ceilings = Some(vec![]); + p.roofs = Some(vec![]); + p.walls.retain(|w| w.id == "W1"); + // Halbkreis (0,0)→(5,0), Scheitel oben: Achsradius 2.5. + p.walls[0].bulge = Some(1.0); + p + } + + /// [T2] Bogenwand: Sehnen-Teilkörper sind je dicht, das Volumen trifft den Ringsektor. + #[test] + fn bogenwand_dicht_und_volumen_wie_ringsektor() { + let p = arc_project(); + let (zb, zt) = p.wall_vertical_extent(&p.walls[0]); + let t = 0.345; + let exact = std::f64::consts::PI * 2.5 * t * (zt - zb); + let walls = model3d::emit_walls(&p, true).unwrap(); + assert!(walls.len() >= 4 * 20, "Schichten × Sehnen: {}", walls.len()); + let (vol, tight) = bodies(&walls); + assert!(tight); + assert!((vol - exact).abs() < exact * 1e-3, "{vol} ≠ {exact}"); + // Schnitt-Eingabe (ungeschichtet) ebenso. + let (vol2, tight2) = bodies(&model3d::emit_walls(&p, false).unwrap()); + assert!(tight2 && (vol2 - exact).abs() < exact * 1e-3, "{vol2}"); + } + + /// [T2] Öffnung in der Bogenwand: Laibungen radial, Loch = Ringsektor über die Öffnungshöhe. + #[test] + fn bogenwand_oeffnung_als_ringsektor() { + let mut p = arc_project(); + let (vol0, _) = bodies(&model3d::emit_walls(&p, true).unwrap()); + p.openings = Some(vec![Opening { id: "O".into(), host_wall_id: "W1".into(), kind: ElementKind::Window, position: 2.0, width: 1.5, height: 1.2, sill_height: 0.9, ..Default::default() }]); + let walls = model3d::emit_walls(&p, true).unwrap(); + let (vol, tight) = bodies(&walls); + assert!(tight); + // Achsmass der Öffnung = Bogenlänge → Ringsektor-Volumen = Breite · Dicke · Höhe (Achse mittig). + let hole = 1.5 * 0.345 * 1.2; + assert!(((vol0 - vol) - hole).abs() < hole * 2e-3, "{} ≠ {hole}", vol0 - vol); + } + + /// [T2] Bogenwand an zwei geraden Wänden (L an beiden Enden): alle Teilkörper dicht, Schnittlinien + /// an den Enden gesetzt. + #[test] + fn bogenwand_mit_l_anschluessen_dicht() { + let mut p = sample(); + p.openings = Some(vec![]); + p.ceilings = Some(vec![]); + p.roofs = Some(vec![]); + p.walls.retain(|w| w.id == "W1" || w.id == "W2" || w.id == "W4"); + // W1 (0,0)→(5,0) als flacher Bogen nach unten, W2/W4 stehen senkrecht darauf. + p.walls.iter_mut().find(|w| w.id == "W1").unwrap().bulge = Some(-0.3); + let walls = model3d::emit_walls(&p, true).unwrap(); + let arc: Vec<&RWall> = walls.iter().filter(|w| w.wall_id == "W1").collect(); + assert!(arc.iter().any(|w| w.start_cut.is_some()) && arc.iter().all(|w| w.end_cut.is_some() || w.start_cut.is_some())); + let (_, tight) = bodies(&walls); + assert!(tight); + } } diff --git a/src-tauri/core/src/model/generated.rs b/src-tauri/core/src/model/generated.rs index 406b077d..c4ec39d4 100644 --- a/src-tauri/core/src/model/generated.rs +++ b/src-tauri/core/src/model/generated.rs @@ -1982,6 +1982,12 @@ pub struct Wall { pub start: Vec2, /// Achs-Endpunkt im Grundriss (Meter). pub end: Vec2, + /// Bogenwand ([T2]): Achse als Kreisbogen von `start` nach `end`, `bulge = tan(Öffnungswinkel/4)`; + /// positiv = Scheitel links der Sehne (Modell-Konvention wie Polylinien, = −DXF-Bulge). Fehlt/0 = + /// gerade Wand. + #[serde(default, skip_serializing_if = "Option::is_none")] + #[ts(optional)] + pub bulge: Option, /// Verweis auf den (mehrschichtigen) Wandtyp. #[serde(rename = "wallTypeId")] pub wall_type_id: String, diff --git a/src-tauri/core/src/model3d.rs b/src-tauri/core/src/model3d.rs index 7ab0b2d6..bc365158 100644 --- a/src-tauri/core/src/model3d.rs +++ b/src-tauri/core/src/model3d.rs @@ -273,6 +273,10 @@ pub struct RWall { pub start_cut: Option<[f64; 4]>, #[serde(skip_serializing_if = "Option::is_none")] pub end_cut: Option<[f64; 4]>, + /// Anfang/Ende liegt an einer inneren Stossfuge einer Bogenwand ([T2], Sehnen-Teilkörper): dort + /// keine sichtbare Stirnfläche (Ansicht). + #[serde(skip)] + pub joint: [bool; 2], } /// Textur-Karten-URLs der Bauteile in der Reihenfolge des ersten Auftretens: Wandtypen, dann @@ -408,6 +412,10 @@ pub(crate) fn wall_reference(w: &Wall) -> Reference { fn wall_ref(p: &Project, w: &Wall) -> WallRef { let total = p.wall_thickness(w, 0.2); + // Bogenwand ([T2]): abgewickelt (Achsmass = Bogenlänge). + if let Some((_, v)) = crate::wall_arc::unrolled_wall(w) { + return WallRef { start: opening_geom::v(v.start.x, v.start.y), end: opening_geom::v(v.end.x, v.end.y), total, ref_off: joins::reference_offset(wall_reference(w), total) }; + } WallRef { start: opening_geom::v(w.start.x, w.start.y), end: opening_geom::v(w.end.x, w.end.y), total, ref_off: joins::reference_offset(wall_reference(w), total) } } @@ -485,7 +493,7 @@ fn compute_joins_by_floor(p: &Project) -> Result, Stri finite &= [w.start.x, w.start.y, w.end.x, w.end.y].iter().all(|v| v.is_finite()) && !matches!(reference, Reference::Offset(v) if !v.is_finite()) && layers.as_ref().is_none_or(|l| l.iter().all(|x| x.thickness.is_finite())); - jw.push(JoinWall { start: kv(w.start), end: kv(w.end), reference, layers }); + jw.push(JoinWall { start: kv(w.start), end: kv(w.end), reference, layers, bulge: w.bulge }); } if !finite { for w in walls { @@ -543,6 +551,13 @@ fn floor_context(p: &Project, floor_id: &str) -> FloorContext { FloorContext::new(ceilings, roofs) } +/// Liegt der Achspunkt `p` eines Bogen-Teilkörpers an einer inneren Stossfuge (nicht an Anfang, Ende +/// oder einer Laibung)? +fn inner_joint(a: &crate::wall_arc::WallArc, _w: &Wall, keep: &[f64], p: KVec) -> bool { + let (s, _) = a.local(p); + keep.iter().all(|k| (s - k).abs() > 0.01) +} + /// Wandkörper (`projectToWalls3d`): `layered` = ein Körper je Schicht mit Löchern (3D-Viewer), /// sonst Pfeiler/Brüstung/Sturz-Segmente (Schnitt-Eingabe). pub fn emit_walls(p: &Project, layered: bool) -> Result, String> { @@ -579,9 +594,26 @@ pub fn emit_walls(p: &Project, layered: bool) -> Result, String> { cuts: if layered { joins.as_ref().and_then(|j| j.get(&wall.id)).cloned().unwrap_or_default() } else { WallCuts::default() }, reveals: if layered && stacked { wall_reveals(p, wall, by_wall.get(wall.id.as_str()).map_or(&[][..], |v| v.as_slice()), bands.len()) } else { Vec::new() }, }; - let (dx, dy) = (wall.end.x - wall.start.x, wall.end.y - wall.start.y); - for piece in wall_bands::wall_bands(&win, ctx) { + // Bogenwand ([T2]): Sehnen-Teilwände mit radialen Gehrungen. + let arc = crate::wall_arc::WallArc::of_wall(wall); + // Echte Enden der Bogenwand: Anfang, Ende, Laibungen. + let keep: Vec = match arc { + Some(a) => [0.0, a.length()].into_iter().chain(win.openings.iter().flat_map(|o| [o.from, o.to])).collect(), + None => Vec::new(), + }; + let wins = match arc { + Some(a) => crate::wall_arc::chord_walls(&win, &a), + None => vec![win], + }; + for win in &wins { + let (dx, dy) = (win.end.x - win.start.x, win.end.y - win.start.y); + for mut piece in wall_bands::wall_bands(win, ctx) { let Some(b) = bands.get(piece.band) else { continue }; + // Schnitt-Eingabe der Bogen-Teilwände: radiale Gehrungen auch ohne Schichtband-Pfad. + if arc.is_some() && !layered { + piece.start_cut = win.cuts.start_cut; + piece.end_cut = win.cuts.end_cut; + } out.push(RWall { start: [piece.start.x, piece.start.y], end: [piece.end.x, piece.end.y], @@ -598,8 +630,10 @@ pub fn emit_walls(p: &Project, layered: bool) -> Result, String> { cut: band_cut_meta(b), start_cut: piece.start_cut.map(|l| [l.point.x, l.point.y, l.dir.x, l.dir.y]), end_cut: piece.end_cut.map(|l| [l.point.x, l.point.y, l.dir.x, l.dir.y]), + joint: arc.map_or([false; 2], |a| [inner_joint(&a, wall, &keep, piece.start), inner_joint(&a, wall, &keep, piece.end)]), }); } + } } let _ = hypot2; Ok(out) @@ -766,7 +800,34 @@ fn write_opening(w: &mut FlatWriter, p: &Project, op: &Opening) { } /// Öffnungs-Einbauteile als Quader-Meshes (`emitOpeningMeshes`); `detail`: 0 grob, 1 mittel, 2 fein. +/// Bogenwände ([T2]): je Wand auf der abgewickelten Ersatzwand gerechnet und die Ecken gebogen — die +/// Einbauteile bleiben gerade (Sehne zwischen den Laibungen), ihre Enden sitzen radial in der Laibung. pub fn emit_opening_meshes(p: &Project, detail: f64) -> Vec { + let arcs: Vec = p.walls.iter().enumerate().filter(|(_, w)| crate::wall_arc::WallArc::of_wall(w).is_some()).map(|(i, _)| i).collect(); + if arcs.is_empty() { + return emit_opening_meshes_plain(p, detail); + } + let mut q = p.clone(); + let arc_ids: std::collections::HashSet<&str> = arcs.iter().map(|&i| p.walls[i].id.as_str()).collect(); + q.openings = p.openings.as_ref().map(|v| v.iter().filter(|o| !arc_ids.contains(o.host_wall_id.as_str())).cloned().collect()); + let mut out = emit_opening_meshes_plain(&q, detail); + for &i in &arcs { + let Some((arc, v)) = crate::wall_arc::unrolled_wall(&p.walls[i]) else { continue }; + q.walls = vec![v]; + q.openings = p.openings.as_ref().map(|o| o.iter().filter(|o| o.host_wall_id == p.walls[i].id).cloned().collect()); + for mut m in emit_opening_meshes_plain(&q, detail) { + for c in m.positions.chunks_exact_mut(3) { + let w = arc.point(c[0], c[1]); + c[0] = w.x; + c[1] = w.y; + } + out.push(m); + } + } + out +} + +fn emit_opening_meshes_plain(p: &Project, detail: f64) -> Vec { let mut shaped: Vec = Vec::new(); let mut w = FlatWriter::new(); w.num(detail).num(p.walls.len() as f64); @@ -1779,7 +1840,13 @@ pub fn pick_openings(p: &Project) -> Vec { for o in p.openings.as_deref().unwrap_or(&[]) { let Some(wall) = p.walls.iter().find(|w| w.id == o.host_wall_id) else { continue }; let wr = wall_ref(p, wall); - let Some((jamb_start, jamb_end)) = opening_geom::opening_jambs(&wr, o.position, o.width) else { continue }; + let Some((mut jamb_start, mut jamb_end)) = opening_geom::opening_jambs(&wr, o.position, o.width) else { continue }; + // Bogenwand ([T2]): Laibungen auf dem Bogen (Sehne als Pick-Quader). + if let Some(a) = crate::wall_arc::WallArc::of_wall(wall) { + let (ps, pe) = (a.point(jamb_start.x, 0.0), a.point(jamb_end.x, 0.0)); + jamb_start = opening_geom::v(ps.x, ps.y); + jamb_end = opening_geom::v(pe.x, pe.y); + } let thickness = Project::type_thickness(&p.wall_type_or_fallback(wall).layers); let (zb, zt) = p.wall_vertical_extent(wall); let o_bottom = zb + o.sill_height.max(0.0); diff --git a/src-tauri/core/src/plan/domains.rs b/src-tauri/core/src/plan/domains.rs index a0bb2041..60eb5bbf 100644 --- a/src-tauri/core/src/plan/domains.rs +++ b/src-tauri/core/src/plan/domains.rs @@ -1048,4 +1048,48 @@ mod tests { serde_json::to_string(&(&d.ceilings, &d.roofs, &d.rooms, &d.walls, &d.stairs, &d.columns, &d.drawings.prims, &d.solids, &d.context, &d.sections)).unwrap(); }); } + + /// [T2] Bogenwand im Grundriss: alle Poché-Punkte im Kreisring, Schichtflächen = Ringsektor, + /// Umriss als Bögen (DXF-tauglich). + #[test] + fn bogenwand_poche_im_kreisring() { + let mut p = sample(); + p.walls.retain(|w| w.id == "W1"); + p.openings = Some(vec![]); + p.ceilings = Some(vec![]); + p.rooms = Some(vec![]); + p.walls[0].bulge = Some(1.0); // Halbkreis (0,0)→(5,0), Mitte (2.5,0), r 2.5, Scheitel oben + let t = serde_json::json!({ "floor": "eg", "show": ["20"], "grey": [], "scale": 50 }).to_string(); + let r = plan_domains(&p, &PlanArgs::parse(1.0, &t).unwrap()).unwrap(); + let (r_in, r_out) = (2.5 - 0.345 / 2.0, 2.5 + 0.345 / 2.0); + let mut band_area = 0.0; + let mut arcs = 0; + for pr in &r.walls { + match pr { + Primitive::Polygon { pts, stroke, .. } => { + for q in pts { + let d = ((q.x - 2.5).powi(2) + q.y.powi(2)).sqrt(); + assert!(d > r_in - 1e-6 && d < r_out + 1e-6 && q.y > -1e-6, "{q:?} d={d}"); + } + if stroke == "none" { + let mut a = 0.0; + for i in 0..pts.len() { + let (u, v) = (pts[i], pts[(i + 1) % pts.len()]); + a += u.x * v.y - v.x * u.y; + } + band_area += a.abs() / 2.0; + } + } + Primitive::Arc { center, r: rr, .. } => { + arcs += 1; + assert!((center.x - 2.5).abs() < 1e-9 && center.y.abs() < 1e-9 && *rr > r_in - 1e-9 && *rr < r_out + 1e-9); + } + Primitive::Line { a, b, .. } => panic!("Gerade an der Bogenwand: {a:?} {b:?}"), + _ => {} + } + } + let exact = std::f64::consts::PI / 2.0 * (r_out * r_out - r_in * r_in); + assert!((band_area - exact).abs() < exact * 2e-3, "{band_area} ≠ {exact}"); + assert!(arcs >= 2 * 2, "Umriss innen/aussen als Bögen (≤ 90° je Stück): {arcs}"); + } } diff --git a/src-tauri/core/src/plan/elevation.rs b/src-tauri/core/src/plan/elevation.rs index 0c5b9f53..0e071541 100644 --- a/src-tauri/core/src/plan/elevation.rs +++ b/src-tauri/core/src/plan/elevation.rs @@ -96,8 +96,14 @@ struct RoofIn { /// `projectFaces`. fn project_faces(frame: &[f64; 9], walls: &[RWall], slabs: &[RSlab], roofs: &[RoofIn]) -> Vec { let mut w = vec![walls.len() as f64]; + // Mit Schnittlinien (Bogen-Teilkörper, [T2]): die Ecken liegen auf der Gehrung statt rechtwinklig. + let cut = walls.iter().any(|x| x.start_cut.is_some() || x.end_cut.is_some() || x.joint != [false; 2]); for x in walls { w.extend([x.start[0], x.start[1], x.end[0], x.end[1], x.thickness, x.height, x.base_elevation]); + if cut { + w.extend(corner_shifts(x)); + w.extend([if x.joint[0] { 1.0 } else { 0.0 }, if x.joint[1] { 1.0 } else { 0.0 }]); + } } let mut sl = vec![slabs.len() as f64]; for x in slabs { @@ -140,6 +146,34 @@ fn project_faces(frame: &[f64; 9], walls: &[RWall], slabs: &[RSlab], roofs: &[Ro out } +/// Verschiebung der vier Wandecken längs der Achse bis auf die Schnittlinien (Anfang +n, Anfang −n, +/// Ende +n, Ende −n; +n = rechte Normale wie in `plan_elevation::wall_faces`). +fn corner_shifts(x: &RWall) -> [f64; 4] { + let (dx, dy) = (x.end[0] - x.start[0], x.end[1] - x.start[1]); + let l = hypot2(dx, dy); + if l < 1e-9 { + return [0.0; 4]; + } + let (ax, ay) = (dx / l, dy / l); + let (nx, ny) = (ay, -ax); + let ht = x.thickness / 2.0; + let shift = |base: [f64; 2], t: f64, cut: Option<[f64; 4]>| -> f64 { + let Some([cx, cy, ux, uy]) = cut else { return 0.0 }; + let (qx, qy) = (base[0] + nx * t, base[1] + ny * t); + let den = ax * uy - ay * ux; + if den.abs() < 1e-12 { + return 0.0; + } + let lam = ((cx - qx) * uy - (cy - qy) * ux) / den; + if lam.is_finite() && lam.abs() < l { + lam + } else { + 0.0 + } + }; + [shift(x.start, ht, x.start_cut), shift(x.start, -ht, x.start_cut), shift(x.end, ht, x.end_cut), shift(x.end, -ht, x.end_cut)] +} + /// `collectRoofFaces`. fn collect_roof_faces(p: &Project, frame: &[f64; 9]) -> Result, String> { let mut roofs = Vec::new(); @@ -252,12 +286,21 @@ fn collect_openings(p: &Project, frame: &[f64; 9]) -> Vec { for wall in &p.walls { let thickness = p.wall_type(wall).map_or(0.2, |t| t.layers.iter().fold(0.0, |s, l| s + l.thickness)); for &op in by_wall.get(wall.id.as_str()).map_or(&[][..], |v| v.as_slice()) { - let axis = hypot2(wall.end.x - wall.start.x, wall.end.y - wall.start.y); + let arc = crate::wall_arc::WallArc::of_wall(wall); + let axis = arc.map_or_else(|| hypot2(wall.end.x - wall.start.x, wall.end.y - wall.start.y), |a| a.length()); let from = max(0.0, min(op.position, axis)); let to = max(from, min(op.position + op.width, axis)); if to - from < 1e-4 { continue; } + // [T2] Bogenwand: Öffnung als Sehne zwischen den Laibungen (Ersatzwand je Öffnung). + let (ws, we, from, to) = match arc { + Some(a) => { + let (ps, pe) = (a.point(from, 0.0), a.point(to, 0.0)); + (Vec2 { x: ps.x, y: ps.y }, Vec2 { x: pe.x, y: pe.y }, 0.0, hypot2(pe.x - ps.x, pe.y - ps.y)) + } + None => (wall.start, wall.end, from, to), + }; let (zb, zt) = p.wall_vertical_extent(wall); let ob = zb + max(0.0, op.sill_height); let ot = min(zt, ob + op.height); @@ -265,10 +308,10 @@ fn collect_openings(p: &Project, frame: &[f64; 9]) -> Vec { let dt = if door { p.door_type(op) } else { None }; let wt = if door { None } else { p.window_type(op) }; b.extend([ - wall.start.x, - wall.start.y, - wall.end.x, - wall.end.y, + ws.x, + ws.y, + we.x, + we.y, thickness, from, to, @@ -599,6 +642,38 @@ pub fn elevation_primitives(p: &Project, level: &LevelSpec, shadows: bool, mono: }) }) }; + // [T2] Bogenwände: Stossfugen der Sehnen-Teilkörper nicht als Kante zeichnen (die Fläche wirkt + // gekrümmt statt facettiert). Eine senkrechte Kante gilt als Fuge, wenn eine andere Fläche derselben + // Wand mit fast gleicher Normale, gleicher Blickseite (nicht die Silhouette) dort ebenfalls eine + // senkrechte Kante hat (Toleranz 2 cm: die Teilquader enden rechtwinklig, nicht auf der Gehrung). + let arc_ids: std::collections::HashSet<&str> = p.walls.iter().filter(|w| crate::wall_arc::WallArc::of_wall(w).is_some()).map(|w| w.id.as_str()).collect(); + let view_n = [frame[3], frame[4], frame[5]]; + let facing = |f: &Face| f.normal[0] * view_n[0] + f.normal[1] * view_n[1] + f.normal[2] * view_n[2]; + let mut arc_faces: HashMap<&str, Vec> = HashMap::new(); + for (fi, f) in faces.iter().enumerate() { + if f.role == Role::Wall && arc_ids.contains(f.id.as_str()) { + arc_faces.entry(f.id.as_str()).or_default().push(fi); + } + } + let smooth_seam = |fi: usize, a: Pt, b: Pt| -> bool { + let f = &faces[fi]; + if f.role != Role::Wall || (a[0] - b[0]).abs() > 1e-6 { + return false; + } + let Some(list) = arc_faces.get(f.id.as_str()) else { return false }; + let (lo, hi) = (a[1].min(b[1]), a[1].max(b[1])); + let side = facing(f); + list.iter().any(|&oi| { + let o = &faces[oi]; + if oi == fi || f.normal[0] * o.normal[0] + f.normal[1] * o.normal[1] + f.normal[2] * o.normal[2] < 0.98 || facing(o) * side <= 0.0 { + return false; + } + (0..o.pts.len()).any(|i| { + let (c, d) = (o.pts[i], o.pts[(i + 1) % o.pts.len()]); + (c[0] - d[0]).abs() < 1e-6 && (c[0] - a[0]).abs() < 0.02 && c[1].min(d[1]) < hi - 1e-6 && c[1].max(d[1]) > lo + 1e-6 + }) + }) + }; let mut group_order: Vec = Vec::new(); let mut groups: HashMap, f64)> = HashMap::new(); for (fi, f) in faces.iter().enumerate() { @@ -626,7 +701,7 @@ pub fn elevation_primitives(p: &Project, level: &LevelSpec, shadows: bool, mono: for i in 0..f.pts.len() { let a = f.pts[i]; let b = f.pts[(i + 1) % f.pts.len()]; - if coplanar_seam(fi, a, b) { + if coplanar_seam(fi, a, b) || smooth_seam(fi, a, b) { continue; } pending.push(Pending::Line { a, b, depth: f.depth_min - EPS * 5.0, style: None, paint: None }); @@ -1027,6 +1102,36 @@ mod tests { serde_json::to_string(&prims).unwrap() } + /// [T2] Bogenwand in der Ansicht: keine Facetten-Fugen der Sehnen-Teilkörper, Umriss bleibt. + #[test] + fn bogenwand_ohne_facettenfugen() { + let mut p = sample(); + p.walls.retain(|w| w.id == "W1"); + p.openings = Some(vec![]); + p.roofs = Some(vec![]); + p.ceilings = Some(vec![]); + p.stairs = Some(vec![]); + p.walls[0].bulge = Some(-0.5); // Bogen nach Süden, zur Ansicht hin (vor der Ansichtslinie y = −2) + let l = p.drawing_levels.iter().find(|l| l.id == "ansicht-sued").unwrap(); + let level = LevelSpec::from_json(&serde_json::to_value(l).unwrap()); + let (prims, _) = elevation_primitives(&p, &level, false, false, &Visibility::default(), 100.0).unwrap().unwrap(); + let mut inner = Vec::new(); + let mut all = 0; + for pr in &prims { + if let Primitive::Line { a, b, cls, .. } = pr { + if cls == "elevation-outline" && (a.x - b.x).abs() < 1e-6 { + all += 1; + // Ansichts-x = Welt-x + 1 (Ansichtslinie ab x = −1); die Wand reicht von 1 bis 6. + if a.x > 1.3 && a.x < 5.7 { + inner.push(a.x); + } + } + } + } + assert!(all >= 2, "Silhouette fehlt"); + assert!(inner.is_empty(), "Facetten-Fugen: {inner:?}"); + } + #[test] fn ansichtsschraffur_und_ansichtsfarbe_der_aussenschicht() { let mut p = sample(); diff --git a/src-tauri/core/src/plan/prim.rs b/src-tauri/core/src/plan/prim.rs index c14db0a9..70f6acd9 100644 --- a/src-tauri/core/src/plan/prim.rs +++ b/src-tauri/core/src/plan/prim.rs @@ -126,6 +126,9 @@ pub enum Primitive { weight_mm: f64, #[serde(default, skip_serializing_if = "Option::is_none", deserialize_with = "de_dash")] dash: Dash, + /// Strichfarbe (sonst die der Klasse), z. B. Umriss einer Bogenwand ([T2]). + #[serde(default, skip_serializing_if = "Option::is_none")] + color: Option, #[serde(skip_serializing_if = "Option::is_none")] opening_id: Option, #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src-tauri/core/src/plan/section.rs b/src-tauri/core/src/plan/section.rs index a05d7d39..7a79494d 100644 --- a/src-tauri/core/src/plan/section.rs +++ b/src-tauri/core/src/plan/section.rs @@ -610,6 +610,10 @@ fn split_wall_layers(cp: &Cut, p: &Project, layers: &[Layer], owner: &Wall, u_wo #[allow(clippy::type_complexity)] fn section_reveal(p: &Project, wall: &Wall, plane: &Plane, v_min: f64, v_max: f64) -> (Option<(f64, Vec)>, Option<(f64, Vec)>) { let (mut top, mut bottom) = (None, None); + // Bogenwände: kein Schichteinzug ([106] gilt nur gerade). + if crate::wall_arc::is_arc_bulge(wall.bulge) { + return (None, None); + } let u_raw = plane.u_model(); let l = hypot2(u_raw.0, u_raw.1); if !(l > 1e-12) { @@ -818,7 +822,8 @@ fn shaped_wall_cuts(cuts: &mut [Cut], p: &Project, walls_r: &[RWall], base: (f64 } let u = (u.0 / ul, u.1 / ul); for o in p.openings.as_deref().unwrap_or(&[]).iter().filter(|o| crate::opening_shape::is_shaped(o)) { - let Some(wall) = p.walls.iter().find(|w| w.id == o.host_wall_id) else { continue }; + // Formöffnungen in Bogenwänden bleiben im Schnitt rechteckig ([T2], offen). + let Some(wall) = p.walls.iter().find(|w| w.id == o.host_wall_id && !crate::wall_arc::is_arc_bulge(w.bulge)) else { continue }; let Some((from, to)) = opening_interval(wall, o) else { continue }; let (a, _) = axis_frame(wall); let den = a.0 * u.1 - a.1 * u.0; @@ -1272,7 +1277,16 @@ pub fn compute_section(p: &Project, level: &LevelSpec, bodies: &[BodyMesh]) -> R shaped_wall_cuts(&mut cuts, p, &walls_r, plane.base(), plane.u_model()); append_roof_sections(&mut cuts, p, &plane); - let walls = wall_owners(p, &walls_r); + let owners = wall_owners(p, &walls_r); + // Bogenwand ([T2]): Schichtfolge quer zum Schnitt aus der Richtung des Sehnen-Teilkörpers. + let virt: Vec> = walls_r + .iter() + .zip(&owners) + .map(|(r, o)| { + o.filter(|w| crate::wall_arc::WallArc::of_wall(w).is_some()).map(|w| Wall { start: Vec2 { x: r.start[0], y: r.start[1] }, end: Vec2 { x: r.end[0], y: r.end[1] }, ..w.clone() }) + }) + .collect(); + let walls: Vec> = owners.iter().zip(&virt).map(|(o, v)| v.as_ref().or(*o)).collect(); let slabs = slab_owners(p, &slabs_r); let cuts = attach_cut_styles(cuts, p, &plane, &walls, &slabs)?; let cuts = merge_monolith_cuts(cuts, &slabs_r); @@ -1812,6 +1826,20 @@ pub fn section_opening_primitives(p: &Project, level: &LevelSpec, vis: &Visibili if !vis.visible(&wall.category_code) { continue; } + // Bogenwand ([T2]): Öffnung auf der Sehne zwischen den Laibungen (gerades Einbauteil). + let chord = crate::wall_arc::WallArc::of_wall(wall).map(|a| { + let axis = a.length(); + let from = max(0.0, min(o.position, axis)); + let to = max(from, min(o.position + o.width, axis)); + let (ps, pe) = (a.point(from, 0.0), a.point(to, 0.0)); + let vw = Wall { start: Vec2 { x: ps.x, y: ps.y }, end: Vec2 { x: pe.x, y: pe.y }, bulge: None, ..wall.clone() }; + let vo = Opening { position: 0.0, width: hypot2(pe.x - ps.x, pe.y - ps.y), ..o.clone() }; + (vw, vo) + }); + let (wall, o) = match &chord { + Some((vw, vo)) => (vw, vo), + None => (wall, o), + }; let Some(c) = cross_section(p, wall, o, p0, u)? else { continue }; let mut prims = if o.kind == ElementKind::Window { window_cut(p, wall, o, &c)? } else { door_cut(p, o, &c) }; prims.extend(rebate_cut(p, wall, o, &c)?); diff --git a/src-tauri/core/src/plan/stairs.rs b/src-tauri/core/src/plan/stairs.rs index d732719d..bbe3b3b1 100644 --- a/src-tauri/core/src/plan/stairs.rs +++ b/src-tauri/core/src/plan/stairs.rs @@ -112,6 +112,7 @@ pub fn plan_stairs(c: &Ctx, out: &mut Vec, bounds: &mut Bounds) { cls: "stair-outline".into(), weight_mm: f[i + 1], dash: None, + color: None, opening_id: None, stair_id: Some(s.id.clone()), greyed, diff --git a/src-tauri/core/src/plan/underlay.rs b/src-tauri/core/src/plan/underlay.rs index 98f49ce0..8da2093b 100644 --- a/src-tauri/core/src/plan/underlay.rs +++ b/src-tauri/core/src/plan/underlay.rs @@ -71,7 +71,7 @@ pub fn map_primitive(m: &SectionMap, pr: Primitive) -> Option { } // `motif` ist im Strich-lokalen Raum definiert — dreht mit der Linie mit. Primitive::Line { a, b, cls, weight_mm, dash, zigzag, motif, color, drawing_id, opening_id, stair_id, greyed, opacity } => Primitive::Line { a: p(a), b: p(b), cls, weight_mm, dash, zigzag, motif, color, drawing_id, opening_id, stair_id, greyed, opacity }, - Primitive::Arc { center, from, to, r, cls, weight_mm, dash, opening_id, stair_id, greyed, opacity } => Primitive::Arc { center: p(center), from: p(from), to: p(to), r, cls, weight_mm, dash, opening_id, stair_id, greyed, opacity }, + Primitive::Arc { center, from, to, r, cls, weight_mm, dash, color, opening_id, stair_id, greyed, opacity } => Primitive::Arc { center: p(center), from: p(from), to: p(to), r, cls, weight_mm, dash, color, opening_id, stair_id, greyed, opacity }, Primitive::Text { at, doc, extra_lines, base_pt, color, room_id, greyed, opacity } => Primitive::Text { at: p(at), doc, extra_lines, base_pt, color, room_id, greyed, opacity }, Primitive::DrawingText { at, text, height_m, angle, color, marks, wrap_width, doc, drawing_id, greyed, opacity } => Primitive::DrawingText { at: p(at), text, height_m, angle: angle + m.theta, color, marks, wrap_width, doc, drawing_id, greyed, opacity }, Primitive::DrawingTextPath { path_pts, text, height_m, color, drawing_id, greyed, opacity } => Primitive::DrawingTextPath { path_pts: path_pts.into_iter().map(p).collect(), text, height_m, color, drawing_id, greyed, opacity }, diff --git a/src-tauri/core/src/plan/walls.rs b/src-tauri/core/src/plan/walls.rs index 161cfeb6..c6267a09 100644 --- a/src-tauri/core/src/plan/walls.rs +++ b/src-tauri/core/src/plan/walls.rs @@ -10,6 +10,7 @@ use super::domains::Ctx; use super::prim::{HatchRender, Primitive}; use super::style::*; use crate::joins::{self, WallCuts}; +use crate::wall_arc::Unroll; use crate::js_fmt::to_fixed; use crate::jsnum::{atan2, round}; use crate::model::*; @@ -63,17 +64,15 @@ fn plan_joins(p: &Project, walls: &[EffWall]) -> Result, String> { buf.extend([l.thickness, idx, comp.join_priority]); } } - let out = joins::compute_joins_flat(&buf); // Fehler der Verschneidung (mit den Rückfällen oben nicht mehr erwartet): Wände ohne Verschneidung. - if out.first() != Some(&0.0) { + let Some(mut jw) = joins::decode_walls(&buf) else { return Ok(vec![WallCuts::default(); walls.len()]); + }; + // Bogenwände ([T2]) tragen ihren Bulge. + for (j, e) in jw.iter_mut().zip(walls) { + j.bulge = e.w.bulge; } - let mut r = crate::flat_read::Reader::new(&out[1..]); - let mut cuts = Vec::with_capacity(walls.len()); - for _ in walls { - cuts.push(joins::decode_cuts(&mut r).unwrap_or_default()); - } - Ok(cuts) + Ok(joins::compute_joins(&jw).unwrap_or_else(|_| vec![WallCuts::default(); walls.len()])) } /// Wand mit angewandten Override-Regeln (Farbe → Umriss/Fugen, Strichstärke). @@ -167,7 +166,7 @@ fn v2(x: f64, y: f64) -> Vec2 { /// Wand-Poché (`addWallPoche`). #[allow(clippy::too_many_arguments)] -fn wall_poche(c: &Ctx, out: &mut Vec, e: &EffWall, gaps: &[(f64, f64)], cuts: &WallCuts, greyed: bool, wall_lw: f64, category: Option<&LayerCategory>, view_only: bool, reveals: &[f64]) -> Result<(), String> { +fn wall_poche(c: &Ctx, out: &mut Vec, e: &EffWall, gaps: &[(f64, f64)], cuts: &WallCuts, greyed: bool, wall_lw: f64, category: Option<&LayerCategory>, view_only: bool, reveals: &[f64], bend: Option<&Unroll>) -> Result<(), String> { let p = c.p; let w = e.w; let detail = c.a.detail; @@ -203,6 +202,18 @@ fn wall_poche(c: &Ctx, out: &mut Vec, e: &EffWall, gaps: &[(f64, f64) let q = i + 4 + n_no; let pts: Vec = (0..4).map(|j| v2(f[q + 2 * j], f[q + 2 * j + 1])).collect(); i = q + 8; + if let (Some(u), true) = (bend, art == 2.0) { + // [T2] Bogenwand: Schichtband in Winkelstücke teilen, damit die Schraffur der + // Tangente folgt (gebogen wird danach in `bend_prims`). + for (piece, s_mid) in split_band(u, &pts) { + let t = u.arc.tangent(s_mid); + let local = atan2(t.y, t.x) * 180.0 / std::f64::consts::PI; + let (hatch, fill) = layer_style(p, w, wt, li, category, local)?; + let all: Vec = (0..piece.len()).map(|k| k as f64).collect(); + out.push(wall_polygon(piece, &fill, "none", 0.0, hatch, greyed, Some(all), Some(&w.id), None)); + } + continue; + } if art == 2.0 { let (hatch, fill) = style_of(li)?; out.push(wall_polygon(pts, &fill, "none", 0.0, hatch, greyed, Some(no_stroke), Some(&w.id), None)); @@ -489,6 +500,7 @@ fn opening_symbol(c: &Ctx, out: &mut Vec, w: &Wall, o: &Opening, colo cls: "door-swing".into(), weight_mm: f[i + 1], dash: None, + color: None, opening_id: Some(o.id.clone()), stair_id: None, greyed: Some(greyed), @@ -613,14 +625,19 @@ pub fn plan_walls(c: &Ctx, reference_lines: bool, out: &mut Vec, boun for e in &walls { let w = e.w; bounds_wall(p, w, bounds); + // Bogenwand ([T2]): die gerade Pipeline rechnet auf der abgewickelten Ersatzwand `wv`, die + // Ausgabe wird gebogen (`bend_prims`). + let arc_wall = crate::wall_arc::unrolled_wall(w); + let wv: &Wall = arc_wall.as_ref().map_or(w, |a| &a.1); + let ev = EffWall { w: wv, color: e.color.clone(), stroke_weight: e.stroke_weight }; let greyed = c.greyed(&w.category_code); let category = c.cat(&w.category_code); let lw = resolve_stroke_weight(e.stroke_weight, w.stroke_weight_source, category, category.map_or(WALL_FALLBACK_MM, |k| k.lw)); let openings: Vec<&Opening> = p.openings_of_wall(&w.id).collect(); let wr_total = p.wall_thickness(w, 0.2); let wr = crate::opening_geom::WallRef { - start: crate::opening_geom::v(w.start.x, w.start.y), - end: crate::opening_geom::v(w.end.x, w.end.y), + start: crate::opening_geom::v(wv.start.x, wv.start.y), + end: crate::opening_geom::v(wv.end.x, wv.end.y), total: wr_total, ref_off: joins::reference_offset(crate::model3d::wall_reference(w), wr_total), }; @@ -630,10 +647,32 @@ pub fn plan_walls(c: &Ctx, reference_lines: bool, out: &mut Vec, boun let cut = cut_by_id.get(w.id.as_str()).copied().unwrap_or(&empty); let (zb, zt) = p.wall_vertical_extent(w); let view_only = zt < cut_z || zb > cut_z; - let reveals = crate::opening_detail::plan_reveal_block(p, w, &openings); - wall_poche(c, out, e, &gaps, cut, greyed, lw, category, view_only, &reveals)?; - if reference_lines { - out.push(mk_line(w.start, w.end, "wall-axis", 0.13, Some(Some(vec![0.18, 0.06, 0.04, 0.06])), None, greyed, None)); + let reveals = crate::opening_detail::plan_reveal_block(p, wv, &openings); + let (unroll, cut_u) = match &arc_wall { + Some((arc, _)) => { + let total = p.wall_thickness(w, 0.2); + let ro = joins::reference_offset(crate::model3d::wall_reference(w), total); + let mut u = Unroll::new(*arc); + let cu = unroll_cuts(&mut u, cut, ro - total / 2.0, ro + total / 2.0); + (Some(u), cu) + } + None => (None, WallCuts::default()), + }; + match &unroll { + Some(u) => { + let mut tmp = Vec::new(); + wall_poche(c, &mut tmp, &ev, &gaps, &cut_u, greyed, lw, category, view_only, &reveals, Some(u))?; + if reference_lines { + tmp.push(mk_line(wv.start, wv.end, "wall-axis", 0.13, Some(Some(vec![0.18, 0.06, 0.04, 0.06])), None, greyed, None)); + } + bend_prims(u, tmp, out); + } + None => { + wall_poche(c, out, e, &gaps, cut, greyed, lw, category, view_only, &reveals, None)?; + if reference_lines { + out.push(mk_line(w.start, w.end, "wall-axis", 0.13, Some(Some(vec![0.18, 0.06, 0.04, 0.06])), None, greyed, None)); + } + } } for o in openings { if !c.shown(&o.category_code) { @@ -649,16 +688,171 @@ pub fn plan_walls(c: &Ctx, reference_lines: bool, out: &mut Vec, boun _ => c.a.detail, }; let wall_line = (e.color.as_deref().unwrap_or(POCHE_STROKE), lw * c.a.detail.outline_factor()); - opening_symbol(c, out, w, o, color, c.greyed(&o.category_code), detail, olw, wall_line)?; + match &unroll { + Some(u) => { + let mut tmp = Vec::new(); + opening_symbol(c, &mut tmp, wv, o, color, c.greyed(&o.category_code), detail, olw, wall_line)?; + bend_prims(u, tmp, out); + } + None => opening_symbol(c, out, w, o, color, c.greyed(&o.category_code), detail, olw, wall_line)?, + } } } Ok(()) } +/// Schnittlinien einer Bogenwand in den abgewickelten Rahmen ([T2]); Aussparungen sind schon in +/// Bogenlänge. Nicht abwickelbare Linien fallen weg (Ende bleibt radial). +fn unroll_cuts(u: &mut Unroll, c: &WallCuts, lo: f64, hi: f64) -> WallCuts { + let len = u.arc.length(); + let mut one = |l: &Option, s: f64| l.as_ref().and_then(|l| u.unroll_line(l, lo, hi, s)); + let start_cut = one(&c.start_cut, 0.0); + let end_cut = one(&c.end_cut, len); + let layer_cuts = c.layer_cuts.as_ref().map(|lc| joins::LayerCuts { + start: lc.start.iter().map(|l| one(l, 0.0)).collect(), + end: lc.end.iter().map(|l| one(l, len)).collect(), + start_side: lc.start_side.iter().map(|l| one(l, 0.0)).collect(), + end_side: lc.end_side.iter().map(|l| one(l, len)).collect(), + }); + WallCuts { start_cut, end_cut, layer_cuts, span_cutouts: c.span_cutouts.clone() } +} + +/// Konvexes Viereck (abgewickelt) an den Zerlegungsstellen in Stücke teilen: (Stück, mittleres s). +fn split_band(u: &Unroll, pts: &[Vec2]) -> Vec<(Vec, f64)> { + let (x0, x1) = pts.iter().fold((f64::INFINITY, f64::NEG_INFINITY), |(a, b), q| (a.min(q.x), b.max(q.x))); + if !(x1 > x0) { + return vec![]; + } + let (n0, n1) = pts.iter().fold((f64::INFINITY, f64::NEG_INFINITY), |(a, b), q| (a.min(q.y), b.max(q.y))); + let st = u.arc.stations(x0, x1, u.arc.r_max(n0, n1)); + let mut out = Vec::new(); + for k in 0..st.len() - 1 { + let piece = clip_slab(pts, st[k], st[k + 1]); + if piece.len() >= 3 { + out.push((piece, (st[k] + st[k + 1]) / 2.0)); + } + } + out +} + +/// Polygon auf den Streifen a ≤ x ≤ b beschneiden (Sutherland–Hodgman). +fn clip_slab(pts: &[Vec2], a: f64, b: f64) -> Vec { + let clip = |poly: Vec, keep: &dyn Fn(Vec2) -> bool, x: f64| -> Vec { + let n = poly.len(); + let mut o = Vec::with_capacity(n + 2); + for i in 0..n { + let (p, q) = (poly[i], poly[(i + 1) % n]); + let (kp, kq) = (keep(p), keep(q)); + if kp { + o.push(p); + } + if kp != kq && (q.x - p.x).abs() > 1e-15 { + let t = (x - p.x) / (q.x - p.x); + o.push(v2(x, p.y + (q.y - p.y) * t)); + } + } + o + }; + let p1 = clip(pts.to_vec(), &|q: Vec2| q.x >= a - 1e-12, a); + let mut p2 = clip(p1, &|q: Vec2| q.x <= b + 1e-12, b); + p2.dedup_by(|p, q| (p.x - q.x).abs() < 1e-12 && (p.y - q.y).abs() < 1e-12); + p2 +} + +fn kv(p: Vec2) -> kernel2d::Vec2 { + kernel2d::Vec2::new(p.x, p.y) +} + +fn mv(p: kernel2d::Vec2) -> Vec2 { + v2(p.x, p.y) +} + +fn bmap(u: &Unroll, p: Vec2) -> Vec2 { + mv(u.map(kv(p))) +} + +fn bend_poly(u: &Unroll, pts: &[Vec2], ns: &[f64]) -> (Vec, Vec) { + let k: Vec = pts.iter().map(|q| kv(*q)).collect(); + let (o, n) = u.polygon(&k, ns); + (o.into_iter().map(mv).collect(), n) +} + +/// Grundriss-Primitive der abgewickelten Ersatzwand biegen ([T2]): Flächen über die Bogenkanten +/// zerlegt, Linien mit konstantem Querversatz als Bögen (≤ 90° je Stück, Gegenuhrzeigersinn, wie +/// es Bildschirm, SVG und DXF erwarten), übrige Linien gerade. +fn bend_prims(u: &Unroll, prims: Vec, out: &mut Vec) { + for mut p in prims { + match &mut p { + Primitive::Polygon { pts, no_stroke_edges, .. } => { + let (bp, ns) = bend_poly(u, pts, no_stroke_edges.as_deref().unwrap_or(&[])); + *pts = bp; + if no_stroke_edges.is_some() { + *no_stroke_edges = Some(ns); + } + } + Primitive::Line { a, b, cls, weight_mm, dash, color, opening_id, greyed, opacity, .. } => { + if u.is_arc_edge(kv(*a), kv(*b)) { + let c = mv(u.arc.center); + let r = u.arc.radius_at(a.y); + let (pa, pb) = (bmap(u, *a), bmap(u, *b)); + let (fa, fb) = crate::wall_arc::arc_angles(kv(c), kv(pa), kv(pb)); + let est = u.arc.sigma() * (b.x - a.x) / u.arc.r; + let mut d = (fb - fa) - est; + d = d - (d / (2.0 * std::f64::consts::PI)).round() * 2.0 * std::f64::consts::PI; + let sweep = est + d; + let k = ((sweep.abs() / (std::f64::consts::PI / 2.0)).ceil() as usize).max(1); + for i in 0..k { + let t0 = fa + sweep * i as f64 / k as f64; + let t1 = fa + sweep * (i + 1) as f64 / k as f64; + let (lo, hi) = if t1 >= t0 { (t0, t1) } else { (t1, t0) }; + let at = |t: f64| v2(c.x + r * t.cos(), c.y + r * t.sin()); + // Exakte Endpunkte (eingerastet) an den Enden. + let q0 = if (lo - fa).abs() < 1e-12 { pa } else if (lo - (fa + sweep)).abs() < 1e-12 { pb } else { at(lo) }; + let q1 = if (hi - fa).abs() < 1e-12 { pa } else if (hi - (fa + sweep)).abs() < 1e-12 { pb } else { at(hi) }; + out.push(Primitive::Arc { + center: c, + from: q0, + to: q1, + r, + cls: cls.clone(), + weight_mm: *weight_mm, + dash: dash.clone(), + color: color.clone(), + opening_id: opening_id.clone(), + stair_id: None, + greyed: *greyed, + opacity: *opacity, + }); + } + continue; + } + *a = bmap(u, *a); + *b = bmap(u, *b); + } + Primitive::Arc { center, from, to, .. } => { + *center = bmap(u, *center); + *from = bmap(u, *from); + *to = bmap(u, *to); + } + _ => {} + } + out.push(p); + } +} + /// Wand-Ecken (`wallCorners` mit Typ-Dicke) ins Ausmass. fn bounds_wall(p: &Project, w: &Wall, bounds: &mut super::domains::Bounds) { let Some(wt) = p.wall_type(w) else { return }; let h = thickness(&wt.layers) / 2.0; + if let Some(a) = crate::wall_arc::WallArc::of_wall(w) { + for s in a.stations(0.0, a.length(), a.r + h) { + for off in [h, -h] { + let q = a.point(s, off); + bounds.acc(q.x, q.y); + } + } + return; + } let (dx, dy) = (w.end.x - w.start.x, w.end.y - w.start.y); let l = crate::jsmath::hypot2(dx, dy); let l = if l == 0.0 || l.is_nan() { 1.0 } else { l }; diff --git a/src-tauri/core/src/plan_buf.rs b/src-tauri/core/src/plan_buf.rs index 22e90843..fb8842ee 100644 --- a/src-tauri/core/src/plan_buf.rs +++ b/src-tauri/core/src/plan_buf.rs @@ -927,6 +927,7 @@ impl<'a> View<'a> { cls: self.opt_string(f[0])?.unwrap_or_default(), weight_mm: f[2], dash, + color: if fl & F_COLOR != 0 { self.opt_string(f[1])? } else { None }, opening_id, stair_id, greyed, @@ -1730,11 +1731,11 @@ impl Writer { self.line_ref(&line, dash_ref); return; } - Primitive::Arc { center, from, to, r, cls, weight_mm, dash, opening_id, stair_id, greyed, opacity } => { - let flags = Self::style_flags(*greyed, *opacity) | Self::dash_flags(dash); + Primitive::Arc { center, from, to, r, cls, weight_mm, dash, color, opening_id, stair_id, greyed, opacity } => { + let flags = Self::style_flags(*greyed, *opacity) | Self::dash_flags(dash) | if color.is_some() { F_COLOR } else { 0 }; let rest = self.head(T_ARC, flags, &[(4, opening_id.as_deref()), (5, stair_id.as_deref())]); self.str(Some(cls)); - self.str(None); + self.str(color.as_deref()); self.num(*weight_mm); self.num(opacity.unwrap_or(1.0)); for v in [center.x, center.y, from.x, from.y, to.x, to.y, *r] { @@ -2213,6 +2214,7 @@ pub(crate) mod tests { cls: "door-swing".into(), weight_mm: 0.13, dash: Some(Some(vec![0.5])), + color: Some("#123456".into()), opening_id: Some("D1".into()), stair_id: None, greyed: None, diff --git a/src-tauri/core/src/plan_elevation.rs b/src-tauri/core/src/plan_elevation.rs index e53ecca3..6cccffb7 100644 --- a/src-tauri/core/src/plan_elevation.rs +++ b/src-tauri/core/src/plan_elevation.rs @@ -547,15 +547,40 @@ fn wall_faces(f: &Frame, w: &[f64], src: usize, out: &mut Vec) { let corner = |s_along: f64, t_off: f64, y: f64| -> V3 { [sx + a_hat[0] * s_along + n_hat[0] * t_off, y, sz + a_hat[2] * s_along + n_hat[2] * t_off] }; + // Schnitt-Verschiebungen der vier Ecken längs der Achse ([T2]: Gehrung der Bogen-Teilkörper): + // Anfang +n, Anfang −n, Ende +n, Ende −n; ohne Angabe 0 (rechtwinklig wie bisher). + let [sp, sm, ep, em] = if w.len() >= 11 { [w[7], w[8], w[9], w[10]] } else { [0.0; 4] }; + // Innere Stossfuge (Bogen-Teilkörper): keine Stirnfläche, sie läge im Inneren der Wand. + let (cap_start, cap_end) = if w.len() >= 13 { (w[11] == 0.0, w[12] == 0.0) } else { (true, true) }; + let (s_p, s_m, e_p, e_m) = (sp, sm, len + ep, len + em); + // Normale einer schrägen Stirnfläche (Grundriss-Senkrechte zur Kante, Richtung `toward`). + let cap_normal = |a: V3, b: V3, toward: V3, square: V3| -> V3 { + let (dx, dz) = (b[0] - a[0], b[2] - a[2]); + let l = hypot2(dx, dz); + if l < 1e-12 { + return square; + } + let n: V3 = [dz / l, 0.0, -dx / l]; + if n[0] * toward[0] + n[2] * toward[2] >= 0.0 { + n + } else { + neg(n) + } + }; + let start_n = if sp == 0.0 && sm == 0.0 { neg(a_hat) } else { cap_normal(corner(s_m, -ht, zb), corner(s_p, ht, zb), neg(a_hat), neg(a_hat)) }; + let end_n = if ep == 0.0 && em == 0.0 { a_hat } else { cap_normal(corner(e_m, -ht, zb), corner(e_p, ht, zb), a_hat, a_hat) }; let faces: [(V3, [V3; 4]); 6] = [ - (n_hat, [corner(0.0, ht, zb), corner(len, ht, zb), corner(len, ht, zt), corner(0.0, ht, zt)]), - (neg(n_hat), [corner(0.0, -ht, zb), corner(0.0, -ht, zt), corner(len, -ht, zt), corner(len, -ht, zb)]), - (neg(a_hat), [corner(0.0, -ht, zb), corner(0.0, ht, zb), corner(0.0, ht, zt), corner(0.0, -ht, zt)]), - (a_hat, [corner(len, -ht, zb), corner(len, -ht, zt), corner(len, ht, zt), corner(len, ht, zb)]), - ([0.0, 1.0, 0.0], [corner(0.0, -ht, zt), corner(0.0, ht, zt), corner(len, ht, zt), corner(len, -ht, zt)]), - ([0.0, -1.0, 0.0], [corner(0.0, -ht, zb), corner(len, -ht, zb), corner(len, ht, zb), corner(0.0, ht, zb)]), + (n_hat, [corner(s_p, ht, zb), corner(e_p, ht, zb), corner(e_p, ht, zt), corner(s_p, ht, zt)]), + (neg(n_hat), [corner(s_m, -ht, zb), corner(s_m, -ht, zt), corner(e_m, -ht, zt), corner(e_m, -ht, zb)]), + (start_n, [corner(s_m, -ht, zb), corner(s_p, ht, zb), corner(s_p, ht, zt), corner(s_m, -ht, zt)]), + (end_n, [corner(e_m, -ht, zb), corner(e_m, -ht, zt), corner(e_p, ht, zt), corner(e_p, ht, zb)]), + ([0.0, 1.0, 0.0], [corner(s_m, -ht, zt), corner(s_p, ht, zt), corner(e_p, ht, zt), corner(e_m, -ht, zt)]), + ([0.0, -1.0, 0.0], [corner(s_m, -ht, zb), corner(e_m, -ht, zb), corner(e_p, ht, zb), corner(s_p, ht, zb)]), ]; - for (normal, poly) in faces { + for (i, (normal, poly)) in faces.into_iter().enumerate() { + if (i == 2 && !cap_start) || (i == 3 && !cap_end) { + continue; + } if let Some(p) = project_face(f, &poly, normal, 0, src) { out.push(p); } @@ -685,12 +710,17 @@ pub fn faces(frame: &[f64], walls: &[f64], slabs: &[f64], roofs: &[f64]) -> Vec< let (Some(nw), Some(ns), Some(nr)) = (counted(walls), counted(slabs), counted(roofs)) else { return Vec::new(); }; - if walls.len() != 1 + 7 * nw { + // 7 Werte je Wand, oder 13 mit den Schnitt-Verschiebungen der Ecken und den inneren Stossfugen ([T2]). + let stride = if walls.len() == 1 + 7 * nw { + 7 + } else if walls.len() == 1 + 13 * nw { + 13 + } else { return Vec::new(); - } + }; let mut out: Vec = Vec::new(); for k in 0..nw { - wall_faces(&fr, &walls[1 + 7 * k..8 + 7 * k], k, &mut out); + wall_faces(&fr, &walls[1 + stride * k..1 + stride * (k + 1)], k, &mut out); } let mut i = 1; for k in 0..ns { diff --git a/src-tauri/core/src/plan_scene.rs b/src-tauri/core/src/plan_scene.rs index a8dd6a4d..5d6fc9c5 100644 --- a/src-tauri/core/src/plan_scene.rs +++ b/src-tauri/core/src/plan_scene.rs @@ -569,7 +569,8 @@ pub fn build_scene(parts: &mut [Part], greyed_ranges: &[(usize, usize)]) -> Opti T_ARC => { b.flush(); let cls = part.str(f[0]).map(str::to_owned); - let col = with_opacity(stroke_color_for(cls.as_deref(), None), cls.as_deref(), greyed); + let col_s = if rec.flags & F_COLOR != 0 { part.str(f[1]).map(str::to_owned) } else { None }; + let col = with_opacity(stroke_color_for(cls.as_deref(), col_s.as_deref()), cls.as_deref(), greyed); let dash = dash_of(part, &rec)?; b.s.arcs.push(SArc { center: v2(f[4], f[5]), from: v2(f[6], f[7]), to: v2(f[8], f[9]), r: f[10], color: col, width_mm: f[2], dash }); } diff --git a/src-tauri/core/src/plan_walls.rs b/src-tauri/core/src/plan_walls.rs index 16dc4a69..de0c6321 100644 --- a/src-tauri/core/src/plan_walls.rs +++ b/src-tauri/core/src/plan_walls.rs @@ -903,7 +903,7 @@ mod tests { fn schraeger_t_stoss_grundriss_exakt_15_bis_165_grad() { use crate::joins::{compute_joins, JoinLayer, JoinWall, Reference}; let lay = || vec![JoinLayer { thickness: 0.02, component: Some(0), priority: 10.0 }, JoinLayer { thickness: 0.16, component: Some(1), priority: 20.0 }, JoinLayer { thickness: 0.15, component: Some(2), priority: 50.0 }, JoinLayer { thickness: 0.015, component: Some(3), priority: 10.0 }]; - let jw = |s: (f64, f64), e: (f64, f64)| JoinWall { start: kernel2d::Vec2::new(s.0, s.1), end: kernel2d::Vec2::new(e.0, e.1), reference: Reference::Center, layers: Some(lay()) }; + let jw = |s: (f64, f64), e: (f64, f64)| JoinWall { start: kernel2d::Vec2::new(s.0, s.1), end: kernel2d::Vec2::new(e.0, e.1), reference: Reference::Center, layers: Some(lay()), bulge: None }; let face = 0.345 / 2.0; let merge = face - 0.015; for deg in (15..=165).step_by(15) { diff --git a/src-tauri/core/src/selection_info.rs b/src-tauri/core/src/selection_info.rs index 8f9fe45e..9caaed28 100644 --- a/src-tauri/core/src/selection_info.rs +++ b/src-tauri/core/src/selection_info.rs @@ -447,7 +447,10 @@ fn wall_selection(root: &Map, w: &Value) -> Result { let color = color_of(w, cat, WALL_FALLBACK_COLOR); let weight = lw_or(field(w, "strokeWeight"), cat, WALL_FALLBACK_MM); let (s, e) = (xy(field(w, "start").unwrap_or(&Value::Null)), xy(field(w, "end").unwrap_or(&Value::Null))); - let bb = [jsnum::min(s.0, e.0), jsnum::min(s.1, e.1), jsnum::max(s.0, e.0), jsnum::max(s.1, e.1)]; + let mut bb = [jsnum::min(s.0, e.0), jsnum::min(s.1, e.1), jsnum::max(s.0, e.0), jsnum::max(s.1, e.1)]; + for q in crate::wall_arc::axis_polyline(s, e, field(w, "bulge").and_then(Value::as_f64), 0.0, 0.0) { + bb = [bb[0].min(q.0), bb[1].min(q.1), bb[2].max(q.0), bb[3].max(q.1)]; + } let wt = find_by(arr(root.get("wallTypes")), "id", field(w, "wallTypeId")) .ok_or_else(|| format!("Unbekannter Wandtyp: {}", field(w, "wallTypeId").map_or("undefined".into(), js_text)))?; let thickness = type_thickness(wt); @@ -457,7 +460,9 @@ fn wall_selection(root: &Map, w: &Value) -> Result { let floor = level(root, field(w, "floorId")); let (zb, zt) = vertical_extent(root, w); let above = next_floor_above(root, field(w, "floorId")); - let length = hypot2(e.0 - s.0, e.1 - s.1); + // Bogenwand ([T2]): Bogenlänge der Achse. + let bulge = field(w, "bulge").and_then(Value::as_f64); + let length = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(s.0, s.1), kernel2d::Vec2::new(e.0, e.1), bulge).map_or_else(|| hypot2(e.0 - s.0, e.1 - s.1), |a| a.length()); let height = jsnum::max(0.0, zt - zb); let gross = length * thickness * height; let opening_volume = arr(root.get("openings")) diff --git a/src-tauri/core/src/site_rules.rs b/src-tauri/core/src/site_rules.rs index bf71018b..e096b571 100644 --- a/src-tauri/core/src/site_rules.rs +++ b/src-tauri/core/src/site_rules.rs @@ -286,7 +286,11 @@ fn footprint_parts(p: &Project) -> Vec { if hypot2(w.end.x - w.start.x, w.end.y - w.start.y) < 1e-9 { continue; } - parts.push(vec![wall_corners(w.start, w.end, p.wall_thickness(w, 0.2))]); + // Bogenwand ([T2]): Kreisringsektor. + match crate::wall_arc::arc_footprint(w, p.wall_thickness(w, 0.2)) { + Some(f) => parts.push(vec![f]), + None => parts.push(vec![wall_corners(w.start, w.end, p.wall_thickness(w, 0.2))]), + } } for s in p.extruded_solids.as_deref().unwrap_or(&[]) { if s.operation.as_deref() == Some("subtract") || s.points.len() < 3 { diff --git a/src-tauri/core/src/snap_model.rs b/src-tauri/core/src/snap_model.rs index 126e6083..2d9e675c 100644 --- a/src-tauri/core/src/snap_model.rs +++ b/src-tauri/core/src/snap_model.rs @@ -98,6 +98,20 @@ pub fn wall_layer_segments(p: &Project, w: &crate::model::Wall, out: &mut Vec -half, _ => 0.0, }; + // Bogenwand ([T2]): jede Schichtfuge als Sehnenzug. + if crate::wall_arc::is_arc_bulge(w.bulge) { + let mut push = |o: f64| { + let pts = crate::wall_arc::axis_polyline((w.start.x, w.start.y), (w.end.x, w.end.y), w.bulge, o, total); + out.extend(pts.windows(2).map(|q| [q[0].0, q[0].1, q[1].0, q[1].1])); + }; + let mut off = ref_off - total / 2.0; + push(off); + for layer in &wt.layers { + off += layer.thickness; + push(off); + } + return; + } let (dx, dy) = (w.end.x - w.start.x, w.end.y - w.start.y); let l = hypot2(dx, dy); let l = if l == 0.0 || l.is_nan() { 1.0 } else { l }; @@ -118,7 +132,12 @@ pub fn collect_model(p: &Project, level: &str, codes: &HashSet) -> SnapP let mut segs: Vec = Vec::new(); for w in &p.walls { if vis(&w.floor_id, &w.category_code) { - segs.push(seg(&w.start, &w.end)); + if crate::wall_arc::is_arc_bulge(w.bulge) { + let pts = crate::wall_arc::axis_polyline((w.start.x, w.start.y), (w.end.x, w.end.y), w.bulge, 0.0, 0.0); + segs.extend(pts.windows(2).map(|q| [q[0].0, q[0].1, q[1].0, q[1].1])); + } else { + segs.push(seg(&w.start, &w.end)); + } wall_layer_segments(p, w, &mut segs); } } diff --git a/src-tauri/core/src/sun.rs b/src-tauri/core/src/sun.rs index aee487e5..90537dc7 100644 --- a/src-tauri/core/src/sun.rs +++ b/src-tauri/core/src/sun.rs @@ -293,6 +293,11 @@ pub fn shadow_polygons_project(p: &Project, sun: SunPosition) -> Vec { let mut prisms: Vec = Vec::new(); for w in &p.walls { let (z_bottom, z_top) = p.wall_vertical_extent(w); + // Bogenwand ([T2]): Kreisringsektor als Prisma. + if let Some(footprint) = crate::wall_arc::arc_footprint(w, p.wall_thickness(w, 0.2)) { + prisms.push(Prism { footprint, z_bottom, z_top }); + continue; + } let dx = w.end.x - w.start.x; let dy = w.end.y - w.start.y; let len = hypot2(dx, dy); diff --git a/src-tauri/core/src/wall_arc.rs b/src-tauri/core/src/wall_arc.rs new file mode 100644 index 00000000..a790aebf --- /dev/null +++ b/src-tauri/core/src/wall_arc.rs @@ -0,0 +1,609 @@ +//! Bogenwände ([T2]): Achse als Kreisbogen von `start` nach `end` mit `Wall.bulge` (Modell-Konvention +//! wie bei Polylinien: `bulge = tan(Öffnungswinkel/4)`, positiv = Scheitel LINKS der Sehne, also +//! Uhrzeigersinn; = −DXF-Bulge). Jede Schicht ist ein Kreisringsektor (konzentrische Versätze). +//! +//! Wandlokale Koordinaten wie bei der geraden Wand: `s` = Bogenlänge auf der Achse ab `start`, +//! `n` = Querversatz entlang der LINKEN Normalen der Laufrichtung. Auf dem Versatz `n` liegt der +//! Punkt auf dem Radius `r − σ·n` (σ = +1 Gegenuhrzeigersinn, −1 Uhrzeigersinn). +//! +//! Die Ableitungen nutzen zwei Wege: +//! - **Abwickeln/Biegen** (Grundriss): die gerade Pipeline rechnet auf der abgewickelten Wand +//! (`start` = (0,0), `end` = (L,0)), die Ausgabe wird mit [`WallArc::point`] gebogen; Kanten mit +//! konstantem `n` werden Bögen, Punkte auf Schnittlinien rastet [`Unroll::map`] exakt ein. +//! - **Sehnen-Zerlegung** (3D, Schnitt, Ansicht, Exporte): [`WallArc::stations`] liefert Teilstellen, +//! zwischen denen gerade Teilwände mit radialen Gehrungs-Schnitten liegen; die Versätze eines +//! Sehnenpolygons sind wieder Sehnenpolygone, die Teilkörper schliessen also lückenlos. + +use crate::joins::Line; +use kernel2d::{add, dot, scale, sub, Vec2}; +use std::f64::consts::PI; + +/// Bulge unterhalb dieser Grösse gilt als gerade (wie `kernel2d::bulge_arc`). +pub const BULGE_EPS: f64 = 1e-9; +/// Sehnen-Toleranz (Pfeilhöhe) der Zerlegung, Meter. +pub const CHORD_TOL: f64 = 1e-3; +/// Grösster Winkelschritt der Zerlegung (7.5°), damit auch kleine Radien glatt bleiben. +pub const MAX_STEP: f64 = PI / 24.0; + +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct WallArc { + pub center: Vec2, + /// Achsradius. + pub r: f64, + /// Winkel des Startpunkts (Bogenmass). + pub a0: f64, + /// Vorzeichenbehafteter Öffnungswinkel (+ = Gegenuhrzeigersinn). + pub sweep: f64, +} + +/// Ist das ein echter Bogen (endlich, nicht ~0)? +pub fn is_arc_bulge(b: Option) -> bool { + b.is_some_and(|b| b.is_finite() && b.abs() > BULGE_EPS) +} + +fn wrap_pi(a: f64) -> f64 { + let mut x = a % (2.0 * PI); + if x > PI { + x -= 2.0 * PI; + } else if x <= -PI { + x += 2.0 * PI; + } + x +} + +impl WallArc { + /// Bogen aus Achse und Modell-Bulge; `None` = gerade (oder entartet). + pub fn of(start: Vec2, end: Vec2, bulge: Option) -> Option { + let b = bulge.filter(|b| b.is_finite() && b.abs() > BULGE_EPS)?; + if ![start.x, start.y, end.x, end.y].iter().all(|v| v.is_finite()) { + return None; + } + // Öffnungswinkel begrenzen: |bulge| ≤ 1e3 (fast Vollkreis), sonst entartet. + let b = b.clamp(-1e3, 1e3); + let a = kernel2d::bulge_arc(start, end, b)?; + if !(a.r.is_finite() && a.r > 1e-9 && a.sweep.is_finite()) { + return None; + } + Some(WallArc { center: a.center, r: a.r, a0: a.a0, sweep: a.sweep }) + } + + /// Aus dem Modell (Achse + `bulge`). + pub fn of_wall(w: &crate::model::Wall) -> Option { + WallArc::of(Vec2::new(w.start.x, w.start.y), Vec2::new(w.end.x, w.end.y), w.bulge) + } + + pub fn sigma(&self) -> f64 { + if self.sweep >= 0.0 { + 1.0 + } else { + -1.0 + } + } + + /// Bogenlänge der Achse. + pub fn length(&self) -> f64 { + self.r * self.sweep.abs() + } + + /// Radius der Versatzlinie `n` (links der Laufrichtung positiv). + pub fn radius_at(&self, n: f64) -> f64 { + self.r - self.sigma() * n + } + + pub fn angle_at(&self, s: f64) -> f64 { + self.a0 + self.sigma() * s / self.r + } + + /// Weltpunkt zu (s, n). + pub fn point(&self, s: f64, n: f64) -> Vec2 { + let a = self.angle_at(s); + let rr = self.radius_at(n); + Vec2::new(self.center.x + rr * a.cos(), self.center.y + rr * a.sin()) + } + + /// Einheits-Tangente (Laufrichtung) bei `s`. + pub fn tangent(&self, s: f64) -> Vec2 { + let a = self.angle_at(s); + Vec2::new(-self.sigma() * a.sin(), self.sigma() * a.cos()) + } + + /// Linke Normale der Laufrichtung bei `s`. + pub fn normal(&self, s: f64) -> Vec2 { + let t = self.tangent(s); + Vec2::new(-t.y, t.x) + } + + /// Wandlokale Koordinaten (s, n) eines Weltpunkts; `s` läuft über das Bogenende hinaus + /// (negativ vor dem Start), gewählt nächst der Bogenmitte. + pub fn local(&self, p: Vec2) -> (f64, f64) { + let d = sub(p, self.center); + let dist = d.x.hypot(d.y); + let ang = d.y.atan2(d.x); + let mid = self.a0 + self.sweep / 2.0; + let rel = self.sigma() * wrap_pi(ang - mid) + self.sweep.abs() / 2.0; + (rel * self.r, self.sigma() * (self.r - dist)) + } + + /// Winkelschritt-Anzahl für die Zerlegung bei grösstem Radius `r_max` (Toleranz [`CHORD_TOL`]). + pub fn segments(&self, r_max: f64) -> usize { + let rm = r_max.max(self.r).max(1e-6); + let c = (1.0 - CHORD_TOL / rm).clamp(-1.0, 1.0); + let step = (2.0 * c.acos()).clamp(1e-3, MAX_STEP); + ((self.sweep.abs() / step).ceil() as usize).clamp(1, 512) + } + + /// Bogenlängen gleichmässiger Teilstellen auf [a, b] (mit beiden Enden). + pub fn stations(&self, a: f64, b: f64, r_max: f64) -> Vec { + let total = self.length().max(1e-12); + let n = ((self.segments(r_max) as f64 * (b - a).abs() / total).ceil() as usize).max(1); + (0..=n).map(|i| a + (b - a) * i as f64 / n as f64).collect() + } + + /// Bogenlängen, an denen der Versatzkreis `n` die Gerade `l` trifft (beide Lösungen, `s` + /// unbeschnitten, s. [`WallArc::local`]). + pub fn line_hits(&self, n: f64, l: &Line) -> Vec { + circle_line(self.center, self.radius_at(n), l).into_iter().map(|p| self.local(p).0).collect() + } + + /// Welt-Treffer des Versatzkreises `n` mit der Geraden, nächst `near`. + pub fn line_hit_near(&self, n: f64, l: &Line, near: Vec2) -> Option { + nearest(circle_line(self.center, self.radius_at(n), l), near) + } + + /// Grösster Radius über den Querbereich [lo, hi]. + pub fn r_max(&self, lo: f64, hi: f64) -> f64 { + self.radius_at(lo).abs().max(self.radius_at(hi).abs()) + } +} + +/// Schnittpunkte Kreis (c, r) × Gerade. +pub fn circle_line(c: Vec2, r: f64, l: &Line) -> Vec { + let dl = l.dir.x.hypot(l.dir.y); + if !(dl > 1e-15) || !(r > 0.0) { + return vec![]; + } + let u = Vec2::new(l.dir.x / dl, l.dir.y / dl); + let f = sub(l.point, c); + let b = dot(f, u); + let cc = dot(f, f) - r * r; + let disc = b * b - cc; + if disc < -1e-12 { + return vec![]; + } + let sq = disc.max(0.0).sqrt(); + vec![add(l.point, scale(u, -b - sq)), add(l.point, scale(u, -b + sq))] +} + +/// Schnittpunkte zweier Kreise. +pub fn circle_circle(c1: Vec2, r1: f64, c2: Vec2, r2: f64) -> Vec { + let d = sub(c2, c1); + let dd = d.x.hypot(d.y); + if !(dd > 1e-12) || dd > r1 + r2 + 1e-9 || dd < (r1 - r2).abs() - 1e-9 { + return vec![]; + } + let a = (r1 * r1 - r2 * r2 + dd * dd) / (2.0 * dd); + let h = (r1 * r1 - a * a).max(0.0).sqrt(); + let m = add(c1, scale(d, a / dd)); + let o = Vec2::new(-d.y / dd * h, d.x / dd * h); + vec![add(m, o), sub(m, o)] +} + +pub fn nearest(pts: Vec, near: Vec2) -> Option { + pts.into_iter().filter(|p| p.x.is_finite() && p.y.is_finite()).min_by(|a, b| { + let da = sub(*a, near); + let db = sub(*b, near); + (da.x * da.x + da.y * da.y).partial_cmp(&(db.x * db.x + db.y * db.y)).unwrap_or(std::cmp::Ordering::Equal) + }) +} + +/// Versatzkurve einer Wand: Gerade oder Kreis. +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum Curve { + Line(Line), + Circle(Vec2, f64), +} + +/// Alle Schnittpunkte zweier Versatzkurven. +pub fn curve_hits(a: &Curve, b: &Curve) -> Vec { + match (a, b) { + (Curve::Line(l1), Curve::Line(l2)) => kernel2d::line_intersect(l1.point, l1.dir, l2.point, l2.dir).into_iter().collect(), + (Curve::Line(l), Curve::Circle(c, r)) | (Curve::Circle(c, r), Curve::Line(l)) => circle_line(*c, *r, l), + (Curve::Circle(c1, r1), Curve::Circle(c2, r2)) => circle_circle(*c1, *r1, *c2, *r2), + } +} + +/// Abwicklung einer Bogenwand: Schnittlinien (Welt) als Geraden im abgewickelten Rahmen, damit die +/// gerade Pipeline sie benutzen kann, und die Rück-Abbildung mit exaktem Einrasten auf ihnen. +#[derive(Clone, Debug)] +pub struct Unroll { + pub arc: WallArc, + /// (abgewickelte Gerade, Weltgerade). + pairs: Vec<(Line, Line)>, +} + +impl Unroll { + pub fn new(arc: WallArc) -> Unroll { + Unroll { arc, pairs: Vec::new() } + } + + /// Weltgerade → abgewickelte Gerade durch ihre Treffer mit den Flächen `n_lo`/`n_hi` + /// (jeweils nächst `s_near`). `None`, wenn sie eine Fläche nicht trifft. + pub fn unroll_line(&mut self, l: &Line, n_lo: f64, n_hi: f64, s_near: f64) -> Option { + let near_lo = self.arc.point(s_near, n_lo); + let near_hi = self.arc.point(s_near, n_hi); + let p_lo = self.arc.line_hit_near(n_lo, l, near_lo)?; + let p_hi = self.arc.line_hit_near(n_hi, l, near_hi)?; + let (s_lo, _) = self.arc.local(p_lo); + let (s_hi, _) = self.arc.local(p_hi); + let (a, b) = (Vec2::new(s_lo, n_lo), Vec2::new(s_hi, n_hi)); + let d = sub(b, a); + if d.x.hypot(d.y) < 1e-12 { + return None; + } + let u = Line { point: a, dir: d }; + self.pairs.push((u, *l)); + Some(u) + } + + /// Registriert ein Paar direkt (z. B. radiale Stossfuge). + pub fn pair(&mut self, unrolled: Line, world: Line) { + self.pairs.push((unrolled, world)); + } + + /// Abgewickelter Punkt → Welt; Punkte auf einer registrierten Schnittlinie landen exakt auf + /// deren Weltgerade (Schnitt mit dem Versatzkreis). + pub fn map(&self, p: Vec2) -> Vec2 { + let base = self.arc.point(p.x, p.y); + for (u, w) in &self.pairs { + let dl = u.dir.x.hypot(u.dir.y); + let dist = kernel2d::cross(u.dir, sub(p, u.point)).abs() / dl; + if dist < 1e-7 { + if let Some(q) = self.arc.line_hit_near(p.y, w, base) { + let e = sub(q, base); + // Nur nahe Treffer (Schutz gegen die zweite Kreislösung). + if e.x.hypot(e.y) < 0.5 { + return q; + } + } + } + } + base + } + + /// Ist die Kante a→b eine Bogenkante (konstantes n, verschiedenes s, nicht auf einer Schnittlinie)? + pub fn is_arc_edge(&self, a: Vec2, b: Vec2) -> bool { + (a.y - b.y).abs() < 1e-9 && (a.x - b.x).abs() > 1e-9 + } + + /// Kante a→b gebogen als Punktfolge (ohne `a`, mit `b`). + pub fn edge(&self, a: Vec2, b: Vec2) -> Vec { + if !self.is_arc_edge(a, b) { + return vec![self.map(b)]; + } + let rm = self.arc.radius_at(a.y).abs(); + let total = self.arc.length().max(1e-12); + let k = ((self.arc.segments(rm) as f64 * (b.x - a.x).abs() / total).ceil() as usize).clamp(1, 512); + (1..=k).map(|i| if i == k { self.map(b) } else { self.arc.point(a.x + (b.x - a.x) * i as f64 / k as f64, a.y) }).collect() + } + + /// Polygon biegen; `no_stroke` (Kantenindizes) wird auf die neuen Kanten umgerechnet. + pub fn polygon(&self, pts: &[Vec2], no_stroke: &[f64]) -> (Vec, Vec) { + let n = pts.len(); + let mut out = Vec::with_capacity(n * 4); + let mut ns = Vec::new(); + if n == 0 { + return (out, ns); + } + out.push(self.map(pts[0])); + for i in 0..n { + let a = pts[i]; + let b = pts[(i + 1) % n]; + let seg = self.edge(a, b); + let first_edge = out.len() - 1; + let last = i + 1 == n; + let k = seg.len(); + if last { + // Schlusskante: der letzte Punkt ist der Startpunkt selbst. + out.extend_from_slice(&seg[..k - 1]); + } else { + out.extend(seg); + } + if no_stroke.iter().any(|&e| e as usize == i) { + for j in 0..k { + ns.push((first_edge + j) as f64); + } + } + } + (out, ns) + } +} + +/// Bulge eines Bogens aus Start-/Endwinkel um `c` (Modell-Konvention): für Bogen-Primitive. +pub fn arc_angles(c: Vec2, a: Vec2, b: Vec2) -> (f64, f64) { + ((a.y - c.y).atan2(a.x - c.x), (b.y - c.y).atan2(b.x - c.x)) +} + +/// Band (Umriss, Dicke `t` mittig) und Achse einer Bogenwand als Punktzüge — für Vorschauen +/// (Wand-Befehl, Transformieren, Griffe). `None` = gerade. +pub fn band_preview(start: (f64, f64), end: (f64, f64), bulge: Option, t: f64) -> Option<(Vec<(f64, f64)>, Vec<(f64, f64)>)> { + let arc = WallArc::of(Vec2::new(start.0, start.1), Vec2::new(end.0, end.1), bulge)?; + let st = arc.stations(0.0, arc.length(), arc.r + t / 2.0); + let at = |s: f64, n: f64| { + let q = arc.point(s, n); + (q.x, q.y) + }; + let mut band: Vec<(f64, f64)> = st.iter().map(|&s| at(s, t / 2.0)).collect(); + band.extend(st.iter().rev().map(|&s| at(s, -t / 2.0))); + let axis = st.iter().map(|&s| at(s, 0.0)).collect(); + Some((band, axis)) +} + +/// Achse als Punktzug (Sehnen; gerade Wand: Anfang und Ende) mit Querversatz `n`. +pub fn axis_polyline(start: (f64, f64), end: (f64, f64), bulge: Option, n: f64, t: f64) -> Vec<(f64, f64)> { + match WallArc::of(Vec2::new(start.0, start.1), Vec2::new(end.0, end.1), bulge) { + Some(a) => a + .stations(0.0, a.length(), a.r + t / 2.0) + .into_iter() + .map(|s| { + let q = a.point(s, n); + (q.x, q.y) + }) + .collect(), + None => { + let (dx, dy) = (end.0 - start.0, end.1 - start.1); + let l = dx.hypot(dy); + let (nx, ny) = if l > 0.0 { (-dy / l * n, dx / l * n) } else { (0.0, 0.0) }; + vec![(start.0 + nx, start.1 + ny), (end.0 + nx, end.1 + ny)] + } + } +} + +/// Grundriss einer Bogenwand (Kreisringsektor, Dicke mittig auf der Achse) als Polygon; `None` = gerade. +pub fn arc_footprint(w: &crate::model::Wall, thickness: f64) -> Option> { + WallArc::of_wall(w)?; + let (s, e) = ((w.start.x, w.start.y), (w.end.x, w.end.y)); + let h = thickness / 2.0; + let mut out: Vec<[f64; 2]> = axis_polyline(s, e, w.bulge, h, thickness).into_iter().map(|q| [q.0, q.1]).collect(); + out.extend(axis_polyline(s, e, w.bulge, -h, thickness).into_iter().rev().map(|q| [q.0, q.1])); + Some(out) +} + +/// Achslänge einer Wand (Bogenlänge bei Bogenwänden). +pub fn axis_length(w: &crate::model::Wall) -> f64 { + match WallArc::of_wall(w) { + Some(a) => a.length(), + None => (w.end.x - w.start.x).hypot(w.end.y - w.start.y), + } +} + +/// Abgewickelte gerade Ersatzwand (`start` = (0,0), `end` = (L,0), ohne Bulge) einer Bogenwand. +pub fn unrolled_wall(w: &crate::model::Wall) -> Option<(WallArc, crate::model::Wall)> { + let a = WallArc::of_wall(w)?; + let mut v = w.clone(); + v.start = crate::model::Vec2 { x: 0.0, y: 0.0 }; + v.end = crate::model::Vec2 { x: a.length(), y: 0.0 }; + v.bulge = None; + Some((a, v)) +} + +/// Querbereich (lo, hi) der Wand aus den Bändern. +fn band_extent(w: &crate::wall_bands::WallIn) -> (f64, f64) { + let total = if w.stacked { w.bands.iter().fold(0.0, |s, b| s + b.thickness) } else { w.bands.iter().fold(0.0f64, |m, b| m.max(b.thickness)) }; + let off = crate::joins::reference_offset(w.reference, total); + (off - total / 2.0, off + total / 2.0) +} + +/// Sehnen-Zerlegung einer Bogenwand für die Schichtbänder: `w` trägt Öffnungen und Aussparungen in +/// Bogenlänge, Schnitte in Weltkoordinaten (Start/Ende/Achse werden ignoriert). Ergebnis: gerade +/// Teilwände (Sehnen der Achse) mit radialen Gehrungen dazwischen; Teilstellen auch an den +/// Öffnungskanten (Laibungen radial), keine Teilstelle im Bereich der Anschluss-Schnitte. Teilwände +/// innerhalb einer Öffnung werden zu Brüstung und Sturz (z-Bereich ohne Loch). Schichteinzug ([106]) +/// entfällt bei Bogenwänden. +pub fn chord_walls(w: &crate::wall_bands::WallIn, arc: &WallArc) -> Vec { + use crate::joins::{LayerCuts, SpanCutout, WallCuts}; + let len = arc.length(); + if !(len > 1e-9) { + return vec![]; + } + let (lo, hi) = band_extent(w); + let r_max = arc.r_max(lo, hi); + let mut st = arc.stations(0.0, len, r_max); + // Anschluss-Zonen: keine Teilstelle, wo die Schnittlinien die Wand queren. + let reach = |lines: Vec, at_end: bool| -> f64 { + let mut ext = if at_end { len } else { 0.0 }; + for l in lines { + for n in [lo, hi] { + let target = if at_end { len } else { 0.0 }; + let best = arc.line_hits(n, &l).into_iter().filter(|s| s.is_finite()).min_by(|a, b| (a - target).abs().partial_cmp(&(b - target).abs()).unwrap_or(std::cmp::Ordering::Equal)); + if let Some(s) = best { + if (s - target).abs() < len / 2.0 { + ext = if at_end { ext.min(s) } else { ext.max(s) }; + } + } + } + } + ext + }; + let lc = w.cuts.layer_cuts.as_ref(); + let starts: Vec = w.cuts.start_cut.into_iter().chain(lc.into_iter().flat_map(|l| l.start.iter().chain(l.start_side.iter()).flatten().copied())).collect(); + let ends: Vec = w.cuts.end_cut.into_iter().chain(lc.into_iter().flat_map(|l| l.end.iter().chain(l.end_side.iter()).flatten().copied())).collect(); + let z0 = reach(starts, false) + 1e-3; + let z1 = reach(ends, true) - 1e-3; + st.retain(|&s| s <= 0.0 || s >= len || (s > z0 && s < z1)); + for o in &w.openings { + for s in [o.from, o.to] { + if s > 1e-6 && s < len - 1e-6 { + st.push(s); + } + } + } + st.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)); + st.dedup_by(|a, b| (*a - *b).abs() < 1e-6); + let k = st.len() - 1; + let mut out = Vec::new(); + for i in 0..k { + let (sa, sb) = (st[i], st[i + 1]); + let (pa, pb) = (arc.point(sa, 0.0), arc.point(sb, 0.0)); + let chord = (pb.x - pa.x).hypot(pb.y - pa.y); + if chord < 1e-9 { + continue; + } + let map = |s: f64| ((s - sa) / (sb - sa) * chord).clamp(0.0, chord); + let radial = |s: f64| Line { point: arc.point(s, 0.0), dir: arc.normal(s) }; + let first = i == 0; + let last = i + 1 == k; + let layer_cuts = lc.map(|l| { + let none = vec![None; l.start.len()]; + LayerCuts { + start: if first { l.start.clone() } else { none.clone() }, + start_side: if first { l.start_side.clone() } else { none.clone() }, + end: if last { l.end.clone() } else { none.clone() }, + end_side: if last { l.end_side.clone() } else { none }, + } + }); + let span_cutouts: Vec = w + .cuts + .span_cutouts + .iter() + .filter(|c| c.from.min(c.from_b) < sb && c.to.max(c.to_b) > sa) + .map(|c| SpanCutout { from: map(c.from), to: map(c.to), from_b: map(c.from_b), to_b: map(c.to_b), ..*c }) + .filter(|c| c.to > c.from + 1e-9 || c.to_b > c.from_b + 1e-9) + .collect(); + let cuts = WallCuts { + start_cut: if first { w.cuts.start_cut } else { Some(radial(sa)) }, + end_cut: if last { w.cuts.end_cut } else { Some(radial(sb)) }, + layer_cuts, + span_cutouts, + }; + // z-Bereiche ohne die Öffnungen, die diese Teilwand ganz überdecken. + let mut zs = vec![[w.z_bottom, w.z_top]]; + for o in w.openings.iter().filter(|o| o.from <= sa + 1e-6 && o.to >= sb - 1e-6) { + let mut next = Vec::new(); + for [a, b] in zs { + if o.z_bottom > a + 1e-9 { + next.push([a, o.z_bottom.min(b)]); + } + if o.z_top < b - 1e-9 { + next.push([o.z_top.max(a), b]); + } + } + zs = next.into_iter().filter(|z| z[1] > z[0] + 1e-9).collect(); + } + for [zb, zt] in zs { + out.push(crate::wall_bands::WallIn { + start: pa, + end: pb, + z_bottom: zb, + z_top: zt, + openings: vec![], + cuts: cuts.clone(), + reveals: vec![], + ..w.clone() + }); + } + } + out +} + +#[cfg(test)] +mod tests { + use super::*; + + fn close(a: f64, b: f64, e: f64) -> bool { + (a - b).abs() < e + } + + #[test] + fn halbkreis_konvention() { + // bulge = 1: Halbkreis, Scheitel links der Sehne (0,0)→(10,0), also oben; Uhrzeigersinn. + let a = WallArc::of(Vec2::new(0.0, 0.0), Vec2::new(10.0, 0.0), Some(1.0)).unwrap(); + assert!(close(a.r, 5.0, 1e-12) && a.sigma() < 0.0); + assert!(close(a.length(), 5.0 * PI, 1e-9)); + let mid = a.point(a.length() / 2.0, 0.0); + assert!(close(mid.x, 5.0, 1e-9) && close(mid.y, 5.0, 1e-9)); + // Linke Normale zeigt im Uhrzeigersinn nach aussen: n = +0.2 → Radius 5.2. + let p = a.point(a.length() / 2.0, 0.2); + assert!(close(p.y, 5.2, 1e-9)); + let t = a.tangent(0.0); + assert!(close(t.x, 0.0, 1e-12) && close(t.y, 1.0, 1e-12)); + let e = a.point(a.length(), 0.0); + assert!(close(e.x, 10.0, 1e-9) && close(e.y, 0.0, 1e-9)); + } + + #[test] + fn lokal_ist_umkehrung() { + for b in [0.3, -0.3, 1.0, -2.0] { + let a = WallArc::of(Vec2::new(1.0, 2.0), Vec2::new(7.0, -1.0), Some(b)).unwrap(); + for (s, n) in [(0.0, 0.0), (1.3, 0.1), (a.length(), -0.2), (a.length() * 0.5, 0.15)] { + let (s2, n2) = a.local(a.point(s, n)); + assert!(close(s, s2, 1e-9) && close(n, n2, 1e-9), "{b} {s} {n} → {s2} {n2}"); + } + } + } + + #[test] + fn gerade_und_entartet() { + assert!(WallArc::of(Vec2::new(0.0, 0.0), Vec2::new(1.0, 0.0), Some(0.0)).is_none()); + assert!(WallArc::of(Vec2::new(0.0, 0.0), Vec2::new(1.0, 0.0), None).is_none()); + assert!(WallArc::of(Vec2::new(0.0, 0.0), Vec2::new(0.0, 0.0), Some(1.0)).is_none()); + assert!(WallArc::of(Vec2::new(0.0, 0.0), Vec2::new(1.0, 0.0), Some(f64::NAN)).is_none()); + assert!(WallArc::of(Vec2::new(f64::NAN, 0.0), Vec2::new(1.0, 0.0), Some(1.0)).is_none()); + } + + #[test] + fn zerlegung_haelt_toleranz() { + let a = WallArc::of(Vec2::new(0.0, 0.0), Vec2::new(10.0, 0.0), Some(1.0)).unwrap(); + let n = a.segments(5.2); + let step = a.sweep.abs() / n as f64; + assert!(5.2 * (1.0 - (step / 2.0).cos()) <= CHORD_TOL + 1e-12); + assert!(step <= MAX_STEP + 1e-12); + } + + #[test] + fn schnitte_kreis_gerade_und_kreis_kreis() { + let l = Line { point: Vec2::new(-10.0, 3.0), dir: Vec2::new(1.0, 0.0) }; + let h = circle_line(Vec2::new(0.0, 0.0), 5.0, &l); + assert_eq!(h.len(), 2); + assert!(h.iter().all(|p| close(p.x.abs(), 4.0, 1e-12) && close(p.y, 3.0, 1e-12))); + let h = circle_circle(Vec2::new(0.0, 0.0), 5.0, Vec2::new(8.0, 0.0), 5.0); + assert!(h.iter().all(|p| close(p.x, 4.0, 1e-12) && close(p.y.abs(), 3.0, 1e-12))); + } + + #[test] + fn abwicklung_rastet_auf_schnittlinie() { + let a = WallArc::of(Vec2::new(0.0, 0.0), Vec2::new(10.0, 0.0), Some(1.0)).unwrap(); + let mut u = Unroll::new(a); + // Schräge Weltgerade nahe dem Start. + let w = Line { point: Vec2::new(0.0, 0.0), dir: Vec2::new(1.0, 1.0) }; + let ul = u.unroll_line(&w, -0.2, 0.2, 0.0).unwrap(); + // Ein Punkt der abgewickelten Geraden bei n = 0.05 liegt nach dem Biegen auf der Weltgeraden. + let t = (0.05 - ul.point.y) / ul.dir.y; + let p = Vec2::new(ul.point.x + ul.dir.x * t, 0.05); + let q = u.map(p); + assert!(kernel2d::cross(w.dir, sub(q, w.point)).abs() < 1e-9); + assert!(close(sub(q, a.center).x.hypot(sub(q, a.center).y), a.radius_at(0.05), 1e-9)); + } + + #[test] + fn polygon_biegen_kanten_und_ohne_strich() { + let a = WallArc::of(Vec2::new(0.0, 0.0), Vec2::new(10.0, 0.0), Some(1.0)).unwrap(); + let u = Unroll::new(a); + let l = a.length(); + let pts = [Vec2::new(0.0, -0.1), Vec2::new(l, -0.1), Vec2::new(l, 0.1), Vec2::new(0.0, 0.1)]; + let (out, ns) = u.polygon(&pts, &[1.0]); + assert!(out.len() > 20); + // Kante 1 (radial am Ende) bleibt eine Kante. + assert_eq!(ns.len(), 1); + let e = ns[0] as usize; + let (p, q) = (out[e], out[(e + 1) % out.len()]); + assert!(close(p.x, 10.1, 1e-9) || close(q.x, 10.1, 1e-9)); + // Fläche ≈ Ringsektor π/2·(5.1² − 4.9²) = π·2·0.2·5/2 + let mut area = 0.0; + for i in 0..out.len() { + let (p, q) = (out[i], out[(i + 1) % out.len()]); + area += p.x * q.y - q.x * p.y; + } + let exact = PI / 2.0 * (5.1f64.powi(2) - 4.9f64.powi(2)); + assert!(close(area.abs() / 2.0, exact, exact * 1e-3), "{} {}", area.abs() / 2.0, exact); + } +} diff --git a/src-tauri/core/src/wall_bands.rs b/src-tauri/core/src/wall_bands.rs index 07d16dc2..b83f01a8 100644 --- a/src-tauri/core/src/wall_bands.rs +++ b/src-tauri/core/src/wall_bands.rs @@ -866,6 +866,7 @@ mod tests { end: Vec2::new(e.0, e.1), reference: Reference::Center, layers: Some(vec![JoinLayer { thickness: 0.1, component: Some(0), priority: 10.0 }, JoinLayer { thickness: 0.2, component: Some(1), priority: 50.0 }]), + bulge: None, }; let cuts = compute_joins(&[jw((0.0, 0.0), (4.0, 0.0)), jw((4.0, 0.0), (4.0, 3.0))]).unwrap(); let mut w = base((0.0, 0.0), (4.0, 0.0), vec![band(0.1, 10.0), band(0.2, 50.0)]); @@ -964,7 +965,7 @@ mod tests { let th = (deg as f64).to_radians(); let b0 = Vec2::new(5.0, 0.0); let b1 = Vec2::new(5.0 + 3.0 * th.cos(), 3.0 * th.sin()); - let jw = |s: Vec2, e: Vec2| JoinWall { start: s, end: e, reference: Reference::Center, layers: Some(lay.clone()) }; + let jw = |s: Vec2, e: Vec2| JoinWall { start: s, end: e, reference: Reference::Center, layers: Some(lay.clone()), bulge: None }; // Soll: Durchgangswand + Abzweig ab ihrer Fläche (y = h) bis zum freien Ende. let ub = scale(sub(b1, b0), 1.0 / 3.0); let nb = left_normal(ub); @@ -987,7 +988,7 @@ mod tests { fn schraege_l_ecke_und_kreuzung_3d_lueckenlos() { for (name, lay) in lay_sets() { let h: f64 = lay.iter().map(|l| l.thickness).sum::() / 2.0; - let jw = |s: Vec2, e: Vec2| JoinWall { start: s, end: e, reference: Reference::Center, layers: Some(lay.clone()) }; + let jw = |s: Vec2, e: Vec2| JoinWall { start: s, end: e, reference: Reference::Center, layers: Some(lay.clone()), bulge: None }; for deg in [30.0f64, 60.0, 120.0, 150.0] { // L: A (0,0)→(4,0), dann B mit Richtungswinkel `deg`. let th = deg.to_radians(); diff --git a/src-tauri/fileio/src/ifc_export.rs b/src-tauri/fileio/src/ifc_export.rs index 6b48d8d4..d0235a67 100644 --- a/src-tauri/fileio/src/ifc_export.rs +++ b/src-tauri/fileio/src/ifc_export.rs @@ -33,6 +33,10 @@ // und, bei usage = 1 und vorhandenem Typ, IfcMaterialLayerSetUsage (AXIS2, POSITIVE, `offset` = // Abstand der ersten Schicht von der Achse entlang +Y). Ohne Rahmen: Placement ohne Drehung wie bisher. // WALL_MESH = 2, structure, id, name, TYPEREF, PSETS, MESH +// WALL_ARC = 16 ([T2] Bogenwand), structure, id, name, TYPEREF, PSETS, cx, cy, r, a0, sweep, MESH +// Körper als Netz (Sehnen-Zerlegung, Öffnungen ausgespart), dazu die Achse als +// IfcTrimmedCurve auf einem IfcCircle (Welt-XY; a0/sweep im Bogenmass, sweep < 0 = +// Uhrzeigersinn → SenseAgreement .F.). // CEILING = 3, structure, id, name, TYPEREF, PSETS, PTS, n_inner, PTS × n_inner, z_rel, depth // (innere Ringe = Deckenaussparungen, IfcArbitraryProfileDefWithVoids) // OPENING = 4, wall_id, structure, opening_id, is_door (0/1), fill_name, PTS (Öffnungskörper), z_rel, @@ -126,6 +130,7 @@ pub const REC_CLASSIFICATION: f64 = 12.0; pub const REC_ZONE: f64 = 13.0; pub const REC_ATTACH: f64 = 14.0; pub const REC_OPENING_SOLID: f64 = 15.0; +pub const REC_WALL_ARC: f64 = 16.0; // ── IFC-GUID (Kompression nach IfcOpenShell `guid.compress`) ──────────────── @@ -1066,6 +1071,40 @@ impl Builder { (placement, shape) } + /// Bogenwand ([T2]): Netz-Körper wie [`Self::emit_triangulated_product`] plus Achse als + /// IfcTrimmedCurve (IfcCircle, Parameter = Winkel im Bogenmass). + fn emit_arc_wall_product(&mut self, mesh: &Mesh, (cx, cy, r, a0, sweep): (f64, f64, f64, f64, f64), relative_to: usize) -> (usize, usize) { + let (item, rep_type) = if self.v2() { self.emit_face_brep(mesh) } else { (self.emit_face_set(mesh), "Tessellation") }; + let body = self.add( + "IFCSHAPEREPRESENTATION", + format!("#{},{},{},{}", self.context, ifc_string("Body"), ifc_string(rep_type), refs(&[item])), + ); + let c = self.add("IFCCARTESIANPOINT", list(&[fmt_real(cx), fmt_real(cy)])); + let pl = self.add("IFCAXIS2PLACEMENT2D", format!("#{c},$")); + let circle = self.add("IFCCIRCLE", format!("#{pl},{}", fmt_real(r))); + let tau = std::f64::consts::TAU; + let norm = |a: f64| ((a % tau) + tau) % tau; + let (t1, t2) = (norm(a0), norm(a0 + sweep)); + let trimmed = self.add( + "IFCTRIMMEDCURVE", + format!( + "#{circle},(IFCPARAMETERVALUE({})),(IFCPARAMETERVALUE({})),{},{}", + fmt_real(t1), + fmt_real(t2), + if sweep > 0.0 { ".T." } else { ".F." }, + enum_("PARAMETER") + ), + ); + let axis_ctx = self.axis_context(); + let axis = self.add( + "IFCSHAPEREPRESENTATION", + format!("#{axis_ctx},{},{},{}", ifc_string("Axis"), ifc_string("Curve2D"), refs(&[trimmed])), + ); + let shape = self.add("IFCPRODUCTDEFINITIONSHAPE", format!("$,$,{}", refs(&[axis, body]))); + let placement = self.emit_placement(0.0, relative_to); + (placement, shape) + } + fn emit_face_set(&mut self, mesh: &Mesh) -> usize { let coords: Vec = mesh .positions @@ -1233,6 +1272,7 @@ fn rec_name(code: f64) -> &'static str { match code { c if c == REC_WALL_SOLIDS => "WALL_SOLIDS", c if c == REC_WALL_MESH => "WALL_MESH", + c if c == REC_WALL_ARC => "WALL_ARC", c if c == REC_CEILING => "CEILING", c if c == REC_OPENING => "OPENING", c if c == REC_OPENING_SOLID => "OPENING_SOLID", @@ -1571,6 +1611,21 @@ pub fn build_ifc(flat: &[f64], strings: &str) -> Result { let entity = w.finish_typed("IFCWALL", format!("wall/{id}"), &name, &ty, &psets, structure, placement, shape, None, true); w.walls.insert(id, (entity, placement, Frame::WORLD)); } + c if c == REC_WALL_ARC => { + let structure = r.structure(n_storeys)?; + let id = r.string()?; + let name = r.string()?; + let ty = r.type_ref()?; + let psets = r.psets()?; + let (cx, cy, rad, a0, sweep) = (r.f()?, r.f()?, r.f()?, r.f()?, r.f()?); + if !(rad > 0.0) || !(sweep.abs() > 1e-9) { + return Err(format!("Bogenachse ungültig bei {}", r.pos - 1)); + } + let mesh = r.mesh()?; + let (placement, shape) = w.emit_arc_wall_product(&mesh, (cx, cy, rad, a0, sweep), w.placement_of(structure)); + let entity = w.finish_typed("IFCWALL", format!("wall/{id}"), &name, &ty, &psets, structure, placement, shape, None, true); + w.walls.insert(id, (entity, placement, Frame::WORLD)); + } c if c == REC_CEILING => { let structure = r.structure(n_storeys)?; let id = r.string()?; @@ -2722,6 +2777,36 @@ mod tests { b } + /// [T2] Bogenwand: Netz-Körper plus Achse als IfcTrimmedCurve auf IfcCircle (Uhrzeigersinn = .F.). + #[test] + fn bogenwand_mit_kreisachse() { + let mut b = mini(); + b.n(&[REC_WALL_ARC, -1.0]); + b.str("WA"); + b.str("Bogen"); + b.no_type(); + b.no_psets(); + b.n(&[2.5, 0.0, 2.5, std::f64::consts::PI, -std::f64::consts::PI]); + b.mesh_tetra(); + let ifc = build(&b).unwrap(); + check_structure(&ifc); + assert_eq!(count(&ifc, "IFCWALL"), 1); + assert_eq!(count(&ifc, "IFCCIRCLE"), 1); + let t = first_line(&ifc, "IFCTRIMMEDCURVE"); + assert!(t.contains("(IFCPARAMETERVALUE(3.141593)),(IFCPARAMETERVALUE(0.0)),.F.,.PARAMETER.);"), "{t}"); + assert!(ifc.contains("'Axis','Curve2D'")); + // Ungültiger Radius: Fehler statt Panik. + let mut b = mini(); + b.n(&[REC_WALL_ARC, -1.0]); + b.str("WA"); + b.str("Bogen"); + b.no_type(); + b.no_psets(); + b.n(&[2.5, 0.0, 0.0, 0.0, 1.0]); + b.mesh_tetra(); + assert!(build(&b).is_err()); + } + #[test] fn wand_mit_achse_und_layer_set_usage() { let ifc = build(&full_house(false)).unwrap(); diff --git a/src/commands/cmds/opening.ts b/src/commands/cmds/opening.ts index 7faa6407..c8af9910 100644 --- a/src/commands/cmds/opening.ts +++ b/src/commands/cmds/opening.ts @@ -29,15 +29,15 @@ const DEF_WINDOW = { width: 1.2, height: 1.2, sill: 0.9 }; const DEF_DOOR = { width: 0.9, height: 2.1, sill: 0 }; /** Nächste Wand des Geschosses zum Klickpunkt (Kern): id, Achse und Abstand des Fusspunkts vom Anfang. */ -function pickWall(ctx: CommandContext, p: Vec2): { id: string; start: Vec2; end: Vec2; t: number } | null { - const r = createQuery<{ hit: { id: string; start: [number, number]; end: [number, number]; t: number } | null }>(ctx.project, { +function pickWall(ctx: CommandContext, p: Vec2): { id: string; start: Vec2; end: Vec2; t: number; bulge?: number } | null { + const r = createQuery<{ hit: { id: string; start: [number, number]; end: [number, number]; t: number; bulge?: number } | null }>(ctx.project, { q: "pickWall", level: ctx.level.id, pt: xy(p), }); if (!r.hit) return null; - const { id, start, end, t } = r.hit; - return { id, start: { x: start[0], y: start[1] }, end: { x: end[0], y: end[1] }, t }; + const { id, start, end, t, bulge } = r.hit; + return { id, start: { x: start[0], y: start[1] }, end: { x: end[0], y: end[1] }, t, bulge }; } /** Tab-Felder im Positionsschritt: Breite/Höhe/Brüstung (+ Winkel bei Tür). */ @@ -69,6 +69,8 @@ interface OpPos extends CommandState { wallId: string; start: Vec2; end: Vec2; + /** Bogenwand ([T2]): Bulge der Host-Wand; die Position gilt dann als Bogenlänge. */ + bulge?: number; cursor: Vec2 | null; posAlong: number; // Abstand vom Wandanfang (Meter) kind: "window" | "door"; @@ -104,6 +106,7 @@ const openingReq = (s: OpPos, pos: number | null) => ({ wall: s.wallId, start: xy(s.start), end: xy(s.end), + bulge: s.bulge ?? null, kind: s.kind, hinge: s.hinge, side: s.side, @@ -212,6 +215,7 @@ export const openingCommand: Command = { wallId: w.id, start: w.start, end: w.end, + bulge: w.bulge, cursor: pt, posAlong: w.t, kind: s.kind, diff --git a/src/commands/cmds/wall.test.ts b/src/commands/cmds/wall.test.ts index b2a78c44..07615872 100644 --- a/src/commands/cmds/wall.test.ts +++ b/src/commands/cmds/wall.test.ts @@ -84,3 +84,47 @@ describe("wallCommand — Cursor-HUD (Länge/Winkel)", () => { expect(res.draft).toBeNull(); }); }); + +describe("wallCommand — Bogen-Modus ([T2])", () => { + /** Spielt Eingaben ab und liefert das committete Projekt. */ + function run(inputs: ({ pt: Vec2 } | { opt: string } | "confirm")[]): Project { + let state = wallCommand.init(); + let p = project(); + const ctx = makeCtx(null); + for (const step of inputs) { + const [next, res] = + step === "confirm" + ? wallCommand.onConfirm(state, ctx) + : "pt" in step + ? wallCommand.onInput(state, { kind: "point", point: step.pt }, ctx) + : wallCommand.onInput(state, { kind: "option", id: step.opt }, ctx); + state = next; + if (res.commit) p = res.commit(p); + } + return p; + } + + it("Drei-Punkt-Bogen: Durchgangspunkt + Endpunkt ergeben EINE Bogenwand (Modell-Bulge)", () => { + const p = run([{ opt: "arc" }, { pt: { x: 0, y: 0 } }, { pt: { x: 2, y: 2 } }, { pt: { x: 4, y: 0 } }, "confirm"]); + expect(p.walls.length).toBe(1); + // Scheitel links der Sehne (oben) → +1 (Halbkreis). + expect(p.walls[0].bulge).toBeCloseTo(1, 9); + }); + + it("Vorschau zeigt den Bogen vor dem Endpunkt; Zurück verwirft erst den Durchgangspunkt", () => { + const ctx = makeCtx(null); + let [s] = wallCommand.onInput(wallCommand.init(), { kind: "option", id: "arc" }, ctx); + [s] = wallCommand.onInput(s, { kind: "point", point: { x: 0, y: 0 } }, ctx); + expect(wallCommand.prompt(s)).toBe("cmd.polyline.arcThrough"); + [s] = wallCommand.onInput(s, { kind: "point", point: { x: 2, y: 2 } }, ctx); + const [, res] = wallCommand.onMove(s, { x: 4, y: 0 }, null, ctx); + expect((res.draft?.preview ?? []).length).toBeGreaterThan(0); + [s] = wallCommand.onInput(s, { kind: "option", id: "undo" }, ctx); + expect(wallCommand.prompt(s)).toBe("cmd.polyline.arcThrough"); + }); + + it("ohne Bogen-Modus bleibt die Wand gerade und ohne bulge-Feld", () => { + const p = run([{ pt: { x: 0, y: 0 } }, { pt: { x: 4, y: 0 } }, "confirm"]); + expect(p.walls[0].bulge).toBeUndefined(); + }); +}); diff --git a/src/commands/cmds/wall.ts b/src/commands/cmds/wall.ts index 0f73184f..8e860a3e 100644 --- a/src/commands/cmds/wall.ts +++ b/src/commands/cmds/wall.ts @@ -4,6 +4,10 @@ // 2) „Nächster Punkt ( Zurück ):" → Punkt … (chainend: jede weitere Wand // beginnt am letzten Endpunkt) bis Esc/Enter den Zug beendet. // +// BOGEN-MODUS ([T2], Option „Bogen", wie bei der Polylinie): das nächste Segment wird eine Bogenwand +// (`Wall.bulge`). Drei-Punkt (Default: Durchgangspunkt, dann Endpunkt) oder „Tangential" (schliesst +// weich an das vorige Segment an). Die Bulges rechnet der Kern (`cmd_create.rs`/`cmd_draw.rs`). +// // Akzeptiert je Punkt Maus-Picks UND getippte Koordinaten (0,0 · r3,0 · 5<45) — // derselbe Eingabepfad wie Linie/Polylinie. Die fertige Wand rendert über die // bestehende Wand-Darstellung (generatePlan / 3D); der Draft zeigt die Achse + @@ -62,16 +66,30 @@ function isSingleLayer(ctx: CommandContext): boolean { return !!wt && wt.layers.length === 1; } -interface WallIdle extends CommandState { +/** Art eines Segments: gerade (`0`), tangential (`1`) oder Bogen durch einen Durchgangspunkt. */ +type Seg = 0 | 1 | Vec2; + +interface ArcMode { + /** Bogen-Modus (bleibt über den Befehl hinweg erhalten). */ + arc: boolean; + /** Im Bogen-Modus: tangential an den Vorgänger statt Drei-Punkt-Bogen. */ + tangent: boolean; +} + +interface WallIdle extends CommandState, ArcMode { phase: "start"; /** Sticky Dicke-Übersteuerung (nur einschichtig); null = Wandtyp-Dicke. */ thickOverride: number | null; /** Ist der aktive Wandtyp einschichtig? (aus ctx in onMove/onInput gesetzt) */ single: boolean; } -interface WallDrawing extends CommandState { +interface WallDrawing extends CommandState, ArcMode { phase: "next"; points: Vec2[]; + /** Art je Segment (s. {@link Seg}). */ + segs: Seg[]; + /** Drei-Punkt-Bogen: gesetzter Durchgangspunkt, der auf seinen Endpunkt wartet. */ + pendingThrough: Vec2 | null; cursor: Vec2 | null; /** Sticky Dicke-Übersteuerung (nur einschichtig); null = Wandtyp-Dicke. */ thickOverride: number | null; @@ -81,6 +99,8 @@ interface WallDrawing extends CommandState { type WallCmdState = WallIdle | WallDrawing; const UNDO: CmdOption = { id: "undo", labelKey: "cmd.polyline.undo" }; +const arcOption = (on: boolean): CmdOption => ({ id: "arc", labelKey: "cmd.polyline.arcOpt", value: on ? "on" : "off" }); +const tangentOption = (on: boolean): CmdOption => ({ id: "tangent", labelKey: "cmd.polyline.tangentOpt", value: on ? "on" : "off" }); /** * Bänder der schon gesetzten Segmente: sie ändern sich je Mausschritt nicht und werden nur neu gerechnet, @@ -102,7 +122,22 @@ function fixedShapes(ctx: CommandContext, points: Vec2[], thick: number | null): * (`cmd_create.rs`), dazu HUD (Länge·Winkel des lebenden Segments). Die FERTIGE Wand rendert über die * bestehende Wand-Darstellung — hier ist nur der Rubber-Band-Entwurf. */ -function wallDraft(ctx: CommandContext, points: Vec2[], cursor: Vec2 | null, thick: number | null): ToolDraft { +function wallDraft( + ctx: CommandContext, + points: Vec2[], + cursor: Vec2 | null, + thick: number | null, + arc?: ArcMode & { segs: Seg[]; pendingThrough: Vec2 | null }, +): ToolDraft { + // Bogen im Spiel: ganze Vorschau im Kern (Tangente hängt am Vorgänger), ohne Zwischenspeicher. + if (arc && (arc.arc || arc.segs.some((g) => g !== 0))) { + const all = cursor ? [...points, cursor] : points; + const req = { cmd: "wall", thick, segs: arc.segs, arc: arc.arc, tangent: arc.tangent, through: arc.pendingThrough, cursor: !!cursor }; + const draft: ToolDraft = { preview: all.length >= 2 ? createPreview(ctx, req, all).shapes : [], vertices: points }; + const last = points[points.length - 1]; + if (cursor && last && segLen(last, cursor) >= EPS) draft.hud = segmentHud(last, cursor); + return draft; + } const fixed = fixedShapes(ctx, points, thick); const live = cursor && points.length ? createPreview(ctx, { cmd: "wall", thick }, [points[points.length - 1], cursor]).shapes : []; const draft: ToolDraft = { preview: live.length ? [...fixed, ...live] : fixed, vertices: points }; @@ -115,30 +150,41 @@ function wallDraft(ctx: CommandContext, points: Vec2[], cursor: Vec2 | null, thi * Commit: je Achssegment eine Wand des aktiven Typs (Höhe aus dem Geschoss); eine gelockte Dicke * (einschichtig) wählt/erzeugt den passenden Wandtyp — beides im Kern (`cmd_create.rs`). */ -const appendWalls = (pts: Vec2[], ctx: CommandContext, thick: number | null) => - createMutation(ctx, { cmd: "wall", pts: pts.map(xy), thick }); +const appendWalls = (pts: Vec2[], ctx: CommandContext, thick: number | null, segs: Seg[] = []) => + createMutation( + ctx, + segs.some((g) => g !== 0) ? { cmd: "wall", pts: pts.map(xy), thick, segs } : { cmd: "wall", pts: pts.map(xy), thick }, + ); const idle = ( thickOverride: number | null = null, single = false, + mode: ArcMode = { arc: false, tangent: false }, ): [CommandState, CommandResult] => [ - { phase: "start", lastPoint: null, thickOverride, single } as WallIdle, + { phase: "start", lastPoint: null, thickOverride, single, arc: mode.arc, tangent: mode.tangent } as WallIdle, { draft: null, done: true }, ]; +const modeOf = (s: ArcMode): ArcMode => ({ arc: s.arc, tangent: s.tangent }); +const draftOf = (ctx: CommandContext, s: WallDrawing): ToolDraft => wallDraft(ctx, s.points, s.cursor, s.thickOverride, s); + export const wallCommand: Command = { name: "wall", labelKey: "cmd.wall.label", // Wände leben auf Geschossen — wie das Legacy-Werkzeug nur dort aktiv. floorOnly: true, - prompt: (s) => ((s as WallCmdState).phase === "next" ? "cmd.wall.next" : "cmd.wall.start"), - accepts: (s) => - (s as WallCmdState).phase === "next" ? ["point", "number", "option"] : ["point", "number"], + prompt: (s) => { + const ps = s as WallCmdState; + if (ps.phase !== "next") return "cmd.wall.start"; + return ps.arc && !ps.tangent && !ps.pendingThrough ? "cmd.polyline.arcThrough" : "cmd.wall.next"; + }, + accepts: () => ["point", "number", "option"], options: (s) => { const ps = s as WallCmdState; - return ps.phase === "next" ? [UNDO] : []; + const arc = [arcOption(!!ps.arc), ...(ps.arc ? [tangentOption(!!ps.tangent)] : [])]; + return ps.phase === "next" ? [...arc, UNDO] : arc; }, - init: (): WallIdle => ({ phase: "start", lastPoint: null, thickOverride: null, single: false }), + init: (): WallIdle => ({ phase: "start", lastPoint: null, thickOverride: null, single: false, arc: false, tangent: false }), onInput: (state, input, ctx): [CommandState, CommandResult] => { const s = state as WallCmdState; @@ -146,48 +192,87 @@ export const wallCommand: Command = { const single = isSingleLayer(ctx); if (input.kind === "option") { + // Bogen-Modus/Tangential umschalten (auch vor dem Startpunkt); verwirft einen wartenden + // Durchgangspunkt. + if (input.id === "arc" || input.id === "tangent") { + const flip = input.id === "arc" ? { arc: !s.arc } : { tangent: !s.tangent }; + if (s.phase !== "next") return [{ ...s, ...flip, single } as WallIdle, { draft: null }]; + const ns: WallDrawing = { ...s, ...flip, single, pendingThrough: null }; + return [ns, { draft: draftOf(ctx, ns) }]; + } if (s.phase !== "next") return [s, { draft: null }]; if (input.id === "undo") { + if (s.pendingThrough) { + const ns: WallDrawing = { ...s, pendingThrough: null }; + return [ns, { draft: draftOf(ctx, ns) }]; + } const pts = s.points.slice(0, -1); if (pts.length === 0) - return [{ phase: "start", lastPoint: null, thickOverride: to, single } as WallIdle, { draft: null }]; + return [{ phase: "start", lastPoint: null, thickOverride: to, single, ...modeOf(s) } as WallIdle, { draft: null }]; const ns: WallDrawing = { phase: "next", points: pts, + segs: s.segs.slice(0, Math.max(0, pts.length - 1)), + pendingThrough: null, cursor: s.cursor, lastPoint: pts[pts.length - 1], thickOverride: to, single, + ...modeOf(s), }; - return [ns, { draft: wallDraft(ctx, pts, s.cursor, to) }]; + return [ns, { draft: draftOf(ctx, ns) }]; } - return [{ ...s, single } as WallCmdState, { draft: wallDraft(ctx, s.points, s.cursor, to) }]; + return [{ ...s, single } as WallCmdState, { draft: draftOf(ctx, s) }]; } if (input.kind !== "point") { - return [{ ...s, single } as WallCmdState, { draft: s.phase === "next" ? wallDraft(ctx, s.points, s.cursor, to) : null }]; + return [{ ...s, single } as WallCmdState, { draft: s.phase === "next" ? draftOf(ctx, s) : null }]; } const pt = input.point; if (s.phase !== "next") { - const ns: WallDrawing = { phase: "next", points: [pt], cursor: pt, lastPoint: pt, thickOverride: to, single }; - return [ns, { draft: wallDraft(ctx, [pt], pt, to) }]; + const ns: WallDrawing = { + phase: "next", + points: [pt], + segs: [], + pendingThrough: null, + cursor: pt, + lastPoint: pt, + thickOverride: to, + single, + ...modeOf(s), + }; + return [ns, { draft: draftOf(ctx, ns) }]; } // Chaining: jede weitere Wand beginnt am letzten Endpunkt. Null-Strecke // (Klick auf denselben Punkt) ignorieren — nicht abbrechen. const last = s.points[s.points.length - 1]; if (segLen(last, pt) < EPS) { - return [{ ...s, single } as WallCmdState, { draft: wallDraft(ctx, s.points, s.cursor, to) }]; + return [{ ...s, single } as WallCmdState, { draft: draftOf(ctx, s) }]; } - const points = [...s.points, pt]; - const ns: WallDrawing = { phase: "next", points, cursor: pt, lastPoint: pt, thickOverride: to, single }; - return [ns, { draft: wallDraft(ctx, points, pt, to) }]; + // Drei-Punkt-Bogen: der erste Klick setzt nur den Durchgangspunkt. + if (s.arc && !s.tangent && !s.pendingThrough) { + const ns: WallDrawing = { ...s, pendingThrough: pt, cursor: pt, single }; + return [ns, { draft: draftOf(ctx, ns) }]; + } + const seg: Seg = !s.arc ? 0 : (s.pendingThrough ?? 1); + const ns: WallDrawing = { + ...s, + points: [...s.points, pt], + segs: [...s.segs, seg], + pendingThrough: null, + cursor: pt, + lastPoint: pt, + thickOverride: to, + single, + }; + return [ns, { draft: draftOf(ctx, ns) }]; }, onMove: (state, point, _snap, ctx): [CommandState, CommandResult] => { const s = state as WallCmdState; if (s.phase !== "next") return [s, { draft: null }]; const ns: WallDrawing = { ...s, cursor: point, single: isSingleLayer(ctx) }; - return [ns, { draft: wallDraft(ctx, s.points, point, s.thickOverride) }]; + return [ns, { draft: draftOf(ctx, ns) }]; }, // Enter/Space/Rechtsklick: offenen Zug beenden (≥2 Punkte) und committen. @@ -197,15 +282,15 @@ export const wallCommand: Command = { const pts = s.points; const to = s.thickOverride; return [ - { phase: "start", lastPoint: null, thickOverride: to, single: s.single } as WallIdle, - { draft: null, done: true, commit: appendWalls(pts, ctx, to) }, + { phase: "start", lastPoint: null, thickOverride: to, single: s.single, ...modeOf(s) } as WallIdle, + { draft: null, done: true, commit: appendWalls(pts, ctx, to, s.segs) }, ]; } - return idle(s.thickOverride, s.single); + return idle(s.thickOverride, s.single, modeOf(s)); }, onCancel: (state): [CommandState, CommandResult] => { const s = state as WallCmdState; - return idle(s.thickOverride, s.single); + return idle(s.thickOverride, s.single, modeOf(s)); }, // Tab-Feld-Zyklus im „next"-Schritt: Länge + Winkel relativ zum letzten Punkt. diff --git a/src/model/types.generated.ts b/src/model/types.generated.ts index 7e6dd280..f626d9e9 100644 --- a/src/model/types.generated.ts +++ b/src/model/types.generated.ts @@ -2865,6 +2865,12 @@ export type Wall = { start: Vec2; /** Achs-Endpunkt im Grundriss (Meter). */ end: Vec2; + /** + * Bogenwand ([T2]): Achse als Kreisbogen von `start` nach `end`, `bulge = tan(Öffnungswinkel/4)`; + * positiv = Scheitel links der Sehne (Modell-Konvention wie Polylinien, = −DXF-Bulge). Fehlt/0 = + * gerade Wand. + */ + bulge?: number; /** Verweis auf den (mehrschichtigen) Wandtyp. */ wallTypeId: string; /** Wandhöhe in Metern. */ diff --git a/src/state/useGripEditing.ts b/src/state/useGripEditing.ts index 94258ae8..ec283d55 100644 --- a/src/state/useGripEditing.ts +++ b/src/state/useGripEditing.ts @@ -9,7 +9,7 @@ import { useRef, useState, type RefObject } from "react"; import { add, dot, leftNormal, normalize, scale, sub, wallCorners } from "../model/geometry"; import type { Ceiling, Drawing2D, EdgeGrip, Project, Room, Stair, Vec2 } from "../model/types"; import { wallTypeThickness } from "../model/types"; -import { drawingVertices } from "../core"; +import { bulgeArcPoints, drawingVertices } from "../core"; import { gripDrawingIdsFor } from "./gripLimits"; import { openEdges, polylineEdgeGrips, ringEdges } from "../core"; import { areaMovePreview, drawingMovePreview } from "../tools/transform"; @@ -29,6 +29,12 @@ export interface GripEditFieldsState { active: boolean; } +/** Scheitel eines Bogens a→b (Modell-Bulge: Pfeilhöhe = halbe Sehne · bulge, links der Sehne). */ +function arcApex(a: Vec2, b: Vec2, bulge: number): Vec2 { + const h = Math.hypot(b.x - a.x, b.y - a.y) / 2; + return add(scale(add(a, b), 0.5), scale(normalize(leftNormal(sub(b, a))), h * bulge)); +} + export function useGripEditing(opts: { project: Project; selectedDrawing: Drawing2D | null; @@ -318,7 +324,8 @@ export function useGripEditing(opts: { if (modelEditable && effectiveDrawingIds.length === 0) { for (const id of selectedWallIds) { const w = project.walls.find((x) => x.id === id); - if (w) pushGroup([w.start, w.end], { wallId: id }); + // Bogenwand ([T2]): dritter Griff im Bogenscheitel (zieht den Bogen durch den Punkt). + if (w) pushGroup(w.bulge ? [w.start, w.end, arcApex(w.start, w.end, w.bulge)] : [w.start, w.end], { wallId: id }); } } return out; @@ -941,6 +948,8 @@ export function useGripEditing(opts: { const th = wt ? wallTypeThickness(wt) : 0.2; const a = pw.localIndex === 0 ? pw.pt : w.start; const b = pw.localIndex === 0 ? w.end : pw.pt; + // Bogenwand: der Bogen behält seinen Öffnungswinkel (Bulge), Vorschau als Achse. + if (w.bulge) return [{ kind: "poly", pts: bulgeArcPoints(a, b, w.bulge), closed: false }]; return [ { kind: "poly", pts: wallCorners(a, b, th), closed: true }, { kind: "line", a, b }, From b7c2b3e548384ef534e8efcab6380a57552566b5 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 30 Oct 2026 04:25:26 +0000 Subject: [PATCH 2/2] =?UTF-8?q?[T2]=20Bogenw=C3=A4nde:=20Schnitt=20ein=20B?= =?UTF-8?q?and=20je=20Schicht=20=C3=BCber=20Stossfugen,=20keine=20Facetten?= =?UTF-8?q?-Kanten=20in=20Schnitt/Ansicht,=20Schichteinzug=20und=203D-Ansi?= =?UTF-8?q?chtsschraffur=20in=20Bogenw=C3=A4nden=20vorerst=20aus,=20TODO?= =?UTF-8?q?=20nachgef=C3=BChrt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 8 +- src-tauri/core/src/opening_detail.rs | 4 + src-tauri/core/src/plan/elevation.rs | 2 +- src-tauri/core/src/plan/section.rs | 113 ++++++++++++++++++++++++ src-tauri/core/src/plan/walls.rs | 2 +- src-tauri/core/src/surface_pattern3d.rs | 4 + 6 files changed, 127 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index b42c6a1d..58ea9bb9 100644 --- a/TODO.md +++ b/TODO.md @@ -1296,16 +1296,16 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]). Bogenlänge auf der Achse; Lücke radial durch alle Schichten, Plansymbol gebogen; Einbauteile (3D, Schnitt, Ansicht, IFC-Füllung) gerade auf der Sehne zwischen den Laibungen (Entscheid). **3D/Schnitt/Ansicht/OBJ**: Sehnen-Teilwände mit radialen Gehrungen (`chord_walls`, Teilstellen auch an den Laibungen, Teilwände in der - Öffnung = Brüstung/Sturz); Ansicht ohne Facetten-Fugen (Ecken auf der Gehrung, innere Stirnflächen - entfallen). **Mengen** exakt (Bogenlänge, Ringsektor; IFC Qto, Objekt-Info, Bauteilliste). **IFC**: Datensatz + Öffnung = Brüstung/Sturz); Ansicht und Schnitt ohne Facetten-Fugen (Ecken auf der Gehrung, innere + Stirnflächen/Stosskanten entfallen, Umriss bleibt); Schnitt quer durch eine Stossfuge = ein Band je Schicht. **Mengen** exakt (Bogenlänge, Ringsektor; IFC Qto, Objekt-Info, Bauteilliste). **IFC**: Datensatz `WALL_ARC` — Körper als Netz, Achse `IfcTrimmedCurve` auf `IfcCircle` (`validate-ifc.py` ohne Befund). **Befehle**: Wand-Option „Bogen" (Drei-Punkt/Tangential wie Polylinie), Scheitel-Griff, Spiegeln kehrt den Bulge, Öffnung am Bogen platzieren; Fang, Raum-Erkennung, Schatten, Baurecht, Flächen über den Sehnenzug. Tests: Rust (Verschneidung, Ringsektor-Volumen/dicht, Grundriss im Kreisring, Ansicht ohne Fugen, IFC, Befehle), vitest (Wand-Befehl). Geprüft im Linux-Container (CLI-SVG Grundriss/Schnitt/Ansicht, IFC), nicht in - der Tauri-App. Offen: Schichteinzug [106] und Formöffnungen [G3] in Bogenwänden; Wände teilen/trimmen (fehlt + der Tauri-App. Offen: Schichteinzug [106], Formöffnungen [G3] und Ansichtsschraffur im 3D ([100]) in Bogenwänden; Wände teilen/trimmen (fehlt auch für gerade); echte Polar-Schraffur; IFC-Körper als extrudiertes Bogenprofil statt Netz; Griff-Vorschau - zeigt nur die Achse. + zeigt nur die Achse; automatische Aussenbemassung misst Bogenwände als Sehne. - ○ **[T3] Wendeltreppe/Wendelfläche** + Handlauf-Sweep. · M - ○ **[T4] Import-Meshes glätten oder kantig** (`add_smooth_normals`). · S - ○ **[T5] Import reparieren** (`put_together_same_attrs`, Healing). · S diff --git a/src-tauri/core/src/opening_detail.rs b/src-tauri/core/src/opening_detail.rs index f5d3111f..a3c6ec97 100644 --- a/src-tauri/core/src/opening_detail.rs +++ b/src-tauri/core/src/opening_detail.rs @@ -376,6 +376,10 @@ pub const SIDES: [Side; 4] = [Side::Left, Side::Right, Side::Top, Side::Bottom]; /// `None`: keine Regeln, kein Wandtyp oder Öffnung ausserhalb der Wand. pub fn opening_reveal(p: &Project, w: &Wall, o: &Opening) -> Option { + // Bogenwände ([T2]): Schichteinzug noch nicht (Laibungen radial, Schichten bündig). + if crate::wall_arc::is_arc_bulge(w.bulge) { + return None; + } let rules = reveal_rules(p, o); if rules.is_empty() { return None; diff --git a/src-tauri/core/src/plan/elevation.rs b/src-tauri/core/src/plan/elevation.rs index 0e071541..4882aff4 100644 --- a/src-tauri/core/src/plan/elevation.rs +++ b/src-tauri/core/src/plan/elevation.rs @@ -148,7 +148,7 @@ fn project_faces(frame: &[f64; 9], walls: &[RWall], slabs: &[RSlab], roofs: &[Ro /// Verschiebung der vier Wandecken längs der Achse bis auf die Schnittlinien (Anfang +n, Anfang −n, /// Ende +n, Ende −n; +n = rechte Normale wie in `plan_elevation::wall_faces`). -fn corner_shifts(x: &RWall) -> [f64; 4] { +pub(crate) fn corner_shifts(x: &RWall) -> [f64; 4] { let (dx, dy) = (x.end[0] - x.start[0], x.end[1] - x.start[1]); let l = hypot2(dx, dy); if l < 1e-9 { diff --git a/src-tauri/core/src/plan/section.rs b/src-tauri/core/src/plan/section.rs index 8a2847c0..8bf059af 100644 --- a/src-tauri/core/src/plan/section.rs +++ b/src-tauri/core/src/plan/section.rs @@ -372,6 +372,86 @@ fn opening_interval(w: &Wall, o: &Opening) -> Option<(f64, f64)> { } +/// Senkrechte Kanten eines Bogen-Teilkörpers, die an einer inneren Stossfuge liegen (Ecken auf der +/// Gehrung, in Schnitt-u projiziert), entfallen. +fn drop_arc_seams(visible: Vec, hidden: Vec, walls_r: &[RWall], base: (f64, f64), u: (f64, f64)) -> (Vec, Vec) { + let ul = hypot2(u.0, u.1); + if !walls_r.iter().any(|r| r.joint != [false; 2]) || !(ul > 1e-12) { + return (visible, hidden); + } + let u = (u.0 / ul, u.1 / ul); + let seams: HashMap> = walls_r + .iter() + .enumerate() + .filter(|(_, r)| r.joint != [false; 2]) + .map(|(i, r)| { + let (dx, dy) = (r.end[0] - r.start[0], r.end[1] - r.start[1]); + let l = hypot2(dx, dy).max(1e-12); + let (ax, ay) = (dx / l, dy / l); + let (nx, ny) = (ay, -ax); + let ht = r.thickness / 2.0; + let sh = super::elevation::corner_shifts(r); + let mut us = Vec::new(); + for (k, (p, t, s)) in [(r.start, ht, sh[0]), (r.start, -ht, sh[1]), (r.end, ht, sh[2]), (r.end, -ht, sh[3])].into_iter().enumerate() { + if !r.joint[k / 2] { + continue; + } + let (x, y) = (p[0] + nx * t + ax * s, p[1] + ny * t + ay * s); + us.push((x - base.0) * u.0 + (y - base.1) * u.1); + } + (i, us) + }) + .collect(); + // Umriss (Silhouette) bleibt: senkrechte Kanten am äussersten u der ganzen Wand. + let vertical = |e: &Edge| e.kind == Kind::Wall && (e.a[0] - e.b[0]).abs() < 1e-4 && seams.contains_key(&e.index); + let mut extent: HashMap<&str, (f64, f64)> = HashMap::new(); + for e in visible.iter().chain(&hidden).filter(|e| vertical(e)) { + let Some(r) = walls_r.get(e.index) else { continue }; + let x = extent.entry(r.wall_id.as_str()).or_insert((f64::INFINITY, f64::NEG_INFINITY)); + *x = (x.0.min(e.a[0]), x.1.max(e.a[0])); + } + let keep = |e: &Edge| { + if !vertical(e) { + return true; + } + let silhouette = walls_r.get(e.index).and_then(|r| extent.get(r.wall_id.as_str())).is_some_and(|x| (e.a[0] - x.0).abs() < 1e-3 || (e.a[0] - x.1).abs() < 1e-3); + silhouette || !seams.get(&e.index).is_some_and(|us| us.iter().any(|x| (x - e.a[0]).abs() < 1e-2)) + }; + (visible.into_iter().filter(keep).collect(), hidden.into_iter().filter(keep).collect()) +} + +/// [T2] Schnitt durch eine Bogenwand: quert die Ebene eine innere Stossfuge der Sehnen-Teilkörper, +/// liegt der Querschnitt in zwei Rechtecken nebeneinander — zu EINEM zusammenfassen, damit die +/// Schichtaufteilung (anteilig über die ganze Dicke) stimmt. +fn merge_arc_wall_cuts(cuts: Vec, p: &Project, walls_r: &[RWall]) -> Vec { + let arc_ids: HashSet<&str> = p.walls.iter().filter(|w| crate::wall_arc::WallArc::of_wall(w).is_some()).map(|w| w.id.as_str()).collect(); + if arc_ids.is_empty() { + return cuts; + } + let owner = |c: &Cut| -> Option<&str> { (c.kind == Kind::Wall).then(|| walls_r.get(c.index).map(|w| w.wall_id.as_str())).flatten().filter(|id| arc_ids.contains(id)) }; + let (mut arc, mut out): (Vec, Vec) = cuts.into_iter().partition(|c| owner(c).is_some() && c.pts.len() >= 3); + arc.sort_by(|a, b| { + let (ba, bb) = (bbox(&a.pts), bbox(&b.pts)); + owner(a).cmp(&owner(b)).then(cmp_num(ba[2] - bb[2])).then(cmp_num(ba[0] - bb[0])) + }); + let mut merged: Vec = Vec::new(); + for c in arc { + let b = bbox(&c.pts); + if let Some(last) = merged.last_mut() { + let lb = bbox(&last.pts); + let same = owner(last) == owner(&c) && (lb[2] - b[2]).abs() < 1e-6 && (lb[3] - b[3]).abs() < 1e-6; + if same && b[0] <= lb[1] + 1e-3 && b[1] >= lb[0] - 1e-3 { + let (u0, u1) = (lb[0].min(b[0]), lb[1].max(b[1])); + last.pts = vec![[u0, lb[3]], [u1, lb[3]], [u1, lb[2]], [u0, lb[2]]]; + continue; + } + } + merged.push(c); + } + out.extend(merged); + out +} + /// Je emittiertem Wand-Teilquader die Quellwand (über `RWall::wall_id`). fn wall_owners<'a>(p: &'a Project, walls: &[RWall]) -> Vec> { let mut by_id: HashMap<&str, &Wall> = HashMap::with_capacity(p.walls.len()); @@ -1280,8 +1360,11 @@ pub fn compute_section(p: &Project, level: &LevelSpec, bodies: &[BodyMesh]) -> R let not_cut = |e: &&render3d::SectionEdge| !cut_owners.contains(&(kind_of(e.component.kind), e.component.index)); let visible: Vec = raw.visible_edges.iter().filter(not_cut).map(&mut edge).collect(); let hidden: Vec = raw.hidden_edges.iter().filter(not_cut).map(&mut edge).collect(); + // [T2] Bogenwände: senkrechte Kanten an den inneren Stossfugen der Sehnen-Teilkörper nicht zeigen. + let (visible, hidden) = drop_arc_seams(visible, hidden, &walls_r, plane.base(), plane.u_model()); shaped_wall_cuts(&mut cuts, p, &walls_r, plane.base(), plane.u_model()); + let mut cuts = merge_arc_wall_cuts(cuts, p, &walls_r); append_roof_sections(&mut cuts, p, &plane); let owners = wall_owners(p, &walls_r); // Bogenwand ([T2]): Schichtfolge quer zum Schnitt aus der Richtung des Sehnen-Teilkörpers. @@ -2070,6 +2153,36 @@ mod tests { assert!(df.len() >= 4, "Rahmen beidseits, Glas, Eindeckrahmen: {}", df.len()); } + /// [T2] Schräger Schnitt durch eine Bogenwand: je Durchstoss genau ein Band je Schicht (auch wenn die + /// Ebene eine Stossfuge der Sehnen-Teilkörper quert), Schichtfolge vollständig. + #[test] + fn bogenwand_im_schnitt_je_schicht_ein_band() { + let mut p = sample(); + p.walls.retain(|w| w.id == "W1"); + p.openings = Some(vec![]); + p.ceilings = Some(vec![]); + p.roofs = Some(vec![]); + p.stairs = Some(vec![]); + p.walls[0].bulge = Some(-1.0); // Halbkreis nach Süden, Mitte (2.5, 0), r 2.5 + for l in p.drawing_levels.iter_mut().filter(|l| l.id == "schnitt-a") { + l.line_points = Some([Vec2 { x: -1.0, y: -1.5 }, Vec2 { x: 6.0, y: -1.5 }]); + } + let out = compute_section(&p, &level(&p, "schnitt-a"), &[]).unwrap().unwrap(); + let walls: Vec<&Cut> = out.cuts.iter().filter(|c| c.kind == Kind::Wall).collect(); + assert_eq!(walls.len(), 8, "2 Durchstösse × 4 Schichten: {:#?}", walls.iter().map(|c| (bbox(&c.pts), c.component_id.clone())).collect::>()); + let mut us: Vec<[f64; 4]> = walls.iter().map(|c| bbox(&c.pts)).collect(); + us.sort_by(|a, b| cmp_num(a[0] - b[0])); + // Lückenlos je Durchstoss. + for k in [0usize, 4] { + for i in k..k + 3 { + assert!((us[i][1] - us[i + 1][0]).abs() < 1e-6, "{us:?}"); + } + } + // Hinter der Ebene keine Facetten-Fugen der Sehnen-Teilkörper (nur Umriss). + let seams = out.visible.iter().chain(&out.hidden).filter(|e| e.kind == Kind::Wall && (e.a[0] - e.b[0]).abs() < 1e-4).count(); + assert!(seams <= 4, "senkrechte Kanten: {seams}"); + } + #[test] fn beschnittene_baender_behalten_ihre_ebene() { // Von der Dominanz beschnittene Wand-/Deckenstücke tragen ihre Kategorie weiter: Ebene aus → weg. diff --git a/src-tauri/core/src/plan/walls.rs b/src-tauri/core/src/plan/walls.rs index 0749542c..ac49968e 100644 --- a/src-tauri/core/src/plan/walls.rs +++ b/src-tauri/core/src/plan/walls.rs @@ -647,7 +647,7 @@ pub fn plan_walls(c: &Ctx, reference_lines: bool, out: &mut Vec, boun let cut = cut_by_id.get(w.id.as_str()).copied().unwrap_or(&empty); let (zb, zt) = p.wall_vertical_extent(w); let view_only = zt < cut_z || zb > cut_z; - let reveals = crate::opening_detail::plan_reveal_block(p, wv, &openings); + let reveals = crate::opening_detail::plan_reveal_block(p, w, &openings); let (unroll, cut_u) = match &arc_wall { Some((arc, _)) => { let total = p.wall_thickness(w, 0.2); diff --git a/src-tauri/core/src/surface_pattern3d.rs b/src-tauri/core/src/surface_pattern3d.rs index 8dc9bf7c..066dcede 100644 --- a/src-tauri/core/src/surface_pattern3d.rs +++ b/src-tauri/core/src/surface_pattern3d.rs @@ -158,6 +158,10 @@ fn newell(poly: &[[f64; 3]]) -> [f64; 3] { /// Beide Wandseiten: rechts der Achse die äusserste Schicht (`layers[0]`), links die innerste — wie /// die Ansicht. Wand-Koordinaten: x ab Wandanfang, y ab UK; Öffnungen ausgespart. fn wall_lines(p: &Project, w: &Wall, s: &mut Sink) { + // Bogenwände ([T2]): Ansichtsschraffur im 3D noch nicht (Fläche gekrümmt). + if crate::wall_arc::is_arc_bulge(w.bulge) { + return; + } let (dx, dy) = (w.end.x - w.start.x, w.end.y - w.start.y); let len = crate::jsmath::hypot2(dx, dy); if !(len > 1e-6) || !len.is_finite() {