diff --git a/TODO.md b/TODO.md index a3eba91e..3fd9f3ba 100644 --- a/TODO.md +++ b/TODO.md @@ -2847,6 +2847,29 @@ Format · [90] Versionsvergleich · [91] Assistent · [92] Speckle. `#`, Projektwechsel passt also neu ein. Tests: vitest `geometry.test.ts` (leer/NaN/normal), e2e `initialZoom.spec.ts` (Massstab 1:30–1:400 und Inhalt sichtbar nach Neu, Musterhaus, Musterhaus komplex). Nur Linux/Chromium geprüft, nicht in der Tauri-App. +- ◐ **[146] Linienenden und -ecken einstellbar.** (6.11., Maintainer: „Manche Linienenden sind rund, manche eckig. + Globale Einstellung.") Bestand vorher: render2d (WebGPU-Szene) und Kern `gpu_compile` (Metal-Chunks) zeichneten volle + Striche mit runden Kappen/Ecken, Strich-Shader runde Strichenden, Bögen (SDF) flach; Plan-SVG rund nur bei vollen + Linien/Kantenläufen ([141]), Polygone `linejoin=round`; Druck-SVG (`print_svg.rs`, `sceneToPrintSvg.ts`) rund; React-SVG + über CSS `linecap: round`, `miterlimit 8`. Neu: Projekt-Felder `lineCap` (`butt`/`round`/`square`) und `lineJoin` + (`miter`/`round`/`bevel`), fehlt = flach + Gehrung (Grenze 4, darüber gefast); Kodierung `cap | join << 2` + (`plan/line_ends.rs`, `model/lineEnds.ts`), reist als `Plan.lineEnds` (generatePlan/Schnitt/Ansicht). Wirkt in: + render2d (Gehrungs-/Fasen-Dreiecke, vorstehende Kappe; Szenenkopf-Wort 44 statt Reserve-0; Strich-Shader `count + 16·cap`, + innere Ecken gestrichelter Züge bleiben rund; Bogen-Kappe in `wdash.w`), `gpu_compile` (gleich; gepacktes Miter-Byte jetzt + `(m−1)/3`, Byte 0 = 1, `chunks.rs` dekodiert; Chunk-Cache verwirft bei Wechsel), Plan-SVG (`` mit den Attributen), + Druck-SVG/PDF (Attribute am ``), React-SVG-Ansicht (``, CSS `inherit`). Punkt-Muster bleiben überall rund ([96]). + Kerben an Wandecken: volle Einzel-Linien und Kantenläufe gleicher Farbe/Breite(/Deckkraft) werden an Enden, an denen + genau zwei zusammentreffen, zu Zügen genäht (`stitch_runs_members`; Szene, `gpu_compile` bis zum nächsten Strich-Muster, + Plan-SVG, Druck-SVG), ein Zug steht an der Stelle seines spätesten Teils. UI: Einstellungen → Projekt („Linienenden", + „Linienecken"), beide Felder ein Undo-Schritt. Tests: Rust `line_ends` (Kodierung), render2d (`flach_mit_gehrung_ist_standard`, + `spitzer_winkel_ueber_gehrungsgrenze_wird_gefast`, `vorstehende_und_runde_kappen`, `strich_instanzen_tragen_die_kappe`, + `linienenden_im_kopf`), Kern (`ecke_aus_zwei_linien_wird_ein_zug_mit_gehrung`, `umriss_ecke_als_zug`), vitest + `plan/lineEnds.test.ts`. Goldens neu (Plan/Schnitt/Ansicht + CLI: `` mit Attributen, genähte `` statt + Einzel-``/``, keine `linecap=round` mehr; Komplex-EG 1:50 mit Schraffur 4.95 → 1.05 MB, v. a. Höhenlinien). + Geprüft: cargo test Kern + render2d, WASM gebaut (Linux, `--no-opt`), tsc, vitest, CLI-SVG vorher/nachher in Chromium + (Ecke, T-Stoss, Tür, Masslinie). **Offen:** DXF/DWG ohne Einstellung (acadrust schreibt `$ENDCAPS/$JOINSTYLE` nur in DWG; + CAD zeichnet Stiftbreiten selbst); Druck-SVG streicht Polygone weiter rundum (keine `noStrokeEdges`); Nähen in den + Metal-Chunks nur innerhalb eines Chunks; nicht in der Tauri-App/Metal und nicht im WebGPU-Browser angesehen. · M - ◐ **[68] Baugrube / Geländebearbeitung.** (30.10.) Kontext-Objekt `excavation` (Rust-Modell, `ContextObject`): Sohle (`outline`, `bottom` m ±0.00), Böschung `slope` (Standard 45°, je Kante `edgeSlopes`), Schüttung `fillSlope` (33.7°), Bermen `bermWidth`/`bermHeight`. Neues Gelände = clamp(t, b − d·tan β, b + H(d)) mit d = Abstand zum diff --git a/src-tauri/core/src/gpu_compile.rs b/src-tauri/core/src/gpu_compile.rs index c1d9e4a9..93cbffe1 100644 --- a/src-tauri/core/src/gpu_compile.rs +++ b/src-tauri/core/src/gpu_compile.rs @@ -36,6 +36,8 @@ use crate::hatch::{self, v2, Hatch, HatchKind, Pattern, Run, V2, DASH_MM_TO_M}; use crate::jsmath::hypot2; use crate::jsnum; use crate::plan::buf::{self, PlanBuf, Prim, Style}; +use crate::plan::line_ends::{LineEnds, MITER_LIMIT}; +use crate::plan::scene::stitch_runs; use std::f64::consts::PI; const PX_PER_M: f64 = 90.0; @@ -285,14 +287,21 @@ fn snorm8(v: f64) -> u32 { ((r as i32) & 0xff) as u32 } -/// Gepacktes Normalen-Wort: snorm8 nx | ny | side | miter (=127). +/// Gepacktes Normalen-Wort: snorm8 nx | ny | side | miter-Byte (0 = Faktor 1, s. [`miter_word`]). #[inline] fn normal_word(nx: f64, ny: f64, side: f64) -> u32 { - snorm8(nx) | (snorm8(ny) << 8) | (snorm8(side) << 16) | (127 << 24) + snorm8(nx) | (snorm8(ny) << 8) | (snorm8(side) << 16) +} + +/// Wie [`normal_word`] mit Längenfaktor `m` in [1, 4] ([146] Gehrungsspitze, vorstehende Kappe): +/// Byte = snorm8((m − 1) / 3), der Shader (`render2d/chunks.rs`) rechnet `1 + max(w, 0) · 3`. +#[inline] +fn miter_word(nx: f64, ny: f64, side: f64, m: f64) -> u32 { + normal_word(nx, ny, side) | (snorm8((m - 1.0) / 3.0) << 24) } /// Fächer-Zentrum (1, 0, 0) gepackt. -const CENTER_WORD: u32 = 127 | (127 << 24); +const CENTER_WORD: u32 = 127; #[inline] fn left_normal(d: V2) -> V2 { @@ -322,6 +331,12 @@ struct Compiler { scratch: Vec, seg_dir: Vec>, seg_ang: Vec<[Option; 2]>, + /// Linienenden und -ecken ([146]). + ends: LineEnds, + /// Volle, offene Züge je (Farbe, Breite), am Ende zusammengenäht ([146]): Wand-Umrisse zweier + /// Wände treffen sich an der Ecke als EIN Zug mit Ecke statt zwei Enden (keine Kerbe). + solid: Vec<(Rgba, f64, Vec>)>, + solid_of: std::collections::HashMap<[u64; 5], usize>, } impl Compiler { @@ -390,8 +405,37 @@ impl Compiler { /// Linienzug mit Strichmuster `dash` (Papier-mm): gültiges Muster bis [`MAX_LINE_DASH`] /// Einträge → Shader-Instanzen; längeres → CPU-Zerlegung; ungültiges/fehlendes → durchgezogen. + /// Vollen offenen Zug zum Zusammennähen vormerken (gezeichnet am Ende von `compile`). + fn defer_solid(&mut self, pts_m: &[V2], color: Rgba, stroke_mm: f64) { + if pts_m.len() < 2 { + return; + } + let k = [color[0].to_bits(), color[1].to_bits(), color[2].to_bits(), color[3].to_bits(), stroke_mm.to_bits()]; + let gi = match self.solid_of.get(&k) { + Some(&g) => g, + None => { + self.solid.push((color, stroke_mm, Vec::new())); + self.solid_of.insert(k, self.solid.len() - 1); + self.solid.len() - 1 + } + }; + self.solid[gi].2.push(pts_m.to_vec()); + } + + fn flush_solid(&mut self) { + for (color, stroke_mm, runs) in std::mem::take(&mut self.solid) { + for (pts, closed) in stitch_runs(runs) { + self.stroke_polyline(&pts, closed, color, stroke_mm, false); + } + } + self.solid_of.clear(); + } + fn stroke_styled(&mut self, pts_m: &[V2], closed: bool, dash: Option<&[f64]>, color: Rgba, stroke_mm: f64) { let Some(d) = dash.filter(|d| !d.is_empty()) else { + if !closed { + return self.defer_solid(pts_m, color, stroke_mm); + } return self.stroke_polyline(pts_m, closed, color, stroke_mm, false); }; match dash_cycle_m(d) { @@ -401,9 +445,15 @@ impl Compiler { if closed && pts_m.len() > 2 { run.push(pts_m[0]); } + // Punkte im Muster brauchen runde Enden ([96]), auch bei flacher Einstellung. + let saved = self.ends; + if d.iter().step_by(2).any(|v| *v <= 0.0) { + self.ends.cap = 1; + } for piece in hatch::apply_dash_runs(vec![run], &line_dash_for_runs(d)) { self.stroke_polyline(&piece, false, color, stroke_mm, false); } + self.ends = saved; } None => self.stroke_polyline(pts_m, closed, color, stroke_mm, false), } @@ -416,8 +466,12 @@ impl Compiler { if pts_m.len() < 2 { return; } + // Maler-Reihenfolge: vorgemerkte volle Züge vor diesem Strich zeichnen ([146]). + self.flush_solid(); let close = closed && pts_m.len() > 2 && (pts_m[0].x != pts_m[pts_m.len() - 1].x || pts_m[0].y != pts_m[pts_m.len() - 1].y); let n_seg = pts_m.len() - 1 + usize::from(close); + // [146] Linienende im Muster-Zähler (`count + 16 · cap`); Punkte (Länge 0) immer rund ([96]). + let cap = if cycle_m.iter().step_by(2).any(|d| *d <= 0.0) { 1 } else { self.ends.cap as u32 }; let seg = |i: usize| (pts_m[i], pts_m[(i + 1) % pts_m.len()]); let mut run = 0.0f64; for i in 0..n_seg { @@ -455,7 +509,7 @@ impl Compiler { (s0 * PX_PER_M) as f32, (run * PX_PER_M) as f32, total as f32, - cycle_m.len() as f32, + (cycle_m.len() as u32 + 16 * cap) as f32, ]); self.dash_inst.extend_from_slice(&dash); s0 += l; @@ -475,6 +529,12 @@ impl Compiler { /// Wie `push_vert`, mit bereits gepacktem Normalen-Wort `w` (nur im gepackten Layout benutzt). #[inline] fn push_vert_w(&mut self, p: V2, w: u32, nx: f64, ny: f64, side: f64) -> u32 { + self.push_vert_m(p, w, nx, ny, side, 1.0) + } + + /// Wie `push_vert_w` mit Längenfaktor `m` (Gehrungsspitze, Ecke der vorstehenden Kappe). + #[inline] + fn push_vert_m(&mut self, p: V2, w: u32, nx: f64, ny: f64, side: f64, m: f64) -> u32 { if self.packed { self.line_verts.extend_from_slice(&[(p.x as f32).to_bits(), (p.y as f32).to_bits(), w]); (self.line_verts.len() / 3 - 1) as u32 @@ -485,7 +545,7 @@ impl Compiler { (nx as f32).to_bits(), (ny as f32).to_bits(), (side as f32).to_bits(), - 1.0f32.to_bits(), + (m as f32).to_bits(), ]); (self.line_verts.len() / 6 - 1) as u32 } @@ -582,7 +642,55 @@ impl Compiler { let d_in = if has_in { seg_dir[i_in] } else { None }; let d_out = if has_out { seg_dir[i_out] } else { None }; let p = s_pts[v]; + let ends = self.ends; match (d_in, d_out) { + (Some(d1), Some(d2)) if ends.join != 1 => { + // [146] Gehrung (bis `MITER_LIMIT`, sonst gefast) bzw. Fase auf der Aussenseite. + let turn = d1.x * d2.y - d1.y * d2.x; + let dot = d1.x * d2.x + d1.y * d2.y; + if (turn.abs() < 1e-6 && dot > 0.0) || dot < -0.9999 { + continue; + } + let outer = if turn > 0.0 { -1.0 } else { 1.0 }; + let n1 = left_normal(d1); + let n2 = left_normal(d2); + let u1 = v2(outer * n1.x, outer * n1.y); + let u2 = v2(outer * n2.x, outer * n2.y); + let i_c = self.push_vert_w(p, CENTER_WORD, 1.0, 0.0, 0.0); + let i1 = self.push_vert(p, u1.x, u1.y, 1.0); + let i2 = self.push_vert(p, u2.x, u2.y, 1.0); + let cos_half = ((1.0 + dot) * 0.5).sqrt(); + let m = if cos_half > 1e-9 { 1.0 / cos_half } else { f64::INFINITY }; + if ends.join == 0 && m <= MITER_LIMIT { + let bx = u1.x + u2.x; + let by = u1.y + u2.y; + let bl = hypot2(bx, by); + let (bx, by) = (bx / bl, by / bl); + let w = if self.packed { miter_word(bx, by, 1.0, m) } else { 0 }; + let it = self.push_vert_m(p, w, bx, by, 1.0, m); + self.line_idx.extend_from_slice(&[i_c, i1, it, i_c, it, i2]); + } else { + self.line_idx.extend_from_slice(&[i_c, i1, i2]); + } + } + (None, Some(d)) | (Some(d), None) if ends.cap != 1 => { + // [146] Flach: nichts; vorstehend: Rechteck um die halbe Breite nach aussen. + if ends.cap == 2 { + let e = if d_in.is_none() { v2(-d.x, -d.y) } else { d }; + let n = left_normal(d); + let r2 = std::f64::consts::FRAC_1_SQRT_2; + let ia = self.push_vert(p, n.x, n.y, 1.0); + let ib = self.push_vert(p, n.x, n.y, -1.0); + let (ax, ay) = ((n.x + e.x) * r2, (n.y + e.y) * r2); + let (cx, cy) = ((-n.x + e.x) * r2, (-n.y + e.y) * r2); + let m = std::f64::consts::SQRT_2; + let wa = if self.packed { miter_word(ax, ay, 1.0, m) } else { 0 }; + let wc = if self.packed { miter_word(cx, cy, 1.0, m) } else { 0 }; + let ic = self.push_vert_m(p, wa, ax, ay, 1.0, m); + let id = self.push_vert_m(p, wc, cx, cy, 1.0, m); + self.line_idx.extend_from_slice(&[ia, ic, id, ia, id, ib]); + } + } (Some(d1), Some(d2)) => { // Runder Übergang nur auf der äusseren Seite der Ecke. let turn = d1.x * d2.y - d1.y * d2.x; @@ -680,7 +788,7 @@ impl Compiler { break; } } - self.stroke_polyline(&run, false, color, stroke_mm, false); + self.defer_solid(&run, color, stroke_mm); } } @@ -734,8 +842,11 @@ fn hatch_draws_lines(h: &Hatch) -> bool { /// Kompiliert die Primitive eines Plan-Puffers. `px_per_meter` steuert nur die Bogen- /// Tessellierung (0 = zoomunabhängig). `packed` = kompakte Linien-Vertices (nativer Renderer). -pub fn compile(plan: &PlanBuf, px_per_meter: f64, packed: bool) -> GpuOut { +pub fn compile(plan: &PlanBuf, px_per_meter: f64, packed: bool, ends: LineEnds) -> GpuOut { let mut c = Compiler { + ends, + solid: Vec::new(), + solid_of: std::collections::HashMap::new(), packed, fill_pos: Vec::new(), fill_idx: Vec::new(), @@ -868,6 +979,7 @@ pub fn compile(plan: &PlanBuf, px_per_meter: f64, packed: bool) -> GpuOut { } } } + c.flush_solid(); GpuOut { fill_pos: c.fill_pos, @@ -932,9 +1044,9 @@ fn draw_circle_like( /// Flache Ausgabe (s. Modulkopf) für die Primitive `[from, to)` eines Plan-Puffers (v2); leer bei /// unlesbarem Puffer oder ungültigem Bereich. -pub fn compile_flat(bytes: &[u8], from: usize, to: usize, px_per_meter: f64, packed: bool) -> Vec { +pub fn compile_flat(bytes: &[u8], from: usize, to: usize, px_per_meter: f64, packed: bool, ends: LineEnds) -> Vec { let Some(plan) = buf::View::parse(bytes).and_then(|v| v.gpu(from, to)) else { return Vec::new() }; - let o = compile(&plan, px_per_meter, packed); + let o = compile(&plan, px_per_meter, packed, ends); let mut meta: Vec = vec![ o.origin.0, o.origin.1, @@ -1012,8 +1124,36 @@ mod tests { PlanBuf { colors: vec![[0.0, 0.0, 0.0, 1.0], [0.5, 0.5, 0.5, 1.0]], hatches: vec![], prims } } + /// [146] Zwei einzelne volle Linien mit gemeinsamem Ende (Wand-Umrisse zweier Wände an der + /// Ecke) werden EIN Zug: Gehrung statt zweier flacher Enden (keine Kerbe); andere Enden/Ecken je + /// Einstellung. + #[test] + fn ecke_aus_zwei_linien_wird_ein_zug_mit_gehrung() { + let corner = |ends: LineEnds, packed: bool| { + let mut b = line(1.0, 1.0, false); + if let Prim::Line { b: bb, .. } = &mut b { + *bb = v2(1.0, 1.0); + } + compile(&plan(vec![line(0.0, 1.0, false), b]), 90.0, packed, ends) + }; + let o = corner(LineEnds::default(), false); + assert_eq!(o.line_idx.len(), 2 * 6 + 2 * 3, "zwei Quads + Gehrung, keine Kappen"); + let m: Vec = o.line_verts.chunks_exact(6).map(|v| f32::from_bits(v[5])).filter(|m| *m != 1.0).collect(); + assert_eq!(m.len(), 1); + assert!((m[0] - std::f32::consts::SQRT_2).abs() < 1e-6); + // Gepackt: Faktor im obersten Byte als snorm8((m − 1) / 3), 0 = 1. + let p = corner(LineEnds::default(), true); + let bytes: Vec = p.line_verts.chunks_exact(3).map(|v| (v[2] >> 24) as u8 as i8).collect(); + let tips: Vec = bytes.iter().filter(|b| **b != 0).map(|b| 1.0 + (*b as f32 / 127.0).max(0.0) * 3.0).collect(); + assert_eq!(tips.len(), 1); + assert!((tips[0] - std::f32::consts::SQRT_2).abs() < 0.02, "{tips:?}"); + // Gefast: ein Dreieck; vorstehend: je offenes Ende ein Rechteck. + assert_eq!(corner(LineEnds { cap: 0, join: 2 }, false).line_idx.len(), 2 * 6 + 3); + assert_eq!(corner(LineEnds { cap: 2, join: 0 }, false).line_idx.len(), 2 * 6 + 2 * 3 + 2 * 6); + } + fn line_idx_count(p: &PlanBuf) -> u32 { - compile(p, 90.0, false).line_batches.iter().map(|b| b.count).sum() + compile(p, 90.0, false, LineEnds::default()).line_batches.iter().map(|b| b.count).sum() } #[test] @@ -1080,7 +1220,7 @@ mod tests { }, color: -1, }); - let o = compile(&p, 90.0, true); + let o = compile(&p, 90.0, true, LineEnds::default()); assert_eq!(o.fill_idx.len(), 6); assert_eq!(o.fill_batches[0].color, [1.0, 1.0, 1.0, 0.5]); // Schraffur (0.13 mm, grau) und Umriss (0.5 mm) als eigene Batches. @@ -1099,7 +1239,7 @@ mod tests { Prim::DrawingArc { style: st(), stroke: 0, weight_mm: 0.5, center: v2(0.0, 0.0), r: 1.0, a0: 0.0, a1: 0.0, dash: None }, Prim::Placeholder, ]); - let o = compile(&p, 0.0, false); + let o = compile(&p, 0.0, false, LineEnds::default()); assert!(!o.fill_idx.is_empty()); assert_eq!(o.line_batches.len(), 2); assert_eq!(o.bounds, (-1.0, -1.0, 2.0, 2.0)); @@ -1107,7 +1247,7 @@ mod tests { #[test] fn kaputter_puffer_leer() { - assert!(compile_flat(&[1, 2, 3], 0, 0, 90.0, true).is_empty()); + assert!(compile_flat(&[1, 2, 3], 0, 0, 90.0, true, LineEnds::default()).is_empty()); let mut w = buf::Writer::new(false); w.push(&crate::plan::prim::Primitive::Line { a: crate::model::Vec2 { x: 0.0, y: 0.0 }, @@ -1125,9 +1265,9 @@ mod tests { opacity: None, }); let enc = w.finish(); - assert!(!compile_flat(&enc, 0, 1, 90.0, true).is_empty()); - assert!(compile_flat(&enc, 0, 2, 90.0, true).is_empty(), "Bereich ausserhalb"); - assert!(!compile_flat(&enc, 1, 1, 90.0, true).is_empty(), "leerer Bereich = leere Geometrie"); + assert!(!compile_flat(&enc, 0, 1, 90.0, true, LineEnds::default()).is_empty()); + assert!(compile_flat(&enc, 0, 2, 90.0, true, LineEnds::default()).is_empty(), "Bereich ausserhalb"); + assert!(!compile_flat(&enc, 1, 1, 90.0, true, LineEnds::default()).is_empty(), "leerer Bereich = leere Geometrie"); } // --- Strichmuster im Shader (Chunk-Pfad, gleiche Instanzen wie render2d `DashSegment`) --- @@ -1142,7 +1282,7 @@ mod tests { #[test] fn gestrichelte_linie_als_shader_instanz() { - let o = compile(&plan(vec![dashed(1.0, 4.0, false, vec![0.12, 0.08])]), 90.0, true); + let o = compile(&plan(vec![dashed(1.0, 4.0, false, vec![0.12, 0.08])]), 90.0, true, LineEnds::default()); assert!(o.line_idx.is_empty() && o.line_verts.is_empty(), "keine durchgezogenen Striche mehr"); assert_eq!(o.dash_inst.len(), DASH_INST_FLOATS); let d = inst(&o, 0); @@ -1162,7 +1302,7 @@ mod tests { #[test] fn gestrichelter_zug_phase_laeuft_durch() { // Verkettete Linien: ein Zug, Phase über die Ecke, ungerades Muster verdoppelt. - let o = compile(&plan(vec![dashed(0.0, 1.0, false, vec![1.0]), dashed(1.0, 3.0, true, vec![1.0])]), 90.0, true); + let o = compile(&plan(vec![dashed(0.0, 1.0, false, vec![1.0]), dashed(1.0, 3.0, true, vec![1.0])]), 90.0, true, LineEnds::default()); assert_eq!(o.dash_inst.len(), 2 * DASH_INST_FLOATS); assert_eq!(inst(&o, 1)[4], 90.0); assert_eq!(inst(&o, 1)[5], 270.0); @@ -1170,21 +1310,21 @@ mod tests { assert_eq!(o.dash_batches.len(), 1); assert_eq!(o.dash_batches[0].count, 2); // Einzeln (nicht verkettet): jede Linie beginnt ihr Muster neu. - let o = compile(&plan(vec![dashed(0.0, 1.0, false, vec![1.0]), dashed(1.0, 3.0, false, vec![1.0])]), 90.0, true); + let o = compile(&plan(vec![dashed(0.0, 1.0, false, vec![1.0]), dashed(1.0, 3.0, false, vec![1.0])]), 90.0, true, LineEnds::default()); assert_eq!(inst(&o, 1)[4], 0.0); assert_eq!(inst(&o, 1)[5], 180.0); } #[test] fn ungueltiges_muster_durchgezogen_langes_muster_zerlegt() { - let solid = compile(&plan(vec![line(0.0, 1.0, false)]), 90.0, true); - let o = compile(&plan(vec![dashed(0.0, 1.0, false, vec![0.0, -1.0])]), 90.0, true); + let solid = compile(&plan(vec![line(0.0, 1.0, false)]), 90.0, true, LineEnds::default()); + let o = compile(&plan(vec![dashed(0.0, 1.0, false, vec![0.0, -1.0])]), 90.0, true, LineEnds::default()); assert!(o.dash_inst.is_empty()); assert_eq!(o.line_idx.len(), solid.line_idx.len(), "Nullmuster = durchgezogen"); - let o = compile(&plan(vec![dashed(0.0, 1.0, false, vec![])]), 90.0, true); + let o = compile(&plan(vec![dashed(0.0, 1.0, false, vec![])]), 90.0, true, LineEnds::default()); assert!(o.dash_inst.is_empty() && o.line_idx.len() == solid.line_idx.len()); // 9 Einträge → verdoppelt 18 > MAX_LINE_DASH: CPU-Zerlegung (mehrere Stücke). - let o = compile(&plan(vec![dashed(0.0, 1.0, false, vec![1.0; 9])]), 90.0, true); + let o = compile(&plan(vec![dashed(0.0, 1.0, false, vec![1.0; 9])]), 90.0, true, LineEnds::default()); assert!(o.dash_inst.is_empty()); assert!(o.line_idx.len() > 2 * solid.line_idx.len()); } @@ -1197,7 +1337,7 @@ mod tests { Prim::Circle { style: st(), fill: 1, stroke: 0, weight_mm: 0.18, center: v2(3.0, 0.0), r: 1.0, dash: d.clone() }, Prim::DrawingArc { style: st(), stroke: 0, weight_mm: 0.18, center: v2(0.0, 0.0), r: 2.0, a0: 0.0, a1: 1.0, dash: d }, ]); - let o = compile(&p, 90.0, true); + let o = compile(&p, 90.0, true, LineEnds::default()); assert!(o.line_idx.is_empty(), "alle Striche gestrichelt"); assert!(!o.fill_idx.is_empty(), "Kreisfüllung bleibt"); let n = o.dash_inst.len() / DASH_INST_FLOATS; @@ -1229,7 +1369,7 @@ mod tests { xs.push(xs[xs.len() - 1] + 0.05 + rnd() * 1.5); } let prims: Vec = xs.windows(2).enumerate().map(|(i, w)| dashed(w[0], w[1], i > 0, pat.clone())).collect(); - let o = compile(&plan(prims), 90.0, true); + let o = compile(&plan(prims), 90.0, true, LineEnds::default()); let runs = hatch::apply_dash_runs(vec![xs.iter().map(|&x| v2(x, 0.0)).collect()], &line_dash_for_runs(&pat)); let total_len = xs[xs.len() - 1]; for _ in 0..300 { @@ -1267,14 +1407,14 @@ mod tests { /// dieser Folge — die zweite Linie deckt die gestrichelte (z. B. verdeckte Kante unter einer Wand). #[test] fn strich_batches_in_maler_reihenfolge() { - let o = compile(&plan(vec![line(0.0, 1.0, false), dashed(0.0, 1.0, false, vec![2.0, 1.0]), dashed(0.0, 2.0, false, vec![2.0, 1.0]), line(2.0, 3.0, false)]), 90.0, true); + let o = compile(&plan(vec![line(0.0, 1.0, false), dashed(0.0, 1.0, false, vec![2.0, 1.0]), dashed(0.0, 2.0, false, vec![2.0, 1.0]), line(2.0, 3.0, false)]), 90.0, true, LineEnds::default()); assert_eq!(o.line_batches.len(), 2, "keine Zusammenfassung über den Strich-Batch hinweg"); assert_eq!(o.dash_batches.len(), 1, "zwei gestrichelte ohne Linie dazwischen = ein Batch"); assert_eq!(o.dash_batches[0].count, 2); assert_eq!(o.dash_batches[0].line_at, o.line_batches[0].count); assert_eq!(o.line_batches[1].start, o.dash_batches[0].line_at); // Ohne Strich dazwischen werden gleich gestylte Linien weiter zusammengefasst. - let o = compile(&plan(vec![line(0.0, 1.0, false), line(2.0, 3.0, false)]), 90.0, true); + let o = compile(&plan(vec![line(0.0, 1.0, false), line(2.0, 3.0, false)]), 90.0, true, LineEnds::default()); assert_eq!(o.line_batches.len(), 1); } @@ -1297,7 +1437,7 @@ mod tests { opacity: None, }); let enc = w.finish(); - let out = compile_flat(&enc, 0, 1, 90.0, true); + let out = compile_flat(&enc, 0, 1, 90.0, true, LineEnds::default()); let m = out[0] as usize; let meta: Vec = (0..m).map(|i| f64::from_bits(out[2 + 2 * i] as u64 | ((out[3 + 2 * i] as u64) << 32))).collect(); let (n_fill, n_line) = (meta[10] as usize, meta[11] as usize); diff --git a/src-tauri/core/src/model/generated.rs b/src-tauri/core/src/model/generated.rs index 8b18af08..f43f9cb9 100644 --- a/src-tauri/core/src/model/generated.rs +++ b/src-tauri/core/src/model/generated.rs @@ -6,6 +6,36 @@ use super::manual::*; use serde::{Deserialize, Serialize}; use ts_rs::TS; +/// Linienenden aller Striche im Plan/Schnitt/Ansicht und in den Exporten ([146]); fehlt = flach. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, TS)] +pub enum LineCap { + #[default] + #[serde(rename = "butt")] + Butt, + #[serde(rename = "round")] + Round, + #[serde(rename = "square")] + Square, + #[serde(other)] + #[ts(skip)] + Unknown, +} + +/// Linienecken (Stoss zweier Segmente eines Zugs) ([146]); fehlt = Gehrung (Grenze 4, sonst gefast). +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, TS)] +pub enum LineJoin { + #[default] + #[serde(rename = "miter")] + Miter, + #[serde(rename = "round")] + Round, + #[serde(rename = "bevel")] + Bevel, + #[serde(other)] + #[ts(skip)] + Unknown, +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, TS)] pub enum LineStyleKind { #[default] @@ -4690,6 +4720,14 @@ pub struct Project { #[serde(rename = "scaleLineWeights", default, skip_serializing_if = "Option::is_none")] #[ts(optional)] pub scale_line_weights: Option, + /// Linienenden aller Striche ([146]); fehlt = flach (`butt`). + #[serde(rename = "lineCap", default, skip_serializing_if = "Option::is_none")] + #[ts(optional)] + pub line_cap: Option, + /// Linienecken aller Striche ([146]); fehlt = Gehrung (`miter`, Grenze 4). + #[serde(rename = "lineJoin", default, skip_serializing_if = "Option::is_none")] + #[ts(optional)] + pub line_join: Option, /// Grafik-Kategorie-Baum (geschossübergreifend). pub layers: Vec, pub walls: Vec, @@ -5493,6 +5531,18 @@ impl Project { None => Default::default(), }; } + "lineCap" => { + self.line_cap = match v { + Some(v) => >::deserialize(v).map_err(|e| e.to_string())?, + None => Default::default(), + }; + } + "lineJoin" => { + self.line_join = match v { + Some(v) => >::deserialize(v).map_err(|e| e.to_string())?, + None => Default::default(), + }; + } "layers" => { self.layers = match v { Some(v) => >::deserialize(v).map_err(|e| e.to_string())?, diff --git a/src-tauri/core/src/opening_preview.rs b/src-tauri/core/src/opening_preview.rs index cd1ba416..2da70a53 100644 --- a/src-tauri/core/src/opening_preview.rs +++ b/src-tauri/core/src/opening_preview.rs @@ -74,6 +74,8 @@ pub fn opening_preview(p: &Project, opening_id: &str) -> Option { walls: vec![wall], openings: Some(vec![op]), scale_line_weights: p.scale_line_weights, + line_cap: p.line_cap, + line_join: p.line_join, ..Default::default() }) } diff --git a/src-tauri/core/src/plan/line_ends.rs b/src-tauri/core/src/plan/line_ends.rs new file mode 100644 index 00000000..41415ca9 --- /dev/null +++ b/src-tauri/core/src/plan/line_ends.rs @@ -0,0 +1,79 @@ +//! Linienenden und -ecken ([146]): EINE Projekt-Einstellung (`Project.lineCap`/`lineJoin`) für alle +//! Ausgabewege — Bildschirm (render2d-Szene, GPU-Chunks), Plan-SVG, Druck-SVG/PDF, DXF. Über die +//! WASM-Grenze als kleine Zahl `cap | join << 2` (0 = flach + Gehrung, der Standard). + +use crate::model::{LineCap, LineJoin, Project}; + +/// Gehrungsgrenze (Gehrungslänge / Strichbreite, wie SVG `stroke-miterlimit`); darüber gefast. +pub const MITER_LIMIT: f64 = 4.0; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct LineEnds { + /// 0 flach (butt), 1 rund, 2 vorstehend (square). + pub cap: u8, + /// 0 Gehrung (miter), 1 rund, 2 gefast (bevel). + pub join: u8, +} + +impl LineEnds { + pub fn of(p: &Project) -> Self { + let cap = match p.line_cap { + Some(LineCap::Round) => 1, + Some(LineCap::Square) => 2, + _ => 0, + }; + let join = match p.line_join { + Some(LineJoin::Round) => 1, + Some(LineJoin::Bevel) => 2, + _ => 0, + }; + Self { cap, join } + } + /// Aus der Kodierung `cap | join << 2`; Unsinn (NaN, ausserhalb) → Standard. + pub fn from_code(c: f64) -> Self { + if !c.is_finite() || !(0.0..16.0).contains(&c) { + return Self::default(); + } + let c = c as u32; + let cap = (c & 3) as u8; + let join = ((c >> 2) & 3) as u8; + Self { cap: if cap > 2 { 0 } else { cap }, join: if join > 2 { 0 } else { join } } + } + pub fn code(self) -> u32 { + self.cap as u32 | (self.join as u32) << 2 + } + pub fn svg_cap(self) -> &'static str { + ["butt", "round", "square"][self.cap as usize] + } + pub fn svg_join(self) -> &'static str { + ["miter", "round", "bevel"][self.join as usize] + } + /// SVG-Attribute für einen umschliessenden `` (Kinder erben sie). + pub fn svg_attrs(self) -> String { + format!("stroke-linecap=\"{}\" stroke-linejoin=\"{}\" stroke-miterlimit=\"{}\"", self.svg_cap(), self.svg_join(), MITER_LIMIT) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn kodierung_rundreise_und_unsinn() { + for cap in 0..3 { + for join in 0..3 { + let e = LineEnds { cap, join }; + assert_eq!(LineEnds::from_code(e.code() as f64), e); + } + } + assert_eq!(LineEnds::from_code(f64::NAN), LineEnds::default()); + assert_eq!(LineEnds::from_code(3.0), LineEnds::default()); + assert_eq!(LineEnds::from_code(-1.0), LineEnds::default()); + let mut p = Project::default(); + assert_eq!(LineEnds::of(&p), LineEnds { cap: 0, join: 0 }); + p.line_cap = Some(LineCap::Square); + p.line_join = Some(LineJoin::Bevel); + assert_eq!(LineEnds::of(&p).code(), 2 | 2 << 2); + assert_eq!(LineEnds::of(&p).svg_attrs(), "stroke-linecap=\"square\" stroke-linejoin=\"bevel\" stroke-miterlimit=\"4\""); + } +} diff --git a/src-tauri/core/src/plan/mod.rs b/src-tauri/core/src/plan/mod.rs index 05d96a4c..6a707362 100644 --- a/src-tauri/core/src/plan/mod.rs +++ b/src-tauri/core/src/plan/mod.rs @@ -32,3 +32,4 @@ pub mod elevation_geom; pub mod pick; pub mod sketch; pub mod ceiling_plan; +pub mod line_ends; diff --git a/src-tauri/core/src/plan/print_svg.rs b/src-tauri/core/src/plan/print_svg.rs index 851000f8..9e8478f2 100644 --- a/src-tauri/core/src/plan/print_svg.rs +++ b/src-tauri/core/src/plan/print_svg.rs @@ -65,17 +65,61 @@ fn dash_attr(d: &[f64]) -> String { /// Anweisungsliste. struct Out { - s: String, - first: bool, + recs: Vec, + /// Volle Einzel-Linien je (Farbe, Stift, Deckkraft) zum Zusammennähen ([146]): Wand-Umrisse zweier + /// Wände treffen sich als EIN Zug mit Ecke; jeder Zug steht an der Stelle seiner spätesten Linie. + solid: Vec<((String, String, String), Vec>, Vec)>, } impl Out { fn rec(&mut self, fields: &[&str]) { - if !self.first { - self.s.push('\u{1e}'); + self.recs.push(fields.join("\u{1f}")); + } + + fn defer_solid(&mut self, key: (String, String, String), a: V2, b: V2) { + self.recs.push(String::new()); + let slot = self.recs.len() - 1; + let gi = match self.solid.iter().position(|g| g.0 == key) { + Some(g) => g, + None => { + self.solid.push((key, Vec::new(), Vec::new())); + self.solid.len() - 1 + } + }; + self.solid[gi].1.push(vec![a, b]); + self.solid[gi].2.push(slot); + } + + fn finish(mut self) -> String { + for ((color, pen, o), runs, slots) in std::mem::take(&mut self.solid) { + for (pts, closed, members) in crate::plan::scene::stitch_runs_members(&runs) { + let slot = members.iter().map(|&m| slots[m]).max().unwrap_or(0); + let line = pts.len() == 2 && !closed; + let mut attrs = if line { + vec![("x1", r3(pts[0].x)), ("y1", r3(pts[0].y)), ("x2", r3(pts[1].x)), ("y2", r3(pts[1].y)), ("stroke", color.clone()), ("stroke-width", pen.clone())] + } else { + vec![("points", pts_attr(&pts)), ("fill", "none".to_string()), ("stroke", color.clone()), ("stroke-width", pen.clone())] + }; + if !o.is_empty() { + attrs.push(("opacity", o.clone())); + } + let tag = if line { "line" } else if closed { "polygon" } else { "polyline" }; + let mut f: Vec<&str> = vec!["E", "0", tag]; + for (k, v) in &attrs { + f.push(k); + f.push(v); + } + let r = f.join("\u{1f}"); + if self.recs[slot].is_empty() { + self.recs[slot] = r; + } else { + self.recs[slot].push('\u{1e}'); + self.recs[slot].push_str(&r); + } + } } - self.first = false; - self.s.push_str(&fields.join("\u{1f}")); + self.recs.retain(|r| !r.is_empty()); + self.recs.join("\u{1e}") } /// Datensatz aus festen Feldern und Name/Wert-Paaren. @@ -140,7 +184,6 @@ fn poly_node(pts: &str, fill: &str, stroke: &str, stroke_mm: f64) -> Vec<(&'stat if stroke != "none" && stroke_mm > 0.0 { a.push(("stroke", stroke.to_string())); a.push(("stroke-width", js_number(stroke_mm))); - a.push(("stroke-linejoin", "round".to_string())); } else { a.push(("stroke", "none".to_string())); } @@ -155,11 +198,8 @@ fn line_attrs(a: V2, b: V2, color: &str, stroke_mm: f64, dash: Option<&[f64]>) - ("y2", r3(b.y)), ("stroke", color.to_string()), ("stroke-width", js_number(stroke_mm)), - ("stroke-linecap", "round".to_string()), ]; - if let Some(d) = dash.filter(|d| !d.is_empty()) { - v.push(("stroke-dasharray", dash_attr(d))); - } + push_dash(&mut v, dash); v } @@ -169,16 +209,13 @@ fn polyline_attrs(pts: &[V2], color: &str, stroke_mm: f64, dash: Option<&[f64]>) ("fill", "none".to_string()), ("stroke", color.to_string()), ("stroke-width", js_number(stroke_mm)), - ("stroke-linecap", "round".to_string()), - ("stroke-linejoin", "round".to_string()), ]; - if let Some(d) = dash.filter(|d| !d.is_empty()) { - v.push(("stroke-dasharray", dash_attr(d))); - } + push_dash(&mut v, dash); v } -/// Strichmuster + runde Kappe bei Punkten (Bögen, Kreise). +/// Strichmuster + runde Kappe bei Punkten. Sonst erben Enden und Ecken die Projekt-Einstellung +/// ([146]) vom ``, das TS anlegt (`planToPrintSvg.ts`). fn push_dash(v: &mut Vec<(&'static str, String)>, dash: Option<&[f64]>) { if let Some(d) = dash.filter(|d| !d.is_empty()) { v.push(("stroke-dasharray", dash_attr(d))); @@ -392,6 +429,11 @@ fn entry(out: &mut Out, view: &View, i: usize, hatches: &[(i32, Hatch, i32)], m: let p = hatch::motif_points_opt(a, b, &Motif { points: pts, length }, 1.0).unwrap_or_else(|| vec![a, b]); polyline_attrs(&p, &color, pen, d.as_deref()) } else { + let o = opacity_of(greyed, obj(3)); + if d.as_deref().is_none_or(|d| d.is_empty()) && pen > 0.0 { + out.defer_solid((color, js_number(pen), o), a, b); + return Some(()); + } line_attrs(a, b, &color, pen, d.as_deref()) }; let tag = if rec.zigzag.is_some() || rec.motif.is_some() { "polyline" } else { "line" }; @@ -601,14 +643,14 @@ pub fn print_svg_ops(parts: &mut [Part], o: &PrintOptions) -> Option { let content_w = (max_x - min_x) * k; let content_h = (max_y - min_y) * k; let m = Map { off_x: (o.page_w - content_w) / 2.0, off_y: (o.page_h - content_h) / 2.0, min_x, max_y, k }; - let mut out = Out { s: String::new(), first: true }; + let mut out = Out { recs: Vec::new(), solid: Vec::new() }; for part in parts.iter_mut() { let hatches = part.view.hatch_table()?; for i in part.from..part.to { entry(&mut out, &part.view, i, &hatches, m)?; } } - Some(out.s) + Some(out.finish()) } #[cfg(test)] @@ -646,9 +688,10 @@ mod tests { let js = "{\"kind\":\"drawingText\",\"at\":{\"x\":1,\"y\":2},\"text\":\"aa bb\",\"heightM\":0.5,\"angle\":0.5,\"color\":\"#123\",\"wrapWidth\":2,\"marks\":{\"bold\":true}}"; let t: SingleText = serde_json::from_str(js).unwrap(); let m = Map { off_x: 0.0, off_y: 0.0, min_x: 0.0, max_y: 10.0, k: 10.0 }; - let mut out = Out { s: String::new(), first: true }; + let mut out = Out { recs: Vec::new(), solid: Vec::new() }; text_node(&mut out, &t, m, "0.5".into()); - let recs: Vec> = out.s.split('\u{1e}').map(|r| r.split('\u{1f}').collect()).collect(); + let s = out.finish(); + let recs: Vec> = s.split('\u{1e}').map(|r| r.split('\u{1f}').collect()).collect(); // Drehung um den Anker (10, 80 mm), eine Zeile (Spalte 20 mm), je Wort/Leerraum ein Run. assert_eq!(recs[0], ["X", "transform", "rotate(-28.648 10 80)", "opacity", "0.5"]); assert_eq!(recs[1], ["L", "", "x", "10", "y", "80", "text-anchor", "start"]); @@ -664,9 +707,10 @@ mod tests { let js = r##"{"at":{"x":0,"y":10},"text":"","heightM":0.25,"angle":0,"wrapWidth":2,"doc":{"version":1,"paragraphs":[{"runs":[{"text":"aaaa bbbb","marks":{}}]},{"runs":[{"text":"c","marks":{"sizePt":72}}],"lineHeight":2}]}}"##; let t: SingleText = serde_json::from_str(js).unwrap(); let m = Map { off_x: 0.0, off_y: 0.0, min_x: 0.0, max_y: 10.0, k: 10.0 }; - let mut out = Out { s: String::new(), first: true }; + let mut out = Out { recs: Vec::new(), solid: Vec::new() }; text_node(&mut out, &t, m, String::new()); - let recs: Vec> = out.s.split('\u{1e}').map(|r| r.split('\u{1f}').collect()).collect(); + let s = out.finish(); + let recs: Vec> = s.split('\u{1e}').map(|r| r.split('\u{1f}').collect()).collect(); let lines: Vec<&Vec<&str>> = recs.iter().filter(|r| r[0] == "L").collect(); assert_eq!(lines.len(), 2); // Absatz-Zeilenhöhe 2 × Basisgrösse (2.5 mm). @@ -680,9 +724,10 @@ mod tests { let js = r##"{"at":{"x":2,"y":3},"doc":{"version":1,"paragraphs":[{"runs":[{"text":"Wohnen","marks":{"bold":true}}],"align":"center"}]},"extraLines":[{"text":"17.01 m²","align":"center"}],"basePt":10,"color":"#333"}"##; let t: StampText = serde_json::from_str(js).unwrap(); let m = Map { off_x: 0.0, off_y: 0.0, min_x: 0.0, max_y: 10.0, k: 20.0 }; - let mut out = Out { s: String::new(), first: true }; + let mut out = Out { recs: Vec::new(), solid: Vec::new() }; stamp_node(&mut out, &t, m, "0.3".into()); - let recs: Vec> = out.s.split('\u{1e}').map(|r| r.split('\u{1f}').collect()).collect(); + let s = out.finish(); + let recs: Vec> = s.split('\u{1e}').map(|r| r.split('\u{1f}').collect()).collect(); assert_eq!(recs[0], ["X", "opacity", "0.3"]); // Anker (40, 140 mm); 10 pt = 3.528 mm, Live-Zeile 0.8 ×; Block um den Anker zentriert. assert_eq!(&recs[1][..4], ["L", "", "x", "40"]); diff --git a/src-tauri/core/src/plan/scene.rs b/src-tauri/core/src/plan/scene.rs index d4cd2035..407d83b4 100644 --- a/src-tauri/core/src/plan/scene.rs +++ b/src-tauri/core/src/plan/scene.rs @@ -95,6 +95,8 @@ pub struct Scene { pub polylines: Vec, pub arcs: Vec, pub lines: Vec, + /// Linienenden und -ecken ([146], `LineEnds::code`), im Kopfwort der Binärszene. + pub line_ends: u32, } // ── Farben (wie `toRgba`/`withOpacity` der TS-Fassung) ────────────────────────────────────────── @@ -259,8 +261,14 @@ fn stitch_key(p: V2) -> (u64, u64) { /// Ergebnis: (Punkte, geschlossen). Gleiche Wahl wie die lineare Suche der TS-Fassung (der /// erste passende Lauf in Pool-Reihenfolge); ein Raster über den Endpunkten findet die Kandidaten. pub fn stitch_runs(runs: Vec>) -> Vec<(Vec, bool)> { + stitch_runs_members(&runs).into_iter().map(|(c, closed, _)| (c, closed)).collect() +} + +/// Wie [`stitch_runs`], zusätzlich die Indizes der beteiligten Läufe je Zug ([146]: Zeichen- +/// Reihenfolge je Zug statt je Gruppe). +pub fn stitch_runs_members(runs: &[Vec]) -> Vec<(Vec, bool, Vec)> { let mut end_count: HashMap<(u64, u64), u32> = HashMap::new(); - for r in &runs { + for r in runs { for p in [r[0], r[r.len() - 1]] { *end_count.entry(stitch_key(p)).or_insert(0) += 1; } @@ -291,6 +299,7 @@ pub fn stitch_runs(runs: Vec>) -> Vec<(Vec, bool)> { continue; } used[seed] = true; + let mut members = vec![seed]; let mut chain = runs[seed].clone(); let mut extended = true; while extended && !(chain.len() > 2 && same_pt(chain[0], chain[chain.len() - 1])) { @@ -337,6 +346,7 @@ pub fn stitch_runs(runs: Vec>) -> Vec<(Vec, bool)> { continue; } used[ci] = true; + members.push(ci); extended = true; break; } @@ -345,7 +355,7 @@ pub fn stitch_runs(runs: Vec>) -> Vec<(Vec, bool)> { if closed { chain.pop(); } - out.push((chain, closed)); + out.push((chain, closed, members)); } out } @@ -365,7 +375,8 @@ struct EdgeGroup { color: Rgba, width_mm: f64, runs: Vec>, - z: f64, + /// Zeichen-Stelle je Lauf; ein genähter Zug liegt an der spätesten seiner Läufe ([146]). + zs: Vec, } struct Builder { @@ -409,14 +420,14 @@ impl Builder { let gi = match self.group_of.get(&k) { Some(&g) => g, None => { - self.groups.push(EdgeGroup { color, width_mm, runs: Vec::new(), z }); + self.groups.push(EdgeGroup { color, width_mm, runs: Vec::new(), zs: Vec::new() }); self.group_of.insert(k, self.groups.len() - 1); self.groups.len() - 1 } }; let g = &mut self.groups[gi]; g.runs.push(run); - g.z = jsnum::max(g.z, z); + g.zs.push(z); } } @@ -562,7 +573,18 @@ pub fn build_scene(parts: &mut [Part], greyed_ranges: &[(usize, usize)]) -> Opti b.flush(); let col = with_opacity(stroke_color_for(cls.as_deref(), col_s.as_deref()), cls.as_deref(), greyed); let z = b.z(); - b.s.lines.push(SLine { a, b: bb, color: col, width_mm: w, dash, z }); + let solid = match &dash { + SDash::List(d) => d.is_empty(), + _ => true, + }; + if solid && w > 0.0 { + // [146] Volle Einzel-Linien (Wand-Umrisse im Raster-Pfad u. a.) mit den + // Kantenläufen gleicher Farbe/Breite zusammennähen: an Ecken EIN Zug mit + // Gehrung statt zweier flacher Enden (keine Kerbe). + b.edge_run(vec![a, bb], col, w, z); + } else { + b.s.lines.push(SLine { a, b: bb, color: col, width_mm: w, dash, z }); + } } } } @@ -605,11 +627,12 @@ pub fn build_scene(parts: &mut [Part], greyed_ranges: &[(usize, usize)]) -> Opti b.flush(); let groups = std::mem::take(&mut b.groups); for g in groups { - for (pts, closed) in stitch_runs(g.runs) { + for (pts, closed, members) in stitch_runs_members(&g.runs) { if pts.len() < 2 { continue; } - let s = SStroke { pts, color: g.color, width_mm: g.width_mm, dash: SDash::Absent, z: g.z, width_screen: false }; + let z = members.iter().fold(f64::NEG_INFINITY, |m, &i| jsnum::max(m, g.zs[i])); + let s = SStroke { pts, color: g.color, width_mm: g.width_mm, dash: SDash::Absent, z, width_screen: false }; if closed { b.s.outlines.push(s); } else { @@ -742,7 +765,7 @@ pub fn encode_scene_bin(s: &Scene, texts: &[SText]) -> Vec { } let mut out = Vec::with_capacity(total); out.extend_from_slice(b"DR2S"); - for v in [1u32, s.fills.len() as u32, s.outlines.len() as u32, s.polylines.len() as u32, s.arcs.len() as u32, s.lines.len() as u32, texts.len() as u32, n_pts as u32, n_dash as u32, str_bytes as u32, 0] { + for v in [1u32, s.fills.len() as u32, s.outlines.len() as u32, s.polylines.len() as u32, s.arcs.len() as u32, s.lines.len() as u32, texts.len() as u32, n_pts as u32, n_dash as u32, str_bytes as u32, s.line_ends] { out.extend_from_slice(&v.to_le_bytes()); } out.extend_from_slice(&pts); @@ -830,6 +853,7 @@ mod tests { ], arcs: vec![SArc { center: v2(1.0, 1.0), from: v2(2.0, 1.0), to: v2(1.0, 2.0), r: 1.0, color: [1.0, 0.0, 0.0, 1.0], width_mm: 0.125, dash: SDash::Absent }], lines: vec![SLine { a: v2(0.0, 0.0), b: v2(2600000.5, 1200000.25), color: [0.0, 0.5, 0.0, 1.0], width_mm: 0.35, dash: SDash::List(vec![3.0, 1.0, 0.5, 1.0]), z: 4.0 }], + line_ends: 0, }; let t = |x: f64, y: f64, content: &str, size_mm: f64, color: Rgba, align: u32| SText { pos: v2(x, y), size_mm, color, align, content: content.as_bytes().to_vec() }; let texts = vec![ @@ -847,6 +871,9 @@ mod tests { assert_eq!(encode_scene_bin(&s, &t), FIXTURE); // Leere Szene = reiner Kopf; Landeskoordinaten bleiben f64. assert_eq!(encode_scene_bin(&Scene::default(), &[]).len(), 48); + // [146] Linienenden im letzten Kopfwort (früher 0). + let le = encode_scene_bin(&Scene { line_ends: 9, ..Scene::default() }, &[]); + assert_eq!(&le[44..48], &9u32.to_le_bytes()); let mut l = Scene::default(); l.lines.push(SLine { a: v2(2600000.123456, 1200000.654321), b: v2(0.0, 0.0), color: [0.0; 4], width_mm: 0.1, dash: SDash::Null, z: 0.0 }); let b = encode_scene_bin(&l, &[]); diff --git a/src-tauri/core/src/plan/svg.rs b/src-tauri/core/src/plan/svg.rs index 87f2987d..9cd116b1 100644 --- a/src-tauri/core/src/plan/svg.rs +++ b/src-tauri/core/src/plan/svg.rs @@ -10,7 +10,10 @@ use crate::hatch::{self, Pattern, V2}; use crate::jsnum; use crate::plan::print_svg::{hatch_dash_paper, hatch_lines, is_generated, 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; +use crate::plan::scene::stitch_runs_members; +use std::collections::HashMap; use serde_json::Value; use std::f64::consts::PI; @@ -48,6 +51,53 @@ pub struct SvgOptions { pub max_y: f64, /// Schraffurlinien ausbreiten (wie der Druckpfad, an der Fläche beschnitten); Standard aus. pub hatch: bool, + /// Linienenden und -ecken ([146]) als Attribute eines umschliessenden ``. + pub line_ends: LineEnds, +} + +/// Volle, offene Striche gleicher Farbe/Breite/Deckkraft, am Ende zusammengenäht ([146]): Wand-Umrisse +/// zweier Wände treffen sich an der Ecke als EIN Zug mit Ecke (Gehrung) statt mit zwei flachen Enden. +/// Jeder Zug steht an der Stelle seines spätesten Laufs (Zeichen-Reihenfolge wie bisher). +#[derive(Default)] +struct Stitcher { + groups: Vec<(String, Vec>, Vec)>, + of: HashMap, +} + +impl Stitcher { + /// `attrs` = ` stroke=… stroke-width=…{op}`; `slot` = Platzhalter in `out`. + fn add(&mut self, attrs: String, run: Vec, slot: usize) { + let gi = *self.of.entry(attrs.clone()).or_insert_with(|| { + self.groups.push((attrs, Vec::new(), Vec::new())); + self.groups.len() - 1 + }); + self.groups[gi].1.push(run); + self.groups[gi].2.push(slot); + } + + fn finish(self, out: &mut [String], xs: &dyn Fn(f64) -> String, ys: &dyn Fn(f64) -> String) { + for (attrs, runs, slots) in self.groups { + for (pts, closed, members) in stitch_runs_members(&runs) { + if pts.len() < 2 { + continue; + } + let slot = members.iter().map(|&m| slots[m]).max().unwrap_or(0); + let el = if !closed && pts.len() == 2 { + format!("", xs(pts[0].x), ys(pts[0].y), xs(pts[1].x), ys(pts[1].y)) + } else { + let pl = pts.iter().map(|q| format!("{},{}", xs(q.x), ys(q.y))).collect::>().join(" "); + let tag = if closed { "polygon" } else { "polyline" }; + format!("<{tag} points=\"{pl}\" fill=\"none\"{attrs}/>") + }; + if out[slot].is_empty() { + out[slot] = el; + } else { + out[slot].push('\n'); + out[slot].push_str(&el); + } + } + } + } } /// Zahl aus JSON (null/fehlend → NaN wie `undefined`/`NaN` in JS-Rechnungen). @@ -91,6 +141,7 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option { let xs = |x: f64| num(x); let ys = |y: f64| num(top - y); let mut out: Vec = Vec::new(); + let mut stitch = Stitcher::default(); for part in parts.iter_mut() { let hatches = if o.hatch { part.view.hatch_table()? } else { Vec::new() }; for i in part.from..part.to { @@ -128,30 +179,18 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option { None => Vec::new(), }; if !nse.is_empty() && stroke != "none" && !stroke.is_empty() { - let k = pts.len(); - let mut d = String::new(); - for e in 0..k { - if nse.contains(&e) { - continue; - } - if e == 0 || nse.contains(&(e - 1)) { - d.push_str(&format!("M{},{}", xs(pts[e].x), ys(pts[e].y))); - } - let q = pts[(e + 1) % k]; - d.push_str(&format!(" L{},{}", xs(q.x), ys(q.y))); - } out.push(format!("", op(greyed, opacity(4)))); - if !d.is_empty() { - out.push(format!( - "", - num(f[2] * mm_to_m), - op(greyed, opacity(4)) - )); + // Sichtbare Kantenläufe zum Zusammennähen ([146]), Kanten in Ring-Reihenfolge. + let nse_f: Vec = nse.iter().map(|&e| e as f64).collect(); + let attrs = format!(" stroke=\"{stroke}\" stroke-width=\"{}\"{}", num(f[2] * mm_to_m), op(greyed, opacity(4))); + for run in crate::plan::scene::visible_edge_runs(&pts, &nse_f) { + out.push(String::new()); + stitch.add(attrs.clone(), run, out.len() - 1); } continue; } out.push(format!( - "", + "", num(f[2] * mm_to_m), op(greyed, opacity(4)) )); @@ -196,11 +235,14 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option { } T_LINE => { let color = if fl & F_COLOR != 0 { esc(part.str(f[1]).unwrap_or("")) } else { "#000".into() }; - let mut dash = dash_attr(part)?; - // [141] Volle Linien mit runder Kappe wie Bildschirm (render2d) und Druck: Wand-Umrisse - // zweier Wände treffen sich an der Ecke ohne Kerbe (Stumpf-Kappe liess sie offen). - if dash.is_empty() { - dash = " stroke-linecap=\"round\"".into(); + let dash = dash_attr(part)?; + // [146] Volle Linien: mit Kantenläufen gleicher Farbe/Breite zusammennähen (Ecke statt + // zweier Enden); Enden und Ecken erben die Projekt-Einstellung vom ``. + if dash.is_empty() && f[2] > 0.0 { + out.push(String::new()); + let attrs = format!(" stroke=\"{color}\" stroke-width=\"{}\"{}", num(f[2] * mm_to_m), op(greyed, opacity(3))); + stitch.add(attrs, vec![V2 { x: f[4], y: f[5] }, V2 { x: f[6], y: f[7] }], out.len() - 1); + continue; } out.push(format!( "", @@ -326,8 +368,10 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option { } } } + stitch.finish(&mut out, &xs, &ys); + out.retain(|s| !s.is_empty()); Some(format!( - "\n\n\n{}\n\n", + "\n\n\n\n{}\n\n\n", num(x0), num(w), num(h), @@ -336,6 +380,7 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option { num(x0), num(w), num(h), + o.line_ends.svg_attrs(), out.join("\n") )) } @@ -355,10 +400,11 @@ mod tests { assert_eq!(op(false, Some(1.0)), ""); } - /// [141] Wand-Umrisse als volle Linien bzw. offene Kantenläufe (Stossfugen nicht gestrichen) tragen - /// runde Kappen: an der Ecke zweier Wände bleibt keine Kerbe (Stumpf-Kappe, halbe Strichbreite). + /// [146] Wand-Umrisse als volle Linie bzw. offene Kantenläufe (Stossfugen nicht gestrichen) werden + /// an der gemeinsamen Ecke zu EINEM Zug genäht (Gehrung statt zweier flacher Enden = keine Kerbe); + /// Enden und Ecken stehen einmal am umschliessenden ``. #[test] - fn umriss_mit_runder_kappe() { + fn umriss_ecke_als_zug() { use crate::model::Vec2; use crate::plan::buf::{View, Writer}; use crate::plan::prim::Primitive; @@ -392,10 +438,16 @@ mod tests { let view = View::parse(&bytes).unwrap(); let n = view.len(); let mut parts = vec![Part::new(view, 0, n).unwrap()]; - let svg = plan_svg(&mut parts, &SvgOptions { scale_denominator: 50.0, margin_m: 0.5, min_x: 0.0, min_y: 0.0, max_x: 4.0, max_y: 4.0, hatch: false }).unwrap(); - let path = svg.lines().find(|l| l.starts_with(""), "{svg}"); + assert!(!svg.contains(" Vec { - crate::gpu_compile::compile_flat(buf, from as usize, to as usize, px_per_meter, packed_lines) +pub fn gpu_compile_flat(buf: &[u8], from: u32, to: u32, px_per_meter: f64, packed_lines: bool, line_ends: u32) -> Vec { + crate::gpu_compile::compile_flat(buf, from as usize, to as usize, px_per_meter, packed_lines, LineEnds::from_code(line_ends as f64)) } /// Wie [`gpu_compile_flat`] auf einem gehaltenen Puffer (`plan_buf_hold`); leer, wenn er nicht /// mehr gehalten wird. #[wasm_bindgen] -pub fn gpu_compile_held(id: u32, from: u32, to: u32, px_per_meter: f64, packed_lines: bool) -> Vec { - super::plan_buf::with_held(id, |b| crate::gpu_compile::compile_flat(b, from as usize, to as usize, px_per_meter, packed_lines)).unwrap_or_default() +pub fn gpu_compile_held(id: u32, from: u32, to: u32, px_per_meter: f64, packed_lines: bool, line_ends: u32) -> Vec { + super::plan_buf::with_held(id, |b| crate::gpu_compile::compile_flat(b, from as usize, to as usize, px_per_meter, packed_lines, LineEnds::from_code(line_ends as f64))).unwrap_or_default() } /// Ear-Clipping eines Rings `[x, y, …]` → Dreiecks-Indizes. diff --git a/src-tauri/core/src/web/plan_scene.rs b/src-tauri/core/src/web/plan_scene.rs index 924ac561..7a73b739 100644 --- a/src-tauri/core/src/web/plan_scene.rs +++ b/src-tauri/core/src/web/plan_scene.rs @@ -7,6 +7,7 @@ use crate::plan::parts::{parts_from, ranges_from}; use crate::plan::scene::SText; use crate::plan::text::scene_texts; use crate::plan::scene::{build_scene, encode_scene_bin, encode_scene_f64, Scene}; +use crate::plan::line_ends::LineEnds; use wasm_bindgen::prelude::wasm_bindgen; fn scene_of(segs: &[f64], greyed: &[f64]) -> Option { @@ -23,12 +24,16 @@ fn texts_of(segs: &[f64], greyed: &[f64], paper_scale_n: f64) -> Option Vec { +pub fn plan_scene_bin(segs: &[f64], greyed: &[f64], paper_scale_n: f64, line_ends: u32) -> Vec { let Some(texts) = texts_of(segs, greyed, paper_scale_n) else { return Vec::new() }; match scene_of(segs, greyed) { - Some(s) => encode_scene_bin(&s, &texts), + Some(mut s) => { + s.line_ends = LineEnds::from_code(line_ends as f64).code(); + encode_scene_bin(&s, &texts) + } None => Vec::new(), } } diff --git a/src-tauri/core/src/web/plan_svg.rs b/src-tauri/core/src/web/plan_svg.rs index e55a7111..01fd4159 100644 --- a/src-tauri/core/src/web/plan_svg.rs +++ b/src-tauri/core/src/web/plan_svg.rs @@ -1,19 +1,22 @@ //! Bindung des SVG-Text-Exports (`crate::plan::svg`) auf gehaltenen Plan-Puffern (Abschnitte wie //! `plan_parts`). Leerer Text = Puffer fehlt oder kaputt (TS legt neu ab und fragt nochmals). +use crate::plan::line_ends::LineEnds; use crate::plan::parts::parts_from; use crate::plan::svg::{plan_svg, SvgOptions}; use wasm_bindgen::prelude::wasm_bindgen; -/// `opts` = `[Massstab-Nenner, Rand m, minX, minY, maxX, maxY, (Schraffur 0/1)]`. +/// `opts` = `[Massstab-Nenner, Rand m, minX, minY, maxX, maxY, (Schraffur 0/1, (Linienenden +/// `cap | join << 2`, [146]))]`. #[wasm_bindgen] pub fn plan_svg_string(segs: &[f64], opts: &[f64]) -> String { - let hatch = opts.len() == 7 && opts[6] != 0.0; + let hatch = opts.len() >= 7 && opts[6] != 0.0; + let line_ends = LineEnds::from_code(opts.get(7).copied().unwrap_or(0.0)); let [n, margin, min_x, min_y, max_x, max_y] = match <[f64; 6]>::try_from(&opts[..opts.len().min(6)]) { Ok(a) => a, Err(_) => return String::new(), }; let Some(held) = super::plan_buf::held_for_segs(segs) else { return String::new() }; let Some(mut parts) = parts_from(segs, |nr| held.iter().find(|e| e.0 == nr).map(|e| &*e.1)) else { return String::new() }; - plan_svg(&mut parts, &SvgOptions { scale_denominator: n, margin_m: margin, min_x, min_y, max_x, max_y, hatch }).unwrap_or_default() + plan_svg(&mut parts, &SvgOptions { scale_denominator: n, margin_m: margin, min_x, min_y, max_x, max_y, hatch, line_ends }).unwrap_or_default() } diff --git a/src-tauri/render2d/src/chunks.rs b/src-tauri/render2d/src/chunks.rs index efe6f6a8..33b5116e 100644 --- a/src-tauri/render2d/src/chunks.rs +++ b/src-tauri/render2d/src/chunks.rs @@ -31,7 +31,7 @@ const GREY: f32 = 0.549; const PX_PER_M: f64 = 90.0; /// Linien-Shader fuer das KOMPAKTE Vertex-Format der Webview (12 statt 24 Byte): -/// `position` (2 x f32) + `packed` (4 x snorm8 = bisector.xy, side, miter). +/// `position` (2 x f32) + `packed` (4 x snorm8 = bisector.xy, side, (miter − 1) / 3). /// Rechnung identisch zu `shaders::LINE_WGSL`. const LINE_PACKED_WGSL: &str = r#" struct Globals { @@ -58,7 +58,9 @@ fn vs_main(in : VsIn) -> @builtin(position) vec4 { if (len > 1e-6) { unit_px = dir_px / len; } - let width_px = max(1.0, globals.stroke_px * globals.stroke_scale) * in.packed.w; + // Laengenfaktor ([146]): Byte 0 = 1 (normale Kante), bis 4 (Gehrungsspitze, Ecke der Kappe). + let miter = 1.0 + max(in.packed.w, 0.0) * 3.0; + let width_px = max(1.0, globals.stroke_px * globals.stroke_scale) * miter; let offset_px = unit_px * (width_px * 0.5) * in.packed.z; return vec4(clip_p.xy + offset_px / (globals.viewport_px * 0.5), clip_p.z, clip_p.w); } diff --git a/src-tauri/render2d/src/demo.rs b/src-tauri/render2d/src/demo.rs index 80881ca7..3db2d346 100644 --- a/src-tauri/render2d/src/demo.rs +++ b/src-tauri/render2d/src/demo.rs @@ -127,6 +127,7 @@ pub fn demo_scene() -> Scene { color: ink, align: TextAlign::Center, }], + line_ends: 0, } } diff --git a/src-tauri/render2d/src/gpu.rs b/src-tauri/render2d/src/gpu.rs index ebe803ae..ca9e1db3 100644 --- a/src-tauri/render2d/src/gpu.rs +++ b/src-tauri/render2d/src/gpu.rs @@ -81,7 +81,7 @@ struct ArcInstance { /// (r_screen, a0, sweep, r_model) geom: [f32; 4], color: [f32; 4], - /// (width_mm, dash_total, dash_count, _pad) + /// (width_mm, dash_total, dash_count, cap) — cap [146]: 0 flach, 1 rund, 2 vorstehend wdash: [f32; 4], /// bis zu MAX_ARC_DASH An/Aus-Laengen (Modell-Meter). dash: [f32; 4], @@ -95,7 +95,7 @@ impl ArcInstance { center: a.center, geom: [a.r_screen, a.a0, a.sweep, a.r_model], color: a.color, - wdash: [a.width_mm, a.dash_total, a.dash_count as f32, 0.0], + wdash: [a.width_mm, a.dash_total, a.dash_count as f32, a.cap as f32], dash: a.dash, } } diff --git a/src-tauri/render2d/src/scene_bin.rs b/src-tauri/render2d/src/scene_bin.rs index 4585f374..3cb82ac6 100644 --- a/src-tauri/render2d/src/scene_bin.rs +++ b/src-tauri/render2d/src/scene_bin.rs @@ -3,7 +3,8 @@ // // Aufbau (alle Abschnitte lueckenlos hintereinander, kein Fuellmaterial): // Kopf, 48 Byte: magic "DR2S" | version u32 | n_fills n_outlines n_polylines n_arcs -// n_lines n_texts (je u32) | n_pts u32 | n_dash u32 | str_bytes u32 | 0 u32 +// n_lines n_texts (je u32) | n_pts u32 | n_dash u32 | str_bytes u32 | +// line_ends u32 ([146] `cap | join << 2`, frueher 0 = flach + Gehrung) // Punkte: n_pts x (x f64, y f64) in Modell-Metern (LV95-gross moeglich). Gemeinsamer // Pool, der der Reihe nach verbraucht wird: Fuellungen, Umrisse, Polylinien // (je `n` Punkte), Boegen (je 3: Mitte, von, nach), Linien (je 2), Texte (je 1). @@ -123,7 +124,8 @@ pub fn decode_scene(bytes: &[u8]) -> Result { let n_pts = r.u32() as u64; let n_dash = r.u32() as u64; let str_bytes = r.u32() as u64; - let _reserved = r.u32(); + // Frueher reserviert (0), seit [146] Linienenden/-ecken `cap | join << 2`. + let line_ends = r.u32() & 0xf; // Gesamtlaenge in u64 vorab pruefen (u32-Zaehler * kleine Faktoren laufen nicht // ueber), bevor irgendetwas alloziert wird. @@ -207,6 +209,7 @@ pub fn decode_scene(bytes: &[u8]) -> Result { if pts.next != n_pts || dashes.next != dashes.v.len() { return Err("Pools nicht vollstaendig verbraucht".into()); } + scene.line_ends = line_ends; Ok(scene) } @@ -240,6 +243,7 @@ mod tests { Text { pos: [3.0, 4.0], content: String::new(), size_mm: 2.0, color: [0.0, 0.0, 0.0, 1.0], align: TextAlign::Right }, Text { pos: [5.0, 6.0], content: "A".into(), size_mm: 1.0, color: [0.0, 0.0, 1.0, 1.0], align: TextAlign::Left }, ], + line_ends: 0, } } @@ -264,6 +268,15 @@ mod tests { assert_same(&decode_scene(&b).unwrap(), &Scene::default()); } + #[test] + fn linienenden_im_kopf() { + // [146] Das frühere Reservewort trägt `cap | join << 2`; alte Szenen (0) = flach + Gehrung. + assert_eq!(decode_scene(FIXTURE).unwrap().line_ends, 0); + let mut v = FIXTURE.to_vec(); + v[44..48].copy_from_slice(&(1u32 | 2 << 2).to_le_bytes()); + assert_eq!(decode_scene(&v).unwrap().line_ends, 9); + } + #[test] fn rejects_foreign_version_magic_and_truncation() { let mut v = FIXTURE.to_vec(); @@ -417,7 +430,7 @@ mod roundtrip { (pts.len() / 16) as u32, (dash.len() / 4) as u32, strs.len() as u32, - 0, + s.line_ends, ] { out.extend_from_slice(&v.to_le_bytes()); } diff --git a/src-tauri/render2d/src/shaders.rs b/src-tauri/render2d/src/shaders.rs index ffa323c6..72f189fa 100644 --- a/src-tauri/render2d/src/shaders.rs +++ b/src-tauri/render2d/src/shaders.rs @@ -211,7 +211,6 @@ fn fs_main(in : VsOut) -> @location(0) vec4 { // 1) Radiale Kante (Strichbreite quer zum Bogen), analytisch antialiased. let d_ring_px = abs(dist - r_s) * pps; let half_w_px = 0.5 * max(1.0, width_mm * g.stroke_scale); - let cov_radial = 1.0 - smoothstep(half_w_px - 0.6, half_w_px + 0.6, d_ring_px); // 2) Winkel-Clamp auf [min(0,sweep), max(0,sweep)] mit Butt-Cap an den Enden. let theta = atan2(rel.y, rel.x); @@ -228,7 +227,17 @@ fn fs_main(in : VsOut) -> @location(0) vec4 { sd = -min(da - lo, hi - da); } let cap_px = sd * r_s * pps; // signierter Abstand zur Kappe (Geraete-px) - let cov_cap = 1.0 - smoothstep(-0.5, 0.5, cap_px); + // [146] Linienende: 0 flach, 1 rund (Abstand zum Endpunkt), 2 vorstehend (um halbe Breite). + let cap_kind = i32(in.wdash.w + 0.5); + var cov_cap = 1.0 - smoothstep(-0.5, 0.5, cap_px); + var cov_radial = 1.0 - smoothstep(half_w_px - 0.6, half_w_px + 0.6, d_ring_px); + if (cap_kind == 2) { + cov_cap = 1.0 - smoothstep(-0.5, 0.5, cap_px - half_w_px); + } else if (cap_kind == 1 && cap_px > 0.0) { + cov_cap = 1.0; + let d_end = length(vec2(cap_px, d_ring_px)); + cov_radial = 1.0 - smoothstep(half_w_px - 0.6, half_w_px + 0.6, d_end); + } // 3) Dash: Bogenlaenge ab a0 (Modell-Meter) modulo Muster, weicher Uebergang. var cov_dash = 1.0; @@ -359,7 +368,10 @@ fn fs_main(in : VsOut) -> @location(0) vec4 { let sc = clamp(s, in.seg.x, in.seg.y); let e_out = abs(s - sc); let total = in.pat.x; - let n = i32(in.pat.y + 0.5); + // `count` traegt `16 · cap` ([146]): 0 flach, 1 rund, 2 vorstehend. + let nc = i32(in.pat.y + 0.5); + let n = nc % 16; + let cap_kind = nc / 16; var e_in = 0.0; if (n > 0 && total > 1e-6) { let k = floor(sc / total); @@ -391,9 +403,17 @@ fn fs_main(in : VsOut) -> @location(0) vec4 { // [140] Deckung unter 1 Geraete-px wie `LINE_WGSL`. var a = globals.color.a * clamp(globals.stroke_px * globals.stroke_scale, 0.35, 1.0); if (e > 0.0) { - // Rundes Strich-Ende (Abstand zum Strich), Kante ~1 px weich wie die Boegen. - let d = sqrt(e * e + y * y); - a = a * (1.0 - smoothstep(hw - 0.5, hw + 0.5, d)); + // Innere Ecke eines Zugs (nicht in einer Luecke): rund verbunden wie bisher. + let inner = e_in <= 0.0 && sc > 1e-3 && sc < in.seg.z - 1e-3; + if (cap_kind == 1 || inner) { + // Rundes Strich-Ende (Abstand zum Strich), Kante ~1 px weich wie die Boegen. + let d = sqrt(e * e + y * y); + a = a * (1.0 - smoothstep(hw - 0.5, hw + 0.5, d)); + } else if (cap_kind == 2) { + a = a * (1.0 - smoothstep(hw - 0.5, hw + 0.5, max(e, abs(y)))); + } else { + a = a * (1.0 - smoothstep(0.0, 1.0, e)); + } } if (a <= 0.002) { discard; diff --git a/src-tauri/render2d/src/tessellate.rs b/src-tauri/render2d/src/tessellate.rs index fa4c922a..c9484ef5 100644 --- a/src-tauri/render2d/src/tessellate.rs +++ b/src-tauri/render2d/src/tessellate.rs @@ -62,6 +62,8 @@ pub struct ArcInstanceData { pub dash_count: u32, /// Summe der gueltigen `dash`-Eintraege (Zykluslaenge, Modell-Meter). pub dash_total: f32, + /// Linienende ([146]): 0 flach, 1 rund, 2 vorstehend. + pub cap: u32, } /// Hoechstzahl Eintraege eines Linien-Strichmusters (nach Verdoppeln ungerader Muster), die der @@ -84,7 +86,8 @@ pub struct DashSegment { pub run_len: f32, /// Zykluslaenge (Bildschirm-Einheiten). pub total: f32, - /// Gueltige Eintraege in `dash` (gerade Indizes = Strich, ungerade = Luecke). + /// Gueltige Eintraege in `dash` (gerade Indizes = Strich, ungerade = Luecke) plus + /// `16 · cap` ([146] Linienende: 0 flach, 1 rund, 2 vorstehend; Muster mit Punkten immer rund). pub count: u32, /// An/Aus-Laengen (Bildschirm-Einheiten). pub dash: [f32; MAX_LINE_DASH], @@ -315,11 +318,17 @@ fn stroke_dashed_or_solid( // Ungueltiges Muster: ein offener Zug (wie `split_dash` → ein Stueck); sehr lange // Muster zerlegt weiter die CPU. _ => { + // Punkte im Muster brauchen runde Enden ([96]), auch bei flacher Einstellung ([146]). + let saved = geo.ends; + if d.iter().step_by(2).any(|v| *v <= 0.0) { + geo.ends.cap = 1; + } for piece in split_dash(pts, d) { if piece.len() >= 2 { geo.stroke_polyline(&piece, false, color, stroke_mm, width_screen, bounds); } } + geo.ends = saved; } }, _ => geo.stroke_polyline(pts, closed, color, stroke_mm, width_screen, bounds), @@ -508,6 +517,27 @@ pub struct GpuGeometry { pub draw_sequence: Vec<(BatchKind, u32)>, /// Modell-Bounds (Meter) fuer Debug/Einpassen; nicht render-kritisch. pub bounds: [f32; 4], // [min_x, min_y, max_x, max_y] + /// Linienenden und -ecken der Szene ([146]). + pub ends: LineEnds, +} + +/// Linienenden und -ecken ([146], `Scene::line_ends`): cap 0 flach, 1 rund, 2 vorstehend; +/// join 0 Gehrung (bis [`MITER_LIMIT`], sonst gefast), 1 rund, 2 gefast. +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +pub struct LineEnds { + pub cap: u32, + pub join: u32, +} + +/// Gehrungsgrenze wie SVG `stroke-miterlimit` (Gehrungslaenge / Strichbreite). +pub const MITER_LIMIT: f32 = 4.0; + +impl LineEnds { + pub fn from_code(c: u32) -> Self { + let cap = c & 3; + let join = (c >> 2) & 3; + Self { cap: if cap > 2 { 0 } else { cap }, join: if join > 2 { 0 } else { join } } + } } #[inline] @@ -599,6 +629,8 @@ impl GpuGeometry { *d = c * PX_PER_M; } let total: f32 = cycle_m.iter().sum::() * PX_PER_M; + // Punkte (Strich der Laenge 0) brauchen runde Enden, sonst sind sie unsichtbar ([96]). + let cap = if cycle_m.iter().step_by(2).any(|d| *d <= 0.0) { 1 } else { self.ends.cap }; let before = self.dash_segments.len(); let mut s0 = 0.0f32; for (w, &l) in pts.windows(2).zip(&lens) { @@ -613,7 +645,7 @@ impl GpuGeometry { s0: s0 * PX_PER_M, run_len: run * PX_PER_M, total, - count: cycle_m.len() as u32, + count: cycle_m.len() as u32 + 16 * cap, dash, }); s0 += l; @@ -772,6 +804,52 @@ impl GpuGeometry { add_fan_arc(verts, idx, p, a0, a0 + sweep_sign * std::f32::consts::PI); } + // [146] Gehrung (bis `MITER_LIMIT`, sonst gefast) bzw. Fase: Dreiecke auf der Aussenseite, + // Spitze mit Laengenfaktor `m` im 6. Vertex-Wert (Shader: Breite · miter). + #[inline] + fn add_miter_join(verts: &mut Vec, idx: &mut Vec, p: Point, d1: Point, d2: Point, miter: bool) { + let turn = d1[0] * d2[1] - d1[1] * d2[0]; + let dot = d1[0] * d2[0] + d1[1] * d2[1]; + if (turn.abs() < 1e-6 && dot > 0.0) || dot < -0.9999 { + return; // gerade bzw. Umkehr (flach wie SVG bei ueberschrittener Grenze) + } + let outer = if turn > 0.0 { -1.0 } else { 1.0 }; + let n1 = left_normal_of(d1); + let n2 = left_normal_of(d2); + let u1 = [outer * n1[0], outer * n1[1]]; + let u2 = [outer * n2[0], outer * n2[1]]; + let ic = push_vert(verts, p, [1.0, 0.0], 0.0); + let i1 = push_vert(verts, p, u1, 1.0); + let i2 = push_vert(verts, p, u2, 1.0); + let cos_half = ((1.0 + dot) * 0.5).max(0.0).sqrt(); + let m = if cos_half > 1e-6 { 1.0 / cos_half } else { f32::INFINITY }; + if miter && m <= MITER_LIMIT { + let b = [u1[0] + u2[0], u1[1] + u2[1]]; + let bl = (b[0] * b[0] + b[1] * b[1]).sqrt(); + verts.extend_from_slice(&[p[0], p[1], b[0] / bl, b[1] / bl, 1.0, m]); + let it = (verts.len() / 6 - 1) as u32; + idx.extend_from_slice(&[ic, i1, it, ic, it, i2]); + } else { + idx.extend_from_slice(&[ic, i1, i2]); + } + } + + // [146] Vorstehende Kappe: Rechteck um die halbe Breite nach aussen (`e` = Richtung weg + // von der Linie); Ecken diagonal mit Faktor sqrt(2). + #[inline] + fn add_square_cap(verts: &mut Vec, idx: &mut Vec, p: Point, n: Point, e: Point) { + let r = std::f32::consts::FRAC_1_SQRT_2; + let m = std::f32::consts::SQRT_2; + let ia = push_vert(verts, p, n, 1.0); + let ib = push_vert(verts, p, n, -1.0); + verts.extend_from_slice(&[p[0], p[1], (n[0] + e[0]) * r, (n[1] + e[1]) * r, 1.0, m]); + let ic = (verts.len() / 6 - 1) as u32; + verts.extend_from_slice(&[p[0], p[1], (-n[0] + e[0]) * r, (-n[1] + e[1]) * r, 1.0, m]); + let id = (verts.len() / 6 - 1) as u32; + idx.extend_from_slice(&[ia, ic, id, ia, id, ib]); + } + + let ends = self.ends; for v in 0..k { let has_in = closed || v > 0; let has_out = closed || v < k - 1; @@ -782,6 +860,19 @@ impl GpuGeometry { }; let d_out = if has_out { seg_dir[v % segs] } else { None }; match (d_in, d_out) { + (Some(di), Some(do_)) if ends.join != 1 => { + add_miter_join(&mut self.line_verts, &mut self.line_idx, s[v], di, do_, ends.join == 0) + } + (None, Some(d)) if ends.cap != 1 => { + if ends.cap == 2 { + add_square_cap(&mut self.line_verts, &mut self.line_idx, s[v], left_normal_of(d), [-d[0], -d[1]]); + } + } + (Some(d), None) if ends.cap != 1 => { + if ends.cap == 2 { + add_square_cap(&mut self.line_verts, &mut self.line_idx, s[v], left_normal_of(d), d); + } + } (Some(di), Some(do_)) => { add_round_join(&mut self.line_verts, &mut self.line_idx, s[v], di, do_) } @@ -857,7 +948,7 @@ impl Bounds { /// ist zoom-INVARIANT: Papier-mm-Striche wie auch die Bogen-Kanten werden erst im /// Shader auf Geraete-px abgebildet — keine Neu-Tessellierung bei Zoom noetig. pub fn compile_scene(scene: &Scene) -> GpuGeometry { - let mut geo = GpuGeometry::default(); + let mut geo = GpuGeometry { ends: LineEnds::from_code(scene.line_ends), ..GpuGeometry::default() }; let mut bounds = Bounds::new(); // Maler-Reihenfolge herstellen: alle Elemente (Fuellungen, Umrisse, offene @@ -982,6 +1073,7 @@ fn compile_arc(geo: &mut GpuGeometry, a: &Arc, bounds: &mut Bounds) { dash, dash_count, dash_total, + cap: geo.ends.cap, }); // Modell-Bounds: Bounding-Box des vollen Kreises (grosszuegig, aber sicher // fuer "Einpassen"; der sichtbare Bogen liegt stets darin). @@ -1077,6 +1169,74 @@ mod tests { // --- Strichmuster im Shader (DashSegment, dash_coverage) ------------------- + // --- [146] Linienenden und -ecken ------------------------------------------- + + fn poly_scene(pts: Vec, line_ends: u32) -> GpuGeometry { + compile_scene(&Scene { + polylines: vec![crate::types::Polyline { pts, color: [0.0, 0.0, 0.0, 1.0], width_mm: 0.5, dash: None, z: 0, width_screen: false }], + line_ends, + ..Scene::default() + }) + } + + /// Längenfaktoren (6. Wert) aller Vertices. + fn miters(g: &GpuGeometry) -> Vec { + g.line_verts.chunks_exact(6).map(|v| v[5]).collect() + } + + #[test] + fn flach_mit_gehrung_ist_standard() { + // Rechter Winkel: zwei Segment-Quads + Gehrung (2 Dreiecke, Spitze mit Faktor sqrt(2)), + // keine Kappen an den offenen Enden. + let g = poly_scene(vec![[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]], 0); + assert_eq!(g.line_idx.len(), 2 * 6 + 2 * 3); + let tip: Vec = miters(&g).into_iter().filter(|m| *m != 1.0).collect(); + assert_eq!(tip.len(), 1); + assert!((tip[0] - std::f32::consts::SQRT_2).abs() < 1e-5, "{tip:?}"); + // Gerade Linie: nur das Quad. + assert_eq!(poly_scene(vec![[0.0, 0.0], [1.0, 0.0]], 0).line_idx.len(), 6); + } + + #[test] + fn spitzer_winkel_ueber_gehrungsgrenze_wird_gefast() { + // ~10 Grad Innenwinkel: Gehrungsfaktor ~11.5 > 4 → nur das Fasen-Dreieck. + let a = 10f32.to_radians(); + let g = poly_scene(vec![[1.0, 0.0], [0.0, 0.0], [a.cos(), a.sin()]], 0); + assert_eq!(g.line_idx.len(), 2 * 6 + 3); + assert!(miters(&g).iter().all(|m| *m == 1.0)); + // Gefast (join 2) auch im rechten Winkel. + let g = poly_scene(vec![[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]], 2 << 2); + assert_eq!(g.line_idx.len(), 2 * 6 + 3); + } + + #[test] + fn vorstehende_und_runde_kappen() { + // Vorstehend: je Ende ein Rechteck (2 Dreiecke) mit zwei Ecken im Faktor sqrt(2). + let g = poly_scene(vec![[0.0, 0.0], [1.0, 0.0]], 2); + assert_eq!(g.line_idx.len(), 6 + 2 * 6); + assert_eq!(miters(&g).iter().filter(|m| (**m - std::f32::consts::SQRT_2).abs() < 1e-5).count(), 4); + // Rund (Kappe + Ecke rund): Halbkreis-Fächer an beiden Enden, Fächer an der Ecke. + let r = poly_scene(vec![[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]], 1 | 1 << 2); + assert!(r.line_idx.len() > 2 * 6 + 2 * 3 * 10, "{}", r.line_idx.len()); + assert!(miters(&r).iter().all(|m| *m == 1.0)); + } + + #[test] + fn strich_instanzen_tragen_die_kappe() { + let scene = |line_ends, dash: Vec| Scene { + lines: vec![Line { a: [0.0, 0.0], b: [3.0, 0.0], color: [0.0; 4], width_mm: 0.25, dash: Some(dash), z: 0 }], + line_ends, + ..Scene::default() + }; + assert_eq!(compile_scene(&scene(0, vec![2.0, 1.0])).dash_segments[0].count, 2); + assert_eq!(compile_scene(&scene(2, vec![2.0, 1.0])).dash_segments[0].count, 2 + 32); + // Punkte bleiben rund, auch bei flacher Einstellung. + assert_eq!(compile_scene(&scene(0, vec![2.0, 1.0, 0.0, 1.0])).dash_segments[0].count, 4 + 16); + // Bögen: Kappe im Instanz-Feld. + let arc = Scene { arcs: vec![Arc { center: [0.0, 0.0], from: [1.0, 0.0], to: [0.0, 1.0], r: 1.0, color: [0.0; 4], width_mm: 0.25, dash: None }], line_ends: 1, ..Scene::default() }; + assert_eq!(compile_scene(&arc).arcs[0].cap, 1); + } + fn dashed_line(a: Point, b: Point, dash: Vec) -> Scene { Scene { lines: vec![Line { a, b, color: [0.2, 0.2, 0.2, 1.0], width_mm: 0.13, dash: Some(dash), z: 0 }], ..Scene::default() } } @@ -1136,7 +1296,7 @@ mod tests { assert!((c[0] - 12.0 * DASH_MM_TO_M).abs() < 1e-6); let geo = compile_scene(&dashed_line([0.0, 0.0], [5.0, 0.0], vec![12.0, 1.5, 0.0, 1.5])); assert_eq!(geo.dash_segments.len(), 1); - assert_eq!(geo.dash_segments[0].count, 4); + assert_eq!(geo.dash_segments[0].count, 4 + 16, "Punkte: Kappe rund ([146])"); // Deckung: der Punkt liegt bei 13.5 mm (Muster-Raum) und ist rund sichtbar, die Luecken nicht. let px = PX_PER_M; // 1 Bildschirm-Einheit = 1 px let cyc: Vec = c.iter().map(|d| d * px).collect(); diff --git a/src-tauri/render2d/src/types.rs b/src-tauri/render2d/src/types.rs index d8a1d9cd..8f6948de 100644 --- a/src-tauri/render2d/src/types.rs +++ b/src-tauri/render2d/src/types.rs @@ -180,6 +180,10 @@ pub struct Scene { pub lines: Vec, #[serde(default)] pub texts: Vec, + /// Linienenden und -ecken ([146]) `cap | join << 2`: cap 0 flach, 1 rund, 2 vorstehend; + /// join 0 Gehrung (Grenze 4, sonst gefast), 1 rund, 2 gefast. 0 = Standard. + #[serde(default)] + pub line_ends: u32, } /// Rechteckiger Ausschnitt in BILDSCHIRM-Einheiten (viewBox), analog `ViewBox` diff --git a/src/App.tsx b/src/App.tsx index 5ccd36fa..f47557f6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -29,6 +29,7 @@ import type { } from "./model/types"; import { generatePlan, computeKennzahlen, checkRoomProgram } from "./core"; import { addedItems } from "./core"; +import { lineEndsOf, type LineEnds } from "./core"; import { programStatusLabel } from "./panels/KennzahlenSection"; import { sectionPlaneFromLevel, sectionUAxisModel } from "./core"; import { setDxfImportTrigger } from "./io/dxfImportHook"; @@ -1634,6 +1635,12 @@ export default function App() { // Befehle auf die echten Setter an (siehe native/settingsWindow.ts). const setScaleLineWeights = (on: boolean) => applyChange((p) => setFieldIfChanged(p, "scaleLineWeights", on ? true : undefined)); + // [146] Linienenden/-ecken: Standard (flach, Gehrung) = Feld weglassen; beide Felder ein Undo-Schritt. + const setLineEnds = (e: LineEnds) => + groupChanges(() => { + applyChange((p) => setFieldIfChanged(p, "lineCap", e.cap === "butt" ? undefined : e.cap)); + applyChange((p) => setFieldIfChanged(p, "lineJoin", e.join === "miter" ? undefined : e.join)); + }); useSettingsWindowHost( { themeMode, @@ -1641,6 +1648,7 @@ export default function App() { snapColor, referenceElevationMasl: project.referenceElevationMasl, scaleLineWeights: project.scaleLineWeights === true, + lineEnds: lineEndsOf(project), offline, aiAccess, layout, @@ -1651,6 +1659,7 @@ export default function App() { onSnapColorChange: setSnapColor, onReferenceElevationChange: (n) => applyChange((p) => setFieldIfChanged(p, "referenceElevationMasl", n)), onScaleLineWeightsChange: setScaleLineWeights, + onLineEndsChange: setLineEnds, onOfflineChange, onAiAccessChange: setAiAccessEnabled, onApplyLayout: (l) => setLayout(reconcileLayout(l)), @@ -2728,6 +2737,8 @@ export default function App() { onReferenceElevationChange={(n) => applyChange((p) => setFieldIfChanged(p, "referenceElevationMasl", n))} scaleLineWeights={project.scaleLineWeights === true} onScaleLineWeightsChange={setScaleLineWeights} + lineEnds={lineEndsOf(project)} + onLineEndsChange={setLineEnds} offline={offline} onOfflineChange={onOfflineChange} aiAccess={aiAccess} diff --git a/src/cli/__golden__/ansicht.svg b/src/cli/__golden__/ansicht.svg index 3aff1d35..81a1e9d2 100644 --- a/src/cli/__golden__/ansicht.svg +++ b/src/cli/__golden__/ansicht.svg @@ -1,77 +1,62 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/cli/__golden__/grundriss-eg.svg b/src/cli/__golden__/grundriss-eg.svg index 29bf5155..1a595688 100644 --- a/src/cli/__golden__/grundriss-eg.svg +++ b/src/cli/__golden__/grundriss-eg.svg @@ -1,129 +1,116 @@ - - + + + Wohnen 17.01 m² HNF · Hauptnutzfläche - - - - - + + + + - - - - - - - + + + + + + - - - - - - - - + + + + + - - - - - - + + + + - - - - - - + + + + + - - - - - - - + + + + + + - - - - - - - - + + + + + - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - - - - - - + + + + + + - - - - + + + A - - - - + + + A - + - - - - + + + Süd - - - - + + + Süd - + + diff --git a/src/cli/__golden__/schnitt.svg b/src/cli/__golden__/schnitt.svg index e530ab09..5e6cce72 100644 --- a/src/cli/__golden__/schnitt.svg +++ b/src/cli/__golden__/schnitt.svg @@ -1,94 +1,65 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/core/extra.ts b/src/core/extra.ts index 22fc5fc4..59394696 100644 --- a/src/core/extra.ts +++ b/src/core/extra.ts @@ -84,3 +84,6 @@ export { callAiTool } from "./aiTools"; export type { AiHost } from "./aiTools"; export { PRESENTATION_TEMPLATE_ID, presentationDefaults, presentationSheetOps, planPresentationSheet } from "../plan/presentationSheet"; export type { PresentationOptions, PresentationPlan, PresentationLabels } from "../plan/presentationSheet"; +export { lineEndsOf, lineEndsCode, lineEndsFromCode, lineEndsSvgAttrs, planLineEndsProps, MITER_LIMIT as LINE_MITER_LIMIT } from "../model/lineEnds"; +export type { LineEnds } from "../model/lineEnds"; +export type { LineCap, LineJoin } from "../model/types"; diff --git a/src/export/planToPrintSvg.ts b/src/export/planToPrintSvg.ts index b2ea8179..ab11c561 100644 --- a/src/export/planToPrintSvg.ts +++ b/src/export/planToPrintSvg.ts @@ -28,6 +28,7 @@ import type { HatchRender, Plan } from "../plan/generatePlan"; import { core } from "../engine/coreWasm"; +import { lineEndsSvgAttrs } from "../model/lineEnds"; import { planParts, withPlanParts } from "../plan/planParts"; /** SVG-Namespace für die programmatisch erzeugten Knoten. */ @@ -107,6 +108,8 @@ export interface PrintSvgOptions { bounds?: { minX: number; minY: number; maxX: number; maxY: number }; /** Ohne weisses Blatt dahinter (als Schicht über anderem Inhalt). */ transparent?: boolean; + /** Linienenden und -ecken ([146], `cap | join << 2`); Standard `plan.lineEnds`. */ + lineEnds?: number; } /** Modell-Meter → Papier-Millimeter im Massstab 1:N. */ @@ -150,6 +153,9 @@ export function planToPrintSvg(plan: Plan, opts: PrintSvgOptions): PrintSvg { svg.setAttribute("width", String(opts.pageWidthMm)); svg.setAttribute("height", String(opts.pageHeightMm)); svg.setAttribute("viewBox", `0 0 ${opts.pageWidthMm} ${opts.pageHeightMm}`); + // Linienenden und -ecken des Projekts ([146]): einmal am Wurzelelement, alle Striche erben sie + // (der Kern setzt nur bei Punkt-Mustern eine eigene runde Kappe). + for (const [k, v] of Object.entries(lineEndsSvgAttrs(opts.lineEnds ?? plan.lineEnds))) svg.setAttribute(k, v); // Weisses Blatt (deckt die volle Seite). const bg = document.createElementNS(SVG_NS, "rect"); diff --git a/src/export/planToSvgString.ts b/src/export/planToSvgString.ts index cf4181e2..2029ef69 100644 --- a/src/export/planToSvgString.ts +++ b/src/export/planToSvgString.ts @@ -16,10 +16,12 @@ export interface SvgStringOptions { marginM?: number; /** Schraffurlinien ausbreiten (wie im Druck); Standard aus. */ hatch?: boolean; + /** Linienenden und -ecken ([146], `cap | join << 2`); Standard `plan.lineEnds`. */ + lineEnds?: number; } export function planToSvgString(plan: Plan, opts: SvgStringOptions = {}): string { const b = plan.bounds; - const o = Float64Array.from([opts.scaleDenominator ?? 100, opts.marginM ?? 0.5, b.minX, b.minY, b.maxX, b.maxY, ...(opts.hatch ? [1] : [])]); + const o = Float64Array.from([opts.scaleDenominator ?? 100, opts.marginM ?? 0.5, b.minX, b.minY, b.maxX, b.maxY, opts.hatch ? 1 : 0, opts.lineEnds ?? plan.lineEnds ?? 0]); return withPlanParts(planParts(plan, true), (segs) => core().plan_svg_string(segs, o)); } diff --git a/src/export/sceneToPrintSvg.ts b/src/export/sceneToPrintSvg.ts index bdafcb04..737598f6 100644 --- a/src/export/sceneToPrintSvg.ts +++ b/src/export/sceneToPrintSvg.ts @@ -22,6 +22,7 @@ // // Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md). +import { lineEndsSvgAttrs } from "../model/lineEnds"; import type { RArc, RFill, @@ -134,6 +135,8 @@ export function sceneToPrintSvg(scene: RScene, opts: PrintSceneOptions): PrintSc svg.setAttribute("width", String(opts.pageWidthMm)); svg.setAttribute("height", String(opts.pageHeightMm)); svg.setAttribute("viewBox", `0 0 ${opts.pageWidthMm} ${opts.pageHeightMm}`); + // Linienenden und -ecken des Projekts ([146]): einmal am Wurzelelement, alle Striche erben sie. + for (const [k, v] of Object.entries(lineEndsSvgAttrs(scene.lineEnds))) svg.setAttribute(k, v); const bg = document.createElementNS(SVG_NS, "rect"); bg.setAttribute("x", "0"); @@ -269,12 +272,12 @@ function appendStroke( el.setAttribute("stroke", rgbCss(color)); setOpacityAttr(el, "stroke-opacity", color[3]); el.setAttribute("stroke-width", String(strokeMm)); - el.setAttribute("stroke-linejoin", "round"); - el.setAttribute("stroke-linecap", "round"); if (dash && dash.length) { // Strichmuster ist bereits in Papier-mm definiert (siehe `toRenderScene.ts`: // „unveraendert durchgereicht"), also direkt uebernehmen. el.setAttribute("stroke-dasharray", dash.map((d) => round(d)).join(" ")); + // Punkte (Strich 0) brauchen runde Enden, sonst unsichtbar ([96]). + if (dash.some((d) => d === 0)) el.setAttribute("stroke-linecap", "round"); } svg.appendChild(el); } @@ -292,9 +295,9 @@ function appendLine(svg: SVGSVGElement, l: RLine, map: Mapper, _mmPerM: number): el.setAttribute("stroke", rgbCss(l.color)); setOpacityAttr(el, "stroke-opacity", l.color[3]); el.setAttribute("stroke-width", String(quantizePen(l.widthMm))); - el.setAttribute("stroke-linecap", "round"); if (l.dash && l.dash.length) { el.setAttribute("stroke-dasharray", l.dash.map((d) => round(d)).join(" ")); + if (l.dash.some((d) => d === 0)) el.setAttribute("stroke-linecap", "round"); } svg.appendChild(el); } diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 18415b49..ca261e92 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -2648,6 +2648,15 @@ export const de = { "settings.referenceElevation": "Höhe ±0.00 (m ü. M.)", "settings.referenceElevation.hint": "OK fertig Boden des Bezugsgeschosses (±0.00) über Meer; erscheint in Schnitten und Ansichten an der Kote ±0.00.", + "settings.lineCap": "Linienenden", + "settings.lineCap.butt": "Flach", + "settings.lineCap.round": "Rund", + "settings.lineCap.square": "Vorstehend (eckig)", + "settings.lineJoin": "Linienecken", + "settings.lineJoin.miter": "Gehrung (spitz)", + "settings.lineJoin.round": "Rund", + "settings.lineJoin.bevel": "Gefast", + "settings.lineEnds.hint": "Gilt für alle Striche im Grundriss, Schnitt und in der Ansicht – am Bildschirm, in Layouts, im Druck/PDF und im SVG-Export. Sehr spitze Ecken werden gefast (Gehrungsgrenze 4).", "settings.scaleLineWeights": "Strichstärken nach Massstab", "settings.scaleLineWeights.hint": "Grundriss-Strichstärken werden mit (100/n)^¼ skaliert: 1:200 ≈ 84 %, 1:50 ≈ 119 %. Gilt am Bildschirm, in Layouts und im Export.", "settings.section.shortcuts": "Befehlszeilen-Kürzel (Tipp-Alias)", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 18a27eef..30085143 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -2635,6 +2635,15 @@ export const en: Record = { "settings.referenceElevation": "Elevation of ±0.00 (m a.s.l.)", "settings.referenceElevation.hint": "Finished floor of the datum storey (±0.00) above sea level; shown in sections and elevations at the ±0.00 level mark.", + "settings.lineCap": "Line ends", + "settings.lineCap.butt": "Flat", + "settings.lineCap.round": "Round", + "settings.lineCap.square": "Projecting (square)", + "settings.lineJoin": "Line corners", + "settings.lineJoin.miter": "Miter (sharp)", + "settings.lineJoin.round": "Round", + "settings.lineJoin.bevel": "Bevel", + "settings.lineEnds.hint": "Applies to all strokes in plans, sections and elevations – on screen, in layouts, print/PDF and SVG export. Very sharp corners are bevelled (miter limit 4).", "settings.scaleLineWeights": "Line weights by scale", "settings.scaleLineWeights.hint": "Plan line weights are scaled by (100/n)^¼: 1:200 ≈ 84 %, 1:50 ≈ 119 %. Applies on screen, in layouts and exports.", "settings.section.shortcuts": "Command-line shortcuts (typed alias)", diff --git a/src/model/lineEnds.ts b/src/model/lineEnds.ts new file mode 100644 index 00000000..083f491b --- /dev/null +++ b/src/model/lineEnds.ts @@ -0,0 +1,47 @@ +// Linienenden und -ecken ([146]): eine Projekt-Einstellung (`Project.lineCap`/`lineJoin`) für alle +// Ausgabewege. Über die WASM-Grenze als Zahl `cap | join << 2` (Kern `plan/line_ends.rs`); +// 0 = flach + Gehrung (Standard, auch wenn die Felder fehlen). + +import type { LineCap, LineJoin, Project } from "./types"; + +const CAPS: readonly LineCap[] = ["butt", "round", "square"]; +const JOINS: readonly LineJoin[] = ["miter", "round", "bevel"]; + +/** Gehrungsgrenze wie SVG `stroke-miterlimit` (darüber gefast). */ +export const MITER_LIMIT = 4; + +export interface LineEnds { + cap: LineCap; + join: LineJoin; +} + +export function lineEndsOf(p: Pick): LineEnds { + return { + cap: p.lineCap && CAPS.includes(p.lineCap) ? p.lineCap : "butt", + join: p.lineJoin && JOINS.includes(p.lineJoin) ? p.lineJoin : "miter", + }; +} + +/** Kodierung `cap | join << 2` für die Kern-Bindungen. */ +export function lineEndsCode(p: Pick): number { + const e = lineEndsOf(p); + return CAPS.indexOf(e.cap) | (JOINS.indexOf(e.join) << 2); +} + +/** Umkehrung von {@link lineEndsCode}; Unsinn → Standard. */ +export function lineEndsFromCode(code: number | undefined): LineEnds { + const c = Number.isInteger(code) && code! >= 0 && code! < 16 ? code! : 0; + return { cap: CAPS[c & 3] ?? "butt", join: JOINS[(c >> 2) & 3] ?? "miter" }; +} + +/** SVG-Attribute (Name → Wert) für ein umschliessendes Element; Kinder erben sie. */ +export function lineEndsSvgAttrs(code: number | undefined): Record<"stroke-linecap" | "stroke-linejoin" | "stroke-miterlimit", string> { + const e = lineEndsFromCode(code); + return { "stroke-linecap": e.cap, "stroke-linejoin": e.join, "stroke-miterlimit": String(MITER_LIMIT) }; +} + +/** Wie {@link lineEndsSvgAttrs} als React-SVG-Eigenschaften (PlanView-Gruppe der Plan-Striche). */ +export function planLineEndsProps(code: number | undefined): { strokeLinecap: LineCap; strokeLinejoin: LineJoin; strokeMiterlimit: number } { + const e = lineEndsFromCode(code); + return { strokeLinecap: e.cap, strokeLinejoin: e.join, strokeMiterlimit: MITER_LIMIT }; +} diff --git a/src/model/types.generated.ts b/src/model/types.generated.ts index 054d72d0..6eecf554 100644 --- a/src/model/types.generated.ts +++ b/src/model/types.generated.ts @@ -1787,6 +1787,14 @@ export type LayoutViewport = { scaleDenominator?: number; }; +/** Linienenden aller Striche im Plan/Schnitt/Ansicht und in den Exporten ([146]); fehlt = flach. */ +export type LineCap = "butt" | "round" | "square"; + +/** + * Linienecken (Stoss zweier Segmente eines Zugs) ([146]); fehlt = Gehrung (Grenze 4, sonst gefast). + */ +export type LineJoin = "miter" | "round" | "bevel"; + /** Ein wiederverwendbarer Linienstil (Line Manager). */ export type LineStyle = { id: string; @@ -2330,6 +2338,10 @@ export type Project = { * Strichstärken im Grundriss mit dem Massstab skalieren, (100/n)^0.25 (`plan/lineWeightScale.ts`). */ scaleLineWeights?: boolean; + /** Linienenden aller Striche ([146]); fehlt = flach (`butt`). */ + lineCap?: LineCap; + /** Linienecken aller Striche ([146]); fehlt = Gehrung (`miter`, Grenze 4). */ + lineJoin?: LineJoin; /** Grafik-Kategorie-Baum (geschossübergreifend). */ layers: Array; walls: Array; diff --git a/src/native/SettingsWindowApp.tsx b/src/native/SettingsWindowApp.tsx index 8fe99b87..af59eeff 100644 --- a/src/native/SettingsWindowApp.tsx +++ b/src/native/SettingsWindowApp.tsx @@ -95,6 +95,8 @@ export function SettingsWindowApp() { onReferenceElevationChange={handlers.onReferenceElevationChange} scaleLineWeights={state.scaleLineWeights} onScaleLineWeightsChange={handlers.onScaleLineWeightsChange} + lineEnds={state.lineEnds} + onLineEndsChange={handlers.onLineEndsChange} offline={state.offline} onOfflineChange={handlers.onOfflineChange} aiAccess={state.aiAccess} diff --git a/src/native/settingsWindow.ts b/src/native/settingsWindow.ts index f3b206f9..50ea2762 100644 --- a/src/native/settingsWindow.ts +++ b/src/native/settingsWindow.ts @@ -12,6 +12,7 @@ // // Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md). +import type { LineEnds } from "../core"; import type { AiAccessView } from "../ui/AiAccessSection"; import type { LayoutState } from "../panels/types"; import type { ThemeMode } from "../theme/themeMode"; @@ -27,6 +28,8 @@ export interface SettingsSyncState { snapColor: string; referenceElevationMasl: number | undefined; scaleLineWeights: boolean; + /** Projekt-Option: Linienenden und -ecken ([146]). */ + lineEnds: LineEnds; offline: boolean; /** [9] KI-Zugriff (Schalter, Sitzungsschlüssel, Stand). */ aiAccess: AiAccessView; @@ -40,6 +43,7 @@ export interface SettingsCommandHandlers { onSnapColorChange: (hex: string) => void; onReferenceElevationChange: (n: number | undefined) => void; onScaleLineWeightsChange: (on: boolean) => void; + onLineEndsChange: (ends: LineEnds) => void; onOfflineChange: (offline: boolean) => void; onAiAccessChange: (on: boolean) => void; onApplyLayout: (layout: LayoutState) => void; diff --git a/src/plan/__golden__/komplex-ansicht-ansicht-sued.txt b/src/plan/__golden__/komplex-ansicht-ansicht-sued.txt index 4ae17af0..680eab98 100644 --- a/src/plan/__golden__/komplex-ansicht-ansicht-sued.txt +++ b/src/plan/__golden__/komplex-ansicht-ansicht-sued.txt @@ -1,9 +1,11 @@ viewBox -4.2 0 37.045 17.778 -bytes 375391 +bytes 265283 circle 4 -line 1272 -polygon 1541 +g 1 +line 615 +polygon 1555 +polyline 68 rect 1 svg 1 text 4 -hash ba128fc3cd96941c +hash 18d42b37d5c973f7 diff --git a/src/plan/__golden__/komplex-grundriss-dg-100.txt b/src/plan/__golden__/komplex-grundriss-dg-100.txt index c5de23ad..b7ded20d 100644 --- a/src/plan/__golden__/komplex-grundriss-dg-100.txt +++ b/src/plan/__golden__/komplex-grundriss-dg-100.txt @@ -1,10 +1,11 @@ viewBox -4 0 23 18 -bytes 408672 +bytes 317361 circle 14 -line 3444 -path 7 +g 1 +line 3227 polygon 75 +polyline 73 rect 1 svg 1 text 36 -hash e873dd1daa6ea113 +hash b639c8605f1c4c9d diff --git a/src/plan/__golden__/komplex-grundriss-dg-50.txt b/src/plan/__golden__/komplex-grundriss-dg-50.txt index 1becb0ee..9640bf2e 100644 --- a/src/plan/__golden__/komplex-grundriss-dg-50.txt +++ b/src/plan/__golden__/komplex-grundriss-dg-50.txt @@ -1,10 +1,11 @@ viewBox -4 0 23 18 -bytes 416589 +bytes 323049 circle 14 -line 3484 -path 7 +g 1 +line 3240 polygon 75 +polyline 84 rect 1 svg 1 text 36 -hash 10e9a3b43fd5705a +hash 67469479cfe01b3d diff --git a/src/plan/__golden__/komplex-grundriss-eg-100.txt b/src/plan/__golden__/komplex-grundriss-eg-100.txt index 3979d86a..b39ffeb0 100644 --- a/src/plan/__golden__/komplex-grundriss-eg-100.txt +++ b/src/plan/__golden__/komplex-grundriss-eg-100.txt @@ -1,10 +1,12 @@ viewBox -41.5 0 95 63.6 -bytes 154702 +bytes 109717 circle 16 -line 742 -path 63 -polygon 256 +g 1 +line 338 +path 39 +polygon 259 +polyline 126 rect 1 svg 1 text 121 -hash 31eb0ce63a3514ff +hash 6872e879c06f7f46 diff --git a/src/plan/__golden__/komplex-grundriss-eg-50.txt b/src/plan/__golden__/komplex-grundriss-eg-50.txt index 4709bdf3..3bc169d5 100644 --- a/src/plan/__golden__/komplex-grundriss-eg-50.txt +++ b/src/plan/__golden__/komplex-grundriss-eg-50.txt @@ -1,10 +1,12 @@ viewBox -41.5 0 95 63.6 -bytes 165876 +bytes 114546 circle 16 -line 834 -path 69 -polygon 256 +g 1 +line 349 +path 45 +polygon 259 +polyline 151 rect 1 svg 1 text 121 -hash a9e2d4dd24b3f54c +hash 49fa5877b4a27a36 diff --git a/src/plan/__golden__/komplex-grundriss-og-100.txt b/src/plan/__golden__/komplex-grundriss-og-100.txt index 29301995..66d8e2e0 100644 --- a/src/plan/__golden__/komplex-grundriss-og-100.txt +++ b/src/plan/__golden__/komplex-grundriss-og-100.txt @@ -1,10 +1,12 @@ viewBox -4.055 0 25.109 23.11 -bytes 494072 +bytes 366491 circle 14 -line 3915 -path 36 -polygon 226 +g 1 +line 3333 +path 21 +polygon 227 +polyline 169 rect 1 svg 1 text 91 -hash 3a01d6133c531e3d +hash 48bd54ad5e8b1c20 diff --git a/src/plan/__golden__/komplex-grundriss-og-50.txt b/src/plan/__golden__/komplex-grundriss-og-50.txt index ba4f8266..880d2837 100644 --- a/src/plan/__golden__/komplex-grundriss-og-50.txt +++ b/src/plan/__golden__/komplex-grundriss-og-50.txt @@ -1,10 +1,12 @@ viewBox -4.055 0 25.109 23.11 -bytes 507906 +bytes 374934 circle 14 -line 4002 -path 42 -polygon 226 +g 1 +line 3350 +path 27 +polygon 227 +polyline 195 rect 1 svg 1 text 91 -hash 50c683de7aeef5d0 +hash 7bd001e733642672 diff --git a/src/plan/__golden__/komplex-grundriss-ug-100.txt b/src/plan/__golden__/komplex-grundriss-ug-100.txt index 3cb16b53..15497bb5 100644 --- a/src/plan/__golden__/komplex-grundriss-ug-100.txt +++ b/src/plan/__golden__/komplex-grundriss-ug-100.txt @@ -1,10 +1,12 @@ viewBox -10.004 0 31.058 26.958 -bytes 90451 +bytes 61153 circle 14 -line 466 -path 28 -polygon 103 +g 1 +line 171 +path 13 +polygon 105 +polyline 77 rect 1 svg 1 text 75 -hash 3dae77c418383e16 +hash d31704c307ac309d diff --git a/src/plan/__golden__/komplex-grundriss-ug-50.txt b/src/plan/__golden__/komplex-grundriss-ug-50.txt index dbe471d1..bb058b7e 100644 --- a/src/plan/__golden__/komplex-grundriss-ug-50.txt +++ b/src/plan/__golden__/komplex-grundriss-ug-50.txt @@ -1,10 +1,12 @@ viewBox -10.004 0 31.058 26.958 -bytes 91807 +bytes 62007 circle 14 -line 475 -path 30 -polygon 103 +g 1 +line 173 +path 15 +polygon 105 +polyline 80 rect 1 svg 1 text 75 -hash 45fabe68cc29824d +hash eba7b491c822b768 diff --git a/src/plan/__golden__/komplex-schnitt-schnitt-a.txt b/src/plan/__golden__/komplex-schnitt-schnitt-a.txt index 4598e3eb..44e07947 100644 --- a/src/plan/__golden__/komplex-schnitt-schnitt-a.txt +++ b/src/plan/__golden__/komplex-schnitt-schnitt-a.txt @@ -1,9 +1,11 @@ viewBox 4.457 0 21.343 17.778 -bytes 72287 +bytes 41694 circle 3 -line 376 -polygon 168 +g 1 +line 96 +polygon 186 +polyline 13 rect 1 svg 1 text 3 -hash 20b9f7ab702f9ed7 +hash 471491b0c51f190a diff --git a/src/plan/__golden__/muster-ansicht-ansicht-sued.txt b/src/plan/__golden__/muster-ansicht-ansicht-sued.txt index 45bdf02f..04a5230b 100644 --- a/src/plan/__golden__/muster-ansicht-ansicht-sued.txt +++ b/src/plan/__golden__/muster-ansicht-ansicht-sued.txt @@ -1,7 +1,9 @@ viewBox 0.1 0 6.8 7.586 -bytes 9105 -line 31 -polygon 42 +bytes 6297 +g 1 +line 7 +polygon 43 +polyline 6 rect 1 svg 1 -hash 8989d8c3eda53c4f +hash 965767e4ac42c4f0 diff --git a/src/plan/__golden__/muster-grundriss-eg-100.txt b/src/plan/__golden__/muster-grundriss-eg-100.txt index 8a74da8a..4ea5f9b6 100644 --- a/src/plan/__golden__/muster-grundriss-eg-100.txt +++ b/src/plan/__golden__/muster-grundriss-eg-100.txt @@ -1,9 +1,10 @@ viewBox -0.672 0 6.345 5.345 -bytes 15406 -line 49 -path 8 -polygon 61 +bytes 11826 +g 1 +line 33 +polygon 62 +polyline 8 rect 1 svg 1 text 7 -hash 5ab24b7693923d27 +hash 6d3b7926ca1a3a6d diff --git a/src/plan/__golden__/muster-grundriss-eg-50.txt b/src/plan/__golden__/muster-grundriss-eg-50.txt index 685f9679..ad064cfe 100644 --- a/src/plan/__golden__/muster-grundriss-eg-50.txt +++ b/src/plan/__golden__/muster-grundriss-eg-50.txt @@ -1,9 +1,10 @@ viewBox -0.672 0 6.345 5.345 -bytes 17388 -line 67 -path 8 -polygon 61 +bytes 12491 +g 1 +line 34 +polygon 62 +polyline 13 rect 1 svg 1 text 7 -hash 76655e0c29ed72d2 +hash 7378e595c698986f diff --git a/src/plan/__golden__/muster-grundriss-og-100.txt b/src/plan/__golden__/muster-grundriss-og-100.txt index 49852e51..65fbc77a 100644 --- a/src/plan/__golden__/muster-grundriss-og-100.txt +++ b/src/plan/__golden__/muster-grundriss-og-100.txt @@ -1,9 +1,10 @@ viewBox -0.9 0 6.8 5.8 -bytes 7329 -line 27 -path 4 -polygon 23 +bytes 5572 +g 1 +line 15 +polygon 26 +polyline 4 rect 1 svg 1 text 4 -hash ce46a0be23194084 +hash 97d2aa8ea90eafff diff --git a/src/plan/__golden__/muster-grundriss-og-50.txt b/src/plan/__golden__/muster-grundriss-og-50.txt index 7009363f..88855425 100644 --- a/src/plan/__golden__/muster-grundriss-og-50.txt +++ b/src/plan/__golden__/muster-grundriss-og-50.txt @@ -1,9 +1,10 @@ viewBox -0.9 0 6.8 5.8 -bytes 8243 -line 35 -path 4 -polygon 23 +bytes 5816 +g 1 +line 15 +polygon 28 +polyline 4 rect 1 svg 1 text 4 -hash 1ed106fb31a8203a +hash 7ca726f020333afb diff --git a/src/plan/__golden__/muster-schnitt-schnitt-a.txt b/src/plan/__golden__/muster-schnitt-schnitt-a.txt index a9bf8b35..0aad82ff 100644 --- a/src/plan/__golden__/muster-schnitt-schnitt-a.txt +++ b/src/plan/__golden__/muster-schnitt-schnitt-a.txt @@ -1,7 +1,9 @@ viewBox 0.1 0 6.8 7.586 -bytes 11068 -line 59 -polygon 31 +bytes 6668 +g 1 +line 21 +polygon 34 +polyline 4 rect 1 svg 1 -hash 9f3f228ecf8a3650 +hash 8ce8b71fc217069c diff --git a/src/plan/generatePlan.ts b/src/plan/generatePlan.ts index b927a324..6e492661 100644 --- a/src/plan/generatePlan.ts +++ b/src/plan/generatePlan.ts @@ -25,6 +25,7 @@ import type { Vec2, } from "../model/types"; import { documentFor } from "../core/document"; +import { lineEndsCode } from "../model/lineEnds"; import { registerCoreRestore } from "../engine/coreWasm"; import { decodePlanBuf, type DecodedPlanBuf } from "./planBuf"; import { @@ -86,6 +87,11 @@ export interface Plan { * Verbraucher prüft die Objekt-Identität und fällt sonst auf die Objekte zurück. */ bufRuns?: PlanBufRun[]; + /** + * Linienenden und -ecken des Projekts ([146], `cap | join << 2`, s. `model/lineEnds.ts`); fehlt = 0 + * (flach + Gehrung). Alle Ausgabewege (Szene, GPU-Chunks, Plan-SVG, Druck) lesen es von hier. + */ + lineEnds?: number; } /** `primitives[at + k]` ist (solange nicht ersetzt) `buf.prims[from + k]`, `k < to − from`. */ @@ -288,7 +294,7 @@ export function generatePlan( })); // Ausmass samt Schatten, Baurecht und Kontext (immer gesetzt, ohne Punkte 0,0–1,1). const [minX, minY, maxX, maxY] = dom.buf.bounds ?? [0, 0, 1, 1]; - return lazyPlan({ bounds: { minX, minY, maxX, maxY }, backgroundImages, ...(underlay.length ? { underlay } : {}) }, pieces); + return lazyPlan({ bounds: { minX, minY, maxX, maxY }, backgroundImages, lineEnds: lineEndsCode(project), ...(underlay.length ? { underlay } : {}) }, pieces); } /** @@ -404,6 +410,7 @@ export function generateVisibleLevelsPlan( { bounds, backgroundImages: activePlan.backgroundImages, + lineEnds: lineEndsCode(project), ...(greyedRanges.length ? { greyedRanges } : {}), ...(underlay.length ? { underlay } : {}), }, diff --git a/src/plan/glPlan/glPlanChunks.ts b/src/plan/glPlan/glPlanChunks.ts index 7434e684..ebfd1850 100644 --- a/src/plan/glPlan/glPlanChunks.ts +++ b/src/plan/glPlan/glPlanChunks.ts @@ -299,6 +299,17 @@ export class GpuChunkCache { /** Geometrien in Zeichenreihenfolge (nur bei `update`/`dispose` neu aufgebaut). */ geometries: GpuGeometry[] = []; + /** + * Linienenden und -ecken ([146], `Plan.lineEnds`): bei einem Wechsel sind alle Chunks veraltet + * (andere Tessellierung) — verwerfen, das nächste `update` kompiliert neu. + */ + setLineEnds(code: number | undefined): void { + const c = code ?? 0; + if ((this.gl.lineEnds ?? 0) === c) return; + this.dispose(); + (this.gl as { lineEnds?: number }).lineEnds = c; + } + update( primitives: readonly Primitive[], pxPerMeter: number, diff --git a/src/plan/glPlan/glPlanCompile.test.ts b/src/plan/glPlan/glPlanCompile.test.ts index 611becd2..15fe86d2 100644 --- a/src/plan/glPlan/glPlanCompile.test.ts +++ b/src/plan/glPlan/glPlanCompile.test.ts @@ -18,8 +18,9 @@ const glStub = { STATIC_DRAW: 3, } as unknown as WebGL2RenderingContext; +// Runde Enden/Ecken ([146] `lineEnds` 1 | 1 << 2): nur dort kosten Kappen eigene Dreiecke. const lineIndexCount = (prims: Primitive[]): number => - compilePrimitivesToGpu(glStub, prims, 90).line.batches.reduce((s, b) => s + b.indexCount, 0); + compilePrimitivesToGpu({ ...glStub, lineEnds: 1 | (1 << 2) }, prims, 90).line.batches.reduce((s, b) => s + b.indexCount, 0); const seg = (ax: number, ay: number, bx: number, by: number, drawingId: string): Primitive => ({ kind: 'line', @@ -43,10 +44,11 @@ describe('compilePrimitivesToGpu: zusammenhängende Linien-Segmente', () => { expect(merged).toBe(single + 2 * 6); }); - it('verkettet NICHT über Elementgrenzen, auch bei gemeinsamem Eckpunkt', () => { + it('[146] näht gleich gestylte volle Linien auch über Elementgrenzen (Ecke statt zweier Enden)', () => { const single = lineIndexCount([seg(0, 0, 1, 0, 'a')]); const twoDrawings = lineIndexCount([seg(0, 0, 1, 0, 'a'), seg(1, 0, 2, 0, 'b')]); - expect(twoDrawings).toBe(2 * single); + // Ein Zug: zweites Quad, aber keine Kappen am gemeinsamen Punkt (Wandecken ohne Kerbe). + expect(twoDrawings).toBe(single + 6); }); it('verkettet NICHT bei unterschiedlichem Stil', () => { diff --git a/src/plan/glPlan/glPlanCompile.ts b/src/plan/glPlan/glPlanCompile.ts index 73903296..a6722e8d 100644 --- a/src/plan/glPlan/glPlanCompile.ts +++ b/src/plan/glPlan/glPlanCompile.ts @@ -42,7 +42,7 @@ export function compilePrimitivesToGpu( pxPerMeter = 0, ): GpuGeometry { const packed = gl.packedLineVertices === true; - const out = core().gpu_compile_flat(encodePlanBuf(primitives, { lean: true }), 0, primitives.length, pxPerMeter, packed); + const out = core().gpu_compile_flat(encodePlanBuf(primitives, { lean: true }), 0, primitives.length, pxPerMeter, packed, gl.lineEnds ?? 0); return uploadCompiled(gl, out); } @@ -53,13 +53,14 @@ export function compilePrimitivesToGpu( */ export function compilePlanBufRange(gl: BufferGl, src: DecodedPlanBuf, from: number, to: number, pxPerMeter = 0): GpuGeometry { const packed = gl.packedLineVertices === true; + const ends = gl.lineEnds ?? 0; const c = core(); if (src.holdEpoch !== coreEpoch()) src.hold = 0; // Nummer aus einer Kern-Instanz vor dem Neustart ([118]) - let out = src.hold ? c.gpu_compile_held(src.hold, from, to, pxPerMeter, packed) : new Uint32Array(0); + let out = src.hold ? c.gpu_compile_held(src.hold, from, to, pxPerMeter, packed, ends) : new Uint32Array(0); if (out.length === 0) { src.hold = c.plan_buf_hold(src.bytes); src.holdEpoch = coreEpoch(); - out = src.hold ? c.gpu_compile_held(src.hold, from, to, pxPerMeter, packed) : c.gpu_compile_flat(src.bytes, from, to, pxPerMeter, packed); + out = src.hold ? c.gpu_compile_held(src.hold, from, to, pxPerMeter, packed, ends) : c.gpu_compile_flat(src.bytes, from, to, pxPerMeter, packed, ends); } return uploadCompiled(gl, out); } diff --git a/src/plan/glPlan/glPlanTypes.ts b/src/plan/glPlan/glPlanTypes.ts index 95625b65..63c81d99 100644 --- a/src/plan/glPlan/glPlanTypes.ts +++ b/src/plan/glPlan/glPlanTypes.ts @@ -121,6 +121,11 @@ export interface BufferGl { * der WebGL-Pfad bleibt beim 6-Float-Layout. */ readonly packedLineVertices?: boolean; + /** + * Linienenden und -ecken ([146], `cap | join << 2`, `Plan.lineEnds`) für die Kompilierung; + * gesetzt über `GpuChunkCache.setLineEnds` (verwirft bei Wechsel alle Chunks). Fehlt = 0. + */ + lineEnds?: number; readonly ARRAY_BUFFER: number; readonly ELEMENT_ARRAY_BUFFER: number; readonly STATIC_DRAW: number; diff --git a/src/plan/lineEnds.test.ts b/src/plan/lineEnds.test.ts new file mode 100644 index 00000000..bfdf4fbb --- /dev/null +++ b/src/plan/lineEnds.test.ts @@ -0,0 +1,74 @@ +/** + * [146] Linienenden und -ecken: eine Projekt-Einstellung (`lineCap`/`lineJoin`), Standard flach + + * Gehrung. Sie reist als `Plan.lineEnds` in alle Ausgabewege: render2d-Szene (Kopfwort), Plan-SVG + * (``), GPU-Chunks (`BufferGl.lineEnds`). + */ + +import { describe, expect, it } from "vitest"; +import { generatePlan } from "./generatePlan"; +import { planSceneBin } from "./toRenderScene"; +import { planToSvgString } from "../export/planToSvgString"; +import { sampleProject } from "../model/sampleProject"; +import { flattenCategories, type Project } from "../model/types"; +import { lineEndsCode, lineEndsFromCode, lineEndsOf, lineEndsSvgAttrs } from "../model/lineEnds"; +import { GpuChunkCache } from "./glPlan/glPlanChunks"; +import type { BufferGl } from "./glPlan/glPlanTypes"; + +const ALL = new Set(flattenCategories(sampleProject.layers).map((c) => c.code)); +const floor = sampleProject.drawingLevels.find((l) => l.kind === "floor")!.id; +const planOf = (p: Project) => generatePlan(p, floor, ALL); + +describe("[146] Linienenden und -ecken", () => { + it("Kodierung: fehlt = flach + Gehrung, Rundreise, Unsinn = Standard", () => { + expect(lineEndsOf({})).toEqual({ cap: "butt", join: "miter" }); + expect(lineEndsCode({})).toBe(0); + expect(lineEndsCode({ lineCap: "square", lineJoin: "bevel" })).toBe(2 | (2 << 2)); + expect(lineEndsFromCode(1 | (1 << 2))).toEqual({ cap: "round", join: "round" }); + expect(lineEndsFromCode(Number.NaN)).toEqual({ cap: "butt", join: "miter" }); + expect(lineEndsSvgAttrs(0)).toEqual({ "stroke-linecap": "butt", "stroke-linejoin": "miter", "stroke-miterlimit": "4" }); + }); + + it("Plan trägt die Einstellung; Plan-SVG und render2d-Szene übernehmen sie", () => { + const std = planOf(sampleProject); + expect(std.lineEnds).toBe(0); + const round = planOf({ ...sampleProject, lineCap: "round", lineJoin: "bevel" }); + expect(round.lineEnds).toBe(1 | (2 << 2)); + + const svg0 = planToSvgString(std, { scaleDenominator: 100 }); + expect(svg0).toContain(''); + // Volle Linien tragen keine eigene Kappe mehr (nur Punkt-Muster runden selbst). + expect(svg0).not.toMatch(/]*stroke-linecap="round"(?![^>]*stroke-dasharray)/); + const svg1 = planToSvgString(round, { scaleDenominator: 100 }); + expect(svg1).toContain(' new DataView(b.buffer, b.byteOffset, b.byteLength).getUint32(44, true); + expect(head(planSceneBin(std))).toBe(0); + expect(head(planSceneBin(round))).toBe(1 | (2 << 2)); + }); + + it("GPU-Chunks: Wechsel der Einstellung verwirft die Chunks und kompiliert mit ihr", () => { + const uploads: number[] = []; + const gl: BufferGl = { + packedLineVertices: true, + ARRAY_BUFFER: 1, + ELEMENT_ARRAY_BUFFER: 2, + STATIC_DRAW: 3, + createBuffer: () => ({}) as WebGLBuffer, + bindBuffer: () => {}, + bufferData: (_t, data) => void uploads.push(data.byteLength), + deleteBuffer: () => {}, + }; + const cache = new GpuChunkCache(gl); + const run = (p: Project) => { + const plan = planOf(p); + cache.setLineEnds(plan.lineEnds); + cache.update(plan.primitives, 0, -Infinity, plan.greyedRanges, plan.underlay, plan.bufRuns); + return cache.lastStats.recompiled; + }; + expect(run(sampleProject)).toBeGreaterThan(0); + expect(run(sampleProject)).toBe(0); + expect(gl.lineEnds ?? 0).toBe(0); + expect(run({ ...sampleProject, lineCap: "square" })).toBeGreaterThan(0); + expect(gl.lineEnds).toBe(2); + }); +}); diff --git a/src/plan/planBuf.test.ts b/src/plan/planBuf.test.ts index 7c649f84..6ee61420 100644 --- a/src/plan/planBuf.test.ts +++ b/src/plan/planBuf.test.ts @@ -142,8 +142,8 @@ describe("Plan-Puffer v2", () => { expect(lean.byteLength).toBeLessThan(encodePlanBuf(prims).byteLength); expect(() => decodePlanBuf(lean).prims).toThrow(); // Die GPU-Kompilierung liest beide gleich. - const a = core().gpu_compile_flat(lean, 0, prims.length, 90, true); - const b = core().gpu_compile_flat(encodePlanBuf(prims), 0, prims.length, 90, true); + const a = core().gpu_compile_flat(lean, 0, prims.length, 90, true, 0); + const b = core().gpu_compile_flat(encodePlanBuf(prims), 0, prims.length, 90, true, 0); expect(a.length).toBeGreaterThan(30); expect(Array.from(a)).toEqual(Array.from(b)); }); @@ -170,13 +170,13 @@ describe("Plan-Puffer v2", () => { const wrong = buf.slice(); new Float64Array(wrong.buffer, 0, 2)[1] = PLAN_BUF_VERSION + 1; expect(core().plan_buf_recode(wrong).length).toBe(0); - expect(core().gpu_compile_flat(wrong, 0, 1, 90, true).length).toBe(0); + expect(core().gpu_compile_flat(wrong, 0, 1, 90, true, 0).length).toBe(0); expect(() => decodePlanBuf(wrong)).toThrow(/Version/); expect(core().plan_buf_recode(buf.subarray(0, buf.length - 3)).length).toBe(0); expect(() => decodePlanBuf(buf.subarray(0, buf.length - 2))).toThrow(); - expect(core().gpu_compile_flat(new Uint8Array([1, 2, 3]), 0, 0, 90, false).length).toBe(0); - expect(core().gpu_compile_flat(buf, 0, prims.length + 1, 90, false).length).toBe(0); - expect(core().gpu_compile_held(424242, 0, 1, 90, false).length).toBe(0); + expect(core().gpu_compile_flat(new Uint8Array([1, 2, 3]), 0, 0, 90, false, 0).length).toBe(0); + expect(core().gpu_compile_flat(buf, 0, prims.length + 1, 90, false, 0).length).toBe(0); + expect(core().gpu_compile_held(424242, 0, 1, 90, false, 0).length).toBe(0); expect(core().plan_buf_hold(wrong)).toBe(0); // Danach arbeitet der Kern normal weiter. expect(canon(decodePlanBuf(core().plan_buf_recode(buf)).prims)).toBe(canon(prims)); @@ -187,9 +187,9 @@ describe("Plan-Puffer v2", () => { const buf = encodePlanBuf(prims); const id = core().plan_buf_hold(buf); expect(id).toBeGreaterThan(0); - expect(Array.from(core().gpu_compile_held(id, 1, 5, 90, true))).toEqual(Array.from(core().gpu_compile_flat(buf, 1, 5, 90, true))); + expect(Array.from(core().gpu_compile_held(id, 1, 5, 90, true, 0))).toEqual(Array.from(core().gpu_compile_flat(buf, 1, 5, 90, true, 0))); core().plan_buf_release(id); - expect(core().gpu_compile_held(id, 1, 5, 90, true).length).toBe(0); + expect(core().gpu_compile_held(id, 1, 5, 90, true, 0).length).toBe(0); }); it("Puffer einer Runde verdrängen sich nicht gegenseitig (viele Zeichnungs-Stücke)", () => { diff --git a/src/plan/toElevation.ts b/src/plan/toElevation.ts index 96691b85..0ee7b0cb 100644 --- a/src/plan/toElevation.ts +++ b/src/plan/toElevation.ts @@ -5,6 +5,7 @@ import type { DrawingLevel, Project } from "../model/types"; import { documentFor } from "../core/document"; +import { lineEndsCode } from "../model/lineEnds"; import { decodePlanBuf } from "./planBuf"; import { lazyPlan } from "./planLazy"; import { hasLine, levelArg, visibilityArgs } from "./toSection"; @@ -38,7 +39,7 @@ export function generateElevationPlan(project: Project, level: DrawingLevel, opt if (buf.groups.length === 0) return null; const b = buf.bounds ?? [0, 0, 1, 1]; return lazyPlan( - { bounds: { minX: b[0], minY: b[1], maxX: b[2], maxY: b[3] } }, + { bounds: { minX: b[0], minY: b[1], maxX: b[2], maxY: b[3] }, lineEnds: lineEndsCode(project) }, buf.groups.map(([from, to]) => ({ buf, from, to })), ); } diff --git a/src/plan/toRenderScene.test.ts b/src/plan/toRenderScene.test.ts index dbf85bd6..e7e88a4d 100644 --- a/src/plan/toRenderScene.test.ts +++ b/src/plan/toRenderScene.test.ts @@ -21,8 +21,9 @@ const line = (ax: number, ay: number, bx: number, by: number, extra: Partial { it("verkettet 2D-Zeichenlinien zu Polylinie bzw. Umriss", () => { const open = planToRenderScene(planOf([line(0, 0, 1, 0), line(1, 0, 1, 1), line(5, 5, 6, 6, { drawingId: undefined })])); - expect(open.polylines.map((p) => p.pts.length)).toEqual([3]); - expect(open.lines.length).toBe(1); + // [146] Die volle Einzel-Linie ohne Zeichnung läuft über die Naht-Gruppen (Ecken statt Enden). + expect(open.polylines.map((p) => p.pts.length)).toEqual([3, 2]); + expect(open.lines.length).toBe(0); const ring = planToRenderScene(planOf([line(0, 0, 1, 0), line(1, 0, 1, 1), line(1, 1, 0, 0)])); expect(ring.outlines.map((o) => o.pts.length)).toEqual([3]); expect(ring.outlines[0].dash).toBeNull(); diff --git a/src/plan/toRenderScene.ts b/src/plan/toRenderScene.ts index 2b1c5f59..38b222a5 100644 --- a/src/plan/toRenderScene.ts +++ b/src/plan/toRenderScene.ts @@ -123,6 +123,8 @@ export interface RScene { * Felder ohne `deny_unknown_fields`), also rückwirkungsfrei fürs GPU-Backend. */ bounds: RBounds; + /** Linienenden und -ecken ([146], `Plan.lineEnds`); fehlt = flach + Gehrung. */ + lineEnds?: number; } /** @@ -182,7 +184,7 @@ function emptySceneBin(): Uint8Array { */ export function planSceneBin(plan: Plan, paperScaleN: number = STAMP_DEFAULT_N): Uint8Array { const greyed = greyedFlat(plan); - const out = withPlanParts(planParts(plan), (segs) => core().plan_scene_bin(segs, greyed, paperScaleN)); + const out = withPlanParts(planParts(plan), (segs) => core().plan_scene_bin(segs, greyed, paperScaleN, plan.lineEnds ?? 0)); return out.length ? out : emptySceneBin(); } @@ -260,5 +262,5 @@ function decodeSceneF64(f: Float64Array): SceneGeometry { export function planToRenderScene(plan: Plan, paperScaleN: number = STAMP_DEFAULT_N): RScene { const greyed = greyedFlat(plan); const geo = decodeSceneF64(withPlanParts(planParts(plan), (segs) => core().plan_scene_f64(segs, greyed))); - return { ...geo, texts: sceneTexts(plan, paperScaleN), images: sceneImages(plan), bounds: { ...plan.bounds } }; + return { ...geo, texts: sceneTexts(plan, paperScaleN), images: sceneImages(plan), bounds: { ...plan.bounds }, lineEnds: plan.lineEnds ?? 0 }; } diff --git a/src/plan/toSection.ts b/src/plan/toSection.ts index ddfc9162..7e01617f 100644 --- a/src/plan/toSection.ts +++ b/src/plan/toSection.ts @@ -12,6 +12,7 @@ import { buildSolidMesh } from "../engine/truckSolid"; import { extrudedSolidSpec } from "./extrudedSolidSpec"; import { decodePlanBuf } from "./planBuf"; import { lazyPlan } from "./planLazy"; +import { lineEndsCode } from "../model/lineEnds"; import type { CategoryDisplayResolver, Plan } from "./generatePlan"; /** Vorbereitete Eingabe eines Schnitts: Projekt, Ebene und die truck-Körper (flach). */ @@ -141,7 +142,7 @@ export function generateSectionPlan( if (buf.groups.length === 0) return { primitives: [], bounds: { minX: 0, minY: 0, maxX: 1, maxY: 1 } }; const b = buf.bounds ?? [0, 0, 1, 1]; return lazyPlan( - { bounds: { minX: b[0], minY: b[1], maxX: b[2], maxY: b[3] } }, + { bounds: { minX: b[0], minY: b[1], maxX: b[2], maxY: b[3] }, lineEnds: lineEndsCode(project) }, buf.groups.map(([from, to]) => ({ buf, from, to })), ); } diff --git a/src/styles.css b/src/styles.css index 9ee65ffc..de68256b 100644 --- a/src/styles.css +++ b/src/styles.css @@ -2146,17 +2146,16 @@ body { vector-effect: non-scaling-stroke; } -/* CAD-typische Ecken: alle Plan-Striche gehren (miter) statt an dicken Ecken eine - Stufe/Butt-Cap-Lücke zu zeigen. Der Miter-Grenzwert verhindert überlange Spitzen - bei sehr spitzen Winkeln (dann kappen die Enden rund). Gilt für Poché-Umrisse - (polygon), Wand-/Tür-/2D-Linien und Bögen gleichermaßen. */ +/* Linienenden und -ecken der Plan-Striche ([146]): Projekt-Einstellung, gesetzt als Attribute am + umschliessenden in PlanView (`planLineEndsProps`); die Elemente erben sie. Ausserhalb dieser + Gruppe gelten die SVG-Standardwerte (flach, Gehrung, Grenze 4) bzw. die eigenen Klassen. */ .plan-svg polygon, .plan-svg polyline, .plan-svg line, .plan-svg path { - stroke-linejoin: miter; - stroke-linecap: round; - stroke-miterlimit: 8; + stroke-linejoin: inherit; + stroke-linecap: inherit; + stroke-miterlimit: inherit; } /* Tür-/Fenster- + Referenz-Linien: NUR Farbe + fill hier. Strichstärke und diff --git a/src/ui/SettingsDialog.tsx b/src/ui/SettingsDialog.tsx index 0e1b0189..6f77e1ba 100644 --- a/src/ui/SettingsDialog.tsx +++ b/src/ui/SettingsDialog.tsx @@ -17,6 +17,7 @@ import { LayoutMenu } from "./LayoutMenu"; import { AiAccessSection, type AiAccessView } from "./AiAccessSection"; import { APP_VERSION } from "./TopBar"; import type { LayoutState } from "../panels/types"; +import type { LineCap, LineEnds, LineJoin } from "../core"; import type { ThemeMode } from "../theme/themeMode"; import { checkForUpdate, getUpdateSnoozeUntil, setUpdateSnooze } from "../update/checkForUpdate"; import { getRunningVersion } from "../update/version"; @@ -77,6 +78,9 @@ export interface SettingsDialogProps { /** Projekt-Option: Strichstärken nach Massstab ([32]). */ scaleLineWeights: boolean; onScaleLineWeightsChange: (on: boolean) => void; + /** Projekt-Option: Linienenden und -ecken aller Striche ([146]). */ + lineEnds: LineEnds; + onLineEndsChange: (ends: LineEnds) => void; /** Offline-Modus: sperrt alle entfernten Abrufe (Materialbibliothek, swisstopo, OSM). */ offline: boolean; onOfflineChange: (offline: boolean) => void; @@ -126,6 +130,8 @@ export function SettingsDialog({ onReferenceElevationChange, scaleLineWeights, onScaleLineWeightsChange, + lineEnds, + onLineEndsChange, offline, onOfflineChange, aiAccess, @@ -292,6 +298,7 @@ export function SettingsDialog({ />
{t("settings.referenceElevation.hint")}
+ )} @@ -731,6 +738,38 @@ function ShortcutRemapSection({ ); } +const LINE_CAPS: readonly LineCap[] = ["butt", "round", "square"]; +const LINE_JOINS: readonly LineJoin[] = ["miter", "round", "bevel"]; + +/** Projekt-Option „Linienenden und -ecken" ([146], `model/lineEnds.ts`): gilt in allen Ausgaben. */ +function LineEndsField({ value, onChange }: { value: LineEnds; onChange: (e: LineEnds) => void }) { + return ( + <> + + +
{t("settings.lineEnds.hint")}
+ + ); +} + /** Projekt-Option „Strichstärken nach Massstab" ([32], `plan/lineWeightScale.ts`). */ function LineWeightScaleField({ enabled, onChange }: { enabled: boolean; onChange: (on: boolean) => void }) { return ( diff --git a/src/views/plan/PlanView.tsx b/src/views/plan/PlanView.tsx index 71f917d7..4b02a868 100644 --- a/src/views/plan/PlanView.tsx +++ b/src/views/plan/PlanView.tsx @@ -18,6 +18,7 @@ import { import type { ComponentProps, CSSProperties, ReactNode } from "react"; import type { HatchRender, Plan, PlanImage, Primitive } from "../../core"; import { materializeGreyed, materializeUnderlay, type UnderlayGroup } from "../../core"; +import { planLineEndsProps } from "../../core"; import type { Drawing2D, EdgeGrip, Vec2 } from "../../model/types"; import { t } from "../../i18n"; import type { ToolHandlers, ToolId, ToolMods } from "../../tools/types"; @@ -3249,11 +3250,14 @@ export const PlanView = forwardRef( })} {/* 2D-Zeichen-Linien mit drawingId werden gemergt (drawingRuns) als EIN Zug gezeichnet → gehrte Ecken statt Butt-Cap-Stufe; im Memo übersprungen. */} + {/* Linienenden und -ecken des Projekts ([146], `Plan.lineEnds`) für alle Plan-Striche. */} + {primitiveEls} {/* Zusammenhängende 2D-Zeichen-Linienzüge als EIN /: CAD-typische Gehrung an den Ecken (stroke-linejoin), keine Stufe bei dicken Linien. Nach der Haupt-Ebene gezeichnet (2D liegt ohnehin oben). */} {drawingRunEls} + {/* Ist eine GRUPPE gewählt, ersetzt die Bounding-Box unten die einzelnen Mitglieds-Hervorhebungen (s. `groupBBox`) — dieser ganze Block bleibt dann aus. */} diff --git a/src/views/plan/useNativePlanRenderer.ts b/src/views/plan/useNativePlanRenderer.ts index 34d02a4d..f6bf3c81 100644 --- a/src/views/plan/useNativePlanRenderer.ts +++ b/src/views/plan/useNativePlanRenderer.ts @@ -256,6 +256,7 @@ export function useNativePlanRenderer( const invoke = invokeRef.current; if (!cache || !gl || !invoke || !plan) return; try { + cache.setLineEnds(plan.lineEnds); cache.update( plan.primitives, pxPerMeter,