Merge branch 'worktree-agent-a0b745691c75e80a3' into claude/practical-noether-1hb2s1

This commit is contained in:
Claude committed 2026-11-09 13:20:16 +00:00
commit 66fa208151
8 files changed
+159 -39

No files matched your search

+45 -4
View File
@@ -793,10 +793,26 @@ fn opening_ops(root: &Map<String, Value>, p: &Project, v: &Value, ctx: &Ctx, ids
add_op("openings", vec![obj(f)])
}
/// Lage der Lücke, wie das Setzen sie ergibt ([`opening_ops`]): Breite und Anfang in die Wand geklemmt,
/// bei Überlappung an die nächste freie Stelle gerückt ([145]: die Vorschau zeigt die gesetzte Lage, nicht
/// den Cursor). Ohne Platz bleibt die geklemmte Lage (das Setzen bewirkt dann nichts). `(pos, width)`.
fn placed_gap(root: &Map<String, Value>, v: &Value, len: f64, pos: f64) -> (f64, f64) {
let width = jsnum::max(0.1, jsnum::min(n_of(v, "width"), len));
let pos = jsnum::max(0.0, jsnum::min(pos, jsnum::max(0.0, len - width)));
match crate::opening_slide::place(root, s_of(v, "wall"), len, width, None, pos, &|_| false) {
Some(pl) if pl.clamped => (pl.position, width),
_ => (pos, width),
}
}
/// Öffnungs-Vorschau (Lücken-Balken + Symbol). `pos` fehlt → aus dem Cursor projiziert.
/// `info = [pos, von, ax, ay, bx, by, mx, my]` (Position für den Zustand, HUD/Stützpunkte).
fn opening_preview(v: &Value, cursor: Option<V>, out: &mut Shapes, info: &mut Vec<f64>) {
fn opening_preview(root: &Map<String, Value>, v: &Value, cursor: Option<V>, out: &mut Shapes, info: &mut Vec<f64>) {
let (st, en) = (p_of(v, "start"), p_of(v, "end"));
let wall_len = match arc_of(st, en, opt_n(v, "bulge")) {
Some(a) => a.length(),
None => hypot2(en.0 - st.0, en.1 - st.1),
};
// 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();
@@ -805,7 +821,7 @@ fn opening_preview(v: &Value, cursor: Option<V>, out: &mut Shapes, info: &mut Ve
(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 (pos, width) = placed_gap(root, v, wall_len, pos);
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| {
@@ -836,12 +852,12 @@ fn opening_preview(v: &Value, cursor: Option<V>, out: &mut Shapes, info: &mut Ve
(None, Some(c)) => project_onto_wall(st, en, c).0,
(None, None) => 0.0,
};
let (pos, width) = placed_gap(root, v, wall_len, pos);
let ax = (en.0 - st.0, en.1 - st.1);
let l = hypot2(ax.0, ax.1);
let len = if l == 0.0 || l.is_nan() { 1e-9 } else { l };
let u = (ax.0 / len, ax.1 / len);
let n = (-u.1, u.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 a = (st.0 + u.0 * from, st.1 + u.1 * from);
@@ -1163,7 +1179,7 @@ pub fn preview_req(root: &Map<String, Value>, project: &Project, req: &Req, pts:
match req.cmd.as_str() {
"wall" => wall_preview(root, v, &ctx, &pts, out),
"stair" => stair_preview(project, v, &ctx, out, &mut p.info),
"opening" => opening_preview(v, pts.first().copied(), out, &mut p.info),
"opening" => opening_preview(root, v, pts.first().copied(), out, &mut p.info),
"roomInside" => p.ok = pts.first().and_then(|at| room_inside(project, ctx.level, *at)).is_some_and(|b| b.len() >= 3),
// Zauberstab ([77]): die gefundene Masche unter dem Cursor.
"wand" => match pts.first().and_then(|at| crate::magic_wand::region_at(project, ctx.level, *at)) {
@@ -1444,5 +1460,30 @@ mod tests {
assert_eq!(p.info[0], 2.0);
assert_eq!(p.shapes.count, 2);
}
/// [145] Die Vorschau zeigt die Lage, die das Setzen ergibt (an die Wand geklemmt, an die nächste freie
/// Stelle gerückt), nicht den Cursor-Ort.
#[test]
fn oeffnung_vorschau_zeigt_gerueckte_lage() {
let r = root(json!({"walls": [{"id": "w", "floorId": "F1", "start": {"x": 0, "y": 0}, "end": {"x": 6, "y": 0}}], "openings": [{"id": "a", "hostWallId": "w", "position": 2, "width": 1}], "windowTypes": [{"id": "FT"}]}));
let t = crate::model::lenient::typed_for_test(&r);
let pos_of = |width: f64, cursor: f64, pos: Value| {
let v = json!({"cmd": "opening", "wall": "w", "start": [0, 0], "end": [6, 0], "kind": "window", "width": width, "pos": pos});
let pv = preview(&r, &t, &v, &[cursor, 0.0]);
let set = ops(&r, &t, &req(json!({"cmd": "opening", "wall": "w", "start": [0, 0], "end": [6, 0], "kind": "window", "pos": pos_or(&pv), "width": width, "height": 1.2, "sill": 0.9}))).unwrap();
(pv.info[0], pv.info[1], items(&set, 0)[0]["position"].as_f64().unwrap())
};
// Cursor über der Nachbaröffnung: rückt neben sie (Steg 5 cm), Setzen an derselben Stelle.
let (p, from, set) = pos_of(1.0, 2.6, Value::Null);
assert_eq!((p, from), (3.05, 3.05));
assert_eq!(set, 3.05);
// Cursor am Wandende: die Lücke behält ihre Breite und rückt in die Wand.
let (p, from, set) = pos_of(1.2, 5.9, Value::Null);
assert_eq!((p, from, set), (4.8, 4.8, 4.8));
}
fn pos_or(p: &Preview) -> f64 {
p.info[0]
}
}
+78 -4
View File
@@ -235,6 +235,28 @@ fn poly_node(pts: &str, fill: &str, stroke: &str, stroke_mm: f64) -> Vec<(&'stat
a
}
/// Polygon mit Füllung und Strich; mit `nse` (nicht gestrichene Kanten, [146]) die Füllung ohne Strich
/// und die sichtbaren Kantenläufe als offene Linienzüge — wie das Plan-SVG (`plan/svg.rs`).
fn poly_stroked(out: &mut Out, attr: &str, pts_mm: &[V2], nse: &[f64], fill: &str, stroke: &str, stroke_mm: f64) {
if nse.is_empty() || stroke_mm <= 0.0 || stroke == "none" {
out.el(1, "polygon", &poly_node(attr, fill, stroke, stroke_mm));
return;
}
out.el(1, "polygon", &poly_node(attr, fill, "none", 0.0));
poly_outline(out, pts_mm, nse, stroke, stroke_mm);
}
/// Nur der Umriss (Füllung oder Schraffur liegt schon darunter).
fn poly_outline(out: &mut Out, pts_mm: &[V2], nse: &[f64], stroke: &str, stroke_mm: f64) {
if nse.is_empty() {
out.el(1, "polygon", &poly_node(&pts_attr(pts_mm), "none", stroke, stroke_mm));
return;
}
for run in crate::plan::scene::visible_edge_runs(pts_mm, nse) {
out.el(1, "polyline", &polyline_attrs(&run, stroke, stroke_mm, None));
}
}
fn line_attrs(a: V2, b: V2, color: &str, stroke_mm: f64, dash: Option<&[f64]>) -> Vec<(&'static str, String)> {
let mut v = vec![
("x1", r3(a.x)),
@@ -398,6 +420,10 @@ fn entry(out: &mut Out, view: &View, i: usize, hatches: &[(i32, Hatch, i32)], m:
let opacity = opacity_of(greyed, obj(4));
let pts_mm: Vec<V2> = pts.iter().map(|p| m.at(p.x, p.y)).collect();
let attr = pts_attr(&pts_mm);
let nse: Vec<f64> = match rec.nse {
Some((o, n)) => view.pool(o, n)?.into_iter().filter(|e| e.is_finite() && *e >= 0.0).collect(),
None => Vec::new(),
};
let sw = f[2];
let stroke_mm = if sw > 0.0 { quantize_pen(sw) } else { 0.0 };
let fill = s(f[0])?;
@@ -418,12 +444,12 @@ fn entry(out: &mut Out, view: &View, i: usize, hatches: &[(i32, Hatch, i32)], m:
}
out.rec(&["I", &attr, &img]);
if stroke_mm > 0.0 {
out.el(1, "polygon", &poly_node(&attr, "none", &stroke, stroke_mm));
poly_outline(out, &pts_mm, &nse, &stroke, stroke_mm);
}
} else if h.pattern == Pattern::None {
out.el(1, "polygon", &poly_node(&attr, &fill, &stroke, stroke_mm));
poly_stroked(out, &attr, &pts_mm, &nse, &fill, &stroke, stroke_mm);
} else if h.pattern == Pattern::Solid {
out.el(1, "polygon", &poly_node(&attr, &hatch_color, &stroke, stroke_mm));
poly_stroked(out, &attr, &pts_mm, &nse, &hatch_color, &stroke, stroke_mm);
} else {
if fill != "none" {
out.el(1, "polygon", &poly_node(&attr, &fill, "none", 0.0));
@@ -455,7 +481,7 @@ fn entry(out: &mut Out, view: &View, i: usize, hatches: &[(i32, Hatch, i32)], m:
}
}
if stroke_mm > 0.0 {
out.el(1, "polygon", &poly_node(&attr, "none", &stroke, stroke_mm));
poly_outline(out, &pts_mm, &nse, &stroke, stroke_mm);
}
}
out.rec(&["g"]);
@@ -809,4 +835,52 @@ mod tests {
assert_eq!(segs.len(), 6);
assert!(segs.iter().all(|(a, b)| (b.x - a.x - 10.0).abs() < 1e-9 || (a.x - b.x - 10.0).abs() < 1e-9));
}
/// [146] Nicht gestrichene Kanten (`noStrokeEdges`) bleiben im Druck-SVG ohne Strich: Füllung ohne
/// Umriss, die übrigen Kanten als offener Linienzug.
#[test]
fn ungestrichene_kante_ohne_strich() {
use crate::model::Vec2;
use crate::plan::buf::{View, Writer};
use crate::plan::prim::Primitive;
let v = |x: f64, y: f64| Vec2 { x, y };
let mut w = Writer::new(false);
let g = w.begin_group();
w.push(&Primitive::Polygon {
pts: vec![v(0.0, 0.0), v(1.0, 0.0), v(1.0, 1.0), v(0.0, 1.0)],
fill: "#fff".into(),
stroke: "#123456".into(),
stroke_width_mm: 0.5,
hatch: crate::plan::style::no_hatch(),
greyed: None,
opacity: None,
no_stroke_edges: Some(vec![3.0]),
wall_id: None,
drawing_id: None,
ceiling_id: None,
opening_id: None,
stair_id: None,
room_id: None,
extruded_solid_id: None,
context_object_id: None,
column_id: None,
roof_id: None,
section_line_id: None,
});
w.end_group(g);
let bytes = w.finish();
let view = View::parse(&bytes).unwrap();
let n = view.len();
let mut parts = vec![Part::new(view, 0, n).unwrap()];
let o = PrintOptions { scale_denominator: 1000.0, page_w: 10.0, page_h: 10.0, bounds: [0.0, 0.0, 1.0, 1.0] };
let ops = print_svg_ops(&mut parts, &o).unwrap();
let recs: Vec<&str> = ops.split('\x1e').collect();
let poly = recs.iter().find(|r| r.contains("\x1fpolygon")).expect("Füllung");
assert!(!poly.contains("#123456"), "Füllung ohne Strich: {poly:?}");
let line = recs.iter().find(|r| r.contains("\x1fpolyline")).expect("Kantenzug");
assert!(line.contains("#123456"), "{line:?}");
// Drei sichtbare Kanten = vier Punkte; die vierte Kante (0,1)→(0,0) fehlt.
let pts = line.split('\x1f').skip_while(|x| *x != "points").nth(1).unwrap();
assert_eq!(pts.split(' ').count(), 4, "{pts}");
}
}
+12
View File
@@ -102,6 +102,18 @@ pub fn grip_opening_slide_sheet(sx: f64, sy: f64, ex: f64, ey: f64, bulge: f64,
gd::opening_slide_sheet((sx, sy), (ex, ey), bulge, (ux, uy), position, width, du).map(|(p, d)| vec![p, d]).unwrap_or_default()
}
/// Punkt im Umriss halten (`opening_slide::clamp_inside`, Dach-/Deckenöffnung): `[x, y]`; Ring als
/// flacher Puffer, kaputte Eingabe (NaN, weniger als 3 Ecken) = Punkt unverändert.
#[wasm_bindgen]
pub fn grip_clamp_inside(x: f64, y: f64, ring: &[f64]) -> Vec<f64> {
let r = pts(ring);
if !x.is_finite() || !y.is_finite() || r.len() < 3 || r.iter().any(|p| !p.0.is_finite() || !p.1.is_finite()) {
return vec![x, y];
}
let q = crate::opening_slide::clamp_inside((x, y), &r);
vec![q.0, q.1]
}
/// Bewegpunkt einer Treppe (Zentrum NaN = keines): `[x, y]`.
#[wasm_bindgen]
#[allow(clippy::too_many_arguments)]