diff --git a/TODO.md b/TODO.md index 9a132323..28d583cf 100644 --- a/TODO.md +++ b/TODO.md @@ -178,8 +178,13 @@ Wer zu einer ID mehr wissen will (Entscheide, Tests, Bilder), sucht dort nach `* - ◐ **[T1]** Polyeder-Körper (`trucksolid::polyhedron`). Mehrteilige Netze und Hohlräume als mehrere Shells; Entscheid zu import-Netzen im STEP-Export (`solid_specs.rs`) offen; Komplanarität streng, f32-Importe ergeben mehr Flächen. · M -- ◐ **[T2]** Bogenwände. Teilen/Trimmen/Verrunden/Fasen/Verketten an Bogenwänden mit [113] (10.11.); offen: - Bogenmass-Griffe verschieben Punkte frei statt auf dem Kreis. · M +- ◐ **[T2]** Bogenwände. Teilen/Trimmen/Verrunden/Fasen/Verketten an Bogenwänden mit [113] (10.11.). Griffe (10.11.): + Start/Ende einer Bogenwand laufen auf dem Kreis (Mittelpunkt/Radius fest, anderes Ende fest, Bulge nachgeführt; + Kern `grip_drag::arc_wall_endpoint`), Tab = Bogenlänge ab dem festen Ende (nur Längenfeld, `arc_wall_point_at_length`); + Randpunkte von Radius-/Durchmesser-/Bogenmassen bleiben auf dem Kreis um den Mittelpunkt (`grips.rs`). Öffnungen in + Bogenwänden liefen schon über Bogenlänge ([144]). Geprüft: Rust-Tests; nicht in der App angesehen. Offen: Radius-Griff + mit festem Mittelpunkt (Option; der Scheitel-Griff ändert den Radius bei festen Endpunkten), Bogenlänge > Halbkreis + per Tab (nächstliegender Bogen gewinnt). · M - ◐ **[T3]** Wendeltreppe. Kein Handlauf-Profil im Modell (rund fest). · S - ◐ **[T4]** Import-Meshes glätten oder kantig. Metal-Pfad nicht gebaut/gesehen. · S - ◐ **[T6]** Glattes Gelände aus Höhenlinien (`terrain.rs`). Natural-Neighbour/Clough-Tocher statt Hermite-Teilung; diff --git a/src-tauri/core/src/grip_drag.rs b/src-tauri/core/src/grip_drag.rs index 74da9846..e84dd5bc 100644 --- a/src-tauri/core/src/grip_drag.rs +++ b/src-tauri/core/src/grip_drag.rs @@ -220,6 +220,75 @@ pub fn opening_wall_grip(ws: P, we: P, bulge: f64, position: f64, width: f64) -> add(ws, scale(normalize(sub(we, ws)), position + width / 2.0)) } +/// [T2] Endpunkt einer Bogenwand entlang des Kreises ziehen: Mittelpunkt und Achsradius bleiben, das +/// andere Ende bleibt stehen. `index` 0 = Start, 1 = Ende; `target` wird auf den Kreis projiziert, der +/// Öffnungswinkel zwischen den zwei möglichen Bögen so gewählt, dass er dem bisherigen am nächsten +/// liegt (stetig beim Ziehen). Ergebnis `(neuer Start, neues Ende, neuer Bulge)`; `None` bei Unsinn, +/// Ziel im Mittelpunkt oder ohne Bogen. +pub fn arc_wall_endpoint(s: P, e: P, bulge: f64, index: usize, target: P) -> Option<(P, P, f64)> { + let a = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(s.0, s.1), kernel2d::Vec2::new(e.0, e.1), Some(bulge))?; + let (c, r) = ((a.center.x, a.center.y), a.r); + let th = arc_angle_of(c, target)?; + let (a1, tau) = (a.a0 + a.sweep, 2.0 * PI); + // Fester Winkel F und Richtung: Start bewegt → Sweep läuft von th nach a1; Ende bewegt → von a0 nach th. + let sweep = if index == 0 { nearest_sweep(a1 - th, a.sweep, tau) } else { nearest_sweep(th - a.a0, a.sweep, tau) }; + if sweep.abs() < 1e-6 || sweep.abs() > tau - 1e-6 { + return None; + } + let at = |ang: f64| (c.0 + r * jsnum::cos(ang), c.1 + r * jsnum::sin(ang)); + let (ns, ne) = if index == 0 { (at(th), e) } else { (s, at(th)) }; + let nb = -jsnum::tan(sweep / 4.0); + (nb.is_finite()).then_some((ns, ne, nb)) +} + +fn arc_angle_of(c: P, p: P) -> Option { + let (dx, dy) = (p.0 - c.0, p.1 - c.1); + (dx.is_finite() && dy.is_finite() && hypot2(dx, dy) > 1e-9).then(|| jsnum::atan2(dy, dx)) +} + +/// Von den zwei Bögen mit Winkel `d` (mod 2π) — `d` in (0, 2π) CCW bzw. `d − 2π` CW — der dem `old` nächste. +fn nearest_sweep(d: f64, old: f64, tau: f64) -> f64 { + let m = ((d % tau) + tau) % tau; + let (ccw, cw) = (m, m - tau); + if (ccw - old).abs() <= (cw - old).abs() { ccw } else { cw } +} + +/// [T2] Zielpunkt eines Endpunkt-Griffs der Bogenwand samt Bogenlänge der Wand danach: mit `length` (Tab) +/// der Punkt dieser Bogenlänge vom festen Ende ([`arc_wall_point_at_length`]), sonst der auf den Kreis +/// projizierte Cursor `raw`. `None` bei Unsinn. +pub fn arc_wall_grip_target(s: P, e: P, bulge: f64, index: usize, length: Option, raw: P) -> Option<(P, f64)> { + let p = match length { + Some(l) => arc_wall_point_at_length(s, e, bulge, index, l, raw)?, + None => raw, + }; + let (ns, ne, nb) = arc_wall_endpoint(s, e, bulge, index, p)?; + let a = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(ns.0, ns.1), kernel2d::Vec2::new(ne.0, ne.1), Some(nb))?; + Some((if index == 0 { ns } else { ne }, a.length())) +} + +/// [T2] Bogenlängen-Eingabe (Tab) am Endpunkt einer Bogenwand: der Punkt, der `length` (Bogenlänge, +/// Meter) vom festen Ende entfernt auf dem Kreis liegt, auf der Seite des Cursors `raw` (am Fixpunkt: +/// Laufrichtung des bisherigen Bogens). `None` bei Unsinn oder `length` ≤ 0 bzw. ≥ Vollkreis. +pub fn arc_wall_point_at_length(s: P, e: P, bulge: f64, index: usize, length: f64, raw: P) -> Option

{ + let a = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(s.0, s.1), kernel2d::Vec2::new(e.0, e.1), Some(bulge))?; + let (c, r) = ((a.center.x, a.center.y), a.r); + let tau = 2.0 * PI; + if !(length.is_finite() && length > 0.0 && length / r < tau - 1e-6) { + return None; + } + let (fixed_angle, run_dir) = if index == 0 { (a.a0 + a.sweep, -a.sigma()) } else { (a.a0, a.sigma()) }; + let side = match arc_angle_of(c, raw) { + Some(t) => { + let mut d = (t - fixed_angle) % tau; + if d > PI { d -= tau } else if d <= -PI { d += tau } + if d.abs() < 1e-9 { run_dir } else { d.signum() } + } + None => run_dir, + }; + let ang = fixed_angle + side * length / r; + Some((c.0 + r * jsnum::cos(ang), c.1 + r * jsnum::sin(ang))) +} + /// Öffnung im Schnitt-Blatt waagrecht ziehen: Blatt-Delta `du` (gesamt, entlang der Schnitt-Achse `u_axis`) /// → neue `position` (geklemmt) und das dazu passende, tatsächlich wirksame Blatt-Delta. `None`, wenn die /// Wand fast quer zur Schnittlinie steht (|u · Wandrichtung| < 0.15). Bogenwand ([144], `bulge`): @@ -593,6 +662,59 @@ mod tests { assert_eq!(opening_slide_sheet(s, e, 1.0, (1.0, 0.0), p0, 100.0, 1.0), None); } + /// [T2] Endpunkt einer Bogenwand folgt dem Kreis (Mittelpunkt/Radius bleiben), Bogenlänge per Eingabe. + #[test] + fn bogenwand_endpunkt_auf_dem_kreis() { + // Halbkreis über (0,0)–(4,0), bulge 1: Mitte (2,0), r = 2, Scheitel (2,2). + let (s, e) = ((0.0, 0.0), (4.0, 0.0)); + let (ns, ne, nb) = arc_wall_endpoint(s, e, 1.0, 1, (2.0, 5.0)).unwrap(); + assert!(close(ns, s) && close(ne, (2.0, 2.0)), "{ne:?}"); + // Viertelkreis (Scheitel links der Sehne = Uhrzeigersinn): tan(π/8). + assert!((nb - (std::f64::consts::FRAC_PI_8).tan()).abs() < 1e-9, "{nb}"); + let a = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(ns.0, ns.1), kernel2d::Vec2::new(ne.0, ne.1), Some(nb)).unwrap(); + assert!((a.center.x - 2.0).abs() < 1e-9 && a.center.y.abs() < 1e-9 && (a.r - 2.0).abs() < 1e-9); + // Start bewegt: Ende bleibt, Kreis bleibt. + let (ns, ne, nb) = arc_wall_endpoint(s, e, 1.0, 0, (2.0, 9.0)).unwrap(); + assert!(close(ne, e) && close(ns, (2.0, 2.0)), "{ns:?}"); + let a = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(ns.0, ns.1), kernel2d::Vec2::new(ne.0, ne.1), Some(nb)).unwrap(); + assert!((a.center.x - 2.0).abs() < 1e-9 && (a.r - 2.0).abs() < 1e-9); + // Unsinn: Mittelpunkt, NaN, Fixpunkt (Sweep 0). + assert!(arc_wall_endpoint(s, e, 1.0, 1, (2.0, 0.0)).is_none()); + assert!(arc_wall_endpoint(s, e, 1.0, 1, (f64::NAN, 0.0)).is_none()); + assert!(arc_wall_endpoint(s, e, 1.0, 1, (-2.0, 0.0)).is_none()); + assert!(arc_wall_endpoint(s, e, 0.0, 1, (1.0, 1.0)).is_none()); + } + + #[test] + fn bogenwand_bogenlaenge_eingabe() { + let (s, e) = ((0.0, 0.0), (4.0, 0.0)); + // Ende: Bogenlänge π (Viertelkreis r = 2) ab dem Start, Cursor oben rechts → Scheitel (2, 2). + let p = arc_wall_point_at_length(s, e, 1.0, 1, std::f64::consts::PI, (3.0, 3.0)).unwrap(); + assert!(close(p, (2.0, 2.0)), "{p:?}"); + // Nach dem Anwenden hat die Wand genau diese Bogenlänge. + let (ns, ne, nb) = arc_wall_endpoint(s, e, 1.0, 1, p).unwrap(); + let a = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(ns.0, ns.1), kernel2d::Vec2::new(ne.0, ne.1), Some(nb)).unwrap(); + assert!((a.length() - std::f64::consts::PI).abs() < 1e-9); + // Start bewegt: Länge 1 vom Ende aus. + let p = arc_wall_point_at_length(s, e, 1.0, 0, 1.0, (1.0, 1.0)).unwrap(); + assert!(((p.0 - 2.0).hypot(p.1) - 2.0).abs() < 1e-9 && p.1 > 0.0); + let (ns, ne, nb) = arc_wall_endpoint(s, e, 1.0, 0, p).unwrap(); + let a = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(ns.0, ns.1), kernel2d::Vec2::new(ne.0, ne.1), Some(nb)).unwrap(); + assert!((a.length() - 1.0).abs() < 1e-9, "{}", a.length()); + assert!(arc_wall_point_at_length(s, e, 1.0, 1, -1.0, (0.0, 0.0)).is_none()); + assert!(arc_wall_point_at_length(s, e, 1.0, 1, 100.0, (0.0, 0.0)).is_none()); + } + + #[test] + fn bogenwand_griff_ziel() { + let (s, e) = ((0.0, 0.0), (4.0, 0.0)); + let (p, l) = arc_wall_grip_target(s, e, 1.0, 1, Some(std::f64::consts::PI), (3.0, 3.0)).unwrap(); + assert!(close(p, (2.0, 2.0)) && (l - std::f64::consts::PI).abs() < 1e-9); + let (p, l) = arc_wall_grip_target(s, e, 1.0, 1, None, (2.0, 7.0)).unwrap(); + assert!(close(p, (2.0, 2.0)) && (l - std::f64::consts::PI).abs() < 1e-9); + assert!(arc_wall_grip_target(s, e, 1.0, 1, Some(f64::NAN), (2.0, 7.0)).is_none()); + } + #[test] fn treppe_wand_baugrube() { assert!(close(stair_handle(false, None, (1.0, 1.0), (0.0, 2.0), 4.0), (1.0, 3.0))); diff --git a/src-tauri/core/src/grips.rs b/src-tauri/core/src/grips.rs index e380943e..42731749 100644 --- a/src-tauri/core/src/grips.rs +++ b/src-tauri/core/src/grips.rs @@ -405,6 +405,17 @@ fn wall_grip(w: &Value, index: f64, x: f64, y: f64) -> Value { 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)))]); } + // Endpunkt einer Bogenwand ([T2]): der Punkt folgt dem Kreis (Mittelpunkt und Radius bleiben, das + // andere Ende steht), der Bulge passt sich an. + if index == 0.0 || index == 1.0 { + let (s, e) = (xy(field(w, "start").unwrap_or(&Value::Null)), xy(field(w, "end").unwrap_or(&Value::Null))); + if let Some(b) = field(w, "bulge").and_then(Value::as_f64).filter(|b| crate::wall_arc::is_arc_bulge(Some(*b))) { + return match crate::grip_drag::arc_wall_endpoint(s, e, b, index as usize, (x, y)) { + Some((ns, ne, nb)) => with_all(w, vec![("start", pt(ns.0, ns.1)), ("end", pt(ne.0, ne.1)), ("bulge", js_num(nb))]), + None => w.clone(), + }; + } + } with(w, if index == 0.0 { "start" } else { "end" }, pt(x, y)) } @@ -521,6 +532,20 @@ fn drawing_grip(d: &Value, index: f64, x: f64, y: f64, scale: f64) -> Option { let pts = arr(field(g, "pts")); let n = pts.len(); + // Radius-/Durchmesser-/Bogenlängen-Mass ([T2]): Randpunkte bleiben auf dem Kreis um den Mittelpunkt + // (Radius = bisheriger Abstand des ersten Randpunkts), nur die Lage auf dem Kreis ändert sich. + let round = matches!(field(g, "kind").and_then(Value::as_str), Some("radius" | "diameter" | "arc")) && n >= 2; + if round && index >= 1.0 && index < n as f64 { + let (c, rim) = (xy(&pts[0]), xy(&pts[1])); + let r = hypot2(rim.0 - c.0, rim.1 - c.1); + let l = hypot2(x - c.0, y - c.1); + if !(l > 1e-9 && r.is_finite()) { + return None; + } + let q = pt(c.0 + (x - c.0) * r / l, c.1 + (y - c.1) * r / l); + let ng = with(g, "pts", replace_at(pts, index, &q)); + return Some(with_geom(d, crate::dim_assoc::without_ref(&ng, index_in(index, n)))); + } if index < n as f64 { // Von Hand gezogener Punkt ist frei ([38]). let ng = with(g, "pts", replace_at(pts, index, &p)); @@ -1328,12 +1353,32 @@ mod tests { 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}"); + // Endpunkt-Griff: entlang des Kreises (Mittelpunkt/Radius bleiben), nicht frei. 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 e = res.ops[0].to_json()["entity"].clone(); + let (s, en) = (xy(&e["start"]), xy(&e["end"])); + let a = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(s.0, s.1), kernel2d::Vec2::new(en.0, en.1), e["bulge"].as_f64()).unwrap(); + let a0 = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(0.0, 0.0), kernel2d::Vec2::new(4.0, 0.0), Some(0.5)).unwrap(); + assert!(s == (0.0, 0.0) && (a.center.x - a0.center.x).abs() < 1e-9 && (a.center.y - a0.center.y).abs() < 1e-9 && (a.r - a0.r).abs() < 1e-9, "{e}"); + assert!((en.0 - a0.center.x).hypot(en.1 - a0.center.y) - a0.r < 1e-9); 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()); } + /// [T2] Bogenlängen-/Radiusmass: Randpunkte-Griffe bleiben auf dem Kreis um den Mittelpunkt. + #[test] + fn bogenmass_griff_auf_dem_kreis() { + let d = json!({"id": "d", "level": "L", "geom": {"shape": "dimension", "kind": "arc", "pts": [{"x": 0, "y": 0}, {"x": 2, "y": 0}, {"x": 0, "y": 2}], "offset": 0.5}}); + let r = root(json!({"drawings2d": [d]})); + let res = run(&Lookup::plain(&r), &rq(json!({"op": "moveGrip", "drawingId": "d", "index": 2, "pt": [-6, 0], "scale": 100}))).unwrap(); + let p = &res.ops[0].to_json()["entity"]["geom"]["pts"][2]; + assert!((p["x"].as_f64().unwrap() + 2.0).abs() < 1e-9 && p["y"].as_f64().unwrap().abs() < 1e-9, "{p}"); + // Mittelpunkt bleibt frei. + let res = run(&Lookup::plain(&r), &rq(json!({"op": "moveGrip", "drawingId": "d", "index": 0, "pt": [1, 1], "scale": 100}))).unwrap(); + let p = &res.ops[0].to_json()["entity"]["geom"]["pts"][0]; + assert_eq!((p["x"].as_f64(), p["y"].as_f64()), (Some(1.0), Some(1.0))); + } + /// [68] Baugrube: Ecke, Kante und Sohlen-Griff (Index hinter der letzten Ecke). #[test] fn baugrube_griffe() { diff --git a/src-tauri/core/src/web/grip_drag.rs b/src-tauri/core/src/web/grip_drag.rs index 91561c5b..018f256a 100644 --- a/src-tauri/core/src/web/grip_drag.rs +++ b/src-tauri/core/src/web/grip_drag.rs @@ -35,6 +35,18 @@ pub fn grip_polar_point(ax: f64, ay: f64, length: f64, angle: f64, rx: f64, ry: vec![p.0, p.1] } +/// [T2] Endpunkt-Griff einer Bogenwand (`grip_drag::arc_wall_grip_target`): `index` 0/1, `length` NaN = Cursor +/// `(rx, ry)` auf den Kreis projiziert. `[x, y, bogenlänge]`, bei Unsinn leer. +#[wasm_bindgen] +#[allow(clippy::too_many_arguments)] +pub fn grip_arc_wall_target(sx: f64, sy: f64, ex: f64, ey: f64, bulge: f64, index: f64, length: f64, rx: f64, ry: f64) -> Vec { + let i = if index == 0.0 { 0 } else if index == 1.0 { 1 } else { return Vec::new() }; + match gd::arc_wall_grip_target((sx, sy), (ex, ey), bulge, i, opt(length), (rx, ry)) { + Some((p, l)) => vec![p.0, p.1, l], + None => Vec::new(), + } +} + /// Shift-Achsen-Lock (`grip_drag::axis_lock`): Ursprung `(ox, oy)` NaN = noch keiner; `ring` = Punkte des /// Elements (leer = keine Polygon-Nachbarn), `index` = gezogener Punkt darin. `[x, y]`. #[wasm_bindgen] diff --git a/src/core/extra.ts b/src/core/extra.ts index 5c04de1f..5942df3d 100644 --- a/src/core/extra.ts +++ b/src/core/extra.ts @@ -74,7 +74,7 @@ export { drawingVertices, gripPt, openEdges, polylineEdgeGrips, ringEdges } from export { verticalExtents } from "../geometry/grips"; export type { VerticalExtent } from "../geometry/grips"; export type { GripRequest } from "../geometry/grips"; -export { clampInside, coincidentGripPoints, excavationGripPoints, gripAxisLock, gripEdgeTarget, gripPolar, gripPolarPoint, openingGripPoint, openingSheetSlide, openingTypedPosition, sheetHeightDrag, stairMoveHandle, stairParamPoints, wallGripPoints } from "../geometry/gripDrag"; +export { clampInside, coincidentGripPoints, excavationGripPoints, gripArcWallTarget, gripAxisLock, gripEdgeTarget, gripPolar, gripPolarPoint, openingGripPoint, openingSheetSlide, openingTypedPosition, sheetHeightDrag, stairMoveHandle, stairParamPoints, wallGripPoints } from "../geometry/gripDrag"; export type { EdgeDrive, GripLocks, SheetHeightKind } from "../geometry/gripDrag"; export { openingPreviewProject, openingPreviewSvgs } from "../plan/openingPreview"; export type { OpeningPreviewSvgs } from "../plan/openingPreview"; diff --git a/src/geometry/gripDrag.test.ts b/src/geometry/gripDrag.test.ts index 12fff5d7..e3ba2d39 100644 --- a/src/geometry/gripDrag.test.ts +++ b/src/geometry/gripDrag.test.ts @@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest"; import { + gripArcWallTarget, coincidentGripPoints, gripAxisLock, gripEdgeTarget, @@ -80,3 +81,19 @@ describe("Griff-Zug (Kern)", () => { expect(coincidentGripPoints(corners, groups)).toEqual([{ group: 2, index: 0 }, { group: 0, index: 0 }]); }); }); + +describe("[T2] Bogenwand-Endpunkt-Griff", () => { + const wall = { start: { x: 0, y: 0 }, end: { x: 4, y: 0 }, bulge: 1 }; + it("projiziert den Cursor auf den Kreis und meldet die Bogenlänge", () => { + const r = gripArcWallTarget(wall, 1, undefined, { x: 2, y: 7 }); + expect(r?.pt.x).toBeCloseTo(2, 9); + expect(r?.pt.y).toBeCloseTo(2, 9); + expect(r?.arcLength).toBeCloseTo(Math.PI, 9); + }); + it("getippte Bogenlänge ab dem festen Ende", () => { + const r = gripArcWallTarget(wall, 1, Math.PI, { x: 3, y: 3 }); + expect(r?.pt.x).toBeCloseTo(2, 9); + expect(r?.pt.y).toBeCloseTo(2, 9); + expect(gripArcWallTarget(wall, 1, -1, { x: 3, y: 3 })).toBeNull(); + }); +}); diff --git a/src/geometry/gripDrag.ts b/src/geometry/gripDrag.ts index 8b2d606c..04905acb 100644 --- a/src/geometry/gripDrag.ts +++ b/src/geometry/gripDrag.ts @@ -41,6 +41,16 @@ export function gripPolarPoint(anchor: Vec2, locks: GripLocks, raw: Vec2): Vec2 return v(core().grip_polar_point(anchor.x, anchor.y, locks.length ?? NaN, locks.angle ?? NaN, raw.x, raw.y)); } +/** + * [T2] Endpunkt-Griff einer Bogenwand (`index` 0 = Start, 1 = Ende): Zielpunkt auf dem Kreis (Mittelpunkt und + * Radius bleiben) und die Bogenlänge der Wand danach. `length` = getippte Bogenlänge ab dem festen Ende, + * sonst folgt der Punkt dem Cursor `raw`. `null` bei Unsinn. + */ +export function gripArcWallTarget(w: Pick, index: 0 | 1, length: number | undefined, raw: Vec2): { pt: Vec2; arcLength: number } | null { + const f = core().grip_arc_wall_target(w.start.x, w.start.y, w.end.x, w.end.y, w.bulge ?? 0, index, length ?? NaN, raw.x, raw.y); + return f.length >= 3 ? { pt: v(f), arcLength: f[2] } : null; +} + /** * Shift-Achsen-Lock eines Punkt-Griffs: Welt-H/V durch den Nachbar-Griff `anchor`, bei einem Vielecks- * Eckpunkt (`ring` = Punkte des Elements, `index` darin, `origin` = Lage vor dem Zug) zusätzlich die Flucht diff --git a/src/state/useGripEditing.ts b/src/state/useGripEditing.ts index 64090231..dc665319 100644 --- a/src/state/useGripEditing.ts +++ b/src/state/useGripEditing.ts @@ -8,7 +8,7 @@ import { useRef, useState, type RefObject } from "react"; import { useEventBundle, useSameData } from "./useEvent"; import { leftNormal, normalize, scale, sub, wallCorners } from "../model/geometry"; -import type { Ceiling, Drawing2D, EdgeGrip, Excavation, Project, Room, Vec2 } from "../model/types"; +import type { Ceiling, Drawing2D, EdgeGrip, Excavation, Project, Room, Vec2, Wall } from "../model/types"; import { wallTypeThickness } from "../model/types"; import { bulgeArcPoints, drawingVertices, surfaceOpeningGripPatch, surfaceOpeningGrips, surfaceOpeningInfo, wallArcBand } from "../core"; import { gripDrawingIdsFor } from "./gripLimits"; @@ -16,6 +16,7 @@ import { openEdges, polylineEdgeGrips, ringEdges } from "../core"; import { coincidentGripPoints, excavationGripPoints, + gripArcWallTarget, gripAxisLock, gripEdgeTarget, gripPolar, @@ -583,13 +584,28 @@ export function useGripEditing(opts: { const gripOpeningPos0Ref = useRef<{ position: number; dir: Vec2 } | null>(null); // Endpunkt aus Anker + (gelockten/Live-)Länge/Winkel (Kern `gripPolarPoint`) — wie lineEndFromFields. - const gripEditPoint = gripPolarPoint; + // [T2] Endpunkt-Griff einer Bogenwand: der Punkt folgt dem Kreis, die getippte Länge ist die Bogenlänge + // ab dem festen Ende (kein Winkel-Feld). + const arcWallEnd = (index: number): { wall: Wall; end: 0 | 1 } | null => { + const owner = gripOwners[index]; + const wall = owner?.wallId ? project.walls.find((x) => x.id === owner.wallId) : undefined; + return wall && wall.bulge && (owner?.localIndex === 0 || owner?.localIndex === 1) ? { wall, end: owner.localIndex } : null; + }; + const gripEditPoint = (anchor: Vec2, locks: GripLocks, raw: Vec2, index?: number): Vec2 => { + const arc = index != null ? arcWallEnd(index) : null; + return (arc && gripArcWallTarget(arc.wall, arc.end, locks.length, raw)?.pt) ?? gripPolarPoint(anchor, locks, raw); + }; // Felder fürs Befehlsfeld während des Vertex-Drags (Live ODER gelockt). const gripEditFields = (): GripEditFieldsState[] => { const ge = gripEdit; const info = gripDragInfoRef.current; if (!ge || !info) return []; + const arc = arcWallEnd(info.index); + if (arc) { + const live = gripArcWallTarget(arc.wall, arc.end, undefined, info.raw)?.arcLength ?? 0; + return [{ id: "length", labelKey: "cmd.field.length", value: ge.locks.length ?? live, locked: ge.locks.length != null, active: true }]; + } return polarFields(ge, gripPolar(ge.anchor, info.raw)); }; @@ -668,7 +684,14 @@ export function useGripEditing(opts: { const anchor = resolveGripAnchor(info.index); if (!anchor) return; // ohne Anker keine polare Eingabe möglich const wallDir = openingWallDir(); + const arcEnd = arcWallEnd(info.index); setGripEdit((prev) => { + if (arcEnd) { + // Bogenwand ([T2]): nur das Längenfeld (Bogenlänge), eingefroren auf der aktuellen Länge. + if (prev) return prev; + const length = gripArcWallTarget(arcEnd.wall, arcEnd.end, undefined, grips[info.index])?.arcLength; + return length != null ? { anchor, active: "length", locks: { length } } : prev; + } if (!prev && wallDir) { // Öffnung ([144]): Richtung = Wandrichtung (bzw. Gegenrichtung, je nach bisherigem Zug), damit // die getippte Länge genau die Strecke entlang der Wand ist. @@ -701,10 +724,10 @@ export function useGripEditing(opts: { const info = gripDragInfoRef.current; if (!ge || !info) return; const locks = { ...ge.locks, [ge.active]: value }; - const next = ge.active === "length" ? "angle" : "length"; + const next = ge.active === "length" && !arcWallEnd(info.index) ? "angle" : "length"; setGripEdit({ ...ge, locks, active: next }); // Zielpunkt mit dem frischen Lock anwenden (live, ohne Maus-Bewegung). - const pt = gripEditPoint(ge.anchor, locks, info.raw); + const pt = gripEditPoint(ge.anchor, locks, info.raw, info.index); applyGripEdit(info.index, pt, ge.anchor, locks.length); }; @@ -1069,7 +1092,10 @@ export function useGripEditing(opts: { const anchor = resolveGripAnchor(index); if (!anchor) return undefined; const { length, angleDeg } = gripPolar(anchor, pt); - return { at: pt, length, angleDeg }; + // Bogenwand ([T2]): Länge = Bogenlänge der Wand mit dem Endpunkt am Cursor. + const arc = arcWallEnd(index); + const arcLength = arc ? gripArcWallTarget(arc.wall, arc.end, undefined, pt)?.arcLength : undefined; + return { at: pt, length: arcLength ?? length, angleDeg }; }; // Dasselbe für einen gezogenen Kanten-Griff: freie Kanten zeigen Länge+Winkel // (wie ein Punkt-Griff), geführte Kanten nur EINEN Wert (Abstand entlang der @@ -1216,7 +1242,7 @@ export function useGripEditing(opts: { const ge = gripEditRef.current; gripDragInfoRef.current = { index, raw }; if (ge && (ge.locks.length != null || ge.locks.angle != null)) { - const pt = gripEditPoint(ge.anchor, ge.locks, raw); + const pt = gripEditPoint(ge.anchor, ge.locks, raw, index); applyGripEdit(index, pt, ge.anchor, ge.locks.length); setDraft({ preview: gripPreviewShapes(), vertices: [], snap: null, hud: hudFor(index, pt) }); return;