[154] Bauteile aus Zeichnung erkennen: Wände (Linienpaare, Bögen, Stösse), Türen/Fenster/Durchbrüche, Räume aus DXF-Linien
Kern drawing_recognize.rs (Befehl recognize über cmd_create: Ops, Vorschau, Bericht), Befehl erkennen mit Vorschau/Zählern/Bericht, CLI erkennen, Rundreise-Test DXF-Export → Import → erkennen (Musterhaus 100 %, komplex Wände 79 %/Achsen 96 %, Öffnungen 76 %).
This commit is contained in:
14 files changed
+2880
-2
No files matched your search
@@ -255,7 +255,7 @@ pub(crate) fn category_or(p: &Project, code: &str, ctx: &Ctx) -> Value {
|
||||
|
||||
/// Farbe der Kategorie `code` (erste im Baum), sonst `def` (auch bei leerer Farbe: fehlt sie in der
|
||||
/// Datei, liest die typisierte Sicht "").
|
||||
fn category_color(p: &Project, code: &str, def: &str) -> Value {
|
||||
pub(crate) fn category_color(p: &Project, code: &str, def: &str) -> Value {
|
||||
match find_category(&p.layers, code) {
|
||||
Some(c) if !c.color.is_empty() => s(&c.color),
|
||||
_ => s(def),
|
||||
@@ -1093,6 +1093,8 @@ pub fn ops(root: &Map<String, Value>, p: &Project, v: &Value) -> Option<Vec<Op>>
|
||||
"ceiling" => ceiling_ops(p, v, &ctx, ids),
|
||||
"room" => room_ops(p, v, &ctx, ids),
|
||||
"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),
|
||||
"opening" => opening_ops(root, p, v, &ctx, ids),
|
||||
"roof" => roof_ops(p, v, &ctx, ids),
|
||||
@@ -1173,6 +1175,7 @@ pub fn preview_req(root: &Map<String, Value>, project: &Project, req: &Req, pts:
|
||||
}
|
||||
None => p.ok = false,
|
||||
},
|
||||
"recognize" => p.ok = crate::drawing_recognize::preview(project, v, &ctx, out, &mut p.info),
|
||||
"column" => {
|
||||
if let Some(at) = pts.first() {
|
||||
out.poly(&column_footprint(*at, v));
|
||||
@@ -1217,6 +1220,7 @@ pub fn query(root: &Map<String, Value>, p: &Project, v: &Value) -> Option<Result
|
||||
}
|
||||
None => json!({ "hit": null }),
|
||||
},
|
||||
"recognize" => crate::drawing_recognize::report(p, v),
|
||||
"pickProfile" => json!({ "hit": pick_profile(root, level, at).map_or(Value::Null, profile_json) }),
|
||||
"profile" => json!({ "hit": find(root, "drawings2d", s_of(v, "id")).map_or(Value::Null, profile_json) }),
|
||||
_ => return crate::cmd_draw::query(root, p, v).or_else(|| crate::cmd_solid::query(root, p, v)).map(Ok),
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,486 @@
|
||||
//! Tests zu [154] Bauteile aus Zeichnung erkennen: synthetische Grundrisse (L-Haus mit T- und Kreuzstoss,
|
||||
//! Bogenwand, Tür mit Bogen, Fenster, Durchbruch, Raumtexte), Layer-Filter, Schichtlinie, Ops, Unsinn.
|
||||
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
const EPS: f64 = 1e-6;
|
||||
|
||||
struct B {
|
||||
inp: Input,
|
||||
}
|
||||
|
||||
impl B {
|
||||
fn new() -> B {
|
||||
B { inp: Input::default() }
|
||||
}
|
||||
fn line(&mut self, layer: &str, a: V, b: V) -> &mut B {
|
||||
let l = self.inp.layer(layer);
|
||||
self.inp.segs.push(Seg { a, b, layer: l });
|
||||
self
|
||||
}
|
||||
/// Geschlossener Linienzug (Polylinie als Kanten).
|
||||
fn ring(&mut self, layer: &str, pts: &[V]) -> &mut B {
|
||||
for i in 0..pts.len() {
|
||||
self.line(layer, pts[i], pts[(i + 1) % pts.len()]);
|
||||
}
|
||||
self
|
||||
}
|
||||
fn rect(&mut self, layer: &str, x0: f64, y0: f64, x1: f64, y1: f64) -> &mut B {
|
||||
self.ring(layer, &[(x0, y0), (x1, y0), (x1, y1), (x0, y1)])
|
||||
}
|
||||
fn arc(&mut self, layer: &str, c: V, r: f64, a0_deg: f64, sweep_deg: f64) -> &mut B {
|
||||
let l = self.inp.layer(layer);
|
||||
self.inp.arcs.push(ArcIn { c, r, a0: a0_deg.to_radians(), sweep: sweep_deg.to_radians(), layer: l });
|
||||
self
|
||||
}
|
||||
fn text(&mut self, at: V, t: &str, h: f64) -> &mut B {
|
||||
self.inp.texts.push(TextIn { at, text: t.into(), h, angle: 0.0 });
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn near(a: V, b: V, tol: f64) -> bool {
|
||||
len(sub(a, b)) <= tol
|
||||
}
|
||||
|
||||
/// Wand mit Achse a–b (beide Richtungen).
|
||||
fn has_wall(r: &Recognition, a: V, b: V, t: f64) -> bool {
|
||||
r.walls.iter().any(|w| (w.t - t).abs() < 1e-6 && ((near(w.a, a, 1e-6) && near(w.b, b, 1e-6)) || (near(w.a, b, 1e-6) && near(w.b, a, 1e-6))))
|
||||
}
|
||||
|
||||
/// L-Haus (Achsen 12×6 + 6×4, Aussenwände 30 cm) mit zwei Innenwänden 15 cm: T-Stösse bei (6,0) und (0,6),
|
||||
/// Kreuz bei (6,6). Zeichnung wie aus CAD: Aussenumriss + Raumumrisse (lichte Masse).
|
||||
fn l_house() -> B {
|
||||
let mut b = B::new();
|
||||
b.ring("A-WALL", &[(-0.15, -0.15), (12.15, -0.15), (12.15, 6.15), (6.15, 6.15), (6.15, 10.15), (-0.15, 10.15)]);
|
||||
b.rect("A-WALL", 0.15, 0.15, 5.925, 5.925); // A1
|
||||
b.rect("A-WALL", 0.15, 6.075, 5.85, 9.85); // A2
|
||||
b.rect("A-WALL", 6.075, 0.15, 11.85, 5.85); // B
|
||||
b
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn l_haus_mit_t_und_kreuzstoss() {
|
||||
let mut b = l_house();
|
||||
b.text((1.0, 3.0), "Wohnen", 0.35).text((1.0, 2.5), "33.35 m²", 0.25).text((1.0, 2.0), "HNF", 0.25);
|
||||
b.text((7.0, 3.0), "Küche", 0.35).text((1.0, 8.0), "Zimmer", 0.35).text((1.0, 7.5), "1.07", 0.2);
|
||||
let r = analyze(&b.inp);
|
||||
assert!(r.layer_filter);
|
||||
assert_eq!(r.walls.len(), 8, "{:#?}", r.walls);
|
||||
for (a, bb, t) in [
|
||||
((0.0, 0.0), (12.0, 0.0), 0.3),
|
||||
((12.0, 0.0), (12.0, 6.0), 0.3),
|
||||
((12.0, 6.0), (6.0, 6.0), 0.3),
|
||||
((6.0, 6.0), (6.0, 10.0), 0.3),
|
||||
((6.0, 10.0), (0.0, 10.0), 0.3),
|
||||
((0.0, 10.0), (0.0, 0.0), 0.3),
|
||||
((6.0, 0.0), (6.0, 6.0), 0.15),
|
||||
((0.0, 6.0), (6.0, 6.0), 0.15),
|
||||
] {
|
||||
assert!(has_wall(&r, a, bb, t), "fehlt {a:?}–{bb:?} t={t}: {:#?}", r.walls);
|
||||
}
|
||||
// Aussenwände laufen gegen den Uhrzeigersinn (rechts = aussen).
|
||||
let bottom = r.walls.iter().find(|w| w.a.1.abs() < EPS && w.b.1.abs() < EPS).unwrap();
|
||||
assert!(bottom.b.0 > bottom.a.0);
|
||||
assert!(r.openings.is_empty(), "{:?}", r.openings);
|
||||
assert_eq!(r.rooms.len(), 3);
|
||||
let wohnen = r.rooms.iter().find(|x| x.name.as_deref() == Some("Wohnen")).expect("Wohnen");
|
||||
assert!((polygon_area(&wohnen.ring).abs() - 33.350625).abs() < 1e-6, "{:?}", wohnen.ring);
|
||||
assert_eq!(wohnen.sia, Some("HNF"));
|
||||
assert_eq!(wohnen.area_text, Some(33.35));
|
||||
assert!(r.rooms.iter().any(|x| x.name.as_deref() == Some("Küche")));
|
||||
// Grösster Text gewinnt vor der Raumnummer.
|
||||
assert!(r.rooms.iter().any(|x| x.name.as_deref() == Some("Zimmer")));
|
||||
assert!(r.unclear.is_empty(), "{:?}", r.unclear);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flaechenangabe_falsch_ist_unklar() {
|
||||
let mut b = l_house();
|
||||
b.text((7.0, 3.0), "Küche", 0.35).text((7.0, 2.0), "20.0 m2", 0.25).text((20.0, 2.0), "5 m²", 0.25);
|
||||
let r = analyze(&b.inp);
|
||||
let codes: Vec<&str> = r.unclear.iter().map(|u| u.code).collect();
|
||||
assert!(codes.contains(&"areaMismatch") && codes.contains(&"areaOutside"), "{codes:?}");
|
||||
}
|
||||
|
||||
/// Gerade Wand 6 m (30 cm) mit Lücken; Hilfe für die Öffnungs-Tests.
|
||||
fn wall_with_gaps(gaps: &[(f64, f64)]) -> B {
|
||||
let mut b = B::new();
|
||||
let mut x = 0.0;
|
||||
let mut spans = Vec::new();
|
||||
for &(g0, g1) in gaps {
|
||||
spans.push((x, g0));
|
||||
x = g1;
|
||||
}
|
||||
spans.push((x, 6.0));
|
||||
for (x0, x1) in spans {
|
||||
b.rect("Mauerwerk Wand", x0, -0.15, x1, 0.15);
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuer_mit_bogen_fenster_und_durchbruch() {
|
||||
let mut b = wall_with_gaps(&[(1.0, 1.9), (3.0, 4.2), (4.6, 5.4)]);
|
||||
// Tür: Scharnier am rechten Pfosten (x = 1.9), Blatt schlägt nach −y auf (Bogen 180°…270°).
|
||||
b.arc("Türen", (1.9, -0.12), 0.9, 180.0, 90.0).line("Türen", (1.9, -0.12), (1.9, -1.02));
|
||||
// Fenster: Glaslinien im Band.
|
||||
b.line("Fenster", (3.0, -0.03), (4.2, -0.03)).line("Fenster", (3.0, 0.03), (4.2, 0.03));
|
||||
let r = analyze(&b.inp);
|
||||
assert_eq!(r.walls.len(), 1, "{:#?}", r.walls);
|
||||
let w = &r.walls[0];
|
||||
assert!((w.t - 0.3).abs() < EPS);
|
||||
assert_eq!(w.material, Some("mauerwerk"));
|
||||
assert_eq!(r.openings.len(), 3, "{:#?}", r.openings);
|
||||
// Lage unabhängig von der Wandrichtung: Anfang des Pfostens in Weltkoordinaten.
|
||||
let u = mul(sub(w.b, w.a), 1.0 / len(sub(w.b, w.a)));
|
||||
let x_of = |o: &ROpening| {
|
||||
let p0 = add(w.a, mul(u, o.pos));
|
||||
let p1 = add(w.a, mul(u, o.pos + o.width));
|
||||
(p0.0.min(p1.0), p0.0.max(p1.0))
|
||||
};
|
||||
let door = r.openings.iter().find(|o| matches!(o.kind, RKind::Door { .. })).unwrap();
|
||||
let (x0, x1) = x_of(door);
|
||||
assert!((x0 - 1.0).abs() < EPS && (x1 - 1.9).abs() < EPS);
|
||||
let RKind::Door { hinge_end, swing_right, leaves } = door.kind else { unreachable!() };
|
||||
assert_eq!(leaves, 1);
|
||||
// Scharnier bei x = 1.9, Blatt auf −y — in Wandrichtung ausgedrückt.
|
||||
let hinge = add(w.a, mul(u, if hinge_end { door.pos + door.width } else { door.pos }));
|
||||
assert!((hinge.0 - 1.9).abs() < EPS);
|
||||
let n = (-u.1, u.0);
|
||||
let side = if swing_right { -1.0 } else { 1.0 };
|
||||
assert!(mul(n, side).1 < 0.0, "Aufschlag nach −y");
|
||||
let win = r.openings.iter().find(|o| o.kind == RKind::Window).unwrap();
|
||||
let (x0, x1) = x_of(win);
|
||||
assert!((x0 - 3.0).abs() < EPS && (x1 - 4.2).abs() < EPS);
|
||||
let void = r.openings.iter().find(|o| o.kind == RKind::Void).unwrap();
|
||||
let (x0, x1) = x_of(void);
|
||||
assert!((x0 - 4.6).abs() < EPS && (x1 - 5.4).abs() < EPS);
|
||||
assert!(r.unclear.is_empty(), "{:?}", r.unclear);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zweifluegelige_tuer_aus_zwei_halben_boegen() {
|
||||
let mut b = wall_with_gaps(&[(2.0, 3.6)]);
|
||||
b.arc("Türen", (2.0, 0.15), 0.8, 0.0, 90.0).arc("Türen", (3.6, 0.15), 0.8, 90.0, 90.0);
|
||||
let r = analyze(&b.inp);
|
||||
assert_eq!(r.openings.len(), 1);
|
||||
assert!(matches!(r.openings[0].kind, RKind::Door { leaves: 2, .. }), "{:?}", r.openings);
|
||||
assert!((r.openings[0].width - 1.6).abs() < EPS);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn breite_luecke_ohne_hinweis_trennt_waende() {
|
||||
let r = analyze(&wall_with_gaps(&[(2.0, 4.5)]).inp);
|
||||
assert_eq!(r.walls.len(), 2);
|
||||
assert!(r.openings.is_empty());
|
||||
// Mit Fensterlinien wird es eine Wand mit Fenster.
|
||||
let mut b = wall_with_gaps(&[(2.0, 4.5)]);
|
||||
b.line("Fenster", (2.0, 0.0), (4.5, 0.0));
|
||||
let r = analyze(&b.inp);
|
||||
assert_eq!(r.walls.len(), 1);
|
||||
assert_eq!(r.openings.len(), 1);
|
||||
assert_eq!(r.openings[0].kind, RKind::Window);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuer_in_der_ecke() {
|
||||
// Ecke bei (0,0): Wand 1 entlang x (Lücke 0.15–1.05 an der Ecke), Wand 2 entlang y.
|
||||
let mut b = B::new();
|
||||
b.ring("Wand", &[(-0.15, -0.15), (6.0, -0.15), (6.0, 0.15), (1.05, 0.15), (1.05, -0.15)]);
|
||||
b.line("Wand", (-0.15, -0.15), (-0.15, 5.0)).line("Wand", (0.15, 0.15), (0.15, 5.0)).line("Wand", (-0.15, 5.0), (0.15, 5.0));
|
||||
b.line("Wand", (-0.15, -0.15), (0.15, -0.15)).line("Wand", (0.15, -0.15), (0.15, 0.15));
|
||||
b.arc("Tür", (0.15, 0.15), 0.9, 0.0, 90.0);
|
||||
let r = analyze(&b.inp);
|
||||
assert_eq!(r.walls.len(), 2, "{:#?}", r.walls);
|
||||
assert!(has_wall(&r, (0.0, 0.0), (6.0, 0.0), 0.3), "{:#?}", r.walls);
|
||||
assert!(has_wall(&r, (0.0, 0.0), (0.0, 5.0), 0.3), "{:#?}", r.walls);
|
||||
assert_eq!(r.openings.len(), 1, "{:?} {:?}", r.openings, r.unclear);
|
||||
assert!(matches!(r.openings[0].kind, RKind::Door { leaves: 1, .. }));
|
||||
assert!((r.openings[0].width - 0.9).abs() < EPS);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bogenwand_aus_konzentrischen_boegen() {
|
||||
let mut b = B::new();
|
||||
b.arc("Wand", (0.0, 0.0), 4.85, 0.0, 90.0).arc("Wand", (0.0, 0.0), 5.15, 0.0, 90.0);
|
||||
b.line("Wand", (4.85, 0.0), (5.15, 0.0)).line("Wand", (0.0, 4.85), (0.0, 5.15));
|
||||
let r = analyze(&b.inp);
|
||||
assert_eq!(r.walls.len(), 1, "{:#?}", r.walls);
|
||||
let w = &r.walls[0];
|
||||
assert!((w.t - 0.3).abs() < EPS);
|
||||
assert!(near(w.a, (5.0, 0.0), 1e-9) && near(w.b, (0.0, 5.0), 1e-9), "{w:?}");
|
||||
let arc = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(w.a.0, w.a.1), kernel2d::Vec2::new(w.b.0, w.b.1), w.bulge).unwrap();
|
||||
assert!((arc.r - 5.0).abs() < 1e-9 && (arc.sweep - PI / 2.0).abs() < 1e-9, "{arc:?}");
|
||||
assert!(len(sub((arc.center.x, arc.center.y), (0.0, 0.0))) < 1e-9);
|
||||
// Kein Türbogen-Hinweis (die Bögen sind die Wand).
|
||||
assert!(r.unclear.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bogenwand_aus_polylinien_bulge() {
|
||||
// Polylinien-Bogen (Modell-Bulge, negativ = gegen den Uhrzeigersinn).
|
||||
let bl = -tan(PI / 8.0);
|
||||
let a1 = bulge_arc((4.85, 0.0), (0.0, 4.85), bl, 0).unwrap();
|
||||
let a2 = bulge_arc((5.15, 0.0), (0.0, 5.15), bl, 0).unwrap();
|
||||
assert!((a1.sweep - PI / 2.0).abs() < 1e-9 && a1.a0.abs() < 1e-9, "{a1:?}");
|
||||
let mut inp = Input::default();
|
||||
inp.layer("Wand");
|
||||
inp.arcs.extend([a1, a2]);
|
||||
let r = analyze(&inp);
|
||||
assert_eq!(r.walls.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layer_filter_ignoriert_moebel() {
|
||||
let mut b = wall_with_gaps(&[]);
|
||||
// Möbel parallel in 40 cm Abstand (wäre sonst eine Wand) und ein Tisch.
|
||||
b.line("Möbel", (1.0, 0.55), (4.0, 0.55)).rect("Möbel", 1.0, 2.0, 3.0, 2.4);
|
||||
b.line("Mauerwerk Wand", (8.0, 8.0), (12.0, 8.0));
|
||||
let r = analyze(&b.inp);
|
||||
assert!(r.layer_filter);
|
||||
assert_eq!(r.walls.len(), 1, "{:#?}", r.walls);
|
||||
// Die einsame Linie auf dem Wand-Layer ist unklar.
|
||||
assert_eq!(r.unclear.iter().filter(|u| u.code == "lineUnpaired").count(), 1, "{:?}", r.unclear);
|
||||
// Ohne Wand-Layer zählt alles: der Tisch (40 cm) wird eine Wand.
|
||||
let mut b = B::new();
|
||||
b.rect("0", 0.0, -0.15, 6.0, 0.15).rect("0", 1.0, 2.0, 3.0, 2.4);
|
||||
let r = analyze(&b.inp);
|
||||
assert!(!r.layer_filter);
|
||||
assert_eq!(r.walls.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schichtlinie_und_achslinie_ergeben_eine_wand() {
|
||||
let mut b = B::new();
|
||||
// Aussenwand 34.5 cm: Putz/Dämmung/Mauerwerk-Linien (Schichtgrenzen bei −0.1525 und 0.0075).
|
||||
for y in [-0.1725, -0.1525, 0.0075, 0.1575, 0.1725] {
|
||||
b.line("Wand", (0.0, y), (5.0, y));
|
||||
}
|
||||
let r = analyze(&b.inp);
|
||||
assert_eq!(r.walls.len(), 1, "{:#?}", r.walls);
|
||||
assert!((r.walls[0].t - 0.345).abs() < 1e-9);
|
||||
assert!(near(mul(add(r.walls[0].a, r.walls[0].b), 0.5), (2.5, 0.0), 1e-9));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schraffur_bestaetigt_und_gibt_material() {
|
||||
let mut b = wall_with_gaps(&[]);
|
||||
let l = b.inp.layer("Schraffur");
|
||||
b.inp.fills.push(FillIn { ring: vec![(0.0, -0.15), (6.0, -0.15), (6.0, 0.15), (0.0, 0.15)], layer: l, hatch: Some("Beton".into()) });
|
||||
let r = analyze(&b.inp);
|
||||
assert!(r.walls[0].filled);
|
||||
assert_eq!(r.walls[0].material, Some("beton"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn material_und_flaechentexte() {
|
||||
assert_eq!(material_of("A-WALL-CONC"), None);
|
||||
assert_eq!(material_of("Wand Beton"), Some("beton"));
|
||||
assert_eq!(material_of("MW 15"), Some("mauerwerk"));
|
||||
assert_eq!(material_of("Wand_KS"), Some("kalksandstein"));
|
||||
assert_eq!(material_of("Kasten"), None);
|
||||
assert_eq!(parse_area("17.01 m²"), Some(17.01));
|
||||
assert_eq!(parse_area("F: 17,5 m2"), Some(17.5));
|
||||
assert_eq!(parse_area("1'017 qm"), Some(1017.0));
|
||||
assert_eq!(parse_area("Wohnen"), None);
|
||||
assert!(wallish_layer("20_Wände") && wallish_layer("A-WALL") && wallish_layer("Mauerwerk") && !wallish_layer("Möbel"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsinn_ohne_panic() {
|
||||
let mut b = B::new();
|
||||
b.line("Wand", (f64::NAN, 0.0), (1.0, 0.0)).line("Wand", (0.0, 0.0), (0.0, 0.0)).arc("Wand", (0.0, 0.0), f64::INFINITY, 0.0, 90.0);
|
||||
b.line("Wand", (0.0, 0.0), (1e300, 1e300)).line("Wand", (0.0, 0.1), (1e300, 1e300));
|
||||
let _ = analyze(&b.inp);
|
||||
let _ = analyze(&Input::default());
|
||||
}
|
||||
|
||||
// ── Über das Projekt (Ops) ───────────────────────────────────────────────────
|
||||
|
||||
fn project(drawings: Vec<Value>) -> (Project, serde_json::Map<String, Value>) {
|
||||
let v = json!({
|
||||
"id": "p", "name": "t", "lineStyles": [], "hatches": [],
|
||||
"components": [{"id": "brick", "name": "Mauerwerk", "color": "#a0522d"}, {"id": "concrete", "name": "Beton", "color": "#999999"}],
|
||||
"wallTypes": [{"id": "aw", "name": "Aussenwand 30", "layers": [{"componentId": "brick", "thickness": 0.3}]}],
|
||||
"doorTypes": [{"id": "dt1", "name": "Tür", "kind": "dreh", "leafCount": 1, "leafStyle": "glatt", "frameThickness": 0.06}],
|
||||
"layers": [
|
||||
{"code": "20", "name": "Wände", "color": "#000000", "lw": 0.5, "visible": true, "locked": false},
|
||||
{"code": "21", "name": "Türen/Fenster", "color": "#000000", "lw": 0.25, "visible": true, "locked": false},
|
||||
{"code": "60", "name": "Räume", "color": "#6b7280", "lw": 0.1, "visible": true, "locked": false},
|
||||
{"code": "101", "name": "A-WALL", "color": "#000000", "lw": 0.5, "visible": true, "locked": false},
|
||||
{"code": "102", "name": "A-DOOR", "color": "#000000", "lw": 0.25, "visible": true, "locked": false},
|
||||
{"code": "103", "name": "A-ANNO", "color": "#000000", "lw": 0.25, "visible": true, "locked": false}
|
||||
],
|
||||
"openings": [], "walls": [],
|
||||
"drawingLevels": [
|
||||
{"id": "eg", "name": "EG", "kind": "floor", "visible": true, "locked": false, "floorHeight": 2.8},
|
||||
{"id": "imp", "name": "Import", "kind": "drawing", "visible": true, "locked": false}
|
||||
],
|
||||
"drawings2d": drawings
|
||||
});
|
||||
let p: Project = serde_json::from_value(v.clone()).unwrap();
|
||||
(p, v.as_object().unwrap().clone())
|
||||
}
|
||||
|
||||
fn dl(id: &str, code: &str, geom: Value) -> Value {
|
||||
json!({"id": id, "type": "drawing2d", "levelId": "imp", "categoryCode": code, "geom": geom})
|
||||
}
|
||||
|
||||
fn poly(pts: &[V]) -> Value {
|
||||
json!({"shape": "polyline", "closed": true, "pts": pts.iter().map(|p| json!({"x": p.0, "y": p.1})).collect::<Vec<_>>()})
|
||||
}
|
||||
|
||||
/// Raum 5 × 4 (Achsen) mit Aussenwänden 30 cm und Innenwand 15 cm, Tür mit Bogen, Raumtext.
|
||||
fn small_house() -> Vec<Value> {
|
||||
vec![
|
||||
dl("o", "101", poly(&[(-0.15, -0.15), (1.0, -0.15), (1.0, 0.15), (0.15, 0.15), (0.15, 3.85), (4.85, 3.85), (4.85, 0.15), (1.9, 0.15), (1.9, -0.15), (5.15, -0.15), (5.15, 4.15), (-0.15, 4.15)])),
|
||||
dl("i", "101", poly(&[(2.425, 0.15), (2.575, 0.15), (2.575, 3.85), (2.425, 3.85)])),
|
||||
dl("arc", "102", json!({"shape": "arc", "center": {"x": 1.0, "y": 0.0}, "r": 0.9, "a0": 0.0, "a1": PI / 2.0})),
|
||||
dl("t1", "103", json!({"shape": "text", "at": {"x": 0.5, "y": 2.0}, "text": "Wohnen", "height": 0.35, "angle": 0.0})),
|
||||
dl("t2", "103", json!({"shape": "text", "at": {"x": 0.5, "y": 1.5}, "text": "9.5 m²", "height": 0.25, "angle": 0.0})),
|
||||
]
|
||||
}
|
||||
|
||||
/// Neue Elemente einer Liste aus den Ops.
|
||||
fn added(ops: &[Op], coll: &str) -> Vec<Value> {
|
||||
ops.iter()
|
||||
.filter_map(|o| match o {
|
||||
Op::Add { collection, items, .. } if collection == coll => Some(items.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.flatten()
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn req(extra: Value) -> Value {
|
||||
let mut v = json!({"cmd": "recognize", "src": "imp", "stamp": "s", "typeName": "Wand {cm} cm (erkannt)",
|
||||
"ctx": {"level": "eg", "floorHeight": 2.8, "cat": "20", "wallType": "aw"}});
|
||||
for (k, x) in extra.as_object().unwrap() {
|
||||
v[k] = x.clone();
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ops_waende_typen_oeffnungen_raeume() {
|
||||
let (p, root) = project(small_house());
|
||||
let ops = crate::cmd_create::ops(&root, &p, &req(json!({}))).expect("recognize");
|
||||
let items = |coll: &str| added(&ops, coll);
|
||||
let walls = items("walls");
|
||||
assert_eq!(walls.len(), 5, "{walls:#?}");
|
||||
// 30 cm: vorhandener Typ; 15 cm: neuer Typ (Baustoff des aktiven Typs).
|
||||
assert_eq!(walls.iter().filter(|w| w["wallTypeId"] == "aw").count(), 4);
|
||||
let types = items("wallTypes");
|
||||
assert_eq!(types.len(), 1, "{types:?}");
|
||||
assert_eq!(types[0]["name"], "Wand 15 cm (erkannt)");
|
||||
assert_eq!(types[0]["layers"][0]["componentId"], "brick");
|
||||
assert!(walls.iter().all(|w| w["floorId"] == "eg" && w["height"] == 2.8 && w["categoryCode"] == "20"));
|
||||
let openings = items("openings");
|
||||
assert_eq!(openings.len(), 1, "{openings:?}");
|
||||
let o = &openings[0];
|
||||
assert_eq!(o["kind"], "door");
|
||||
assert_eq!(o["typeId"], "dt1");
|
||||
assert_eq!(o["sillHeight"], 0.0);
|
||||
assert!((o["width"].as_f64().unwrap() - 0.9).abs() < 1e-9);
|
||||
let host = walls.iter().find(|w| w["id"] == o["hostWallId"]).unwrap();
|
||||
assert_eq!(host["wallTypeId"], "aw");
|
||||
let rooms = items("rooms");
|
||||
assert_eq!(rooms.len(), 2);
|
||||
assert!(rooms.iter().any(|r| r["name"] == "Wohnen" && r["categoryCode"] == "60"));
|
||||
// Alles typisiert lesbar.
|
||||
for w in &walls {
|
||||
let _: crate::model::Wall = serde_json::from_value(w.clone()).unwrap();
|
||||
}
|
||||
let _: crate::model::Opening = serde_json::from_value(o.clone()).unwrap();
|
||||
for r in &rooms {
|
||||
let _: crate::model::Room = serde_json::from_value(r.clone()).unwrap();
|
||||
}
|
||||
for t in &types {
|
||||
let _: crate::model::WallType = serde_json::from_value(t.clone()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auswahl_vorschau_und_bericht() {
|
||||
let (p, root) = project(small_house());
|
||||
// Nur die Innenwand gewählt: eine Wand.
|
||||
let ops = crate::cmd_create::ops(&root, &p, &req(json!({"ids": ["i"]}))).unwrap();
|
||||
let n = added(&ops, "walls").len();
|
||||
// Ohne Gegen-Wände kein Stoss; ein Wand-Layer mit 4 Linien → Filter an.
|
||||
assert_eq!(n, 1);
|
||||
let pv = crate::cmd_create::preview(&root, &p, &req(json!({})), &[]);
|
||||
assert!(pv.ok);
|
||||
assert_eq!(pv.info, vec![5.0, 1.0, 0.0, 0.0, 2.0, 1.0]);
|
||||
let rep = report(&p, &json!({"q": "recognize", "level": "eg", "src": "imp"}));
|
||||
assert_eq!(rep["walls"], 5);
|
||||
assert_eq!(rep["doors"], 1);
|
||||
assert_eq!(rep["layerFilter"], true);
|
||||
// „9.5 m²“ steht im westlichen Raum (2.275 × 3.7 = 8.4175 m²): Abweichung > 5 %.
|
||||
assert_eq!(rep["unclear"][0]["code"], "areaMismatch");
|
||||
// Leere Ebene: nichts.
|
||||
let pv = crate::cmd_create::preview(&root, &p, &req(json!({"src": "eg"})), &[]);
|
||||
assert!(!pv.ok);
|
||||
assert!(crate::cmd_create::ops(&root, &p, &req(json!({"src": "eg"}))).unwrap().is_empty());
|
||||
}
|
||||
|
||||
/// Erker wie im Musterhaus komplex: gerade Wand – halbkreisförmige Bogenwand – gerade Wand, der Bogen im
|
||||
/// DXF in Sehnen zerlegt (Polylinie ohne Bulge). → drei Wände, Bogenwand mit Mittelpunkt/Radius, Stösse auf
|
||||
/// den Achsen.
|
||||
#[test]
|
||||
fn tessellierter_erker() {
|
||||
let (c, t): (V, f64) = ((15.0, 5.0), 0.39);
|
||||
let arc_pts = |r: f64, a0: f64, a1: f64, n: usize| -> Vec<V> {
|
||||
(0..=n)
|
||||
.map(|i| {
|
||||
let a = a0 + (a1 - a0) * i as f64 / n as f64;
|
||||
(c.0 + r * a.cos(), c.1 + r * a.sin())
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
let ro = 2.0 + t / 2.0;
|
||||
let ri = 2.0 - t / 2.0;
|
||||
let ao = (t / 2.0 / ro).asin();
|
||||
let ai = (t / 2.0 / ri).asin();
|
||||
// Aussen: x = 15.195 und der äussere Bogen; innen: x = 14.805 und der innere Bogen.
|
||||
let mut outer = vec![(15.195, 0.0)];
|
||||
outer.extend(arc_pts(ro, -PI / 2.0 + ao, PI / 2.0 - ao, 24));
|
||||
outer.push((15.195, 10.0));
|
||||
let mut inner = vec![(14.805, 0.0)];
|
||||
inner.extend(arc_pts(ri, -PI / 2.0 - ai, PI / 2.0 + ai, 24));
|
||||
inner.push((14.805, 10.0));
|
||||
let mut inp = Input::default();
|
||||
let l = inp.layer("Wand");
|
||||
fit_arcs(&outer, l, &mut inp.segs, &mut inp.arcs);
|
||||
fit_arcs(&inner, l, &mut inp.segs, &mut inp.arcs);
|
||||
assert_eq!(inp.arcs.len(), 2, "{:?}", inp.arcs);
|
||||
assert!(inp.arcs.iter().all(|a| len(sub(a.c, c)) < 1e-9));
|
||||
let r = analyze(&inp);
|
||||
assert_eq!(r.walls.len(), 3, "{:#?}", r.walls);
|
||||
assert!(has_wall(&r, (15.0, 0.0), (15.0, 3.0), t) && has_wall(&r, (15.0, 7.0), (15.0, 10.0), t), "{:#?}", r.walls);
|
||||
let w = r.walls.iter().find(|w| w.bulge.is_some()).unwrap();
|
||||
assert!(near(w.a, (15.0, 3.0), 1e-6) && near(w.b, (15.0, 7.0), 1e-6), "{w:?}");
|
||||
let arc = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(w.a.0, w.a.1), kernel2d::Vec2::new(w.b.0, w.b.1), w.bulge).unwrap();
|
||||
assert!((arc.r - 2.0).abs() < 1e-6 && len(sub((arc.center.x, arc.center.y), c)) < 1e-6, "{arc:?}");
|
||||
// Fenster im Bogen: Bogenwand mit Lücke 60°–75° (Fensterbögen im Band) → eine Bogenwand mit Fenster.
|
||||
let mut inp = Input::default();
|
||||
let l = inp.layer("Wand");
|
||||
let f = inp.layer("Fenster");
|
||||
for (r0, a0, sw) in [(ro, -60.0, 120.0), (ri, -60.0, 120.0), (ro, 75.0, 30.0), (ri, 75.0, 30.0)] {
|
||||
inp.arcs.push(ArcIn { c, r: r0, a0: wrap2pi(f64::to_radians(a0)), sweep: f64::to_radians(sw), layer: l });
|
||||
}
|
||||
inp.arcs.push(ArcIn { c, r: 2.0, a0: f64::to_radians(60.0), sweep: f64::to_radians(15.0), layer: f });
|
||||
let r = analyze(&inp);
|
||||
assert_eq!(r.walls.len(), 1, "{:#?}", r.walls);
|
||||
assert_eq!(r.openings.len(), 1, "{:?}", r.openings);
|
||||
assert_eq!(r.openings[0].kind, RKind::Window);
|
||||
assert!((r.openings[0].pos - 2.0 * f64::to_radians(120.0)).abs() < 1e-6 && (r.openings[0].width - 2.0 * f64::to_radians(15.0)).abs() < 1e-6, "{:?}", r.openings);
|
||||
// Rechtecke und Zickzack bleiben gerade.
|
||||
let mut segs = Vec::new();
|
||||
let mut arcs = Vec::new();
|
||||
fit_arcs(&[(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0)], 0, &mut segs, &mut arcs);
|
||||
fit_arcs(&[(0.0, 0.0), (1.0, 0.1), (2.0, 0.0), (3.0, 0.1), (4.0, 0.0)], 0, &mut segs, &mut arcs);
|
||||
assert!(arcs.is_empty());
|
||||
assert_eq!(segs.len(), 8);
|
||||
}
|
||||
@@ -128,5 +128,6 @@ pub mod opening_slide;
|
||||
#[cfg(feature = "web")]
|
||||
mod web;
|
||||
pub mod presentation_sheet;
|
||||
pub mod drawing_recognize;
|
||||
#[cfg(test)]
|
||||
mod wall_join3d_tests;
|
||||
Reference in new issue
Block a user