[109] SIA-400-Schraffuren: Dämmschlange, Zickzack, Welle, Holzkreuz, Naturstein, Erdreich, Kies; Schnitt-Ausrichtung

This commit is contained in:
Claude committed 2026-10-30 01:53:06 +00:00
1 parent 765a93e562
commit de53bfe1c9
17 files changed
+515 -268

No files matched your search

+14
View File
@@ -1515,6 +1515,20 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]).
Aufbau: Fugen-Strichstärke). Geprüft: Rust-/vitest-Tests; CLI-Szenen (Grundriss 1:50/1:100, Schnitte) und
DXF von Musterhaus und einem Format-3-Projekt mit allen Standards vor/nach der Migration bytegleich (Linux).
Offen: nicht in der Tauri-App geprüft. · S
- ◐ **[109] SIA-400-Schraffuren überarbeitet.** (30.10., Maintainer: „einige Schraffuren sehen trashy aus,
Dämmung ist ein spezieller Sinus") Kern-Generator (`hatch.rs`) kennt Schicht-Muster, die über die GANZE
Schichtdicke spannen und entlang der Schicht laufen (breite Flächen in Bänder à ~0.3 m geteilt): Dämmschlange
(`insulation`, Schlaufenlinie u = a·t + R·sin t, v = h·cos t, Steigung 0.45·Dicke), Hartschaum-Zickzack
(`insulationHard`), Holzfaser-Welle (`insulationWave`), Holz im Querschnitt als Diagonalkreuz je Feld
(`timber`); dazu Naturstein-Doppellinien (`stone`), Erdreich-Flechtmuster (`earth`), Kies-Kreise
(`gravel`). Standards neu abgestimmt (Abstände im Modell 0.025–0.09 m ≈ 0.5–1.8 mm Papier in 1:50/1:100;
Musterlinien 0.10/0.13 mm). Schnitt: Dachschichten-Muster folgen der Dachneigung, Deckenschichten liegen
(Achse 0°, vorher 90°), einschalige Wände wie Schicht-Bänder (vorher Grundriss-Winkel). DXF: Kurven-Muster
als Polylinien; Ressourcen-Vorschau zeichnet Vektor-Schraffuren mit dem Kern-Generator. Geprüft: Rust-
Tests, CLI-Grundriss 1:50/1:100 und Schnitte (Wand, Decke, Dach) aller Standard-Baustoffe angesehen
(Linux). Offen: 3D-Live-Schnitt (render3d) zeigt neue Muster vereinfacht (Zickzack/Kreuz/Diagonal);
Projekte mit Standards vom 29.10. behalten die alten Schraffur-Definitionen (Standards laden ergänzt nur);
Alt-Pfade `planToPrintSvg`/SVG-PlanView zeichnen neue Muster als Diagonale; nicht in der Tauri-App geprüft. · M
## Priorität 4 — später
+310 -55
View File
@@ -1,6 +1,7 @@
//! Schraffur- und Linienmuster-Geometrie des Grundrisses ([K3b], früher `glPlanHatch.ts`):
//! Linie/Segment/Polylinie gegen ein (konkaves) Polygon clippen (even-odd, halb-offene Kanten),
//! Geradenscharen (diagonal/kreuz/eigenes Motiv), Dämmungswelle, deterministische Random-
//! Geradenscharen (diagonal/kreuz/Doppellinie/eigenes Motiv), Schicht-Muster über die ganze Dicke
//! (Dämmschlange, Zickzack, Welle, Holzkreuz, [109]), Erdreich, Kies, deterministische Random-
//! Schraffur (mulberry32, modellraum-stabil), Strichmuster (`apply_dash_runs`), Zickzack und
//! Motiv-Kachelung entlang einer Strecke.
//!
@@ -43,6 +44,12 @@ pub enum Pattern {
Crosshatch = 3,
Insulation = 4,
Custom = 5,
InsulationHard = 6,
InsulationWave = 7,
Timber = 8,
Earth = 9,
Gravel = 10,
Stone = 11,
}
impl Pattern {
@@ -53,6 +60,12 @@ impl Pattern {
3 => Pattern::Crosshatch,
4 => Pattern::Insulation,
5 => Pattern::Custom,
6 => Pattern::InsulationHard,
7 => Pattern::InsulationWave,
8 => Pattern::Timber,
9 => Pattern::Earth,
10 => Pattern::Gravel,
11 => Pattern::Stone,
_ => Pattern::Diagonal,
}
}
@@ -388,8 +401,14 @@ pub fn build_hatch_runs(poly: &[V2], hatch: &Hatch) -> Vec<Run> {
if hatch.kind == HatchKind::Vector && hatch.random {
return build_random_hatch_runs(poly, hatch, Some(scale));
}
if pattern == Pattern::Insulation {
return insulation_runs(poly, hatch, scale);
match pattern {
Pattern::Insulation => return insulation_runs(poly, hatch, scale),
Pattern::InsulationHard => return zigzag_band_runs(poly, hatch, scale),
Pattern::InsulationWave => return wave_band_runs(poly, hatch, scale),
Pattern::Timber => return timber_band_runs(poly, hatch, scale),
Pattern::Earth => return earth_runs(poly, hatch, scale),
Pattern::Gravel => return gravel_runs(poly, hatch, scale),
_ => {}
}
let spacing_m = 8.0 * scale * PX_TO_M;
let rot = to_model_angle_rad(hatch.angle);
@@ -408,69 +427,225 @@ pub fn build_hatch_runs(poly: &[V2], hatch: &Hatch) -> Vec<Run> {
runs.push(vec![a, b]);
}
}
// Naturstein: jede Musterlinie als Doppellinie (zweite um 18 % des Abstands versetzt).
if pattern == Pattern::Stone {
for (a, b) in hatch_line_family(poly, a1, spacing_m, 0.18 * spacing_m, anchor) {
runs.push(vec![a, b]);
}
}
runs
}
/// Dämmungswelle (Kachel 14×10·scale px, zwei quadratische Béziers je Welle).
fn insulation_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
// ── Schicht-Muster (SIA 400, [109]) ──────────────────────────────────────────
//
// Dämmschlange, Zickzack, Welle und Holzkreuz spannen über die GANZE Schichtdicke: das Polygon wird
// im Musterrahmen (u = Laufrichtung = Schraffurwinkel, bei Wänden wandbezogen also die Wandachse;
// v quer dazu) vermessen, die Dicke ist seine Ausdehnung in v. Sehr breite Flächen (keine Schicht,
// z. B. eine freie 2D-Fläche) werden in Bänder von etwa `BAND_ROW_M` geteilt.
/// Bis zu dieser Dicke (m · scale) zeichnet ein Schichtmuster EINE Schlange über die ganze Dicke.
const BAND_MAX_M: f64 = 0.6;
/// Bandhöhe (m · scale) beim Teilen breiter Flächen.
const BAND_ROW_M: f64 = 0.3;
/// Kleinste Musterlänge (m): dünne Schichten werden nicht zu Brei.
const BAND_MIN_PITCH_M: f64 = 0.012;
/// Grenze der Stützpunkte je Muster (Schutz gegen entartete Eingaben).
const BAND_MAX_POINTS: f64 = 400_000.0;
/// Musterrahmen eines Polygons: Achsen, Ausdehnung in u, Bänder (Mitte v, halbe Höhe).
struct Band {
u: V2,
v: V2,
u0: f64,
u1: f64,
/// Phase entlang u (Projektion des Ankers): benachbarte Flächen setzen gleich an.
ua: f64,
rows: Vec<(f64, f64)>,
}
impl Band {
fn at(&self, u: f64, v: f64) -> V2 {
v2(self.u.x * u + self.v.x * v, self.u.y * u + self.v.y * v)
}
}
fn band_frame(poly: &[V2], hatch: &Hatch, scale: f64) -> Option<Band> {
let rot = to_model_angle_rad(hatch.angle);
let wavelength = 14.0 * scale * PX_TO_M;
let row_gap = 10.0 * scale * PX_TO_M;
let u_dir = rotate(v2(1.0, 0.0), rot);
let v_dir = rotate(v2(0.0, 1.0), rot);
let (mut u_min, mut u_max, mut v_min, mut v_max) = (f64::INFINITY, f64::NEG_INFINITY, f64::INFINITY, f64::NEG_INFINITY);
let u = rotate(v2(1.0, 0.0), rot);
let v = rotate(v2(0.0, 1.0), rot);
let (mut u0, mut u1, mut v0, mut v1) = (f64::INFINITY, f64::NEG_INFINITY, f64::INFINITY, f64::NEG_INFINITY);
for p in poly {
let u = p.x * u_dir.x + p.y * u_dir.y;
let v = p.x * v_dir.x + p.y * v_dir.y;
if u < u_min {
u_min = u;
}
if u > u_max {
u_max = u;
}
if v < v_min {
v_min = v;
}
if v > v_max {
v_max = v;
}
let pu = p.x * u.x + p.y * u.y;
let pv = p.x * v.x + p.y * v.y;
u0 = u0.min(pu);
u1 = u1.max(pu);
v0 = v0.min(pv);
v1 = v1.max(pv);
}
if !(u_max > u_min) || !(v_max > v_min) {
let t = v1 - v0;
if !(u1 > u0) || !(t > 1e-6) || !(u1 - u0).is_finite() || !t.is_finite() {
return None;
}
let n = if t <= BAND_MAX_M * scale { 1.0 } else { (t / (BAND_ROW_M * scale)).ceil() };
if !(n.is_finite()) || n > 10_000.0 {
return None;
}
let h = t / n;
let rows = (0..n as usize).map(|i| (v0 + (i as f64 + 0.5) * h, h / 2.0)).collect();
let anchor = hatch.origin.unwrap_or(v2(0.0, 0.0));
Some(Band { u, v, u0, u1, ua: anchor.x * u.x + anchor.y * u.y, rows })
}
/// Linienzug aus `f(x) → (Δu, v)` über die Bandlänge, `x` in Schritten `dx`, geclippt.
fn band_curve(poly: &[V2], b: &Band, vc: f64, margin: f64, dx: f64, f: impl Fn(f64) -> (f64, f64)) -> Vec<Run> {
let x0 = ((b.u0 - b.ua - margin) / dx).floor() * dx;
let x1 = b.u1 - b.ua + margin;
if !(dx > 1e-9) || (x1 - x0) / dx > BAND_MAX_POINTS {
return Vec::new();
}
const STEPS: f64 = 22.0;
let du = wavelength / STEPS;
let to_world = |u: f64, v: f64| v2(u_dir.x * u + v_dir.x * v, u_dir.y * u + v_dir.y * v);
let first_row = (v_min / row_gap - 0.5).floor() - 1.0;
let last_row = (v_max / row_gap - 0.5).ceil() + 1.0;
let u_start = ((u_min - wavelength) / du).floor() * du;
let u_end = u_max + wavelength;
if !(last_row - first_row).is_finite() || !(u_end - u_start).is_finite() {
return Vec::new();
let mut pts = Vec::new();
let mut x = x0;
while x <= x1 + 1e-12 {
let (du, dv) = f(x);
pts.push(b.at(b.ua + du, vc + dv));
x += dx;
}
let half = wavelength / 2.0;
let wave_at = |u: f64| -> f64 {
let phase = ((u % wavelength) + wavelength) % wavelength;
let t = (phase % half) / half;
let mag = 12.0 * scale * PX_TO_M * t * (1.0 - t);
if phase < half {
mag
} else {
-mag
}
};
clip_polyline_to_polygon(&pts, poly)
}
/// Dämmschlange (SIA 400, weiche Dämmung): fortlaufende, sich überlappende Schlaufen über die
/// ganze Schichtdicke — eine „Sinuslinie mit Schlaufen" (projizierte Schraubenlinie):
/// `u = a·t + R·sin t`, `v = h·cos t`, Steigung `P = 2πa` ≈ 0.45 · Dicke, Schlaufenbreite `R` = ⅔ P.
fn insulation_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
let Some(b) = band_frame(poly, hatch, scale) else { return Vec::new() };
let mut runs = Vec::new();
let mut r = first_row;
while r <= last_row {
let v_base = (r + 0.5) * row_gap;
let mut wave_pts = Vec::new();
let mut u = u_start;
while u <= u_end + 1e-9 {
wave_pts.push(to_world(u, v_base + wave_at(u)));
u += du;
for &(vc, half) in &b.rows {
let pitch = (0.45 * 2.0 * half * scale).max(BAND_MIN_PITCH_M);
let a = pitch / (2.0 * PI);
let r = pitch * (2.0 / 3.0);
// Parameter t läuft gleichmässig; 36 Stützpunkte je Schlaufe.
let dt = 2.0 * PI / 36.0;
runs.extend(band_curve(poly, &b, vc, r + pitch, a * dt, |x| {
let t = x / a;
(a * t + r * jsnum::sin(t), half * jsnum::cos(t))
}));
}
runs
}
/// Hartschaum (EPS/XPS): Zickzack über die ganze Dicke, halbe Periode = 0.5 · Dicke · scale.
fn zigzag_band_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
let Some(b) = band_frame(poly, hatch, scale) else { return Vec::new() };
let mut runs = Vec::new();
for &(vc, half) in &b.rows {
let hp = (0.5 * 2.0 * half * scale).max(BAND_MIN_PITCH_M);
runs.extend(band_curve(poly, &b, vc, hp, hp, |x| {
let k = jsnum::round(x / hp);
(x, if (k as i64).rem_euclid(2) == 0 { half } else { -half })
}));
}
runs
}
/// Holzfaser-Dämmung: Sinuswelle über die ganze Dicke, Periode = 1.2 · Dicke · scale.
fn wave_band_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
let Some(b) = band_frame(poly, hatch, scale) else { return Vec::new() };
let mut runs = Vec::new();
for &(vc, half) in &b.rows {
let period = (1.2 * 2.0 * half * scale).max(BAND_MIN_PITCH_M);
let w = 2.0 * PI / period;
runs.extend(band_curve(poly, &b, vc, period, period / 32.0, |x| (x, half * jsnum::cos(w * x))));
}
runs
}
/// Holz im Querschnitt: Diagonalkreuz je quadratischem Feld (Seite = Dicke · scale) — zwei
/// gegenläufige Zickzacks über die ganze Dicke.
fn timber_band_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
let Some(b) = band_frame(poly, hatch, scale) else { return Vec::new() };
let mut runs = Vec::new();
for &(vc, half) in &b.rows {
let side = (2.0 * half * scale).max(BAND_MIN_PITCH_M);
for sign in [1.0, -1.0] {
runs.extend(band_curve(poly, &b, vc, side, side, |x| {
let k = jsnum::round(x / side);
(x, if (k as i64).rem_euclid(2) == 0 { sign * half } else { -sign * half })
}));
}
runs.extend(clip_polyline_to_polygon(&wave_pts, poly));
r += 1.0;
}
runs
}
/// Rasterzellen (i, j) über das Polygon im Musterrahmen (Zellgrösse `cell`), mit Zellen-Grenze.
fn cells_over(poly: &[V2], u: V2, v: V2, cell: f64) -> Option<(f64, f64, f64, f64)> {
let (mut u0, mut u1, mut v0, mut v1) = (f64::INFINITY, f64::NEG_INFINITY, f64::INFINITY, f64::NEG_INFINITY);
for p in poly {
let pu = p.x * u.x + p.y * u.y;
let pv = p.x * v.x + p.y * v.y;
u0 = u0.min(pu);
u1 = u1.max(pu);
v0 = v0.min(pv);
v1 = v1.max(pv);
}
let (i0, i1, j0, j1) = ((u0 / cell).floor(), (u1 / cell).floor(), (v0 / cell).floor(), (v1 / cell).floor());
let n = (i1 - i0 + 1.0) * (j1 - j0 + 1.0);
(n.is_finite() && n <= 250_000.0 && cell > 1e-9).then_some((i0, i1, j0, j1))
}
/// Erdreich: Flechtmuster — je Zelle drei kurze parallele Striche, von Zelle zu Zelle um 90°
/// gewechselt (mit dem Schraffurwinkel gedreht, Standard 45°). Zelle 0.15 m · scale.
fn earth_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
let rot = to_model_angle_rad(hatch.angle);
let (u, v) = (rotate(v2(1.0, 0.0), rot), rotate(v2(0.0, 1.0), rot));
let cell = 0.15 * scale;
let Some((i0, i1, j0, j1)) = cells_over(poly, u, v, cell) else { return Vec::new() };
let at = |a: f64, b: f64| v2(u.x * a + v.x * b, u.y * a + v.y * b);
let mut runs = Vec::new();
let mut j = j0;
while j <= j1 {
let mut i = i0;
while i <= i1 {
let along_u = (i + j).rem_euclid(2.0) == 0.0;
for k in [0.25, 0.5, 0.75] {
let (a, b) = if along_u {
(at((i + 0.15) * cell, (j + k) * cell), at((i + 0.85) * cell, (j + k) * cell))
} else {
(at((i + k) * cell, (j + 0.15) * cell), at((i + k) * cell, (j + 0.85) * cell))
};
for (sa, sb) in clip_segment_to_polygon(a, b, poly) {
runs.push(vec![sa, sb]);
}
}
i += 1.0;
}
j += 1.0;
}
runs
}
/// Kies: kleine Kreise (Ø 25–55 % der Zelle) auf gestreutem Raster, modellraum-stabil.
/// Zelle 0.05 m · scale.
fn gravel_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
let cell = 0.05 * scale;
let Some((i0, i1, j0, j1)) = cells_over(poly, v2(1.0, 0.0), v2(0.0, 1.0), cell) else { return Vec::new() };
let seed = hatch.seed.unwrap_or(0.0);
let mut runs = Vec::new();
let mut j = j0;
while j <= j1 {
let mut i = i0;
while i <= i1 {
let mut rnd = Mulberry32 { a: hash_cell(i, j, seed) };
let r = cell * (0.125 + 0.15 * rnd.next());
let cx = (i + 0.5) * cell + (rnd.next() - 0.5) * (cell - 2.0 * r);
let cy = (j + 0.5) * cell + (rnd.next() - 0.5) * (cell - 2.0 * r);
let ring: Vec<V2> = (0..=12).map(|k| {
let a = k as f64 * PI / 6.0;
v2(cx + r * jsnum::cos(a), cy + r * jsnum::sin(a))
}).collect();
runs.extend(clip_polyline_to_polygon(&ring, poly));
i += 1.0;
}
j += 1.0;
}
runs
}
@@ -752,6 +927,86 @@ mod tests {
assert!(build_hatch_runs(&p, &hatch(Pattern::Insulation)).is_empty());
}
fn band(len: f64, t: f64) -> Vec<V2> {
vec![v2(0.0, 0.0), v2(len, 0.0), v2(len, t), v2(0.0, t)]
}
fn extent(runs: &[Run], f: impl Fn(&V2) -> f64) -> (f64, f64) {
runs.iter().flatten().fold((f64::INFINITY, f64::NEG_INFINITY), |(lo, hi), p| (lo.min(f(p)), hi.max(f(p))))
}
/// [109] Schicht-Muster spannen über die ganze Schichtdicke und laufen entlang der Schicht.
#[test]
fn schichtmuster_ueber_ganze_dicke() {
for pat in [Pattern::Insulation, Pattern::InsulationHard, Pattern::InsulationWave, Pattern::Timber] {
let mut h = hatch(pat);
h.angle = 0.0;
let runs = build_hatch_runs(&band(1.0, 0.16), &h);
assert!(!runs.is_empty(), "{pat:?}");
let (lo, hi) = extent(&runs, |p| p.y);
assert!(lo < 0.005 && hi > 0.155, "{pat:?}: {lo}..{hi}");
let (ulo, uhi) = extent(&runs, |p| p.x);
assert!(ulo < 0.02 && uhi > 0.98, "{pat:?}: {ulo}..{uhi}");
// Wand senkrecht (Winkel −90°): Muster läuft in y, spannt die Dicke in x.
h.angle = -90.0;
let vert: Vec<V2> = band(1.0, 0.16).iter().map(|p| v2(p.y, p.x)).collect();
let (xlo, xhi) = extent(&build_hatch_runs(&vert, &h), |p| p.x);
assert!(xlo < 0.005 && xhi > 0.155, "{pat:?} senkrecht: {xlo}..{xhi}");
}
}
/// Die Dämmschlange bildet Schlaufen (läuft stellenweise zurück), Steigung ≈ 0.45 · Dicke.
#[test]
fn daemmschlange_hat_schlaufen() {
let mut h = hatch(Pattern::Insulation);
h.angle = 0.0;
let runs = build_hatch_runs(&band(2.0, 0.2), &h);
let back = runs.iter().any(|r| r.windows(2).any(|w| w[1].x < w[0].x - 1e-6));
assert!(back, "Schlaufen fehlen");
// Scheitel oben: Anzahl Annäherungen an die Oberkante ≈ Länge / Steigung (2.0 / 0.09 ≈ 22).
let tops = runs.iter().flat_map(|r| r.windows(3)).filter(|w| w[1].y > w[0].y && w[1].y >= w[2].y && w[1].y > 0.199).count();
assert!((19..=25).contains(&tops), "{tops}");
}
/// Breite Flächen werden in Bänder geteilt (keine riesige Schlange).
#[test]
fn breite_flaeche_in_baender() {
let mut h = hatch(Pattern::InsulationHard);
h.angle = 0.0;
let runs = build_hatch_runs(&band(1.0, 1.2), &h);
let max_rise = runs.iter().flat_map(|r| r.windows(2)).map(|w| (w[1].y - w[0].y).abs()).fold(0.0, f64::max);
assert!(max_rise < 0.31 && max_rise > 0.29, "{max_rise}");
}
#[test]
fn erdreich_kies_naturstein() {
let sq = band(1.0, 1.0);
for pat in [Pattern::Earth, Pattern::Gravel, Pattern::Stone] {
let runs = build_hatch_runs(&sq, &hatch(pat));
assert!(!runs.is_empty(), "{pat:?}");
let (lo, hi) = extent(&runs, |p| p.x);
assert!(lo >= -1e-9 && hi <= 1.0 + 1e-9, "{pat:?} ausserhalb");
}
// Kies: geschlossene Kreise, gleiche Fläche → gleiche Steine (modellraum-stabil).
let a = build_hatch_runs(&sq, &hatch(Pattern::Gravel));
assert_eq!(a, build_hatch_runs(&sq, &hatch(Pattern::Gravel)));
assert!(a.iter().filter(|r| r.len() == 13 && r[0] == r[12]).count() > 300);
// Naturstein: doppelt so viele Linien wie Diagonal.
let d = build_hatch_runs(&sq, &hatch(Pattern::Diagonal)).len() as f64;
let st = build_hatch_runs(&sq, &hatch(Pattern::Stone)).len() as f64;
assert!((st / d - 2.0).abs() < 0.1, "{st} / {d}");
}
#[test]
fn schichtmuster_entartet_leer() {
let p = vec![v2(0.0, 0.0), v2(f64::INFINITY, 0.0), v2(1.0, 1.0)];
for pat in [Pattern::InsulationHard, Pattern::InsulationWave, Pattern::Timber, Pattern::Earth, Pattern::Gravel, Pattern::Stone] {
assert!(build_hatch_runs(&p, &hatch(pat)).is_empty(), "{pat:?}");
}
// Linie ohne Dicke
assert!(build_hatch_runs(&[v2(0.0, 0.0), v2(1.0, 0.0), v2(2.0, 0.0)], &hatch(Pattern::Insulation)).is_empty());
}
#[test]
fn strichmuster_zerlegt() {
let run = vec![v2(0.0, 0.0), v2(1.0, 0.0)];
+18
View File
@@ -232,6 +232,24 @@ pub enum HatchPattern {
Crosshatch,
#[serde(rename = "custom")]
Custom,
/// Hartschaum (EPS/XPS, [109]): Zickzack über die ganze Schichtdicke.
#[serde(rename = "insulationHard")]
InsulationHard,
/// Holzfaser-Dämmung ([109]): Sinuswelle über die ganze Schichtdicke.
#[serde(rename = "insulationWave")]
InsulationWave,
/// Holz im Querschnitt ([109]): Diagonalkreuz je Querschnittsfeld über die Schichtdicke.
#[serde(rename = "timber")]
Timber,
/// Erdreich ([109]): Gruppen kurzer Striche, wechselnd ±45° (Flechtmuster).
#[serde(rename = "earth")]
Earth,
/// Kies/Geröll ([109]): kleine Kreise auf gestreutem Raster.
#[serde(rename = "gravel")]
Gravel,
/// Naturstein ([109]): Diagonale in Doppellinien.
#[serde(rename = "stone")]
Stone,
#[serde(other)]
#[ts(skip)]
Unknown,
+9 -3
View File
@@ -26,7 +26,9 @@ const SECTION_HIDDEN_MM: f64 = 0.13;
const SECTION_HIDDEN_DASH: [f64; 2] = [0.12, 0.08];
/// Achswinkel geschnittener Wände/Decken für wandrelative Muster (s. `toSection.ts`).
const SECTION_WALL_AXIS_ANGLE_DEG: f64 = 90.0;
const SECTION_SLAB_AXIS_ANGLE_DEG: f64 = 90.0;
/// Decken liegen: wandbezogene Muster laufen waagrecht entlang der Schicht ([109]; vorher 90° wie Wände,
/// dann lagen Querstriche der Dämmung längs und die Dämmschlange stand quer).
const SECTION_SLAB_AXIS_ANGLE_DEG: f64 = 0.0;
/// Seitenrand (m) der Geländelinie um den Inhalt des Schnitts.
const TERRAIN_MARGIN: f64 = 6.0;
/// Neutrale Füllung geschnittener freier Körper.
@@ -428,7 +430,9 @@ fn wall_section_style(p: &Project, wall: &Wall) -> Option<(String, HatchRender)>
}
let best = best?;
let category = p.layer_category(&wall.category_code);
let angle = atan2(wall.end.y - wall.start.y, wall.end.x - wall.start.x) * 180.0 / std::f64::consts::PI;
// Im Schnitt steht die geschnittene Wand senkrecht — wandbezogene Muster wie bei den Schicht-Bändern
// (`split_wall_layers`), nicht nach dem Grundriss-Winkel der Wand ([109]).
let angle = SECTION_WALL_AXIS_ANGLE_DEG;
let hatch_id = resolve_hatch_id(wall.hatch_id.as_deref(), wall.hatch_source, category, Some(&best.hatch_id)).unwrap_or(&best.hatch_id);
let hatch = resolve_hatch(p, hatch_id, Some(angle), resolve_foreground(best, wall.foreground.as_deref(), category, wall.foreground_source), None)?;
Some((poche_fill(hatch.pattern).to_string(), hatch))
@@ -826,7 +830,9 @@ fn append_roof_sections(cuts: &mut Vec<Cut>, p: &Project, plane: &Plane) {
for h in &holes {
pieces = pieces.iter().flat_map(|pc| crate::opening_shape::subtract_convex(pc, h)).collect();
}
let hatch = if layer.component_id.is_empty() { None } else { p.component(&layer.component_id).and_then(|comp| resolve_hatch(p, &comp.hatch_id, None, None, None)) };
// Wandbezogene Muster laufen entlang der Dachneigung ([109]: Dämmschlange über die Schichtdicke).
let slope_deg = atan2(z1 - z0, t_hi - t_lo) * 180.0 / std::f64::consts::PI;
let hatch = if layer.component_id.is_empty() { None } else { p.component(&layer.component_id).and_then(|comp| resolve_hatch(p, &comp.hatch_id, Some(slope_deg), None, None)) };
for pts in pieces {
let mut c = Cut::new(Kind::Roof, index, pts);
if let Some(h) = &hatch {
+6
View File
@@ -2044,6 +2044,12 @@ fn write_hatch_words(out: &mut Vec<f64>, h: &HatchRender, color: f64) {
HatchPattern::Crosshatch => 3.0,
HatchPattern::Insulation => 4.0,
HatchPattern::Custom => 5.0,
HatchPattern::InsulationHard => 6.0,
HatchPattern::InsulationWave => 7.0,
HatchPattern::Timber => 8.0,
HatchPattern::Earth => 9.0,
HatchPattern::Gravel => 10.0,
HatchPattern::Stone => 11.0,
_ => 2.0,
};
let kind = match h.kind {
+17 -4
View File
@@ -523,10 +523,18 @@ fn dash_seg(a: V2, b: V2, cycle: &[f64]) -> Vec<(V2, V2)> {
out
}
/// Muster, die nicht als DXF-Linienscharen gehen und als Polylinien geschrieben werden ([109]).
fn is_curve_pattern(p: Pattern) -> bool {
matches!(
p,
Pattern::Insulation | Pattern::InsulationHard | Pattern::InsulationWave | Pattern::Timber | Pattern::Earth | Pattern::Gravel | Pattern::Stone
)
}
/// Linienscharen einer Vektor-Schraffur als (Winkel rad, Abstand m) (`hatchFamilies`).
fn hatch_families(h: &Hatch) -> Vec<(f64, f64)> {
let unit_m = 1.0 / 90.0;
let tile_m = (if h.pattern == Pattern::Insulation { 10.0 } else { 8.0 }) * h.scale * unit_m;
let tile_m = 8.0 * h.scale * unit_m;
let spacing = jsnum::max(0.02, tile_m);
if !spacing.is_finite() {
return Vec::new();
@@ -536,9 +544,6 @@ fn hatch_families(h: &Hatch) -> Vec<(f64, f64)> {
if h.pattern == Pattern::Crosshatch {
out.push((angle + PI / 2.0, spacing));
}
if h.pattern == Pattern::Insulation {
out.push((angle - PI / 4.0, spacing));
}
out
}
@@ -929,6 +934,14 @@ impl Ctx<'_> {
None => self.flat.add_line(b, hatch_layer, a, q),
}
}
} else if is_curve_pattern(pattern) {
// Schicht-/Kurvenmuster ([109]: Dämmschlange, Zickzack, Welle, Holzkreuz, Erdreich,
// Kies, Naturstein) kennt DXF-HATCH nicht: als Polylinien aus dem Kern-Generator.
let runs = hatch::apply_dash_runs(hatch::build_hatch_runs(pts, &h.h), &h.h.dash);
self.flat.set_pen(b, -1.0);
for run in runs.iter().filter(|r| r.len() >= 2) {
self.flat.add_polyline(b, hatch_layer, run, false);
}
} else if pattern != Pattern::None {
let families = hatch_families(&h.h);
if !families.is_empty() {
+48 -31
View File
@@ -51,52 +51,69 @@ pub fn line_styles() -> Vec<Value> {
json!({"id": "std-ls-bruch", "name": "Bruchlinie (Zickzack)", "color": INK, "dash": null,
"kind": "zigzag", "zigzag": {"amplitude": 1.5, "wavelength": 4}}),
dash("std-ls-schraffur-strich", "Strichlinie kurz", json!([1, 0.7])),
dash("std-ls-schraffur-punkt", "Punktlinie kurz", json!([0.15, 0.5])),
]
}
/// Schnittschraffuren (SIA 400). Abstand im Modell (Kachel 8·scale/90 m), Winkel in Grad.
/// Schnittschraffuren nach SIA 400 ([109]). Abstände im Modell (Linienschar: `spacing_m`, intern
/// `scale = spacing_m · 90 / 8`), gewählt für 1:50 (≈ 1–2 mm Papier) und noch ruhig in 1:100; Winkel in
/// Grad; Musterlinien 0.10 mm (dichte Muster) bzw. 0.13 mm (Dämmung, Holz, Backstein) — deutlich feiner als
/// die Schnittkante (0.35–0.5 mm). Schicht-Muster (Dämmschlange, Zickzack, Welle, Holzkreuz) spannen über
/// die ganze Schichtdicke und laufen entlang der Schicht (`relativeToWall`); `scale` streckt dort die
/// Musterlänge relativ zur Dicke.
pub fn hatches() -> Vec<Value> {
let h = |id: &str, name: &str, pattern: &str, scale: f64, angle: f64, rel: bool, ls: &str| {
let mut v = json!({"id": id, "name": name, "pattern": pattern, "scale": scale, "angle": angle, "color": INK});
let lines = |id: &str, name: &str, pattern: &str, spacing_m: f64, angle: f64, rel: bool, lw: f64, ls: &str| {
let scale = (spacing_m * 90.0 / 8.0 * 1e4).round() / 1e4;
let mut v = json!({"id": id, "name": name, "pattern": pattern, "scale": scale, "angle": angle, "color": INK, "lineWeight": lw});
if rel {
v["relativeToWall"] = json!(true);
}
if !ls.is_empty() {
v["lineWeight"] = json!(if ls == "std-ls-voll-025" { 0.25 } else { 0.1 });
if ls == "std-ls-voll-025" {
v["lineStyleId"] = json!("std-ls-voll");
} else if ls != "std-ls-schraffur" {
v["lineStyleId"] = json!(ls);
}
v["lineStyleId"] = json!(ls);
}
v
};
let solid = |id: &str, name: &str, color: &str| json!({"id": id, "name": name, "pattern": "solid", "scale": 1, "angle": 0, "color": color});
let random = |id: &str, name: &str, angle: f64, density: f64, lmin: f64, lmax: f64, seed: f64| {
json!({"id": id, "name": name, "kind": "vector", "lines": "random", "pattern": "diagonal", "scale": 1, "angle": angle,
"color": INK, "lineWeight": 0.1, "density": density, "lengthMin": lmin, "lengthMax": lmax, "seed": seed})
let layer = |id: &str, name: &str, pattern: &str, scale: f64| {
json!({"id": id, "name": name, "pattern": pattern, "scale": scale, "angle": 0, "relativeToWall": true, "color": INK, "lineWeight": 0.13})
};
let solid = |id: &str, name: &str, color: &str| json!({"id": id, "name": name, "pattern": "solid", "scale": 1, "angle": 0, "color": color});
vec![
h("std-h-ohne", "SIA Ohne Schraffur", "none", 1.0, 0.0, false, ""),
h("std-h-stahlbeton", "SIA Stahlbeton", "crosshatch", 0.5, 45.0, false, "std-ls-schraffur"),
h("std-h-beton", "SIA Beton unbewehrt", "crosshatch", 0.6, 45.0, false, "std-ls-schraffur-strich"),
h("std-h-backstein", "SIA Backstein", "diagonal", 0.5, 45.0, true, "std-ls-schraffur"),
h("std-h-kalksandstein", "SIA Kalksandstein", "diagonal", 0.35, 135.0, true, "std-ls-schraffur"),
h("std-h-porenbeton", "SIA Porenbeton", "diagonal", 0.5, 45.0, true, "std-ls-schraffur-strich"),
h("std-h-holz", "SIA Holz (Querschnitt)", "crosshatch", 0.6, 0.0, true, "std-ls-schraffur"),
h("std-h-bsp", "SIA Brettsperrholz", "diagonal", 0.3, 90.0, true, "std-ls-schraffur"),
random("std-h-holzwerkstoff", "SIA Holzwerkstoff", 30.0, 1.4, 0.6, 1.5, 7.0),
h("std-h-daemmung-weich", "SIA Dämmung weich", "insulation", 1.0, 0.0, true, "std-ls-schraffur"),
h("std-h-eps", "SIA Dämmung EPS", "diagonal", 0.45, 0.0, true, "std-ls-schraffur"),
h("std-h-xps", "SIA Dämmung XPS", "crosshatch", 0.45, 0.0, true, "std-ls-schraffur"),
h("std-h-holzfaser", "SIA Dämmung Holzfaser", "insulation", 0.8, 0.0, true, "std-ls-schraffur-strich"),
json!({"id": "std-h-ohne", "name": "SIA Ohne Schraffur", "pattern": "none", "scale": 1, "angle": 0, "color": INK}),
// Stahlbeton: Kreuzschraffur 45°/135°, bildschirmfest.
lines("std-h-stahlbeton", "SIA Stahlbeton", "crosshatch", 0.07, 45.0, false, 0.1, ""),
// Beton unbewehrt: Diagonale 45°, unterbrochen.
lines("std-h-beton", "SIA Beton unbewehrt", "diagonal", 0.07, 45.0, false, 0.1, "std-ls-schraffur-strich"),
// Mauerwerk Backstein: Diagonale 45° zur Wand.
lines("std-h-backstein", "SIA Backstein", "diagonal", 0.06, 45.0, true, 0.13, ""),
// Kalksandstein: Diagonale gegenläufig (135°), enger.
lines("std-h-kalksandstein", "SIA Kalksandstein", "diagonal", 0.045, 135.0, true, 0.1, ""),
// Porenbeton: Diagonale 45°, weit, lange Striche.
lines("std-h-porenbeton", "SIA Porenbeton", "diagonal", 0.09, 45.0, true, 0.1, "std-ls-strich-fein"),
// Holz im Querschnitt: Diagonalkreuz je Feld über die Dicke.
layer("std-h-holz", "SIA Holz (Querschnitt)", "timber", 1.0),
// Brettsperrholz: Lamellenfugen längs der Schicht.
lines("std-h-bsp", "SIA Brettsperrholz", "diagonal", 0.04, 90.0, true, 0.1, ""),
// Holzwerkstoff (Span-/OSB-Platte): kurze, gestreute Späne.
json!({"id": "std-h-holzwerkstoff", "name": "SIA Holzwerkstoff", "kind": "vector", "lines": "random", "pattern": "diagonal", "scale": 1,
"angle": 30, "color": INK, "lineWeight": 0.1, "density": 2, "lengthMin": 0.15, "lengthMax": 0.3, "seed": 7}),
// Dämmung weich (Mineral-/Steinwolle, Trittschall): Dämmschlange über die ganze Dicke.
layer("std-h-daemmung-weich", "SIA Dämmung weich", "insulation", 1.0),
// Hartschaum: Zickzack über die Dicke; XPS dichter als EPS (SIA 400 unterscheidet sie nicht).
layer("std-h-eps", "SIA Dämmung EPS", "insulationHard", 1.0),
layer("std-h-xps", "SIA Dämmung XPS", "insulationHard", 0.7),
// Holzfaser: Welle über die Dicke.
layer("std-h-holzfaser", "SIA Dämmung Holzfaser", "insulationWave", 1.0),
solid("std-h-gips", "SIA Gips", "#cfcfcf"),
h("std-h-estrich", "SIA Estrich", "diagonal", 0.35, 45.0, false, "std-ls-schraffur-strich"),
// Estrich/Überzug: feines Punktfeld (punktierte Diagonale).
lines("std-h-estrich", "SIA Estrich", "diagonal", 0.025, 45.0, false, 0.1, "std-ls-schraffur-punkt"),
solid("std-h-stahl", "SIA Stahl", INK),
solid("std-h-alu", "SIA Aluminium", "#8c8c8c"),
h("std-h-naturstein", "SIA Naturstein", "diagonal", 0.8, 45.0, false, "std-ls-voll-025"),
random("std-h-erdreich", "SIA Erdreich", 45.0, 0.8, 1.5, 4.0, 11.0),
random("std-h-kies", "SIA Kies / Sauberkeitsschicht", 60.0, 1.8, 0.4, 0.9, 13.0),
// Naturstein: Diagonale in Doppellinien.
lines("std-h-naturstein", "SIA Naturstein", "stone", 0.08, 45.0, false, 0.1, ""),
// Erdreich: Flechtmuster kurzer Striche ±45°.
lines("std-h-erdreich", "SIA Erdreich", "earth", 0.0889, 45.0, false, 0.1, ""),
// Kies/Sauberkeitsschicht: kleine Kreise gestreut.
lines("std-h-kies", "SIA Kies / Sauberkeitsschicht", "gravel", 0.0889, 0.0, false, 0.1, ""),
]
}
@@ -358,7 +375,7 @@ mod tests {
assert_eq!(comps[0]["color"], "#8c5544", "vorhandenes Bauteil unverändert");
let iw = r["wallTypes"].as_array().unwrap().iter().find(|t| t["id"] == "std-wt-iw-backstein").unwrap();
assert_eq!(iw["layers"][1]["componentId"], "brick");
let pb = r["hatches"].as_array().unwrap().iter().find(|h| h["id"] == "std-h-porenbeton").unwrap();
let pb = r["hatches"].as_array().unwrap().iter().find(|h| h["id"] == "std-h-beton").unwrap();
assert_eq!(pb["lineStyleId"], "thin");
}
}
+4 -1
View File
@@ -42,7 +42,10 @@ fn pattern_id(p: HatchPattern) -> f64 {
HatchPattern::Solid => 1.0,
HatchPattern::Diagonal => 2.0,
HatchPattern::Crosshatch => 3.0,
HatchPattern::Insulation => 4.0,
HatchPattern::Insulation | HatchPattern::InsulationHard | HatchPattern::InsulationWave => 4.0,
// 3D-Schnittflächen (render3d) kennen nur die Grundmuster: nächstliegendes ([109]).
HatchPattern::Timber | HatchPattern::Earth => 3.0,
HatchPattern::Gravel | HatchPattern::Stone => 2.0,
_ => 0.0,
}
}
+1
View File
@@ -131,6 +131,7 @@ export {
export {
DASH_MM_TO_M,
buildRandomHatchRuns,
buildHatchRuns,
motifPoints,
zigzagPoints,
} from "../plan/glPlan/glPlanHatch";
+7 -1
View File
@@ -1317,7 +1317,13 @@ export const de = {
// Schraffur-Muster.
"pattern.none": "Ohne",
"pattern.solid": "Vollfläche",
"pattern.insulation": "Wärmedämmung",
"pattern.insulation": "Wärmedämmung weich (Dämmschlange)",
"pattern.insulationHard": "Wärmedämmung hart (Zickzack)",
"pattern.insulationWave": "Holzfaser-Dämmung (Welle)",
"pattern.timber": "Holz im Querschnitt",
"pattern.stone": "Naturstein",
"pattern.earth": "Erdreich",
"pattern.gravel": "Kies",
"pattern.diagonal": "Diagonal",
"pattern.crosshatch": "Kreuzschraffur",
"pattern.custom": "Eigenes Motiv",
+7 -1
View File
@@ -1308,7 +1308,13 @@ export const en: Record<TranslationKey, string> = {
"pattern.none": "None",
"pattern.solid": "Solid",
"pattern.insulation": "Insulation",
"pattern.insulation": "Soft insulation (loop line)",
"pattern.insulationHard": "Rigid insulation (zigzag)",
"pattern.insulationWave": "Wood-fibre insulation (wave)",
"pattern.timber": "Timber cross-section",
"pattern.stone": "Natural stone",
"pattern.earth": "Earth",
"pattern.gravel": "Gravel",
"pattern.diagonal": "Diagonal",
"pattern.crosshatch": "Crosshatch",
"pattern.custom": "Custom motif",
+13 -1
View File
@@ -1116,7 +1116,19 @@ export type Group = {
};
/** Mögliche Schraffur-Muster im Plan/Schnitt. */
export type HatchPattern = "none" | "solid" | "insulation" | "diagonal" | "crosshatch" | "custom";
export type HatchPattern =
| "none"
| "solid"
| "insulation"
| "diagonal"
| "crosshatch"
| "custom"
| "insulationHard"
| "insulationWave"
| "timber"
| "earth"
| "gravel"
| "stone";
/** Eine wiederverwendbare Schraffur (Hatch Manager). */
export type HatchStyle = {
+4 -3
View File
@@ -121,13 +121,14 @@ describe("generatePlan — Schichtfugen als stilisierbare Linien", () => {
p.kind === "line" && p.cls === "layer-joint",
);
it("zieht die innere Fuge als eigene Linie und übernimmt Gewicht/Farbe des LineStyle", () => {
it("zieht die innere Fuge als eigene Linie: Farbe/Muster vom LineStyle, Stärke von der Schicht ([110])", () => {
const proj = cornerProject();
proj.walls = [proj.walls[0]]; // nur W1, zwei Schichten → genau eine innere Fuge
proj.wallTypes[0].layers[0].jointLineStyleId = "thin"; // weight 0.13, color #111
proj.wallTypes[0].layers[0].jointLineStyleId = "thin"; // color #111
proj.wallTypes[0].layers[0].jointWeightMm = 0.13;
const joints = jointLines(proj);
expect(joints.length).toBe(1);
// LAYER_DETAIL_FACTOR["mittel"] == 1 → das LineStyle-Gewicht wirkt direkt.
// LAYER_DETAIL_FACTOR["mittel"] == 1 → die Fugen-Stärke der Schicht wirkt direkt.
expect(joints[0].weightMm).toBeCloseTo(0.13, 6);
expect(joints[0].color).toBe("#111");
expect(joints[0].dash ?? null).toBeNull();
+2 -1
View File
@@ -136,7 +136,8 @@ export function applyDashRuns(runs: HatchRun[], dash: number[] | null): HatchRun
/**
* Schraffur eines Polygons als zusammenhängende Läufe (Modell-Meter): diagonal (eine Schar),
* crosshatch (zwei Scharen), insulation (Welle), custom (Motiv je Musterlinie), Random-Untermodus
* crosshatch (zwei Scharen), Schicht-Muster über die Dicke (Dämmschlange, Zickzack, Welle, Holzkreuz),
* Naturstein, Erdreich, Kies, custom (Motiv je Musterlinie), Random-Untermodus
* (gestreute Striche); solid/none sowie Bild/Verlauf liefern keine Linien-Geometrie des Musters.
*/
export function buildHatchRuns(poly: Vec2[], hatch: HatchRender): HatchRun[] {
+6
View File
@@ -111,6 +111,12 @@ const PATTERN_CODE: Record<string, number> = {
crosshatch: 3,
insulation: 4,
custom: 5,
insulationHard: 6,
insulationWave: 7,
timber: 8,
earth: 9,
gravel: 10,
stone: 11,
};
/** Ein Hatch-Datensatz (auch Eingabe der Einzel-Bindungen in `glPlanHatch.ts`). */
+43 -167
View File
@@ -1,72 +1,48 @@
// Live-SVG-Vorschau (Swatch) für Schraffuren und Linienstile — eigenständig.
// Live-SVG-Vorschau (Swatch) für Schraffuren und Linienstile.
//
// Bewusst OHNE Rückgriff auf die Plan-Renderer (generatePlan/toRenderScene):
// diese Datei zeichnet die Muster direkt aus den HatchStyle-/LineStyle-Parametern
// als SVG nach, damit die Vorschau im Ressourcen-Manager auch dann konsistent
// bleibt, während der Plan-Renderer separat umgebaut wird. Die Farbe kommt hier
// bewusst NICHT vom (deprecated) HatchStyle.color, sondern über `currentColor`
// aus dem umgebenden CSS (var(--ink)) — die echte Vordergrundfarbe stammt im Plan
// vom Bauteil/Attribut. Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
// Vektor-Schraffuren zeichnet die Vorschau mit DEMSELBEN Kern-Generator wie Plan, Schnitt und Druck
// (`buildHatchRuns`, [109]) — die Box wird als Fläche in Modell-Metern (`SWATCH_PX_PER_M`) übergeben,
// Schicht-Muster (Dämmschlange, Zickzack …) spannen also über das Band wie im Plan. Bild/Verlauf als
// SVG-Füllung. Die Farbe kommt bewusst NICHT vom (deprecated) HatchStyle.color, sondern über
// `currentColor` aus dem umgebenden CSS (var(--ink)) — die echte Vordergrundfarbe stammt im Plan vom
// Bauteil/Attribut. Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
import { useId } from "react";
import type { HatchStyle, LineStyle } from "../model/types";
import { dashHasDot } from "../core";
import { buildHatchRuns, dashHasDot } from "../core";
// ── Kleiner deterministischer PRNG (mulberry32) ────────────────────────────
// Für „random"-Striche: stabil pro Seed, damit die Vorschau bei gleichem
// Maßstab/Winkel nicht bei jedem Render „springt".
function mulberry32(seed: number): () => number {
let a = seed >>> 0;
return () => {
a |= 0;
a = (a + 0x6d2b79f5) | 0;
let t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
/** Vorschau-Massstab: px je Modell-Meter (128 px ≈ 0.43 m, etwa 1:10 am Bildschirm). */
const SWATCH_PX_PER_M = 300;
/**
* Parallele Linienschar über die Box (w×h) unter `angleDeg`, Abstand `spacing`
* px senkrecht zur Linienrichtung. Liefert fertige <line>-Elemente, die die Box
* komplett überdecken (Clip übernimmt der Aufrufer).
* Musterlinien einer Vektor-Schraffur für eine Box `w`×`h` (px) aus dem Kern-Generator. `wallAngleDeg`
* dreht wandbezogene Muster wie im Plan (Wand senkrecht = 90).
*/
function parallelLines(
w: number,
h: number,
angleDeg: number,
spacing: number,
strokeWidth: number,
keyPrefix: string,
): React.ReactNode[] {
const a = (angleDeg * Math.PI) / 180;
const cos = Math.cos(a);
const sin = Math.sin(a);
// Senkrechte zur Linienrichtung.
const px = -sin;
const py = cos;
const cx = w / 2;
const cy = h / 2;
const half = Math.hypot(w, h); // Linien lang genug, um die Box zu überdecken.
const step = Math.max(spacing, 1.2);
const n = Math.ceil(half / step) + 2;
const out: React.ReactNode[] = [];
for (let k = -n; k <= n; k++) {
const mx = cx + k * step * px;
const my = cy + k * step * py;
out.push(
<line
key={`${keyPrefix}${k}`}
x1={mx - cos * half}
y1={my - sin * half}
x2={mx + cos * half}
y2={my + sin * half}
stroke="currentColor"
strokeWidth={strokeWidth}
/>,
);
}
return out;
function vectorRuns(hatch: HatchStyle, w: number, h: number, wallAngleDeg: number | undefined): string[] {
const k = SWATCH_PX_PER_M;
const poly = [
{ x: 0, y: 0 },
{ x: w / k, y: 0 },
{ x: w / k, y: h / k },
{ x: 0, y: h / k },
];
const angle = hatch.relativeToWall && wallAngleDeg != null ? hatch.angle - wallAngleDeg : hatch.angle;
const runs = buildHatchRuns(poly, {
pattern: hatch.pattern,
scale: hatch.scale,
angle,
color: "#000",
lineWeight: hatch.lineWeight ?? 0.13,
dash: null,
kind: hatch.kind,
lines: hatch.lines,
seed: hatch.seed,
density: hatch.density,
lengthMin: hatch.lengthMin,
lengthMax: hatch.lengthMax,
motif: hatch.motif,
});
return runs.map((r) => r.map((p, i) => `${i ? "L" : "M"}${(p.x * k).toFixed(1)} ${(h - p.y * k).toFixed(1)}`).join(""));
}
/**
@@ -76,14 +52,9 @@ function parallelLines(
* Band DASSELBE Muster zeichnet. `uid` macht interne <pattern>-IDs eindeutig
* (mehrere Bänder je SVG).
*/
function hatchInner(hatch: HatchStyle, w: number, h: number, uid: string): React.ReactNode {
function hatchInner(hatch: HatchStyle, w: number, h: number, uid: string, wallAngleDeg?: number): React.ReactNode {
const patId = `hsp_${uid}`;
// Grundabstand der Musterlinien (px), über den Maßstab moduliert.
const scale = hatch.scale > 0 ? hatch.scale : 1;
const spacing = Math.max(3, 8 / Math.sqrt(scale));
const angle = hatch.angle || 0;
let inner: React.ReactNode = null;
if (hatch.kind === "image") {
@@ -172,106 +143,11 @@ function hatchInner(hatch: HatchStyle, w: number, h: number, uid: string): React
inner = <rect x={0} y={0} width={w} height={h} fill="currentColor" />;
} else if (hatch.pattern === "none") {
inner = null;
} else if (hatch.lines === "random") {
// Zufällig verteilte kurze Striche (deterministisch geseedet). Dichte, Länge
// und der explizite Seed spiegeln die Plan-Parameter (HatchStyle) — so ändert
// „Neu würfeln"/Dichte/Länge die Vorschau wie im Plan. Rein schematisch (px),
// NICHT deckungsgleich mit der Modell-Streuung, aber qualitativ konsistent.
const density = hatch.density != null && hatch.density > 0 ? hatch.density : 1;
const seed = (Math.round(scale * 1000) + Math.round(angle) + Math.round(hatch.seed ?? 0)) >>> 0;
const rnd = mulberry32(seed);
const count = Math.min(400, Math.max(4, Math.round((18 * Math.min(2, scale) + 6) * density)));
// mm-Papier → Vorschau-px (wie das Dash-Muster im LineSwatch: ·4).
const PX_PER_MM = 4;
const hasRange =
hatch.lengthMin != null && hatch.lengthMax != null &&
hatch.lengthMin > 0 && hatch.lengthMax >= hatch.lengthMin;
const baseLen = Math.max(3, 6 / Math.sqrt(scale));
const out: React.ReactNode[] = [];
for (let i = 0; i < count; i++) {
const cx = rnd() * w;
const cy = rnd() * h;
const ang = rnd() * Math.PI;
const lr = rnd();
const len = hasRange
? (hatch.lengthMin! + lr * (hatch.lengthMax! - hatch.lengthMin!)) * PX_PER_MM
: baseLen;
const dx = (Math.cos(ang) * len) / 2;
const dy = (Math.sin(ang) * len) / 2;
out.push(
<line
key={i}
x1={cx - dx}
y1={cy - dy}
x2={cx + dx}
y2={cy + dy}
stroke="currentColor"
strokeWidth={0.9}
strokeLinecap="round"
/>,
);
}
inner = out;
} else if (hatch.pattern === "crosshatch") {
inner = [
...parallelLines(w, h, angle, spacing, 0.8, "a"),
...parallelLines(w, h, angle + 90, spacing, 0.8, "b"),
];
} else if (hatch.pattern === "insulation") {
// Dämmung: eine gewellte Schar quer über die Box (angenähert als Zickzack).
const rows = Math.max(2, Math.round(h / Math.max(6, spacing)));
const out: React.ReactNode[] = [];
for (let r = 0; r < rows; r++) {
const y = ((r + 0.5) / rows) * h;
const amp = Math.min(h / rows / 2, 3);
const waves = Math.max(2, Math.round(w / 6));
let d = `M 0 ${y}`;
for (let i = 1; i <= waves; i++) {
const x = (i / waves) * w;
const yy = y + (i % 2 === 0 ? -amp : amp);
d += ` L ${x.toFixed(1)} ${yy.toFixed(1)}`;
}
out.push(
<path key={r} d={d} fill="none" stroke="currentColor" strokeWidth={0.8} />,
);
}
inner = out;
} else if (hatch.pattern === "custom" && hatch.motif && hatch.motif.points.length >= 2 && hatch.motif.length > 1e-6) {
// Eigenes Motiv: EINE Wiederhollänge als <pattern>-Kachel (analog zur
// Bild-Schraffur oben) — motif.x (0..length) läuft entlang der Kachel-
// Höhe (wie die Musterlinie bei diagonal/crosshatch), motif.y (Versatz
// quer) entlang der Kachelbreite. Bewusst eigenständig tesseliert (KEIN
// Import aus glPlanHatch, s. Moduldoc oben) — schematisch/px, wie der
// übrige Swatch, nicht deckungsgleich mit dem Plan-Renderer.
const PX_PER_MM = 2;
const rowSpacing = Math.max(3, 8 / Math.sqrt(scale));
const period = Math.max(4, hatch.motif.length * scale * PX_PER_MM);
const d = hatch.motif.points
.map((p, i) => {
const x = (p.y * scale * PX_PER_MM).toFixed(1);
const y = (p.x * scale * PX_PER_MM).toFixed(1);
return `${i === 0 ? "M" : "L"} ${x} ${y}`;
})
.join(" ");
inner = (
<>
<defs>
<pattern
id={patId}
patternUnits="userSpaceOnUse"
width={rowSpacing}
height={period}
patternTransform={`rotate(${angle})`}
>
<path d={d} fill="none" stroke="currentColor" strokeWidth={0.8} />
</pattern>
</defs>
<rect x={0} y={0} width={w} height={h} fill={`url(#${patId})`} />
</>
);
} else {
// "diagonal" (Default, auch "custom" ohne gesetztes Motiv): eine parallele Schar.
inner = parallelLines(w, h, angle, spacing, 0.8, "d");
// Vektor (parallel, Kreuz, Schicht-Muster, Motiv, gestreut): Kern-Generator.
inner = vectorRuns(hatch, w, h, wallAngleDeg).map((d, i) => (
<path key={i} d={d} fill="none" stroke="currentColor" strokeWidth={0.8} strokeLinejoin="round" />
));
}
return inner;
@@ -412,7 +288,7 @@ export function WallTypeSwatch({
transform={`translate(${b.bx.toFixed(2)},${b.by.toFixed(2)})`}
clipPath={`url(#${clipId}_b${i})`}
>
{b.hatch && hatchInner(b.hatch, b.bw, b.bh, `${rawId}_${i}`)}
{b.hatch && hatchInner(b.hatch, b.bw, b.bh, `${rawId}_${i}`, orientation === "wall" ? 90 : undefined)}
</g>
))}
{/* Fugen: dünne Trennlinie an jeder INNEREN Bandgrenze. */}
+6
View File
@@ -26,6 +26,12 @@ const PATTERN_OPTIONS: { value: HatchPattern; labelKey: string }[] = [
{ value: "insulation", labelKey: "pattern.insulation" },
{ value: "diagonal", labelKey: "pattern.diagonal" },
{ value: "crosshatch", labelKey: "pattern.crosshatch" },
{ value: "insulationHard", labelKey: "pattern.insulationHard" },
{ value: "insulationWave", labelKey: "pattern.insulationWave" },
{ value: "timber", labelKey: "pattern.timber" },
{ value: "stone", labelKey: "pattern.stone" },
{ value: "earth", labelKey: "pattern.earth" },
{ value: "gravel", labelKey: "pattern.gravel" },
{ value: "custom", labelKey: "pattern.custom" },
];