[K3a] Wand-Poche und Decken-Umriss im Grundriss in Rust (plan_walls.rs); TS nur noch Stil und Uebersetzung
This commit is contained in:
1 parent
63f653d1c2
commit
8c112b2bc5
7 files changed
+690
-390
No files matched your search
@@ -86,7 +86,12 @@ truck (`trucksolid`) bleibt eigenes WASM-Modul (Panic-Isolation), wird vom Kern
|
||||
(Farbe, Graustufen, Pick-ID) — kein Format-v2, bis [K3d] den Puffer direkt liefert.
|
||||
✅ Treppen: `plan_stairs.rs` (`plan_stair_flat`), `generatePlan/stairs.ts` nur noch Übersetzung; bitgleich zur
|
||||
alten TS-Fassung (49 Fälle: gerade/L/Wendel, Pfeilstil, Schnitthöhen). Nicht in der Tauri-App angesehen.
|
||||
Offen: Decken, Räume, Dächer, Stützen, 2D-Zeichnung, Kontext, Schnittlinien, Wände, Öffnungen.
|
||||
✅ Wand-Poché und Decken-Umriss: `plan_walls.rs` (Segmente zwischen Öffnungen, Gehrungsbänder, Schichtfugen,
|
||||
L-Anschlüsse, Durchgangswand-Aussparungen, Verdeckung durch Wand-Footprints). Stil (Bauteil, Schraffur, Farbe,
|
||||
Fugen-Linienstil) bleibt in TS, bis das Modell in Rust liegt [K4]; Zuordnung über den Schichtindex. Bitgleich zur
|
||||
alten Fassung (60 Zufallspläne × 3 Detailgrade, Öffnungen, Beispielprojekt, Decken mit/ohne Loch); `subtractIntervals`/
|
||||
`segmentInsideWallBand` aus TS gelöscht. Nicht in der Tauri-App angesehen.
|
||||
Offen: Öffnungssymbole, Räume, Dächer, Stützen, 2D-Zeichnung, Kontext, Schnittlinien.
|
||||
- ○ **[K3c] Schnitt und Ansicht** (`toSection`, `toElevation`, `meshSection`) im selben Puffer-Format.
|
||||
- ○ **[K3d] Aufräumen:** TS-Primitive-Erzeugung löschen, SVG/PDF/DXF-Export lesen den Puffer.
|
||||
Nachteile (bewusst): Übergang mit doppelter Datenhaltung, Format muss TS/Rust gleich bleiben
|
||||
|
||||
@@ -34,6 +34,7 @@ pub mod hatch_flat;
|
||||
pub mod plan_buf;
|
||||
pub mod gpu_compile;
|
||||
pub mod plan_stairs;
|
||||
pub mod plan_walls;
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
mod web;
|
||||
@@ -0,0 +1,527 @@
|
||||
//! Wand-Poché und Decken-Umriss im Grundriss ([K3a]): die Geometrie von `generatePlan/walls.ts`
|
||||
//! und `ceilings.ts` (Segmente zwischen Öffnungen, Gehrungsbänder, Schichtfugen, Durchgangswand-
|
||||
//! Aussparungen, Verdeckung von Decken-Umrissen durch Wand-Footprints). Stil (Bauteil, Schraffur,
|
||||
//! Farbe, Strichstärke, Linienstil der Fuge) löst TS aus dem Modell auf und ordnet ihn über den
|
||||
//! Schichtindex zu — das Modell bleibt bis [K4] in TS.
|
||||
//!
|
||||
//! Rechenreihenfolge und Zahlsemantik wie in TS (`Math.hypot` über `jsmath`, `Math.min/max` über
|
||||
//! `jsnum`), damit die Ausgabe bitgleich bleibt.
|
||||
//!
|
||||
//! ## Wand-Poché
|
||||
//! Eingabe (alles `f64`): `[sx, sy, ex, ey, dicke, refOff, grob (0|1), nurAnsicht (0|1), nSchichten,
|
||||
//! dicke × n, startCut, endCut, hatLayerCuts, (je Schicht: start, end, startSide, endSide)×n,
|
||||
//! nAussparungen, (from, to, offA, offB)×m, nLuecken, (from, to)×k]` mit einer Linie als
|
||||
//! `[vorhanden (0|1), px, py, dx, dy]`.
|
||||
//!
|
||||
//! Ausgabe `[n, Eintrag × n]` in Zeichenreihenfolge:
|
||||
//! ```text
|
||||
//! 1 polygon [1, art, schicht, nOhneStrich, kante…, x0,y0 … x3,y3]
|
||||
//! art 0 Ansichts-Umriss · 1 Sammelfläche (grob) · 2 Schichtband · 3 Wand-Umriss
|
||||
//! 2 line [2, art, schicht, ax, ay, bx, by]
|
||||
//! art 0 layer-joint-l · 1 layer-joint · 2 wall-outline
|
||||
//! ```
|
||||
//!
|
||||
//! ## Decken-Umriss
|
||||
//! Eingabe `[nRing, x, y …, nBruecken, kante…, nFootprints, (ax, ay, ux, uy, mx, my, len, half,
|
||||
//! refOff)×n]`; Ausgabe `[n, ax, ay, bx, by …]` (freie Teilstücke der Umrisskanten).
|
||||
|
||||
use crate::flat_read::Reader;
|
||||
use crate::jsmath::hypot2;
|
||||
use crate::jsnum::{max, min};
|
||||
|
||||
pub const CUTOUT_EPS: f64 = 1e-9;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
struct V {
|
||||
x: f64,
|
||||
y: f64,
|
||||
}
|
||||
|
||||
fn v(x: f64, y: f64) -> V {
|
||||
V { x, y }
|
||||
}
|
||||
fn sub(a: V, b: V) -> V {
|
||||
v(a.x - b.x, a.y - b.y)
|
||||
}
|
||||
fn add(a: V, b: V) -> V {
|
||||
v(a.x + b.x, a.y + b.y)
|
||||
}
|
||||
fn scale(a: V, s: f64) -> V {
|
||||
v(a.x * s, a.y * s)
|
||||
}
|
||||
fn dot(p: V, q: V) -> f64 {
|
||||
p.x * q.x + p.y * q.y
|
||||
}
|
||||
fn cross(p: V, q: V) -> f64 {
|
||||
p.x * q.y - p.y * q.x
|
||||
}
|
||||
fn normalize(a: V) -> V {
|
||||
let l = hypot2(a.x, a.y);
|
||||
let l = if l == 0.0 || l.is_nan() { 1.0 } else { l };
|
||||
v(a.x / l, a.y / l)
|
||||
}
|
||||
fn left_normal(a: V) -> V {
|
||||
v(-a.y, a.x)
|
||||
}
|
||||
fn along(p1: V, p2: V, d: f64) -> V {
|
||||
add(p1, scale(normalize(sub(p2, p1)), d))
|
||||
}
|
||||
fn line_intersect(a: V, da: V, b: V, db: V) -> Option<V> {
|
||||
let denom = cross(da, db);
|
||||
if denom.abs() < 1e-9 {
|
||||
return None;
|
||||
}
|
||||
let t = cross(sub(b, a), db) / denom;
|
||||
Some(add(a, scale(da, t)))
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct Line {
|
||||
point: V,
|
||||
dir: V,
|
||||
}
|
||||
|
||||
fn clipped_band(start: V, end: V, off_a: f64, off_b: f64, sc: Option<Line>, ec: Option<Line>) -> [V; 4] {
|
||||
let u = normalize(sub(end, start));
|
||||
let n = left_normal(u);
|
||||
let edge_start = |off: f64| {
|
||||
let base = add(start, scale(n, off));
|
||||
match sc {
|
||||
None => base,
|
||||
Some(c) => line_intersect(base, u, c.point, c.dir).unwrap_or(base),
|
||||
}
|
||||
};
|
||||
let edge_end = |off: f64| {
|
||||
let base = add(end, scale(n, off));
|
||||
match ec {
|
||||
None => base,
|
||||
Some(c) => line_intersect(base, u, c.point, c.dir).unwrap_or(base),
|
||||
}
|
||||
};
|
||||
[edge_start(off_a), edge_end(off_a), edge_end(off_b), edge_start(off_b)]
|
||||
}
|
||||
|
||||
/// Loch-Intervalle vom Segment `[s,e]` abziehen (wie `subtractIntervals` in TS).
|
||||
pub fn subtract_intervals(s: f64, e: f64, holes: &[(f64, f64)]) -> Vec<(f64, f64)> {
|
||||
let mut clipped: Vec<(f64, f64)> = holes
|
||||
.iter()
|
||||
.map(|&(a, b)| (max(s, min(a, b)), min(e, max(a, b))))
|
||||
.filter(|&(a, b)| b > a + CUTOUT_EPS)
|
||||
.collect();
|
||||
clipped.sort_by(|p, q| p.0.partial_cmp(&q.0).unwrap_or(std::cmp::Ordering::Equal));
|
||||
let mut parts = Vec::new();
|
||||
let mut cursor = s;
|
||||
for (a, b) in clipped {
|
||||
if a > cursor + CUTOUT_EPS {
|
||||
parts.push((cursor, a));
|
||||
}
|
||||
if b > cursor {
|
||||
cursor = b;
|
||||
}
|
||||
}
|
||||
if cursor < e - CUTOUT_EPS {
|
||||
parts.push((cursor, e));
|
||||
}
|
||||
parts
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct Footprint {
|
||||
a: V,
|
||||
u: V,
|
||||
m: V,
|
||||
len: f64,
|
||||
half: f64,
|
||||
ref_off: f64,
|
||||
}
|
||||
|
||||
fn clip_slab(f0: f64, fd: f64, lo: f64, hi: f64) -> Option<(f64, f64)> {
|
||||
if fd.abs() < 1e-12 {
|
||||
return if f0 >= lo - CUTOUT_EPS && f0 <= hi + CUTOUT_EPS { Some((0.0, 1.0)) } else { None };
|
||||
}
|
||||
let mut ta = (lo - f0) / fd;
|
||||
let mut tb = (hi - f0) / fd;
|
||||
if ta > tb {
|
||||
std::mem::swap(&mut ta, &mut tb);
|
||||
}
|
||||
Some((ta, tb))
|
||||
}
|
||||
|
||||
/// Intervall `[t0,t1] ⊆ [0,1]`, über das `pa→pb` im Wand-Footprint liegt.
|
||||
fn segment_inside(pa: V, pb: V, fp: &Footprint) -> Option<(f64, f64)> {
|
||||
let d = sub(pb, pa);
|
||||
let rel = sub(pa, fp.a);
|
||||
let su = clip_slab(dot(rel, fp.u), dot(d, fp.u), -fp.half, fp.len + fp.half)?;
|
||||
let sm = clip_slab(dot(rel, fp.m), dot(d, fp.m), fp.ref_off - fp.half, fp.ref_off + fp.half)?;
|
||||
let t0 = max(max(0.0, su.0), sm.0);
|
||||
let t1 = min(min(1.0, su.1), sm.1);
|
||||
if t1 > t0 + CUTOUT_EPS {
|
||||
Some((t0, t1))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
// ── Decken-Umriss ───────────────────────────────────────────────────────────
|
||||
|
||||
pub fn ceiling_outline(buf: &[f64]) -> Vec<f64> {
|
||||
(|| {
|
||||
let mut r = Reader::new(buf);
|
||||
let ring: Vec<V> = r.ring()?.into_iter().map(|p| v(p[0], p[1])).collect();
|
||||
let n_bridge = r.count()?;
|
||||
let mut bridge = Vec::with_capacity(n_bridge);
|
||||
for _ in 0..n_bridge {
|
||||
bridge.push(r.num()?);
|
||||
}
|
||||
let n_fp = r.count()?;
|
||||
let mut fps = Vec::with_capacity(n_fp);
|
||||
for _ in 0..n_fp {
|
||||
let a = [r.num()?, r.num()?, r.num()?, r.num()?, r.num()?, r.num()?, r.num()?, r.num()?, r.num()?];
|
||||
fps.push(Footprint { a: v(a[0], a[1]), u: v(a[2], a[3]), m: v(a[4], a[5]), len: a[6], half: a[7], ref_off: a[8] });
|
||||
}
|
||||
let n = ring.len();
|
||||
let mut lines: Vec<f64> = Vec::new();
|
||||
let mut count = 0usize;
|
||||
for i in 0..n {
|
||||
if bridge.contains(&(i as f64)) {
|
||||
continue;
|
||||
}
|
||||
let a = ring[i];
|
||||
let b = ring[(i + 1) % n];
|
||||
let holes: Vec<(f64, f64)> = fps.iter().filter_map(|fp| segment_inside(a, b, fp)).collect();
|
||||
let d = sub(b, a);
|
||||
for (t0, t1) in subtract_intervals(0.0, 1.0, &holes) {
|
||||
let p = add(a, scale(d, t0));
|
||||
let q = add(a, scale(d, t1));
|
||||
lines.extend([p.x, p.y, q.x, q.y]);
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
let mut out = vec![count as f64];
|
||||
out.extend(lines);
|
||||
Some(out)
|
||||
})()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
// ── Wand-Poché ──────────────────────────────────────────────────────────────
|
||||
|
||||
struct LayerCuts {
|
||||
start: Vec<Option<Line>>,
|
||||
end: Vec<Option<Line>>,
|
||||
start_side: Vec<Option<Line>>,
|
||||
end_side: Vec<Option<Line>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct Cutout {
|
||||
from: f64,
|
||||
to: f64,
|
||||
off_a: f64,
|
||||
off_b: f64,
|
||||
}
|
||||
|
||||
fn read_line(r: &mut Reader) -> Option<Option<Line>> {
|
||||
let has = r.num()?;
|
||||
let (px, py, dx, dy) = (r.num()?, r.num()?, r.num()?, r.num()?);
|
||||
Some(if has != 0.0 { Some(Line { point: v(px, py), dir: v(dx, dy) }) } else { None })
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Out {
|
||||
buf: Vec<f64>,
|
||||
n: usize,
|
||||
}
|
||||
|
||||
impl Out {
|
||||
fn polygon(&mut self, art: f64, layer: usize, no_stroke: &[f64], pts: &[V; 4]) {
|
||||
self.n += 1;
|
||||
self.buf.extend([1.0, art, layer as f64, no_stroke.len() as f64]);
|
||||
self.buf.extend_from_slice(no_stroke);
|
||||
for p in pts {
|
||||
self.buf.extend([p.x, p.y]);
|
||||
}
|
||||
}
|
||||
fn line(&mut self, art: f64, layer: usize, a: V, b: V) {
|
||||
self.n += 1;
|
||||
self.buf.extend([2.0, art, layer as f64, a.x, a.y, b.x, b.y]);
|
||||
}
|
||||
}
|
||||
|
||||
const ART_VIEW: f64 = 0.0;
|
||||
const ART_GROB: f64 = 1.0;
|
||||
const ART_BAND: f64 = 2.0;
|
||||
const ART_OUTLINE: f64 = 3.0;
|
||||
const LINE_JOINT_L: f64 = 0.0;
|
||||
const LINE_JOINT: f64 = 1.0;
|
||||
const LINE_OUTLINE: f64 = 2.0;
|
||||
|
||||
fn join_edges(sc: Option<Line>, ec: Option<Line>) -> Vec<f64> {
|
||||
let mut e = Vec::new();
|
||||
if ec.is_some() {
|
||||
e.push(1.0);
|
||||
}
|
||||
if sc.is_some() {
|
||||
e.push(3.0);
|
||||
}
|
||||
e
|
||||
}
|
||||
|
||||
pub fn wall_poche(buf: &[f64]) -> Vec<f64> {
|
||||
wall_poche_inner(buf).unwrap_or_default()
|
||||
}
|
||||
|
||||
fn wall_poche_inner(buf: &[f64]) -> Option<Vec<f64>> {
|
||||
let mut r = Reader::new(buf);
|
||||
let (sx, sy, ex, ey) = (r.num()?, r.num()?, r.num()?, r.num()?);
|
||||
let (total, ref_off) = (r.num()?, r.num()?);
|
||||
let grob = r.num()? != 0.0;
|
||||
let view_only = r.num()? != 0.0;
|
||||
let n_layers = r.count()?;
|
||||
let mut thick = Vec::with_capacity(n_layers);
|
||||
for _ in 0..n_layers {
|
||||
thick.push(r.num()?);
|
||||
}
|
||||
let start_cut = read_line(&mut r)?;
|
||||
let end_cut = read_line(&mut r)?;
|
||||
let has_layer_cuts = r.num()? != 0.0;
|
||||
let mut layer_cuts = None;
|
||||
if has_layer_cuts {
|
||||
let mut lc = LayerCuts { start: vec![], end: vec![], start_side: vec![], end_side: vec![] };
|
||||
for _ in 0..n_layers {
|
||||
lc.start.push(read_line(&mut r)?);
|
||||
lc.end.push(read_line(&mut r)?);
|
||||
lc.start_side.push(read_line(&mut r)?);
|
||||
lc.end_side.push(read_line(&mut r)?);
|
||||
}
|
||||
layer_cuts = Some(lc);
|
||||
}
|
||||
let n_cut = r.count()?;
|
||||
let mut span_cutouts = Vec::with_capacity(n_cut);
|
||||
for _ in 0..n_cut {
|
||||
span_cutouts.push(Cutout { from: r.num()?, to: r.num()?, off_a: r.num()?, off_b: r.num()? });
|
||||
}
|
||||
let n_gap = r.count()?;
|
||||
let mut gaps = Vec::with_capacity(n_gap);
|
||||
for _ in 0..n_gap {
|
||||
gaps.push((r.num()?, r.num()?));
|
||||
}
|
||||
if !(sx.is_finite() && sy.is_finite() && ex.is_finite() && ey.is_finite() && total.is_finite() && ref_off.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let wstart = v(sx, sy);
|
||||
let wend = v(ex, ey);
|
||||
let axis_len = hypot2(ex - sx, ey - sy);
|
||||
let mut segments: Vec<(f64, f64)> = Vec::new();
|
||||
let mut cursor = 0.0;
|
||||
for &(from, to) in &gaps {
|
||||
if from > cursor {
|
||||
segments.push((cursor, from));
|
||||
}
|
||||
cursor = max(cursor, to);
|
||||
}
|
||||
if cursor < axis_len {
|
||||
segments.push((cursor, axis_len));
|
||||
}
|
||||
|
||||
let mut o = Out::default();
|
||||
for &(s, e) in &segments {
|
||||
let p1 = along(wstart, wend, s);
|
||||
let p2 = along(wstart, wend, e);
|
||||
let sc = if s <= 1e-6 { start_cut } else { None };
|
||||
let ec = if e >= axis_len - 1e-6 { end_cut } else { None };
|
||||
|
||||
if view_only {
|
||||
o.polygon(ART_VIEW, 0, &join_edges(sc, ec), &clipped_band(p1, p2, ref_off - total / 2.0, ref_off + total / 2.0, sc, ec));
|
||||
continue;
|
||||
}
|
||||
if grob {
|
||||
o.polygon(ART_GROB, 0, &join_edges(sc, ec), &clipped_band(p1, p2, ref_off - total / 2.0, ref_off + total / 2.0, sc, ec));
|
||||
continue;
|
||||
}
|
||||
|
||||
let band_join_edges = join_edges(sc, ec);
|
||||
let seg_cutouts: Vec<Cutout> = span_cutouts
|
||||
.iter()
|
||||
.filter(|c| min(c.from, c.to) < e - CUTOUT_EPS && max(c.from, c.to) > s + CUTOUT_EPS)
|
||||
.copied()
|
||||
.collect();
|
||||
let axis_pt = |d: f64| if d == s { p1 } else if d == e { p2 } else { along(wstart, wend, d) };
|
||||
let mut off = ref_off - total / 2.0;
|
||||
for li in 0..n_layers {
|
||||
let layer_start_cut = if s <= 1e-6 {
|
||||
match &layer_cuts {
|
||||
Some(lc) => lc.start[li],
|
||||
None => sc,
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let layer_end_cut = if e >= axis_len - 1e-6 {
|
||||
match &layer_cuts {
|
||||
Some(lc) => lc.end[li],
|
||||
None => ec,
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let band_lo = off;
|
||||
let band_hi = off + thick[li];
|
||||
let mut band_holes: Vec<(f64, f64)> = Vec::new();
|
||||
for c in &seg_cutouts {
|
||||
let c_lo = min(c.off_a, c.off_b);
|
||||
let c_hi = max(c.off_a, c.off_b);
|
||||
if band_lo < c_hi - CUTOUT_EPS && band_hi > c_lo + CUTOUT_EPS {
|
||||
band_holes.push((c.from, c.to));
|
||||
}
|
||||
}
|
||||
for (a, b) in subtract_intervals(s, e, &band_holes) {
|
||||
let bsc = if a <= s + CUTOUT_EPS { layer_start_cut } else { None };
|
||||
let bec = if b >= e - CUTOUT_EPS { layer_end_cut } else { None };
|
||||
o.polygon(ART_BAND, li, &band_join_edges, &clipped_band(axis_pt(a), axis_pt(b), off, off + thick[li], bsc, bec));
|
||||
}
|
||||
let side_start = if s <= 1e-6 { layer_cuts.as_ref().and_then(|lc| lc.start_side[li]) } else { None };
|
||||
let side_end = if e >= axis_len - 1e-6 { layer_cuts.as_ref().and_then(|lc| lc.end_side[li]) } else { None };
|
||||
if side_start.is_some() || side_end.is_some() {
|
||||
let u_seg = normalize(sub(p2, p1));
|
||||
let n_seg = left_normal(u_seg);
|
||||
let side_point = |base: V, layer_off: f64, cut: Line| {
|
||||
let pt = add(base, scale(n_seg, layer_off));
|
||||
line_intersect(pt, u_seg, cut.point, cut.dir).unwrap_or(pt)
|
||||
};
|
||||
if let Some(c) = side_start {
|
||||
o.line(LINE_JOINT_L, li, side_point(p1, off, c), side_point(p1, off + thick[li], c));
|
||||
}
|
||||
if let Some(c) = side_end {
|
||||
o.line(LINE_JOINT_L, li, side_point(p2, off, c), side_point(p2, off + thick[li], c));
|
||||
}
|
||||
}
|
||||
off += thick[li];
|
||||
if li + 1 < n_layers {
|
||||
let mut fuge_holes: Vec<(f64, f64)> = Vec::new();
|
||||
for c in &seg_cutouts {
|
||||
let c_lo = min(c.off_a, c.off_b);
|
||||
let c_hi = max(c.off_a, c.off_b);
|
||||
if off >= c_lo - CUTOUT_EPS && off <= c_hi + CUTOUT_EPS {
|
||||
fuge_holes.push((c.from, c.to));
|
||||
}
|
||||
}
|
||||
for (a, b) in subtract_intervals(s, e, &fuge_holes) {
|
||||
let jsc = if a <= s + CUTOUT_EPS { sc } else { None };
|
||||
let jec = if b >= e - CUTOUT_EPS { ec } else { None };
|
||||
let jq = clipped_band(axis_pt(a), axis_pt(b), off, off, jsc, jec);
|
||||
o.line(LINE_JOINT, li, jq[0], jq[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let off_lo = ref_off - total / 2.0;
|
||||
let off_hi = ref_off + total / 2.0;
|
||||
let mut holes_hi: Vec<(f64, f64)> = Vec::new();
|
||||
let mut holes_lo: Vec<(f64, f64)> = Vec::new();
|
||||
for c in &seg_cutouts {
|
||||
if (c.off_a - off_hi).abs() < 1e-6 {
|
||||
holes_hi.push((c.from, c.to));
|
||||
} else if (c.off_a - off_lo).abs() < 1e-6 {
|
||||
holes_lo.push((c.from, c.to));
|
||||
}
|
||||
}
|
||||
let mut outline_no_stroke = band_join_edges.clone();
|
||||
if !holes_hi.is_empty() {
|
||||
outline_no_stroke.push(2.0);
|
||||
}
|
||||
if !holes_lo.is_empty() {
|
||||
outline_no_stroke.push(0.0);
|
||||
}
|
||||
o.polygon(ART_OUTLINE, 0, &outline_no_stroke, &clipped_band(p1, p2, off_lo, off_hi, sc, ec));
|
||||
let mut near_edge = |edge_off: f64, holes: &[(f64, f64)]| {
|
||||
for (a, b) in subtract_intervals(s, e, holes) {
|
||||
let nsc = if a <= s + CUTOUT_EPS { sc } else { None };
|
||||
let nec = if b >= e - CUTOUT_EPS { ec } else { None };
|
||||
let jq = clipped_band(axis_pt(a), axis_pt(b), edge_off, edge_off, nsc, nec);
|
||||
o.line(LINE_OUTLINE, 0, jq[0], jq[1]);
|
||||
}
|
||||
};
|
||||
if !holes_hi.is_empty() {
|
||||
near_edge(off_hi, &holes_hi);
|
||||
}
|
||||
if !holes_lo.is_empty() {
|
||||
near_edge(off_lo, &holes_lo);
|
||||
}
|
||||
}
|
||||
let mut out = Vec::with_capacity(o.buf.len() + 1);
|
||||
out.push(o.n as f64);
|
||||
out.extend(o.buf);
|
||||
Some(out)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const NO_LINE: [f64; 5] = [0.0; 5];
|
||||
|
||||
fn wall(len: f64, grob: bool, gaps: &[(f64, f64)]) -> Vec<f64> {
|
||||
let mut b = vec![0.0, 0.0, len, 0.0, 0.3, 0.0, grob as u8 as f64, 0.0, 2.0, 0.1, 0.2];
|
||||
b.extend(NO_LINE);
|
||||
b.extend(NO_LINE);
|
||||
b.extend([0.0, 0.0, gaps.len() as f64]);
|
||||
for g in gaps {
|
||||
b.extend([g.0, g.1]);
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
fn count(out: &[f64], tag: f64) -> usize {
|
||||
let (mut i, mut n) = (1, 0);
|
||||
for _ in 0..out[0] as usize {
|
||||
let t = out[i];
|
||||
if t == tag {
|
||||
n += 1;
|
||||
}
|
||||
i += if t == 1.0 { 4 + out[i + 3] as usize + 8 } else { 7 };
|
||||
}
|
||||
assert_eq!(i, out.len());
|
||||
n
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intervalle_abziehen() {
|
||||
assert_eq!(subtract_intervals(0.0, 5.0, &[]), vec![(0.0, 5.0)]);
|
||||
assert_eq!(subtract_intervals(0.0, 5.0, &[(1.0, 2.0), (1.5, 3.0)]), vec![(0.0, 1.0), (3.0, 5.0)]);
|
||||
assert!(subtract_intervals(0.0, 5.0, &[(-1.0, 9.0)]).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wand_ohne_luecke_hat_zwei_baender_fuge_und_umriss() {
|
||||
let o = wall_poche(&wall(4.0, false, &[]));
|
||||
assert_eq!(count(&o, 1.0), 3); // 2 Bänder + Umriss
|
||||
assert_eq!(count(&o, 2.0), 1); // 1 Fuge
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn luecke_teilt_die_wand_in_zwei_segmente() {
|
||||
let o = wall_poche(&wall(4.0, false, &[(1.0, 2.0)]));
|
||||
assert_eq!(count(&o, 1.0), 6);
|
||||
assert_eq!(count(&wall_poche(&wall(4.0, true, &[(1.0, 2.0)])), 1.0), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsinn_ohne_panic() {
|
||||
assert!(wall_poche(&[1.0, 2.0]).is_empty());
|
||||
let mut b = wall(4.0, false, &[]);
|
||||
b[0] = f64::NAN;
|
||||
assert!(wall_poche(&b).is_empty());
|
||||
assert!(ceiling_outline(&[3.0, 0.0]).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decken_umriss_wird_von_wand_verdeckt() {
|
||||
// Quadrat 4×4, Wand entlang der unteren Kante (Mitte y=0, Dicke 0.4)
|
||||
let mut b = vec![4.0, 0.0, 0.0, 4.0, 0.0, 4.0, 4.0, 0.0, 4.0, 0.0, 1.0];
|
||||
b.extend([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 4.0, 0.2, 0.0]);
|
||||
let o = ceiling_outline(&b);
|
||||
assert_eq!(o[0], 3.0); // untere Kante entfällt, drei freie Kanten
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ mod wall_mesh_cut;
|
||||
mod plan_buf;
|
||||
mod gpu_compile;
|
||||
mod plan_stairs;
|
||||
mod plan_walls;
|
||||
mod hatch;
|
||||
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//! Bindungen von Wand-Poché und Decken-Umriss im Grundriss (`crate::plan_walls`). Layout s. dort.
|
||||
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
/// Wand-Poché-Geometrie einer Wand; Unsinn → leer.
|
||||
#[wasm_bindgen]
|
||||
pub fn plan_wall_poche_flat(buf: &[f64]) -> Vec<f64> {
|
||||
crate::plan_walls::wall_poche(buf)
|
||||
}
|
||||
|
||||
/// Freie Teilstücke eines Decken-Umrisses gegen Wand-Footprints; Unsinn → leer.
|
||||
#[wasm_bindgen]
|
||||
pub fn plan_ceiling_outline_flat(buf: &[f64]) -> Vec<f64> {
|
||||
crate::plan_walls::ceiling_outline(buf)
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
import type { Ceiling, LayerCategory, Project } from "../../model/types";
|
||||
import { getCeilingType, getComponent } from "../../model/types";
|
||||
import { mergeHoles } from "../../geometry/polygonHoles";
|
||||
import { add, scale, sub } from "../../model/geometry";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import {
|
||||
NO_HATCH,
|
||||
OVERHEAD_DASH,
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
type DetailLevel,
|
||||
type Primitive,
|
||||
} from "./shared";
|
||||
import { segmentInsideWallBand, subtractIntervals, type WallFootprint } from "./walls";
|
||||
import type { WallFootprint } from "./walls";
|
||||
|
||||
/**
|
||||
* Decken-Poché im Grundriss: die Decke liegt als Slab ÜBER der Schnittebene und
|
||||
@@ -116,32 +116,25 @@ export function addCeilingPoche(
|
||||
// der Umriss ganz; nur Überstände (Vordach/Balkon jenseits der Wand)
|
||||
// bleiben sichtbar. Brückenkanten (künstliche Verbindung Aussenring↔Loch)
|
||||
// werden NICHT gestrichen.
|
||||
const n = ring.length;
|
||||
const bridgeSet = new Set(bridgeEdges);
|
||||
for (let i = 0; i < n; i++) {
|
||||
if (bridgeSet.has(i)) continue;
|
||||
const a = ring[i];
|
||||
const b = ring[(i + 1) % n];
|
||||
const holes: Array<[number, number]> = [];
|
||||
for (const fp of wallFootprints) {
|
||||
const iv = segmentInsideWallBand(a, b, fp);
|
||||
if (iv) holes.push(iv);
|
||||
}
|
||||
const d = sub(b, a);
|
||||
for (const [t0, t1] of subtractIntervals(0, 1, holes)) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: add(a, scale(d, t0)),
|
||||
b: add(a, scale(d, t1)),
|
||||
cls: "ceiling-outline",
|
||||
// Überkopf-Ansichtslinie (Decke liegt als Slab über der Schnittebene) →
|
||||
// gestrichelt statt durchgezogen (BIM-Konvention) — die DICKE folgt
|
||||
// aber ceiling.strokeWeight/-Source wie bei der Wand (s. Aufrufer).
|
||||
weightMm: lwMm * LAYER_DETAIL_FACTOR[detail],
|
||||
dash: OVERHEAD_DASH,
|
||||
color: stroke,
|
||||
greyed,
|
||||
});
|
||||
}
|
||||
// Die freien Teilstücke berechnet der Kern (`plan_walls.rs`, [K3a]).
|
||||
const buf: number[] = [ring.length];
|
||||
for (const p of ring) buf.push(p.x, p.y);
|
||||
buf.push(bridgeEdges.length, ...bridgeEdges, wallFootprints.length);
|
||||
for (const fp of wallFootprints) buf.push(fp.a.x, fp.a.y, fp.u.x, fp.u.y, fp.m.x, fp.m.y, fp.len, fp.half, fp.refOff);
|
||||
const f = core().plan_ceiling_outline_flat(Float64Array.from(buf));
|
||||
for (let i = 0; i < f[0]; i++) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: { x: f[1 + 4 * i], y: f[2 + 4 * i] },
|
||||
b: { x: f[3 + 4 * i], y: f[4 + 4 * i] },
|
||||
cls: "ceiling-outline",
|
||||
// Überkopf-Ansichtslinie (Decke liegt als Slab über der Schnittebene) →
|
||||
// gestrichelt statt durchgezogen (BIM-Konvention) — die DICKE folgt
|
||||
// aber ceiling.strokeWeight/-Source wie bei der Wand (s. Aufrufer).
|
||||
weightMm: lwMm * LAYER_DETAIL_FACTOR[detail],
|
||||
dash: OVERHEAD_DASH,
|
||||
color: stroke,
|
||||
greyed,
|
||||
});
|
||||
}
|
||||
}
|
||||
+118
-360
@@ -2,24 +2,19 @@
|
||||
// die Wand-Footprints (für das Verdecken darunterliegender Decken-Umrisse, s.
|
||||
// {@link ../ceilings}) und die eigentliche Wand-Poché (Schichten + Umriss +
|
||||
// Öffnungsaussparungen + T-Stoss-/Gehrungs-Behandlung).
|
||||
//
|
||||
// Die Geometrie der Poché entsteht im Rust-Kern (`src-tauri/core/src/plan_walls.rs`, [K3a]); hier
|
||||
// bleibt die Stilauflösung aus dem Modell (Bauteil, Schraffur, Farbe, Fugen-Linienstil) und die
|
||||
// Übersetzung in `Primitive`-Objekte. Fällt mit [K3d] weg.
|
||||
|
||||
import type { LayerCategory, Opening, Project, Vec2, Wall } from "../../model/types";
|
||||
import { getComponent, getWallType, wallTypeThickness } from "../../model/types";
|
||||
import { wallReferenceOffset } from "../../model/wall";
|
||||
import { openingInterval } from "../../geometry/opening";
|
||||
import {
|
||||
add,
|
||||
along,
|
||||
clippedBand,
|
||||
dot,
|
||||
leftNormal,
|
||||
lineIntersect,
|
||||
normalize,
|
||||
scale,
|
||||
sub,
|
||||
} from "../../model/geometry";
|
||||
import { leftNormal, normalize, sub } from "../../model/geometry";
|
||||
import type { Line } from "../../model/geometry";
|
||||
import type { WallCuts } from "../../model/joins";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import {
|
||||
HATCH_INK,
|
||||
HATCH_PAPER,
|
||||
@@ -33,6 +28,7 @@ import {
|
||||
resolveHatch,
|
||||
resolveHatchId,
|
||||
type DetailLevel,
|
||||
type HatchRender,
|
||||
type Primitive,
|
||||
} from "./shared";
|
||||
|
||||
@@ -61,38 +57,6 @@ export function wallGaps(
|
||||
return gaps.sort((a, b) => a.from - b.from);
|
||||
}
|
||||
|
||||
/** Toleranz für die Achsen-Intervall-Arithmetik der Durchgangswand-Aussparungen. */
|
||||
export const CUTOUT_EPS = 1e-9;
|
||||
|
||||
/**
|
||||
* Zieht die Loch-Intervalle `holes` vom Segment `[s,e]` ab und liefert die
|
||||
* verbleibenden (gezeichneten) Teil-Intervalle in Achsen-Metern. Löcher werden
|
||||
* auf `[s,e]` geklemmt, sortiert und vereinigt; leeres Ergebnis heisst „ganz
|
||||
* ausgespart". Ist `holes` leer, kommt exakt `[[s,e]]` zurück (unverändertes
|
||||
* Verhalten für Wände ohne Aussparung).
|
||||
*/
|
||||
export function subtractIntervals(
|
||||
s: number,
|
||||
e: number,
|
||||
holes: Array<[number, number]>,
|
||||
): Array<[number, number]> {
|
||||
const clipped = holes
|
||||
.map(([a, b]): [number, number] => [
|
||||
Math.max(s, Math.min(a, b)),
|
||||
Math.min(e, Math.max(a, b)),
|
||||
])
|
||||
.filter(([a, b]) => b > a + CUTOUT_EPS)
|
||||
.sort((p, q) => p[0] - q[0]);
|
||||
const parts: Array<[number, number]> = [];
|
||||
let cursor = s;
|
||||
for (const [a, b] of clipped) {
|
||||
if (a > cursor + CUTOUT_EPS) parts.push([cursor, a]);
|
||||
if (b > cursor) cursor = b;
|
||||
}
|
||||
if (cursor < e - CUTOUT_EPS) parts.push([cursor, e]);
|
||||
return parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wand-Footprint als orientiertes Rechteck (OBB) für das Verdecken der
|
||||
* darunterliegenden Decke im Grundriss: Achs-Startpunkt + Einheits-Richtung `u`
|
||||
@@ -133,49 +97,37 @@ export function buildWallFootprints(project: Project, walls: Wall[]): WallFootpr
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parametrisches Intervall [t0,t1] ⊆ [0,1], über das die Strecke `pa→pb`
|
||||
* INNERHALB des Wand-Footprints liegt (also von der Wand verdeckt). `null`, wenn
|
||||
* die Strecke den Footprint nicht schneidet. OBB-Test über zwei Slabs: Projektion
|
||||
* auf die Achse `u` (Bereich [−half, len+half]) und auf die Normale `m` (Bereich
|
||||
* [refOff−half, refOff+half]); das Schnitt-Intervall beider Slabs ∩ [0,1] ist die
|
||||
* verdeckte Strecke.
|
||||
*/
|
||||
export function segmentInsideWallBand(
|
||||
pa: Vec2,
|
||||
pb: Vec2,
|
||||
fp: WallFootprint,
|
||||
): [number, number] | null {
|
||||
const d = sub(pb, pa);
|
||||
const rel = sub(pa, fp.a);
|
||||
const clipSlab = (
|
||||
f0: number,
|
||||
fd: number,
|
||||
lo: number,
|
||||
hi: number,
|
||||
): [number, number] | null => {
|
||||
if (Math.abs(fd) < 1e-12)
|
||||
return f0 >= lo - CUTOUT_EPS && f0 <= hi + CUTOUT_EPS ? [0, 1] : null;
|
||||
let ta = (lo - f0) / fd;
|
||||
let tb = (hi - f0) / fd;
|
||||
if (ta > tb) [ta, tb] = [tb, ta];
|
||||
return [ta, tb];
|
||||
};
|
||||
const su = clipSlab(dot(rel, fp.u), dot(d, fp.u), -fp.half, fp.len + fp.half);
|
||||
if (!su) return null;
|
||||
const sm = clipSlab(
|
||||
dot(rel, fp.m),
|
||||
dot(d, fp.m),
|
||||
fp.refOff - fp.half,
|
||||
fp.refOff + fp.half,
|
||||
);
|
||||
if (!sm) return null;
|
||||
const t0 = Math.max(0, su[0], sm[0]);
|
||||
const t1 = Math.min(1, su[1], sm[1]);
|
||||
return t1 > t0 + CUTOUT_EPS ? [t0, t1] : null;
|
||||
}
|
||||
const lineBuf = (l: Line | null | undefined): number[] =>
|
||||
l ? [1, l.point.x, l.point.y, l.dir.x, l.dir.y] : [0, 0, 0, 0, 0];
|
||||
|
||||
const length = (w: Wall): number => Math.hypot(w.end.x - w.start.x, w.end.y - w.start.y);
|
||||
/** Eingabe der Kern-Funktion `plan_wall_poche_flat` (Aufbau: `plan_walls.rs`). */
|
||||
function encodeWallPoche(
|
||||
wall: Wall,
|
||||
layerThickness: number[],
|
||||
total: number,
|
||||
refOff: number,
|
||||
gaps: WallGap[],
|
||||
cuts: WallCuts,
|
||||
grob: boolean,
|
||||
viewOnly: boolean,
|
||||
): Float64Array {
|
||||
const b: number[] = [wall.start.x, wall.start.y, wall.end.x, wall.end.y, total, refOff, grob ? 1 : 0, viewOnly ? 1 : 0];
|
||||
b.push(layerThickness.length, ...layerThickness);
|
||||
b.push(...lineBuf(cuts.startCut), ...lineBuf(cuts.endCut));
|
||||
const lc = cuts.layerCuts;
|
||||
b.push(lc ? 1 : 0);
|
||||
if (lc) {
|
||||
for (let i = 0; i < layerThickness.length; i++) {
|
||||
b.push(...lineBuf(lc.start[i]), ...lineBuf(lc.end[i]), ...lineBuf(lc.startSide[i]), ...lineBuf(lc.endSide[i]));
|
||||
}
|
||||
}
|
||||
const sc = cuts.spanCutouts ?? [];
|
||||
b.push(sc.length);
|
||||
for (const c of sc) b.push(c.from, c.to, c.offA, c.offB);
|
||||
b.push(gaps.length);
|
||||
for (const g of gaps) b.push(g.from, g.to);
|
||||
return Float64Array.from(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wand als gefüllte Schnittfläche (Poché), um Öffnungen ausgespart.
|
||||
@@ -188,6 +140,9 @@ const length = (w: Wall): number => Math.hypot(w.end.x - w.start.x, w.end.y - w.
|
||||
* volle Wanddicke (Füllung = Farbe des „Backbone"-Bauteils mit höchster
|
||||
* joinPriority) mit dicker Umrisslinie. Bewusst vereinfacht (≙ DOSSIER
|
||||
* „Einfach").
|
||||
*
|
||||
* Segmente, Gehrungsbänder, Schichtfugen und Durchgangswand-Aussparungen berechnet der Kern;
|
||||
* hier kommen nur Stil und Pick-ID (`wallId`) dazu.
|
||||
*/
|
||||
export function addWallPoche(
|
||||
out: Primitive[],
|
||||
@@ -206,311 +161,114 @@ export function addWallPoche(
|
||||
): void {
|
||||
const wt = getWallType(project, wall);
|
||||
const total = wallTypeThickness(wt);
|
||||
// Versatz der Schichtstapelung über die Dicke gemäß Referenzlinie (center=0,
|
||||
// left=+T/2, right=−T/2). Alle Band-Offsets unten werden hierum verschoben,
|
||||
// sodass die Achse bei „außen"/„innen" auf der jeweiligen Wandfläche liegt.
|
||||
const refOff = wallReferenceOffset(wall, total);
|
||||
// Jede Schicht-/Umrissfläche trägt die Wand-ID, damit ein Links-Klick die
|
||||
// GANZE Wand (alle Bänder) markiert und die PlanView die wallId nach oben
|
||||
// melden kann.
|
||||
const wallId = wall.id;
|
||||
// Achswinkel der Wand (Modell, Grad) — treibt wandbezogene Schraffuren
|
||||
// ({@link resolveHatch}), damit z. B. eine Diagonale oder die Dämmungsstriche
|
||||
// mit der Wandorientierung mitdrehen.
|
||||
// Achswinkel der Wand (Modell, Grad) — treibt wandbezogene Schraffuren ({@link resolveHatch}).
|
||||
const wallAngleDeg =
|
||||
(Math.atan2(wall.end.y - wall.start.y, wall.end.x - wall.start.x) * 180) / Math.PI;
|
||||
// Strich-/Umrandungsfarbe der Wand: optionale Übersteuerung (wall.color),
|
||||
// sonst der Default-Poché-Strich. Betrifft NUR die Linienfarbe (Umriss +
|
||||
// Schichtfugen), nicht die Schicht-Füllfarben/Schraffuren.
|
||||
// Strich-/Umrandungsfarbe der Wand: optionale Übersteuerung (wall.color), sonst der
|
||||
// Default-Poché-Strich. Betrifft NUR die Linienfarbe, nicht die Schicht-Füllfarben/Schraffuren.
|
||||
const stroke = wall.color ?? POCHE_STROKE;
|
||||
|
||||
// Öffnungs-Intervalle entlang der Wandachse, sortiert (bereits vereint).
|
||||
const openings = gaps;
|
||||
|
||||
// Wand in Segmente zwischen den Öffnungen zerlegen.
|
||||
let cursor = 0;
|
||||
const segments: Array<[number, number]> = [];
|
||||
for (const op of openings) {
|
||||
if (op.from > cursor) segments.push([cursor, op.from]);
|
||||
cursor = Math.max(cursor, op.to);
|
||||
}
|
||||
const axisLen = length(wall);
|
||||
if (cursor < axisLen) segments.push([cursor, axisLen]);
|
||||
|
||||
const outlineMm = wallLwMm * OUTLINE_DETAIL_FACTOR[detail];
|
||||
const layerLineMm = LAYER_LINE_MM * LAYER_DETAIL_FACTOR[detail];
|
||||
// Vereinfachte Füllung (grob): immer schwarze Vollfüllung, keine Schraffur
|
||||
|
||||
// Durchgangswand-Aussparungen (Phase 1c): über diese Achsen-Intervalle × Quer-
|
||||
// Offsetbereiche wird die Nah-Putz-Zone der Durchgangswand echt ausgeschnitten
|
||||
// (der Abzweig-Kern sticht durch). `offA` ist stets die Nahfläche, `offB` die
|
||||
// Rückgrat-Nahfläche (siehe SpanCutout in model/joins.ts). Leer ⇒ heutiges
|
||||
// Verhalten (Wand ohne T-Durchstoss).
|
||||
const spanCutouts = cuts.spanCutouts ?? [];
|
||||
const f = core().plan_wall_poche_flat(
|
||||
encodeWallPoche(wall, wt.layers.map((l) => l.thickness), total, refOff, gaps, cuts, detail === "grob", viewOnly),
|
||||
);
|
||||
if (f.length === 0) return;
|
||||
|
||||
// Kanten-Indizes der inneren Gehrungs-Stirnflächen (die Diagonalen am Knoten).
|
||||
// clippedBand liefert [A.start, A.end, B.end, B.start] → Kante 1 (A.end→B.end)
|
||||
// ist die endCut-Stirnfläche, Kante 3 (B.start→A.start) die startCut-Stirnfläche.
|
||||
// Diese werden NICHT umrissen: sonst 45°-Naht zwischen gleichfarbigen Schichten
|
||||
// + überschießende Gehrungs-Barbe am Eck-Apex. Freie Enden (kein Cut) bleiben
|
||||
// rechtwinklig gestrichen. Die Längskanten (Schichtfugen) bleiben stets sichtbar.
|
||||
const joinEdges = (startCut: Line | null, endCut: Line | null): number[] => {
|
||||
const e: number[] = [];
|
||||
if (endCut) e.push(1);
|
||||
if (startCut) e.push(3);
|
||||
return e;
|
||||
};
|
||||
|
||||
for (const [s, e] of segments) {
|
||||
const p1 = along(wall.start, wall.end, s);
|
||||
const p2 = along(wall.start, wall.end, e);
|
||||
// Nur die echten Wandenden bekommen die Gehrung. Türnahe Segmentenden
|
||||
// bleiben rechtwinklig (kein Schnitt).
|
||||
const startCut = s <= 1e-6 ? cuts.startCut : null;
|
||||
const endCut = e >= axisLen - 1e-6 ? cuts.endCut : null;
|
||||
|
||||
if (viewOnly) {
|
||||
// Ansichts-Wand (unter der Schnittebene): ein Umriss über die volle Dicke
|
||||
// als Haarlinie, ohne Füllung/Schraffur. Segment-/Gehrungs-/Öffnungs-Logik
|
||||
// bleibt dieselbe wie im Schnittfall (nur eben ohne Poché).
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: clippedBand(p1, p2, refOff - total / 2, refOff + total / 2, startCut, endCut),
|
||||
fill: "none",
|
||||
stroke,
|
||||
strokeWidthMm: layerLineMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
noStrokeEdges: joinEdges(startCut, endCut),
|
||||
wallId,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
if (detail === "grob") {
|
||||
// Eine Sammelfläche über die volle Dicke, ohne Schraffur, dicker Umriss.
|
||||
// Bei grob: immer Vollschwarz-Füllung gemäß SIA 400 Anhang B.9, Figur 36
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: clippedBand(p1, p2, refOff - total / 2, refOff + total / 2, startCut, endCut),
|
||||
fill: HATCH_INK,
|
||||
stroke,
|
||||
strokeWidthMm: outlineMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
noStrokeEdges: joinEdges(startCut, endCut),
|
||||
wallId,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
// mittel/fein: Schichten von außen (-T/2) nach innen (+T/2) stapeln. Jede
|
||||
// Schicht löst Bauteil (Füllfarbe) + Schraffur (Muster/Maßstab/Winkel/Farbe)
|
||||
// auf. Die Bänder tragen NUR Füllung + Schraffur (kein eigener Umriss); jede
|
||||
// innere Schichtfuge wird als EIGENSTÄNDIGE, stilisierbare Linie gezeichnet.
|
||||
const bandJoinEdges = joinEdges(startCut, endCut);
|
||||
// Nur die Aussparungen, die dieses Segment [s,e] entlang der Achse berühren.
|
||||
const segCutouts = spanCutouts.filter(
|
||||
(c) =>
|
||||
Math.min(c.from, c.to) < e - CUTOUT_EPS &&
|
||||
Math.max(c.from, c.to) > s + CUTOUT_EPS,
|
||||
);
|
||||
// Punkt entlang der Wandachse bei Achsen-Meter `d` (p1/p2 an den Rändern).
|
||||
const axisPt = (d: number): Vec2 =>
|
||||
d === s ? p1 : d === e ? p2 : along(wall.start, wall.end, d);
|
||||
// Materialbewusster T-Stoss (siehe resolveJoinPriority in model/joins.ts):
|
||||
// liegt eine Pro-Schicht-Cut-Überschreibung vor, ersetzt sie PRO SCHICHT den
|
||||
// einheitlichen startCut/endCut — nur an den echten Wandenden (dieselbe
|
||||
// Maskierung wie oben für startCut/endCut, s <= 1e-6 / e >= axisLen-1e-6).
|
||||
// Fehlt sie, bleibt alles wie zuvor (startCut/endCut für jede Schicht).
|
||||
const layerCuts = cuts.layerCuts;
|
||||
let off = refOff - total / 2;
|
||||
for (let li = 0; li < wt.layers.length; li++) {
|
||||
const layer = wt.layers[li];
|
||||
const comp = getComponent(project, layer.componentId);
|
||||
// Stil je Schicht erst beim ersten Band lösen (wie zuvor: nur wenn die Wand Segmente hat).
|
||||
const layerStyle = new Map<number, { hatch: HatchRender; fill: string }>();
|
||||
const styleOf = (li: number) => {
|
||||
let st = layerStyle.get(li);
|
||||
if (!st) {
|
||||
const comp = getComponent(project, wt.layers[li].componentId);
|
||||
const layerHatchId =
|
||||
resolveHatchId(wall.hatchId, wall.hatchSource, category, comp.hatchId) ?? comp.hatchId;
|
||||
const layerHatch = resolveHatch(
|
||||
const hatch = resolveHatch(
|
||||
project,
|
||||
layerHatchId,
|
||||
wallAngleDeg,
|
||||
resolveForeground(comp, wall.foreground, category, wall.foregroundSource),
|
||||
);
|
||||
// SIA-Poché: neutraler Hintergrund (Papier) statt Bauteil-Albedo, die
|
||||
// Schichtschraffur (fest in HATCH_INK, siehe resolveHatch) liegt darüber;
|
||||
// Vollmuster ("solid") = Tinten-Poché.
|
||||
const layerSolid = layerHatch.pattern === "solid";
|
||||
// SIA-Poché: neutraler Hintergrund (Papier) statt Bauteil-Albedo, die Schichtschraffur
|
||||
// (fest in HATCH_INK, siehe resolveHatch) liegt darüber; Vollmuster ("solid") = Tinten-Poché.
|
||||
const bgOverride = resolveBackground(comp, wall.background, category, wall.backgroundSource);
|
||||
const layerStartCut = s <= 1e-6 ? (layerCuts ? layerCuts.start[li] : startCut) : null;
|
||||
const layerEndCut = e >= axisLen - 1e-6 ? (layerCuts ? layerCuts.end[li] : endCut) : null;
|
||||
// Durchgangswand-Aussparung: liegt der Quer-Offsetbereich dieses Bandes
|
||||
// [off, off+thickness] im Nah-Putz-Bereich einer Aussparung, wird das Band
|
||||
// entlang der Achse in Teil-Bänder VOR/NACH dem Intervall zerlegt (das
|
||||
// Durchstoss-Stück entfällt). Ohne Überlappung bleibt genau ein Band
|
||||
// [s,e] (unverändertes Verhalten).
|
||||
const bandLo = off;
|
||||
const bandHi = off + layer.thickness;
|
||||
const bandHoles: Array<[number, number]> = [];
|
||||
for (const c of segCutouts) {
|
||||
const cLo = Math.min(c.offA, c.offB);
|
||||
const cHi = Math.max(c.offA, c.offB);
|
||||
if (bandLo < cHi - CUTOUT_EPS && bandHi > cLo + CUTOUT_EPS)
|
||||
bandHoles.push([c.from, c.to]);
|
||||
}
|
||||
for (const [a, b] of subtractIntervals(s, e, bandHoles)) {
|
||||
const sc = a <= s + CUTOUT_EPS ? layerStartCut : null;
|
||||
const ec = b >= e - CUTOUT_EPS ? layerEndCut : null;
|
||||
st = { hatch, fill: bgOverride ?? (hatch.pattern === "solid" ? HATCH_INK : HATCH_PAPER) };
|
||||
layerStyle.set(li, st);
|
||||
}
|
||||
return st;
|
||||
};
|
||||
|
||||
const n = f[0];
|
||||
let i = 1;
|
||||
for (let k = 0; k < n; k++) {
|
||||
if (f[i] === 1) {
|
||||
const art = f[i + 1];
|
||||
const li = f[i + 2];
|
||||
const nNo = f[i + 3];
|
||||
const noStrokeEdges = Array.from(f.subarray(i + 4, i + 4 + nNo));
|
||||
const q = i + 4 + nNo;
|
||||
const pts = [0, 1, 2, 3].map((j) => ({ x: f[q + 2 * j], y: f[q + 2 * j + 1] }));
|
||||
i = q + 8;
|
||||
if (art === 2) {
|
||||
const st = styleOf(li);
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: clippedBand(axisPt(a), axisPt(b), off, off + layer.thickness, sc, ec),
|
||||
fill: bgOverride ?? (layerSolid ? HATCH_INK : HATCH_PAPER),
|
||||
// Band ohne Umriss: keine Schichtfuge über die Bandkante, keine 45°-Naht
|
||||
// am Knoten. Die Fugen kommen als separate `line`-Primitive (siehe unten).
|
||||
pts,
|
||||
fill: st.fill,
|
||||
// Band ohne Umriss: keine Schichtfuge über die Bandkante, keine 45°-Naht am Knoten.
|
||||
// Die Fugen kommen als separate `line`-Primitive.
|
||||
stroke: "none",
|
||||
strokeWidthMm: 0,
|
||||
hatch: layerHatch,
|
||||
hatch: st.hatch,
|
||||
greyed,
|
||||
// Für die Ecktests/Konsistenz beibehalten (bei stroke:"none" wirkungslos).
|
||||
noStrokeEdges: bandJoinEdges,
|
||||
noStrokeEdges,
|
||||
wallId,
|
||||
});
|
||||
} else {
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts,
|
||||
// Grob: immer Vollschwarz-Füllung gemäss SIA 400 Anhang B.9, Figur 36.
|
||||
fill: art === 1 ? HATCH_INK : "none",
|
||||
stroke,
|
||||
strokeWidthMm: art === 0 ? layerLineMm : outlineMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
noStrokeEdges,
|
||||
wallId,
|
||||
});
|
||||
}
|
||||
// L-Anschluss: eine getrimmte Schicht (z. B. Putz), die an eine
|
||||
// verschmelzende Nachbarschicht (durchlaufender Kern) grenzt, bekommt
|
||||
// zusätzlich eine seitliche Cut-Linie entlang der Durchgangsachse — sie
|
||||
// begrenzt die Schichtbreite dort, wo der Kern sie unterbricht (L-Form).
|
||||
const sideStart = s <= 1e-6 ? layerCuts?.startSide[li] : null;
|
||||
const sideEnd = e >= axisLen - 1e-6 ? layerCuts?.endSide[li] : null;
|
||||
if (sideStart || sideEnd) {
|
||||
const uSeg = normalize(sub(p2, p1));
|
||||
const nSeg = leftNormal(uSeg);
|
||||
const sidePoint = (base: Vec2, layerOff: number, cut: Line): Vec2 => {
|
||||
const pt = add(base, scale(nSeg, layerOff));
|
||||
return lineIntersect(pt, uSeg, cut.point, cut.dir) ?? pt;
|
||||
};
|
||||
if (sideStart) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: sidePoint(p1, off, sideStart),
|
||||
b: sidePoint(p1, off + layer.thickness, sideStart),
|
||||
cls: "layer-joint-l",
|
||||
weightMm: layerLineMm,
|
||||
color: stroke,
|
||||
greyed,
|
||||
});
|
||||
}
|
||||
if (sideEnd) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: sidePoint(p2, off, sideEnd),
|
||||
b: sidePoint(p2, off + layer.thickness, sideEnd),
|
||||
cls: "layer-joint-l",
|
||||
weightMm: layerLineMm,
|
||||
color: stroke,
|
||||
greyed,
|
||||
});
|
||||
}
|
||||
}
|
||||
off += layer.thickness;
|
||||
// Innere Schichtfuge (zwischen dieser und der nächst-inneren Schicht) als
|
||||
// eigene Linie am kumulierten Offset `off`, mit dem Cut der Bänder geclippt.
|
||||
// Stil aus layer.jointLineStyleId (Gewicht/Farbe/Strich); Rückfall = Haar-
|
||||
// linie (LAYER_LINE_MM) in Wandfarbe. Das Gewicht folgt demselben Detail-
|
||||
// Faktor wie die frühere Schichtfuge (`layerLineMm`), damit die Detailgrade
|
||||
// sich unverändert verhalten. Die innerste Schicht hat keine innere Fuge.
|
||||
// Nutzt bewusst weiterhin den einheitlichen startCut/endCut (nicht die
|
||||
// Pro-Schicht-Cuts): die Fuge markiert den Materialwechsel INNERHALB
|
||||
// dieser Wand und bleibt daher an der bisherigen Nahfläche.
|
||||
if (li < wt.layers.length - 1) {
|
||||
const jls = layer.jointLineStyleId
|
||||
? project.lineStyles.find((l) => l.id === layer.jointLineStyleId)
|
||||
: undefined;
|
||||
// Durchgangswand-Aussparung: liegt die Fuge im (geschlossenen) Nah-Putz-
|
||||
// Bereich einer Aussparung — inkl. der Rückgrat-Nahfläche (Merge-Kontakt)
|
||||
// —, wird sie über das Durchstoss-Intervall unterbrochen. So bleibt an der
|
||||
// Verschmelzungsfläche keine Trennlinie stehen.
|
||||
const fugeHoles: Array<[number, number]> = [];
|
||||
for (const c of segCutouts) {
|
||||
const cLo = Math.min(c.offA, c.offB);
|
||||
const cHi = Math.max(c.offA, c.offB);
|
||||
if (off >= cLo - CUTOUT_EPS && off <= cHi + CUTOUT_EPS)
|
||||
fugeHoles.push([c.from, c.to]);
|
||||
}
|
||||
for (const [a, b] of subtractIntervals(s, e, fugeHoles)) {
|
||||
const sc = a <= s + CUTOUT_EPS ? startCut : null;
|
||||
const ec = b >= e - CUTOUT_EPS ? endCut : null;
|
||||
// clippedBand(pa, pb, off, off, …) liefert [edgeStart, edgeEnd, edgeEnd,
|
||||
// edgeStart] → die zwei distinkten Endpunkte sind Index 0 (Start) und 1
|
||||
// (Ende), beide am Cut abgeschnitten wie die Bandlängskante.
|
||||
const jq = clippedBand(axisPt(a), axisPt(b), off, off, sc, ec);
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: jq[0],
|
||||
b: jq[1],
|
||||
cls: "layer-joint",
|
||||
weightMm: jls ? jls.weight * LAYER_DETAIL_FACTOR[detail] : layerLineMm,
|
||||
color: jls ? jls.color : stroke,
|
||||
dash: jls ? jls.dash : null,
|
||||
// Zickzack-Fuge (LineStyle kind==="zigzag") ebenfalls durchreichen.
|
||||
zigzag: jls?.kind === "zigzag" ? jls.zigzag : undefined,
|
||||
// Custom-Motiv-Fuge (LineStyle kind==="custom") ebenfalls durchreichen.
|
||||
motif: jls?.kind === "custom" ? jls.motif : undefined,
|
||||
greyed,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// Kräftige Wand-Umrisslinie über die volle Dicke (nur Kontur, keine Füllung),
|
||||
// damit die Wand sich klar von den dünnen Schichtfugen abhebt. Die Gehrungs-
|
||||
// Stirnkanten am Knoten entfallen → sauberer Eck-Apex ohne überschießende Barbe.
|
||||
// Bei einer Durchgangswand-Aussparung wird zusätzlich die NAHFLÄCHEN-Kante
|
||||
// (die Längskante auf der Durchstoss-Seite) über [from,to] strokelos gemacht
|
||||
// und als separate Segmente vor/nach dem Durchstoss gezeichnet — sonst liefe
|
||||
// die Umrisslinie über die Durchstoss-Breite.
|
||||
const offLo = refOff - total / 2;
|
||||
const offHi = refOff + total / 2;
|
||||
const holesHi: Array<[number, number]> = [];
|
||||
const holesLo: Array<[number, number]> = [];
|
||||
for (const c of segCutouts) {
|
||||
// `offA` ist stets die Nahfläche (Wandoberfläche); ordne die Aussparung der
|
||||
// passenden Längskante (offHi bzw. offLo) zu.
|
||||
if (Math.abs(c.offA - offHi) < 1e-6) holesHi.push([c.from, c.to]);
|
||||
else if (Math.abs(c.offA - offLo) < 1e-6) holesLo.push([c.from, c.to]);
|
||||
}
|
||||
const outlineNoStroke = [...bandJoinEdges];
|
||||
// clippedBand-Kantenreihenfolge [A.start(offLo), A.end(offLo), B.end(offHi),
|
||||
// B.start(offHi)]: Kante 0 ist die offLo-Längskante, Kante 2 die offHi-Längskante.
|
||||
if (holesHi.length) outlineNoStroke.push(2);
|
||||
if (holesLo.length) outlineNoStroke.push(0);
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: clippedBand(p1, p2, offLo, offHi, startCut, endCut),
|
||||
fill: "none",
|
||||
stroke,
|
||||
strokeWidthMm: outlineMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
noStrokeEdges: outlineNoStroke,
|
||||
wallId,
|
||||
});
|
||||
const drawNearEdge = (edgeOff: number, holes: Array<[number, number]>): void => {
|
||||
for (const [a, b] of subtractIntervals(s, e, holes)) {
|
||||
const sc = a <= s + CUTOUT_EPS ? startCut : null;
|
||||
const ec = b >= e - CUTOUT_EPS ? endCut : null;
|
||||
const jq = clippedBand(axisPt(a), axisPt(b), edgeOff, edgeOff, sc, ec);
|
||||
} else {
|
||||
const art = f[i + 1];
|
||||
const li = f[i + 2];
|
||||
const a = { x: f[i + 3], y: f[i + 4] };
|
||||
const b = { x: f[i + 5], y: f[i + 6] };
|
||||
i += 7;
|
||||
if (art === 0) {
|
||||
out.push({ kind: "line", a, b, cls: "layer-joint-l", weightMm: layerLineMm, color: stroke, greyed });
|
||||
} else if (art === 1) {
|
||||
// Innere Schichtfuge: Stil aus layer.jointLineStyleId (Gewicht/Farbe/Strich), Rückfall =
|
||||
// Haarlinie in Wandfarbe.
|
||||
const id = wt.layers[li].jointLineStyleId;
|
||||
const jls = id ? project.lineStyles.find((l) => l.id === id) : undefined;
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: jq[0],
|
||||
b: jq[1],
|
||||
cls: "wall-outline",
|
||||
weightMm: outlineMm,
|
||||
color: stroke,
|
||||
a,
|
||||
b,
|
||||
cls: "layer-joint",
|
||||
weightMm: jls ? jls.weight * LAYER_DETAIL_FACTOR[detail] : layerLineMm,
|
||||
color: jls ? jls.color : stroke,
|
||||
dash: jls ? jls.dash : null,
|
||||
zigzag: jls?.kind === "zigzag" ? jls.zigzag : undefined,
|
||||
motif: jls?.kind === "custom" ? jls.motif : undefined,
|
||||
greyed,
|
||||
});
|
||||
} else {
|
||||
out.push({ kind: "line", a, b, cls: "wall-outline", weightMm: outlineMm, color: stroke, greyed });
|
||||
}
|
||||
};
|
||||
if (holesHi.length) drawNearEdge(offHi, holesHi);
|
||||
if (holesLo.length) drawNearEdge(offLo, holesLo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user