[K4][6][8] Aktionen erzeugen Ops direkt statt Projekt → Projekt + diffToOps

- Store `applyChange(ops | (p) => ops, coalesceKey?)` geht ohne Differenz an den Kern;
  `setProject` erkennt `opsMutation`-Funktionen und nimmt deren Ops.
- Umgestellt: Griffe (moveGripOf/moveElementByOf/moveEdgeOf, Decke/Dach/Treppe/Raum),
  Objekt-Info (updateWall/-Ceiling/-Opening/-Roof/-Stair/-Room/-Drawing2D, Farbe, Füllung,
  Vorder-/Hintergrund, Resize, Wand-/Deckendicke, Polylinien-Punkte), Auswahl verschieben/
  kopieren/drehen (`transformOps`), Löschen der Auswahl (+ Schnittlinien, eine Gruppe),
  Ebenen/Sichtbarkeit/Kategorien, Text-Tippen, Panel-Zeichnungs-Eigenschaften und die
  Zeichenbefehle (Wand, Decke, Raum, Treppe, Öffnung, Dach, Stütze, Extrusion, alle
  2D-Zeichenbefehle, move/copy/mirror/rotate/scale/array). Gruppen-Zuordnung beim Zeichnen
  in einer Gruppe über `activeGroupOps`.
- Griff-Zug mit mitgeführten Ecken: je Mausschritt eine Gruppe mit Schlüssel → ein
  Undo-Schritt für den ganzen Zug; aufgeschobene Commits beim Loslassen als Gruppe.
- Tests: Store-Zufallsfolgen (Leseansicht = Kern, Aktion = applyOps(vorher, ihre Ops),
  Undo bis Anfang/Redo bis Ende exakt), activeGroupOps = addNewElementsToActiveGroup;
  beim Umbau zusätzlich 2400 Zufallsschritte gegen die alte setProject-Fassung und 400
  Transformationen gegen das alte commitTransform geprüft (gleiches Projekt bis auf
  erzeugte ids und fehlend/leere Listen).
- Messung (vitest, 3000 Wände): Griff ziehen 3,3 → 0,2–0,3 ms/Schritt, Auswahl (300 Wände)
  verschieben 30 → 6–7 ms, Eigenschaft tippen 3 → 0,03 ms.

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-28 22:02:40 +00:00
1 parent b33f336bf0
commit a24cfbb3d7
49 files changed
+1001 -750

No files matched your search

+29
View File
@@ -7,6 +7,7 @@
import { describe, it, expect } from "vitest";
import {
activeGroupOps,
addNewElementsToActiveGroup,
applyGroupDimming,
applyGroupDimmingToPlan,
@@ -21,6 +22,9 @@ import {
import type { Primitive } from "../plan/generatePlan/shared";
import { materializeUnderlay, type Plan } from "../plan/generatePlan";
import type { Drawing2D, Group, Project } from "../model/types";
import { applyOps } from "../core/ops";
import type { CoreOp } from "../core/ops";
import { addItems, replaceItem } from "../core/opsBuild";
const EMPTY_MEM = {
wallIds: [] as string[],
@@ -261,6 +265,31 @@ describe("addNewElementsToActiveGroup", () => {
});
});
describe("activeGroupOps ([K4] S3: Ops statt Differenz)", () => {
const mk = (id: string): Group => ({ id, wallIds: ["w1"], drawingIds: [], ceilingIds: [], roomIds: [], stairIds: [], columnIds: [], roofIds: [], openingIds: [], groupIds: [] });
const line = (id: string) =>
({ id, type: "drawing2d", levelId: "eg", categoryCode: "20", geom: { shape: "line", a: { x: 0, y: 0 }, b: { x: 1, y: 0 } } }) as Project["drawings2d"][number];
const wall = (id: string) => ({ id, start: { x: 0, y: 0 }, end: { x: 1, y: 0 } }) as unknown as Project["walls"][number];
it("gleiches Ergebnis wie addNewElementsToActiveGroup, Zufall", () => {
let x = 11;
const r = () => ((x = (x * 1664525 + 1013904223) % 4294967296) / 4294967296);
for (let n = 0; n < 200; n++) {
const before: Project = { ...project([mk("g1"), mk("g2")]), drawings2d: [line("d0")], walls: [wall("w0")] };
const ops: CoreOp[] = [];
const k = Math.floor(r() * 4);
if (k >= 1) ops.push(...addItems("drawings2d", [line(`a${n}`), line(`b${n}`)], r() < 0.5 ? 0 : undefined));
if (k >= 2) ops.push(...addItems("walls", [wall(`w${n}x`)]));
if (k >= 3) ops.push(replaceItem("drawings2d", { ...line("d0"), color: "#f00" }));
const path = r() < 0.2 ? [] : r() < 0.5 ? ["g1"] : ["g2", "g1", "gx"];
const after = applyOps(before, ops);
const legacy = addNewElementsToActiveGroup(before, after, path);
const viaOps = applyOps(before, [...ops, ...activeGroupOps(before, ops, path)]);
expect(viaOps).toEqual(legacy);
}
});
});
describe("ungroup", () => {
it("löst genau EIN Level auf; Untergruppen bleiben als eigene Gruppen bestehen", () => {
const inner: Group = { id: "g1", wallIds: ["w1"], drawingIds: [], ceilingIds: [], roomIds: [], stairIds: [], columnIds: [], roofIds: [], openingIds: [], groupIds: [] };