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

This commit is contained in:
Claude committed 2026-11-11 07:44:48 +00:00
commit e4c2d1806a
6 files changed
+209 -44

No files matched your search

+6 -4
View File
@@ -85,10 +85,12 @@ Wer zu einer ID mehr wissen will (Entscheide, Tests, Bilder), sucht dort nach `*
gedämpft (render3d hat nur `set_ghost` für die Hülle); natives Mac-3D-Fenster bekommt nur den Ebenen-Baum, nicht
den Darstellungsmodus; Datei-Exporte (OBJ/glTF/IFC/STEP) bleiben vollständig; kein e2e (3D-Pick headless unzuverlässig);
nicht in der Tauri-App/auf dem Mac geprüft. · M
- ◐ **[133]** Musterhaus komplex: Rest. Skalieren-Kopie lässt `position`/Breite unverändert; Vollflächen-/Bildschraffur
und Schraffur-Löcher beim Ausbreiten fehlen (`src/export/planToSvgString.ts`, Kern `plan/svg.rs`; wegen paralleler
Arbeit an `svg.rs` (Bögen) am 10.11. nicht angefasst). (10.11.: Skalieren skaliert `position`/`width` der Wandöffnungen
bei Kopie und Original, Test `skalieren_skaliert_oeffnungen`.) · S
- ◐ **[133]** Musterhaus komplex: Rest. Skalieren-Kopie lässt `position`/Breite unverändert (10.11.: Skalieren skaliert
`position`/`width` der Wandöffnungen bei Kopie und Original, Test `skalieren_skaliert_oeffnungen`). 11.11.: Schraffur-
Ausbreiten: Vollfläche füllt in Schraffurfarbe, Bild-Schraffur als `<pattern>`/`<image>` (CLI `--hatch`; Druck/PDF hatte
beides schon), eine gemeinsame Linien-Funktion `print_svg::hatch_runs`; Löcher (Ring mit Brücke) liefen schon richtig,
jetzt per Test belegt (`plan/hatch_fill_tests.rs`, Szene/CLI/Druck). Bildschirm (render2d) zeichnet Vollflächen-/Bild-
Schraffur nicht selbst (Füllung des Erzeugers) und Verläufe fehlen in allen Ausgaben. Nur im Linux-Container geprüft. · S
- ◐ **[140]** Plandarstellung. (9.11.: Stempel in Tusche ohne farbige Auszeichnung, eigene Stempel ab 1:200
verkleinert, IFC-Räume ohne festen Anker, Schatten-Reihenfolge geprüft; Rest der Liste war schon erledigt.)
Offen: Fang-Punkt des Stempels rechnet mit Detail „mittel“; Deckenspiegel-Stempel ohne Hindernisse; Mac-Gegenprobe
+2 -2
View File
@@ -44,7 +44,7 @@ fn base() -> Project {
type Axis = Box<dyn Fn(V2) -> V2>;
/// Gezeichneter Lauf (Linie/Polylinie) in Modell-Metern.
type Seg = Vec<V2>;
pub(super) type Seg = Vec<V2>;
fn unit(x: f64, y: f64) -> V2 {
let l = x.hypot(y);
@@ -131,7 +131,7 @@ fn check(bands: &[(Vec<V2>, Axis)], runs: &[Seg], what: &str) {
}
/// Die drei Ausgaben eines Plan-Puffers: Linien der Szene, des CLI-SVG und des Druck-SVG.
fn rendered(prims: &[Primitive], scale: f64) -> Vec<(&'static str, Vec<Seg>)> {
pub(super) fn rendered(prims: &[Primitive], scale: f64) -> Vec<(&'static str, Vec<Seg>)> {
let mut w = Writer::new(true);
w.group(prims);
let bytes = w.finish();
+120
View File
@@ -0,0 +1,120 @@
//! [133] Vollflächen-, Bild-Schraffur und Löcher beim Ausbreiten der Schraffur (CLI-SVG `--hatch`,
//! Druck-SVG der Layout-Blätter). Der Bildschirm (render2d-Szene) zeichnet weder Vollflächen- noch Bildschraffur
//! selbst (die Fläche trägt die Füllung des Erzeugers); die Ausgaben mit Blatt-Treue (CLI, Druck/PDF) füllen mit
//! Schraffurfarbe bzw. kacheln das Bild. Löcher reisen als Ring mit Brücke (`polygon_holes::merge_holes`); die
//! Schraffur darf nicht in das Loch laufen.
use super::buf::{View, Writer};
use super::hatch_dir_tests::{rendered, Seg};
use super::parts::Part;
use super::prim::Primitive;
use crate::hatch::V2;
use crate::model::{HatchPattern, HatchStyleImage, HatchStyleKind, Vec2};
fn poly(pts: Vec<Vec2>, fill: &str, hatch: crate::plan::prim::HatchRender, nse: Option<Vec<f64>>) -> Primitive {
Primitive::Polygon {
pts,
fill: fill.into(),
stroke: "#000000".into(),
stroke_width_mm: 0.25,
hatch: Box::new(hatch),
greyed: None,
opacity: None,
no_stroke_edges: nse,
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,
}
}
fn rect(x0: f64, y0: f64, x1: f64, y1: f64) -> Vec<[f64; 2]> {
vec![[x0, y0], [x1, y0], [x1, y1], [x0, y1]]
}
fn svgs(p: &Primitive, scale: f64, hatch: bool) -> (String, String) {
let mut w = Writer::new(true);
w.group(std::slice::from_ref(p));
let bytes = w.finish();
let parts = || {
let view = View::parse(&bytes).unwrap();
let n = view.len();
vec![Part::new(view, 0, n).unwrap()]
};
let o = super::svg::SvgOptions { scale_denominator: scale, margin_m: 0.0, min_x: 0.0, min_y: 0.0, max_x: 4.0, max_y: 4.0, hatch, line_ends: Default::default() };
let svg = super::svg::plan_svg(&mut parts(), &o).unwrap();
let po = super::print_svg::PrintOptions { scale_denominator: scale, page_w: 4.0 * 1000.0 / scale, page_h: 4.0 * 1000.0 / scale, bounds: [0.0, 0.0, 4.0, 4.0] };
let ops = super::print_svg::print_svg_ops(&mut parts(), &po).unwrap();
(svg, ops)
}
fn square() -> Vec<Vec2> {
[[0.0, 0.0], [4.0, 0.0], [4.0, 4.0], [0.0, 4.0]].iter().map(|p| Vec2 { x: p[0], y: p[1] }).collect()
}
#[test]
fn schraffur_laeuft_nicht_ins_loch() {
let mut h = crate::plan::style::no_hatch();
h.pattern = HatchPattern::Diagonal;
h.scale = 1.0;
h.angle = 45.0;
let merged = crate::polygon_holes::merge_holes(&rect(0.0, 0.0, 4.0, 4.0), &[rect(1.0, 1.0, 3.0, 3.0)], 1e-4);
assert!(!merged.bridge_edges.is_empty());
let ring: Vec<Vec2> = merged.ring.iter().map(|q| Vec2 { x: q[0], y: q[1] }).collect();
let nse: Vec<f64> = merged.bridge_edges.iter().map(|&k| k as f64).collect();
let p = poly(ring, "#ffffff", h, Some(nse));
for (what, segs) in rendered(std::slice::from_ref(&p), 50.0) {
let n: usize = segs.iter().map(|s| s.len()).sum();
assert!(n > 20, "{what}: Schraffur fehlt ({n})");
let hatch_segs: Vec<&Seg> = segs.iter().filter(|s| s.len() >= 2).collect();
let mut in_ring = 0;
for s in &hatch_segs {
for w in s.windows(2) {
let m = V2 { x: (w[0].x + w[1].x) / 2.0, y: (w[0].y + w[1].y) / 2.0 };
// Mitte der Teilstrecke strikt im Loch (Umriss und Brücke liegen auf dem Rand: Toleranz).
let in_hole = m.x > 1.01 && m.x < 2.99 && m.y > 1.01 && m.y < 2.99;
assert!(!in_hole, "{what}: Schraffurlinie im Loch bei {m:?}");
in_ring += 1;
}
}
assert!(in_ring > 10, "{what}: zu wenig Linien im Ring");
}
}
#[test]
fn vollflaeche_als_gefuelltes_polygon() {
let mut h = crate::plan::style::no_hatch();
h.pattern = HatchPattern::Solid;
h.color = "#223344".into();
let p = poly(square(), "none", h, None);
let (svg, ops) = svgs(&p, 50.0, true);
let line = svg.lines().find(|l| l.starts_with("<polygon")).expect("Polygon");
assert!(line.contains("fill=\"#223344\""), "CLI-Vollfläche in Schraffurfarbe: {line}");
assert!(!svg.contains("<line"), "keine Schraffurlinien bei Vollfläche");
assert!(ops.contains("#223344"), "Druck: {ops}");
}
#[test]
fn bildschraffur_als_pattern() {
let mut h = crate::plan::style::no_hatch();
h.pattern = HatchPattern::Diagonal;
h.kind = Some(HatchStyleKind::Image);
h.image = Some(HatchStyleImage { src: "data:image/png;base64,AAAA".into(), scale_x: 2.0, scale_y: 1.0, rotation: 30.0, ..Default::default() });
let p = poly(square(), "#eeeeee", h, None);
let (svg, ops) = svgs(&p, 50.0, true);
assert!(svg.contains("<defs>") && svg.contains("<pattern id=\"imgpat-"), "{svg}");
assert!(svg.contains("<image href=\"data:image/png;base64,AAAA\""), "{svg}");
assert!(svg.contains("patternTransform=\"rotate(30)\""), "{svg}");
assert!(svg.contains("fill=\"url(#imgpat-"), "{svg}");
assert!(ops.contains("I\x1f"), "Druck kachelt das Bild: {ops}");
// Ohne `hatch` bleibt es bei der Grundfüllung.
let (plain, _) = svgs(&p, 50.0, false);
assert!(!plain.contains("<pattern"));
}
+2
View File
@@ -46,6 +46,8 @@ pub(crate) mod wall_join_tests;
#[cfg(test)]
mod hatch_dir_tests;
#[cfg(test)]
mod hatch_fill_tests;
#[cfg(test)]
mod arc_output_tests;
#[cfg(test)]
mod derived_class_tests;
+29 -20
View File
@@ -346,6 +346,25 @@ pub(super) fn hatch_dash_paper(h: &Hatch, mm_per_m: f64) -> Vec<f64> {
hatch::hatch_dash(h).iter().map(|d| jsnum::max(0.0, *d) * hatch::DASH_MM_TO_M * mm_per_m).collect()
}
/// [133] Kachelgrösse einer Bild-Schraffur bei Massstab-Faktor 1 (Papier-mm), wie `IMG_TILE_MM` in `planToPrintSvg.ts`.
pub(super) const IMG_TILE_MM: f64 = 20.0;
/// [133] Bild-Schraffur (JSON `{src, scaleX, scaleY, rotation}`): Kachelbreite/-höhe in Papier-mm und Drehung (Grad).
pub(super) fn image_tile(img: &serde_json::Value) -> (f64, f64, f64) {
let sc = |k: &str| img.get(k).and_then(|v| v.as_f64()).filter(|v| *v > 0.0).unwrap_or(1.0);
(jsnum::max(0.5, IMG_TILE_MM * sc("scaleX")), jsnum::max(0.5, IMG_TILE_MM * sc("scaleY")), img.get("rotation").and_then(|v| v.as_f64()).unwrap_or(0.0))
}
/// [133] Linienzüge einer Vektor-Schraffur in Modell-Metern — der eine Generator für CLI-SVG (`svg.rs`) und
/// Druck-SVG (zufällige Schraffur: nur Anfang/Ende je Lauf; sonst `hatch::build_hatch_runs` wie Szene und PDF).
pub(super) fn hatch_runs(pts: &[V2], h: &Hatch) -> Vec<Vec<V2>> {
if h.random {
hatch::build_random_hatch_runs(pts, h, None).into_iter().filter(|r| r.len() >= 2).map(|r| vec![r[0], r[r.len() - 1]]).collect()
} else {
hatch::build_hatch_runs(pts, h)
}
}
fn num(o: &serde_json::Value, k: &str) -> f64 {
o.get(k).and_then(|x| x.as_f64()).unwrap_or(f64::NAN)
}
@@ -430,26 +449,16 @@ fn entry(out: &mut Out, view: &View, i: usize, hatches: &[(i32, Hatch, i32)], m:
}
let pen = quantize_pen(h.line_weight);
let hdash = hatch_dash_paper(&h, k);
if h.random {
for run in hatch::build_random_hatch_runs(&pts, &h, None) {
if run.len() < 2 {
continue;
}
let (a, b) = (run[0], run[run.len() - 1]);
out.el(1, "line", &line_attrs(m.at(a.x, a.y), m.at(b.x, b.y), &hatch_color, pen, Some(&hdash)));
}
} else {
// Alle Vektor-Schraffuren aus dem Kern-Generator: dieselben Linien wie Szene, PDF-Export und
// Chunk-Pfad ([109] Schicht-/Streumuster; [166] auch Geraden-/Kreuzschar und Motiv: die
// frühere eigene Linienschar las den Winkel um 90° verdreht — Dämm-Striche längs statt quer —
// und kannte die polare Schraffur der Bogenwand nicht).
for run in hatch::build_hatch_runs(&pts, &h) {
let p: Vec<V2> = run.iter().map(|q| m.at(q.x, q.y)).collect();
match p.len() {
0 | 1 => {}
2 => out.el(1, "line", &line_attrs(p[0], p[1], &hatch_color, pen, Some(&hdash))),
_ => out.el(1, "polyline", &polyline_attrs(&p, &hatch_color, pen, Some(&hdash))),
}
// Alle Vektor-Schraffuren aus dem Kern-Generator: dieselben Linien wie Szene, PDF-Export und
// Chunk-Pfad ([109] Schicht-/Streumuster; [166] auch Geraden-/Kreuzschar und Motiv: die
// frühere eigene Linienschar las den Winkel um 90° verdreht — Dämm-Striche längs statt quer —
// und kannte die polare Schraffur der Bogenwand nicht).
for run in hatch_runs(&pts, &h) {
let p: Vec<V2> = run.iter().map(|q| m.at(q.x, q.y)).collect();
match p.len() {
0 | 1 => {}
2 => out.el(1, "line", &line_attrs(p[0], p[1], &hatch_color, pen, Some(&hdash))),
_ => out.el(1, "polyline", &polyline_attrs(&p, &hatch_color, pen, Some(&hdash))),
}
}
if stroke_mm > 0.0 {
+50 -18
View File
@@ -2,13 +2,13 @@
//! MCP und Referenzbild-Tests, direkt aus den Abschnitten eines zusammengesetzten Plans
//! ([`crate::plan::parts`]). Koordinaten in Metern (Y nach oben → SVG gespiegelt), Strichstärken
//! aus Papier-mm über den Massstab; Schraffur-Muster werden nur mit `hatch` ausgebreitet (sonst nur Grundfüllung),
//! Bilder und Textpfade fehlen — gedacht für Kontrolle und Diffs, nicht für Druck. Byte-gleich zur
//! Vollflächen-Schraffur (Füllung) und Bild-Schraffur (`<pattern>`) nur mit `hatch`, Textpfade fehlen — gedacht für Kontrolle und Diffs, nicht für Druck. Byte-gleich zur
//! TS-Fassung (Zahlen wie `String(Math.round(v·1e5)/1e5)`, Texte aus dem Text-JSON des Puffers).
use crate::js_fmt::js_number;
use crate::hatch::{self, Pattern, V2};
use crate::jsnum;
use crate::plan::print_svg::{hatch_dash_paper, quantize_pen};
use crate::plan::print_svg::{hatch_dash_paper, hatch_runs, image_tile, quantize_pen};
use crate::plan::buf::{whole, F_COLOR, F_DASH_LIST, F_GREYED, F_OPACITY, T_ARC, T_CIRCLE, T_DRAWING_ARC, T_DRAWING_TEXT, T_LINE, T_POLYGON, T_TEXT};
use crate::plan::line_ends::LineEnds;
use crate::plan::parts::Part;
@@ -262,6 +262,9 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option<String> {
let ys = |y: f64| num(top - y);
let mut out: Vec<String> = Vec::new();
let mut stitch = Stitcher::default();
// [133] Muster der Bild-Schraffuren (je Bild einmal).
let mut defs: Vec<String> = Vec::new();
let mut patterns: HashMap<String, String> = HashMap::new();
// [153] Gestrichelte Linien, die aneinander anschliessen, als EIN Zug (Phase über die Ecken).
let mut run: Option<DashRun> = None;
for part in parts.iter_mut() {
@@ -298,8 +301,15 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option<String> {
// nachtesselierten Ring beschnitten (endet am Bogen, nicht an der Sehne).
let (geo, _) = shape_el(&pts, true, &xs, &ys, top);
let hatch_pts = if geo.starts_with("polygon") { pts.clone() } else { arc_fit::refine(&pts, true, arc_fit::TOL, &arc_fit::fine_segments).unwrap_or_else(|| pts.clone()) };
let fill = esc(part.str(f[0]).unwrap_or(""));
let mut fill = esc(part.str(f[0]).unwrap_or(""));
let stroke = esc(part.str(f[1]).unwrap_or(""));
// [133] Schraffur-Eintrag der Fläche; Vollfläche füllt in Schraffurfarbe (wie Druck/PDF).
let hent = if o.hatch && f[3] >= 0.0 { Some(hatches.get(whole(f[3])?)?.clone()) } else { None };
if let Some((_, h, color)) = &hent {
if h.pattern == Pattern::Solid && h.kind != hatch::HatchKind::Image {
fill = if *color >= 0 { esc(&part.view.string(*color as usize)?) } else { "#000".into() };
}
}
// Nicht gestrichene Kanten (Stossfugen, Lücken an Anschlüssen): Fläche ohne Strich,
// die übrigen Kanten als offener Pfad — wie der GPU-Pfad (`stroke_polygon_outline`).
let nse: Vec<usize> = match rec.nse {
@@ -328,29 +338,50 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option<String> {
op(greyed, opacity(4))
));
}
// [133] Bild-Schraffur: gekacheltes `<pattern>` über die Fläche (wie Druck/PDF), Umriss darüber.
if let Some((json, h, _)) = &hent {
if h.kind == hatch::HatchKind::Image && *json >= 0 {
let j: Value = serde_json::from_str(&part.view.string(*json as usize)?).unwrap_or(Value::Null);
if let Some(img) = j.get("image").filter(|v| v.is_object()) {
let key = img.to_string();
let id = match patterns.get(&key) {
Some(id) => id.clone(),
None => {
let id = format!("imgpat-{}", patterns.len());
let (tw, th, rot) = image_tile(img);
let (tw, th) = (num(tw * mm_to_m), num(th * mm_to_m));
let tf = if rot != 0.0 { format!(" patternTransform=\"rotate({})\"", num(rot)) } else { String::new() };
defs.push(format!(
"<pattern id=\"{id}\" patternUnits=\"userSpaceOnUse\" width=\"{tw}\" height=\"{th}\"{tf}><image href=\"{}\" x=\"0\" y=\"0\" width=\"{tw}\" height=\"{th}\" preserveAspectRatio=\"none\"/></pattern>",
esc(jstr(img, "src").unwrap_or(""))
));
patterns.insert(key, id.clone());
id
}
};
out.push(format!("<{geo} fill=\"url(#{id})\" stroke=\"none\"{}/>", op(greyed, opacity(4))));
if nse.is_empty() && stroke != "none" && !stroke.is_empty() && f[2] > 0.0 {
out.push(format!("<{geo} fill=\"none\" stroke=\"{stroke}\" stroke-width=\"{}\"{}/>", num(f[2] * mm_to_m), op(greyed, opacity(4))));
}
}
}
}
// [140] Schraffur auch bei Kantenläufen (Wandschichten mit offenen Kanten).
if o.hatch && f[3] >= 0.0 {
let (_, h, color) = hatches.get(whole(f[3])?)?.clone();
if h.pattern != Pattern::None && h.pattern != Pattern::Solid && h.kind != hatch::HatchKind::Image {
let hc = if color >= 0 { esc(&part.view.string(color as usize)?) } else { "#000".into() };
if let Some((_, h, color)) = &hent {
if h.pattern != Pattern::None && h.pattern != Pattern::Solid && h.kind == hatch::HatchKind::Vector {
let hc = if *color >= 0 { esc(&part.view.string(*color as usize)?) } else { "#000".into() };
let k = 1000.0 / n;
let pen = num(quantize_pen(h.line_weight) * mm_to_m);
let dash = hatch_dash_paper(&h, k);
let dash = hatch_dash_paper(h, k);
let da = if dash.is_empty() {
String::new()
} else {
let cap = if dash.iter().any(|v| *v == 0.0) { " stroke-linecap=\"round\"" } else { "" };
format!(" stroke-dasharray=\"{}\"{cap}", dash.iter().map(|v| num(v * mm_to_m)).collect::<Vec<_>>().join(" "))
};
let mut runs: Vec<Vec<V2>> = Vec::new();
if h.random {
runs.extend(hatch::build_random_hatch_runs(&hatch_pts, &h, None).into_iter().filter(|r| r.len() >= 2).map(|r| vec![r[0], r[r.len() - 1]]));
} else {
// [166] Alle Vektor-Schraffuren aus dem Kern-Generator wie Szene/PDF (Winkel-Lesart
// der SVG-Kachel, polare Schraffur der Bogenwand).
runs.extend(hatch::build_hatch_runs(&hatch_pts, &h));
}
for run in runs {
// [166] Alle Vektor-Schraffuren aus dem Kern-Generator wie Szene/PDF/Druck-SVG (Winkel-Lesart
// der SVG-Kachel, polare Schraffur der Bogenwand); [133] Löcher: Ring mit Brücke, even-odd.
for run in hatch_runs(&hatch_pts, h) {
match run.len() {
0 | 1 => {}
2 => out.push(format!(
@@ -495,7 +526,7 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option<String> {
stitch.finish(&mut out, &xs, &ys, top);
out.retain(|s| !s.is_empty());
Some(format!(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"{} 0 {} {}\" width=\"{}mm\" height=\"{}mm\">\n<rect x=\"{}\" y=\"0\" width=\"{}\" height=\"{}\" fill=\"#ffffff\"/>\n<g {}>\n{}\n</g>\n</svg>\n",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"{} 0 {} {}\" width=\"{}mm\" height=\"{}mm\">\n<rect x=\"{}\" y=\"0\" width=\"{}\" height=\"{}\" fill=\"#ffffff\"/>\n{}<g {}>\n{}\n</g>\n</svg>\n",
num(x0),
num(w),
num(h),
@@ -504,6 +535,7 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option<String> {
num(x0),
num(w),
num(h),
if defs.is_empty() { String::new() } else { format!("<defs>{}</defs>\n", defs.concat()) },
o.line_ends.svg_attrs(),
out.join("\n")
))