[K4][G10] Merge: Aufräumen (tote TS-/Rust-Doppelspuren), id-Index, Commit ohne Kopie, Punkttyp im Kern; Tests unter Last stabil

CLAUDE.md: Dokument im Kern, Modulkarte nachgeführt.

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-29 13:21:24 +00:00
commit 34e77b607c
53 files changed
+1293 -1043

No files matched your search

+93
View File
@@ -0,0 +1,93 @@
// [K4] Messung: Objekt-Info (`deriveSelection`), Griff-Schritte und grosse Polylinien auf einem grossen
// Projekt (3000 Wände + 20 000 Zeichnungen, 40 Dächer) über den Store. Werte gehen nach stderr (TODO [K4]);
// die Grenzen sind grosszügig (Container unter Last), geprüft wird vor allem das Ergebnis.
import { describe, expect, it } from "vitest";
import { getState } from "./appStore";
import { deriveSelection } from "./selectionInfo";
import { sampleProject } from "../model/sampleProject";
import type { Drawing2D, Project, Roof, Wall } from "../model/types";
const st = () => getState();
function bigProject(): Project {
const base = sampleProject.walls;
const walls: Wall[] = Array.from({ length: 3000 }, (_, i) => ({
...base[i % base.length],
id: `w${i}`,
start: { x: i, y: 0 },
end: { x: i + 1, y: 0 },
}));
const level = sampleProject.drawingLevels[0].id;
const drawings: Drawing2D[] = Array.from({ length: 20000 }, (_, i) => ({
id: `d${i}`,
levelId: level,
categoryCode: "01",
geom:
i === 19000
? {
shape: "polyline",
closed: false,
pts: Array.from({ length: 5000 }, (_, k) => ({ x: k * 0.1, y: Math.sin(k / 50) })),
}
: { shape: "polyline", closed: false, pts: [{ x: i, y: 1 }, { x: i + 1, y: 2 }, { x: i + 2, y: 1 }] },
})) as Drawing2D[];
const roof = sampleProject.roofs![0];
const roofs: Roof[] = Array.from({ length: 40 }, (_, i) => ({
...roof,
id: `r${i}`,
outline: roof.outline.map((p) => ({ x: p.x + i * 10, y: p.y })),
}));
return { ...structuredClone(sampleProject), walls, drawings2d: drawings, roofs };
}
/** Kleinster Mittelwert (µs) aus `rounds` Läufen à `n` Aufrufen. */
function bench(n: number, fn: (i: number) => void, rounds = 3): number {
let best = Infinity;
for (let i = 0; i < Math.ceil(n / 4); i++) fn(i); // Aufwärmen (JIT, Caches)
for (let r = 0; r < rounds; r++) {
const t = performance.now();
for (let i = 0; i < n; i++) fn(i);
best = Math.min(best, ((performance.now() - t) * 1000) / n);
}
return best;
}
const sel = (p: Project, k: { wall?: string; drawing?: string; roof?: string }) =>
deriveSelection(p, k.wall ? [k.wall] : [], k.drawing ?? null, null, null, null, null, null, null, k.roof ?? null);
describe("Messung Objekt-Info und Griffe, 3000 Wände + 20 000 Zeichnungen", () => {
it("Objekt-Info, Griff-Schritte, Polylinien-Punkttyp", { timeout: 120000 }, () => {
st().loadProject(bigProject());
const p = st().project;
const out: string[] = [];
for (const i of [10, 1500, 2990]) {
expect(sel(p, { wall: `w${i}` })?.kind).toBe("wall");
out.push(`Info Wand ${i} ${bench(200, () => sel(p, { wall: `w${i}` })).toFixed(0)} µs`);
}
expect(sel(p, { drawing: "d10000" })?.kind).toBe("drawing2d");
out.push(`Info Zeichnung 10000 ${bench(200, () => sel(p, { drawing: "d10000" })).toFixed(0)} µs`);
expect(sel(p, { roof: "r20" })?.kind).toBe("roof");
out.push(`Info Dach (40 im Wechsel) ${bench(200, (i) => sel(p, { roof: `r${i % 40}` })).toFixed(0)} µs`);
for (const i of [10, 1500, 2990]) {
const us = bench(50, (k) => st().moveGripOf(null, `w${i}`, 0, { x: i + (k % 7) * 0.01, y: 0.5 }));
out.push(`Griff Wand ${i} ${us.toFixed(0)} µs`);
}
expect(st().project.walls[1500].start.y).toBe(0.5);
const big = (k: number) => st().moveGripOf("d19000", null, 2500, { x: 250 + (k % 5) * 0.01, y: 3 });
out.push(`Griff Polylinie 5000 Punkte ${(bench(20, big) / 1000).toFixed(2)} ms`);
out.push(`Griff Zeichnung 15000 ${bench(50, (k) => st().moveGripOf("d15000", null, 1, { x: 15001, y: 2 + (k % 5) * 0.01 })).toFixed(0)} µs`);
const types = ["arc", "spline", "corner"] as const;
out.push(
`Punkttyp Polylinie 5000 Punkte ${(bench(20, (k) => st().setPolylineVertexType("d19000", 100 + k, types[k % 3])) / 1000).toFixed(2)} ms`,
);
out.push(`Punkttyp kleine Polylinie ${bench(50, (k) => st().setPolylineVertexType("d12000", 1, types[k % 3])).toFixed(0)} µs`);
st().setPolylineVertexType("d12000", 1, "arc");
expect((st().project.drawings2d[12000].geom as { bulge?: number[] }).bulge?.length).toBe(2);
st().setPolylineVertexType("d12000", 1, "corner");
expect((st().project.drawings2d[12000].geom as { bulge?: number[] }).bulge).toBeUndefined();
process.stderr.write(`Objekt-Info/Griffe (Store): ${out.join(", ")}\n`);
});
});
+3 -11
View File
@@ -22,7 +22,7 @@ import {
setField,
setFieldIfChanged,
} from "../core";
import { withVertexType, type PolylineVertexType } from "../core";
import type { PolylineVertexType } from "../core";
import { sampleProject } from "../model/sampleProject";
import {
addChildByCode,
@@ -218,7 +218,7 @@ export interface ProjectSlice {
deleteDrawingPoint: (drawingId: string, index: number) => void;
/**
* Punkttyp eines Polylinien-Stützpunkts setzen (Eckpunkt/Bogenpunkt/Splinepunkt),
* s. `geometry/polylineVertexType.ts` — rechnet nur die Bulges der beiden
* im Kern (`polyline_vertex.rs`, Griff-Änderung `vertexType`) — rechnet nur die Bulges der beiden
* anliegenden Segmente um.
*/
setPolylineVertexType: (drawingId: string, index: number, type: PolylineVertexType) => void;
@@ -1055,15 +1055,7 @@ export function createProjectSlice(
applyGrip({ op: "insertPoint", id: drawingId, seg: segIndex, pt: gripPt(pt) }),
setPolylineVertexType: (drawingId, index, type) =>
applyChange((p) =>
patchItem(p, "drawings2d", drawingId, (d) => {
if (d.geom.shape !== "polyline" || d.locked) return d;
const g = d.geom;
const bulge = withVertexType(g, index, type);
const { bulge: _old, ...rest } = g;
return { ...d, geom: bulge.some((b) => b !== 0) ? { ...rest, bulge } : rest };
}),
),
applyGrip({ op: "vertexType", id: drawingId, index, vertexType: type }),
deleteDrawingPoint: (drawingId, index) => applyGrip({ op: "deletePoint", id: drawingId, index }),
+1 -18
View File
@@ -547,25 +547,8 @@ export function deriveSelection(
columnId: selectedColumnId,
roofId: selectedRoofId,
contextObjectId: selectedContextObjectId,
// Lage in der Leseansicht (= Reihenfolge im Dokument): erspart dem Kern die lineare Suche.
at: {} as Record<string, number>,
};
const P = project as unknown as Record<string, { id: string }[] | undefined>;
const hint = (list: string, id: string | null | undefined) => {
if (!id) return;
const i = (P[list] ?? []).findIndex((x) => x.id === id);
if (i >= 0) args.at[list] = i;
};
hint("context", selectedContextObjectId);
hint("drawings2d", selectedDrawingId);
hint("extrudedSolids", selectedExtrudedSolidId);
hint("columns", selectedColumnId);
hint("openings", selectedOpeningId);
hint("walls", selectedWallIds[0]);
hint("ceilings", selectedCeilingId);
hint("roofs", selectedRoofId);
hint("stairs", selectedStairId);
hint("rooms", selectedRoomId);
// Das Element sucht der Kern über den Positions-Index des Dokuments (keine lineare Suche).
let sel: Selection | null;
try {
sel = documentFor(project).queryRootMarked<Selection | null>("selectionInfo", JSON.stringify(args));