Files
DOSSIER/src/compute/index.ts
T
karim 1507c2bf00 God-Files aufgeteilt (ResourceManager/generatePlan/toWalls3d/App.tsx-Handler), Totcode entfernt (geometry-Crate, OCCT/HLR-Spike), PDF/Bild-Import ergänzt.
ResourceManager.tsx, generatePlan.ts und toWalls3d.ts sind nach Bauteil-
Domäne in src/ui/resourceManager/, src/plan/generatePlan/ und
src/plan/toWalls3d/ aufgeteilt (reine Verschiebung, keine Verhaltens-
änderung). App.tsx verliert weitere Handler-Gruppen an eigene Hooks
(useExportHandlers, useImportHandling, useKeyboardShortcuts) sowie
Hit-Testing an src/viewport/planHitTest.ts.

Unbenutzte Rust-geometry-Crate (durch WASM-Joins abgelöst) sowie der alte
OCCT/HLR-Schnitt-Spike (hlr.ts/occt.ts, vite occt-Aliases) entfernt.

Neu: PDF-Import als Rasterbild (src/io/pdfImport.ts) + gemeinsamer
Bild-Asset-Helfer (src/io/imageAsset.ts) für Plan- und Layout-Bilder.

tsc -b sauber, vitest 891/891 grün.
2026-08-19 22:45:41 +02:00

102 lines
3.5 KiB
TypeScript

// Compute-Grenze: der EINE Einstiegspunkt für rechenintensive Operationen.
// War als Brücke zu einem Rust-`#[tauri::command]` gedacht (PoC), aber
// ungenutzt: kein Aufrufer im Frontend, und die Rust-Seite (`compute_joins` +
// das `geometry`-Crate) wurde entfernt (ungenutzter Totcode, s. PENDENZEN.md).
// `computeJoins` läuft daher immer über den TS-Fallback; die übrigen
// Funktionen waren schon vorher reine TS-Pass-throughs.
import type { Project, Wall } from "../model/types";
import { getWallType, wallTypeThickness } from "../model/types";
import { wallReferenceOffset } from "../model/wall";
import { computeJoins as computeJoinsTS } from "../model/joins";
import type { WallCuts } from "../model/joins";
import type { Line } from "../model/geometry";
import { detectRooms as detectRoomsTS } from "../geometry/roomBoundary";
import type { WallSegment, DetectRoomsOptions } from "../geometry/roomBoundary";
import { parseDwg as parseDwgTS } from "../io/dwgParser";
import type { DxfImportResult } from "../io/dxfParser";
import type { Vec2 } from "../model/types";
// Tauri-invoke, wenn vorhanden — sonst null (Browser/kein Tauri). Dynamischer,
// GEGUARDETER Import, damit der Build ohne @tauri-apps/api grün bleibt.
async function tauriInvoke<T>(cmd: string, args: Record<string, unknown>): Promise<T | null> {
try {
// @ts-ignore optionales Paket
const mod = await import(/* @vite-ignore */ "@tauri-apps/api/core").catch(() => null);
if (!mod || typeof (mod as any).invoke !== "function") return null;
return await (mod as any).invoke(cmd, args) as T;
} catch {
return null;
}
}
/** Serialisierbare Wand-Repräsentation für den Rust-Kern. */
interface FlatWall {
id: string;
start: Vec2;
end: Vec2;
thickness: number;
referenceOffset: number;
}
/** Rohantwort des Rust-Befehls `compute_joins`. */
interface RustWallCut {
wallId: string;
startCut: Line | null;
endCut: Line | null;
}
/**
* Gehrungs-Schnittlinien pro Wand. Unter Tauri via Rust-Kern, sonst TS-Fallback.
* Die Signatur ist synchron-kompatibel zur TS-Impl, aber async (Rust-Aufruf).
*/
export async function computeJoins(
project: Project,
walls: Wall[],
): Promise<Map<string, WallCuts>> {
try {
const flattened: FlatWall[] = walls.map((w) => {
const thickness = wallTypeThickness(getWallType(project, w));
return {
id: w.id,
start: w.start,
end: w.end,
thickness,
referenceOffset: wallReferenceOffset(w, thickness),
};
});
const res = await tauriInvoke<RustWallCut[]>("compute_joins", {
input: { walls: flattened },
});
if (res != null) {
const map = new Map<string, WallCuts>();
for (const c of res) {
map.set(c.wallId, { startCut: c.startCut, endCut: c.endCut });
}
return map;
}
} catch {
// fällt unten in den TS-Pfad
}
console.warn("Rust compute_joins nicht verfügbar, TS-Fallback");
return computeJoinsTS(project, walls);
}
// ── Pass-throughs (noch reines TS; bereit für spätere Rust-Migration) ─────────
/** Raumerkennung aus Wandsegmenten. Aktuell TS; Grenze für spätere Migration. */
export async function detectRooms(
walls: WallSegment[],
options: DetectRoomsOptions = {},
): Promise<Vec2[][]> {
return detectRoomsTS(walls, options);
}
/** DWG-Import (LibreDWG-WASM). Aktuell TS; Grenze für spätere Migration. */
export async function parseShapeFromDwg(
data: ArrayBuffer,
): Promise<DxfImportResult> {
return parseDwgTS(data);
}