diff --git a/CLAUDE.md b/CLAUDE.md index 66594798..388394a8 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -14,6 +14,7 @@ Anzeige nur über die zwei Rust-Engines `render2d` und `render3d` (WebGPU/Metal) ansehen") — Zahlen allein reichen nicht. 5. **Abschliessen:** kleine Commits, Nachricht deutsch, beginnt mit den IDs (`[63] Baurecht: …`), ohne Co-Authored-By-Zeile. `TODO.md` im selben Commit nachführen (Stand + Datum + was offen bleibt). + Gewollte Änderung an Plan/Schnitt/Ansicht/3D: `npx vitest run -u src/plan/golden.test.ts`, Diff in `src/plan/__golden__` im Commit prüfen ([119]). 6. **Ehrlich berichten:** was geprüft wurde und was nicht (z. B. „nicht in der Tauri-App getestet"). ``` diff --git a/TODO.md b/TODO.md index b84c1f5b..89e94d4f 100644 --- a/TODO.md +++ b/TODO.md @@ -1051,8 +1051,9 @@ Prüfung des ganzen Programms (Rust-Kern, TS-Hülle, Build/Sicherheit), nur Code `connect-src` = netFetch-Hosts + ipc). Rich-Text-`innerHTML` prüfen. · S - ○ **[118] Wiederanlauf nach Kern-Panic.** Dokument + Verlauf im selben WASM wie alle Geometrie (`web/document.rs`); TS hält Op-Log seit letztem Laden, baut Instanz nach Trap neu auf. · M -- ○ **[119] Referenz-Ausgaben (golden).** Plan-Puffer/SVG/Schnitt/Ansicht der Musterprojekte als Snapshot; - seit TS gelöscht ist, fehlt die Bitgleich-Referenz. · M +- ✅ **[119] Referenz-Ausgaben (golden).** 3.11.: `src/plan/golden.test.ts` — beide Musterprojekte: Grundriss je Geschoss + (1:100, 1:50), Schnitt, Ansicht, 3D-Zusammenfassung als Digest (Zähler, Rahmen, Hash gerundeter Zahlen) in + `src/plan/__golden__/`; Update mit `vitest -u`. Nur Linux geprüft; Hash deckt Detailabweichungen ab, Diff zeigt nur Zähler. · M - ○ **[120] macOS in CI.** `cargo check --features native2d`, Bildvergleich Metal ↔ WebGPU. · M - ○ **[121] App.tsx zerlegen, Neurendern stoppen.** `App.tsx:365` abonniert ganzes Projekt, 0× `memo`; Abschnitte in Hooks/Komponenten, Panels lesen den Store selbst; Nebenfenster bekommen Ops statt Projekt. · L diff --git a/src/plan/__golden__/komplex-ansicht-ansicht-sued.txt b/src/plan/__golden__/komplex-ansicht-ansicht-sued.txt new file mode 100644 index 00000000..42327abe --- /dev/null +++ b/src/plan/__golden__/komplex-ansicht-ansicht-sued.txt @@ -0,0 +1,9 @@ +viewBox -4.2 0 37.045 17.778 +bytes 344306 +circle 4 +line 1261 +polygon 1529 +rect 1 +svg 1 +text 4 +hash ac47902c2752e848 diff --git a/src/plan/__golden__/komplex-grundriss-dg-100.txt b/src/plan/__golden__/komplex-grundriss-dg-100.txt new file mode 100644 index 00000000..9ba222c5 --- /dev/null +++ b/src/plan/__golden__/komplex-grundriss-dg-100.txt @@ -0,0 +1,10 @@ +viewBox -16.5 0 49 35.22 +bytes 339680 +circle 14 +line 3498 +path 8 +polygon 91 +rect 1 +svg 1 +text 36 +hash 30888ca0d5cb84be diff --git a/src/plan/__golden__/komplex-grundriss-dg-50.txt b/src/plan/__golden__/komplex-grundriss-dg-50.txt new file mode 100644 index 00000000..c9504c2e --- /dev/null +++ b/src/plan/__golden__/komplex-grundriss-dg-50.txt @@ -0,0 +1,10 @@ +viewBox -16.5 0 49 35.22 +bytes 343059 +circle 14 +line 3498 +path 8 +polygon 91 +rect 1 +svg 1 +text 36 +hash f96ebde7ba7f7e74 diff --git a/src/plan/__golden__/komplex-grundriss-eg-100.txt b/src/plan/__golden__/komplex-grundriss-eg-100.txt new file mode 100644 index 00000000..48d39275 --- /dev/null +++ b/src/plan/__golden__/komplex-grundriss-eg-100.txt @@ -0,0 +1,10 @@ +viewBox -41.5 0 95 63.6 +bytes 148973 +circle 16 +line 861 +path 68 +polygon 260 +rect 1 +svg 1 +text 123 +hash aefdd0fe3c4658bd diff --git a/src/plan/__golden__/komplex-grundriss-eg-50.txt b/src/plan/__golden__/komplex-grundriss-eg-50.txt new file mode 100644 index 00000000..58242c95 --- /dev/null +++ b/src/plan/__golden__/komplex-grundriss-eg-50.txt @@ -0,0 +1,10 @@ +viewBox -41.5 0 95 63.6 +bytes 149368 +circle 16 +line 861 +path 68 +polygon 260 +rect 1 +svg 1 +text 123 +hash 65c62fa0ef5ee339 diff --git a/src/plan/__golden__/komplex-grundriss-og-100.txt b/src/plan/__golden__/komplex-grundriss-og-100.txt new file mode 100644 index 00000000..0b01a191 --- /dev/null +++ b/src/plan/__golden__/komplex-grundriss-og-100.txt @@ -0,0 +1,10 @@ +viewBox -16.5 0 49 35.22 +bytes 425217 +circle 14 +line 4040 +path 40 +polygon 236 +rect 1 +svg 1 +text 93 +hash 961473ba9c3e6937 diff --git a/src/plan/__golden__/komplex-grundriss-og-50.txt b/src/plan/__golden__/komplex-grundriss-og-50.txt new file mode 100644 index 00000000..81774b12 --- /dev/null +++ b/src/plan/__golden__/komplex-grundriss-og-50.txt @@ -0,0 +1,10 @@ +viewBox -16.5 0 49 35.22 +bytes 428731 +circle 14 +line 4040 +path 40 +polygon 236 +rect 1 +svg 1 +text 93 +hash 6f37dfa59b4e84a0 diff --git a/src/plan/__golden__/komplex-grundriss-ug-100.txt b/src/plan/__golden__/komplex-grundriss-ug-100.txt new file mode 100644 index 00000000..915f1b5b --- /dev/null +++ b/src/plan/__golden__/komplex-grundriss-ug-100.txt @@ -0,0 +1,10 @@ +viewBox -16.5 0 49 38.11 +bytes 86366 +circle 14 +line 501 +path 29 +polygon 113 +rect 1 +svg 1 +text 74 +hash cd3c20b2431eec2e diff --git a/src/plan/__golden__/komplex-grundriss-ug-50.txt b/src/plan/__golden__/komplex-grundriss-ug-50.txt new file mode 100644 index 00000000..d00f81f1 --- /dev/null +++ b/src/plan/__golden__/komplex-grundriss-ug-50.txt @@ -0,0 +1,10 @@ +viewBox -16.5 0 49 38.11 +bytes 86522 +circle 14 +line 501 +path 29 +polygon 113 +rect 1 +svg 1 +text 74 +hash 53435c6a8ca1a431 diff --git a/src/plan/__golden__/komplex-model3d.txt b/src/plan/__golden__/komplex-model3d.txt new file mode 100644 index 00000000..538d46ea --- /dev/null +++ b/src/plan/__golden__/komplex-model3d.txt @@ -0,0 +1,53 @@ +meshes [1849] +meshes[].color [3] x1849 +meshes[].indices [108] x6 +meshes[].indices [156648] +meshes[].indices [348] x6 +meshes[].indices [36] x1816 +meshes[].indices [372] +meshes[].indices [4032] +meshes[].indices [60] x9 +meshes[].indices [72] +meshes[].indices [84] x2 +meshes[].indices [96] x6 +meshes[].positions [1044] x6 +meshes[].positions [108] x30 +meshes[].positions [180] x9 +meshes[].positions [192] +meshes[].positions [216] +meshes[].positions [24] x1781 +meshes[].positions [252] x2 +meshes[].positions [2688] +meshes[].positions [288] x6 +meshes[].positions [324] x6 +meshes[].positions [72] x5 +meshes[].positions [78840] +roofLayers [59] +roofLayers[].color [3] x59 +roofLayers[].normal [3] x59 +roofLayers[].polygon [4] x53 +roofLayers[].polygon [5] x6 +roofLayers[].polygon[] [3] x242 +slabs [102] +slabs[].color [3] x102 +slabs[].outline [12] +slabs[].outline [14] x5 +slabs[].outline [21] x4 +slabs[].outline [24] +slabs[].outline [33] x5 +slabs[].outline [4] x81 +slabs[].outline [51] x5 +slabs[].outline[] [2] x934 +walls [1508] +walls[].color [3] x1508 +walls[].end [2] x1508 +walls[].endCut [4] x1139 +walls[].holes [1] x84 +walls[].holes [2] x25 +walls[].holes [3] x14 +walls[].layers [0] x1508 +walls[].start [2] x1508 +walls[].startCut [4] x1137 +walls[].topDrop [2] x112 +walls[].topPlane [3] x268 +hash cd9596786d4adacb diff --git a/src/plan/__golden__/komplex-schnitt-schnitt-a.txt b/src/plan/__golden__/komplex-schnitt-schnitt-a.txt new file mode 100644 index 00000000..455a3b6a --- /dev/null +++ b/src/plan/__golden__/komplex-schnitt-schnitt-a.txt @@ -0,0 +1,9 @@ +viewBox 4.457 0 21.343 17.778 +bytes 44167 +circle 3 +line 148 +polygon 169 +rect 1 +svg 1 +text 3 +hash 3310ddbc4a0ea666 diff --git a/src/plan/__golden__/muster-ansicht-ansicht-sued.txt b/src/plan/__golden__/muster-ansicht-ansicht-sued.txt new file mode 100644 index 00000000..78e8913b --- /dev/null +++ b/src/plan/__golden__/muster-ansicht-ansicht-sued.txt @@ -0,0 +1,7 @@ +viewBox 0.1 0 6.8 7.586 +bytes 8483 +line 31 +polygon 42 +rect 1 +svg 1 +hash c9caba6eee20fbd9 diff --git a/src/plan/__golden__/muster-grundriss-eg-100.txt b/src/plan/__golden__/muster-grundriss-eg-100.txt new file mode 100644 index 00000000..c334f7c9 --- /dev/null +++ b/src/plan/__golden__/muster-grundriss-eg-100.txt @@ -0,0 +1,9 @@ +viewBox -0.672 0 6.345 5.345 +bytes 15919 +line 67 +path 8 +polygon 61 +rect 1 +svg 1 +text 7 +hash 97bd11bea3bf9d08 diff --git a/src/plan/__golden__/muster-grundriss-eg-50.txt b/src/plan/__golden__/muster-grundriss-eg-50.txt new file mode 100644 index 00000000..decb859d --- /dev/null +++ b/src/plan/__golden__/muster-grundriss-eg-50.txt @@ -0,0 +1,9 @@ +viewBox -0.672 0 6.345 5.345 +bytes 15939 +line 67 +path 8 +polygon 61 +rect 1 +svg 1 +text 7 +hash 7dfca568eb0b0d41 diff --git a/src/plan/__golden__/muster-grundriss-og-100.txt b/src/plan/__golden__/muster-grundriss-og-100.txt new file mode 100644 index 00000000..0fd1ba0c --- /dev/null +++ b/src/plan/__golden__/muster-grundriss-og-100.txt @@ -0,0 +1,9 @@ +viewBox -0.9 0 6.8 5.8 +bytes 7180 +line 35 +path 4 +polygon 23 +rect 1 +svg 1 +text 4 +hash 5b480a1ff81665ec diff --git a/src/plan/__golden__/muster-grundriss-og-50.txt b/src/plan/__golden__/muster-grundriss-og-50.txt new file mode 100644 index 00000000..df7c84d1 --- /dev/null +++ b/src/plan/__golden__/muster-grundriss-og-50.txt @@ -0,0 +1,9 @@ +viewBox -0.9 0 6.8 5.8 +bytes 7202 +line 35 +path 4 +polygon 23 +rect 1 +svg 1 +text 4 +hash f1c8c391382719b8 diff --git a/src/plan/__golden__/muster-model3d.txt b/src/plan/__golden__/muster-model3d.txt new file mode 100644 index 00000000..ca0e1205 --- /dev/null +++ b/src/plan/__golden__/muster-model3d.txt @@ -0,0 +1,31 @@ +meshes [44] +meshes[].color [3] x44 +meshes[].indices [36] x42 +meshes[].indices [540] +meshes[].indices [60] +meshes[].positions [120] +meshes[].positions [24] x42 +meshes[].positions [360] +roofLayers [2] +roofLayers[].color [3] x2 +roofLayers[].normal [3] x2 +roofLayers[].polygon [4] x2 +roofLayers[].polygon[] [3] x8 +slabs [3] +slabs[].color [3] x3 +slabs[].cut.lineColor [3] +slabs[].outline [4] x3 +slabs[].outline[] [2] x12 +walls [47] +walls[].color [3] x47 +walls[].cut.lineColor [3] x11 +walls[].end [2] x47 +walls[].endCut [4] x47 +walls[].holes [1] x5 +walls[].holes [2] x5 +walls[].layers [0] x47 +walls[].start [2] x47 +walls[].startCut [4] x47 +walls[].topDrop [2] x6 +walls[].topPlane [3] x6 +hash 43431f51d1e44e8b diff --git a/src/plan/__golden__/muster-schnitt-schnitt-a.txt b/src/plan/__golden__/muster-schnitt-schnitt-a.txt new file mode 100644 index 00000000..08bf1a7e --- /dev/null +++ b/src/plan/__golden__/muster-schnitt-schnitt-a.txt @@ -0,0 +1,7 @@ +viewBox 0.1 0 6.8 7.586 +bytes 7242 +line 31 +polygon 31 +rect 1 +svg 1 +hash 64ff798e38d40dd0 diff --git a/src/plan/golden.test.ts b/src/plan/golden.test.ts new file mode 100644 index 00000000..ab4e6d9d --- /dev/null +++ b/src/plan/golden.test.ts @@ -0,0 +1,101 @@ +// [119] Referenz-Ausgaben: Plan (je Geschoss, 1:100 und 1:50), ein Schnitt, eine Ansicht und die +// 3D-Zusammenfassung beider Musterprojekte als lesbarer Digest (Zähler, Rahmen, Hash der gerundeten +// Zahlen) gegen eingecheckte Dateien in src/plan/__golden__. Gewollte Änderung übernehmen mit +// npx vitest run -u src/plan/golden.test.ts +// und den Diff der Dateien im Commit ansehen. Zahlen sind gerundet (Plan 1e-3 m, 3D 1e-4 m). +import { describe, expect, it } from "vitest"; +import { createHash } from "node:crypto"; +import { computeSection, generateElevationPlan, generatePlan, generateSectionPlan, planToSvgString, projectToModel3d } from "../core"; +import { sampleProject } from "../model/sampleProject"; +import { buildComplexSampleProject } from "../model/sampleProjectComplex"; +import type { Project } from "../model/types"; + +const roundNums = (s: string, dec: number): string => + s.replace(/-?\d+\.\d+(?:e-?\d+)?/g, (m) => { + const v = Number(Number(m).toFixed(dec)); + return String(Object.is(v, -0) ? 0 : v); + }); +const sha = (s: string): string => createHash("sha256").update(s).digest("hex").slice(0, 16); + +function svgDigest(svg: string): string { + const s = roundNums(svg, 3); + const tags = new Map(); + for (const m of s.matchAll(/<([a-z]+)\b/g)) tags.set(m[1], (tags.get(m[1]) ?? 0) + 1); + const viewBox = /viewBox="([^"]*)"/.exec(s)?.[1] ?? "-"; + const lines = [`viewBox ${viewBox}`, `bytes ${s.length}`]; + for (const [k, v] of [...tags].sort()) lines.push(`${k} ${v}`); + lines.push(`hash ${sha(s)}`); + return lines.join("\n") + "\n"; +} + +// Beliebige Struktur → Zähler je Feld (Länge von Listen/Puffern) + Hash der gerundeten Zahlen. +function structDigest(o: unknown): string { + const lines: string[] = []; + const h = createHash("sha256"); + const walk = (v: unknown, path: string): void => { + if (typeof v === "number") { + h.update(path + "=" + Number(v.toFixed(4)) + ";"); + } else if (ArrayBuffer.isView(v)) { + const a = Array.from(v as unknown as ArrayLike); + lines.push(`${path} [${a.length}]`); + h.update(path + ":" + a.map((x) => Number(x.toFixed(4))).join(",") + ";"); + } else if (Array.isArray(v)) { + lines.push(`${path} [${v.length}]`); + v.forEach((x, i) => walk(x, `${path}[${i}]`)); + } else if (v && typeof v === "object") { + for (const k of Object.keys(v).sort()) walk((v as Record)[k], path ? `${path}.${k}` : k); + } else { + h.update(path + "=" + String(v) + ";"); + } + }; + walk(o, ""); + // Elementweise Pfade (mit Index) nur im Hash, im Text nur die Feldzähler ohne Index + const counts = new Map(); + for (const l of lines) { + const key = l.replace(/\[\d+\](?=[. ])/g, "[]"); + counts.set(key, (counts.get(key) ?? 0) + 1); + } + return [...counts].sort().map(([k, n]) => `${k}${n > 1 ? ` x${n}` : ""}`).join("\n") + `\nhash ${h.digest("hex").slice(0, 16)}\n`; +} + +const projects: [string, () => Project][] = [ + ["muster", () => sampleProject], + ["komplex", buildComplexSampleProject], +]; + +for (const [name, make] of projects) { + describe(`Golden ${name}`, () => { + const p = make(); + const codes = new Set(p.layers.map((l) => l.code)); + + for (const lvl of p.drawingLevels.filter((l) => l.kind === "floor")) { + for (const scale of [100, 50]) { + it(`Grundriss ${lvl.id} 1:${scale}`, async () => { + const svg = planToSvgString(generatePlan(p, lvl.id, codes, undefined, "mittel", false, false, true, scale), { scaleDenominator: scale }); + await expect(svgDigest(svg)).toMatchFileSnapshot(`__golden__/${name}-grundriss-${lvl.id}-${scale}.txt`); + }); + } + } + + it("Schnitt", async () => { + const sec = p.drawingLevels.find((l) => l.kind === "section"); + if (!sec) return; + const out = await computeSection(p, sec); + expect(out).toBeTruthy(); + const svg = planToSvgString(generateSectionPlan(out!, false, { visibleCodes: codes, hiddenLines: sec.hiddenLines, openings: true, scaleDenominator: 100 }), { scaleDenominator: 100 }); + await expect(svgDigest(svg)).toMatchFileSnapshot(`__golden__/${name}-schnitt-${sec.id}.txt`); + }, 30_000); + + it("Ansicht", async () => { + const el = p.drawingLevels.find((l) => l.kind === "elevation"); + if (!el) return; + const plan = generateElevationPlan(p, el, { scaleDenominator: 100 }); + expect(plan).toBeTruthy(); + await expect(svgDigest(planToSvgString(plan!, { scaleDenominator: 100 }))).toMatchFileSnapshot(`__golden__/${name}-ansicht-${el.id}.txt`); + }); + + it("3D-Modell", async () => { + await expect(structDigest(projectToModel3d(p))).toMatchFileSnapshot(`__golden__/${name}-model3d.txt`); + }); + }); +}