diff --git a/TODO.md b/TODO.md index be6bd08b..c9aebce7 100644 --- a/TODO.md +++ b/TODO.md @@ -96,7 +96,10 @@ truck (`trucksolid`) bleibt eigenes WASM-Modul (Panic-Isolation), wird vom Kern Farben kommen als Slot zurück. `geometry/opening.ts`: `doorSymbol`/`doorLeaves` gelöscht, `windowSymbol` ist Fassade (Schnitt nutzt sie weiter). Bitgleich zur alten Fassung (80 Zufallsfälle × 3 Detailgrade, alle 13 Linienklassen; 600 Zufalls-Fenstersymbole). Tote halbe Ports in `kernel2d` (door/window_symbol, jambs …) entfernt. - Offen: Räume, Dächer, Stützen, 2D-Zeichnung, Kontext, Schnittlinien. + ✅ Kontext-Mesh (Fussabdruck, Rahmen), Schnittführungs-Symbol, Linienenden: `plan_misc.rs`; bitgleich (200 Zufalls-Meshes, + 200 Schnittebenen-Sätze, 400 Linienenden). Räume, Dächer, Stützen, Extrusions-Umriss, Baurecht, Schatten sind nur + noch Stil-Glue um schon in Rust berechnete Geometrie (kein Rechenanteil) — bleiben bis [K4] in TS. + Offen: 2D-Zeichnung (`drawing2d.ts`, 950 Zeilen: Kurven, Bemassung, Kote, Detailverweis, Block, Text …). - ○ **[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 diff --git a/src-tauri/core/src/lib.rs b/src-tauri/core/src/lib.rs index 020fde02..b3366ce7 100644 --- a/src-tauri/core/src/lib.rs +++ b/src-tauri/core/src/lib.rs @@ -37,6 +37,7 @@ pub mod plan_stairs; pub mod plan_walls; pub mod opening_geom; pub mod plan_openings; +pub mod plan_misc; #[cfg(feature = "web")] mod web; diff --git a/src-tauri/core/src/plan_misc.rs b/src-tauri/core/src/plan_misc.rs new file mode 100644 index 00000000..7ca6523e --- /dev/null +++ b/src-tauri/core/src/plan_misc.rs @@ -0,0 +1,278 @@ +//! Kleine Plan-Bausteine ([K3a]): Kontext-Mesh-Fussabdruck und -Rahmen (`generatePlan/context.ts`), +//! Schnittführungs-Symbol (`sections.ts`) und Linienenden (`endMarks.ts`). Stil, Farbe, Pick-IDs und +//! Beschriftungstext setzt TS; Rechenreihenfolge und Zahlsemantik wie dort (`Math.hypot`, `Math.round`). +//! +//! ## Kontext-Mesh +//! `context_footprint(positions, indices)` → `[n, ax, ay, bx, by …]` (Sockelkanten, entdoppelt). +//! `bbox(positions)` → `[minX, minY, maxX, maxY]` oder leer. +//! +//! ## Schnittführung +//! `section_line(p0x, p0y, p1x, p1y, vorzeichen)` → `[n, Eintrag × n]` in Zeichenreihenfolge (leer +//! bei zu kurzer Linie): +//! ```text +//! 2 line [2, art (0 Hauptlinie | 1 Marke), ax, ay, bx, by] +//! 5 label [5, x, y] (Kurz-Tag setzt TS) +//! 1 polygon [1, x0, y0 … x3, y3] (unsichtbares Pick-Band) +//! ``` +//! +//! ## Linienende +//! `end_mark(x, y, dx, dy, art, mm, massstab)` → `[verkuerzung, n, Eintrag × n]` (leer = nichts): +//! ```text +//! art 1 arrow · 2 arrowOpen · 3 dot · 4 tick · 5 square +//! 1 polygon [1, nPts, x, y …] gefüllt in Strichfarbe +//! 2 line [2, ax, ay, bx, by] +//! 4 circle [4, cx, cy, r] gefüllt in Strichfarbe +//! ``` + +use crate::jsmath::hypot2; +use crate::jsnum::round; +use std::collections::HashSet; + +const FOOTPRINT_Z_TOL: f64 = 0.6; +const SECTION_MARK_LEN: f64 = 0.6; +const SECTION_PICK_HALF: f64 = 0.3; +const SECTION_LABEL_H: f64 = 0.5; +const ARROW_ASPECT: f64 = 0.32; + +/// Ganzzahl-Schlüssel für die Quantisierung; NaN/∞ bekommen feste Platzhalter (wie ihre Textform in JS). +fn qkey(v: f64) -> i64 { + if v.is_nan() { + i64::MIN + } else if v == f64::INFINITY { + i64::MAX + } else if v == f64::NEG_INFINITY { + i64::MIN + 1 + } else { + v as i64 + } +} + +pub fn context_footprint(positions: &[f64], indices: &[f64]) -> Vec { + let vcount = positions.len() / 3; + if vcount < 3 || indices.len() < 3 { + return Vec::new(); + } + let mut min_z = f64::INFINITY; + let mut i = 2; + while i < positions.len() { + if positions[i] < min_z { + min_z = positions[i]; + } + i += 3; + } + if !min_z.is_finite() { + return Vec::new(); + } + let z_limit = min_z + FOOTPRINT_Z_TOL; + let q = |v: f64| round(v * 100.0); + let mut seen: HashSet<((i64, i64), (i64, i64))> = HashSet::new(); + let mut lines: Vec = Vec::new(); + let mut count = 0usize; + let mut edge = |ia: f64, ib: f64, lines: &mut Vec, count: &mut usize| { + // Indizes wie in TS: Zahlen ohne Prüfung auf Ganzzahligkeit; ausserhalb → Kante verwerfen + if !(ia >= 0.0 && ib >= 0.0) || ia.fract() != 0.0 || ib.fract() != 0.0 { + return; + } + let (ia, ib) = (ia as usize, ib as usize); + if ia >= vcount || ib >= vcount { + return; + } + let za = positions[ia * 3 + 2]; + let zb = positions[ib * 3 + 2]; + if za > z_limit || zb > z_limit { + return; + } + let (ax, ay) = (positions[ia * 3], positions[ia * 3 + 1]); + let (bx, by) = (positions[ib * 3], positions[ib * 3 + 1]); + let ka = (qkey(q(ax)), qkey(q(ay))); + let kb = (qkey(q(bx)), qkey(q(by))); + if ka == kb { + return; + } + let key = if ka < kb { (ka, kb) } else { (kb, ka) }; + if !seen.insert(key) { + return; + } + lines.extend([ax, ay, bx, by]); + *count += 1; + }; + let mut k = 0; + while k + 2 < indices.len() { + let (a, b, c) = (indices[k], indices[k + 1], indices[k + 2]); + edge(a, b, &mut lines, &mut count); + edge(b, c, &mut lines, &mut count); + edge(c, a, &mut lines, &mut count); + k += 3; + } + let mut out = vec![count as f64]; + out.extend(lines); + out +} + +pub fn bbox(positions: &[f64]) -> Vec { + let (mut min_x, mut min_y, mut max_x, mut max_y) = (f64::INFINITY, f64::INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY); + let mut i = 0; + while i + 2 < positions.len() { + let (x, y) = (positions[i], positions[i + 1]); + if x < min_x { + min_x = x; + } + if x > max_x { + max_x = x; + } + if y < min_y { + min_y = y; + } + if y > max_y { + max_y = y; + } + i += 3; + } + if !min_x.is_finite() { + return Vec::new(); + } + vec![min_x, min_y, max_x, max_y] +} + +pub fn section_line(p0x: f64, p0y: f64, p1x: f64, p1y: f64, sign: f64) -> Vec { + if ![p0x, p0y, p1x, p1y, sign].iter().all(|x| x.is_finite()) { + return Vec::new(); + } + let (ax, ay) = (p1x - p0x, p1y - p0y); + let len = hypot2(ax, ay); + if len < 1e-6 { + return Vec::new(); + } + let (ux, uy) = (ax / len, ay / len); + let (nx, ny) = (-uy, ux); + let (bnx, bny) = (nx * sign, ny * sign); + let mut o: Vec = Vec::new(); + let mut n = 0usize; + let line = |o: &mut Vec, n: &mut usize, art: f64, a: (f64, f64), b: (f64, f64)| { + o.extend([2.0, art, a.0, a.1, b.0, b.1]); + *n += 1; + }; + line(&mut o, &mut n, 0.0, (p0x, p0y), (p1x, p1y)); + let half = SECTION_MARK_LEN / 2.0; + for end in [(p0x, p0y), (p1x, p1y)] { + line(&mut o, &mut n, 1.0, (end.0 - nx * half, end.1 - ny * half), (end.0 + nx * half, end.1 + ny * half)); + let base = (end.0 + bnx * half, end.1 + bny * half); + let tip = (base.0 + bnx * SECTION_MARK_LEN, base.1 + bny * SECTION_MARK_LEN); + let wing_back = (tip.0 - bnx * SECTION_MARK_LEN * 0.4, tip.1 - bny * SECTION_MARK_LEN * 0.4); + let w = SECTION_MARK_LEN * 0.25; + line(&mut o, &mut n, 1.0, base, tip); + line(&mut o, &mut n, 1.0, tip, (wing_back.0 + ux * w, wing_back.1 + uy * w)); + line(&mut o, &mut n, 1.0, tip, (wing_back.0 - ux * w, wing_back.1 - uy * w)); + let lx = tip.0 + bnx * SECTION_MARK_LEN * 0.4 - SECTION_LABEL_H * 0.3; + let ly = tip.1 + bny * SECTION_MARK_LEN * 0.4 + SECTION_LABEL_H * 0.5; + o.extend([5.0, lx, ly]); + n += 1; + } + let (ox, oy) = (nx * SECTION_PICK_HALF, ny * SECTION_PICK_HALF); + o.push(1.0); + o.extend([p0x + ox, p0y + oy, p1x + ox, p1y + oy, p1x - ox, p1y - oy, p0x - ox, p0y - oy]); + n += 1; + let mut out = vec![n as f64]; + out.extend(o); + out +} + +pub fn end_mark(x: f64, y: f64, dx: f64, dy: f64, art: f64, mm: f64, scale_denominator: f64) -> Vec { + if ![x, y, dx, dy, mm, scale_denominator].iter().all(|v| v.is_finite()) { + return Vec::new(); + } + let len = hypot2(dx, dy); + if len < 1e-9 { + return Vec::new(); + } + let size = (mm / 1000.0) * scale_denominator; + let (ux, uy) = (dx / len, dy / len); + let (nx, ny) = (-uy, ux); + let base = (x - ux * size, y - uy * size); + let half = size * ARROW_ASPECT; + let wing_a = (base.0 + nx * half, base.1 + ny * half); + let wing_b = (base.0 - nx * half, base.1 - ny * half); + let at = (x, y); + let mut o: Vec = Vec::new(); + let mut n = 0usize; + let mut shorten = 0.0; + let line = |o: &mut Vec, n: &mut usize, a: (f64, f64), b: (f64, f64)| { + o.extend([2.0, a.0, a.1, b.0, b.1]); + *n += 1; + }; + match art as i64 { + 1 => { + o.extend([1.0, 3.0, at.0, at.1, wing_a.0, wing_a.1, wing_b.0, wing_b.1]); + n += 1; + shorten = size; + } + 2 => { + line(&mut o, &mut n, wing_a, at); + line(&mut o, &mut n, wing_b, at); + } + 3 => { + o.extend([4.0, x, y, size * 0.25]); + n += 1; + } + 4 => { + let tx = (ux + nx) / std::f64::consts::SQRT_2; + let ty = (uy + ny) / std::f64::consts::SQRT_2; + let h = size / 2.0; + line(&mut o, &mut n, (x - tx * h, y - ty * h), (x + tx * h, y + ty * h)); + } + 5 => { + let h = size * 0.3; + o.extend([ + 1.0, 4.0, + x + (ux + nx) * h, y + (uy + ny) * h, + x + (ux - nx) * h, y + (uy - ny) * h, + x + (-ux - nx) * h, y + (-uy - ny) * h, + x + (-ux + nx) * h, y + (-uy + ny) * h, + ]); + n += 1; + } + _ => return Vec::new(), + } + let mut out = vec![shorten, n as f64]; + out.extend(o); + out +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn sockelkanten_werden_entdoppelt() { + // zwei Dreiecke mit gemeinsamer Kante, alle auf z=0; ein Punkt hoch → Kanten dorthin entfallen + let pos = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.5, 0.5, 9.0]; + let idx = [0.0, 1.0, 2.0, 0.0, 2.0, 3.0, 0.0, 1.0, 4.0]; + let f = context_footprint(&pos, &idx); + assert_eq!(f[0], 5.0); // 4 Aussenkanten + Diagonale + assert_eq!(f.len(), 1 + 5 * 4); + } + + #[test] + fn unsinn_ohne_panic() { + assert!(context_footprint(&[0.0, 1.0], &[0.0]).is_empty()); + assert!(bbox(&[]).is_empty()); + assert!(section_line(0.0, 0.0, 0.0, 0.0, 1.0).is_empty()); + assert!(section_line(f64::NAN, 0.0, 1.0, 0.0, 1.0).is_empty()); + assert!(end_mark(0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 100.0).is_empty()); + assert!(end_mark(0.0, 0.0, 1.0, 0.0, 99.0, 3.0, 100.0).is_empty()); + } + + #[test] + fn schnittlinie_hat_hauptlinie_marken_label_und_pickband() { + let f = section_line(0.0, 0.0, 4.0, 0.0, 1.0); + // 1 Hauptlinie + 2 × (Querstrich + 3 Pfeillinien + Label) + Pick = 12 + assert_eq!(f[0], 12.0); + } + + #[test] + fn gefuellter_pfeil_verkuerzt_die_linie() { + let a = end_mark(0.0, 0.0, 1.0, 0.0, 1.0, 3.0, 100.0); + assert!((a[0] - 0.3).abs() < 1e-12); + assert_eq!(end_mark(0.0, 0.0, 1.0, 0.0, 2.0, 3.0, 100.0)[0], 0.0); + } +} diff --git a/src-tauri/core/src/web/mod.rs b/src-tauri/core/src/web/mod.rs index fe186a76..74545534 100644 --- a/src-tauri/core/src/web/mod.rs +++ b/src-tauri/core/src/web/mod.rs @@ -28,6 +28,7 @@ mod gpu_compile; mod plan_stairs; mod plan_walls; mod plan_openings; +mod plan_misc; mod hatch; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/src-tauri/core/src/web/plan_misc.rs b/src-tauri/core/src/web/plan_misc.rs new file mode 100644 index 00000000..e00fb9ae --- /dev/null +++ b/src-tauri/core/src/web/plan_misc.rs @@ -0,0 +1,27 @@ +//! Bindungen kleiner Plan-Bausteine (`crate::plan_misc`). Layouts s. dort. + +use wasm_bindgen::prelude::wasm_bindgen; + +/// Grundriss-Fussabdruck eines Meshes (Sockelkanten); Unsinn → leer. +#[wasm_bindgen] +pub fn context_footprint_flat(positions: &[f64], indices: &[f64]) -> Vec { + crate::plan_misc::context_footprint(positions, indices) +} + +/// `[minX, minY, maxX, maxY]` der x/y-Werte eines [x,y,z…]-Arrays; leer ohne Punkte. +#[wasm_bindgen] +pub fn context_bbox_flat(positions: &[f64]) -> Vec { + crate::plan_misc::bbox(positions) +} + +/// Schnittführungs-Symbol einer Linie; leer bei zu kurzer Linie. +#[wasm_bindgen] +pub fn section_line_flat(p0x: f64, p0y: f64, p1x: f64, p1y: f64, sign: f64) -> Vec { + crate::plan_misc::section_line(p0x, p0y, p1x, p1y, sign) +} + +/// Linienende (Pfeil, Punkt, Schrägstrich, Quadrat); leer ohne Wirkung. +#[wasm_bindgen] +pub fn end_mark_flat(x: f64, y: f64, dx: f64, dy: f64, art: f64, mm: f64, scale_denominator: f64) -> Vec { + crate::plan_misc::end_mark(x, y, dx, dy, art, mm, scale_denominator) +} diff --git a/src/plan/generatePlan/context.ts b/src/plan/generatePlan/context.ts index 9dc1c2de..b2c89304 100644 --- a/src/plan/generatePlan/context.ts +++ b/src/plan/generatePlan/context.ts @@ -1,9 +1,11 @@ // Kontext-Domäne des Grundriss-Generators: zeichnet `project.context` // (Höhenlinien, importierte Gebäude/Terrain-Meshes) als dezente Referenz- // Konturen — für Meshes der Grundriss-Fussabdruck nahe der Objekt-Unterkante, -// nicht das volle Drahtgitter. +// nicht das volle Drahtgitter. Fussabdruck (Sockelkanten, entdoppelt) und Rahmen berechnet der +// Rust-Kern (`src-tauri/core/src/plan_misc.rs`, [K3a]). import type { Project } from "../../model/types"; +import { core } from "../../engine/coreWasm"; import { NO_HATCH, SHOW_ALL, type CategoryDisplayResolver, type Primitive } from "./shared"; /** Dezente Plan-Farbe der Kontext-Konturen (gedämpftes Grau). */ @@ -11,11 +13,6 @@ const CONTEXT_LINE_COLOR = "#9aa3ad"; /** Strichstärke der Kontext-Konturen (mm Papier, dünn). */ const CONTEXT_LINE_MM = 0.1; -/** Höhen-Toleranz (Meter): Dreieckskanten, deren beide Endpunkte höchstens so - * weit über der Objekt-Unterkante (minZ) liegen, gelten als „Sockelkante" und - * bilden den Grundriss-Fussabdruck eines importierten Gebäudes. */ -const FOOTPRINT_Z_TOL = 0.6; - /** * Zeichnet die Kontext-Schicht `project.context` in den Grundriss: * • ContourSet (Höhenlinien) → dünne Referenz-Linien (Z ignoriert). @@ -77,68 +74,41 @@ export function addContextContours( /** * Zeichnet den Grundriss-Fussabdruck eines Meshes: Dreieckskanten nahe der - * Unterkante (minZ + {@link FOOTPRINT_Z_TOL}), auf XY projiziert, über - * quantisierte Endpunkt-Schlüssel entdoppelt. `positions` = flaches [x,y,z…]- - * Array (Modell-Meter, z = Höhe), `indices` = Dreiecks-Indizes. + * Unterkante (minZ + 0.6 m), auf XY projiziert, über 1-cm-quantisierte Endpunkte + * entdoppelt. `positions` = flaches [x,y,z…]-Array (Modell-Meter, z = Höhe), + * `indices` = Dreiecks-Indizes. */ function addMeshFootprint(out: Primitive[], positions: number[], indices: number[]): void { - const vcount = Math.floor(positions.length / 3); - if (vcount < 3 || indices.length < 3) return; - let minZ = Infinity; - for (let i = 2; i < positions.length; i += 3) if (positions[i] < minZ) minZ = positions[i]; - if (!Number.isFinite(minZ)) return; - const zLimit = minZ + FOOTPRINT_Z_TOL; - const q = (v: number) => Math.round(v * 100); // 1-cm-Quantisierung (Entdopplung) - const seen = new Set(); - const edge = (ia: number, ib: number) => { - if (ia >= vcount || ib >= vcount) return; - const za = positions[ia * 3 + 2]; - const zb = positions[ib * 3 + 2]; - if (za > zLimit || zb > zLimit) return; // nur Sockelkanten - const ax = positions[ia * 3], ay = positions[ia * 3 + 1]; - const bx = positions[ib * 3], by = positions[ib * 3 + 1]; - // Kanten-Schlüssel richtungsunabhängig (kleinerer Endpunkt zuerst). - const ka = `${q(ax)},${q(ay)}`; - const kb = `${q(bx)},${q(by)}`; - if (ka === kb) return; - const key = ka < kb ? `${ka}|${kb}` : `${kb}|${ka}`; - if (seen.has(key)) return; - seen.add(key); + const f = core().context_footprint_flat(Float64Array.from(positions), Float64Array.from(indices)); + for (let i = 0; i < f[0]; i++) { out.push({ kind: "line", - a: { x: ax, y: ay }, - b: { x: bx, y: by }, + a: { x: f[1 + 4 * i], y: f[2 + 4 * i] }, + b: { x: f[3 + 4 * i], y: f[4 + 4 * i] }, cls: "context-line", weightMm: CONTEXT_LINE_MM, color: CONTEXT_LINE_COLOR, }); - }; - for (let i = 0; i + 2 < indices.length; i += 3) { - const a = indices[i], b = indices[i + 1], c = indices[i + 2]; - edge(a, b); - edge(b, c); - edge(c, a); } } +/** Grundriss-Rahmen eines Meshes (nur x/y) als vier Eckpunkte, oder `null` ohne Punkte. */ +function meshBboxCorners(positions: number[]): { x: number; y: number }[] | null { + const b = core().context_bbox_flat(Float64Array.from(positions)); + if (b.length === 0) return null; + return [ + { x: b[0], y: b[1] }, + { x: b[2], y: b[1] }, + { x: b[2], y: b[3] }, + { x: b[0], y: b[3] }, + ]; +} + /** Zeichnet nur den achsenparallelen 2D-Umriss (Bounding-Box) eines Meshes — * für Terrain, dessen volles TIN-Gitter im Plan zu dicht wäre. */ function addMeshBboxOutline(out: Primitive[], positions: number[]): void { - let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity; - for (let i = 0; i + 2 < positions.length; i += 3) { - const x = positions[i], y = positions[i + 1]; - if (x < minX) minX = x; - if (x > maxX) maxX = x; - if (y < minY) minY = y; - if (y > maxY) maxY = y; - } - if (!Number.isFinite(minX)) return; - const corners = [ - { x: minX, y: minY }, - { x: maxX, y: minY }, - { x: maxX, y: maxY }, - { x: minX, y: maxY }, - ]; + const corners = meshBboxCorners(positions); + if (!corners) return; for (let i = 0; i < 4; i++) { out.push({ kind: "line", @@ -157,28 +127,14 @@ function addMeshBboxOutline(out: Primitive[], positions: number[]): void { * trägt die `ContextObject.id` (analog `sectionLineId`, s. dort). Macht das * Objekt IRGENDWO innerhalb seiner Grundfläche anklickbar (nicht nur exakt auf * der dünnen Umriss-/Fussabdrucklinie) — wie bei Wänden, deren Poché-Fläche - * ebenfalls als Ganzes klickbar ist (Nutzer-Wunsch: „eigene Elemente wie Wände"). - * `positions` = flaches [x,y,z…]-Array (Modell-Meter); die Bbox nutzt NUR x/y, - * unabhängig von der Höhe. + * ebenfalls als Ganzes klickbar ist. */ function addContextPickRegion(out: Primitive[], positions: number[], id: string): void { - let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity; - for (let i = 0; i + 2 < positions.length; i += 3) { - const x = positions[i], y = positions[i + 1]; - if (x < minX) minX = x; - if (x > maxX) maxX = x; - if (y < minY) minY = y; - if (y > maxY) maxY = y; - } - if (!Number.isFinite(minX)) return; + const pts = meshBboxCorners(positions); + if (!pts) return; out.push({ kind: "polygon", - pts: [ - { x: minX, y: minY }, - { x: maxX, y: minY }, - { x: maxX, y: maxY }, - { x: minX, y: maxY }, - ], + pts, fill: "none", stroke: "none", strokeWidthMm: 0, diff --git a/src/plan/generatePlan/endMarks.ts b/src/plan/generatePlan/endMarks.ts index da03dbe8..263f265b 100644 --- a/src/plan/generatePlan/endMarks.ts +++ b/src/plan/generatePlan/endMarks.ts @@ -9,18 +9,18 @@ // Die Grösse kommt in PAPIER-MILLIMETERN herein und wird mit dem Massstab des // Plans in Modellmass umgerechnet (gleiche Linie wie die Bemassung, s. // `model/dimension.ts`): eine 3-mm-Pfeilspitze soll auf dem Papier 3 mm sein, -// egal ob der Plan 1:50 oder 1:200 steht. +// egal ob der Plan 1:50 oder 1:200 steht. Die Geometrie berechnet der Rust-Kern (`plan_misc.rs`, [K3a]). import type { EndMark, Vec2 } from "../../model/types"; -import { mmToModel } from "../../model/dimension"; +import { core } from "../../engine/coreWasm"; import type { Primitive } from "./shared"; import { NO_HATCH } from "./shared"; /** Default-Grösse der Linienenden in Papier-Millimetern. */ export const END_MARK_DEFAULT_SIZE_MM = 3; -/** Öffnungsverhältnis der Pfeilspitze (halbe Breite ÷ Länge) — schlanke Spitze. */ -const ARROW_ASPECT = 0.32; +/** Kodierung der Linienenden im Kern (`plan_misc.rs`). */ +const MARK_CODE: Record, number> = { arrow: 1, arrowOpen: 2, dot: 3, tick: 4, square: 5 }; export interface EndMarkStyle { weightMm: number; @@ -49,82 +49,35 @@ export function addEndMark( style: EndMarkStyle, ): number { if (!mark || mark === "none") return 0; - const len = Math.hypot(dir.x, dir.y); - if (len < 1e-9) return 0; - const size = mmToModel(sizeMm, scaleDenominator); - const ux = dir.x / len; - const uy = dir.y / len; - const nx = -uy; - const ny = ux; + const f = core().end_mark_flat(at.x, at.y, dir.x, dir.y, MARK_CODE[mark], sizeMm, scaleDenominator); + if (f.length === 0) return 0; const { weightMm, color, greyed, drawingId } = style; - - /** Fusspunkt der Spitze (size zurück entlang der Linie). */ - const base: Vec2 = { x: at.x - ux * size, y: at.y - uy * size }; - const half = size * ARROW_ASPECT; - const wingA: Vec2 = { x: base.x + nx * half, y: base.y + ny * half }; - const wingB: Vec2 = { x: base.x - nx * half, y: base.y - ny * half }; - const line = (a: Vec2, b: Vec2) => - out.push({ kind: "line", a, b, cls: "draw2d", weightMm, dash: null, color, greyed, drawingId }); - - switch (mark) { - case "arrow": + let i = 2; + for (let k = 0; k < f[1]; k++) { + if (f[i] === 1) { + const count = f[i + 1]; + const pts = Array.from({ length: count }, (_, j) => ({ x: f[i + 2 + 2 * j], y: f[i + 3 + 2 * j] })); + out.push({ kind: "polygon", pts, fill: color, stroke: color, strokeWidthMm: weightMm, hatch: NO_HATCH, greyed, drawingId }); + i += 2 + 2 * count; + } else if (f[i] === 2) { out.push({ - kind: "polygon", - pts: [at, wingA, wingB], - fill: color, - stroke: color, - strokeWidthMm: weightMm, - hatch: NO_HATCH, - greyed, - drawingId, - }); - // Die gefüllte Spitze überdeckt die Linie — dort darf sie enden. - return size; - case "arrowOpen": - line(wingA, at); - line(wingB, at); - // Offene Spitze: die Linie läuft bis zum Punkt durch (sie ist Teil des Bildes). - return 0; - case "dot": - out.push({ - kind: "drawingCircle", - center: at, - r: size * 0.25, - fill: color, - stroke: color, + kind: "line", + a: { x: f[i + 1], y: f[i + 2] }, + b: { x: f[i + 3], y: f[i + 4] }, + cls: "draw2d", weightMm, + dash: null, + color, greyed, drawingId, }); - return 0; - case "tick": { - // 45°-Schrägstrich, mittig auf dem Endpunkt (SIA-Massstrich-Anmutung). - const tx = (ux + nx) / Math.SQRT2; - const ty = (uy + ny) / Math.SQRT2; - const h = size / 2; - line({ x: at.x - tx * h, y: at.y - ty * h }, { x: at.x + tx * h, y: at.y + ty * h }); - return 0; - } - case "square": { - const h = size * 0.3; - out.push({ - kind: "polygon", - pts: [ - { x: at.x + (ux + nx) * h, y: at.y + (uy + ny) * h }, - { x: at.x + (ux - nx) * h, y: at.y + (uy - ny) * h }, - { x: at.x + (-ux - nx) * h, y: at.y + (-uy - ny) * h }, - { x: at.x + (-ux + nx) * h, y: at.y + (-uy + ny) * h }, - ], - fill: color, - stroke: color, - strokeWidthMm: weightMm, - hatch: NO_HATCH, - greyed, - drawingId, - }); - return 0; + i += 5; + } else { + out.push({ kind: "drawingCircle", center: { x: f[i + 1], y: f[i + 2] }, r: f[i + 3], fill: color, stroke: color, weightMm, greyed, drawingId }); + i += 4; } } + return f[0]; } /** Punkt `p` um `d` in Richtung `dir` (normiert) zurückgezogen — für die Linienverkürzung. */ diff --git a/src/plan/generatePlan/sections.ts b/src/plan/generatePlan/sections.ts index 633e5b87..d3bd20dd 100644 --- a/src/plan/generatePlan/sections.ts +++ b/src/plan/generatePlan/sections.ts @@ -2,9 +2,9 @@ // Strichpunkt-Schnittlinie mit Endmarken + Label) — NICHT zu verwechseln mit // `generateSectionPlan()` (der Schnitt-ALS-Plan-Übersetzung, bleibt Orchestrator // in `../generatePlan.ts`): diese Domäne zeichnet nur das Führungssymbol EINER -// Schnitt-/Ansichtsebene IM Grundriss. +// Schnitt-/Ansichtsebene IM Grundriss. Die Geometrie berechnet der Rust-Kern (`plan_misc.rs`, [K3a]). -import { leftNormal, normalize, sub } from "../../model/geometry"; +import { core } from "../../engine/coreWasm"; import type { Project } from "../../model/types"; import { NO_HATCH, SHOW_ALL, type CategoryDisplayResolver, type Primitive } from "./shared"; @@ -26,10 +26,6 @@ const SECTION_LINE_MM = 0.18; const SECTION_LINE_MARK_MM = 0.5; /** Strichpunkt-Muster der Schnittlinie (lange Striche + Punkt, mm Papier). */ const SECTION_LINE_DASH: number[] = [6, 1.5, 0.4, 1.5]; -/** Länge der Endmarken (Querstrich/Pfeil) in Modell-Metern. */ -const SECTION_MARK_LEN = 0.6; -/** Halbe Breite des unsichtbaren Pick-Bands über der Linie (Modell-Meter). */ -const SECTION_PICK_HALF = 0.3; /** Schrifthöhe des Schnitt-Labels (Modell-Meter). */ const SECTION_LABEL_H = 0.5; @@ -72,100 +68,48 @@ export function addSectionLines( const line = level.linePoints; if (!line) continue; const [p0, p1] = line; - const axis = sub(p1, p0); - const len = Math.hypot(axis.x, axis.y); - if (len < 1e-6) continue; - const u = normalize(axis); - const n = leftNormal(u); // (-uy, ux) - const sign = level.directionSign ?? 1; - const bn = { x: n.x * sign, y: n.y * sign }; // Blicknormale - - // Hauptlinie (Strichpunkt-Haarlinie). - out.push({ - kind: "line", - a: p0, - b: p1, - cls: "section-line", - weightMm: SECTION_LINE_MM, - dash: SECTION_LINE_DASH, - color: SECTION_LINE_INK, - greyed, - }); - - // Endmarken (Querstrich + Richtungspfeil + Label) an beiden Enden. - const half = SECTION_MARK_LEN / 2; - for (const end of [p0, p1]) { - // Querstrich senkrecht zur Linie, mittig am Endpunkt. - const t0 = { x: end.x - n.x * half, y: end.y - n.y * half }; - const t1 = { x: end.x + n.x * half, y: end.y + n.y * half }; - out.push({ - kind: "line", - a: t0, - b: t1, - cls: "section-line", - weightMm: SECTION_LINE_MARK_MM, - color: SECTION_LINE_INK, - greyed, - }); - // Richtungspfeil: vom Querstrich-Ende auf der Blickseite entlang bn. - const base = { x: end.x + bn.x * half, y: end.y + bn.y * half }; - const tip = { x: base.x + bn.x * SECTION_MARK_LEN, y: base.y + bn.y * SECTION_MARK_LEN }; - const wingBack = { - x: tip.x - bn.x * SECTION_MARK_LEN * 0.4, - y: tip.y - bn.y * SECTION_MARK_LEN * 0.4, - }; - const w = SECTION_MARK_LEN * 0.25; - out.push({ kind: "line", a: base, b: tip, cls: "section-line", weightMm: SECTION_LINE_MARK_MM, color: SECTION_LINE_INK, greyed }); - out.push({ - kind: "line", - a: tip, - b: { x: wingBack.x + u.x * w, y: wingBack.y + u.y * w }, - cls: "section-line", - weightMm: SECTION_LINE_MARK_MM, - color: SECTION_LINE_INK, - greyed, - }); - out.push({ - kind: "line", - a: tip, - b: { x: wingBack.x - u.x * w, y: wingBack.y - u.y * w }, - cls: "section-line", - weightMm: SECTION_LINE_MARK_MM, - color: SECTION_LINE_INK, - greyed, - }); - // Label (Kurz-Tag) etwas hinter dem Pfeil, horizontal. - const labelAt = { - x: tip.x + bn.x * SECTION_MARK_LEN * 0.4 - SECTION_LABEL_H * 0.3, - y: tip.y + bn.y * SECTION_MARK_LEN * 0.4 + SECTION_LABEL_H * 0.5, - }; - out.push({ - kind: "drawingText", - at: labelAt, - text: sectionLabelTag(level.name), - heightM: SECTION_LABEL_H, - angle: 0, - color: SECTION_LINE_INK, - greyed, - }); + const f = core().section_line_flat(p0.x, p0.y, p1.x, p1.y, level.directionSign ?? 1); + if (f.length === 0) continue; + let i = 1; + for (let k = 0; k < f[0]; k++) { + if (f[i] === 2) { + const main = f[i + 1] === 0; + out.push({ + kind: "line", + a: { x: f[i + 2], y: f[i + 3] }, + b: { x: f[i + 4], y: f[i + 5] }, + cls: "section-line", + weightMm: main ? SECTION_LINE_MM : SECTION_LINE_MARK_MM, + ...(main ? { dash: SECTION_LINE_DASH } : {}), + color: SECTION_LINE_INK, + greyed, + }); + i += 6; + } else if (f[i] === 5) { + out.push({ + kind: "drawingText", + at: { x: f[i + 1], y: f[i + 2] }, + text: sectionLabelTag(level.name), + heightM: SECTION_LABEL_H, + angle: 0, + color: SECTION_LINE_INK, + greyed, + }); + i += 3; + } else { + // Unsichtbares Pick-Band (Rechteck entlang der Linie) — klickbar per Punkt-in-Polygon in + // PlanView, trägt die DrawingLevel-Id. + out.push({ + kind: "polygon", + pts: [0, 1, 2, 3].map((j) => ({ x: f[i + 1 + 2 * j], y: f[i + 2 + 2 * j] })), + fill: "none", + stroke: "none", + strokeWidthMm: 0, + hatch: NO_HATCH, + sectionLineId: level.id, + }); + i += 9; + } } - - // Unsichtbares Pick-Band (Rechteck entlang der Linie) — klickbar per - // Punkt-in-Polygon in PlanView, trägt die DrawingLevel-Id. - const off = { x: n.x * SECTION_PICK_HALF, y: n.y * SECTION_PICK_HALF }; - out.push({ - kind: "polygon", - pts: [ - { x: p0.x + off.x, y: p0.y + off.y }, - { x: p1.x + off.x, y: p1.y + off.y }, - { x: p1.x - off.x, y: p1.y - off.y }, - { x: p0.x - off.x, y: p0.y - off.y }, - ], - fill: "none", - stroke: "none", - strokeWidthMm: 0, - hatch: NO_HATCH, - sectionLineId: level.id, - }); } }