[K4] Merge: Griffe und Objekt-Info im Kern (grips.rs, selection_info.rs), 3D-Griffhöhen

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-29 10:51:42 +00:00
commit 30f573e43d
46 files changed
+3352 -2427

No files matched your search

+48
View File
@@ -7,6 +7,7 @@
import type { Project } from "../model/types";
import { core } from "../engine/coreWasm";
import { applyOps, opsToJson } from "./ops";
import { fromMarkedJson, toMarkedJson } from "./ops";
import type { CoreOp } from "./ops";
import { fieldOps } from "./opsBuild";
@@ -238,6 +239,44 @@ export class ProjectDocument {
return { project };
}
/**
* Griff-Änderung ([K4] S3, `grips.rs`): der Kern rechnet `req` (s. `GripRequest`) auf seinem Stand
* von `base` und wendet das Ergebnis wie {@link commit} an — ein Aufruf je Mausschritt. Ergebnis:
* neues Projekt und die angewendeten Ops (leer = nichts zu tun, dann `project === base`), ein
* Hinweis-Schlüssel (i18n) oder die Meldungen der Prüfung (dann bleibt alles unverändert).
*/
commitGrip(base: Project, req: object, coalesceKey: string | undefined, now: number): { project: Project; ops: CoreOp[]; notice?: string } | { problems: string[] } {
this.ensure(base);
if (!this.handle) return { problems: ["Projekt-Dokument im Kern nicht offen."] };
const out = core().doc_grip_commit(this.handle, gripJson(req), coalesceKey ?? "", now);
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
const r = fromMarkedJson<{ ops: CoreOp[]; notice?: string } | { problems: string[] }>(out);
if ("problems" in r) return r;
if (r.ops.length === 0) return { project: base, ops: r.ops, notice: r.notice };
const project = applyOps(base, r.ops);
this.mirror = project;
return { project, ops: r.ops, notice: r.notice };
}
/**
* Wie {@link queryRoot} für Abfragen, deren Antwort nicht endliche Zahlen als Marken trägt
* (`selectionInfo`, `drawingBBoxes`); die Marken werden wieder Zahlen.
*/
queryRootMarked<T>(name: "selectionInfo" | "drawingBBoxes" | "verticalExtents", text = ""): T {
if (!this.handle) throw new Error(`Kern-Abfrage „${name}": Dokument nicht offen`);
const out = core().doc_query_root(this.handle, name, text);
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
return fromMarkedJson<T>(out);
}
/** Wie {@link commitGrip}, aber nur rechnen (ohne Anwenden): die Ops und ggf. der Hinweis. */
gripOps(req: object): { ops: CoreOp[]; notice?: string } {
if (!this.handle) throw new Error("Kern-Abfrage „gripOps“: Dokument nicht offen");
const out = core().doc_query_root(this.handle, "gripOps", gripJson(req));
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
return fromMarkedJson(out);
}
/** 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");
@@ -295,6 +334,15 @@ export class ProjectDocument {
}
}
/** Griff-Anfrage als JSON; Marken nur bei nicht endlichen Zahlen (der Ersetzer kostet je Wert einen Aufruf). */
function gripJson(req: object): string {
for (const v of Object.values(req)) {
const bad = typeof v === "number" ? !Number.isFinite(v) : Array.isArray(v) && v.some((x) => typeof x === "number" && !Number.isFinite(x));
if (bad) return toMarkedJson(req);
}
return JSON.stringify(req);
}
let shared: ProjectDocument | null = null;
/**
+4
View File
@@ -53,3 +53,7 @@ export { addItems, fieldOps, findItem, itemsOf, opsMutation, patchItem, patchIte
export type { EntityCollection, EntityOf, ProjectMutation } from "./opsBuild";
export { EMPTY_MEMBERSHIP, containingGroupId, expandToGroups, isInsideActiveGroup, transitiveMembership } from "../model/groups";
export type { GroupMembership, MemberKind } from "../model/groups";
export { drawingVertices, gripPt, openEdges, polylineEdgeGrips, ringEdges } from "../geometry/grips";
export { verticalExtents } from "../geometry/grips";
export type { VerticalExtent } from "../geometry/grips";
export type { GripRequest } from "../geometry/grips";
-5
View File
@@ -20,7 +20,6 @@ export {
export {
ceilingArea,
normalizeOutline,
outlineBBox,
pointInOutline,
} from "../geometry/ceiling";
@@ -98,7 +97,6 @@ export {
} from "../geometry/lineSegments";
export {
openingGapQuad,
openingVerticalExtent,
} from "../geometry/opening";
export { autoExteriorDimensions } from "../geometry/autoDimensions";
@@ -122,7 +120,6 @@ export {
} from "../geometry/revisionCloud";
export {
roofBBox,
roofBaseElevation,
roofGeometry,
} from "../geometry/roof";
@@ -130,7 +127,6 @@ export {
export {
addRoofHole,
removeRoofHole,
roofEdgeList,
roofHoleWorks,
setRoofEdge,
} from "../geometry/roofEdges";
@@ -155,7 +151,6 @@ export {
IDEAL_TREAD,
MIN_STEPS,
defaultStepCount,
stairBBox,
stairGeometry,
stairOutline,
} from "../geometry/stair";
+17
View File
@@ -154,6 +154,23 @@ export function opsToJson(ops: readonly CoreOp[]): string {
return JSON.stringify(ops, markNonFinite);
}
/** Wert als JSON mit Nicht-endlich-Marken (wie {@link opsToJson}), z. B. Anfragen an den Kern. */
export function toMarkedJson(v: unknown): string {
return JSON.stringify(v, markNonFinite);
}
/** Nicht-endlich-Marken des Kerns (`"\u0001NaN"` …) zurück in Zahlen. */
function reviveNonFinite(_key: string, v: unknown): unknown {
if (typeof v !== "string" || v.charCodeAt(0) !== 1) return v;
const t = v.slice(1);
return t === "NaN" ? NaN : t === "Infinity" ? Infinity : t === "-Infinity" ? -Infinity : v;
}
/** JSON des Kerns lesen; Nicht-endlich-Marken werden wieder Zahlen (nur wenn welche vorkommen). */
export function fromMarkedJson<T>(text: string): T {
return (text.includes("\\u0001") ? JSON.parse(text, reviveNonFinite) : JSON.parse(text)) as T;
}
// ── Validierung ([7]) — im Kern (`ops.rs`) ───────────────────────────────────
function problemsOf(json: string): string[] {