Merge branch 'worktree-agent-abca8f1c9f80d8eb4' into claude/practical-noether-1hb2s1

# Conflicts:
#	TODO.md
#	src-tauri/core/src/web/mod.rs
This commit is contained in:
Claude committed 2026-11-14 11:39:42 +00:00
commit 9fec52035b
15 files changed
+1207 -91

No files matched your search

+14 -4
View File
@@ -89,10 +89,20 @@ Kennwort, anonym) als PDF; Austausch mit Fachplanern über DXF/IFC.
`while sweep <= 0 { sweep += 2π }` bei Winkeln ±1e300 (`svg.rs`, `stamp_place`, `drawing_recognize`, `magic_wand`, `stair_symbol`) durch
`rem_euclid` ersetzt; Obergrenzen für Massstabsbalken-Segmente, Strahlen der Böschungsschraffur, Höhenlinien-Beschriftung, Strichzerlegung
(`dxf::dash_seg`), Blasen-Verschiebung, Wendeltreppen-Vorschau, Raster in `context_ground` (Koordinaten ~1e17). Je ein `regression_*`-Fall.
**Offen:** Seeds: 20 weitere (1001–1020) sauber, aber nur ein
Seed je Lauf (Suche mit anderen Seeds von Hand); Speicher-Abbruch (`handle_alloc_error`) lässt sich nicht per
`catch_unwind` fangen, der Test bricht dann den ganzen Lauf ab; WASM-Bindungen (`web/`) und TS-Seite nicht abgedeckt; Rust-Panic im WASM selbst
nicht gemessen ([118] bleibt Wiederanlauf). · M
**Bindungen 14.11.:** `src-tauri/core/tests/robustness_web.rs` (Feature `web`; `web` ist dafür `pub`+`doc(hidden)`, die wasm-bindgen-Funktionen laufen nativ
als gewöhnliche Rust-Funktionen) ruft ALLE 190 `#[wasm_bindgen]`-Einstiege in `src/web/*.rs` je Seed-Lauf N-mal mit kaputten Eingaben (leere/abgeschnittene/
verdorbene Flat-Puffer, Zähler -1/1e9/NaN/∞, Zufallsbits, ungültiges/abgeschnittenes/verdorbenes Projekt-JSON, falsche Handles/ids, Zufallsbytes) unter `catch_unwind`
samt 30-s-Wächter (Endlosschleife) auf; `jede_bindung_ist_abgedeckt` schlägt fehl, wenn eine neue Bindung nicht in `CALLS` steht (`ROBUST_WEB_N/SEED/ONLY/SKIP/TRACE/DUMP`,
Kopf der Datei; von Hand mit `ulimit -v 6000000`, dann wird ein Speicher-Abbruch zur Meldung statt Absturz des Rechners). Gefunden und behoben (je `regression_*`):
usize-Überlauf bei gesättigten Zählern (`grip_coincident`, `contour_marks`, `decode_step`, `smooth_grid`: 1e300 → `usize::MAX`, `1 + 2·n` lief über → Slice-Panic);
Schraffur (`hatchgen`): Schleifen mit `k += 1.0` bei Indizes ≥ 2^53 (Linienschar, Zufallslinien, Erde/Kies/Streuung, Band-/Punktmuster) → Zählschleife `fseq`/Grenzen,
Linienschar/Strichzerlegung/Zickzack/Motiv mit Obergrenzen, Streuraster bei langen dünnen Flächen (Milliarden Zellen in einer Zeile); Dach: Skelett-Wellenfront lief in einen
Rundungszyklus (Ecken-Obergrenze `32·n+256` → Degeneration/Rückfall); Treppe: `split_steps` sättigte bei Lauflänge `f64::MAX` zu `i64::MAX` Tritten (Speicher-Abbruch);
Delaunay: Koordinaten > 1e60 (Hülle inkonsistent, Endlosschleife). Dazu `render2d/tests/robustness.rs` (Szene lesen → `compile_scene`, Textzeilen, WOFF2, Zerlegung, Strichphase)
und `render3d/tests/robustness.rs` (verdorbenes Teile-Update → `Scene::apply`/`chunk_data`/`cut_section`): beide sauber (100000 bzw. 30000 Läufe je Seed), keine Befunde.
**Offen:** Speicher-Abbruch (`handle_alloc_error`) lässt sich nicht per `catch_unwind` fangen (der Test bricht dann den ganzen Lauf ab; im WASM ein Trap wie ein Panic);
`WebModelRenderer`/`WebRenderer` (GPU, Canvas: `set_model`, `set_scene_bin` …) nur über ihre GPU-freien Leser abgedeckt, nicht als Ganzes; die Ausgangsdaten der Bindungsläufe sind
flach/zufällig (Tiefenprüfung der Dokument-Ops mit gültigen Op-Strukturen fehlt); TS-Seite nicht abgedeckt; Rust-Panic im WASM selbst nicht gemessen ([118] bleibt Wiederanlauf). · M
- ◐ **[116]** Datensicherheit, Audit (14.11.): Speichern/Autosave/Wiederherstellen/Schliessen. Test zuerst, Befunde behoben: (1) **Schliessen ohne Rückfrage:**
Fenster zu, Cmd+Q, Electron-Schliessen und Browser-Tab verwarfen ungespeicherte Änderungen (nur die 30-s-Kopie blieb). Jetzt `registerCloseGuard`
(`native/projectFile.ts`): Tauri `onCloseRequested` → Overlay „Ungespeicherte Änderungen" (wie Neu/Öffnen), danach `destroy`; Cmd+Q ist ein eigener
+11 -1
View File
@@ -314,7 +314,9 @@ impl State<'_> {
pub fn triangulate(coords: &[f64]) -> Vec<u32> {
let n = coords.len() >> 1;
if n < 3 || coords.len() != 2 * n || coords.iter().any(|v| !v.is_finite()) {
// Obergrenze der Koordinaten ([258]): darüber laufen Abstandsquadrate/Umkreisprodukte über (∞/NaN), die Hülle
// wird inkonsistent und die Suchschleifen drehen endlos. Kartenkoordinaten bleiben weit darunter.
if n < 3 || coords.len() != 2 * n || coords.iter().any(|v| !(v.abs() <= 1e60)) {
return Vec::new();
}
let max_triangles = if n * 2 >= 5 { 2 * n - 5 } else { 0 };
@@ -522,6 +524,14 @@ mod tests {
assert_eq!(t.len(), 6);
}
/// [258] Riesige Koordinaten (Quadrate laufen über): leer statt Endlosschleife.
#[test]
fn regression_riesige_koordinaten() {
assert!(triangulate(&[0.0, 0.0, 1e300, 0.0, 0.0, 1e300, 1e300, 1e300, 5e299, 5e299]).is_empty());
assert!(triangulate(&[0.0, 0.0, f64::MAX, 0.0, 0.0, f64::MAX, 1.0, 1.0]).is_empty());
assert_eq!(triangulate(&[0.0, 0.0, 1e6, 0.0, 0.0, 1e6]).len(), 3);
}
#[test]
fn kollinear_und_zu_wenig_sind_leer() {
assert!(triangulate(&[0.0, 0.0, 1.0, 1.0, 2.0, 2.0]).is_empty());
+12 -2
View File
@@ -478,7 +478,7 @@ pub fn decode_mesh(f: &[f64], strings: &[String]) -> Result<(Vec<MeshObject>, Va
let color = (h[2] == 1.0).then(|| vec![h[3], h[4], h[5], h[6]]);
let (np, ni) = (h[7], h[8]);
at += 9;
if !(np.fract() == 0.0 && ni.fract() == 0.0 && np >= 0.0 && ni >= 0.0) || at + np as usize + ni as usize > f.len() {
if !(np.fract() == 0.0 && ni.fract() == 0.0 && np >= 0.0 && ni >= 0.0) || np + ni > (f.len() - at) as f64 {
return Err("Mesh-Import: Puffer beschädigt".into());
}
let positions: Vec<f64> = f[at..at + np as usize].to_vec();
@@ -617,7 +617,7 @@ pub fn decode_step(f: &[f64]) -> Result<Vec<(Vec<f32>, Vec<f64>)>, String> {
let h = f.get(at..at + 2).ok_or_else(bad)?;
let (np, ni) = (h[0], h[1]);
at += 2;
if !(np.fract() == 0.0 && ni.fract() == 0.0 && np >= 0.0 && ni >= 0.0) || at + np as usize + ni as usize > f.len() {
if !(np.fract() == 0.0 && ni.fract() == 0.0 && np >= 0.0 && ni >= 0.0) || np + ni > (f.len() - at) as f64 {
return Err(bad());
}
let positions = f[at..at + np as usize].iter().map(|&x| x as f32).collect();
@@ -657,6 +657,16 @@ pub fn step_meshes(bodies: &[(Vec<f32>, Vec<f64>)], file_name: &str, now: f64) -
mod step_tests {
use super::*;
/// [258] Zähler 1e300 / 1e19 (saturieren zu usize::MAX, Summe lief über): Fehler statt Slice-Panic.
#[test]
fn regression_decode_step_riesige_zaehler() {
for n in [1e300, 1e19, 9.3e18] {
assert!(decode_step(&[1.0, 1.0, n, 0.0, 1.0]).is_err());
assert!(decode_step(&[1.0, 1.0, 1.0, n, 1.0]).is_err());
assert!(decode_step(&[1.0, 1.0, n, n, 1.0]).is_err());
}
}
fn flat() -> Vec<f64> {
// zwei Körper: Dreieck mit 0.1f32 (nicht exakt in f64), Dreieck mit ganzen Zahlen
let mut f = vec![1.0, 2.0, 9.0, 3.0];
+2 -1
View File
@@ -147,7 +147,8 @@ pub mod dim_assoc;
pub mod opening_slide;
#[cfg(feature = "web")]
mod web;
#[doc(hidden)]
pub mod web;
pub mod presentation_sheet;
pub mod drawing_recognize;
pub mod kosten;
+9 -1
View File
@@ -281,7 +281,7 @@ pub fn contour_marks(flat: &[f64]) -> Vec<f64> {
let mut i = 5;
while i + 3 <= flat.len() {
let (z, closed, n) = (flat[i], flat[i + 1] != 0.0, flat[i + 2]);
if !(n >= 0.0 && n.fract() == 0.0) || i + 3 + 2 * (n as usize) > flat.len() {
if !(n >= 0.0 && n.fract() == 0.0) || n > ((flat.len() - i - 3) / 2) as f64 {
return vec![];
}
let pts = flat[i + 3..i + 3 + 2 * (n as usize)].chunks_exact(2).map(|c| [c[0], c[1]]).collect();
@@ -332,6 +332,14 @@ fn ridge_pitch(r: &Value, eave: f64, rise: f64) -> Option<f64> {
mod tests {
use super::*;
/// [258] Punktzahl 1e300 (saturiert zu usize::MAX, `2 * n` lief über → Slice-Panic): leer statt Panic.
#[test]
fn regression_contour_marks_riesige_punktzahl() {
for n in [1e300, 1e19, 4e18, 1e9, f64::INFINITY, f64::NAN, -1.0, 0.5] {
assert!(contour_marks(&[0.0, 0.0, 1.0, 0.0, f64::NAN, 10.0, 1.0, n, 0.0, 0.0]).is_empty());
}
}
fn root() -> Map<String, Value> {
json!({
"drawingLevels": [
+4
View File
@@ -524,6 +524,10 @@ pub fn faces(rings: &[Vec<P2>], speeds: &[f64], budget: Option<usize>) -> Result
}
budget = budget.checked_sub(1).ok_or(SkeletonError::Budget)?;
w.step(e);
// Ecken wachsen höchstens linear mit n; darüber läuft die Front in einen Rundungs-Zyklus ([258]).
if w.corners.len() > 32 * n + 256 {
w.broken = true;
}
}
let left: Vec<&Corner> = w.corners.iter().filter(|c| c.alive).collect();
if !w.broken && !left.is_empty() && left.iter().all(|c| w.edges[c.left].speed <= 0.0 && w.edges[c.right].speed <= 0.0) {
+10 -1
View File
@@ -1020,7 +1020,7 @@ pub fn datum(reference_masl: Option<f64>, z: &[f64]) -> f64 {
/// Binomialfilters [1 2 1]/4 je Achse. Fehlende Nachbarn zählen nicht (Gewichte werden renormiert), fehlende
/// Zellen bleiben fehlend. Falsche Grösse → Eingabe unverändert.
pub fn smooth_grid(z: &[f64], nx: usize, ny: usize, passes: u32) -> Vec<f64> {
if nx == 0 || ny == 0 || z.len() != nx * ny {
if nx == 0 || ny == 0 || nx.checked_mul(ny) != Some(z.len()) {
return z.to_vec();
}
let mut cur = z.to_vec();
@@ -1100,6 +1100,15 @@ pub fn resmooth_grid_mesh(positions: &[f64], passes: u32) -> Option<Vec<f64>> {
#[cfg(test)]
mod tests {
/// [258] Rastergrösse nx · ny läuft über (usize-Wrap passte zur Länge → Index-Panic): Eingabe unverändert.
#[test]
fn regression_smooth_grid_ueberlauf() {
let z = [1.0, 2.0];
assert_eq!(smooth_grid(&z, (1usize << 63) + 1, 2, 1), z.to_vec());
assert_eq!(smooth_grid(&z, usize::MAX, usize::MAX, 1), z.to_vec());
assert_eq!(smooth_grid(&z, 3, 1, 1), z.to_vec());
}
use super::*;
/// [137] Raster-Gelände neu glätten: Raster erkannt, nur z ändert sich, Spitze wird flacher; additiv
+12 -2
View File
@@ -198,10 +198,11 @@ pub fn grip_coincident(corners: &[f64], groups: &[f64]) -> Vec<f64> {
if !(n >= 0.0 && n.fract() == 0.0) {
return vec![];
}
let end = i + 1 + 2 * n as usize;
if end > groups.len() {
// Als f64 prüfen: `n as usize` sättigt bei 1e300, `1 + 2 * n` liefe über ([258]).
if n > ((groups.len() - i - 1) / 2) as f64 {
return vec![];
}
let end = i + 1 + 2 * n as usize;
gs.push(pts(&groups[i + 1..end]));
i = end;
}
@@ -212,6 +213,15 @@ pub fn grip_coincident(corners: &[f64], groups: &[f64]) -> Vec<f64> {
mod tests {
use super::*;
/// [258] Gruppengrösse 1e300 / 1e19: leer statt Slice-Panic durch usize-Überlauf.
#[test]
fn regression_coincident_riesige_gruppe() {
for n in [1e300, 1e19, 9.3e18, 4e18, f64::INFINITY] {
assert!(grip_coincident(&[0.0, 0.0], &[n, 0.0, 0.0]).is_empty());
assert!(grip_coincident(&[0.0, 0.0], &[1.0, 0.0, 0.0, n, 0.0, 0.0]).is_empty());
}
}
#[test]
fn kaputte_puffer_leer() {
assert!(grip_coincident(&[0.0, 0.0], &[3.0, 1.0]).is_empty());
+48 -48
View File
@@ -3,54 +3,54 @@
//! Kaputte Eingaben ergeben ein leeres Ergebnis statt eines Panics (ein Panic legt das ganze
//! WASM-Modul lahm, [14]).
mod kernel2d;
mod polygon;
mod roof;
mod sun;
mod site_rules;
mod kennzahlen;
mod bulge;
mod stair;
mod room_area;
mod room_boundary;
mod polygon_holes;
mod plan_buf;
mod project_format;
mod gpu_compile;
mod delaunay;
mod document;
mod ops;
mod voids;
mod curves;
mod hatch;
mod skeleton;
mod plan_scene;
mod plan_pick;
mod snap;
mod plan_svg;
mod plan_dxf;
mod plan_print_svg;
mod layers;
mod pens;
mod layout_model;
mod clash_broad;
mod parametric_walls;
mod reorder;
mod text_layout;
mod grips;
mod grip_drag;
mod competition;
mod project_refs;
mod commands;
mod import;
mod cmd_create;
mod area_report;
mod rich_text;
mod geo_mesh;
mod opening_presets;
mod furniture_lib;
mod solid_bool;
mod line_pattern;
pub mod kernel2d;
pub mod polygon;
pub mod roof;
pub mod sun;
pub mod site_rules;
pub mod kennzahlen;
pub mod bulge;
pub mod stair;
pub mod room_area;
pub mod room_boundary;
pub mod polygon_holes;
pub mod plan_buf;
pub mod project_format;
pub mod gpu_compile;
pub mod delaunay;
pub mod document;
pub mod ops;
pub mod voids;
pub mod curves;
pub mod hatch;
pub mod skeleton;
pub mod plan_scene;
pub mod plan_pick;
pub mod snap;
pub mod plan_svg;
pub mod plan_dxf;
pub mod plan_print_svg;
pub mod layers;
pub mod pens;
pub mod layout_model;
pub mod clash_broad;
pub mod parametric_walls;
pub mod reorder;
pub mod text_layout;
pub mod grips;
pub mod grip_drag;
pub mod competition;
pub mod project_refs;
pub mod commands;
pub mod import;
pub mod cmd_create;
pub mod area_report;
pub mod rich_text;
pub mod geo_mesh;
pub mod opening_presets;
pub mod furniture_lib;
pub mod solid_bool;
pub mod line_pattern;
use wasm_bindgen::prelude::wasm_bindgen;
+569
View File
@@ -0,0 +1,569 @@
//! [258] Robustheit der WASM-Bindungen (`src/web/*.rs`, Feature "web"): jede `#[wasm_bindgen]`-Funktion wird
//! nativ mit kaputten Eingaben aufgerufen (leere/abgeschnittene Flat-Puffer, falsche Zähler, NaN/Inf/±1e300,
//! Zufallsbits, ungültiges JSON, falsche ids/Handles). Erwartung: leeres Ergebnis oder Fehler, nie Panic —
//! ein Panic legt im Browser das ganze WASM-Modul lahm. Deterministisch (fester Seed, eigener PRNG),
//! jeder Aufruf unter `catch_unwind`, alle Panics gesammelt gemeldet.
//!
//! Lauf: `cargo test --release --features web --test robustness_web`.
//! `ROBUST_WEB_N` (Aufrufe je Funktion, Standard 60), `ROBUST_WEB_SEED`, `ROBUST_WEB_ONLY=<Teilname>`,
//! `ROBUST_WEB_TRACE=1` (jeden Aufruf melden). Die Liste `CALLS` bildet jede Bindung ab;
//! `jede_bindung_ist_abgedeckt` prüft sie gegen die Quellen.
#![cfg(feature = "web")]
use dossier_core::web;
use std::cell::Cell;
use std::collections::BTreeMap;
use std::panic::{catch_unwind, AssertUnwindSafe};
const FIXTURE: &str = include_str!("fixtures/robust/beispiel.json");
thread_local! {
static HANDLE: Cell<u32> = const { Cell::new(0) };
/// Von Hand (`ROBUST_WEB_DUMP=<Teilname>#<Aufruf>`): die erzeugten Puffer/Texte des Aufrufs vor dem Aufruf ausgeben.
static DUMP: Cell<bool> = const { Cell::new(false) };
static LAST: std::cell::RefCell<String> = const { std::cell::RefCell::new(String::new()) };
}
pub struct Rng(u64);
impl Rng {
fn next(&mut self) -> u64 {
self.0 ^= self.0 >> 12;
self.0 ^= self.0 << 25;
self.0 ^= self.0 >> 27;
self.0.wrapping_mul(0x2545_F491_4F6C_DD1D)
}
fn below(&mut self, n: usize) -> usize {
if n == 0 { 0 } else { (self.next() % n as u64) as usize }
}
fn unit(&mut self) -> f64 {
(self.next() >> 11) as f64 / (1u64 << 53) as f64
}
/// Einzelne Zahl: Randwerte, kleine Werte, Zufallsbits.
fn f64(&mut self) -> f64 {
let v = self.f64_inner();
if DUMP.with(|d| d.get()) {
eprintln!("ARG f64 {v:?}");
}
v
}
fn f64_inner(&mut self) -> f64 {
const POOL: [f64; 18] = [0.0, -0.0, 1.0, -1.0, 0.5, 1e-9, -1e-9, 1e9, -1e9, 1e300, -1e300, f64::NAN, f64::INFINITY, f64::NEG_INFINITY, f64::MAX, f64::MIN_POSITIVE, 3.0, 2.0];
match self.below(4) {
0 => POOL[self.below(POOL.len())],
1 => f64::from_bits(self.next()),
2 => self.below(10) as f64,
_ => (self.unit() - 0.5) * 100.0,
}
}
pub fn id(&mut self) -> u32 {
match self.below(6) {
0 => 0,
1 => u32::MAX,
2 => self.below(5) as u32,
_ => HANDLE.with(|h| h.get()),
}
}
fn u32s(&mut self) -> Vec<u32> {
(0..self.below(12)).map(|_| if self.below(3) == 0 { u32::MAX } else { self.below(40) as u32 }).collect()
}
fn bytes(&mut self) -> Vec<u8> {
let n = if self.below(4) == 0 { 0 } else { self.below(300) };
let mut v: Vec<u8> = (0..n).map(|_| self.next() as u8).collect();
// Manchmal ein Kopf, der echten Formaten ähnelt (PNG/ZIP/gzip/PDF/DXF/JSON).
if !v.is_empty() && self.below(3) == 0 {
let heads: [&[u8]; 6] = [b"\x89PNG\r\n\x1a\n", b"PK\x03\x04", b"\x1f\x8b\x08", b"%PDF-1.", b" 0\nSECTION\n", b"{\"a\":"];
let h = heads[self.below(heads.len())];
for (i, b) in h.iter().enumerate() {
if i < v.len() {
v[i] = *b;
}
}
}
v
}
fn opt_text(&mut self) -> Option<String> {
if self.below(2) == 0 { None } else { Some(self.text()) }
}
/// Text: leer, kaputtes/fremdes JSON, Zufallsbytes, das Beispielprojekt (ganz/abgeschnitten/verdorben).
fn text(&mut self) -> String {
let t = self.text_inner();
if DUMP.with(|d| d.get()) {
eprintln!("ARG text {:?}", &t[..t.len().min(300)]);
}
t
}
fn text_inner(&mut self) -> String {
const POOL: [&str; 26] = [
"", " ", "{", "}", "[", "null", "[]", "{}", "0", "-1", "1e999", "NaN", "\"", "\u{0}", "\u{feff}{}",
"{\"id\":\"x\"}", "{\"id\":\"\",\"type\":\"wall\"}", "[{\"id\":\"a\"},{\"id\":\"a\"}]", "{\"floors\":[],\"walls\":[]}",
"{\"floors\":null}", "[1,2,3]", "{\"ops\":[{\"op\":\"remove\",\"id\":\"nix\"}]}", "[{\"op\":\"set\",\"id\":\"w1\",\"patch\":{\"thickness\":1e300}}]",
"{\"kind\":\"wall\",\"points\":[[0,0],[1e300,1e300]]}", "{\"x\":null,\"y\":\"a\"}", "[[0,0],[1,1],[null,2]]",
];
match self.below(8) {
0 => String::new(),
1..=3 => POOL[self.below(POOL.len())].to_string(),
4 => {
let n = self.below(80);
let b: Vec<u8> = (0..n).map(|_| self.next() as u8).collect();
String::from_utf8_lossy(&b).into_owned()
}
5 => FIXTURE.to_string(),
6 => {
let mut c = self.below(FIXTURE.len());
while !FIXTURE.is_char_boundary(c) {
c -= 1;
}
FIXTURE[..c].to_string()
}
_ => {
// Beispielprojekt, an Zufallsstellen durch Unsinn ersetzt.
let mut s = FIXTURE.to_string();
for _ in 0..1 + self.below(4) {
let mut p = self.below(s.len());
while !s.is_char_boundary(p) {
p -= 1;
}
let mut e = (p + 1 + self.below(6)).min(s.len());
while !s.is_char_boundary(e) {
e += 1;
}
s.replace_range(p..e, ["null", "-1", "1e300", "\"x\"", "[]", "{}", "NaN"][self.below(7)]);
}
s
}
}
}
/// Flat-Puffer: leer, gültig kodierte Polygone (dann verdorben), falsche Zähler, NaN/Inf, Zufallsbits, Zufallszahlen.
fn buf(&mut self) -> Vec<f64> {
let v = self.buf_inner();
if DUMP.with(|d| d.get()) {
eprintln!("ARG buf {v:?}");
}
v
}
fn buf_inner(&mut self) -> Vec<f64> {
match self.below(8) {
0 => vec![],
1 => (0..self.below(40)).map(|_| self.f64()).collect(),
2 => (0..self.below(40)).map(|_| f64::from_bits(self.next())).collect(),
// Kleine ganze Zahlen treffen Zählerfelder oft plausibel.
3 => (0..self.below(60)).map(|_| self.below(6) as f64).collect(),
_ => {
let mut v = self.valid_flat();
match self.below(6) {
0 => {
let keep = self.below(v.len() + 1);
v.truncate(keep);
}
1 => {
if !v.is_empty() {
let i = self.below(v.len().min(4));
v[i] = [-1.0, 1e9, 1e18, f64::NAN, f64::INFINITY, 0.5, 4294967296.0][self.below(7)];
}
}
2 => {
for _ in 0..1 + self.below(3) {
if !v.is_empty() {
let i = self.below(v.len());
v[i] = self.f64();
}
}
}
3 => {
let extra: Vec<f64> = (0..self.below(10)).map(|_| self.f64()).collect();
v.extend(extra);
}
4 => {
if !v.is_empty() {
let i = self.below(v.len());
v[i] = f64::from_bits(self.next());
}
}
_ => {}
}
v
}
}
}
/// Gültige Kodierung `[n_polys, (n_rings, (n_pts, x, y …))]` mit zufälligen Ringen.
fn valid_flat(&mut self) -> Vec<f64> {
let mut v = vec![];
let np = self.below(3);
v.push(np as f64);
for _ in 0..np {
let nr = 1 + self.below(2);
v.push(nr as f64);
for _ in 0..nr {
let n = self.below(8);
v.push(n as f64);
for _ in 0..n {
v.push(self.unit() * 10.0);
v.push(self.unit() * 10.0);
}
}
}
v
}
}
// GENERIERT aus den `#[wasm_bindgen]`-Einstiegen in `src/web/*.rs`: je Zeile Modul::Name, Argumente nach Typ.
// Neue Einstiege von Hand ergänzen; `jede_bindung_ist_abgedeckt` schlägt sonst fehl.
type Call = (&'static str, fn(&mut Rng));
const CALLS: &[Call] = &[
("area_report::area_report_csv", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::area_report::area_report_csv(&a0, &a1); }),
("area_report::area_report_parse_csv", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::area_report::area_report_parse_csv(&a0, &a1); }),
("area_report::area_report_layout", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::area_report::area_report_layout(&a0, &a1); }),
("area_report::area_report_svg", |r: &mut Rng| { let a0 = r.text(); let a1 = r.id(); let a2 = r.text(); let _ = web::area_report::area_report_svg(&a0, a1, &a2); }),
("bulge::bulge_arc", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let _ = web::bulge::bulge_arc(a0, a1, a2, a3, a4); }),
("bulge::bulge_arc_points", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let _ = web::bulge::bulge_arc_points(a0, a1, a2, a3, a4); }),
("bulge::bulge_polyline_points", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.below(2) == 1; let _ = web::bulge::bulge_polyline_points(&a0, &a1, a2); }),
("bulge::bulge_from_sagitta_point", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::bulge::bulge_from_sagitta_point(a0, a1, a2, a3, a4, a5); }),
("bulge::bulge_point_at", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::bulge::bulge_point_at(a0, a1, a2, a3, a4, a5); }),
("bulge::wall_arc_band", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::bulge::wall_arc_band(a0, a1, a2, a3, a4, a5); }),
("clash_broad::clash_candidate_pairs", |r: &mut Rng| { let a0 = r.buf(); let _ = web::clash_broad::clash_candidate_pairs(&a0); }),
("cmd_create::doc_create_preview", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.buf(); let _ = web::cmd_create::doc_create_preview(a0, &a1, &a2); }),
("cmd_create::doc_create_preview_again", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let _ = web::cmd_create::doc_create_preview_again(a0, &a1); }),
("cmd_create::doc_create_query", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::cmd_create::doc_create_query(a0, &a1); }),
("cmd_create::extruded_solid_spec_json", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let _ = web::cmd_create::extruded_solid_spec_json(&a0, a1); }),
("cmd_create::terrain_from_contours_json", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::cmd_create::terrain_from_contours_json(&a0, &a1); }),
("cmd_create::terrain_from_contours_opts_json", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let _ = web::cmd_create::terrain_from_contours_opts_json(&a0, &a1, a2, a3, a4); }),
("cmd_create::terrain_resmooth_grid", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let _ = web::cmd_create::terrain_resmooth_grid(&a0, a1); }),
("cmd_create::terrain_smooth_grid", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::cmd_create::terrain_smooth_grid(&a0, a1, a2, a3); }),
("commands::doc_cmd_commit", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.text(); let a3 = r.f64(); let _ = web::commands::doc_cmd_commit(a0, &a1, &a2, a3); }),
("commands::doc_cmd_preview", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::commands::doc_cmd_preview(a0, &a1); }),
("commands::doc_cmd_query", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::commands::doc_cmd_query(a0, &a1); }),
("curves::curves_bezier_chain_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let _ = web::curves::curves_bezier_chain_flat(&a0, a1); }),
("curves::curves_catmull_rom_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.below(2) == 1; let a2 = r.f64(); let _ = web::curves::curves_catmull_rom_flat(&a0, a1, a2); }),
("curves::curves_uniform_bspline_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.below(2) == 1; let a2 = r.f64(); let _ = web::curves::curves_uniform_bspline_flat(&a0, a1, a2); }),
("delaunay::delaunay_flat", |r: &mut Rng| { let a0 = r.buf(); let _ = web::delaunay::delaunay_flat(&a0); }),
("document::doc_open", |r: &mut Rng| { let a0 = r.text(); let _ = web::document::doc_open(&a0); }),
("document::doc_load_file", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.f64(); let _ = web::document::doc_load_file(a0, &a1, a2); }),
("document::doc_load_json", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::document::doc_load_json(a0, &a1); }),
("document::doc_close", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_close(a0); }),
("document::doc_apply", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::document::doc_apply(a0, &a1); }),
("document::doc_commit", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.text(); let a3 = r.f64(); let _ = web::document::doc_commit(a0, &a1, &a2, a3); }),
("document::doc_undo", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_undo(a0); }),
("document::doc_redo", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_redo(a0); }),
("document::doc_jump_quiet", |r: &mut Rng| { let a0 = r.id(); let a1 = r.below(2) == 1; let _ = web::document::doc_jump_quiet(a0, a1); }),
("document::doc_history_seq", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_history_seq(a0); }),
("document::doc_history_state", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_history_state(a0); }),
("document::doc_history_label", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::document::doc_history_label(a0, &a1); }),
("document::doc_history_labels", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_history_labels(a0); }),
("document::doc_history_jump", |r: &mut Rng| { let a0 = r.id(); let a1 = r.id(); let _ = web::document::doc_history_jump(a0, a1); }),
("document::doc_history_clear", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_history_clear(a0); }),
("document::doc_history_limits", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let _ = web::document::doc_history_limits(a0, a1, a2); }),
("document::doc_history_index", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_history_index(a0); }),
("document::doc_history_step", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let _ = web::document::doc_history_step(a0, a1, a2); }),
("document::doc_history_import", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::document::doc_history_import(a0, &a1); }),
("document::doc_group_begin", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_group_begin(a0); }),
("document::doc_group_begin_keyed", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.f64(); let _ = web::document::doc_group_begin_keyed(a0, &a1, a2); }),
("document::doc_group_end", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_group_end(a0); }),
("document::doc_json", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_json(a0); }),
("document::doc_query_args", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.buf(); let a3 = r.text(); let _ = web::document::doc_query_args(a0, &a1, &a2, &a3); }),
("document::doc_query_root", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.text(); let _ = web::document::doc_query_root(a0, &a1, &a2); }),
("document::doc_drawing_line_verts", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.text(); let _ = web::document::doc_drawing_line_verts(a0, a1, &a2); }),
("document::doc_surface_pattern_lines", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.text(); let _ = web::document::doc_surface_pattern_lines(a0, a1, &a2); }),
("document::doc_serialize", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_serialize(a0); }),
("document::doc_serialize_with_ui", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::document::doc_serialize_with_ui(a0, &a1); }),
("document::doc_query_bin", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.buf(); let a3 = r.text(); let _ = web::document::doc_query_bin(a0, &a1, &a2, &a3); }),
("document::doc_last_extra", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_last_extra(a0); }),
("document::doc_last_hits", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::doc_last_hits(a0); }),
("document::__debug_panic", |r: &mut Rng| { let a0 = r.id(); let _ = web::document::__debug_panic(a0); }),
("competition::anonymity_findings", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::competition::anonymity_findings(&a0, &a1); }),
("furniture_lib::furniture_lib_catalog_json", |_r: &mut Rng| { let _ = web::furniture_lib::furniture_lib_catalog_json(); }),
("furniture_lib::furniture_lib_geometry_json", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let a2 = r.text(); let a3 = r.id(); let _ = web::furniture_lib::furniture_lib_geometry_json(&a0, &a1, &a2, a3); }),
("geo_mesh::geo_mesh_clip", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.buf(); let _ = web::geo_mesh::geo_mesh_clip(&a0, &a1, &a2); }),
("geo_mesh::geo_mesh_strip_soffits", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::geo_mesh::geo_mesh_strip_soffits(&a0, &a1); }),
("geo_mesh::geo_mesh_split", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let _ = web::geo_mesh::geo_mesh_split(&a0, &a1, a2); }),
("geo_mesh::geo_extrude_footprints", |r: &mut Rng| { let a0 = r.buf(); let _ = web::geo_mesh::geo_extrude_footprints(&a0); }),
("gpu_compile::gpu_compile_flat", |r: &mut Rng| { let a0 = r.bytes(); let a1 = r.id(); let a2 = r.id(); let a3 = r.f64(); let a4 = r.below(2) == 1; let a5 = r.id(); let _ = web::gpu_compile::gpu_compile_flat(&a0, a1, a2, a3, a4, a5); }),
("gpu_compile::gpu_compile_held", |r: &mut Rng| { let a0 = r.id(); let a1 = r.id(); let a2 = r.id(); let a3 = r.f64(); let a4 = r.below(2) == 1; let a5 = r.id(); let _ = web::gpu_compile::gpu_compile_held(a0, a1, a2, a3, a4, a5); }),
("gpu_compile::triangulate_flat", |r: &mut Rng| { let a0 = r.buf(); let _ = web::gpu_compile::triangulate_flat(&a0); }),
("grip_drag::grip_polar", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::grip_drag::grip_polar(a0, a1, a2, a3, a4, a5); }),
("grip_drag::grip_polar_point", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::grip_drag::grip_polar_point(a0, a1, a2, a3, a4, a5); }),
("grip_drag::grip_arc_wall_target", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let a7 = r.f64(); let a8 = r.f64(); let _ = web::grip_drag::grip_arc_wall_target(a0, a1, a2, a3, a4, a5, a6, a7, a8); }),
("grip_drag::grip_arc_wall_resize", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let a7 = r.f64(); let a8 = r.f64(); let _ = web::grip_drag::grip_arc_wall_resize(a0, a1, a2, a3, a4, a5, a6, a7, a8); }),
("grip_drag::grip_arc_wall_radius", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.below(2) == 1; let a6 = r.f64(); let a7 = r.f64(); let a8 = r.f64(); let _ = web::grip_drag::grip_arc_wall_radius(a0, a1, a2, a3, a4, a5, a6, a7, a8); }),
("grip_drag::grip_axis_lock", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.buf(); let a7 = r.f64(); let a8 = r.below(2) == 1; let _ = web::grip_drag::grip_axis_lock(a0, a1, a2, a3, a4, a5, &a6, a7, a8); }),
("grip_drag::grip_edge_target", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.below(2) == 1; let a5 = r.f64(); let a6 = r.f64(); let a7 = r.below(2) == 1; let a8 = r.f64(); let a9 = r.f64(); let a10 = r.below(2) == 1; let a11 = r.f64(); let a12 = r.f64(); let a13 = r.f64(); let _ = web::grip_drag::grip_edge_target(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13); }),
("grip_drag::grip_sheet_height", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.below(2) == 1; let _ = web::grip_drag::grip_sheet_height(a0, a1, a2, a3, a4, a5); }),
("grip_drag::grip_contour_marks", |r: &mut Rng| { let a0 = r.buf(); let _ = web::grip_drag::grip_contour_marks(&a0); }),
("grip_drag::grip_snap_height", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.buf(); let a2 = r.f64(); let _ = web::grip_drag::grip_snap_height(a0, &a1, a2); }),
("grip_drag::grip_opening_point", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let _ = web::grip_drag::grip_opening_point(a0, a1, a2, a3, a4, a5, a6); }),
("grip_drag::grip_opening_slide_sheet", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let a7 = r.f64(); let a8 = r.f64(); let a9 = r.f64(); let _ = web::grip_drag::grip_opening_slide_sheet(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); }),
("grip_drag::grip_clamp_inside", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.buf(); let _ = web::grip_drag::grip_clamp_inside(a0, a1, &a2); }),
("grip_drag::grip_stair_handle", |r: &mut Rng| { let a0 = r.below(2) == 1; let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let a7 = r.f64(); let _ = web::grip_drag::grip_stair_handle(a0, a1, a2, a3, a4, a5, a6, a7); }),
("grip_drag::grip_stair_param_points", |r: &mut Rng| { let a0 = r.buf(); let _ = web::grip_drag::grip_stair_param_points(&a0); }),
("grip_drag::grip_wall_points", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let _ = web::grip_drag::grip_wall_points(a0, a1, a2, a3, a4); }),
("grip_drag::grip_excavation_points", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let _ = web::grip_drag::grip_excavation_points(&a0, a1); }),
("grip_drag::grip_coincident", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::grip_drag::grip_coincident(&a0, &a1); }),
("grips::doc_grip_commit", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.text(); let a3 = r.f64(); let _ = web::grips::doc_grip_commit(a0, &a1, &a2, a3); }),
("grips::grip_vertices", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let _ = web::grips::grip_vertices(&a0, a1); }),
("grips::camera_grip_points", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let _ = web::grips::camera_grip_points(&a0, a1); }),
("grips::grip_vertices_polyline", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.below(2) == 1; let _ = web::grips::grip_vertices_polyline(&a0, &a1, a2); }),
("grips::edge_grips", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.below(2) == 1; let a2 = r.buf(); let a3 = r.below(2) == 1; let _ = web::grips::edge_grips(&a0, a1, &a2, a3); }),
("grips::polyline_vertex_info", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.below(2) == 1; let a3 = r.f64(); let _ = web::grips::polyline_vertex_info(&a0, &a1, a2, a3); }),
("hatch::hatch_runs_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::hatch::hatch_runs_flat(&a0, &a1); }),
("hatch::random_hatch_runs_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let _ = web::hatch::random_hatch_runs_flat(&a0, &a1, a2); }),
("hatch::dash_runs_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::hatch::dash_runs_flat(&a0, &a1); }),
("hatch::zigzag_points_flat", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::hatch::zigzag_points_flat(a0, a1, a2, a3, a4, a5); }),
("hatch::motif_points_flat", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.buf(); let a5 = r.f64(); let a6 = r.f64(); let _ = web::hatch::motif_points_flat(a0, a1, a2, a3, &a4, a5, a6); }),
("hatch::clip_line_to_polygon_flat", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.buf(); let _ = web::hatch::clip_line_to_polygon_flat(a0, a1, a2, a3, &a4); }),
("hatch::clip_segment_to_polygon_flat", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.buf(); let _ = web::hatch::clip_segment_to_polygon_flat(a0, a1, a2, a3, &a4); }),
("hatch::clip_polyline_to_polygon_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::hatch::clip_polyline_to_polygon_flat(&a0, &a1); }),
("hatch::hatch_line_family_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::hatch::hatch_line_family_flat(&a0, a1, a2, a3, a4, a5); }),
("import::import_drawing_summary", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.text(); let a2 = r.text(); let _ = web::import::import_drawing_summary(&a0, &a1, &a2); }),
("import::import_drawing_view", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.text(); let a2 = r.text(); let a3 = r.f64(); let _ = web::import::import_drawing_view(&a0, &a1, &a2, a3); }),
("import::import_drawing_meshes", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.text(); let a2 = r.text(); let a3 = r.f64(); let _ = web::import::import_drawing_meshes(&a0, &a1, &a2, a3); }),
("import::doc_import_drawing", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let a2 = r.text(); let a3 = r.text(); let a4 = r.text(); let a5 = r.text(); let a6 = r.f64(); let _ = web::import::doc_import_drawing(a0, &a1, &a2, &a3, &a4, &a5, a6); }),
("import::doc_import_ifc", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.buf(); let a3 = r.u32s(); let a4 = r.buf(); let a5 = r.text(); let a6 = r.text(); let a7 = r.f64(); let _ = web::import::doc_import_ifc(a0, &a1, &a2, &a3, &a4, &a5, &a6, a7); }),
("import::mesh_import_report", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.text(); let _ = web::import::mesh_import_report(&a0, &a1); }),
("import::doc_import_mesh", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let a2 = r.text(); let a3 = r.text(); let a4 = r.text(); let a5 = r.f64(); let _ = web::import::doc_import_mesh(a0, &a1, &a2, &a3, &a4, a5); }),
("import::doc_import_step", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let a2 = r.text(); let a3 = r.text(); let a4 = r.f64(); let _ = web::import::doc_import_step(a0, &a1, &a2, &a3, a4); }),
("import::pdf_page_info", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.text(); let _ = web::import::pdf_page_info(&a0, &a1); }),
("kennzahlen::kz_solid_volume", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::kennzahlen::kz_solid_volume(&a0, a1, a2, a3); }),
("kernel2d::k2_circle_circle_intersect", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let _ = web::kernel2d::k2_circle_circle_intersect(a0, a1, a2, a3, a4, a5); }),
("layers::layers_call", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let a2 = r.text(); let a3 = r.f64(); let _ = web::layers::layers_call(&a0, &a1, &a2, a3); }),
("layers::levels_recompute_elevations", |r: &mut Rng| { let a0 = r.text(); let _ = web::layers::levels_recompute_elevations(&a0); }),
("layout_model::layout_call", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::layout_model::layout_call(&a0, &a1); }),
("line_pattern::line_dash_phase", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.buf(); let _ = web::line_pattern::line_dash_phase(a0, &a1); }),
("line_pattern::line_dash_fit_closed", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.buf(); let _ = web::line_pattern::line_dash_fit_closed(a0, &a1); }),
("line_pattern::plan_arc_path_d", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.below(2) == 1; let a2 = r.f64(); let _ = web::line_pattern::plan_arc_path_d(&a0, a1, a2); }),
("opening_presets::opening_type_presets_json", |_r: &mut Rng| { let _ = web::opening_presets::opening_type_presets_json(); }),
("ops::ops_validate", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let a2 = r.text(); let _ = web::ops::ops_validate(&a0, &a1, &a2); }),
("ops::project_validate", |r: &mut Rng| { let a0 = r.text(); let _ = web::ops::project_validate(&a0); }),
("parametric_walls::parametric_call", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::parametric_walls::parametric_call(&a0, &a1); }),
("pens::pens_call", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let _ = web::pens::pens_call(&a0, &a1); }),
("plan_buf::plan_buf_round_begin", |_r: &mut Rng| { let _ = web::plan_buf::plan_buf_round_begin(); }),
("plan_buf::plan_buf_round_end", |_r: &mut Rng| { let _ = web::plan_buf::plan_buf_round_end(); }),
("plan_buf::plan_buf_touch", |r: &mut Rng| { let a0 = r.id(); let _ = web::plan_buf::plan_buf_touch(a0); }),
("plan_buf::plan_buf_recode", |r: &mut Rng| { let a0 = r.bytes(); let _ = web::plan_buf::plan_buf_recode(&a0); }),
("plan_buf::plan_buf_hold", |r: &mut Rng| { let a0 = r.bytes(); let _ = web::plan_buf::plan_buf_hold(&a0); }),
("plan_buf::plan_buf_release", |r: &mut Rng| { let a0 = r.id(); let _ = web::plan_buf::plan_buf_release(a0); }),
("plan_buf::plan_buf_is_held", |r: &mut Rng| { let a0 = r.id(); let _ = web::plan_buf::plan_buf_is_held(a0); }),
("plan_dxf::plan_dxf_flat", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let a2 = r.buf(); let a3 = r.text(); let a4 = r.text(); let _ = web::plan_dxf::plan_dxf_flat(a0, &a1, &a2, &a3, &a4); }),
("plan_pick::pick_index_build", |r: &mut Rng| { let a0 = r.buf(); let _ = web::plan_pick::pick_index_build(&a0); }),
("plan_pick::pick_index_release", |r: &mut Rng| { let a0 = r.id(); let _ = web::plan_pick::pick_index_release(a0); }),
("plan_pick::pick_nearest_segment", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::plan_pick::pick_nearest_segment(a0, a1, a2, a3); }),
("plan_pick::pick_segments_near", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::plan_pick::pick_segments_near(a0, a1, a2, a3); }),
("plan_pick::pick_polygons_at", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.id(); let _ = web::plan_pick::pick_polygons_at(a0, a1, a2, a3); }),
("plan_pick::pick_nearest_symbol_px", |r: &mut Rng| { let a0 = r.id(); let a1 = r.id(); let a2 = r.id(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let a7 = r.f64(); let a8 = r.f64(); let a9 = r.f64(); let a10 = r.f64(); let _ = web::plan_pick::pick_nearest_symbol_px(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); }),
("plan_pick::pick_rings_near", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let _ = web::plan_pick::pick_rings_near(a0, a1, a2, a3, a4); }),
("plan_pick::pick_owned_by", |r: &mut Rng| { let a0 = r.id(); let a1 = r.id(); let a2 = r.text(); let _ = web::plan_pick::pick_owned_by(a0, a1, &a2); }),
("plan_pick::pick_drawing_text", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let _ = web::plan_pick::pick_drawing_text(a0, a1, a2); }),
("plan_pick::pick_drawing_image", |r: &mut Rng| { let a0 = r.id(); let a1 = r.f64(); let a2 = r.f64(); let _ = web::plan_pick::pick_drawing_image(a0, a1, a2); }),
("plan_pick::pick_drawing_kind", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let _ = web::plan_pick::pick_drawing_kind(a0, &a1); }),
("plan_pick::pick_marquee_polygons", |r: &mut Rng| { let a0 = r.id(); let a1 = r.id(); let a2 = r.buf(); let a3 = r.below(2) == 1; let _ = web::plan_pick::pick_marquee_polygons(a0, a1, &a2, a3); }),
("plan_pick::pick_marquee_drawings", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let a2 = r.below(2) == 1; let a3 = r.text(); let _ = web::plan_pick::pick_marquee_drawings(a0, &a1, a2, &a3); }),
("plan_print_svg::plan_print_svg_ops", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::plan_print_svg::plan_print_svg_ops(&a0, &a1); }),
("plan_scene::plan_scene_bin", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let a3 = r.id(); let _ = web::plan_scene::plan_scene_bin(&a0, &a1, a2, a3); }),
("plan_scene::plan_scene_texts", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let _ = web::plan_scene::plan_scene_texts(&a0, &a1, a2); }),
("plan_scene::plan_screen_texts", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::plan_scene::plan_screen_texts(&a0, &a1, a2, a3); }),
("plan_scene::plan_scene_f64", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::plan_scene::plan_scene_f64(&a0, &a1); }),
("plan_svg::plan_svg_string", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::plan_svg::plan_svg_string(&a0, &a1); }),
("polygon::poly_union", |r: &mut Rng| { let a0 = r.buf(); let _ = web::polygon::poly_union(&a0); }),
("polygon::poly_difference", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::polygon::poly_difference(&a0, &a1); }),
("polygon::poly_intersection", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::polygon::poly_intersection(&a0, &a1); }),
("polygon_holes::polygon_merge_holes", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let _ = web::polygon_holes::polygon_merge_holes(&a0, &a1, a2); }),
("project_format::project_format_version", |_r: &mut Rng| { let _ = web::project_format::project_format_version(); }),
("project_refs::project_warnings", |r: &mut Rng| { let a0 = r.text(); let _ = web::project_refs::project_warnings(&a0); }),
("reorder::reorder_call", |r: &mut Rng| { let a0 = r.text(); let a1 = r.text(); let a2 = r.text(); let _ = web::reorder::reorder_call(&a0, &a1, &a2); }),
("rich_text::rich_normalize", |r: &mut Rng| { let a0 = r.text(); let _ = web::rich_text::rich_normalize(&a0); }),
("rich_text::rich_apply_mark", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.text(); let a4 = r.text(); let _ = web::rich_text::rich_apply_mark(&a0, a1, a2, &a3, &a4); }),
("rich_text::rich_toggle_mark", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.text(); let _ = web::rich_text::rich_toggle_mark(&a0, a1, a2, &a3); }),
("rich_text::rich_is_mark_active", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.text(); let _ = web::rich_text::rich_is_mark_active(&a0, a1, a2, &a3); }),
("rich_text::rich_common_mark_value", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.text(); let _ = web::rich_text::rich_common_mark_value(&a0, a1, a2, &a3); }),
("rich_text::rich_serialize", |r: &mut Rng| { let a0 = r.text(); let _ = web::rich_text::rich_serialize(&a0); }),
("rich_text::rich_apply_preset", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.text(); let _ = web::rich_text::rich_apply_preset(&a0, a1, a2, &a3); }),
("roof::roof_geometry_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let _ = web::roof::roof_geometry_flat(&a0, a1); }),
("roof::roof_underside_at", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::roof::roof_underside_at(&a0, a1, a2, a3); }),
("room_area::room_evaluate", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.buf(); let _ = web::room_area::room_evaluate(&a0, a1, &a2); }),
("room_area::room_polygon_area", |r: &mut Rng| { let a0 = r.buf(); let _ = web::room_area::room_polygon_area(&a0); }),
("room_area::room_centroid", |r: &mut Rng| { let a0 = r.buf(); let _ = web::room_area::room_centroid(&a0); }),
("room_area::room_label_point", |r: &mut Rng| { let a0 = r.buf(); let _ = web::room_area::room_label_point(&a0); }),
("room_area::room_balance", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let _ = web::room_area::room_balance(&a0, &a1); }),
("room_area::room_sia_categories", |_r: &mut Rng| { let _ = web::room_area::room_sia_categories(); }),
("room_boundary::rooms_detect", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.below(2) == 1; let _ = web::room_boundary::rooms_detect(&a0, a1, a2, a3); }),
("site_rules::site_multi_polygon_area", |r: &mut Rng| { let a0 = r.buf(); let _ = web::site_rules::site_multi_polygon_area(&a0); }),
("site_rules::site_allowed_area", |r: &mut Rng| { let a0 = r.buf(); let _ = web::site_rules::site_allowed_area(&a0); }),
("site_rules::doc_site_envelope", |r: &mut Rng| { let a0 = r.id(); let _ = web::site_rules::doc_site_envelope(a0); }),
("skeleton::straight_skeleton", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.f64(); let _ = web::skeleton::straight_skeleton(&a0, &a1, a2); }),
("snap::doc_snap_hold", |r: &mut Rng| { let a0 = r.id(); let a1 = r.text(); let a2 = r.text(); let a3 = r.text(); let a4 = r.f64(); let _ = web::snap::doc_snap_hold(a0, &a1, &a2, &a3, a4); }),
("snap::snap_query", |r: &mut Rng| { let a0 = r.id(); let a1 = r.buf(); let a2 = r.buf(); let a3 = r.f64(); let a4 = r.f64(); let a5 = r.f64(); let a6 = r.f64(); let a7 = r.id(); let a8 = r.f64(); let a9 = r.f64(); let _ = web::snap::snap_query(a0, &a1, &a2, a3, a4, a5, a6, a7, a8, a9); }),
("solid_bool::solid_boolean", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.buf(); let a2 = r.buf(); let _ = web::solid_bool::solid_boolean(a0, &a1, &a2); }),
("stair::stair_outline_flat", |r: &mut Rng| { let a0 = r.buf(); let _ = web::stair::stair_outline_flat(&a0); }),
("sun::sun_position", |r: &mut Rng| { let a0 = r.f64(); let a1 = r.f64(); let a2 = r.f64(); let _ = web::sun::sun_position(a0, a1, a2); }),
("sun::sun_shadow_of_prism", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let a4 = r.f64(); let _ = web::sun::sun_shadow_of_prism(&a0, a1, a2, a3, a4); }),
("sun::sun_without_holes", |r: &mut Rng| { let a0 = r.buf(); let _ = web::sun::sun_without_holes(&a0); }),
("text_layout::text_lines", |r: &mut Rng| { let a0 = r.text(); let a1 = r.buf(); let a2 = r.opt_text(); let _ = web::text_layout::text_lines(&a0, &a1, a2); }),
("text_layout::text_frame", |r: &mut Rng| { let a0 = r.text(); let a1 = r.buf(); let _ = web::text_layout::text_frame(&a0, &a1); }),
("text_layout::text_stamp_block", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let a3 = r.f64(); let _ = web::text_layout::text_stamp_block(&a0, a1, a2, a3); }),
("text_layout::text_wrap_plain", |r: &mut Rng| { let a0 = r.text(); let a1 = r.f64(); let a2 = r.f64(); let _ = web::text_layout::text_wrap_plain(&a0, a1, a2); }),
("voids::voids_subtract_rings_flat", |r: &mut Rng| { let a0 = r.buf(); let a1 = r.buf(); let a2 = r.buf(); let _ = web::voids::voids_subtract_rings_flat(&a0, &a1, &a2); }),
("voids::wall_spec_flat", |r: &mut Rng| { let a0 = r.buf(); let _ = web::voids::wall_spec_flat(&a0); }),
];
// ── Lauf ─────────────────────────────────────────────────────────────────────
fn env_num(k: &str, default: u64) -> u64 {
std::env::var(k).ok().and_then(|v| v.parse().ok()).unwrap_or(default)
}
/// Alle offenen Dokumente schliessen (der Fuzz öffnet laufend neue, `doc_open` mit dem Beispielprojekt) und das
/// Beispielprojekt frisch öffnen: Speicher bleibt klein, und die Aufrufe sehen wieder ein gültiges Handle.
fn reset_docs() {
for h in 1..=64u32 {
web::document::doc_close(h);
}
let h = web::document::doc_open(FIXTURE);
assert!(h != 0, "Beispielprojekt muss sich öffnen lassen");
HANDLE.with(|c| c.set(h));
}
#[test]
fn bindungen_kaputte_eingaben() {
let n = env_num("ROBUST_WEB_N", 60);
let seed = env_num("ROBUST_WEB_SEED", 0x5eed_258) | 1;
let only = std::env::var("ROBUST_WEB_ONLY").ok();
let trace = std::env::var("ROBUST_WEB_TRACE").is_ok();
// Von Hand: `ROBUST_WEB_SKIP=a,b` überspringt Bindungen (Teilname), um nach einem Hang weiterzusuchen.
let dump: Option<(String, u64)> = std::env::var("ROBUST_WEB_DUMP").ok().and_then(|v| v.split_once('#').and_then(|(a, b)| Some((a.to_string(), b.parse().ok()?))));
let skip: Vec<String> = std::env::var("ROBUST_WEB_SKIP").map(|v| v.split(',').filter(|x| !x.is_empty()).map(String::from).collect()).unwrap_or_default();
// Wächter: ein Aufruf über 30 s (Endlosschleife / Speicherflut) wird gemeldet und beendet den Lauf.
let progress = std::sync::Arc::new(std::sync::atomic::AtomicU64::new(0));
let label = std::sync::Arc::new(std::sync::Mutex::new(String::new()));
{
let (progress, label) = (progress.clone(), label.clone());
std::thread::spawn(move || {
let mut seen = u64::MAX;
let mut since = std::time::Instant::now();
loop {
std::thread::sleep(std::time::Duration::from_millis(250));
let now = progress.load(std::sync::atomic::Ordering::Relaxed);
if now != seen {
seen = now;
since = std::time::Instant::now();
} else if now != 0 && since.elapsed().as_secs() >= 30 {
eprintln!("HANG (über 30 s): {}", label.lock().unwrap());
std::process::exit(3);
}
}
});
}
let mut counter = 0u64;
reset_docs();
let default = std::panic::take_hook();
let cur = std::sync::Arc::new(std::sync::Mutex::new(false));
let cur2 = cur.clone();
std::panic::set_hook(Box::new(move |info| {
if !*cur2.lock().unwrap() {
default(info);
return;
}
let loc = info.location().map(|l| format!("{}:{}", l.file(), l.line())).unwrap_or_default();
let msg = info.payload().downcast_ref::<&str>().map(|s| s.to_string()).or_else(|| info.payload().downcast_ref::<String>().cloned()).unwrap_or_else(|| "?".into());
LAST.with(|l| *l.borrow_mut() = format!("{msg} @ {loc}"));
}));
// Panic-Text → (Anzahl, erste Bindung)
let mut fails: BTreeMap<String, (usize, String)> = BTreeMap::new();
for (idx, (name, call)) in CALLS.iter().enumerate() {
// Löst absichtlich einen Panic aus (Test-Haken für den Wiederanlauf [118]) und lässt die Dokumenttabelle geborgt.
if *name == "document::__debug_panic" {
continue;
}
if only.as_ref().is_some_and(|o| !name.contains(o.as_str())) || skip.iter().any(|x| name.contains(x.as_str())) {
continue;
}
let mut rng = Rng(seed ^ ((idx as u64 + 1).wrapping_mul(0x9E37_79B9_7F4A_7C15)));
reset_docs();
for i in 0..n {
if i % 100 == 99 {
reset_docs();
}
if trace {
eprintln!("{name} #{i}");
}
DUMP.with(|d| d.set(dump.as_ref().is_some_and(|(nm, k)| name.contains(nm.as_str()) && *k == i)));
counter += 1;
*label.lock().unwrap() = format!("{name} (Aufruf {i}, Seed {seed})");
progress.store(counter, std::sync::atomic::Ordering::Relaxed);
*cur.lock().unwrap() = true;
let r = catch_unwind(AssertUnwindSafe(|| call(&mut rng)));
*cur.lock().unwrap() = false;
progress.store(0, std::sync::atomic::Ordering::Relaxed);
if r.is_err() {
let what = LAST.with(|l| l.borrow().clone());
let e = fails.entry(what).or_insert_with(|| (0, format!("{name} (Aufruf {i}, Seed {seed})")));
e.0 += 1;
}
}
}
let _ = std::panic::take_hook();
if !fails.is_empty() {
let mut s = format!("{} verschiedene Panics in den Bindungen:\n", fails.len());
for (k, (c, ctx)) in &fails {
s += &format!(" {c}x {k}\n erstmals bei: {ctx}\n");
}
panic!("{s}");
}
}
/// Jede `#[wasm_bindgen]`-Funktion in `src/web/*.rs` muss in `CALLS` stehen.
#[test]
fn jede_bindung_ist_abgedeckt() {
let dir = concat!(env!("CARGO_MANIFEST_DIR"), "/src/web");
let mut missing = vec![];
let mut total = 0;
for e in std::fs::read_dir(dir).unwrap() {
let p = e.unwrap().path();
let module = p.file_stem().unwrap().to_string_lossy().to_string();
if module == "mod" || p.extension().is_none_or(|x| x != "rs") {
continue;
}
let text = std::fs::read_to_string(&p).unwrap();
let mut pending = false;
for line in text.lines() {
let t = line.trim();
if t.starts_with("#[wasm_bindgen") && !t.starts_with("#[wasm_bindgen(start") {
pending = true;
} else if pending && t.starts_with("pub fn ") {
pending = false;
let name: String = t["pub fn ".len()..].chars().take_while(|c| c.is_alphanumeric() || *c == '_').collect();
total += 1;
let key = format!("{module}::{name}");
if !CALLS.iter().any(|(n, _)| *n == key) {
missing.push(key);
}
}
}
}
assert!(total > 100, "zu wenige Bindungen gefunden ({total})");
assert!(missing.is_empty(), "Bindungen ohne Robustheits-Aufruf in CALLS: {missing:?}");
}
/// [258] Dachparameter aus dem Fuzzlauf, bei denen die Wellenfront des Skeletts in einen Rundungszyklus lief
/// (Ecken wuchsen unbegrenzt, Aufruf hing > 30 s): jetzt Obergrenze für Ecken -> Degeneration -> Rückfall.
#[test]
fn regression_roof_skeleton_rundungszyklus() {
let params = [
5.0, 1.0, 3.0, 3.0, 4.0, 3.0, 1.0, 5.0, 5.0, 2.0, 1.0, 1.0, 5.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 2.0, 3.0, 4.0, 1.0, 4.0, 2.0, 2.0, 3.0, 2.0, 1.0, 4.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0,
2.0, 2.0, 4.0, 3.0, 3.0,
];
let t = std::time::Instant::now();
let _ = web::roof::roof_geometry_flat(&params, -2.9986637881230873e-22);
assert!(t.elapsed().as_secs() < 10, "Dachgeometrie hängt");
}
+118 -30
View File
@@ -300,15 +300,17 @@ pub fn hatch_line_family(poly: &[V2], angle_rad: f64, spacing_m: f64, offset_m:
let first = ((d_min - offset_m) / spacing_m).floor() - 1.0;
let last = ((d_max - offset_m) / spacing_m).ceil() + 1.0;
// Unendliche Ausdehnung (TS lief hier endlos): nichts zeichnen.
if !(last - first).is_finite() {
// Obergrenze ([258]): Milliarden Linien (riesiges Polygon, feiner Abstand) lähmen wie Endlosschleife.
if !((last - first) <= MAX_FAMILY_LINES) {
return segs;
}
let mut k = first;
while k <= last {
// Zählschleife statt `k += 1.0`: bei |k| ≥ 2^53 ändert `+ 1` den Wert nicht (Endlosschleife, [258]).
let count = (last - first) as u64;
for n in 0..=count {
let k = first + n as f64;
let d = offset_m + k * spacing_m;
let p0 = v2(center.x + nrm.x * d, center.y + nrm.y * d);
segs.extend(clip_line_to_polygon(p0, dir, poly));
k += 1.0;
}
segs
}
@@ -335,6 +337,23 @@ pub fn hatch_dash(h: &Hatch) -> Vec<f64> {
h.dash.iter().map(|d| d * k).collect()
}
/// Ganzzahlige Laufindizes `first..=last` als f64. Zählt über einen ganzzahligen Zähler statt `k += 1.0`:
/// ab |k| ≥ 2^53 ändert `+ 1.0` den Wert nicht mehr (Endlosschleife bei fernen Koordinaten, [258]); unterhalb
/// ist das Ergebnis bitgleich zur fortlaufenden Addition.
fn fseq(first: f64, last: f64) -> impl Iterator<Item = f64> {
let n = if last >= first { Some((last - first).min(1e15) as u64) } else { None };
n.into_iter().flat_map(move |n| (0..=n).map(move |m| first + m as f64))
}
/// Obergrenze der Linien einer Schraffur-Schar ([258]).
const MAX_FAMILY_LINES: f64 = 2_000_000.0;
/// Obergrenze der Punkte einer Zickzack-/Motivlinie ([258]).
const MAX_LINE_POINTS: f64 = 4_000_000.0;
/// Obergrenze der Strichstücke einer Zerlegung ([258]).
const MAX_DASH_PIECES: f64 = 2_000_000.0;
/// Zerlegt Läufe entlang eines Strichmusters (`dash` in mm-Papier, [an, aus, …]; ungerade
/// Länge wird verdoppelt). Die Phase läuft über Stützpunkte hinweg durch.
pub fn apply_dash_runs(runs: Vec<Run>, dash: &[f64]) -> Vec<Run> {
@@ -353,6 +372,20 @@ pub fn apply_dash_runs(runs: Vec<Run>, dash: &[f64]) -> Vec<Run> {
if total <= 1e-9 {
return runs;
}
// Obergrenze ([258]): Lauf von 1e300 m oder unendlicher Länge mit feinem Muster ergäbe Milliarden
// Striche (Speicher-Abbruch bzw. Endlosschleife) — dann durchgezogen lassen.
let mut path_len = 0.0;
for run in &runs {
for w in run.windows(2) {
let l = hypot2(w[1].x - w[0].x, w[1].y - w[0].y);
if !l.is_nan() {
path_len += l;
}
}
}
if !((path_len / total) * cycle.len() as f64 <= MAX_DASH_PIECES) {
return runs;
}
let mut out: Vec<Run> = Vec::new();
for run in &runs {
if run.len() < 2 {
@@ -492,13 +525,11 @@ fn wood_runs(poly: &[V2], angle_rad: f64, spacing_m: f64, anchor: V2, seed: f64)
return Vec::new();
}
let mut runs = Vec::new();
let mut k = first;
while k <= last {
for k in fseq(first, last) {
let jitter = Mulberry32 { a: hash_cell(k, 0.0, seed) }.next() - 0.5;
let d = (k + 0.3 * jitter) * spacing_m;
let p0 = v2(anchor.x + nrm.x * d, anchor.y + nrm.y * d);
runs.extend(clip_line_to_polygon(p0, dir, poly).into_iter().map(|(a, b)| vec![a, b]));
k += 1.0;
}
runs
}
@@ -513,13 +544,15 @@ fn barrier_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
}
let mut runs = Vec::new();
for &(vc, _) in &b.rows {
let mut i = ((b.u0 - b.ua) / (2.0 * dash)).floor();
while b.ua + 2.0 * i * dash <= b.u1 {
let i0 = ((b.u0 - b.ua) / (2.0 * dash)).floor();
for i in fseq(i0, ((b.u1 - b.ua) / (2.0 * dash)).floor() + 1.0) {
if b.ua + 2.0 * i * dash > b.u1 {
break;
}
let s = b.ua + 2.0 * i * dash;
for (sa, sb) in clip_segment_to_polygon(b.at(s, vc), b.at(s + dash, vc), poly) {
runs.push(vec![sa, sb]);
}
i += 1.0;
}
}
runs
@@ -589,7 +622,7 @@ fn band_frame(poly: &[V2], hatch: &Hatch, scale: f64) -> Option<Band> {
fn band_curve(poly: &[V2], b: &Band, vc: f64, margin: f64, dx: f64, f: impl Fn(f64) -> (f64, f64)) -> Vec<Run> {
let x0 = ((b.u0 - b.ua - margin) / dx).floor() * dx;
let x1 = b.u1 - b.ua + margin;
if !(dx > 1e-9) || (x1 - x0) / dx > BAND_MAX_POINTS {
if !(dx > 1e-9) || (x1 - x0) / dx > BAND_MAX_POINTS || !(x0.abs().max(x1.abs()) / dx < 1e15) {
return Vec::new();
}
let mut pts = Vec::new();
@@ -673,6 +706,10 @@ fn insulation_snake(poly: &[V2], b: &Band, vc: f64, h: f64, p: f64) -> Vec<Run>
let n_bot = (bot_sweep / step).ceil().max(1.0) as usize;
let k0 = ((b.u0 - b.ua) / p).floor() - 1.0;
let mut k = ((b.u1 - b.ua) / p).ceil() + 1.0;
// Ferne Koordinaten: ab |k| ≥ 2^53 käme `k -= 1.0` nie voran ([258]).
if !(k.abs() < 1e15 && k0.abs() < 1e15) {
return Vec::new();
}
let mut pts = Vec::new();
while k >= k0 {
let ct = b.ua + k * p;
@@ -758,10 +795,8 @@ fn earth_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
let Some((i0, i1, j0, j1)) = cells_over(poly, u, v, cell) else { return Vec::new() };
let at = |a: f64, b: f64| v2(u.x * a + v.x * b, u.y * a + v.y * b);
let mut runs = Vec::new();
let mut j = j0;
while j <= j1 {
let mut i = i0;
while i <= i1 {
for j in fseq(j0, j1) {
for i in fseq(i0, i1) {
let along_u = (i + j).rem_euclid(2.0) == 0.0;
for k in [0.25, 0.5, 0.75] {
let (a, b) = if along_u {
@@ -773,9 +808,7 @@ fn earth_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
runs.push(vec![sa, sb]);
}
}
i += 1.0;
}
j += 1.0;
}
runs
}
@@ -787,10 +820,8 @@ fn gravel_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
let Some((i0, i1, j0, j1)) = cells_over(poly, v2(1.0, 0.0), v2(0.0, 1.0), cell) else { return Vec::new() };
let seed = hatch.seed.unwrap_or(0.0);
let mut runs = Vec::new();
let mut j = j0;
while j <= j1 {
let mut i = i0;
while i <= i1 {
for j in fseq(j0, j1) {
for i in fseq(i0, i1) {
let mut rnd = Mulberry32 { a: hash_cell(i, j, seed) };
let r = cell * (0.125 + 0.15 * rnd.next());
let cx = (i + 0.5) * cell + (rnd.next() - 0.5) * (cell - 2.0 * r);
@@ -800,9 +831,7 @@ fn gravel_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
v2(cx + r * jsnum::cos(a), cy + r * jsnum::sin(a))
}).collect();
runs.extend(clip_polyline_to_polygon(&ring, poly));
i += 1.0;
}
j += 1.0;
}
runs
}
@@ -831,6 +860,9 @@ fn dots_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
let v = vc - half + (r + 0.5) * step;
let shift = if r.rem_euclid(2.0) == 0.0 { 0.0 } else { 0.5 };
let mut i = ((b.u0 - b.ua) / pitch).floor() - 1.0;
if !(i.abs() < 1e15) {
return Vec::new(); // [258]: `i += 1.0` käme ab 2^53 nie voran
}
while b.ua + (i + shift) * pitch <= b.u1 + pitch {
let cu = b.ua + (i + shift) * pitch;
let (a, e) = (b.at(cu - half_dot, v), b.at(cu + half_dot, v));
@@ -917,8 +949,19 @@ pub fn scatter_strokes(
ix1 = (max_x / eff).floor();
iy0 = (min_y / eff).floor();
iy1 = (max_y / eff).floor();
// Lange, dünne Polygone: die eine Rasterzeile bleibt breit, die Näherung oben reicht nicht ([258]).
// Erst weit über dem Limit eingreifen, damit gewöhnliche Fälle bitgleich bleiben.
let mut rounds = 0;
while (ix1 - ix0 + 1.0) * (iy1 - iy0 + 1.0) > 2.0 * MAX_CELLS && rounds < 200 {
eff *= 2.0;
ix0 = (min_x / eff).floor();
ix1 = (max_x / eff).floor();
iy0 = (min_y / eff).floor();
iy1 = (max_y / eff).floor();
rounds += 1;
}
}
if !(ix1 - ix0).is_finite() || !(iy1 - iy0).is_finite() {
if !(ix1 - ix0).is_finite() || !(iy1 - iy0).is_finite() || !((ix1 - ix0 + 1.0) * (iy1 - iy0 + 1.0) <= 2.0 * MAX_CELLS) {
return Vec::new();
}
let range = match (len_min, len_max) {
@@ -926,10 +969,8 @@ pub fn scatter_strokes(
_ => None,
};
let mut runs = Vec::new();
let mut iy = iy0;
while iy <= iy1 {
let mut ix = ix0;
while ix <= ix1 {
for iy in fseq(iy0, iy1) {
for ix in fseq(ix0, ix1) {
let mut rnd = Mulberry32 { a: hash_cell(ix, iy, seed) };
let cx = (ix + rnd.next()) * eff;
let cy = (iy + rnd.next()) * eff;
@@ -946,9 +987,7 @@ pub fn scatter_strokes(
for (sa, sb) in clip_segment_to_polygon(a, b, poly) {
runs.push(vec![sa, sb]);
}
ix += 1.0;
}
iy += 1.0;
}
runs
}
@@ -1040,6 +1079,10 @@ pub fn zigzag_points(a: V2, b: V2, amplitude: f64, wavelength: f64) -> Option<Ve
let ny = ux;
let quarter = wavelength / 4.0;
let steps = jsnum::max(1.0, jsnum::round(l / quarter));
// Obergrenze ([258]): sehr lange Strecke mit feiner Welle (oder Länge ∞) → Strecke gilt.
if !(steps <= MAX_LINE_POINTS) {
return None;
}
const TRI: [f64; 4] = [0.0, 1.0, 0.0, -1.0];
let mut pts = Vec::new();
let mut i = 0.0f64;
@@ -1078,6 +1121,9 @@ pub fn motif_points_opt(a: V2, b: V2, motif: &Motif, scale: f64) -> Option<Vec<V
let to_world = |ax: f64, off: f64| v2(a.x + ux * ax + nx * off, a.y + uy * ax + ny * off);
let mut out = Vec::new();
let reps = (l / cell).ceil() + 1.0;
if !(reps * motif.points.len() as f64 <= MAX_LINE_POINTS) {
return None; // [258]: Obergrenze wie bei der Zickzacklinie
}
let mut last: Option<(f64, f64)> = None;
let mut r = 0.0f64;
while r < reps {
@@ -1115,6 +1161,48 @@ pub fn motif_points_opt(a: V2, b: V2, motif: &Motif, scale: f64) -> Option<Vec<V
mod tests {
use super::*;
/// [258] Riesige/unendliche Läufe mit feinem Strichmuster: durchgezogen zurück statt Speicher-Abbruch/Endlosschleife.
#[test]
fn regression_zickzack_motiv_riesige_strecke() {
for far in [1e300, f64::INFINITY] {
assert!(zigzag_points(v2(0.0, 0.0), v2(far, 0.0), 0.1, 0.1).is_none());
let m = Motif { points: vec![v2(0.0, 0.0), v2(0.5, 0.2), v2(1.0, 0.0)], length: 1.0 };
assert!(motif_points_opt(v2(0.0, 0.0), v2(far, 0.0), &m, 1e-3).is_none());
}
assert!(zigzag_points(v2(0.0, 0.0), v2(1.0, 0.0), 0.1, 0.1).is_some());
}
#[test]
fn regression_streuung_lange_duenne_flaeche() {
// 1e9 m lang, 1e-3 m hoch: ein Raster von Milliarden Zellen in einer Zeile.
let poly = vec![v2(0.0, 0.0), v2(1e9, 0.0), v2(1e9, 1e-3), v2(0.0, 1e-3)];
let _ = scatter_strokes(&poly, 0.05, 0.3, 1.0, 0.04, None, None);
let _ = scatter_strokes(&poly, 0.05, 0.3, 1.0, 0.04, Some(0.01), Some(0.02));
}
#[test]
fn regression_linienschar_riesiges_polygon() {
let poly = vec![v2(0.0, 0.0), v2(1e12, 0.0), v2(1e12, 1e12), v2(0.0, 1e12)];
assert!(hatch_line_family(&poly, 0.3, 0.01, 0.0, v2(0.0, 0.0)).is_empty());
let sq = vec![v2(0.0, 0.0), v2(1.0, 0.0), v2(1.0, 1.0), v2(0.0, 1.0)];
assert!(!hatch_line_family(&sq, 0.0, 0.1, 0.0, v2(0.0, 0.0)).is_empty());
// Ferne Koordinaten: k ≥ 2^53, `k += 1.0` käme nie voran.
let far = vec![v2(1e300, 1e300), v2(1e300 + 1e290, 1e300), v2(1e300, 1e300 + 1e290)];
let _ = hatch_line_family(&far, 0.3, 1.0, 0.0, v2(0.0, 0.0));
}
#[test]
fn regression_dash_runs_riesiger_lauf() {
for far in [1e300, f64::INFINITY] {
let runs = vec![vec![v2(0.0, 0.0), v2(far, 0.0)]];
let out = apply_dash_runs(runs.clone(), &[0.01, 0.01]);
assert_eq!(out.len(), 1);
}
// Normalfall unverändert: Zerlegung in mehrere Striche.
let out = apply_dash_runs(vec![vec![v2(0.0, 0.0), v2(1.0, 0.0)]], &[1.0, 1.0]);
assert!(out.len() > 1);
}
fn square() -> Vec<V2> {
vec![v2(0.0, 0.0), v2(1.0, 0.0), v2(1.0, 1.0), v2(0.0, 1.0)]
}
+3 -1
View File
@@ -303,7 +303,9 @@ fn split_steps(body: i64, run1: f64, run2: f64, run1_steps: Option<i64>) -> (i64
let s1 = match run1_steps {
Some(n) => n.min(body - 1).max(1),
None => {
let v = ((body as f64 * run1) / (run1 + run2)).round() as i64;
// `as i64` sättigt bei ∞ (Lauflänge f64::MAX: Summe/Produkt laufen über) → i64::MAX Stufen, Speicher-Abbruch
// ([258]); im Normalfall liegt v unter body, die Begrenzung ändert dort nichts.
let v = (((body as f64 * run1) / (run1 + run2)).round() as i64).min(body.max(1));
if v < 1 { 1 } else { v }
}
};
+12
View File
@@ -322,6 +322,18 @@ fn near(a: Vec2, x: f64, y: f64) -> bool {
(a.x - x).abs() < 1e-9 && (a.y - y).abs() < 1e-9
}
/// [258] Lauflänge f64::MAX (Summe/Produkt laufen über, Stufenzahl sättigt zu i64::MAX): endlich viele Tritte.
#[test]
fn regression_stair_riesige_lauflaenge() {
for shape in ["L", "U", "straightLanding", "straight"] {
let mut p = stair(shape);
p.run_length = f64::MAX;
p.run2_length = Some(3.0);
let g = stair_geometry(&p, 1.0);
assert!(g.treads.len() <= 20, "{shape}: {} Tritte", g.treads.len());
}
}
#[test]
fn stair_gerade_tritte_lauflinie_pfeil() {
let g = stair_geometry(&stair("straight"), 2.8);
+187
View File
@@ -0,0 +1,187 @@
//! [258] Robustheit der Eingänge von render2d (`web.rs`: `set_scene_bin`, `add_font`, Textzeilen): die GPU-freien
//! Leser und die Tessellierung dürfen auf kaputten Bytes nie paniken — ein Panic legt im Browser das ganze WASM-Modul
//! lahm. Native (Standard-Features, ohne GPU): `decode_scene` auf abgeschnittenen/verdorbenen/zufälligen Szenen
//! (Ausgangspunkt: `tests/fixtures/scene_v1.bin`), bei Erfolg `compile_scene`; `text_lines`, `woff2::to_sfnt`,
//! Zerlegung und Strichphase mit NaN/∞/Zufall. Fester Seed, eigener PRNG, jeder Aufruf unter `catch_unwind`.
//! `ROBUST_N` (Aufrufe je Fall, Standard 400), `ROBUST_SEED`.
use render2d::scene_bin::decode_scene;
use render2d::tessellate::{arc_screen_params, compile_scene, dash_phase, prepare_arc_dash, triangulate};
use render2d::text_lines::{lines_from_bytes, lines_from_f64};
use render2d::types::Point;
use render2d::woff2::to_sfnt;
use std::collections::BTreeMap;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::sync::{Arc, Mutex};
const FIXTURE: &[u8] = include_bytes!("fixtures/scene_v1.bin");
struct Rng(u64);
impl Rng {
fn next(&mut self) -> u64 {
self.0 ^= self.0 >> 12;
self.0 ^= self.0 << 25;
self.0 ^= self.0 >> 27;
self.0.wrapping_mul(0x2545_F491_4F6C_DD1D)
}
fn below(&mut self, n: usize) -> usize {
if n == 0 { 0 } else { (self.next() % n as u64) as usize }
}
fn f64(&mut self) -> f64 {
const POOL: [f64; 12] = [0.0, -0.0, 1.0, -1.0, 1e-9, 1e9, 1e300, -1e300, f64::NAN, f64::INFINITY, f64::NEG_INFINITY, 3.0];
match self.below(4) {
0 => POOL[self.below(POOL.len())],
1 => f64::from_bits(self.next()),
2 => self.below(10) as f64,
_ => (self.next() >> 11) as f64 / (1u64 << 53) as f64 * 100.0 - 50.0,
}
}
fn f32(&mut self) -> f32 {
self.f64() as f32
}
fn point(&mut self) -> Point {
[self.f32(), self.f32()]
}
fn bytes(&mut self, max: usize) -> Vec<u8> {
let n = self.below(max + 1);
(0..n).map(|_| self.next() as u8).collect()
}
/// Gültige Szene, dann: abschneiden, Bytes verdorben, Zähler-Felder auf Randwerte, Anhang.
fn scene_bytes(&mut self) -> Vec<u8> {
let mut v = FIXTURE.to_vec();
match self.below(6) {
0 => v.truncate(self.below(v.len() + 1)),
1 => {
for _ in 0..1 + self.below(4) {
let i = self.below(v.len());
v[i] = self.next() as u8;
}
}
2 => {
// 4-Byte-Wort (Zähler/Länge/Gleitkommazahl) auf Randwert.
let words: [[u8; 4]; 7] = [[0xff; 4], [0; 4], [0xff, 0xff, 0xff, 0x7f], [0, 0, 0, 0x80], [0, 0, 0xc0, 0x7f], [0, 0, 0x80, 0x7f], [1, 0, 0, 0]];
for _ in 0..1 + self.below(3) {
let i = self.below(v.len().saturating_sub(3));
let w = words[self.below(words.len())];
v[i..i + 4].copy_from_slice(&w);
}
}
3 => {
let extra = self.bytes(40);
v.extend(extra);
}
4 => v = self.bytes(200),
_ => {
// Kopf behalten, Rest zufällig.
let keep = self.below(v.len().min(48) + 1);
v.truncate(keep);
let tail = self.bytes(120);
v.extend(tail);
}
}
v
}
}
#[derive(Default)]
struct Fails(BTreeMap<String, (usize, String)>);
fn check(fails: &mut Fails, cur: &Arc<Mutex<bool>>, last: &Arc<Mutex<String>>, ctx: &str, f: impl FnOnce()) {
*cur.lock().unwrap() = true;
let r = catch_unwind(AssertUnwindSafe(f));
*cur.lock().unwrap() = false;
if r.is_err() {
let what = last.lock().unwrap().clone();
let e = fails.0.entry(what).or_insert_with(|| (0, ctx.to_string()));
e.0 += 1;
}
}
#[test]
fn render2d_eingaenge_kaputte_daten() {
let n: u64 = std::env::var("ROBUST_N").ok().and_then(|v| v.parse().ok()).unwrap_or(400);
let seed: u64 = std::env::var("ROBUST_SEED").ok().and_then(|v| v.parse().ok()).unwrap_or(0x5eed_258) | 1;
let default = std::panic::take_hook();
let cur = Arc::new(Mutex::new(false));
let last = Arc::new(Mutex::new(String::new()));
{
let (cur, last) = (cur.clone(), last.clone());
std::panic::set_hook(Box::new(move |info| {
if !*cur.lock().unwrap() {
default(info);
return;
}
let loc = info.location().map(|l| format!("{}:{}", l.file(), l.line())).unwrap_or_default();
let msg = info.payload().downcast_ref::<&str>().map(|s| s.to_string()).or_else(|| info.payload().downcast_ref::<String>().cloned()).unwrap_or_else(|| "?".into());
*last.lock().unwrap() = format!("{msg} @ {loc}");
}));
}
let mut fails = Fails::default();
let mut rng = Rng(seed);
let mut decoded_ok = 0usize;
for i in 0..n {
// 1. Szene lesen (und bei Erfolg tessellieren).
let bytes = rng.scene_bytes();
let mut ok = false;
check(&mut fails, &cur, &last, &format!("decode_scene/compile_scene (Aufruf {i}, Seed {seed})"), || {
if let Ok(scene) = decode_scene(&bytes) {
ok = true;
let _ = compile_scene(&scene);
}
});
decoded_ok += ok as usize;
// 2. Textzeilen (f64-Puffer der Kern-Bindung und Bytes).
let nf = rng.below(60);
let f: Vec<f64> = (0..nf).map(|_| if rng.below(3) == 0 { rng.below(5) as f64 } else { rng.f64() }).collect();
check(&mut fails, &cur, &last, &format!("lines_from_f64 (Aufruf {i})"), || {
let _ = lines_from_f64(&f);
});
let tb = rng.bytes(300);
check(&mut fails, &cur, &last, &format!("lines_from_bytes (Aufruf {i})"), || {
let _ = lines_from_bytes(&tb);
});
// 3. Schriftdateien: WOFF2-/SFNT-Köpfe mit Zufall.
let mut font = rng.bytes(400);
let head: &[u8] = match rng.below(4) {
0 => b"wOF2",
1 => &[0, 1, 0, 0],
_ => &[],
};
font.splice(0..0, head.iter().copied());
check(&mut fails, &cur, &last, &format!("woff2::to_sfnt (Aufruf {i})"), || {
let _ = to_sfnt(&font);
});
// 4. Zerlegung, Bögen, Strichmuster mit Unsinn.
let pts: Vec<Point> = (0..rng.below(14)).map(|_| rng.point()).collect();
check(&mut fails, &cur, &last, &format!("triangulate (Aufruf {i})"), || {
let _ = triangulate(&pts);
});
let (c, a, b, r) = (rng.point(), rng.point(), rng.point(), rng.f32());
check(&mut fails, &cur, &last, &format!("arc_screen_params (Aufruf {i})"), || {
let _ = arc_screen_params(c, a, b, r);
});
let cyc: Vec<f32> = (0..rng.below(8)).map(|_| rng.f32()).collect();
// (`dash_coverage` ist ein CPU-Spiegel des Shaders nur für Tests, mit `clamp` auf dem Segment: nicht Teil der Eingänge.)
let len = rng.f32();
check(&mut fails, &cur, &last, &format!("Strichmuster (Aufruf {i})"), || {
let _ = dash_phase(len, &cyc);
let _ = prepare_arc_dash(Some(&cyc));
let _ = prepare_arc_dash(None);
});
}
let _ = std::panic::take_hook();
assert!(decoded_ok > 0, "der Fuzz erreicht nie eine lesbare Szene — Ausgangspunkt prüfen");
if !fails.0.is_empty() {
let mut s = format!("{} verschiedene Panics in render2d:\n", fails.0.len());
for (k, (c, ctx)) in &fails.0 {
s += &format!(" {c}x {k}\n erstmals bei: {ctx}\n");
}
panic!("{s}");
}
}
+196
View File
@@ -0,0 +1,196 @@
//! [258] Robustheit der Eingänge von render3d (`web.rs`: `set_model`, `set_parts`, `cut_section_json`, Ghost-Teile):
//! das GPU-freie Rückgrat (JSON-Modell → `Scene::apply` → `chunk_data`, Schnitt `cut_section`) darf auf Unsinn nie
//! paniken — ein Panic legt im Browser das ganze WASM-Modul lahm. Ausgangspunkt ist ein gültiges Teile-Update
//! (Wand mit Öffnung/Loch/Schichten, Decke, Mesh, Dachschicht), dessen Zahlen/Typen/Felder zufällig verdorben werden
//! (0, ±1, 1e-30, 1e30, 1e300, falscher Typ, null, gelöscht, Array verkürzt/verdoppelt); dazu Zufallstext.
//! Fester Seed, eigener PRNG, jeder Aufruf unter `catch_unwind`. `ROBUST_N` (Standard 1500), `ROBUST_SEED`.
use render3d::scene::{PartsUpdate, Scene};
use render3d::section::{cut_section, SectionPlane};
use serde_json::{json, Value};
use std::collections::BTreeMap;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::sync::{Arc, Mutex};
struct Rng(u64);
impl Rng {
fn next(&mut self) -> u64 {
self.0 ^= self.0 >> 12;
self.0 ^= self.0 << 25;
self.0 ^= self.0 >> 27;
self.0.wrapping_mul(0x2545_F491_4F6C_DD1D)
}
fn below(&mut self, n: usize) -> usize {
if n == 0 { 0 } else { (self.next() % n as u64) as usize }
}
fn f32(&mut self) -> f32 {
const POOL: [f32; 10] = [0.0, -0.0, 1.0, -1.0, 1e-30, 1e30, f32::NAN, f32::INFINITY, f32::NEG_INFINITY, f32::MAX];
match self.below(3) {
0 => POOL[self.below(POOL.len())],
1 => f32::from_bits(self.next() as u32),
_ => (self.next() >> 40) as f32 / (1u64 << 24) as f32 * 20.0 - 10.0,
}
}
}
fn seed_update() -> Value {
json!({
"reset": true,
"upsert": [{
"id": "a",
"walls": [{
"start": [0.0, 0.0], "end": [6.0, 0.0], "thickness": 0.3, "height": 2.8, "baseElevation": 0.0,
"openings": [{"from": 1.0, "to": 2.0, "sill": 0.8, "height": 1.2}],
"holes": [{"from": 3.0, "to": 4.0, "zBottom": 0.0, "zTop": 2.1}],
"layers": [{"thickness": 0.1, "color": [0.9, 0.9, 0.9]}, {"thickness": 0.2, "color": [0.5, 0.4, 0.3]}]
}, {
"start": [6.0, 0.0], "end": [6.0, 4.0], "thickness": 0.3, "height": 2.8, "topDrop": [0.2, 0.0]
}],
"slabs": [{"outline": [[0.0, 0.0], [6.0, 0.0], [6.0, 4.0], [0.0, 4.0]], "zBottom": -0.2, "zTop": 0.0}],
"meshes": [{"positions": [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0], "indices": [0, 1, 2]}],
"roofLayers": [{"polygon": [[0.0, 2.8, 0.0], [6.0, 2.8, 0.0], [6.0, 3.6, 4.0], [0.0, 3.6, 4.0]], "normal": [0.0, 0.9, -0.4], "thickness": 0.2, "color": [0.6, 0.2, 0.2]}]
}]
})
}
/// Zahlen verdorben, Typen vertauscht, Felder gelöscht, Arrays verändert.
fn mutate(v: &mut Value, rng: &mut Rng, budget: &mut u32) {
match v {
Value::Number(_) => {
if *budget > 0 && rng.below(6) == 0 {
*budget -= 1;
*v = match rng.below(9) {
0 => json!(0),
1 => json!(-1),
2 => json!(1e-30),
3 => json!(1e30),
4 => json!(1e300),
5 => json!(4294967296u64),
6 => json!(-4294967295i64),
7 => json!(0.5),
_ => Value::Null,
};
}
}
Value::Array(a) => {
if *budget > 0 && rng.below(10) == 0 {
*budget -= 1;
match rng.below(4) {
0 => a.clear(),
1 => {
a.pop();
}
2 => {
if let Some(x) = a.first().cloned() {
a.push(x);
}
}
_ => a.push(json!("x")),
}
}
for x in a.iter_mut() {
mutate(x, rng, budget);
}
}
Value::Object(m) => {
if *budget > 0 && rng.below(14) == 0 {
*budget -= 1;
if let Some(k) = m.keys().nth(rng.below(m.len())).cloned() {
m.remove(&k);
}
}
for (_, x) in m.iter_mut() {
mutate(x, rng, budget);
}
}
Value::String(_) => {
if *budget > 0 && rng.below(4) == 0 {
*budget -= 1;
*v = json!(rng.below(100));
}
}
_ => {}
}
}
#[test]
fn render3d_eingaenge_kaputte_daten() {
let n: u64 = std::env::var("ROBUST_N").ok().and_then(|v| v.parse().ok()).unwrap_or(1500);
let seed: u64 = std::env::var("ROBUST_SEED").ok().and_then(|v| v.parse().ok()).unwrap_or(0x5eed_258) | 1;
let default = std::panic::take_hook();
let cur = Arc::new(Mutex::new(false));
let last = Arc::new(Mutex::new(String::new()));
{
let (cur, last) = (cur.clone(), last.clone());
std::panic::set_hook(Box::new(move |info| {
if !*cur.lock().unwrap() {
default(info);
return;
}
let loc = info.location().map(|l| format!("{}:{}", l.file(), l.line())).unwrap_or_default();
let msg = info.payload().downcast_ref::<&str>().map(|s| s.to_string()).or_else(|| info.payload().downcast_ref::<String>().cloned()).unwrap_or_else(|| "?".into());
*last.lock().unwrap() = format!("{msg} @ {loc}");
}));
}
let mut fails: BTreeMap<String, (usize, String)> = BTreeMap::new();
let mut run = |ctx: String, f: &mut dyn FnMut()| {
*cur.lock().unwrap() = true;
let r = catch_unwind(AssertUnwindSafe(|| f()));
*cur.lock().unwrap() = false;
if r.is_err() {
let what = last.lock().unwrap().clone();
fails.entry(what).or_insert_with(|| (0, ctx)).0 += 1;
}
};
let mut rng = Rng(seed);
let mut parsed_ok = 0usize;
let mut scene = Scene::new();
for i in 0..n {
// Teile-Update: gültig verdorben, ab und zu reiner Zufallstext.
let text = if rng.below(12) == 0 {
let junk: Vec<u8> = (0..rng.below(60)).map(|_| rng.next() as u8).collect();
String::from_utf8_lossy(&junk).into_owned()
} else {
let mut v = seed_update();
let mut budget = 1 + rng.below(4) as u32;
mutate(&mut v, &mut rng, &mut budget);
v.to_string()
};
let plane_pt = [rng.f32(), rng.f32(), rng.f32()];
let plane_n = [rng.f32(), rng.f32(), rng.f32()];
let fresh = rng.below(3) == 0;
run(format!("Teile-Update/Ketten (Aufruf {i}, Seed {seed}): {text}"), &mut || {
let Ok(upd) = serde_json::from_str::<PartsUpdate>(&text) else { return };
parsed_ok += 1;
if fresh {
scene = Scene::new();
}
let change = scene.apply(upd);
let _ = scene.bounds();
let _ = scene.shadow_bounds();
let _ = scene.terrain();
let _ = scene.has_edges();
let _ = scene.edge_adj().count();
for c in 0..scene.chunk_count() {
let _ = scene.chunk_data(c);
}
let _ = change.dirty_chunks.len();
let (walls, slabs, roofs) = scene.collect_inputs();
let plane = SectionPlane::new(plane_pt, plane_n);
let _ = cut_section(&plane, &walls, &slabs, &roofs);
});
}
let _ = std::panic::take_hook();
assert!(parsed_ok > (n / 4) as usize, "zu wenige lesbare Updates ({parsed_ok}) — Ausgangspunkt prüfen");
if !fails.is_empty() {
let mut s = format!("{} verschiedene Panics in render3d:\n", fails.len());
for (k, (c, ctx)) in &fails {
s += &format!(" {c}x {k}\n erstmals bei: {}\n", &ctx[..ctx.len().min(1500)]);
}
panic!("{s}");
}
}