[K4] Aufräumen: tote TS-Funktionen und Bindungen gelöscht, Höhenregeln/JS-Helfer im Kern zusammengelegt

Gelöscht: vertikale Ausdehnungen in model/wall.ts und geometry/opening.ts (ohne Aufrufer seit dem
Schnitt-Port), weitere ungenutzte Exporte (types.ts, ceiling.ts, glPlan, toWalls3d, truckSolid,
meshImport, bulge, planView) und die Bindungen doc_query, core_version, drawing3d_*,
bulge_between_angles, scatter_strokes_flat. Rust: model/helpers.rs::heights für typisierte Sicht
und rohe Wurzel, truthy/or_zero/js_string/arr je einmal.
This commit is contained in:
Claude committed 2026-10-29 13:08:08 +00:00
1 parent 24ab554c2e
commit 8b94abd854
38 files changed
+125 -505

No files matched your search

+1 -7
View File
@@ -81,13 +81,7 @@ fn area_kind(r: &Room) -> usize {
kennzahlen::category_index(r.sia_category)
}
fn finite(v: f64) -> f64 {
if v.is_finite() {
v
} else {
0.0
}
}
use crate::jsnum::or_zero as finite;
/// Woher das Gebäudevolumen kommt.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
+1 -9
View File
@@ -20,15 +20,7 @@ fn shift_all(v: Option<&Value>, dx: f64, dy: f64) -> Value {
Value::Array(v.and_then(Value::as_array).map(|a| a.iter().map(|p| shift(p, dx, dy)).collect()).unwrap_or_default())
}
fn truthy(v: Option<&Value>) -> bool {
match v {
None | Some(Value::Null) => false,
Some(Value::Bool(b)) => *b,
Some(Value::Number(n)) => n.as_f64().is_some_and(|f| f != 0.0 && !f.is_nan()),
Some(Value::String(s)) => !s.is_empty(),
Some(_) => true,
}
}
use crate::grips::truthy;
/// `{...m, key: v}` — ein vorhandener Schlüssel behält seine Stelle; `None` = `undefined` (Feld entfällt).
fn set(m: &mut Map<String, Value>, key: &str, v: Option<Value>) {
+1 -1
View File
@@ -161,7 +161,7 @@ fn calc(f: f64) -> Pass {
Pass { f, v: Some(js_num(f)) }
}
fn arr(v: Option<&Value>) -> &[Value] {
pub fn arr(v: Option<&Value>) -> &[Value] {
v.and_then(Value::as_array).map(Vec::as_slice).unwrap_or(&[])
}
+13
View File
@@ -109,6 +109,19 @@ pub fn js_number(x: f64) -> String {
format!("{sign}{body}")
}
/// JS-`String(v)` eines JSON-Werts (Meldungen, Anzeige-Texte).
pub fn js_string(v: &serde_json::Value) -> String {
use serde_json::Value;
match v {
Value::Null => "null".into(),
Value::Bool(b) => b.to_string(),
Value::Number(n) => n.as_f64().map_or(n.to_string(), js_number),
Value::String(s) => s.clone(),
Value::Array(a) => a.iter().map(|x| if x.is_null() { String::new() } else { js_string(x) }).collect::<Vec<_>>().join(","),
Value::Object(_) => "[object Object]".into(),
}
}
#[cfg(test)]
mod tests {
use super::*;
+10
View File
@@ -85,6 +85,16 @@ mod trig {
pub use trig::{acos, atan2, cos, pow, sin, tan};
/// Endliche Zahl oder 0 (NaN/±∞ → 0; Summen der Kennzahlen/Flächen).
#[inline]
pub fn or_zero(v: f64) -> f64 {
if v.is_finite() {
v
} else {
0.0
}
}
/// `Math.min(a, b)` (NaN gewinnt; −0 < +0).
#[inline]
pub fn min(a: f64, b: f64) -> f64 {
+1 -7
View File
@@ -11,13 +11,7 @@ use crate::flat_read::signed_area;
/// Anzahl der SIA-416-Blattkategorien (Reihenfolge: `room_area::CATEGORIES`).
pub const CATEGORIES: usize = crate::room_area::CATEGORIES.len();
fn finite(v: f64) -> f64 {
if v.is_finite() {
v
} else {
0.0
}
}
use crate::jsnum::or_zero as finite;
/// Volumen (m³): Grundfläche (Polygon `points` oder Kreis mit Radius `circle_r`, NaN = kein
/// Kreis), Höhe, Verjüngung `taper` (0 = Prisma, 1 = Spitze; ausserhalb geklemmt, NaN = 0).
+1 -10
View File
@@ -11,16 +11,7 @@ use std::collections::HashSet;
type Tree = Vec<Value>;
/// JS-Wahrheitswert eines JSON-Werts (`if (c.visible)`).
fn truthy(v: Option<&Value>) -> bool {
match v {
None | Some(Value::Null) => false,
Some(Value::Bool(b)) => *b,
Some(Value::Number(n)) => n.as_f64().is_some_and(|f| f != 0.0 && !f.is_nan()),
Some(Value::String(s)) => !s.is_empty(),
Some(_) => true,
}
}
use crate::grips::truthy;
fn code_of(c: &Value) -> Option<&str> {
c.get("code").and_then(Value::as_str)
+44 -10
View File
@@ -118,7 +118,7 @@ impl Project {
VerticalAnchor::Custom { z } => Some(*z),
VerticalAnchor::Floor { floor_id, offset } => {
let f = self.floor(floor_id)?;
Some(f.base_elevation.unwrap_or(0.0) + offset.unwrap_or(0.0))
Some(heights::floor_anchor(f.base_elevation.unwrap_or(0.0), offset.unwrap_or(0.0)))
}
}
}
@@ -126,16 +126,12 @@ impl Project {
/// (UK, OK) einer Wand in Metern (`wallVerticalExtent`).
pub fn wall_vertical_extent(&self, w: &Wall) -> (f64, f64) {
let floor_base = self.floor(&w.floor_id).map_or(0.0, |f| f.base_elevation.unwrap_or(0.0));
let bottom = self.resolve_anchor(w.bottom.as_ref()).unwrap_or(floor_base);
let top = self.resolve_anchor(w.top.as_ref()).unwrap_or(bottom + w.height);
(bottom, top)
heights::element(floor_base, self.resolve_anchor(w.bottom.as_ref()), self.resolve_anchor(w.top.as_ref()), w.height)
}
pub fn ceiling_vertical_extent(&self, c: &Ceiling) -> (f64, f64) {
let floor_top = self.floor(&c.floor_id).map_or(0.0, |f| f.base_elevation.unwrap_or(0.0) + f.floor_height.unwrap_or(0.0));
let top = self.resolve_anchor(c.top.as_ref()).unwrap_or(floor_top);
let bottom = self.resolve_anchor(c.bottom.as_ref()).unwrap_or(top - self.ceiling_thickness(c));
(bottom, top)
heights::ceiling(floor_top, self.resolve_anchor(c.bottom.as_ref()), self.resolve_anchor(c.top.as_ref()), || self.ceiling_thickness(c))
}
pub fn stair_vertical_extent(&self, s: &Stair) -> (f64, f64) {
@@ -150,9 +146,7 @@ impl Project {
pub fn column_vertical_extent(&self, c: &Column) -> (f64, f64) {
let floor_base = self.floor(&c.floor_id).map_or(0.0, |f| f.base_elevation.unwrap_or(0.0));
let bottom = self.resolve_anchor(c.bottom.as_ref()).unwrap_or(floor_base);
let top = self.resolve_anchor(c.top.as_ref()).unwrap_or(bottom + c.height);
(bottom, top)
heights::element(floor_base, self.resolve_anchor(c.bottom.as_ref()), self.resolve_anchor(c.top.as_ref()), c.height)
}
/// Traufhöhe (absolutes Z): `baseElevation`, sonst Oberkante des Geschosses (`roofBaseElevation`).
@@ -227,3 +221,43 @@ impl Stair {
]
}
}
/// Höhenregeln (UK/OK) — eine Fassung für die typisierte Sicht (oben) und die rohe Projekt-Wurzel
/// (`selection_info.rs`: Objekt-Info, 3D-Griffe); die Aufrufer lösen nur ihre Eingaben auf.
pub mod heights {
/// Bindung „Geschoss“: Basis des Geschosses + Versatz.
pub fn floor_anchor(base: f64, offset: f64) -> f64 {
base + offset
}
/// Wand/Stütze: UK aus der Bindung `bottom`, sonst Geschoss-Basis; OK aus `top`, sonst UK + Höhe.
pub fn element(floor_base: f64, bottom: Option<f64>, top: Option<f64>, height: f64) -> (f64, f64) {
let zb = bottom.unwrap_or(floor_base);
(zb, top.unwrap_or(zb + height))
}
/// Decke: OK aus `top`, sonst Geschoss-Oberkante; UK aus `bottom`, sonst OK − Dicke (die Decke wächst
/// nach unten; die Dicke wird nur dann bestimmt).
pub fn ceiling(floor_top: f64, bottom: Option<f64>, top: Option<f64>, thickness: impl FnOnce() -> f64) -> (f64, f64) {
let zt = top.unwrap_or(floor_top);
(bottom.unwrap_or_else(|| zt - thickness()), zt)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn wand_stuetze_und_decke() {
// Geschoss-Basis + Höhe; Bindungen übersteuern UK/OK unabhängig.
assert_eq!(element(0.0, None, None, 3.0), (0.0, 3.0));
assert_eq!(element(0.0, Some(0.5), Some(floor_anchor(3.0, 0.0)), 3.0), (0.5, 3.0));
assert_eq!(element(2.8, Some(1.0), None, 2.0), (1.0, 3.0));
// Decke: OK = Geschoss-Oberkante, UK = OK − Dicke; die Dicke nur ohne UK-Bindung.
assert_eq!(ceiling(2.6, None, None, || 0.25), (2.35, 2.6));
assert_eq!(ceiling(2.6, Some(2.2), None, || panic!("Dicke nicht gebraucht")), (2.2, 2.6));
assert_eq!(ceiling(2.6, None, Some(3.0), || 0.2), (2.8, 3.0));
assert_eq!(floor_anchor(2.8, 0.1), 2.8 + 0.1);
}
}
}
+1 -10
View File
@@ -12,16 +12,7 @@ pub const PEN_FALLBACK_COLOR: &str = "#9aa0a6";
/// Strichstärke (mm) eines Stifts ohne Eintrag.
pub const PEN_FALLBACK_WEIGHT: f64 = 0.18;
/// JS-Wahrheitswert (`if (x.colorPenId)`).
fn truthy(v: Option<&Value>) -> bool {
match v {
None | Some(Value::Null) => false,
Some(Value::Bool(b)) => *b,
Some(Value::Number(n)) => n.as_f64().is_some_and(|f| f != 0.0 && !f.is_nan()),
Some(Value::String(s)) => !s.is_empty(),
Some(_) => true,
}
}
use crate::grips::truthy;
/// Schlüssel des Stifts als Objekt-Schlüssel (JS: `pens[penId]`, eine Zahl wird zu Text).
fn key_of(v: &Value) -> Option<String> {
+1 -11
View File
@@ -32,17 +32,7 @@ pub enum Parsed {
Err(String),
}
/// JS-`String(v)` für die Meldungen.
fn js_string(v: &Value) -> String {
match v {
Value::Null => "null".into(),
Value::Bool(b) => b.to_string(),
Value::Number(n) => n.as_f64().map_or(n.to_string(), crate::js_fmt::js_number),
Value::String(s) => s.clone(),
Value::Array(a) => a.iter().map(|x| if x.is_null() { String::new() } else { js_string(x) }).collect::<Vec<_>>().join(","),
Value::Object(_) => "[object Object]".into(),
}
}
use crate::js_fmt::js_string;
/// 1 → 2: Legacy-Türen (`doors`) werden zu Öffnungen (`openings`, kind `door`).
fn migrate_doors(mut raw: Map<String, Value>) -> Map<String, Value> {
+1 -7
View File
@@ -30,13 +30,7 @@ use crate::model::{Project, SiaCategory};
pub const DEFAULT_TOLERANCE: f64 = 0.05;
fn finite(v: f64) -> f64 {
if v.is_finite() {
v
} else {
0.0
}
}
use crate::jsnum::or_zero as finite;
fn cat_name(c: SiaCategory) -> &'static str {
match c {
+6 -27
View File
@@ -15,7 +15,8 @@
//! Der B-Rep-Körper einer Extrusion (`spec`) bleibt in TS (truck-Pipeline, `plan/extrudedSolidSpec.ts`).
use crate::document::Lookup;
use crate::grips::{field, js_num, num_of, truthy, xy};
use crate::model::helpers::heights;
use crate::grips::{arr, field, js_num, num_of, truthy, xy};
use crate::jsmath::hypot2;
use crate::jsnum;
use crate::ops::id_of;
@@ -134,10 +135,6 @@ impl O {
}
}
fn arr(v: Option<&Value>) -> &[Value] {
v.and_then(Value::as_array).map(Vec::as_slice).unwrap_or(&[])
}
/// Erstes Element, dessen Feld `key` gleich `val` ist (`===`; fehlend gleich fehlend).
fn find_by<'a>(list: &'a [Value], key: &str, val: Option<&Value>) -> Option<&'a Value> {
list.iter().find(|e| field(e, key) == val)
@@ -152,17 +149,6 @@ fn str_of(v: Option<&Value>) -> Option<&str> {
v.and_then(Value::as_str)
}
/// `String(v)` für die Anzeige (Name eines Geschosses).
fn js_string(v: &Value) -> Value {
match v {
Value::String(_) => v.clone(),
Value::Number(n) => Value::from(crate::js_fmt::js_number(n.as_f64().unwrap_or(f64::NAN))),
Value::Null => Value::from("null"),
Value::Bool(b) => Value::from(if *b { "true" } else { "false" }),
_ => Value::from("[object Object]"),
}
}
/// Kategorie (Ebene) per Code: erster Treffer der Tiefensuche (`findCategory`).
fn category<'a>(root: &'a Map<String, Value>, code: Option<&Value>) -> Option<&'a Value> {
fn walk<'a>(list: &'a [Value], code: Option<&Value>) -> Option<&'a Value> {
@@ -186,10 +172,7 @@ fn component<'a>(root: &'a Map<String, Value>, id: Option<&Value>) -> Result<&'a
/// Wert in einer Template-Zeichenkette (`${v}`).
fn js_text(v: &Value) -> String {
match js_string(v) {
Value::String(s) => s,
_ => String::new(),
}
crate::js_fmt::js_string(v)
}
/// `x.color ?? cat?.color ?? fallback`.
@@ -305,7 +288,7 @@ fn anchor(root: &Map<String, Value>, a: Option<&Value>) -> Option<f64> {
return nn(field(a, "z")).map(|z| num_of(Some(z)));
}
let f = level(root, field(a, "floorId"))?;
Some(num_or(field(f, "baseElevation"), 0.0) + num_or(field(a, "offset"), 0.0))
Some(heights::floor_anchor(num_or(field(f, "baseElevation"), 0.0), num_or(field(a, "offset"), 0.0)))
}
fn num_or(v: Option<&Value>, d: f64) -> f64 {
@@ -319,18 +302,14 @@ fn num_or(v: Option<&Value>, d: f64) -> f64 {
/// (UK, OK) einer Wand oder Stütze: UK aus `bottom` sonst Geschoss-Basis, OK aus `top` sonst UK + Höhe.
fn vertical_extent(root: &Map<String, Value>, el: &Value) -> (f64, f64) {
let floor_base = level(root, field(el, "floorId")).map_or(0.0, |f| num_or(field(f, "baseElevation"), 0.0));
let zb = anchor(root, field(el, "bottom")).unwrap_or(floor_base);
let zt = anchor(root, field(el, "top")).unwrap_or(zb + num_of(field(el, "height")));
(zb, zt)
heights::element(floor_base, anchor(root, field(el, "bottom")), anchor(root, field(el, "top")), num_of(field(el, "height")))
}
/// (UK, OK) einer Decke (`ceilingVerticalExtent`): OK aus `top` sonst Geschoss-Oberkante (Basis + Höhe), UK aus
/// `bottom` sonst OK − `thickness` (die Decke wächst nach unten).
fn ceiling_extent(root: &Map<String, Value>, c: &Value, thickness: f64) -> (f64, f64) {
let floor_top = level(root, field(c, "floorId")).map_or(0.0, |f| num_or(field(f, "baseElevation"), 0.0) + num_or(field(f, "floorHeight"), 0.0));
let zt = anchor(root, field(c, "top")).unwrap_or(floor_top);
let zb = anchor(root, field(c, "bottom")).unwrap_or(zt - thickness);
(zb, zt)
heights::ceiling(floor_top, anchor(root, field(c, "bottom")), anchor(root, field(c, "top")), || thickness)
}
/// Anfrage `verticalExtents`: Wände und Decken als ganze Elemente (die 3D-Griffe zeigen auch gerade gezogene,
-5
View File
@@ -27,11 +27,6 @@ pub fn bulge_from_sagitta_point(ax: f64, ay: f64, bx: f64, by: f64, px: f64, py:
b::from_sagitta_point(ax, ay, bx, by, px, py)
}
#[wasm_bindgen]
pub fn bulge_between_angles(cx: f64, cy: f64, r: f64, a_from: f64, a_to: f64, sweep_sign: f64) -> f64 {
b::between_angles(cx, cy, r, a_from, a_to, sweep_sign)
}
/// `[x, y]` auf dem Bogen bei t∈[0,1].
#[wasm_bindgen]
pub fn bulge_point_at(ax: f64, ay: f64, bx: f64, by: f64, bulge: f64, t: f64) -> Vec<f64> {
+4 -10
View File
@@ -174,15 +174,9 @@ pub fn doc_json(h: u32) -> String {
with_doc(h, |d| d.to_json()).unwrap_or_default()
}
/// Abfrage auf dem typisierten Projekt; Ergebnis als JSON. Fehler (Dokument nicht offen, Modell
/// passt nicht, unbekannte Abfrage, Rechenfehler) kommen als Text mit vorangestelltem `\u{1}`.
/// Abfragen s. `crate::queries`.
#[wasm_bindgen]
pub fn doc_query(h: u32, name: &str) -> String {
doc_query_args(h, name, &[], "")
}
/// Wie [`doc_query`] mit Zahlen- und Textargument.
/// Abfrage auf dem typisierten Projekt mit Zahlen- und Textargument; Ergebnis als JSON. Fehler (Dokument
/// nicht offen, Modell passt nicht, unbekannte Abfrage, Rechenfehler) kommen als Text mit vorangestelltem
/// `\u{1}`. Abfragen s. `crate::queries`.
#[wasm_bindgen]
pub fn doc_query_args(h: u32, name: &str, args: &[f64], text: &str) -> String {
let result = with_doc(h, |d| {
@@ -196,7 +190,7 @@ pub fn doc_query_args(h: u32, name: &str, args: &[f64], text: &str) -> String {
}
}
/// Abfrage auf der rohen Projekt-Wurzel (`crate::queries::run_root`); Fehler wie bei [`doc_query`].
/// Abfrage auf der rohen Projekt-Wurzel (`crate::queries::run_root`); Fehler wie bei [`doc_query_args`].
#[wasm_bindgen]
pub fn doc_query_root(h: u32, name: &str, text: &str) -> String {
let result = with_doc(h, |d| crate::queries::run_root(&d.lookup(), name, text)).unwrap_or_else(|| Err("Dokument nicht offen".to_string()));
-16
View File
@@ -1,16 +0,0 @@
//! Bindungen der 2D-Zeichnungen im 3D (`crate::drawing2d_3d`). Kodierung s. dort.
use crate::drawing2d_3d as d;
use wasm_bindgen::prelude::wasm_bindgen;
/// LineList-Vertices `[px, höhe, py, r, g, b]` (zwei je Segment) einer Charge.
#[wasm_bindgen]
pub fn drawing3d_line_verts(drawings: &[f64]) -> Vec<f32> {
d::line_verts(drawings)
}
/// Pick-Strecken `[ax, ay, bx, by, baseElevation, zeichnung]` einer Charge.
#[wasm_bindgen]
pub fn drawing3d_pick_segs(drawings: &[f64], tolerance: f64) -> Vec<f64> {
d::pick_segs(drawings, tolerance)
}
-13
View File
@@ -75,16 +75,3 @@ pub fn hatch_line_family_flat(poly: &[f64], angle_rad: f64, spacing_m: f64, offs
segs_out(&hatch::hatch_line_family(&pts(poly), angle_rad, spacing_m, offset_m, v2(ax, ay)))
}
/// `len_min`/`len_max` NaN = nicht gesetzt.
#[wasm_bindgen]
pub fn scatter_strokes_flat(
poly: &[f64],
cell: f64,
base_angle_rad: f64,
seed: f64,
stroke_len: f64,
len_min: f64,
len_max: f64,
) -> Vec<f64> {
runs_out(&hatch::scatter_strokes(&pts(poly), cell, base_angle_rad, seed, stroke_len, opt(len_min), opt(len_max)))
}
-7
View File
@@ -15,7 +15,6 @@ mod stair;
mod room_area;
mod room_boundary;
mod polygon_holes;
mod drawing2d_3d;
mod plan_buf;
mod project_format;
mod gpu_compile;
@@ -46,9 +45,3 @@ use wasm_bindgen::prelude::wasm_bindgen;
pub fn start() {
console_error_panic_hook::set_once();
}
/// Version des Kern-Moduls (für Diagnose/Startprotokoll).
#[wasm_bindgen]
pub fn core_version() -> String {
env!("CARGO_PKG_VERSION").to_string()
}