Merge branch 'worktree-agent-a6dfad03524c70231' into claude/practical-noether-1hb2s1
This commit is contained in:
20 files changed
+281
-39
No files matched your search
@@ -106,12 +106,22 @@ pub fn extent(p: &Project) -> Option<[f64; 4]> {
|
||||
bbox(&pts).filter(areal).or_else(|| bbox(p.site_rules.iter().flat_map(|r| &r.parcel)).filter(areal))
|
||||
}
|
||||
|
||||
/// [266] Mindestabstand (m) des automatischen Schnitts von einer parallelen Wandachse, Suchschritt (m) und
|
||||
/// grösster Sinus des Winkels, bis zu dem eine Wand als parallel gilt (≈ 6°).
|
||||
const AXIS_CLEARANCE: f64 = 0.5;
|
||||
const AXIS_STEP: f64 = 0.25;
|
||||
const PARALLEL_SIN: f64 = 0.1;
|
||||
|
||||
/// Kleinste Ausdehnung (m) des Ausmasses in beiden Richtungen, ab der die Linien nachgeführt werden.
|
||||
const MIN_SIZE: f64 = 1.0;
|
||||
|
||||
/// Linie einer automatischen Ebene für das Ausmass `b`: Richtung und Blickrichtung wie `line`, Schnitt durch die
|
||||
/// Mitte, Ansicht vor dem Ausmass (gegen die Blickrichtung), beide mit Rand über das Ausmass hinaus.
|
||||
pub fn place(kind: DrawingLevelKind, line: [Vec2; 2], sign: f64, b: [f64; 4]) -> Option<[Vec2; 2]> {
|
||||
///
|
||||
/// [266] `axes`: Wandachsen des Projekts. Der Schnitt weicht von der Mitte soweit aus, bis er keiner zu ihm
|
||||
/// (fast) parallelen Wandachse näher als [`AXIS_CLEARANCE`] liegt: sonst schneidet er die Wand der Länge nach (schwarze
|
||||
/// Fläche im Schnitt). Gibt es keinen freien Platz, bleibt er in der Mitte.
|
||||
pub fn place(kind: DrawingLevelKind, line: [Vec2; 2], sign: f64, b: [f64; 4], axes: &[[Vec2; 2]]) -> Option<[Vec2; 2]> {
|
||||
let (dx, dy) = (line[1].x - line[0].x, line[1].y - line[0].y);
|
||||
let len = dx.hypot(dy);
|
||||
if !(len > 1e-9) || !b.iter().all(|v| v.is_finite()) {
|
||||
@@ -126,8 +136,26 @@ pub fn place(kind: DrawingLevelKind, line: [Vec2; 2], sign: f64, b: [f64; 4]) ->
|
||||
let (s0, s1) = corners.iter().map(along).fold((f64::INFINITY, f64::NEG_INFINITY), |(a, z), v| (a.min(v), z.max(v)));
|
||||
let (t0, t1) = corners.iter().map(across).fold((f64::INFINITY, f64::NEG_INFINITY), |(a, z), v| (a.min(v), z.max(v)));
|
||||
let margin = 2.0f64.max(0.1 * (s1 - s0).max(t1 - t0));
|
||||
// Quer-Koordinaten (Richtung `n`) der zur Linie parallelen Wandachsen.
|
||||
let parallel: Vec<f64> = axes
|
||||
.iter()
|
||||
.filter_map(|a| {
|
||||
let (wx, wy) = (a[1].x - a[0].x, a[1].y - a[0].y);
|
||||
let wl = wx.hypot(wy);
|
||||
if !(wl > 1e-6) || (wx * d.1 - wy * d.0).abs() / wl > PARALLEL_SIN {
|
||||
return None;
|
||||
}
|
||||
Some(a[0].x * n.0 + a[0].y * n.1)
|
||||
})
|
||||
.collect();
|
||||
let clear = |t: f64| parallel.iter().all(|c| (c - t).abs() >= AXIS_CLEARANCE);
|
||||
let mid = (t0 + t1) / 2.0;
|
||||
let section_t = || {
|
||||
let steps = ((t1 - t0) * 0.45 / AXIS_STEP).floor() as i32;
|
||||
(0..=steps).flat_map(|k| [mid + k as f64 * AXIS_STEP, mid - k as f64 * AXIS_STEP]).find(|t| clear(*t)).unwrap_or(mid)
|
||||
};
|
||||
let t = match kind {
|
||||
DrawingLevelKind::Section => (t0 + t1) / 2.0,
|
||||
DrawingLevelKind::Section => section_t(),
|
||||
DrawingLevelKind::Elevation => t0 - margin,
|
||||
_ => return None,
|
||||
};
|
||||
@@ -142,6 +170,7 @@ pub fn place(kind: DrawingLevelKind, line: [Vec2; 2], sign: f64, b: [f64; 4]) ->
|
||||
pub fn sync_ops(p: &Project, root: &Map<String, Value>, t: &Touch) -> Vec<Op> {
|
||||
let levels = root.get("drawingLevels").and_then(Value::as_array).map(Vec::as_slice).unwrap_or(&[]);
|
||||
let ext = if t.extent { extent(p) } else { None };
|
||||
let axes: Vec<[Vec2; 2]> = p.walls.iter().map(|w| [w.start, w.end]).collect();
|
||||
let mut out = Vec::new();
|
||||
for l in &p.drawing_levels {
|
||||
if l.auto_line != Some(true) || !matches!(l.kind, DrawingLevelKind::Section | DrawingLevelKind::Elevation) {
|
||||
@@ -153,7 +182,7 @@ pub fn sync_ops(p: &Project, root: &Map<String, Value>, t: &Touch) -> Vec<Op> {
|
||||
e.remove("autoLine");
|
||||
} else {
|
||||
let (Some(b), Some(line)) = (ext, l.line_points) else { continue };
|
||||
let Some(next) = place(l.kind, line, l.direction_sign.unwrap_or(1.0), b) else { continue };
|
||||
let Some(next) = place(l.kind, line, l.direction_sign.unwrap_or(1.0), b, &axes) else { continue };
|
||||
let same = line.iter().zip(&next).all(|(a, c)| (a.x - c.x).abs() < 1e-6 && (a.y - c.y).abs() < 1e-6);
|
||||
if same && l.bend_points.as_ref().is_none_or(Vec::is_empty) {
|
||||
continue;
|
||||
@@ -194,17 +223,34 @@ mod tests {
|
||||
fn schnitt_durch_die_mitte_ansicht_davor() {
|
||||
let b = [48.0, 46.0, 60.0, 56.0];
|
||||
let line = [Vec2 { x: -1.0, y: 2.0 }, Vec2 { x: 6.0, y: 2.0 }];
|
||||
let s = place(DrawingLevelKind::Section, line, 1.0, b).unwrap();
|
||||
let s = place(DrawingLevelKind::Section, line, 1.0, b, &[]).unwrap();
|
||||
assert_eq!(s, [Vec2 { x: 46.0, y: 51.0 }, Vec2 { x: 62.0, y: 51.0 }]);
|
||||
let e = place(DrawingLevelKind::Elevation, line, 1.0, b).unwrap();
|
||||
let e = place(DrawingLevelKind::Elevation, line, 1.0, b, &[]).unwrap();
|
||||
// Blick nach +y (Norden): Linie südlich des Gebäudes.
|
||||
assert_eq!(e, [Vec2 { x: 46.0, y: 44.0 }, Vec2 { x: 62.0, y: 44.0 }]);
|
||||
// Umgekehrte Blickrichtung: Linie auf der anderen Seite.
|
||||
let n = place(DrawingLevelKind::Elevation, line, -1.0, b).unwrap();
|
||||
let n = place(DrawingLevelKind::Elevation, line, -1.0, b, &[]).unwrap();
|
||||
assert_eq!(n[0].y, 58.0);
|
||||
assert!(place(DrawingLevelKind::Floor, line, 1.0, b).is_none());
|
||||
assert!(place(DrawingLevelKind::Section, [line[0], line[0]], 1.0, b).is_none());
|
||||
assert!(place(DrawingLevelKind::Section, line, 1.0, [f64::NAN, 0.0, 1.0, 1.0]).is_none());
|
||||
assert!(place(DrawingLevelKind::Floor, line, 1.0, b, &[]).is_none());
|
||||
assert!(place(DrawingLevelKind::Section, [line[0], line[0]], 1.0, b, &[]).is_none());
|
||||
assert!(place(DrawingLevelKind::Section, line, 1.0, [f64::NAN, 0.0, 1.0, 1.0], &[]).is_none());
|
||||
}
|
||||
|
||||
/// [266] Liegt die Mitte auf der Achse einer parallelen Innenwand, rückt der Schnitt zur Seite (nicht auf die Achse).
|
||||
#[test]
|
||||
fn schnitt_meidet_wandachsen() {
|
||||
let b = [48.0, 46.0, 60.0, 56.0];
|
||||
let line = [Vec2 { x: -1.0, y: 2.0 }, Vec2 { x: 6.0, y: 2.0 }];
|
||||
let ax = |y: f64| [Vec2 { x: 48.0, y }, Vec2 { x: 60.0, y }];
|
||||
let y_of = |axes: &[[Vec2; 2]]| place(DrawingLevelKind::Section, line, 1.0, b, axes).unwrap()[0].y;
|
||||
assert_eq!(y_of(&[]), 51.0);
|
||||
let y = y_of(&[ax(51.0)]);
|
||||
assert!((y - 51.0).abs() >= 0.5 && (y - 51.0).abs() <= 1.0, "{y}");
|
||||
// Senkrechte Wände zählen nicht; zwei Achsen beidseits: weiter ausweichen.
|
||||
assert_eq!(y_of(&[[Vec2 { x: 51.0, y: 46.0 }, Vec2 { x: 51.0, y: 56.0 }]]), 51.0);
|
||||
let y = y_of(&[ax(51.0), ax(51.25), ax(50.75)]);
|
||||
assert!(![51.0, 51.25, 50.75].iter().any(|c| (c - y).abs() < 0.5), "{y}");
|
||||
assert!(place(DrawingLevelKind::Elevation, line, 1.0, b, &[ax(44.0)]).unwrap()[0].y == 44.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -686,9 +686,13 @@ fn build_stair(p: &Project, v: &Value, ctx: &Ctx, id: Value) -> StairBuilt {
|
||||
StairBuilt { fields: f, params, rise, steps }
|
||||
}
|
||||
|
||||
fn stair_ops(p: &Project, v: &Value, ctx: &Ctx, ids: &mut IdGen) -> Vec<Op> {
|
||||
fn stair_ops(root: &Map<String, Value>, p: &Project, v: &Value, ctx: &Ctx, ids: &mut IdGen) -> Vec<Op> {
|
||||
let b = build_stair(p, v, ctx, s(&ids.next("ST")));
|
||||
add_op("stairs", vec![obj(b.fields)])
|
||||
// [266] Deckenloch im selben Commit (ein Undo-Schritt), wenn die Treppe die Decke des Geschosses durchstösst.
|
||||
let hole = crate::cmd_solid::stair_hole_ops(root, &b.params, b.rise, b_of(v, "up"), ctx);
|
||||
let mut ops = add_op("stairs", vec![obj(b.fields)]);
|
||||
ops.extend(hole);
|
||||
ops
|
||||
}
|
||||
|
||||
/// Treppen-Vorschau: Tritte, Podest, Lauflinie; `info = [Stufenzahl]`.
|
||||
@@ -1147,7 +1151,7 @@ pub fn ops(root: &Map<String, Value>, p: &Project, v: &Value) -> Option<Vec<Op>>
|
||||
"wand" => wand_ops(p, v, &ctx, ids),
|
||||
// [154] Bauteile aus Zeichnung erkennen.
|
||||
"recognize" => crate::drawing_recognize::ops(p, v, &ctx, ids),
|
||||
"stair" => stair_ops(p, v, &ctx, ids),
|
||||
"stair" => stair_ops(root, p, v, &ctx, ids),
|
||||
"opening" => opening_ops(root, p, v, &ctx, ids),
|
||||
"roof" => roof_ops(p, v, &ctx, ids),
|
||||
"column" => column_ops(v, &ctx, ids),
|
||||
@@ -1539,6 +1543,35 @@ mod tests {
|
||||
assert_eq!((p, from, set), (4.8, 4.8, 4.8));
|
||||
}
|
||||
|
||||
/// [266] Treppe durch die Decke des Geschosses: Aussparung im selben Commit (Treppenumriss), nur wenn die
|
||||
/// Treppe aufwärts über die volle Geschosshöhe läuft und der Umriss ganz in der Decke liegt.
|
||||
#[test]
|
||||
fn treppe_legt_deckenloch_an() {
|
||||
let ceil = json!({"id": "C1", "type": "ceiling", "floorId": "F1", "outline": [{"x": 0, "y": 0}, {"x": 8, "y": 0}, {"x": 8, "y": 6}, {"x": 0, "y": 6}]});
|
||||
let r = root(json!({"ceilings": [ceil]}));
|
||||
let t = crate::model::lenient::typed_for_test(&r);
|
||||
let stair = |start: [f64; 2], cursor: [f64; 2], up: bool, rise: Value| {
|
||||
let mut v = json!({"cmd": "stair", "shape": "straight", "up": up, "width": 1.0, "referenz": "mitte", "treadMode": "without",
|
||||
"auftritt": 0.28, "steps": null, "start": {"x": start[0], "y": start[1]}, "cursor": {"x": cursor[0], "y": cursor[1]}});
|
||||
v["rise"] = rise;
|
||||
ops(&r, &t, &req(v)).unwrap()
|
||||
};
|
||||
let o = stair([1.0, 2.0], [5.0, 2.0], true, Value::Null);
|
||||
assert_eq!(o.len(), 2, "Treppe + Aussparung");
|
||||
let j = o[1].to_json();
|
||||
assert_eq!(j["entity"]["id"], "C1");
|
||||
let ring = j["entity"]["openings"][0].as_array().unwrap();
|
||||
assert!(ring.len() >= 4);
|
||||
for q in ring {
|
||||
let (x, y) = (q["x"].as_f64().unwrap(), q["y"].as_f64().unwrap());
|
||||
assert!((0.9..=5.1).contains(&x) && (1.4..=2.6).contains(&y), "{x},{y}");
|
||||
}
|
||||
// abwärts, Teilhöhe, ausserhalb der Decke → nur die Treppe
|
||||
assert_eq!(stair([1.0, 2.0], [5.0, 2.0], false, Value::Null).len(), 1);
|
||||
assert_eq!(stair([1.0, 2.0], [5.0, 2.0], true, json!(1.5)).len(), 1);
|
||||
assert_eq!(stair([7.0, 2.0], [11.0, 2.0], true, Value::Null).len(), 1);
|
||||
}
|
||||
|
||||
fn pos_or(p: &Preview) -> f64 {
|
||||
p.info[0]
|
||||
}
|
||||
|
||||
@@ -684,6 +684,45 @@ fn ceiling_opening_ops(root: &Map<String, Value>, v: &Value, ctx: &Ctx) -> Vec<O
|
||||
vec![Op::Replace { collection: "ceilings".into(), entity: with(host, "openings", Value::Array(openings)) }]
|
||||
}
|
||||
|
||||
/// [266] Deckenloch einer neuen Treppe: steigt sie über die ganze Geschosshöhe nach oben, wird in die Decke des
|
||||
/// Geschosses (die den ganzen Treppengrundriss enthält) eine Aussparung in der Form des Treppenumrisses gelegt.
|
||||
/// Keine solche Decke, Treppe nach unten oder nicht über die volle Höhe, oder schon ein Loch darüber → keine Op.
|
||||
/// Die Ops laufen mit der Treppe im selben Commit (ein Undo-Schritt).
|
||||
pub(crate) fn stair_hole_ops(root: &Map<String, Value>, params: &[f64], rise: f64, up: bool, ctx: &Ctx) -> Vec<Op> {
|
||||
let floor_h = ctx.floor_height.unwrap_or(f64::NAN);
|
||||
if !up || !(floor_h.is_finite() && rise >= floor_h - 0.05) {
|
||||
return Vec::new();
|
||||
}
|
||||
let o = crate::stair::outline(params);
|
||||
let ring: Vec<V> = match o.first() {
|
||||
Some(&k) if k == 0.0 && o.len() >= 2 => {
|
||||
let n = o[1] as usize;
|
||||
(0..n).filter_map(|i| Some((*o.get(2 + 2 * i)?, *o.get(3 + 2 * i)?))).collect()
|
||||
}
|
||||
// Wendeltreppen (Linien + Bögen statt Polygon): Loch weiter von Hand (`deckenloch`).
|
||||
_ => return Vec::new(),
|
||||
};
|
||||
if ring.len() < 3 || ring.iter().any(|q| !(q.0.is_finite() && q.1.is_finite())) {
|
||||
return Vec::new();
|
||||
}
|
||||
let host = arr(root.get("ceilings")).iter().find(|c| {
|
||||
let outline = ring_of(c);
|
||||
crate::cmd_create::floor_of(c) == Some(ctx.level) && outline.len() >= 3 && ring.iter().all(|q| point_in_polygon(*q, &outline))
|
||||
});
|
||||
let Some(host) = host else { return Vec::new() };
|
||||
let mut openings = arr(field(host, "openings")).to_vec();
|
||||
// Ein bestehendes Loch, das den Umriss schon enthält, genügt.
|
||||
let covered = openings.iter().any(|h| {
|
||||
let hr: Vec<V> = arr(Some(h)).iter().map(xy).collect();
|
||||
hr.len() >= 3 && ring.iter().all(|q| point_in_polygon(*q, &hr))
|
||||
});
|
||||
if covered {
|
||||
return Vec::new();
|
||||
}
|
||||
openings.push(pvs(&ring));
|
||||
vec![Op::Replace { collection: "ceilings".into(), entity: with(host, "openings", Value::Array(openings)) }]
|
||||
}
|
||||
|
||||
/// Dachfenster / Deckenöffnung mit Oberlicht ([103]): ein Klick setzt die Öffnung (Mitte im Grundriss) in das
|
||||
/// Dach, dessen Umriss den Punkt enthält (Dächer des aktiven Geschosses zuerst), sonst in die Decke des
|
||||
/// Geschosses. Masse in der Dachebene (Standard 78 × 118 cm), Fenstertyp wie beim Fenster-Befehl.
|
||||
|
||||
@@ -1571,7 +1571,8 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result<Flat, String>
|
||||
common.push(ident("Reference", n));
|
||||
}
|
||||
common.push(Prop::Bool("IsExternal", external));
|
||||
let (id, name, long) = (f.str(&room.id), f.str(number.unwrap_or(&room.id)), f.str(&room.name));
|
||||
// [266] IFC-Konvention: Name = Raumnummer, LongName = Raumname; ohne Nummer steht der Raumname im Namen (nicht die interne Id).
|
||||
let (id, name, long) = (f.str(&room.id), f.str(number.unwrap_or(if room.name.is_empty() { &room.id } else { &room.name })), f.str(&room.name));
|
||||
let bands = crate::room_book::height_bands(&p, room, roofs, area.net);
|
||||
let arcs = crate::ring_arc::has_arcs(room.boundary_bulge.as_deref(), room.boundary.len());
|
||||
f.nums(&[if arcs { REC_SPACE_ARC } else { REC_SPACE }, structure, id, name, long, if external { 1.0 } else { 0.0 }, height, z_rel, bands.mean]);
|
||||
|
||||
Reference in new issue
Block a user