[K4] S3: Transformation und 2D-Editier-Befehle im Kern (cmd_transform.rs, cmd_edit.rs)

Verschieben/Drehen/Spiegeln/Skalieren/Reihe (alle Elementarten, Vorschau je Mausschritt),
Ausrichten/Verteilen, Block definieren, Trim, Extend, Verrunden, Fasen, Bruch, Offset, Join,
Auflösen rechnen Treffer, Vorschau und Ops im Kern; TS behält die Zustandsautomaten.
cmdMutation + doc_cmd_commit: rechnen und anwenden in einem Kern-Aufruf. Gelöscht:
geometry/geomTransform.ts, tools/drawingPreview.ts, transformSolid, joinDrawings und die
nicht mehr benutzten Kernel-Fassaden samt Bindungen. Gleichheit über Zufallsprojekte
(temporäre Tests, gelöscht) s. TODO.md.
This commit is contained in:
Claude committed 2026-10-29 12:56:27 +00:00
1 parent 30f573e43d
commit ffc1e3a074
45 files changed
+2612 -2620

No files matched your search

+52
View File
@@ -10,6 +10,8 @@ import { applyOps, opsToJson } from "./ops";
import { fromMarkedJson, toMarkedJson } from "./ops";
import type { CoreOp } from "./ops";
import { fieldOps } from "./opsBuild";
import { opsMutation } from "./opsBuild";
import type { ProjectMutation } from "./opsBuild";
/** Ergebnis des Ladens einer Projektdatei ({@link ProjectDocument.loadFile}). */
export type LoadFileResult =
@@ -277,6 +279,48 @@ export class ProjectDocument {
return fromMarkedJson(out);
}
/**
* Ops eines Befehls ([K4] S3, `commands.rs`): `req` = `{cmd, …}` (Zahlen dürfen NaN/±∞ sein), gerechnet
* auf dem Stand des Dokuments (ohne Anwenden). Nicht endliche Ergebnisse kommen als Zahlen zurück.
*/
cmdOps(req: object): CoreOp[] {
if (!this.handle) throw new Error("Kern-Abfrage „cmdOps“: Dokument nicht offen");
const out = core().doc_query_root(this.handle, "cmdOps", toMarkedJson(req));
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
return fromMarkedJson<{ ops: CoreOp[] }>(out).ops;
}
/**
* Befehl rechnen und anwenden ([K4] S3, `doc_cmd_commit`): wie {@link commitGrip} — ein Kern-Aufruf
* statt Ops hin (Rechnung) und zurück (Commit). Ergebnis: neues Projekt und die angewendeten Ops (leer
* = nichts zu tun, dann `project === base`) oder die Meldungen der Prüfung.
*/
commitCmd(base: Project, req: object, coalesceKey: string | undefined, now: number): { project: Project; ops: CoreOp[] } | { problems: string[] } {
this.ensure(base);
if (!this.handle) return { problems: ["Projekt-Dokument im Kern nicht offen."] };
const out = core().doc_cmd_commit(this.handle, toMarkedJson(req), coalesceKey ?? "", now);
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
const r = fromMarkedJson<{ ops: CoreOp[] } | { problems: string[] }>(out);
if ("problems" in r) return r;
if (r.ops.length === 0) return { project: base, ops: r.ops };
const project = applyOps(base, r.ops);
this.mirror = project;
return { project, ops: r.ops };
}
/** Abfrage eines Befehls zwischen den Schritten (`doc_cmd_query`: Treffer, Vorschau-Formen), JSON-Antwort. */
cmdQuery<T>(req: object): T {
if (!this.handle) throw new Error("Kern-Abfrage „cmdQuery“: Dokument nicht offen");
const out = core().doc_cmd_query(this.handle, toMarkedJson(req));
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
return fromMarkedJson<T>(out);
}
/** Vorschau-Formen eines Befehls (`doc_cmd_preview`): flach je Form `[art, n, x0, y0, …]`. */
cmdPreview(req: object): Float64Array {
return this.handle ? core().doc_cmd_preview(this.handle, toMarkedJson(req)) : new Float64Array(0);
}
/** Einen Schritt zurück auf `base` (= aktuelles Projekt); `null` = nichts rückgängig zu machen. */
undo(base: Project): Project | null {
return this.jump(base, "doc_undo");
@@ -372,3 +416,11 @@ export function documentFor(project: Project): ProjectDocument {
else shared.sync(project);
return shared;
}
/**
* Änderung als Befehls-Anfrage an den Kern ([K4] S3, `commands.rs`): `toOps` rechnet die Ops auf dem
* Dokument des Projekts; der Store wendet `coreReq` direkt im Kern an (`ProjectDocument.commitCmd`).
*/
export function cmdMutation(req: object): ProjectMutation {
return Object.assign(opsMutation((p) => documentFor(p).cmdOps(req)), { coreReq: req });
}
+1
View File
@@ -50,6 +50,7 @@ export type { PdfVectorPage, PdfVectorPath, PdfVectorText } from "../io/pdfVecto
export { readMesh, meshObjectsToImportedMeshes, formatMeshReport, isMeshFile, MESH_UNITS, MESH_UNIT_SCALE } from "../io/meshImport";
export type { MeshObject, MeshImportReport, MeshUnit, MeshUp, MeshPlacement } from "../io/meshImport";
export { addItems, fieldOps, findItem, itemsOf, opsMutation, patchItem, patchItems, removeItems, replaceItem, replaceWithMany, setField, setFieldIfChanged } from "./opsBuild";
export { cmdMutation } from "./document";
export type { EntityCollection, EntityOf, ProjectMutation } from "./opsBuild";
export { EMPTY_MEMBERSHIP, containingGroupId, expandToGroups, isInsideActiveGroup, transitiveMembership } from "../model/groups";
export type { GroupMembership, MemberKind } from "../model/groups";
-18
View File
@@ -53,25 +53,9 @@ export {
} from "../geometry/snapSegments";
export {
mvGeom,
reversesOrientation,
scaleFactor,
scaleGeom,
} from "../geometry/geomTransform";
export {
type Chamfer,
type Fillet,
type TangentTarget,
breakCurve,
chamferCorner,
extendBulgeSegment,
extendSegment,
filletCorner,
joinChainsWithBulge,
nearestOnPolyline,
offsetPolyline,
offsetPolylineWithBulge,
offsetSegment,
pointSegmentDistance,
polylineEdges,
@@ -81,7 +65,6 @@ export {
splitClosedByChord,
splitPolylineAtParam,
tangentCircleCenters,
trimPolylineWithBulge,
vecEqual,
} from "../geometry/kernel2d";
@@ -157,7 +140,6 @@ export {
export {
extrudedSolidSpec,
transformSolid,
} from "../plan/extrudedSolidSpec";
export {
+5 -1
View File
@@ -169,7 +169,11 @@ function idTest<E>(ids: ReadonlySet<string> | readonly string[] | ((e: E) => boo
// ── Projekt → Projekt mit mitgeführten Ops ─────────────────────────────────
/** Projekt → Projekt-Funktion, die ihre Ops mitträgt (s. {@link opsMutation}). */
export type ProjectMutation = ((p: Project) => Project) & { readonly toOps: (p: Project) => CoreOp[] };
export type ProjectMutation = ((p: Project) => Project) & {
readonly toOps: (p: Project) => CoreOp[];
/** Befehls-Anfrage an den Kern (`cmdMutation`): der Store rechnet und wendet sie in einem Kern-Aufruf an. */
readonly coreReq?: object;
};
/**
* Verpackt einen Op-Bauer als Projekt → Projekt-Funktion (für Schnittstellen wie