[K3a] Treppen-Symbol im Grundriss in Rust (plan_stairs.rs); generatePlan/stairs.ts nur noch Uebersetzung

This commit is contained in:
karim committed 2026-10-28 00:47:12 +01:00
1 parent 0360790a6d
commit 63f653d1c2
6 files changed
+262 -153

No files matched your search

+6 -1
View File
@@ -80,8 +80,13 @@ truck (`trucksolid`) bleibt eigenes WASM-Modul (Panic-Isolation), wird vom Kern
über `Math` der JS-Engine (musl-libm wich ab, auch in der Topologie). Leistung (Node, Min. über
Wiederholungen): Beispiel-EG 1,5 → 0,8 ms, 100k Linien + 3000 Schraffurflächen 3,9 → 1,8 s, nur
Schraffur ~2×, nur Linien 104 → 81 ms (davon Kodieren in TS 7–29 ms). Mac-Test bestanden.
- ○ **[K3a] Plan-Erzeugung in Rust** (Wand-Poché, Öffnungssymbole, Decken, Treppen, Dächer, Räume,
- ◐ **[K3a] Plan-Erzeugung in Rust** (Wand-Poché, Öffnungssymbole, Decken, Treppen, Dächer, Räume,
2D-Zeichnung, Kontext, Schnittlinien) direkt in den Plan-Puffer; JS-Objekte nur noch für Export/Overlay.
Vorgehen (28.10.): je Domäne ein Rust-Modul mit flacher Primitivliste, TS nur als dünne Übersetzung
(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.
- ○ **[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
+1
View File
@@ -33,6 +33,7 @@ pub mod hatch;
pub mod hatch_flat;
pub mod plan_buf;
pub mod gpu_compile;
pub mod plan_stairs;
#[cfg(feature = "web")]
mod web;
+177
View File
@@ -0,0 +1,177 @@
//! Treppen-Symbol im Grundriss ([K3a]): Tritte, Lauflinie, Pfeil, Podest, SIA-Bruchlinie und
//! Aussenlinie als flache Primitivliste. Port von `src/plan/generatePlan/stairs.ts`; die Geometrie
//! kommt aus `kernel2d` (`stair_geometry`, `stair_cut`, `stair_outline`), Farbe, Pick-ID und
//! Graustufen setzt der Aufrufer.
//!
//! Eingabe: Treppen-Parameter (16 Zahlen, s. `stair.rs`), Gesamt-Steighöhe, Schnitthöhe über der
//! Treppen-UK, Strichstärke `lw_mm` (Papier-mm), `filled_arrow` (0/1).
//!
//! Ausgabe `[n, Eintrag × n]`, Reihenfolge = Zeichenreihenfolge:
//! ```text
//! 1 polygon [1, strokeMm, gefüllt (0 = nur Umriss, 1 = Füllung in Strichfarbe), nPts, x, y …]
//! 2 line [2, cls, weightMm, gestrichelt (0|1), ax, ay, bx, by]
//! 3 arc [3, weightMm, cx, cy, fromX, fromY, toX, toY, r] (cls immer stair-outline)
//! cls 0 stair-outline · 1 stair-tread · 2 stair-break · 3 stair-run · 4 stair-arrow
//! ```
//! Gestrichelte Linien tragen das Strichmuster `[0.12, 0.08]` (Meter, `DASH`).
use crate::jsnum;
use crate::stair::decode_params;
use kernel2d::{stair_cut, stair_geometry, stair_outline, Vec2};
use std::collections::HashSet;
pub const DASH: [f64; 2] = [0.12, 0.08];
const CLS_OUTLINE: f64 = 0.0;
const CLS_TREAD: f64 = 1.0;
const CLS_BREAK: f64 = 2.0;
const CLS_RUN: f64 = 3.0;
const CLS_ARROW: f64 = 4.0;
#[derive(Default)]
struct Out {
buf: Vec<f64>,
n: usize,
}
impl Out {
fn polygon(&mut self, pts: &[Vec2], stroke_mm: f64, filled: bool) {
self.n += 1;
self.buf.extend([1.0, stroke_mm, if filled { 1.0 } else { 0.0 }, pts.len() as f64]);
for p in pts {
self.buf.extend([p.x, p.y]);
}
}
fn line(&mut self, cls: f64, a: Vec2, b: Vec2, weight_mm: f64, dashed: bool) {
self.n += 1;
self.buf.extend([2.0, cls, weight_mm, if dashed { 1.0 } else { 0.0 }, a.x, a.y, b.x, b.y]);
}
fn arc(&mut self, weight_mm: f64, c: Vec2, from: Vec2, to: Vec2, r: f64) {
self.n += 1;
self.buf.extend([3.0, weight_mm, c.x, c.y, from.x, from.y, to.x, to.y, r]);
}
}
pub fn plan_stair(params: &[f64], total_rise: f64, cut_rise: f64, lw_mm: f64, filled_arrow: bool) -> Vec<f64> {
let Some(p) = decode_params(params) else { return Vec::new() };
if !(total_rise.is_finite() && cut_rise.is_finite() && lw_mm.is_finite()) {
return Vec::new();
}
let geo = stair_geometry(&p, total_rise);
let cut = stair_cut(&geo, cut_rise);
let below: HashSet<i64> = cut.below_indices.iter().copied().collect();
let mut o = Out::default();
for tr in &geo.treads {
let is_below = below.contains(&tr.index);
o.polygon(&tr.pts, lw_mm * 0.7, false);
if tr.pts.len() >= 3 {
o.line(CLS_TREAD, tr.pts[1], tr.pts[2], lw_mm * if is_below { 1.0 } else { 0.6 }, !is_below);
}
}
if let Some(l) = &geo.landing {
if l.len() >= 3 {
o.polygon(l, lw_mm * 0.7, false);
}
}
if let Some(lines) = &cut.break_line {
for (a, b) in lines {
o.line(CLS_BREAK, *a, *b, lw_mm, false);
}
}
for w in geo.run_line.windows(2) {
o.line(CLS_RUN, w[0], w[1], lw_mm, false);
}
let (h1, tip, h2) = geo.arrow.head;
if filled_arrow {
o.polygon(&[h1, tip, h2], lw_mm, true);
} else {
o.line(CLS_ARROW, h1, tip, lw_mm, false);
o.line(CLS_ARROW, h2, tip, lw_mm, false);
}
let outline = stair_outline(&p);
if let Some(poly) = &outline.polygon {
if poly.len() >= 3 {
o.polygon(poly, lw_mm, false);
}
}
if let Some(s) = &outline.spiral {
for (a, b) in &s.lines {
o.line(CLS_OUTLINE, *a, *b, lw_mm, false);
}
for (c, r, a0, a1) in &s.arcs {
let from = Vec2::new(c.x + r * jsnum::cos(*a0), c.y + r * jsnum::sin(*a0));
let to = Vec2::new(c.x + r * jsnum::cos(*a1), c.y + r * jsnum::sin(*a1));
o.arc(lw_mm, *c, from, to, *r);
}
}
let mut out = Vec::with_capacity(o.buf.len() + 1);
out.push(o.n as f64);
out.extend(o.buf);
out
}
#[cfg(test)]
mod tests {
use super::*;
const NAN: f64 = f64::NAN;
fn straight() -> Vec<f64> {
vec![0.0, 0.0, 0.0, 1.0, 0.0, 3.0, NAN, NAN, NAN, NAN, NAN, NAN, 1.2, 16.0, NAN, 0.0]
}
/// Zählt Einträge je Tag und prüft, dass der Puffer genau aufgeht.
fn tags(buf: &[f64]) -> Vec<f64> {
let n = buf[0] as usize;
let mut i = 1;
let mut t = Vec::new();
for _ in 0..n {
t.push(buf[i]);
i += match buf[i] as i64 {
1 => 4 + 2 * buf[i + 3] as usize,
2 => 8,
3 => 9,
_ => panic!("unbekannter Tag"),
};
}
assert_eq!(i, buf.len());
t
}
#[test]
fn gerade_treppe_hat_tritte_lauflinie_pfeil_und_aussenlinie() {
let b = plan_stair(&straight(), 2.8, 1.0, 0.25, false);
let t = tags(&b);
// 16 Tritte × (Polygon + Kante) + 2 Bruchstriche + Lauflinie + 2 Pfeilflügel + Aussenlinie
assert_eq!(t.iter().filter(|x| **x == 1.0).count(), 16 + 1);
assert!(t.iter().filter(|x| **x == 2.0).count() >= 16 + 2 + 2);
// erster Tritt liegt unter der Schnittebene: durchgezogen, volle Stärke
assert_eq!(&b[1 + 4 + 8 + 1..][..3], &[1.0, 0.25, 0.0]);
}
#[test]
fn gefuellter_pfeil_ist_ein_dreieck() {
let offen = tags(&plan_stair(&straight(), 2.8, 1.0, 0.25, false));
let voll = tags(&plan_stair(&straight(), 2.8, 1.0, 0.25, true));
assert_eq!(voll.len() + 1, offen.len());
}
#[test]
fn wendel_liefert_boegen() {
let p = vec![2.0, 0.0, 0.0, 1.0, 0.0, 3.0, NAN, NAN, 0.0, 0.0, 1.5, 270.0, 1.0, 14.0, NAN, 0.0];
let t = tags(&plan_stair(&p, 2.8, 1.0, 0.25, false));
assert_eq!(t.iter().filter(|x| **x == 3.0).count(), 2);
}
#[test]
fn unsinn_ergibt_leeres_ergebnis() {
assert!(plan_stair(&[1.0, 2.0], 2.8, 1.0, 0.25, false).is_empty());
assert!(plan_stair(&straight(), NAN, 1.0, 0.25, false).is_empty());
let mut kaputt = straight();
kaputt[1] = NAN;
assert!(plan_stair(&kaputt, 2.8, 1.0, 0.25, false).is_empty());
}
}
+1
View File
@@ -25,6 +25,7 @@ mod openings3d;
mod wall_mesh_cut;
mod plan_buf;
mod gpu_compile;
mod plan_stairs;
mod hatch;
use wasm_bindgen::prelude::wasm_bindgen;
+10
View File
@@ -0,0 +1,10 @@
//! Bindung des Treppen-Symbols im Grundriss (`crate::plan_stairs`). Ausgabe-Layout s. dort.
use wasm_bindgen::prelude::wasm_bindgen;
/// Treppen-Parameter (16 Zahlen), Gesamt-Steighöhe, Schnitthöhe über der UK, Strichstärke (mm),
/// gefüllter Pfeil (0/1) → Primitivliste; Unsinn → leer.
#[wasm_bindgen]
pub fn plan_stair_flat(params: &[f64], total_rise: f64, cut_rise: f64, lw_mm: f64, filled_arrow: f64) -> Vec<f64> {
crate::plan_stairs::plan_stair(params, total_rise, cut_rise, lw_mm, filled_arrow != 0.0)
}
+67 -152
View File
@@ -2,46 +2,21 @@
// Auf-/Abpfeil, Zwischenpodest und Aussenlinie — mit dem Grundriss-Schnitt
// (Tritte unter der Schnitthöhe durchgezogen, darüber gestrichelt/verdeckt +
// SIA-Bruchlinie).
//
// Die Primitive entstehen im Rust-Kern (`src-tauri/core/src/plan_stairs.rs`, [K3a]); hier nur die
// Übersetzung der flachen Liste in `Primitive`-Objekte (Farbe, Graustufen, `stairId`).
// Fällt mit [K3d] weg, wenn der Plan-Puffer direkt aus Rust kommt.
import type { Project, Stair, Vec2 } from "../../model/types";
import type { Project, Stair } from "../../model/types";
import { stairVerticalExtent } from "../../model/wall";
import { stairCut, stairGeometry, stairOutline } from "../../geometry/stair";
import type { SpiralOutlineSegments } from "../../geometry/stair";
import { encodeStair } from "../../geometry/stair";
import { core } from "../../engine/coreWasm";
import { NO_HATCH, POCHE_STROKE, type Primitive } from "./shared";
/**
* Zeichnet die Wendel-Aussenlinie: Innen-/Aussenbogen als Arc-Primitive plus zwei
* radiale Schliesslinien. Wird von `addStairSymbol` aufgerufen wenn `shape === "spiral"`.
*/
function _addSpiralOutline(
out: Primitive[],
seg: SpiralOutlineSegments,
stroke: string,
lwMm: number,
greyed: boolean,
stairId: string,
): void {
// Radiale Schliesslinien (Startwinkel + Endwinkel).
for (const [a, b] of seg.lines) {
out.push({ kind: "line", a, b, cls: "stair-outline", weightMm: lwMm, color: stroke, greyed, stairId });
}
// Innen- und Aussenbogen.
for (const arc of seg.arcs) {
const from: Vec2 = { x: arc.cx + arc.r * Math.cos(arc.a0), y: arc.cy + arc.r * Math.sin(arc.a0) };
const to: Vec2 = { x: arc.cx + arc.r * Math.cos(arc.a1), y: arc.cy + arc.r * Math.sin(arc.a1) };
out.push({
kind: "arc",
center: { x: arc.cx, y: arc.cy },
from,
to,
r: arc.r,
cls: "stair-outline",
weightMm: lwMm,
greyed,
stairId,
});
}
}
/** Linienklassen in der Reihenfolge der Kern-Kodierung (`plan_stairs.rs`). */
const LINE_CLS = ["stair-outline", "stair-tread", "stair-break", "stair-run", "stair-arrow"] as const;
/** Strichmuster der verdeckten Tritte (Meter). */
const TREAD_DASH = [0.12, 0.08];
/**
* Treppen-Symbol im Grundriss (DOSSIER/SIA):
@@ -62,124 +37,64 @@ export function addStairSymbol(
cutHeight: number,
): void {
const { zBottom, zTop } = stairVerticalExtent(project, stair);
const totalRise = zTop - zBottom;
const geo = stairGeometry(stair, totalRise);
const cut = stairCut(geo, cutHeight);
const below = new Set(cut.belowIndices);
const f = core().plan_stair_flat(
encodeStair(stair),
zTop - zBottom,
cutHeight,
lwMm,
stair.arrowStyle === "filled" ? 1 : 0,
);
if (f.length === 0) return;
const stroke = stair.color ?? POCHE_STROKE;
const stairId = stair.id;
// Umriss + Tritt-Trennlinien je Stufe. Der letzte Punkt jedes Tritt-Rechtecks
// liefert die vordere Kante (Auftritt); wir zeichnen jede Tritt-Kante.
for (const tr of geo.treads) {
const isBelow = below.has(tr.index);
// Tritt-Rechteck als reine Umrisslinie (keine Füllung), durchgezogen wenn
// unter der Schnittebene, sonst gestrichelt (verdeckt).
out.push({
kind: "polygon",
pts: tr.pts,
fill: "none",
stroke,
strokeWidthMm: lwMm * 0.7,
hatch: NO_HATCH,
greyed,
stairId,
});
// Zusätzliche Auftrittskante (vordere Kante der Stufe) etwas kräftiger.
const front: [Vec2, Vec2] = [tr.pts[1], tr.pts[2]];
out.push({
kind: "line",
a: front[0],
b: front[1],
cls: "stair-tread",
weightMm: lwMm * (isBelow ? 1.0 : 0.6),
dash: isBelow ? null : [0.12, 0.08],
color: stroke,
greyed,
stairId,
});
}
// Zwischenpodest (L/Wendel-Auge): Umriss-Polygon.
if (geo.landing && geo.landing.length >= 3) {
out.push({
kind: "polygon",
pts: geo.landing,
fill: "none",
stroke,
strokeWidthMm: lwMm * 0.7,
hatch: NO_HATCH,
greyed,
stairId,
});
}
// SIA-Bruchlinie (Doppelstrich diagonal über den Schnitt-Tritt).
if (cut.breakLine) {
for (const [a, b] of cut.breakLine) {
out.push({
kind: "line",
a,
b,
cls: "stair-break",
weightMm: lwMm,
color: stroke,
greyed,
stairId,
});
const n = f[0];
let i = 1;
for (let k = 0; k < n; k++) {
switch (f[i]) {
case 1: {
const count = f[i + 3];
const pts = new Array<{ x: number; y: number }>(count);
for (let j = 0; j < count; j++) pts[j] = { x: f[i + 4 + 2 * j], y: f[i + 5 + 2 * j] };
out.push({
kind: "polygon",
pts,
fill: f[i + 2] ? stroke : "none",
stroke,
strokeWidthMm: f[i + 1],
hatch: NO_HATCH,
greyed,
stairId,
});
i += 4 + 2 * count;
break;
}
case 2:
out.push({
kind: "line",
a: { x: f[i + 4], y: f[i + 5] },
b: { x: f[i + 6], y: f[i + 7] },
cls: LINE_CLS[f[i + 1]],
weightMm: f[i + 2],
...(LINE_CLS[f[i + 1]] === "stair-tread" ? { dash: f[i + 3] ? TREAD_DASH : null } : {}),
color: stroke,
greyed,
stairId,
});
i += 8;
break;
default:
out.push({
kind: "arc",
center: { x: f[i + 2], y: f[i + 3] },
from: { x: f[i + 4], y: f[i + 5] },
to: { x: f[i + 6], y: f[i + 7] },
r: f[i + 8],
cls: "stair-outline",
weightMm: f[i + 1],
greyed,
stairId,
});
i += 9;
}
}
// Lauflinie (Lauflinie) — kräftig, durchgezogen.
for (let i = 0; i < geo.runLine.length - 1; i++) {
out.push({
kind: "line",
a: geo.runLine[i],
b: geo.runLine[i + 1],
cls: "stair-run",
weightMm: lwMm,
color: stroke,
greyed,
stairId,
});
}
// Auf-/Abpfeil an der Spitze der Lauflinie. "filled" = gefülltes Dreieck
// (SIA-Vollpfeil), sonst der offene Winkelpfeil (zwei Linien, Default).
const [h1, tip, h2] = geo.arrow.head;
if (stair.arrowStyle === "filled") {
out.push({
kind: "polygon",
pts: [h1, tip, h2],
fill: stroke,
stroke,
strokeWidthMm: lwMm,
hatch: NO_HATCH,
greyed,
stairId,
});
} else {
out.push({ kind: "line", a: h1, b: tip, cls: "stair-arrow", weightMm: lwMm, color: stroke, greyed, stairId });
out.push({ kind: "line", a: h2, b: tip, cls: "stair-arrow", weightMm: lwMm, color: stroke, greyed, stairId });
}
// Aussenlinie (Outline) der Treppe — schliessendes Umriss-Polygon (gerade/L)
// bzw. Innen-/Aussenbogen + radiale Schliesslinien (Wendel).
// Entspricht `_aussen_gerade` / `_aussen_l_polygon` / `_aussen_wendel` im
// Rhino-Plugin. Stets durchgezogen, volle Strichstärke.
const outline = stairOutline(stair, totalRise);
if (outline.polygon && outline.polygon.length >= 3) {
out.push({
kind: "polygon",
pts: outline.polygon,
fill: "none",
stroke,
strokeWidthMm: lwMm,
hatch: NO_HATCH,
greyed,
stairId,
});
}
if (outline.spiral) {
_addSpiralOutline(out, outline.spiral, stroke, lwMm, greyed, stairId);
}
}