Merge branch 'worktree-agent-aa7e43efb071a922f' into claude/practical-noether-1hb2s1
# Conflicts: # TODO.md
This commit is contained in:
44 files changed
+776
-127
No files matched your search
@@ -3483,6 +3483,31 @@ Format · [90] Versionsvergleich · [91] Assistent · [92] Speckle.
|
||||
(offene Züge ganz) samt Erdreich-Band wie `TerrainMesh` (`section::upper_edge`, `append_terrain_profiles`), keine
|
||||
Projektionskanten. Test `section::mesh_tests::ifc_gelaende_als_gelaendelinie`. FZK Schnitt A: schwarze Geländeplatte →
|
||||
Linie. Ansicht/Grundriss behandeln das Netz weiter als Netz.
|
||||
- ◐ **[153] Strichmuster einheitlich in Papier-mm.** (7.11., Befund [151] „Offen“: gestrichelte Linien im CLI-SVG
|
||||
fein punktiert.) Ursache: alle Ausgaben lesen Strichmuster als Papier-mm (render2d im Plot-Massstab, Plan-SVG ×N/1000,
|
||||
Druck-SVG in mm, DXF-Linientyp ×N/1000), mehrere Erzeuger setzten aber Modell-Meter-Werte (Treppe/Handlauf, verdeckt in
|
||||
Schnitt/Ansicht, Dachbruch `[0.12, 0.08]`, Überkopf `[0.4, 0.12, 0, 0.12]`, Öffnungen `[0.18, 0.09]`/`[0.04, 0.08]`,
|
||||
unter Sichtweite, Konstruktionslinie, gewachsenes Terrain) → überall 0.1-mm-Punkte; Achsraster (Grundriss + Schnitt/Ansicht)
|
||||
waren mit N/1000 vorskaliert → je Massstab anders lang. Neu: Kern `plan/line_pattern.rs` mit allen Linientypen in
|
||||
Papier-mm (verdeckt 2/1, Überkopf 6/1.5/Punkt/1.5, Achse 12/2.5/1.5/2.5, punktiert 0/1, Terrain 4/2, Konstruktion,
|
||||
Schnittführung), `scaled` (Strichmuster-Massstab `dashScale` multiplikativ, wie bisher bei Zeichnungen), `model_m`, und
|
||||
**Musterphase** `phase`: Zug beginnt/endet möglichst mit Strich (Kandidaten Phase 0 und Muster um die Zugmitte auf jedes
|
||||
Element zentriert, bestes kürzeres End-Strichstück). Wirkt in: Plan-SVG (`svg.rs`) und Druck-SVG (`print_svg.rs`, Blätter):
|
||||
aneinander anschliessende gestrichelte Linien gleicher Darstellung als EIN `<polyline>` mit `stroke-dashoffset`;
|
||||
Bildschirm (render2d-Strich-Shader `DASH_LINE_WGSL`, WebGPU und Metal über dieselbe Pipeline): Phase im Vertex-Shader aus
|
||||
Zuglänge und Muster (keine Striche vor dem Anfang/hinter dem Ende), CPU-Spiegel `tessellate::dash_phase`/`dash_coverage`,
|
||||
CPU-Zerlegung `split_dash` mit derselben Phase; Szene (`scene.rs`) verkettet jetzt auch abgeleitete gestrichelte Linien
|
||||
(Handlauf, Terrain) wie Zeichnungs-Linien; PDF-Druck-SVG (`sceneToPrintSvg.ts`) über die Bindung `line_dash_phase`.
|
||||
Beispiel „Dämmungsstrich“ `[0.35, 0.3]` → `[1.5, 1]`. Tests: Rust `line_pattern` (Musterlängen 1:50/100/200 gleich in
|
||||
Plan-SVG, Druck-SVG und DXF-Linientyp; Zug als eine Polylinie mit gleicher Phase in mm; Enden auf Strich für verdeckt und
|
||||
strichpunktiert), `grid_view` (Achsmuster unabhängig vom Massstab), render2d `musterphase_enden_auf_strich` (gleiche Werte
|
||||
wie der Kern), WGSL mit naga validiert (Test lokal ohne `render`-Feature-Sperre laufen lassen); vitest
|
||||
`sceneToPrintSvg.dash.test.ts`. Goldens neu (Plan/Schnitt/Ansicht Muster + komplex, CLI). Geprüft: cargo test Kern +
|
||||
render2d, WASM Kern/render2d (`--no-opt`), tsc, vitest, CLI-SVG Musterhaus komplex EG 1:50/1:100 vorher/nachher in
|
||||
Chromium (Treppe, Achsen, Überkopf am Erker). **Offen:** Bögen/Kreise (Bogen-Shader, SVG-`path`/`circle`) ohne Phase
|
||||
(beginnen mit Strich); DXF/DWG ohne Phase je Objekt (Linientyp beginnt am Anfang, Massstab stimmt); Metal-Pfad verkettet
|
||||
abgeleitete gestrichelte Linien nur über das Ketten-Flag (Zeichnungen), React-SVG-Ansicht ohne Phase; nur Linux, nicht in
|
||||
der Tauri-App/Metal 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
|
||||
|
||||
@@ -16,7 +16,7 @@ const SECTION_LINE_CATEGORY: &str = "90";
|
||||
const SECTION_LINE_INK: &str = "#1f242c";
|
||||
const SECTION_LINE_MM: f64 = 0.18;
|
||||
const SECTION_LINE_MARK_MM: f64 = 0.25;
|
||||
const SECTION_LINE_DASH: [f64; 4] = [6.0, 1.5, 0.4, 1.5];
|
||||
const SECTION_LINE_DASH: [f64; 4] = super::line_pattern::SECTION_LINE;
|
||||
const SECTION_LABEL_H: f64 = 0.5;
|
||||
|
||||
fn v2(x: f64, y: f64) -> Vec2 {
|
||||
|
||||
@@ -1848,7 +1848,7 @@ mod tests {
|
||||
assert!(!s3.contains("\"unten\""), "{s3}");
|
||||
p.drawing_levels.iter_mut().find(|l| l.id == "eg").unwrap().view_depth = Some(0.3);
|
||||
let (_, s4) = walls(&p);
|
||||
assert!(s4.contains("\"unten\"") && s4.contains("[0.04,0.08]"), "{s4}");
|
||||
assert!(s4.contains("\"unten\"") && s4.contains("[0.0,1.0]"), "{s4}");
|
||||
}
|
||||
|
||||
fn set_range(p: &mut Project, floor: &str, top: Option<f64>, bottom: Option<f64>, depth: Option<f64>) {
|
||||
@@ -1874,11 +1874,11 @@ mod tests {
|
||||
assert!(!ceil(&p, "eg").contains("\"GAL\""));
|
||||
set_range(&mut p, "eg", Some(3.0), None, None);
|
||||
let e1 = ceil(&p, "eg");
|
||||
assert!(e1.contains("\"GAL\"") && e1.contains("[0.4,0.12,0.0,0.12]"), "{e1}");
|
||||
assert!(e1.contains("\"GAL\"") && e1.contains("[6.0,1.5,0.0,1.5]"), "{e1}");
|
||||
// OG mit Unterkante 0.1 m und Tiefe: EG-Decke (bis OK OG-Boden) gepunktet „unter Schnitt“.
|
||||
set_range(&mut p, "og", None, Some(0.1), Some(0.5));
|
||||
let o1 = ceil(&p, "og");
|
||||
assert!(o1.contains("\"GAL\"") && o1.contains("[0.04,0.08]") && !o1.contains("[0.4,0.12,0.0,0.12]"), "{o1}");
|
||||
assert!(o1.contains("\"GAL\"") && o1.contains("[0.0,1.0]") && !o1.contains("[6.0,1.5,0.0,1.5]"), "{o1}");
|
||||
// Ohne Tiefe: entfällt wieder.
|
||||
set_range(&mut p, "og", None, Some(0.1), None);
|
||||
assert!(!ceil(&p, "og").contains("\"GAL\""));
|
||||
@@ -1893,8 +1893,8 @@ mod tests {
|
||||
// EG mit Oberkante bis über die Traufe: Dach des OG strichpunktiert (Vordach/Dach darüber).
|
||||
set_range(&mut p, "eg", Some(9.0), None, None);
|
||||
let e1 = roofs(&p, "eg");
|
||||
assert!(e1.contains("RF1") && e1.contains("roof-eaves") && e1.contains("[0.4,0.12,0.0,0.12]"), "{e1}");
|
||||
assert!(!e1.contains("[0.04,0.08]"));
|
||||
assert!(e1.contains("RF1") && e1.contains("roof-eaves") && e1.contains("[6.0,1.5,0.0,1.5]"), "{e1}");
|
||||
assert!(!e1.contains("[0.0,1.0]"));
|
||||
// Oberkante darunter: weiterhin nicht.
|
||||
set_range(&mut p, "eg", Some(3.0), None, None);
|
||||
assert!(!roofs(&p, "eg").contains("RF1"));
|
||||
@@ -1905,10 +1905,10 @@ mod tests {
|
||||
dg.cut_height = Some(1.0);
|
||||
p.drawing_levels.push(dg);
|
||||
let d0 = roofs(&p, "dg");
|
||||
assert!(d0.contains("RF1") && !d0.contains("[0.04,0.08]"), "{d0}");
|
||||
assert!(d0.contains("RF1") && !d0.contains("[0.0,1.0]"), "{d0}");
|
||||
set_range(&mut p, "dg", None, Some(0.0), Some(9.0));
|
||||
let d1 = roofs(&p, "dg");
|
||||
assert!(d1.contains("RF1") && d1.contains("[0.04,0.08]"), "{d1}");
|
||||
assert!(d1.contains("RF1") && d1.contains("[0.0,1.0]"), "{d1}");
|
||||
set_range(&mut p, "dg", None, Some(0.0), None);
|
||||
assert!(!roofs(&p, "dg").contains("RF1"));
|
||||
}
|
||||
@@ -1926,7 +1926,7 @@ mod tests {
|
||||
};
|
||||
let of = |v: &serde_json::Value, id: &str| -> Vec<serde_json::Value> { v.as_array().unwrap().iter().filter(|x| x["openingId"] == id).cloned().collect() };
|
||||
let w1_polys = |v: &serde_json::Value| v.as_array().unwrap().iter().filter(|x| x["kind"] == "polygon" && x["wallId"] == "W1").count();
|
||||
let dashed = |xs: &[serde_json::Value]| xs.iter().filter(|x| x["kind"] == "line").all(|x| x["dash"] == serde_json::json!([0.4, 0.12, 0.0, 0.12]));
|
||||
let dashed = |xs: &[serde_json::Value]| xs.iter().filter(|x| x["kind"] == "line").all(|x| x["dash"] == serde_json::json!([6.0, 1.5, 0.0, 1.5]));
|
||||
// Ohne Grenzen: wie bisher (Lücke in der Wand, Symbol ausgezogen).
|
||||
let (w0, r0) = run(&p);
|
||||
assert!(!of(&w0, "O1").is_empty() && !dashed(&of(&w0, "O1")));
|
||||
@@ -1960,7 +1960,7 @@ mod tests {
|
||||
let run = |p: &Project| serde_json::to_value(&plan_domains(p, &args("eg", 1.0, &codes)).unwrap().walls).unwrap();
|
||||
let of = |v: &serde_json::Value, id: &str| -> Vec<serde_json::Value> { v.as_array().unwrap().iter().filter(|x| x["openingId"] == id).cloned().collect() };
|
||||
let w1_polys = |v: &serde_json::Value| v.as_array().unwrap().iter().filter(|x| x["kind"] == "polygon" && x["wallId"] == "W1").count();
|
||||
let dotted = |xs: &[serde_json::Value]| xs.iter().filter(|x| x["kind"] == "line").all(|x| x["dash"] == serde_json::json!([0.04, 0.08]));
|
||||
let dotted = |xs: &[serde_json::Value]| xs.iter().filter(|x| x["kind"] == "line").all(|x| x["dash"] == serde_json::json!([0.0, 1.0]));
|
||||
let w0 = run(&p);
|
||||
assert!(!of(&w0, "O1").is_empty() && !dotted(&of(&w0, "O1")));
|
||||
// Unterkante 0 m: Schlitz liegt im Bereich unter dem Schnitt → Wand geschlossen, Symbol gepunktet.
|
||||
|
||||
@@ -76,7 +76,7 @@ const SCALEBAR_TEXT_MM: f64 = 3.0;
|
||||
// Konstruktionslinie / Strahl.
|
||||
const XLINE_EXTEND_M: f64 = 1000.0;
|
||||
const XLINE_WEIGHT_MM: f64 = 0.13;
|
||||
const XLINE_DASH: [f64; 4] = [0.3, 0.1, 0.03, 0.1];
|
||||
const XLINE_DASH: [f64; 4] = super::line_pattern::CONSTRUCTION;
|
||||
|
||||
/// Default-Grösse der Linienenden (Papier-mm).
|
||||
const END_MARK_DEFAULT_SIZE_MM: f64 = 3.0;
|
||||
@@ -877,7 +877,7 @@ fn emit_inner(c: &Ctx, d: &Drawing2D, attrs: Attrs, geom: &Drawing2DGeom, greyed
|
||||
if let Some(spec) = crate::grid::Spec::of(geom) {
|
||||
// [140] Achsen enden an der Gebäudegrundfläche (alle Geschosse vereinigt).
|
||||
let house = super::context::building_rings(p);
|
||||
emit_grid(&mut em, &spec, crate::grid::bubble_diameter(*bubble_mm, scale), scale, &house);
|
||||
emit_grid(&mut em, &spec, crate::grid::bubble_diameter(*bubble_mm, scale), &house);
|
||||
}
|
||||
}
|
||||
Drawing2DGeom::Text { at, text: s, height, angle, width, marks, doc, leader_target, leader_bend_points, path_pts, paper_height } => {
|
||||
@@ -1007,10 +1007,10 @@ fn dimension_segment(em: &mut Em, a: Vec2, b: Vec2, offset: f64, st: &DimStyle)
|
||||
}
|
||||
|
||||
/// Achsraster ([112]): Achsen strichpunktiert, an den Enden Blasen mit der Beschriftung.
|
||||
fn emit_grid(em: &mut Em, spec: &crate::grid::Spec, diameter: f64, scale: f64, house: &[Vec<Vec2>]) {
|
||||
fn emit_grid(em: &mut Em, spec: &crate::grid::Spec, diameter: f64, house: &[Vec<Vec2>]) {
|
||||
use crate::grid::Shape;
|
||||
let mm = |x: f64| mm_to_model(x, scale);
|
||||
let dash = [mm(12.0), mm(2.5), mm(1.5), mm(2.5)];
|
||||
// [153] Achsen strichpunktiert in Papier-mm (vorher mit dem Massstab in Modell-Meter vorskaliert).
|
||||
let dash = super::line_pattern::AXIS;
|
||||
let dash_ref = em.sink.fresh_ref();
|
||||
let w = jsnum::min(em.weight, XLINE_WEIGHT_MM.max(0.18));
|
||||
let r = diameter / 2.0;
|
||||
|
||||
@@ -42,7 +42,7 @@ const IMPORTED_RGB: [f64; 3] = [159.0 / 255.0, 166.0 / 255.0, 174.0 / 255.0];
|
||||
const EPS: f64 = 1e-6;
|
||||
const HIDDEN_INK: &str = "#8a929c";
|
||||
const HIDDEN_MM: f64 = 0.13;
|
||||
const HIDDEN_DASH: [f64; 2] = [0.12, 0.08];
|
||||
const HIDDEN_DASH: [f64; 2] = super::line_pattern::HIDDEN;
|
||||
|
||||
type Pt = [f64; 2];
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ const SITE_PROFILE_OPACITY: f64 = 0.25;
|
||||
const PARCEL_COLOR: &str = "#3a3a3a";
|
||||
const ALLOWED_COLOR: &str = "#6e6e6e";
|
||||
const PARCEL_DASH: [f64; 4] = [6.0, 1.5, 0.5, 1.5];
|
||||
const ALLOWED_DASH: [f64; 2] = [2.0, 1.0];
|
||||
const ALLOWED_DASH: [f64; 2] = super::line_pattern::HIDDEN;
|
||||
|
||||
/// Geschoss, auf dem Boden-Schatten und Baurecht erscheinen: Basishöhe am nächsten bei 0 (das erste
|
||||
/// bei Gleichstand).
|
||||
|
||||
@@ -28,7 +28,7 @@ pub fn grid_prims(p: &Project, level: &LevelSpec, bounds: [f64; 4], scale: f64)
|
||||
let Some(spec) = Spec::of(&d.geom) else { continue };
|
||||
// [137] Achsen, Blasen und Beschriftung tragen die Raster-Id: im Schnitt/in der Ansicht anwählbar.
|
||||
let id = Some(d.id.clone());
|
||||
out.extend(one(&spec, &plane, level, bounds, scale, bubble_diameter(*bubble_mm, scale), bubbles.unwrap_or(GridBubbles::Both)).into_iter().map(|mut q| {
|
||||
out.extend(one(&spec, &plane, level, bounds, bubble_diameter(*bubble_mm, scale), bubbles.unwrap_or(GridBubbles::Both)).into_iter().map(|mut q| {
|
||||
match &mut q {
|
||||
Primitive::Line { drawing_id, .. } | Primitive::DrawingCircle { drawing_id, .. } | Primitive::DrawingText { drawing_id, .. } => *drawing_id = id.clone(),
|
||||
_ => {}
|
||||
@@ -70,7 +70,7 @@ pub fn union_bounds(bounds: [f64; 4], grid: &[Primitive]) -> [f64; 4] {
|
||||
extent(grid).map_or(bounds, |g| [bounds[0].min(g[0]), bounds[1].min(g[1]), bounds[2].max(g[2]), bounds[3].max(g[3])])
|
||||
}
|
||||
|
||||
fn one(spec: &Spec, plane: &Plane, level: &LevelSpec, bounds: [f64; 4], scale: f64, diameter: f64, bubbles: GridBubbles) -> Vec<Primitive> {
|
||||
fn one(spec: &Spec, plane: &Plane, level: &LevelSpec, bounds: [f64; 4], diameter: f64, bubbles: GridBubbles) -> Vec<Primitive> {
|
||||
let (bx, by) = plane.base();
|
||||
let (ux, uy) = plane.u_model();
|
||||
let l = ux.hypot(uy);
|
||||
@@ -82,8 +82,8 @@ fn one(spec: &Spec, plane: &Plane, level: &LevelSpec, bounds: [f64; 4], scale: f
|
||||
let [p0, p1] = level.line.unwrap_or([v2(bx, by), v2(bx, by)]);
|
||||
let e = (p1.x - p0.x) * u.0 + (p1.y - p0.y) * u.1;
|
||||
let (lo, hi) = (e.min(0.0), e.max(0.0));
|
||||
let mm = |x: f64| x * scale / 1000.0;
|
||||
let dash = vec![mm(12.0), mm(2.5), mm(1.5), mm(2.5)];
|
||||
// [153] Achsen strichpunktiert in Papier-mm (vorher mit dem Massstab vorskaliert).
|
||||
let dash = super::line_pattern::AXIS.to_vec();
|
||||
let (y0, y1) = (bounds[1] - OVER_BOTTOM, bounds[3] + OVER_TOP);
|
||||
let (r, text_h) = (diameter / 2.0, diameter * 0.5);
|
||||
let mut out = Vec::new();
|
||||
@@ -160,6 +160,11 @@ mod tests {
|
||||
assert!((lines[0].0 - 1.0).abs() < 1e-9 && (lines[1].0 - 5.0).abs() < 1e-9);
|
||||
assert!(lines[0].1 < 0.0 && lines[0].2 > 6.0);
|
||||
assert_eq!(texts(&prims), ["1", "2"]);
|
||||
// [153] Achsmuster in Papier-mm, unabhängig vom Massstab (vorher mit N/1000 vorskaliert).
|
||||
for n in [50.0, 200.0] {
|
||||
let dashes: Vec<Vec<f64>> = grid_prims(&p, &level, [0.0, 0.0, 9.0, 6.0], n).iter().filter_map(|q| if let Primitive::Line { dash: Some(Some(d)), .. } = q { Some(d.clone()) } else { None }).collect();
|
||||
assert!(!dashes.is_empty() && dashes.iter().all(|d| d[..] == super::super::line_pattern::AXIS[..]), "1:{n} {dashes:?}");
|
||||
}
|
||||
// [137] alles mit der Raster-Id (anwählbar)
|
||||
assert!(prims.iter().all(|q| matches!(q, Primitive::Line { drawing_id: Some(i), .. } | Primitive::DrawingCircle { drawing_id: Some(i), .. } | Primitive::DrawingText { drawing_id: Some(i), .. } if i == "G")), "{prims:?}");
|
||||
// Schnitt längs der Achsen 1/2: nur die waagrechten Achsen A, B queren.
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
//! Linientypen der Planableitung ([153]): alle Strichmuster in **Papier-mm**, abwechselnd Strich/Lücke
|
||||
//! (`[an, aus, …]`, ein Strich der Länge 0 ist ein Punkt mit runder Kappe, [96]). Jede Ausgabe rechnet
|
||||
//! sie mit ihrem Massstab um — Bildschirm (render2d, Plot-Massstab), Plan-SVG (`svg.rs`, Modell-Meter =
|
||||
//! mm · N/1000), Druck-SVG (`print_svg.rs`, mm), DXF/DWG (Linientyp in Modell-Metern, `dxf.rs`) und
|
||||
//! Blätter (Viewport-Massstab) —, auf dem Papier ist ein Strich daher überall gleich lang. Vorher
|
||||
//! standen einige Muster in Modell-Metern (Treppe, verdeckt, Überkopf `[0.12, 0.08]` …) und wurden
|
||||
//! überall als mm gelesen (Haarpunkte), die Achsen waren mit dem Massstab vorskaliert.
|
||||
//!
|
||||
//! Längen (eigene Wahl, gängige Praxis im Architekturplan): verdeckt/gestrichelt 2 mm Strich, 1 mm Lücke;
|
||||
//! Überkopf strichpunktiert 6 mm Strich mit Punkt; Achsen lang strichpunktiert 12 mm mit kurzem Strich;
|
||||
//! punktiert = Punkte im Abstand 1 mm. Der Strichmuster-Massstab einer Zeichnung (`dashScale`) wirkt
|
||||
//! multiplikativ ([`scaled`]).
|
||||
//!
|
||||
//! Musterphase ([`phase`]): Ein gestrichelter Zug soll an beiden Enden möglichst mit einem Strich
|
||||
//! beginnen/enden; kurze Stücke dürfen nicht nur aus Lücke bestehen. Die Phase gilt für den ganzen
|
||||
//! Zug (Polylinien laufen über die Ecken durch). Spiegel: `render2d::tessellate::dash_phase` und
|
||||
//! `dash_phase` im Strich-Shader (`DASH_LINE_WGSL`), gleiche Rechenschritte.
|
||||
|
||||
/// Verdeckte Kanten, Bauteile über dem Schnitt (Treppenstufen, Dachbruch), gestrichelte Öffnungslinien.
|
||||
pub const HIDDEN: [f64; 2] = [2.0, 1.0];
|
||||
/// Überkopf (Decken-/Dachränder über der Schnittebene): Strich, Lücke, Punkt, Lücke.
|
||||
pub const OVERHEAD: [f64; 4] = [6.0, 1.5, 0.0, 1.5];
|
||||
/// Achsen (Achsraster im Grundriss, Schnitt, Ansicht): langer Strich, kurzer Strich.
|
||||
pub const AXIS: [f64; 4] = [12.0, 2.5, 1.5, 2.5];
|
||||
/// Punktiert (Bauteile unter der Sichtweite): Punkte im Abstand 1 mm.
|
||||
pub const DOTTED: [f64; 2] = [0.0, 1.0];
|
||||
/// Gewachsenes Terrain im Schnitt: länger gestrichelt.
|
||||
pub const DASHED_LONG: [f64; 2] = [4.0, 2.0];
|
||||
/// Konstruktionslinie/Strahl: Strich, Lücke, kurzer Strich, Lücke.
|
||||
pub const CONSTRUCTION: [f64; 4] = [3.0, 1.0, 0.3, 1.0];
|
||||
/// Schnittführung im Grundriss (Hauptlinie).
|
||||
pub const SECTION_LINE: [f64; 4] = [6.0, 1.5, 0.4, 1.5];
|
||||
|
||||
/// Modell-Meter je Papier-mm bei 1:`scale_n`.
|
||||
pub fn mm_to_m(scale_n: f64) -> f64 {
|
||||
scale_n / 1000.0
|
||||
}
|
||||
|
||||
/// Muster mit dem Strichmuster-Massstab `k` (Faktor, `dashScale`) gestreckt; ohne gültigen Faktor unverändert.
|
||||
pub fn scaled(mm: &[f64], k: f64) -> Vec<f64> {
|
||||
let k = if k.is_finite() && k > 0.0 { k } else { 1.0 };
|
||||
mm.iter().map(|v| v * k).collect()
|
||||
}
|
||||
|
||||
/// Muster (Papier-mm) als Längen im Modell (Meter) bei 1:`scale_n`.
|
||||
pub fn model_m(mm: &[f64], scale_n: f64) -> Vec<f64> {
|
||||
let k = mm_to_m(scale_n);
|
||||
mm.iter().map(|v| v * k).collect()
|
||||
}
|
||||
|
||||
/// Zyklus eines Musters: negative/ungültige Werte zu 0, ungerade Länge verdoppelt (SVG-Semantik),
|
||||
/// Punkte (0) bleiben. `None` = durchgezogen (leer oder ohne Länge).
|
||||
pub fn cycle(dash: &[f64]) -> Option<Vec<f64>> {
|
||||
let pat: Vec<f64> = dash.iter().map(|d| if d.is_finite() { d.max(0.0) } else { 0.0 }).collect();
|
||||
let total: f64 = pat.iter().sum();
|
||||
if pat.is_empty() || total <= 1e-12 {
|
||||
return None;
|
||||
}
|
||||
Some(if pat.len() % 2 == 0 { pat } else { [pat.as_slice(), pat.as_slice()].concat() })
|
||||
}
|
||||
|
||||
/// Sichtbares Strichstück an einem Zugende: `p` = Musterlage am Zuganfang (`at_end` falsch: Strich ab `p`
|
||||
/// bis Elementende) bzw. am Zugende (`at_end` wahr: Strich vom Elementanfang bis `p`). Positiv = Länge des
|
||||
/// Strichstücks (höchstens `len`), negativ = Lücke am Ende.
|
||||
fn end_stub(p: f64, len: f64, total: f64, cyc: &[f64], at_end: bool) -> f64 {
|
||||
let mut m = p - (p / total).floor() * total;
|
||||
if at_end && m <= 0.0 {
|
||||
m = total;
|
||||
}
|
||||
let mut acc = 0.0;
|
||||
let mut r = 0.0;
|
||||
for (i, &d) in cyc.iter().enumerate() {
|
||||
let hit = if at_end { m > acc && m <= acc + d } else { m >= acc && m < acc + d };
|
||||
if hit {
|
||||
let v = if at_end { m - acc } else { acc + d - m };
|
||||
r = if i % 2 == 0 { v.min(len) } else { -v };
|
||||
}
|
||||
acc += d;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
/// Musterphase eines gestrichelten Zugs der Länge `len` (gleiche Einheit wie `dash`): Lage im Muster am
|
||||
/// Zuganfang (für SVG `stroke-dashoffset`). Kandidaten: 0 (voller Strich am Anfang) und das Muster um
|
||||
/// die Zugmitte auf jedes Element zentriert (symmetrische Enden); es gewinnt der Kandidat mit dem
|
||||
/// längeren kürzeren End-Strichstück, bei Gleichstand der frühere.
|
||||
pub fn phase(len: f64, dash: &[f64]) -> f64 {
|
||||
let Some(cyc) = cycle(dash) else { return 0.0 };
|
||||
let total: f64 = cyc.iter().sum();
|
||||
if !(len > 0.0) || !len.is_finite() {
|
||||
return 0.0;
|
||||
}
|
||||
let score = |p: f64| end_stub(p, len, total, &cyc, false).min(end_stub(p + len, len, total, &cyc, true));
|
||||
let mut best_p = 0.0;
|
||||
let mut best = score(0.0);
|
||||
let mut acc = 0.0;
|
||||
for &d in &cyc {
|
||||
let q = acc + 0.5 * d - 0.5 * len;
|
||||
let p = q - (q / total).floor() * total;
|
||||
let s = score(p);
|
||||
if s > best + 1e-4 * total {
|
||||
best = s;
|
||||
best_p = p;
|
||||
}
|
||||
acc += d;
|
||||
}
|
||||
best_p
|
||||
}
|
||||
|
||||
/// Phase in Papier-mm für einen Zug der Modell-Länge `len_m` bei 1:`scale_n` (Muster in Papier-mm).
|
||||
pub fn phase_mm(len_m: f64, dash_mm: &[f64], scale_n: f64) -> f64 {
|
||||
let k = mm_to_m(scale_n);
|
||||
if !(k > 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
phase(len_m / k, dash_mm)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Strichstücke (Anfang, Ende) eines Zugs der Länge `len` mit Phase `ph` (Referenz-Zerlegung).
|
||||
fn pieces(len: f64, dash: &[f64], ph: f64) -> Vec<(f64, f64)> {
|
||||
let cyc = cycle(dash).unwrap();
|
||||
let total: f64 = cyc.iter().sum();
|
||||
let mut out = Vec::new();
|
||||
let mut base = -ph - total;
|
||||
while base < len {
|
||||
let mut acc = base;
|
||||
for (i, d) in cyc.iter().enumerate() {
|
||||
if i % 2 == 0 {
|
||||
let (a, b) = (acc.max(0.0), (acc + d).min(len));
|
||||
if b > a + 1e-9 || (*d == 0.0 && acc >= 0.0 && acc <= len) {
|
||||
out.push((a, b.max(a)));
|
||||
}
|
||||
}
|
||||
acc += d;
|
||||
}
|
||||
base += total;
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn muster_in_papier_mm() {
|
||||
assert_eq!(HIDDEN, [2.0, 1.0]);
|
||||
assert!(OVERHEAD[0] > HIDDEN[0] && AXIS[0] > OVERHEAD[0], "Überkopf/Achsen länger als verdeckt");
|
||||
assert_eq!(OVERHEAD[2], 0.0, "Überkopf mit Punkt");
|
||||
// 2 mm Strich bei 1:50 = 0.1 m, bei 1:100 = 0.2 m, bei 1:200 = 0.4 m Modell.
|
||||
for (n, m) in [(50.0, 0.1), (100.0, 0.2), (200.0, 0.4)] {
|
||||
assert!((model_m(&HIDDEN, n)[0] - m).abs() < 1e-12);
|
||||
}
|
||||
assert_eq!(scaled(&HIDDEN, 2.0), vec![4.0, 2.0]);
|
||||
assert_eq!(scaled(&HIDDEN, f64::NAN), vec![2.0, 1.0]);
|
||||
assert_eq!(cycle(&[3.0]), Some(vec![3.0, 3.0]));
|
||||
assert_eq!(cycle(&[0.0, 0.0]), None);
|
||||
assert_eq!(cycle(&[]), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kurzes_stueck_ist_ein_strich() {
|
||||
// kürzer als ein Strich: ganz Strich (Phase 0).
|
||||
assert_eq!(phase(1.5, &HIDDEN), 0.0);
|
||||
// knapp länger als ein Muster: beide Enden auf einem Strich, nicht in der Lücke.
|
||||
for len in [2.2, 2.5, 3.0, 3.4, 4.0, 5.5, 7.3, 10.0, 31.7] {
|
||||
let ph = phase(len, &HIDDEN);
|
||||
let p = pieces(len, &HIDDEN, ph);
|
||||
assert!(p.first().is_some_and(|q| q.0 < 1e-9 && q.1 - q.0 > 0.4), "Anfang mit Strich, L {len}: {p:?}");
|
||||
assert!(p.last().is_some_and(|q| (q.1 - len).abs() < 1e-9 && q.1 - q.0 > 0.4), "Ende mit Strich, L {len}: {p:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strichpunkt_endet_mit_strich() {
|
||||
for len in [7.0, 9.0, 14.0, 20.0, 47.5] {
|
||||
let ph = phase(len, &OVERHEAD);
|
||||
let p = pieces(len, &OVERHEAD, ph);
|
||||
let first = p.first().unwrap();
|
||||
let last = p.last().unwrap();
|
||||
assert!(first.0 < 1e-9 && first.1 - first.0 > 1.0, "L {len}: {p:?}");
|
||||
assert!((last.1 - len).abs() < 1e-9 && last.1 - last.0 > 1.0, "L {len}: {p:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Plan mit einer gestrichelten Linie (verdeckt) und einem dreiteiligen gestrichelten Zug (Überkopf), in
|
||||
/// Modell-Längen, die bei 1:`n` auf dem Papier immer gleich lang sind (40 mm bzw. 3 × 20 mm).
|
||||
fn plan_bytes(n: f64) -> Vec<u8> {
|
||||
use crate::model::Vec2;
|
||||
use crate::plan::buf::Writer;
|
||||
use crate::plan::prim::Primitive;
|
||||
let m = mm_to_m(n);
|
||||
let v = |x: f64, y: f64| Vec2 { x: x * m, y: y * m };
|
||||
let line = |a: Vec2, b: Vec2, dash: &[f64]| Primitive::Line { a, b, cls: "draw2d".into(), weight_mm: 0.18, dash: Some(Some(dash.to_vec())), zigzag: None, motif: None, color: Some("#000".into()), drawing_id: None, opening_id: None, stair_id: None, greyed: None, opacity: None };
|
||||
let mut w = Writer::new(false);
|
||||
let g = w.begin_group();
|
||||
w.push(&line(v(0.0, 0.0), v(40.0, 0.0), &HIDDEN));
|
||||
w.push(&line(v(0.0, 10.0), v(20.0, 10.0), &OVERHEAD));
|
||||
w.push(&line(v(20.0, 10.0), v(20.0, 30.0), &OVERHEAD));
|
||||
w.push(&line(v(20.0, 30.0), v(40.0, 30.0), &OVERHEAD));
|
||||
w.end_group(g);
|
||||
w.finish()
|
||||
}
|
||||
|
||||
fn parts(bytes: &[u8]) -> Vec<crate::plan::parts::Part<'_>> {
|
||||
let view = crate::plan::buf::View::parse(bytes).unwrap();
|
||||
let len = view.len();
|
||||
vec![crate::plan::parts::Part::new(view, 0, len).unwrap()]
|
||||
}
|
||||
|
||||
fn attr(el: &str, k: &str) -> Option<String> {
|
||||
el.split(&format!(" {k}=\"")).nth(1).map(|t| t.split('"').next().unwrap().to_string())
|
||||
}
|
||||
|
||||
/// [153] Gleiche Strich-/Lückenlängen auf dem Papier in 1:50, 1:100, 1:200: Plan-SVG (Modell-Meter),
|
||||
/// Druck-SVG (mm) und DXF-Linientyp (Modell-Meter). Der Zug ist EIN Element mit Musterphase.
|
||||
#[test]
|
||||
fn gleiche_musterlaenge_in_allen_ausgaben_und_massstaeben() {
|
||||
use crate::plan::line_ends::LineEnds;
|
||||
use crate::plan::print_svg::{print_svg_ops, PrintOptions};
|
||||
use crate::plan::svg::{plan_svg, SvgOptions};
|
||||
let mut offsets = Vec::new();
|
||||
for n in [50.0, 100.0, 200.0] {
|
||||
let k = mm_to_m(n);
|
||||
let bytes = plan_bytes(n);
|
||||
// Plan-SVG
|
||||
let o = SvgOptions { scale_denominator: n, margin_m: 0.0, min_x: 0.0, min_y: 0.0, max_x: 40.0 * k, max_y: 30.0 * k, hatch: false, line_ends: LineEnds::default() };
|
||||
let svg = plan_svg(&mut parts(&bytes), &o).unwrap();
|
||||
let els: Vec<&str> = svg.lines().filter(|l| l.contains("stroke-dasharray")).collect();
|
||||
assert_eq!(els.len(), 2, "Linie + EIN Zug (1:{n}): {svg}");
|
||||
let mm = |el: &str| attr(el, "stroke-dasharray").unwrap().split(' ').map(|x| x.parse::<f64>().unwrap() / k).collect::<Vec<_>>();
|
||||
let close = |a: &[f64], b: &[f64]| a.len() == b.len() && a.iter().zip(b).all(|(x, y)| (x - y).abs() < 1e-3);
|
||||
assert!(close(&mm(els[0]), &HIDDEN), "1:{n} {:?}", mm(els[0]));
|
||||
assert!(els[1].starts_with("<polyline") && close(&mm(els[1]), &OVERHEAD), "1:{n} {}", els[1]);
|
||||
let off = |el: &str| attr(el, "stroke-dashoffset").map_or(0.0, |x| x.parse::<f64>().unwrap() / k);
|
||||
offsets.push((off(els[0]), off(els[1])));
|
||||
// Druck-SVG (Blatt-mm): Muster unverändert in mm.
|
||||
let po = PrintOptions { scale_denominator: n, page_w: 100.0, page_h: 100.0, bounds: [0.0, 0.0, 40.0 * k, 30.0 * k] };
|
||||
let ops = print_svg_ops(&mut parts(&bytes), &po).unwrap();
|
||||
let recs: Vec<Vec<&str>> = ops.split('\u{1e}').map(|r| r.split('\u{1f}').collect()).filter(|f: &Vec<&str>| f.contains(&"stroke-dasharray")).collect();
|
||||
assert_eq!(recs.len(), 2, "1:{n}: {ops:?}");
|
||||
let val = |f: &Vec<&str>, k: &str| f.iter().position(|x| *x == k).map(|i| f[i + 1].to_string());
|
||||
assert_eq!(val(&recs[0], "stroke-dasharray").unwrap(), "2 1");
|
||||
assert_eq!(recs[1][2], "polyline");
|
||||
assert_eq!(val(&recs[1], "stroke-dasharray").unwrap(), "6 1.5 0 1.5");
|
||||
let poff = val(&recs[1], "stroke-dashoffset").map_or(0.0, |x| x.parse::<f64>().unwrap());
|
||||
assert!((poff - offsets.last().unwrap().1).abs() < 2e-3, "Phase Druck = Plan-SVG (1:{n})");
|
||||
// DXF-Linientyp: Modell-Meter / Massstab = Papier-mm.
|
||||
let lt = crate::plan::dxf::dash_to_ltype_meters(&HIDDEN, n).unwrap();
|
||||
assert!((lt[0] / k - 2.0).abs() < 1e-9 && (lt[1] / k + 1.0).abs() < 1e-9);
|
||||
}
|
||||
assert!(offsets.windows(2).all(|w| (w[0].0 - w[1].0).abs() < 1e-3 && (w[0].1 - w[1].1).abs() < 1e-3), "Phase in mm je Massstab gleich: {offsets:?}");
|
||||
// Zug 60 mm lang: Phase setzt beide Enden auf einen Strich.
|
||||
let p = pieces(60.0, &OVERHEAD, offsets[0].1);
|
||||
assert!(p.first().unwrap().0 < 1e-9 && p.last().is_some_and(|q| (q.1 - 60.0).abs() < 1e-9), "{p:?}");
|
||||
}
|
||||
|
||||
/// Gleiche Werte wie `render2d::tessellate::tests::musterphase_enden_auf_strich` (Shader-Spiegel).
|
||||
#[test]
|
||||
fn phase_wie_render2d() {
|
||||
assert_eq!(phase(1.5, &HIDDEN), 0.0);
|
||||
assert!((phase(10.0, &HIDDEN) - 0.5).abs() < 1e-9);
|
||||
assert!((phase(4.0, &HIDDEN) - 0.5).abs() < 1e-9);
|
||||
assert!((phase(3.0, &HIDDEN) - 1.0).abs() < 1e-9);
|
||||
assert!((phase(7.0, &OVERHEAD) - 4.0).abs() < 1e-9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn phase_unabhaengig_vom_massstab_auf_dem_papier() {
|
||||
// gleiche Papierlänge (40 mm) in 1:50/1:100/1:200 → gleiche Phase in mm.
|
||||
let a = phase_mm(2.0, &HIDDEN, 50.0);
|
||||
let b = phase_mm(4.0, &HIDDEN, 100.0);
|
||||
let c = phase_mm(8.0, &HIDDEN, 200.0);
|
||||
assert!((a - b).abs() < 1e-9 && (b - c).abs() < 1e-9);
|
||||
assert_eq!(phase(f64::NAN, &HIDDEN), 0.0);
|
||||
assert_eq!(phase(3.0, &[]), 0.0);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ pub mod pick;
|
||||
pub mod sketch;
|
||||
pub mod ceiling_plan;
|
||||
pub mod line_ends;
|
||||
pub mod line_pattern;
|
||||
pub mod stamp_place;
|
||||
pub mod trees;
|
||||
pub mod mesh_plan;
|
||||
|
||||
@@ -69,14 +69,53 @@ struct Out {
|
||||
/// 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<V2>>, Vec<usize>)>,
|
||||
/// [153] Laufender gestrichelter Zug: aneinander anschliessende Linien gleicher Darstellung
|
||||
/// (Farbe, Stift, Muster in mm, Deckkraft) werden EIN `<polyline>` mit Musterphase.
|
||||
dash_run: Option<((String, String, Vec<f64>, String), Vec<V2>)>,
|
||||
}
|
||||
|
||||
impl Out {
|
||||
fn rec(&mut self, fields: &[&str]) {
|
||||
self.flush_dash();
|
||||
self.recs.push(fields.join("\u{1f}"));
|
||||
}
|
||||
|
||||
/// Gestrichelte Linie (Papier-mm) an den laufenden Zug hängen oder einen neuen beginnen.
|
||||
fn dash_line(&mut self, key: (String, String, Vec<f64>, String), a: V2, b: V2) {
|
||||
if let Some((k, pts)) = self.dash_run.as_mut() {
|
||||
if *k == key && pts.last().is_some_and(|p| (p.x - a.x).abs() < 1e-9 && (p.y - a.y).abs() < 1e-9) {
|
||||
pts.push(b);
|
||||
return;
|
||||
}
|
||||
}
|
||||
self.flush_dash();
|
||||
self.dash_run = Some((key, vec![a, b]));
|
||||
}
|
||||
|
||||
/// Schreibt den laufenden gestrichelten Zug ([`super::line_pattern::phase`]: Enden auf einem Strich).
|
||||
fn flush_dash(&mut self) {
|
||||
let Some(((color, pen, dash, o), pts)) = self.dash_run.take() else { return };
|
||||
let len: f64 = pts.windows(2).map(|w| crate::jsmath::hypot2(w[1].x - w[0].x, w[1].y - w[0].y)).sum();
|
||||
let pen_mm: f64 = pen.parse().unwrap_or(0.0);
|
||||
let mut attrs = if pts.len() == 2 { line_attrs(pts[0], pts[1], &color, pen_mm, Some(&dash)) } else { polyline_attrs(&pts, &color, pen_mm, Some(&dash)) };
|
||||
let ph = super::line_pattern::phase(len, &dash);
|
||||
if ph > 1e-9 {
|
||||
attrs.push(("stroke-dashoffset", r3(ph)));
|
||||
}
|
||||
if !o.is_empty() {
|
||||
attrs.push(("opacity", o));
|
||||
}
|
||||
let tag = if pts.len() == 2 { "line" } else { "polyline" };
|
||||
let mut f: Vec<&str> = vec!["E", "0", tag];
|
||||
for (k, v) in &attrs {
|
||||
f.push(k);
|
||||
f.push(v);
|
||||
}
|
||||
self.recs.push(f.join("\u{1f}"));
|
||||
}
|
||||
|
||||
fn defer_solid(&mut self, key: (String, String, String), a: V2, b: V2) {
|
||||
self.flush_dash();
|
||||
self.recs.push(String::new());
|
||||
let slot = self.recs.len() - 1;
|
||||
let gi = match self.solid.iter().position(|g| g.0 == key) {
|
||||
@@ -91,6 +130,7 @@ impl Out {
|
||||
}
|
||||
|
||||
fn finish(mut self) -> String {
|
||||
self.flush_dash();
|
||||
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);
|
||||
@@ -434,6 +474,10 @@ fn entry(out: &mut Out, view: &View, i: usize, hatches: &[(i32, Hatch, i32)], m:
|
||||
out.defer_solid((color, js_number(pen), o), a, b);
|
||||
return Some(());
|
||||
}
|
||||
if let Some(dd) = d.as_ref().filter(|d| !d.is_empty()) {
|
||||
out.dash_line((color, js_number(pen), dd.clone(), 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" };
|
||||
@@ -644,7 +688,7 @@ pub fn print_svg_ops(parts: &mut [Part], o: &PrintOptions) -> Option<String> {
|
||||
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 { recs: Vec::new(), solid: Vec::new() };
|
||||
let mut out = Out { recs: Vec::new(), solid: Vec::new(), dash_run: None };
|
||||
for part in parts.iter_mut() {
|
||||
let hatches = part.view.hatch_table()?;
|
||||
for i in part.from..part.to {
|
||||
@@ -689,7 +733,7 @@ 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 { recs: Vec::new(), solid: Vec::new() };
|
||||
let mut out = Out { recs: Vec::new(), solid: Vec::new(), dash_run: None };
|
||||
text_node(&mut out, &t, m, "0.5".into());
|
||||
let s = out.finish();
|
||||
let recs: Vec<Vec<&str>> = s.split('\u{1e}').map(|r| r.split('\u{1f}').collect()).collect();
|
||||
@@ -708,7 +752,7 @@ 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 { recs: Vec::new(), solid: Vec::new() };
|
||||
let mut out = Out { recs: Vec::new(), solid: Vec::new(), dash_run: None };
|
||||
text_node(&mut out, &t, m, String::new());
|
||||
let s = out.finish();
|
||||
let recs: Vec<Vec<&str>> = s.split('\u{1e}').map(|r| r.split('\u{1f}').collect()).collect();
|
||||
@@ -725,7 +769,7 @@ 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 { recs: Vec::new(), solid: Vec::new() };
|
||||
let mut out = Out { recs: Vec::new(), solid: Vec::new(), dash_run: None };
|
||||
stamp_node(&mut out, &t, m, "0.3".into());
|
||||
let s = out.finish();
|
||||
let recs: Vec<Vec<&str>> = s.split('\u{1e}').map(|r| r.split('\u{1f}').collect()).collect();
|
||||
|
||||
@@ -551,7 +551,10 @@ pub fn build_scene(parts: &mut [Part], greyed_ranges: &[(usize, usize)]) -> Opti
|
||||
Some(s) => part.str(s).is_some_and(|s| !s.is_empty()),
|
||||
None => false,
|
||||
};
|
||||
if drawing {
|
||||
// [153] Auch abgeleitete gestrichelte Linien (Handlauf, Terrain …), die aneinander
|
||||
// anschliessen, laufen als EIN Zug: Musterphase über die Ecken wie im Plan-/Druck-SVG.
|
||||
let dashed = matches!(&dash, SDash::List(d) if !d.is_empty());
|
||||
if drawing || dashed {
|
||||
let src = RunSrc { cls, color: col_s, weight: w, dash, greyed };
|
||||
let cont = match &b.cur {
|
||||
Some((pts, c)) => {
|
||||
|
||||
@@ -29,10 +29,10 @@ const SECTION_JOINT_MM: f64 = 0.13;
|
||||
const SECTION_VISIBLE_MM: f64 = 0.18;
|
||||
const SECTION_GROUND_MM: f64 = 0.25;
|
||||
const SECTION_HIDDEN_MM: f64 = 0.13;
|
||||
const SECTION_HIDDEN_DASH: [f64; 2] = [0.12, 0.08];
|
||||
const SECTION_HIDDEN_DASH: [f64; 2] = super::line_pattern::HIDDEN;
|
||||
/// [T6] gewachsenes Terrain im Schnitt: gestrichelt, dünner als das gestaltete.
|
||||
const SECTION_NATURAL_MM: f64 = 0.25;
|
||||
const SECTION_NATURAL_DASH: [f64; 2] = [0.4, 0.2];
|
||||
const SECTION_NATURAL_DASH: [f64; 2] = super::line_pattern::DASHED_LONG;
|
||||
/// Achswinkel geschnittener Wände/Decken für wandrelative Muster (s. `toSection.ts`).
|
||||
const SECTION_WALL_AXIS_ANGLE_DEG: f64 = 90.0;
|
||||
/// Decken liegen: wandbezogene Muster laufen waagrecht entlang der Schicht ([109]; vorher 90° wie Wände,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
//! 3 arc [3, weightMm, cx, cy, fromX, fromY, toX, toY, r] (cls immer stair-outline)
|
||||
//! cls 0 stair-outline · 1 stair-tread · 2 stair-break · 3 stair-run · 4 stair-arrow · 5 stair-handrail
|
||||
//! ```
|
||||
//! Gestrichelte Linien tragen das Strichmuster `[0.12, 0.08]` (Meter, `DASH`).
|
||||
//! Gestrichelte Linien tragen das Strichmuster `DASH` (verdeckt, Papier-mm, [153]).
|
||||
//!
|
||||
//! [151] Handlauf (`railing` 0 keiner, 1 links, 2 rechts, 3 beide): Achse aus [`crate::stair_rail`] (wie im
|
||||
//! 3D), unter der Bruchhöhe ausgezogen, darüber gestrichelt; `double` (1:50/fein) zeichnet die beiden
|
||||
@@ -24,7 +24,7 @@ use crate::stair::decode_params;
|
||||
use kernel2d::{stair_cut, stair_geometry, stair_outline, Vec2};
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub const DASH: [f64; 2] = [0.12, 0.08];
|
||||
pub const DASH: [f64; 2] = super::line_pattern::HIDDEN;
|
||||
|
||||
const CLS_OUTLINE: f64 = 0.0;
|
||||
const CLS_TREAD: f64 = 1.0;
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::model::*;
|
||||
/// Linienklassen der Kern-Kodierung (`plan_stairs.rs`).
|
||||
const LINE_CLS: [&str; 6] = ["stair-outline", "stair-tread", "stair-break", "stair-run", "stair-arrow", "stair-handrail"];
|
||||
/// Strichmuster der verdeckten Tritte.
|
||||
const TREAD_DASH: [f64; 2] = [0.12, 0.08];
|
||||
const TREAD_DASH: [f64; 2] = super::line_pattern::HIDDEN;
|
||||
|
||||
/// `stairLabel` (für `object_name`).
|
||||
pub fn stair_label(s: &Stair) -> String {
|
||||
|
||||
@@ -16,14 +16,14 @@ pub const GLASS_LINE_MM: f64 = 0.02;
|
||||
/// [140] Schichtfugen im Wandschnitt ohne eigene Fugenstärke (`Layer.jointWeightMm`): fein, aber druckbar
|
||||
/// (vorher 0.02); bewusst unter der Schraffur-Stärke, damit dünne Schichten in 1:100 nicht zulaufen.
|
||||
pub const LAYER_JOINT_MM: f64 = 0.09;
|
||||
/// Kanten über der Schnittebene (Decken-/Dachränder, Bauteile „über Schnitt"): Strichpunktlinie nach
|
||||
/// SIA 400 B.3.3 (Strich, Lücke, Punkt, Lücke; Punkt = Länge 0 mit runder Kappe).
|
||||
pub const OVERHEAD_DASH: [f64; 4] = [0.4, 0.12, 0.0, 0.12];
|
||||
/// Kanten über der Schnittebene (Decken-/Dachränder, Bauteile „über Schnitt"): Strichpunktlinie
|
||||
/// (Strich, Lücke, Punkt, Lücke; Punkt = Länge 0 mit runder Kappe), Papier-mm ([153]).
|
||||
pub const OVERHEAD_DASH: [f64; 4] = super::line_pattern::OVERHEAD;
|
||||
pub const ROOF_EAVES_MM: f64 = 0.13;
|
||||
pub const ROOF_RIDGE_MM: f64 = 0.25;
|
||||
pub const ROOF_HIP_MM: f64 = 0.18;
|
||||
pub const ROOF_BREAK_MM: f64 = 0.09;
|
||||
pub const ROOF_BREAK_DASH: [f64; 2] = [0.12, 0.08];
|
||||
pub const ROOF_BREAK_DASH: [f64; 2] = super::line_pattern::HIDDEN;
|
||||
pub const WALL_FALLBACK_MM: f64 = 0.18;
|
||||
pub const HATCH_PAPER: &str = "#f0f0f0";
|
||||
pub const HATCH_INK: &str = "#0f0f0f";
|
||||
|
||||
@@ -173,6 +173,31 @@ fn op(greyed: bool, opacity: Option<f64>) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gestrichelter Zug aus aneinander anschliessenden Linien gleicher Darstellung ([153]).
|
||||
struct DashRun {
|
||||
/// Attribute ohne Geometrie (Farbe, Breite, Muster, Deckkraft).
|
||||
key: String,
|
||||
/// Muster in Papier-mm.
|
||||
dash: Vec<f64>,
|
||||
pts: Vec<V2>,
|
||||
/// Platz in der Ausgabe (erste Linie des Zugs).
|
||||
slot: usize,
|
||||
}
|
||||
|
||||
/// Schreibt einen Zug als `<line>`/`<polyline>` mit der Musterphase ([`super::line_pattern::phase`]):
|
||||
/// beide Enden möglichst auf einem Strich, Phase über die Ecken.
|
||||
fn flush_dash_run(run: Option<DashRun>, out: &mut [String], mm_to_m: f64, xs: &dyn Fn(f64) -> String, ys: &dyn Fn(f64) -> String) {
|
||||
let Some(r) = run else { return };
|
||||
let len: f64 = r.pts.windows(2).map(|w| crate::jsmath::hypot2(w[1].x - w[0].x, w[1].y - w[0].y)).sum();
|
||||
let ph = if mm_to_m > 0.0 { super::line_pattern::phase(len / mm_to_m, &r.dash) } else { 0.0 };
|
||||
let off = if ph > 1e-9 { format!(" stroke-dashoffset=\"{}\"", num(ph * mm_to_m)) } else { String::new() };
|
||||
out[r.slot] = if r.pts.len() == 2 {
|
||||
format!("<line x1=\"{}\" y1=\"{}\" x2=\"{}\" y2=\"{}\"{}{off}/>", xs(r.pts[0].x), ys(r.pts[0].y), xs(r.pts[1].x), ys(r.pts[1].y), r.key)
|
||||
} else {
|
||||
format!("<polyline points=\"{}\" fill=\"none\"{}{off}/>", r.pts.iter().map(|q| format!("{},{}", xs(q.x), ys(q.y))).collect::<Vec<_>>().join(" "), r.key)
|
||||
};
|
||||
}
|
||||
|
||||
/// SVG-Text des Plans; `None` bei kaputtem Puffer.
|
||||
pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option<String> {
|
||||
let n = o.scale_denominator;
|
||||
@@ -186,12 +211,17 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option<String> {
|
||||
let ys = |y: f64| num(top - y);
|
||||
let mut out: Vec<String> = Vec::new();
|
||||
let mut stitch = Stitcher::default();
|
||||
// [153] Gestrichelte Linien, die aneinander anschliessen, als EIN Zug (Phase über die Ecken).
|
||||
let mut run: Option<DashRun> = None;
|
||||
for part in parts.iter_mut() {
|
||||
let hatches = if o.hatch { part.view.hatch_table()? } else { Vec::new() };
|
||||
for i in part.from..part.to {
|
||||
let rec = part.view.rec(i)?;
|
||||
let f = rec.f.clone();
|
||||
let fl = rec.flags;
|
||||
if rec.tag != T_LINE || fl & F_DASH_LIST == 0 {
|
||||
flush_dash_run(run.take(), &mut out, mm_to_m, &xs, &ys);
|
||||
}
|
||||
let greyed = fl & F_GREYED != 0;
|
||||
let opacity = |k: usize| (fl & F_OPACITY != 0).then_some(f[k]);
|
||||
let dash_attr = |part: &Part| -> Option<String> {
|
||||
@@ -281,9 +311,25 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option<String> {
|
||||
T_LINE => {
|
||||
let color = if fl & F_COLOR != 0 { esc(part.str(f[1]).unwrap_or("")) } else { "#000".into() };
|
||||
let dash = dash_attr(part)?;
|
||||
if !dash.is_empty() {
|
||||
// Muster (Papier-mm) für die Phase; Zug fortsetzen oder neu beginnen.
|
||||
let (po, plen) = rec.dash?;
|
||||
let pat = part.view.pool(po, plen)?;
|
||||
let key = format!(" stroke=\"{color}\" stroke-width=\"{}\"{dash}{}", num(f[2] * mm_to_m), op(greyed, opacity(3)));
|
||||
let (a, b) = (V2 { x: f[4], y: f[5] }, V2 { x: f[6], y: f[7] });
|
||||
if let Some(r) = run.as_mut().filter(|r| r.key == key && r.pts.last().is_some_and(|p| (p.x - a.x).abs() < 1e-9 && (p.y - a.y).abs() < 1e-9)) {
|
||||
r.pts.push(b);
|
||||
} else {
|
||||
flush_dash_run(run.take(), &mut out, mm_to_m, &xs, &ys);
|
||||
out.push(String::new());
|
||||
run = Some(DashRun { key, dash: pat, pts: vec![a, b], slot: out.len() - 1 });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
flush_dash_run(run.take(), &mut out, mm_to_m, &xs, &ys);
|
||||
// [146] Volle Linien: mit Kantenläufen gleicher Farbe/Breite zusammennähen (Ecke statt
|
||||
// zweier Enden); Enden und Ecken erben die Projekt-Einstellung vom `<g>`.
|
||||
if dash.is_empty() && f[2] > 0.0 {
|
||||
if 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);
|
||||
@@ -385,6 +431,7 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option<String> {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
flush_dash_run(run.take(), &mut out, mm_to_m, &xs, &ys);
|
||||
}
|
||||
stitch.finish(&mut out, &xs, &ys);
|
||||
out.retain(|s| !s.is_empty());
|
||||
|
||||
@@ -9,8 +9,8 @@ use crate::model::*;
|
||||
|
||||
/// Strichmuster „über Schnitt“ (wie die Dach-/Deckenkanten, Strichpunkt nach SIA 400 B.3.3).
|
||||
pub const ABOVE_DASH: [f64; 4] = super::style::OVERHEAD_DASH;
|
||||
/// Strichmuster „unter Schnitt“ (gepunktet).
|
||||
pub const UNDER_DASH: [f64; 2] = [0.04, 0.08];
|
||||
/// Strichmuster „unter Schnitt“ (gepunktet, Papier-mm, [153]).
|
||||
pub const UNDER_DASH: [f64; 2] = super::line_pattern::DOTTED;
|
||||
|
||||
/// Lage eines Bauteils zum Ansichtsbereich.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
||||
@@ -23,9 +23,10 @@ const LINE_CLS: [&str; 11] = [
|
||||
|
||||
fn dash_of(code: f64) -> Option<Vec<f64>> {
|
||||
match code as i64 {
|
||||
1 => Some(vec![0.18, 0.09]),
|
||||
// Papier-mm ([153]): 1 gestrichelt, 2 Überkopf, 3 punktiert.
|
||||
1 => Some(super::line_pattern::HIDDEN.to_vec()),
|
||||
2 => Some(OVERHEAD_DASH.to_vec()),
|
||||
3 => Some(vec![0.04, 0.08]),
|
||||
3 => Some(super::line_pattern::DOTTED.to_vec()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//! Bindung der Linientypen ([153], `crate::plan::line_pattern`): Musterphase für die TS-Ausgaben
|
||||
//! (PDF-Druck-SVG `sceneToPrintSvg.ts`), gleiche Rechnung wie Plan-SVG, Druck-SVG und Strich-Shader.
|
||||
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
/// Musterphase (Papier-mm) eines gestrichelten Zugs der Länge `len_mm` mit Muster `dash_mm` (Papier-mm)
|
||||
/// für `stroke-dashoffset`; 0 bei leerem/ungültigem Muster oder Unsinn — nie Panic.
|
||||
#[wasm_bindgen]
|
||||
pub fn line_dash_phase(len_mm: f64, dash_mm: &[f64]) -> f64 {
|
||||
let p = crate::plan::line_pattern::phase(len_mm, dash_mm);
|
||||
if p.is_finite() {
|
||||
p
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@ mod rich_text;
|
||||
mod geo_mesh;
|
||||
mod opening_presets;
|
||||
mod solid_bool;
|
||||
mod line_pattern;
|
||||
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
|
||||
@@ -187,6 +187,7 @@ mod tests {
|
||||
("fill", super::shaders::FILL_WGSL),
|
||||
("line", super::shaders::LINE_WGSL),
|
||||
("arc", super::shaders::ARC_WGSL),
|
||||
("dash", super::shaders::DASH_LINE_WGSL),
|
||||
] {
|
||||
let module = naga::front::wgsl::parse_str(src)
|
||||
.unwrap_or_else(|e| panic!("{name}: WGSL-Parse-Fehler: {e:?}"));
|
||||
|
||||
@@ -283,7 +283,8 @@ fn fs_main(in : VsOut) -> @location(0) vec4<f32> {
|
||||
/// das Strichmuster rechnet der Fragment-Shader aus der Lauflaenge (frueher zerlegte die CPU jeden
|
||||
/// Zug in seine Striche, je mit runden Kappen — bei grossen Schnitten mit verdeckten Kanten
|
||||
/// Hunderte Millionen Indizes). Gleiche Semantik wie damals (`tessellate::dash_coverage` ist der
|
||||
/// CPU-Spiegel dieses Shaders): Phase ab Zuganfang ueber Ecken durch, Striche mit runden Enden
|
||||
/// CPU-Spiegel dieses Shaders): Phase ueber Ecken durch, am Zuganfang so gewaehlt, dass beide Enden
|
||||
/// moeglichst auf einem Strich liegen ([153], `dash_phase`), Striche mit runden Enden
|
||||
/// (Radius = halbe Strichbreite), hinter dem Zugende kein neuer Strich.
|
||||
///
|
||||
/// Das Quad liegt um das Segment, an beiden Enden um die halbe Breite verlaengert (Kappen/Ecken).
|
||||
@@ -309,11 +310,57 @@ struct VsOut {
|
||||
@builtin(position) pos : vec4<f32>,
|
||||
@location(0) sy : vec2<f32>,
|
||||
@location(1) @interpolate(flat) seg : vec4<f32>,
|
||||
@location(2) @interpolate(flat) pat : vec2<f32>,
|
||||
@location(2) @interpolate(flat) pat : vec4<f32>,
|
||||
@location(3) @interpolate(flat) d0 : vec4<f32>,
|
||||
@location(4) @interpolate(flat) d1 : vec4<f32>,
|
||||
};
|
||||
|
||||
// [153] Sichtbares Strichstueck an einem Zugende (Spiegel `tessellate::dash_stub`).
|
||||
fn dash_stub(p : f32, len : f32, total : f32, n : i32, c : array<f32, 8>, at_end : bool) -> f32 {
|
||||
var cyc = c;
|
||||
var m = p - floor(p / total) * total;
|
||||
if (at_end && m <= 0.0) { m = total; }
|
||||
var acc = 0.0;
|
||||
var r = 0.0;
|
||||
for (var i = 0; i < 8; i = i + 1) {
|
||||
if (i >= n) { break; }
|
||||
let d = cyc[i];
|
||||
var hit = m >= acc && m < acc + d;
|
||||
var v = acc + d - m;
|
||||
if (at_end) {
|
||||
hit = m > acc && m <= acc + d;
|
||||
v = m - acc;
|
||||
}
|
||||
if (hit) {
|
||||
if ((i % 2) == 0) { r = min(v, len); } else { r = -v; }
|
||||
}
|
||||
acc = acc + d;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// [153] Musterphase am Zuganfang: beide Enden moeglichst auf einem Strich (Spiegel `tessellate::dash_phase`).
|
||||
fn dash_phase(len : f32, total : f32, n : i32, c : array<f32, 8>) -> f32 {
|
||||
if (!(len > 0.0) || !(total > 1e-6) || n < 2) { return 0.0; }
|
||||
var cyc = c;
|
||||
var best_p = 0.0;
|
||||
var best = min(dash_stub(0.0, len, total, n, c, false), dash_stub(len, len, total, n, c, true));
|
||||
var acc = 0.0;
|
||||
for (var i = 0; i < 8; i = i + 1) {
|
||||
if (i >= n) { break; }
|
||||
let d = cyc[i];
|
||||
let q = acc + 0.5 * d - 0.5 * len;
|
||||
let p = q - floor(q / total) * total;
|
||||
let s = min(dash_stub(p, len, total, n, c, false), dash_stub(p + len, len, total, n, c, true));
|
||||
if (s > best + 1e-4 * total) {
|
||||
best = s;
|
||||
best_p = p;
|
||||
}
|
||||
acc = acc + d;
|
||||
}
|
||||
return best_p;
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn vs_main(
|
||||
@builtin(vertex_index) vidx : u32,
|
||||
@@ -354,9 +401,12 @@ fn vs_main(
|
||||
out.seg = vec4<f32>(s0, s0 + seg_px, run.y * pps, hw);
|
||||
// Muster bei 1:100 kompiliert, auf dem Papier in mm: mit dem Massstab mitskalieren ([96]).
|
||||
let ds = select(1.0, globals.dash_scale, globals.dash_scale > 0.0);
|
||||
out.pat = vec2<f32>(run.z * pps * ds, run.w);
|
||||
let total = run.z * pps * ds;
|
||||
out.d0 = d0 * pps * ds;
|
||||
out.d1 = d1 * pps * ds;
|
||||
let n = i32(run.w + 0.5) % 16;
|
||||
let cyc = array<f32, 8>(out.d0.x, out.d0.y, out.d0.z, out.d0.w, out.d1.x, out.d1.y, out.d1.z, out.d1.w);
|
||||
out.pat = vec4<f32>(total, run.w, dash_phase(run.y * pps, total, n, cyc), 0.0);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -374,8 +424,10 @@ fn fs_main(in : VsOut) -> @location(0) vec4<f32> {
|
||||
let cap_kind = nc / 16;
|
||||
var e_in = 0.0;
|
||||
if (n > 0 && total > 1e-6) {
|
||||
let k = floor(sc / total);
|
||||
let m = sc - k * total;
|
||||
let ph = in.pat.z;
|
||||
let sp = sc + ph;
|
||||
let k = floor(sp / total);
|
||||
let m = sp - k * total;
|
||||
var cyc = array<f32, 8>(in.d0.x, in.d0.y, in.d0.z, in.d0.w, in.d1.x, in.d1.y, in.d1.z, in.d1.w);
|
||||
var acc = 0.0;
|
||||
var on = true;
|
||||
@@ -393,9 +445,11 @@ fn fs_main(in : VsOut) -> @location(0) vec4<f32> {
|
||||
}
|
||||
if (!on) {
|
||||
let b = k * total;
|
||||
let pe = sc - (b + prev_end);
|
||||
var ne = b + next_start - sc;
|
||||
if (b + next_start > in.seg.z) { ne = 1e30; }
|
||||
// Striche vor dem Zuganfang/hinter dem Zugende gibt es nicht.
|
||||
var pe = sp - (b + prev_end);
|
||||
if (b + prev_end < ph) { pe = 1e30; }
|
||||
var ne = b + next_start - sp;
|
||||
if (b + next_start > in.seg.z + ph) { ne = 1e30; }
|
||||
e_in = max(min(pe, ne), 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +117,56 @@ fn dash_cycle_m(dash: &[f32]) -> Option<Vec<f32>> {
|
||||
(total > 1e-9).then_some(cycle)
|
||||
}
|
||||
|
||||
/// Sichtbares Strichstück an einem Zugende ([153]): `p` = Musterlage am Zuganfang (`at_end` falsch,
|
||||
/// Strich ab `p` bis Elementende) bzw. am Zugende (`at_end` wahr, Strich vom Elementanfang bis `p`).
|
||||
/// Positiv = Länge des Strichstücks (höchstens `len`), negativ = Länge der Lücke am Ende.
|
||||
/// Spiegel von `dash_stub` im WGSL und `line_pattern::end_stub` im Kern.
|
||||
fn dash_stub(p: f32, len: f32, total: f32, cyc: &[f32], at_end: bool) -> f32 {
|
||||
let mut m = p - (p / total).floor() * total;
|
||||
if at_end && m <= 0.0 {
|
||||
m = total;
|
||||
}
|
||||
let mut acc = 0.0f32;
|
||||
let mut r = 0.0f32;
|
||||
for (i, &d) in cyc.iter().enumerate() {
|
||||
let hit = if at_end { m > acc && m <= acc + d } else { m >= acc && m < acc + d };
|
||||
if hit {
|
||||
let v = if at_end { m - acc } else { acc + d - m };
|
||||
r = if i % 2 == 0 { v.min(len) } else { -v };
|
||||
}
|
||||
acc += d;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
/// [153] Musterphase eines gestrichelten Zugs der Länge `len` (gleiche Einheit wie der gerade Zyklus
|
||||
/// `cyc`): Lage im Muster am Zuganfang, so gewählt, dass beide Enden möglichst auf einem Strich liegen.
|
||||
/// Kandidaten: Phase 0 (voller Strich am Anfang) und das Muster um die Zugmitte zentriert auf jedes
|
||||
/// Element (symmetrische Enden); gewinnt das kürzere der beiden End-Strichstücke, bei Gleichstand der
|
||||
/// frühere Kandidat. Spiegel des WGSL-`dash_phase` (`DASH_LINE_WGSL`) und von
|
||||
/// `dossier_core::plan::line_pattern::phase` (gleiche Rechenschritte).
|
||||
pub fn dash_phase(len: f32, cyc: &[f32]) -> f32 {
|
||||
let total: f32 = cyc.iter().sum();
|
||||
if !(len > 0.0) || !(total > 1e-6) || cyc.len() < 2 {
|
||||
return 0.0;
|
||||
}
|
||||
let score = |p: f32| dash_stub(p, len, total, cyc, false).min(dash_stub(p + len, len, total, cyc, true));
|
||||
let mut best_p = 0.0f32;
|
||||
let mut best = score(0.0);
|
||||
let mut acc = 0.0f32;
|
||||
for &d in cyc {
|
||||
let q = acc + 0.5 * d - 0.5 * len;
|
||||
let p = q - (q / total).floor() * total;
|
||||
let s = score(p);
|
||||
if s > best + 1e-4 * total {
|
||||
best = s;
|
||||
best_p = p;
|
||||
}
|
||||
acc += d;
|
||||
}
|
||||
best_p
|
||||
}
|
||||
|
||||
/// Deckung eines Pixels durch einen gestrichelten Zug — CPU-Spiegel des Fragment-Shaders
|
||||
/// (`DASH_LINE_WGSL`, gleiche Rechenschritte), fuer Tests. Alles in Geraete-px: `s` Lauflaenge
|
||||
/// des Pixels (auch vor/hinter dem Segment, im Kappen-Bereich), `y` Abstand quer zur Achse,
|
||||
@@ -128,8 +178,11 @@ pub fn dash_coverage(s: f32, y: f32, seg: [f32; 4], total: f32, cyc: &[f32]) ->
|
||||
let e_out = (s - sc).abs();
|
||||
let mut e_in = 0.0f32;
|
||||
if !cyc.is_empty() && total > 1e-6 {
|
||||
let k = (sc / total).floor();
|
||||
let m = sc - k * total;
|
||||
// [153] Musterphase des ganzen Zugs (Striche an beiden Enden, s. `dash_phase`).
|
||||
let ph = dash_phase(seg[2], cyc);
|
||||
let sp = sc + ph;
|
||||
let k = (sp / total).floor();
|
||||
let m = sp - k * total;
|
||||
let mut acc = 0.0f32;
|
||||
let mut on = true;
|
||||
let mut prev_end = 0.0f32;
|
||||
@@ -144,8 +197,9 @@ pub fn dash_coverage(s: f32, y: f32, seg: [f32; 4], total: f32, cyc: &[f32]) ->
|
||||
}
|
||||
if !on {
|
||||
let base = k * total;
|
||||
let pe = sc - (base + prev_end);
|
||||
let ne = if base + next_start > seg[2] { f32::INFINITY } else { base + next_start - sc };
|
||||
// Ein Strich vor dem Zuganfang bzw. hinter dem Zugende wird nicht gezeichnet.
|
||||
let pe = if base + prev_end < ph { f32::INFINITY } else { sp - (base + prev_end) };
|
||||
let ne = if base + next_start > seg[2] + ph { f32::INFINITY } else { base + next_start - sp };
|
||||
e_in = pe.min(ne).max(0.0);
|
||||
}
|
||||
}
|
||||
@@ -247,7 +301,20 @@ fn split_dash(pts: &[Point], dash: &[f32]) -> Vec<Vec<Point>> {
|
||||
let mut idx = 0usize;
|
||||
let mut dash_left = cycle[0];
|
||||
let mut on = true;
|
||||
let mut piece: Option<Vec<Point>> = Some(vec![pts[0]]);
|
||||
// [153] Musterphase des ganzen Laufs (wie der Shader): vor dem ersten Punkt vorspulen.
|
||||
let run: f32 = pts.windows(2).map(|w| ((w[1][0] - w[0][0]).powi(2) + (w[1][1] - w[0][1]).powi(2)).sqrt()).filter(|l| *l >= 1e-12).sum();
|
||||
let mut skip = dash_phase(run, &cycle);
|
||||
while skip > 1e-9 {
|
||||
let st = skip.min(dash_left);
|
||||
skip -= st;
|
||||
dash_left -= st;
|
||||
if dash_left <= 1e-9 {
|
||||
on = !on;
|
||||
idx += 1;
|
||||
dash_left = cycle[idx % cycle.len()];
|
||||
}
|
||||
}
|
||||
let mut piece: Option<Vec<Point>> = on.then(|| vec![pts[0]]);
|
||||
|
||||
for w in pts.windows(2) {
|
||||
let mut a = w[0];
|
||||
@@ -1286,6 +1353,31 @@ mod tests {
|
||||
assert!(geo.dash_segments.is_empty() && !geo.line_idx.is_empty());
|
||||
}
|
||||
|
||||
/// [153] Musterphase wie im Kern (`line_pattern::phase`, gleiche Werte): kurze Stücke ganz Strich,
|
||||
/// sonst beide Enden auf einem Strich; die Deckung beginnt und endet mit Strich.
|
||||
#[test]
|
||||
fn musterphase_enden_auf_strich() {
|
||||
assert_eq!(dash_phase(1.5, &[2.0, 1.0]), 0.0);
|
||||
assert!((dash_phase(10.0, &[2.0, 1.0]) - 0.5).abs() < 1e-5);
|
||||
assert!((dash_phase(4.0, &[2.0, 1.0]) - 0.5).abs() < 1e-5);
|
||||
assert!((dash_phase(3.0, &[2.0, 1.0]) - 1.0).abs() < 1e-5);
|
||||
assert!((dash_phase(7.0, &[6.0, 1.5, 0.0, 1.5]) - 4.0).abs() < 1e-5);
|
||||
assert_eq!(dash_phase(f32::NAN, &[2.0, 1.0]), 0.0);
|
||||
// Zug 3 px, Muster [2, 1]: Phase 1 → Strich 0–1, Lücke 1–2, Strich 2–3 (statt Strich 0–2, Lücke bis zum Ende).
|
||||
let seg = [0.0, 3.0, 3.0, 0.5];
|
||||
let cyc = [2.0f32, 1.0];
|
||||
assert!(dash_coverage(0.0, 0.0, seg, 3.0, &cyc) < 1e-6);
|
||||
assert!(dash_coverage(2.9, 0.0, seg, 3.0, &cyc) < 1e-6, "Ende auf einem Strich");
|
||||
assert!(dash_coverage(1.5, 0.0, seg, 3.0, &cyc) > 0.4, "Mitte in der Lücke");
|
||||
// Kein Phantom-Strich vor dem Anfang: Zug 10, Phase 0.5 → Anfang im Strich [−0.5+…]; 2.0 liegt in der Lücke (1.5–2.5).
|
||||
let seg = [0.0, 10.0, 10.0, 0.25];
|
||||
assert!(dash_coverage(2.0, 0.0, seg, 3.0, &cyc) > 0.4);
|
||||
// CPU-Zerlegung mit derselben Phase.
|
||||
let pieces = split_dash(&[[0.0, 0.0], [0.3, 0.0]], &[2.0, 1.0]);
|
||||
assert_eq!(pieces.len(), 2, "{pieces:?}");
|
||||
assert!((pieces[0][1][0] - 0.1).abs() < 1e-5 && (pieces[1][0][0] - 0.2).abs() < 1e-5, "{pieces:?}");
|
||||
}
|
||||
|
||||
/// [96] Punkte (AN = 0) bleiben im Zyklus: Strichpunktlinie [12, 1.5, 0, 1.5] behaelt vier
|
||||
/// Eintraege (Strich, Luecke, Punkt, Luecke) statt zu [12, 1.5, 1.5] zusammenzufallen.
|
||||
#[test]
|
||||
@@ -1302,7 +1394,9 @@ mod tests {
|
||||
let cyc: Vec<f32> = c.iter().map(|d| d * px).collect();
|
||||
let total: f32 = cyc.iter().sum();
|
||||
let seg = [0.0, 5.0 * px, 5.0 * px, 0.5];
|
||||
let dot = (12.0 + 1.5) * DASH_MM_TO_M * px;
|
||||
// [153] Musterphase des Zugs: der Punkt liegt um sie verschoben (im nächsten Zyklus, damit s > 0).
|
||||
let ph = dash_phase(seg[2], &cyc);
|
||||
let dot = (12.0 + 1.5) * DASH_MM_TO_M * px - ph + total;
|
||||
assert!(dash_coverage(dot, 0.0, seg, total, &cyc) < 0.01);
|
||||
assert!(dash_coverage(dot - 0.7 * DASH_MM_TO_M * px, 0.0, seg, total, &cyc) > 0.5);
|
||||
}
|
||||
@@ -1383,10 +1477,11 @@ mod tests {
|
||||
#[test]
|
||||
fn split_dash_gerade_linie_erwartete_stueckzahl_und_laenge() {
|
||||
let pts = [[0.0, 0.0], [10.0, 0.0]];
|
||||
// 10mm/10mm bei Referenz-Skala (DASH_MM_TO_M=0.1) -> 1m/1m Zyklus,
|
||||
// 10m Gesamtlaenge -> 5 "an"-Stuecke a 1m (50% Tastverhaeltnis).
|
||||
// 10mm/10mm bei Referenz-Skala (DASH_MM_TO_M=0.1) -> 1m/1m Zyklus, 10m Gesamtlaenge.
|
||||
// [153] Phase: beide Enden mit einem halben Strich -> 0.5 + 4 x 1 + 0.5 m in 6 Stuecken.
|
||||
let pieces = split_dash(&pts, &[10.0, 10.0]);
|
||||
assert_eq!(pieces.len(), 5, "5 an-Stuecke erwartet");
|
||||
assert_eq!(pieces.len(), 6, "6 an-Stuecke erwartet");
|
||||
assert!((pieces[0][0][0]).abs() < 1e-5 && (pieces[5][1][0] - 10.0).abs() < 1e-4, "{pieces:?}");
|
||||
let total: f32 = pieces
|
||||
.iter()
|
||||
.map(|p| {
|
||||
|
||||
@@ -60,10 +60,10 @@
|
||||
<polygon points="4.12,6.06564 4.88,6.06564 4.88,5.10564 4.12,5.10564" fill="#d3d8dd" stroke="#2b3039" stroke-width="0.013"/>
|
||||
<polygon points="4,5.06564 5,5.06564 5,4.98564 4,4.98564" fill="#a7adb5" stroke="none" stroke-width="0"/>
|
||||
<polygon points="4,6.18564 4.08,6.18564 4.08,5.06564 4,5.06564" fill="#a7adb5" stroke="none" stroke-width="0"/>
|
||||
<line x1="4.88" y1="6.06564" x2="4.12" y2="5.58564" stroke="#7d858f" stroke-width="0.01" stroke-dasharray="0.22 0.18"/>
|
||||
<line x1="4.88" y1="5.10564" x2="4.12" y2="5.58564" stroke="#7d858f" stroke-width="0.01" stroke-dasharray="0.22 0.18"/>
|
||||
<line x1="4.12" y1="6.06564" x2="4.5" y2="5.10564" stroke="#7d858f" stroke-width="0.01" stroke-dasharray="0.22 0.18"/>
|
||||
<line x1="4.88" y1="6.06564" x2="4.5" y2="5.10564" stroke="#7d858f" stroke-width="0.01" stroke-dasharray="0.22 0.18"/>
|
||||
<line x1="4.88" y1="6.06564" x2="4.12" y2="5.58564" stroke="#7d858f" stroke-width="0.01" stroke-dasharray="0.22 0.18" stroke-dashoffset="0.06056"/>
|
||||
<line x1="4.88" y1="5.10564" x2="4.12" y2="5.58564" stroke="#7d858f" stroke-width="0.01" stroke-dasharray="0.22 0.18" stroke-dashoffset="0.06056"/>
|
||||
<line x1="4.12" y1="6.06564" x2="4.5" y2="5.10564" stroke="#7d858f" stroke-width="0.01" stroke-dasharray="0.22 0.18" stroke-dashoffset="0.19376"/>
|
||||
<line x1="4.88" y1="6.06564" x2="4.5" y2="5.10564" stroke="#7d858f" stroke-width="0.01" stroke-dasharray="0.22 0.18" stroke-dashoffset="0.19376"/>
|
||||
<polygon points="0.6,1.88564 6.4,1.88564 6.4,2.05885 0.6,2.05885" fill="#b8735c" stroke="none" stroke-width="0"/>
|
||||
<polyline points="1.8,7.08564 1.8,4.98564 2.7,4.98564 2.7,7.08564" fill="none" stroke="#2b3039" stroke-width="0.013"/>
|
||||
<polygon points="5,6.18564 4,6.18564 4,4.98564 5,4.98564" fill="none" stroke="#2b3039" stroke-width="0.013"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.6 KiB |
@@ -30,32 +30,32 @@
|
||||
<polygon points="3.2,3.41917 3.2,3.20583 4.2,3.20583 4.2,3.41917" fill="none" stroke="#1a1a1a" stroke-width="0.0126"/>
|
||||
<line x1="3.2" y1="3.20583" x2="4.2" y2="3.20583" stroke="#1a1a1a" stroke-width="0.018"/>
|
||||
<polygon points="3.2,3.20583 3.2,2.9925 4.2,2.9925 4.2,3.20583" fill="none" stroke="#1a1a1a" stroke-width="0.0126"/>
|
||||
<line x1="3.2" y1="2.9925" x2="4.2" y2="2.9925" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.012 0.008"/>
|
||||
<line x1="3.2" y1="2.9925" x2="4.2" y2="2.9925" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.2 0.1" stroke-dashoffset="0.05"/>
|
||||
<polygon points="3.2,2.9925 3.2,2.77917 4.2,2.77917 4.2,2.9925" fill="none" stroke="#1a1a1a" stroke-width="0.0126"/>
|
||||
<line x1="3.2" y1="2.77917" x2="4.2" y2="2.77917" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.012 0.008"/>
|
||||
<line x1="3.2" y1="2.77917" x2="4.2" y2="2.77917" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.2 0.1" stroke-dashoffset="0.05"/>
|
||||
<polygon points="3.2,2.77917 3.2,2.56583 4.2,2.56583 4.2,2.77917" fill="none" stroke="#1a1a1a" stroke-width="0.0126"/>
|
||||
<line x1="3.2" y1="2.56583" x2="4.2" y2="2.56583" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.012 0.008"/>
|
||||
<line x1="3.2" y1="2.56583" x2="4.2" y2="2.56583" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.2 0.1" stroke-dashoffset="0.05"/>
|
||||
<polygon points="3.2,2.56583 3.2,2.3525 4.2,2.3525 4.2,2.56583" fill="none" stroke="#1a1a1a" stroke-width="0.0126"/>
|
||||
<line x1="3.2" y1="2.3525" x2="4.2" y2="2.3525" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.012 0.008"/>
|
||||
<line x1="3.2" y1="2.3525" x2="4.2" y2="2.3525" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.2 0.1" stroke-dashoffset="0.05"/>
|
||||
<polygon points="3.2,2.3525 3.2,2.13917 4.2,2.13917 4.2,2.3525" fill="none" stroke="#1a1a1a" stroke-width="0.0126"/>
|
||||
<line x1="3.2" y1="2.13917" x2="4.2" y2="2.13917" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.012 0.008"/>
|
||||
<line x1="3.2" y1="2.13917" x2="4.2" y2="2.13917" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.2 0.1" stroke-dashoffset="0.05"/>
|
||||
<polygon points="3.2,2.13917 3.2,1.92583 4.2,1.92583 4.2,2.13917" fill="none" stroke="#1a1a1a" stroke-width="0.0126"/>
|
||||
<line x1="3.2" y1="1.92583" x2="4.2" y2="1.92583" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.012 0.008"/>
|
||||
<line x1="3.2" y1="1.92583" x2="4.2" y2="1.92583" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.2 0.1" stroke-dashoffset="0.05"/>
|
||||
<polygon points="3.2,1.92583 3.2,1.7125 4.2,1.7125 4.2,1.92583" fill="none" stroke="#1a1a1a" stroke-width="0.0126"/>
|
||||
<line x1="3.2" y1="1.7125" x2="4.2" y2="1.7125" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.012 0.008"/>
|
||||
<line x1="3.2" y1="1.7125" x2="4.2" y2="1.7125" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.2 0.1" stroke-dashoffset="0.05"/>
|
||||
<polygon points="3.2,1.7125 3.2,1.49917 4.2,1.49917 4.2,1.7125" fill="none" stroke="#1a1a1a" stroke-width="0.0126"/>
|
||||
<line x1="3.2" y1="1.49917" x2="4.2" y2="1.49917" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.012 0.008"/>
|
||||
<line x1="3.2" y1="1.49917" x2="4.2" y2="1.49917" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.2 0.1" stroke-dashoffset="0.05"/>
|
||||
<polygon points="3.2,1.49917 3.2,1.28583 4.2,1.28583 4.2,1.49917" fill="none" stroke="#1a1a1a" stroke-width="0.0126"/>
|
||||
<line x1="3.2" y1="1.28583" x2="4.2" y2="1.28583" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.012 0.008"/>
|
||||
<line x1="3.2" y1="1.28583" x2="4.2" y2="1.28583" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.2 0.1" stroke-dashoffset="0.05"/>
|
||||
<polygon points="3.2,1.28583 3.2,1.0725 4.2,1.0725 4.2,1.28583" fill="none" stroke="#1a1a1a" stroke-width="0.0126"/>
|
||||
<line x1="3.2" y1="1.0725" x2="4.2" y2="1.0725" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.012 0.008"/>
|
||||
<line x1="3.2" y1="1.0725" x2="4.2" y2="1.0725" stroke="#1a1a1a" stroke-width="0.0108" stroke-dasharray="0.2 0.1" stroke-dashoffset="0.05"/>
|
||||
<line x1="3.2" y1="3.03917" x2="4.2" y2="3.03917" stroke="#1a1a1a" stroke-width="0.018"/>
|
||||
<line x1="3.2" y1="3.15917" x2="4.2" y2="3.15917" stroke="#1a1a1a" stroke-width="0.018"/>
|
||||
<line x1="3.7" y1="4.16583" x2="3.7" y2="1.1045" stroke="#1a1a1a" stroke-width="0.018"/>
|
||||
<line x1="3.579" y1="1.3245" x2="3.7" y2="1.1045" stroke="#1a1a1a" stroke-width="0.018"/>
|
||||
<line x1="3.821" y1="1.3245" x2="3.7" y2="1.1045" stroke="#1a1a1a" stroke-width="0.018"/>
|
||||
<polygon points="3.2,4.2725 4.2,4.2725 4.2,1.0725 3.2,1.0725" fill="none" stroke="#1a1a1a" stroke-width="0.018"/>
|
||||
<line x1="-1" y1="2.6725" x2="6" y2="2.6725" stroke="#1f242c" stroke-width="0.018" stroke-dasharray="0.6 0.15 0.04 0.15"/>
|
||||
<line x1="-1" y1="2.6725" x2="6" y2="2.6725" stroke="#1f242c" stroke-width="0.018" stroke-dasharray="0.6 0.15 0.04 0.15" stroke-dashoffset="0.09"/>
|
||||
<polyline points="-1,2.9725 -1,2.3725 -1,1.7725" fill="none" stroke="#1f242c" stroke-width="0.025"/>
|
||||
<line x1="-1" y1="1.7725" x2="-0.85" y2="2.0125" stroke="#1f242c" stroke-width="0.025"/>
|
||||
<line x1="-1" y1="1.7725" x2="-1.15" y2="2.0125" stroke="#1f242c" stroke-width="0.025"/>
|
||||
@@ -65,7 +65,7 @@
|
||||
<line x1="6" y1="1.7725" x2="5.85" y2="2.0125" stroke="#1f242c" stroke-width="0.025"/>
|
||||
<text x="5.85" y="1.2825" font-size="0.5" fill="#1f242c" font-family="sans-serif" transform="rotate(0 5.85 1.2825)">A</text>
|
||||
<polygon points="-1,2.3725 6,2.3725 6,2.9725 -1,2.9725" fill="none" stroke="none" stroke-width="0"/>
|
||||
<line x1="-1" y1="6.6725" x2="6" y2="6.6725" stroke="#1f242c" stroke-width="0.018" stroke-dasharray="0.6 0.15 0.04 0.15"/>
|
||||
<line x1="-1" y1="6.6725" x2="6" y2="6.6725" stroke="#1f242c" stroke-width="0.018" stroke-dasharray="0.6 0.15 0.04 0.15" stroke-dashoffset="0.09"/>
|
||||
<polyline points="-1,6.9725 -1,6.3725 -1,5.7725" fill="none" stroke="#1f242c" stroke-width="0.025"/>
|
||||
<line x1="-1" y1="5.7725" x2="-0.85" y2="6.0125" stroke="#1f242c" stroke-width="0.025"/>
|
||||
<line x1="-1" y1="5.7725" x2="-1.15" y2="6.0125" stroke="#1f242c" stroke-width="0.025"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 8.3 KiB |
@@ -0,0 +1,59 @@
|
||||
// [153] PDF-Druck-SVG: Strichmuster in Papier-mm, in jedem Massstab gleich lang, Musterphase vom Kern
|
||||
// (`plan::line_pattern::phase`): beide Enden einer gestrichelten Linie auf einem Strich.
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { sceneToPrintSvg } from "./sceneToPrintSvg";
|
||||
import type { RScene } from "../plan/toRenderScene";
|
||||
|
||||
/** Kleinst-DOM (die Testumgebung ist `node`): Elemente mit Attributen und Kindern. */
|
||||
class FakeEl {
|
||||
attrs = new Map<string, string>();
|
||||
children: FakeEl[] = [];
|
||||
textContent = "";
|
||||
constructor(public tag: string) {}
|
||||
setAttribute(k: string, v: string): void {
|
||||
this.attrs.set(k, v);
|
||||
}
|
||||
appendChild(c: FakeEl): FakeEl {
|
||||
this.children.push(c);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
const g = globalThis as { document?: unknown };
|
||||
let saved: unknown;
|
||||
beforeEach(() => {
|
||||
saved = g.document;
|
||||
g.document = { createElementNS: (_ns: string, tag: string) => new FakeEl(tag) };
|
||||
});
|
||||
afterEach(() => {
|
||||
g.document = saved;
|
||||
});
|
||||
|
||||
/** Eine gestrichelte Linie, die bei 1:`n` auf dem Papier 30 mm lang ist. */
|
||||
function scene(n: number): RScene {
|
||||
const len = (30 * n) / 1000;
|
||||
return {
|
||||
fills: [],
|
||||
outlines: [],
|
||||
polylines: [],
|
||||
arcs: [],
|
||||
lines: [{ a: [0, 0], b: [len, 0], color: [0, 0, 0, 1], widthMm: 0.18, dash: [2, 1], z: 0 }],
|
||||
texts: [],
|
||||
images: [],
|
||||
bounds: { minX: 0, minY: -1, maxX: len, maxY: 1 },
|
||||
} as RScene;
|
||||
}
|
||||
|
||||
describe("Druck-SVG: Strichmuster", () => {
|
||||
it("gleiche Musterlänge und Phase in 1:50, 1:100, 1:200", () => {
|
||||
const seen = [50, 100, 200].map((n) => {
|
||||
const svg = sceneToPrintSvg(scene(n), { scaleDenominator: n, pageWidthMm: 100, pageHeightMm: 100 }).svg as unknown as FakeEl;
|
||||
const line = svg.children.find((c) => c.tag === "line")!;
|
||||
return [line.attrs.get("stroke-dasharray"), line.attrs.get("stroke-dashoffset")];
|
||||
});
|
||||
expect(seen.every((s) => s[0] === "2 1")).toBe(true);
|
||||
// 30 mm mit [2, 1]: genau 10 Zyklen → Phase so, dass das Ende auf einem Strich liegt (nicht 0).
|
||||
expect(seen[0][1]).toBeDefined();
|
||||
expect(seen.every((s) => s[1] === seen[0][1])).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -22,6 +22,7 @@
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { lineEndsSvgAttrs } from "../model/lineEnds";
|
||||
import type {
|
||||
RArc,
|
||||
@@ -278,10 +279,27 @@ function appendStroke(
|
||||
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");
|
||||
setDashOffset(el, pts.map((p) => map(p)), closed, dash);
|
||||
}
|
||||
svg.appendChild(el);
|
||||
}
|
||||
|
||||
/**
|
||||
* [153] Musterphase eines gestrichelten Zugs (Papier-mm-Punkte): Kern `plan::line_pattern::phase`,
|
||||
* damit beide Enden möglichst auf einem Strich liegen — gleich wie Plan-/Druck-SVG und Bildschirm.
|
||||
*/
|
||||
function setDashOffset(el: Element, ptsMm: [number, number][], closed: boolean, dash: number[]): void {
|
||||
let len = 0;
|
||||
const n = ptsMm.length;
|
||||
for (let i = 0; i + 1 < n + (closed ? 1 : 0); i++) {
|
||||
const [ax, ay] = ptsMm[i];
|
||||
const [bx, by] = ptsMm[(i + 1) % n];
|
||||
len += Math.hypot(bx - ax, by - ay);
|
||||
}
|
||||
const ph = core().line_dash_phase(len, Float64Array.from(dash));
|
||||
if (ph > 1e-9) el.setAttribute("stroke-dashoffset", String(round(ph)));
|
||||
}
|
||||
|
||||
/** Freies Liniensegment (Tuerblatt, Referenzlinie, Symbol). */
|
||||
function appendLine(svg: SVGSVGElement, l: RLine, map: Mapper, _mmPerM: number): void {
|
||||
if (l.widthMm <= 0) return;
|
||||
@@ -298,6 +316,7 @@ function appendLine(svg: SVGSVGElement, l: RLine, map: Mapper, _mmPerM: number):
|
||||
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");
|
||||
setDashOffset(el, [[ax, ay], [bx, by]], false, l.dash);
|
||||
}
|
||||
svg.appendChild(el);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export const sampleProject: Project = {
|
||||
lineStyles: [
|
||||
{ id: "thin", name: "Volllinie", color: "#1a1a1a", dash: null },
|
||||
// Gestrichelte Linie (z. B. Dämmung, Striche quer durch die Wanddicke).
|
||||
{ id: "hatch-dash", name: "Dämmungsstrich", color: "#1a1a1a", dash: [0.35, 0.3] },
|
||||
{ id: "hatch-dash", name: "Dämmungsstrich", color: "#1a1a1a", dash: [1.5, 1] },
|
||||
],
|
||||
// Schraffuren: color = Linien-/Vollfüllfarbe des Musters; angle in Grad.
|
||||
// "none" = keine Schraffur (nur Component-Füllung).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
viewBox -4.2 0 37.045 17.678
|
||||
bytes 267390
|
||||
bytes 268758
|
||||
circle 4
|
||||
g 1
|
||||
line 625
|
||||
@@ -8,4 +8,4 @@ polyline 69
|
||||
rect 1
|
||||
svg 1
|
||||
text 4
|
||||
hash 84c2ca315113d7e3
|
||||
hash a9745043c9462633
|
||||
@@ -1,12 +1,12 @@
|
||||
viewBox -4.243 0 23.243 18.205
|
||||
bytes 297250
|
||||
bytes 298010
|
||||
circle 14
|
||||
g 1
|
||||
line 3226
|
||||
line 3222
|
||||
polygon 22
|
||||
polyline 68
|
||||
polyline 70
|
||||
rect 1
|
||||
svg 1
|
||||
text 36
|
||||
tspan 12
|
||||
hash acea77aac5e90f51
|
||||
hash 735e870f40a3c586
|
||||
@@ -1,12 +1,12 @@
|
||||
viewBox -4.243 0 23.243 18.205
|
||||
bytes 307703
|
||||
bytes 308573
|
||||
circle 14
|
||||
g 1
|
||||
line 3227
|
||||
line 3223
|
||||
polygon 76
|
||||
polyline 73
|
||||
polyline 75
|
||||
rect 1
|
||||
svg 1
|
||||
text 36
|
||||
tspan 12
|
||||
hash 7d8ea347bfb8922f
|
||||
hash ab8f9617d6f7d16b
|
||||
@@ -1,13 +1,13 @@
|
||||
viewBox -41.5 0 95 63.6
|
||||
bytes 87216
|
||||
bytes 83229
|
||||
circle 16
|
||||
g 1
|
||||
line 317
|
||||
line 269
|
||||
path 18
|
||||
polygon 106
|
||||
polyline 110
|
||||
polyline 120
|
||||
rect 1
|
||||
svg 1
|
||||
text 118
|
||||
tspan 26
|
||||
hash 3f4ca96852c1460f
|
||||
hash 9e9501052d5dfb39
|
||||
@@ -1,13 +1,13 @@
|
||||
viewBox -41.5 0 95 63.6
|
||||
bytes 116056
|
||||
bytes 112023
|
||||
circle 16
|
||||
g 1
|
||||
line 344
|
||||
line 294
|
||||
path 39
|
||||
polygon 268
|
||||
polyline 126
|
||||
polyline 137
|
||||
rect 1
|
||||
svg 1
|
||||
text 121
|
||||
tspan 32
|
||||
hash a0a331bbe3ce8d24
|
||||
hash 3a31318c028477f0
|
||||
@@ -1,12 +1,12 @@
|
||||
viewBox -4.243 0 25.297 23.11
|
||||
bytes 342643
|
||||
bytes 340824
|
||||
circle 14
|
||||
g 1
|
||||
line 3327
|
||||
line 3307
|
||||
polygon 67
|
||||
polyline 154
|
||||
polyline 156
|
||||
rect 1
|
||||
svg 1
|
||||
text 91
|
||||
tspan 23
|
||||
hash 9e90cb9a60071446
|
||||
hash bacb8f3cc9970a80
|
||||
@@ -1,13 +1,13 @@
|
||||
viewBox -4.243 0 25.297 23.11
|
||||
bytes 373890
|
||||
bytes 371899
|
||||
circle 14
|
||||
g 1
|
||||
line 3354
|
||||
line 3334
|
||||
path 21
|
||||
polygon 228
|
||||
polyline 169
|
||||
polyline 171
|
||||
rect 1
|
||||
svg 1
|
||||
text 91
|
||||
tspan 24
|
||||
hash 22915e18849d47c5
|
||||
hash eccc034e26cbd3c2
|
||||
@@ -1,13 +1,13 @@
|
||||
viewBox -10.004 0 31.058 26.958
|
||||
bytes 60339
|
||||
bytes 48741
|
||||
circle 14
|
||||
g 1
|
||||
line 217
|
||||
line 110
|
||||
path 2
|
||||
polygon 60
|
||||
polyline 74
|
||||
polyline 81
|
||||
rect 1
|
||||
svg 1
|
||||
text 75
|
||||
tspan 20
|
||||
hash 6960933f9c854c8d
|
||||
hash a9f5556e41861d67
|
||||
@@ -1,13 +1,13 @@
|
||||
viewBox -10.004 0 31.058 26.958
|
||||
bytes 76091
|
||||
bytes 59010
|
||||
circle 14
|
||||
g 1
|
||||
line 273
|
||||
line 115
|
||||
path 13
|
||||
polygon 105
|
||||
polyline 79
|
||||
polyline 87
|
||||
rect 1
|
||||
svg 1
|
||||
text 75
|
||||
tspan 20
|
||||
hash 4b1eab4a5b710c50
|
||||
hash e38a3134bcc0c0d4
|
||||
@@ -1,11 +1,11 @@
|
||||
viewBox 4.457 0 21.343 17.678
|
||||
bytes 42817
|
||||
bytes 41024
|
||||
circle 3
|
||||
g 1
|
||||
line 113
|
||||
line 82
|
||||
polygon 186
|
||||
polyline 16
|
||||
polyline 26
|
||||
rect 1
|
||||
svg 1
|
||||
text 3
|
||||
hash d02852c41670f4c0
|
||||
hash be087c9e163c62e8
|
||||
@@ -1,9 +1,9 @@
|
||||
viewBox 0.1 0 6.8 7.586
|
||||
bytes 8097
|
||||
bytes 8201
|
||||
g 1
|
||||
line 7
|
||||
polygon 60
|
||||
polyline 6
|
||||
rect 1
|
||||
svg 1
|
||||
hash 92c8d38935671e86
|
||||
hash 69a2f1fc12ec2ea5
|
||||
@@ -1,5 +1,5 @@
|
||||
viewBox -0.672 0 6.345 5.345
|
||||
bytes 7956
|
||||
bytes 8216
|
||||
g 1
|
||||
line 32
|
||||
polygon 30
|
||||
@@ -8,4 +8,4 @@ rect 1
|
||||
svg 1
|
||||
text 7
|
||||
tspan 3
|
||||
hash bf3017439b3240f6
|
||||
hash 261fa3c016628c74
|
||||
@@ -1,5 +1,5 @@
|
||||
viewBox -0.672 0 6.345 5.345
|
||||
bytes 11897
|
||||
bytes 11919
|
||||
g 1
|
||||
line 33
|
||||
polygon 62
|
||||
@@ -8,4 +8,4 @@ rect 1
|
||||
svg 1
|
||||
text 7
|
||||
tspan 3
|
||||
hash 2691a9f68cf90842
|
||||
hash 81055535667e58fc
|
||||
@@ -1,10 +1,10 @@
|
||||
viewBox -0.9 0 6.8 5.8
|
||||
bytes 3630
|
||||
bytes 3322
|
||||
g 1
|
||||
line 15
|
||||
line 11
|
||||
polygon 9
|
||||
polyline 4
|
||||
polyline 5
|
||||
rect 1
|
||||
svg 1
|
||||
text 4
|
||||
hash da75b90e9db14090
|
||||
hash eb3754dda37500de
|
||||
@@ -1,10 +1,10 @@
|
||||
viewBox -0.9 0 6.8 5.8
|
||||
bytes 5578
|
||||
bytes 5279
|
||||
g 1
|
||||
line 15
|
||||
line 11
|
||||
polygon 26
|
||||
polyline 4
|
||||
polyline 5
|
||||
rect 1
|
||||
svg 1
|
||||
text 4
|
||||
hash 860efb50b93e47d9
|
||||
hash ad783367c9666db3
|
||||
@@ -327,7 +327,7 @@ describe("generatePlan — Auf-/Untersicht-Andeutung (WindowType.sillLine)", ()
|
||||
const p = project({ ...baseWindow, typeId: "wt1" }, [wt]);
|
||||
const lines = linesOfClass(p, "window-sill", "mittel");
|
||||
expect(lines.length).toBe(1);
|
||||
expect(lines[0].kind === "line" && lines[0].dash).toEqual([0.4, 0.12, 0, 0.12]);
|
||||
expect(lines[0].kind === "line" && lines[0].dash).toEqual([6, 1.5, 0, 1.5]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user