[K3d] Rahmen-Auswahl, Text-/Bild-Treffer im Kern; PlanView-Overlay liest nur Text-Einträge

plan_pick.rs: Rahmen-Auswahl über Polygone je Pick-Art und über 2D-Zeichnungen (Linien, Polygone,
abgetastete Kreise/Bögen, Text-/Bild-Rahmen, Unterlage ausgenommen), Einzeltext-/Bild-Treffer und
Form einer Zeichnung (drawingLabel). Gleichheit gegen die alte TS-Fassung (temporärer Test, 53 870
Vergleiche: 200 Zufallspläne, Beispiel EG/OG/UG, Überlagerung, bigSample(6)). TS-Fassungen
marqueeHit*/marqueeHitDrawings gelöscht, Tests auf den Kern umgestellt.

PlanView: Einzelzugriffe über planPrimAt, SVG-Kandidaten/Culling mit GPU nur aus den Text-Einträgen
(planTextEntries), Schraffur-Muster nur ohne GPU; planSceneTexts und native Text-Sync lesen nur
Text-Einträge; Überlagerung in viewportContent ohne Lesen (planWithExtra).

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-29 01:30:21 +00:00
1 parent 6715ed826f
commit 70bb23f2bc
13 files changed
+594 -264

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
// Lazy Plan ([K3d], `planLazy.ts`): `generatePlan` liest die Kern-Primitive erst bei Bedarf; die
// Verbraucher im Kern (Szene, Auswahl, SVG) und die Text-Einträge kommen ohne aus.
import { describe, expect, it } from "vitest";
import { generatePlan, generateVisibleLevelsPlan, materializeUnderlay, type Primitive } from "./generatePlan";
import { isLazyUnread, planCount, planPrimAt, planTextEntries, planWithExtra } from "./planLazy";
import { planSceneBin, planToRenderScene } from "./toRenderScene";
import { planToSvgString } from "../export/planToSvgString";
import { PlanPickIndex } from "./planView/planPick";
import { sampleProject } from "../model/sampleProject";
import { flattenCategories, type Project } from "../model/types";
const codes = (p: Project) => new Set(flattenCategories(p.layers).map((c) => c.code));
const withText: Project = {
...sampleProject,
drawings2d: [
...sampleProject.drawings2d,
{ id: "t1", type: "drawing2d", levelId: "eg", categoryCode: "60", geom: { shape: "text", at: { x: 1, y: 2 }, text: "Hallo", height: 0.3, angle: 0 } },
{ id: "l1", type: "drawing2d", levelId: "eg", categoryCode: "60", geom: { shape: "line", a: { x: 0, y: 0 }, b: { x: 3, y: 1 } } },
] as Project["drawings2d"],
};
describe("lazy Plan", () => {
it("Verbraucher im Kern lesen die Primitive nicht", () => {
const plan = generatePlan(withText, "eg", codes(withText));
expect(isLazyUnread(plan)).toBe(true);
planSceneBin(plan);
planToRenderScene(plan);
planToSvgString(plan);
const ix = new PlanPickIndex(plan);
ix.topPolygon({ x: 2, y: 2 });
ix.marquee("wallId", { minX: -100, minY: -100, maxX: 100, maxY: 100 }, false);
ix.drawingTextAt({ x: 1.2, y: 2 });
ix.release();
expect(planTextEntries(plan).length).toBeGreaterThan(0);
expect(planPrimAt(plan, 0)).toBeDefined();
expect(isLazyUnread(plan)).toBe(true);
});
it("Einzelzugriff, Text-Einträge und Anzahl == gelesene Liste (dieselben Objekte)", () => {
for (const l of ["eg", "og"]) {
const plan = generatePlan(withText, l, codes(withText));
const n = planCount(plan);
const single = Array.from({ length: n }, (_, i) => planPrimAt(plan, i));
const texts = planTextEntries(plan);
expect(plan.primitives.length).toBe(n);
single.forEach((p, i) => expect(p).toBe(plan.primitives[i]));
const want = plan.primitives
.map((p, i) => ({ p, i }))
.filter((e) => e.p.kind === "text" || e.p.kind === "drawingText" || e.p.kind === "drawingTextPath" || e.p.kind === "drawingImage");
expect(texts.map((e) => e.i)).toEqual(want.map((e) => e.i));
texts.forEach((e, k) => expect(e.p).toBe(want[k].p));
expect(planPrimAt(plan, n)).toBeUndefined();
}
});
it("Überlagerung, kompakte Unterlage und Anhängen bleiben lazy und gleich", () => {
const plan = generateVisibleLevelsPlan(withText, "og", codes(withText), undefined, "mittel", false, false, undefined, 100, true);
expect(isLazyUnread(plan)).toBe(true);
const mat = materializeUnderlay(plan);
const extra: Primitive = { kind: "line", a: { x: 0, y: 0 }, b: { x: 1, y: 1 }, cls: "x", weightMm: 0.1 };
const ext = planWithExtra(mat, [extra], [extra]);
expect(isLazyUnread(mat) && isLazyUnread(ext)).toBe(true);
expect(ext.primitives).toEqual([extra, ...mat.primitives, extra]);
expect(ext.greyedRanges).toEqual(mat.greyedRanges?.map(([a, b]) => [a + 1, b + 1]));
// Eager zum Vergleich: dieselbe Liste wie die gelesene.
expect(plan.primitives.length).toBe(planCount(plan));
});
it("Mono bleibt eine gewöhnliche Liste", () => {
const plan = generatePlan(sampleProject, "eg", codes(sampleProject), undefined, "mittel", false, true);
expect(isLazyUnread(plan)).toBe(false);
});
});
+13 -2
View File
@@ -1,13 +1,24 @@
/**
* `marqueeHitDrawings` — Rahmenauswahl von 2D-Zeichenelementen. Vorher fehlten
* Rahmenauswahl von 2D-Zeichenelementen (`PlanPickIndex.marqueeDrawings`). Vorher fehlten
* drawingCircle/drawingArc/drawingText/drawingImage komplett (nur line/polygon
* abgedeckt) — Regressionsschutz für den Nachzieh-Fix (2D-Vervollständigung,
* Fund A).
*/
import { describe, it, expect } from "vitest";
import { marqueeHitDrawings, type ModelRect } from "./geometry";
import type { ModelRect } from "./geometry";
import type { Primitive } from "../generatePlan";
import { PlanPickIndex } from "./planPick";
/** Rahmen-Auswahl über 2D-Zeichnungen im Kern ([K3d], `PlanPickIndex.marqueeDrawings`). */
function marqueeHitDrawings(prims: Primitive[], rect: ModelRect, crossing: boolean): string[] {
const ix = new PlanPickIndex({ primitives: prims, bounds: { minX: 0, minY: 0, maxX: 1, maxY: 1 } });
try {
return ix.marqueeDrawings(rect, crossing);
} finally {
ix.release();
}
}
const encloseRect: ModelRect = { minX: -10, minY: -10, maxX: 10, maxY: 10 };
const missRect: ModelRect = { minX: 20, minY: 20, maxX: 30, maxY: 30 };
+3 -137
View File
@@ -3,7 +3,6 @@
// Keine JSX, kein Komponenten-/Closure-Zugriff — pure Funktionen + Konstanten.
import type { Vec2 } from "../../model/types";
import type { Primitive } from "../generatePlan";
/** Rechteckiger Ausschnitt in SVG-Benutzerkoordinaten (viewBox-Einheiten). */
export interface ViewBox {
@@ -231,142 +230,9 @@ export interface ModelRect {
maxY: number;
}
/**
* Bestimmt die vom Auswahl-Rechteck getroffenen Wand-IDs nach CAD-Konvention:
* • crossing = false (links→rechts): nur Wände, deren Polygone VOLLSTÄNDIG im
* Rechteck liegen (jeder Eckpunkt enthalten).
* • crossing = true (rechts→links): zusätzlich Wände, die das Rechteck nur
* BERÜHREN/kreuzen (Überlappung der Polygone mit dem Rechteck).
* Getestet wird je Wand über ALLE ihre Polygon-Bänder; ein Treffer eines Bandes
* genügt. Liefert eindeutige IDs in Auftreten-Reihenfolge.
*/
export function marqueeHit(
prims: Primitive[],
rect: ModelRect,
crossing: boolean,
): string[] {
return marqueeHitByField(prims, "wallId", rect, crossing);
}
/**
* Generische Variante von {@link marqueeHit} für ein beliebiges Polygon-ID-
* Feld (`ceilingId`/`roomId`/`stairId`/`columnId`/`roofId`/…) — dieselbe
* window/crossing-Konvention, nur auf ein anderes Element bezogen. Deckt
* Nutzer-Report: „Auswahlrahmen kann Decken/Räume/Treppen nicht anwählen"
* (bisher nur Wände über `marqueeHit`, alles andere fehlte komplett).
*/
function marqueeHitByField(
prims: Primitive[],
field: "wallId" | "ceilingId" | "roomId" | "stairId" | "columnId" | "roofId",
rect: ModelRect,
crossing: boolean,
): string[] {
const byId = new Map<string, Vec2[][]>();
for (const p of prims) {
if (p.kind !== "polygon") continue;
const id = p[field];
if (id == null) continue;
const list = byId.get(id);
if (list) list.push(p.pts);
else byId.set(id, [p.pts]);
}
const out: string[] = [];
for (const [id, polys] of byId) {
const hit = crossing
? polys.some((poly) => polyTouchesRect(poly, rect))
: polys.every((poly) => polyEnclosedByRect(poly, rect));
if (hit) out.push(id);
}
return out;
}
/** Vom Auswahl-Rechteck getroffene Decken-IDs (gleiche Konvention wie {@link marqueeHit}). */
export function marqueeHitCeilings(prims: Primitive[], rect: ModelRect, crossing: boolean): string[] {
return marqueeHitByField(prims, "ceilingId", rect, crossing);
}
/** Vom Auswahl-Rechteck getroffene Raum-IDs (gleiche Konvention wie {@link marqueeHit}). */
export function marqueeHitRooms(prims: Primitive[], rect: ModelRect, crossing: boolean): string[] {
return marqueeHitByField(prims, "roomId", rect, crossing);
}
/** Vom Auswahl-Rechteck getroffene Treppen-IDs (gleiche Konvention wie {@link marqueeHit}). */
export function marqueeHitStairs(prims: Primitive[], rect: ModelRect, crossing: boolean): string[] {
return marqueeHitByField(prims, "stairId", rect, crossing);
}
/**
* Vom Auswahl-Rechteck getroffene 2D-Zeichenelement-IDs (gleiche window/crossing-
* Konvention wie {@link marqueeHit}). Sammelt je Drawing2D ALLE seine Punkte aus
* den Linien-/Polygon-Primitiven; crossing = irgendein Punkt/Kante im Rechteck,
* window = alle Punkte vollständig eingeschlossen.
*/
/** Punkte auf einem Kreis-/Bogen-Ring (Modell-Meter), für Marquee-Zwecke abgetastet. */
function ringSamplePoints(center: Vec2, r: number, a0?: number, a1?: number): Vec2[] {
const TAU = Math.PI * 2;
const full = a0 === undefined || a1 === undefined;
const start = full ? 0 : a0;
const sweep = full ? TAU : (((a1 - a0) % TAU) + TAU) % TAU || TAU;
const steps = full ? 32 : Math.max(4, Math.round((sweep / TAU) * 32));
const pts: Vec2[] = [];
for (let i = 0; i <= steps; i++) {
const a = start + (sweep * i) / steps;
pts.push({ x: center.x + r * Math.cos(a), y: center.y + r * Math.sin(a) });
}
return pts;
}
/** Bounding-Box-Eckpunkte eines `drawingText`-Primitivs, analog zur Einzelklick-Bbox in PlanView.tsx. */
function drawingTextBboxPoints(p: Extract<Primitive, { kind: "drawingText" }>): Vec2[] {
const singleW = Math.max(1, p.text.length) * p.heightM * 0.6;
const w = p.wrapWidth && p.wrapWidth > 0 ? p.wrapWidth : singleW;
const lines = p.wrapWidth && p.wrapWidth > 0 ? Math.max(1, Math.ceil(singleW / p.wrapWidth)) : 1;
const pad = p.heightM * 0.6;
const minX = p.at.x - pad;
const maxX = p.at.x + w + pad;
const minY = p.at.y - lines * p.heightM * 1.25 - pad;
const maxY = p.at.y + p.heightM * 0.4 + pad;
return [{ x: minX, y: minY }, { x: maxX, y: minY }, { x: maxX, y: maxY }, { x: minX, y: maxY }];
}
export function marqueeHitDrawings(
prims: Primitive[],
rect: ModelRect,
crossing: boolean,
/** Zeichnungen, die der Aufrufer selbst prüft (kompakte Unterlage) — hier überspringen. */
skipIds?: ReadonlyMap<string, unknown>,
): string[] {
const byDrawing = new Map<string, Vec2[]>();
const collect = (id: string, pts: Vec2[]) => {
const list = byDrawing.get(id);
if (list) list.push(...pts);
else byDrawing.set(id, [...pts]);
};
for (const p of prims) {
if (skipIds && "drawingId" in p && p.drawingId && skipIds.has(p.drawingId)) continue;
if (p.kind === "line" && p.drawingId) collect(p.drawingId, [p.a, p.b]);
else if (p.kind === "polygon" && p.drawingId) collect(p.drawingId, p.pts);
else if (p.kind === "drawingCircle" && p.drawingId) collect(p.drawingId, ringSamplePoints(p.center, p.r));
else if (p.kind === "drawingArc" && p.drawingId) collect(p.drawingId, ringSamplePoints(p.center, p.r, p.a0, p.a1));
else if (p.kind === "drawingText" && p.drawingId) collect(p.drawingId, drawingTextBboxPoints(p));
else if (p.kind === "drawingImage" && p.drawingId) {
collect(p.drawingId, [
p.min,
{ x: p.max.x, y: p.min.y },
p.max,
{ x: p.min.x, y: p.max.y },
]);
}
}
const out: string[] = [];
for (const [id, pts] of byDrawing) {
const hit = crossing
? polyTouchesRect(pts, rect)
: polyEnclosedByRect(pts, rect);
if (hit) out.push(id);
}
return out;
}
// Rahmen-Auswahl über Plan-Primitive (Wände, Decken, Räume, Treppen, 2D-Zeichnungen) läuft im
// Kern ([K3d], `PlanPickIndex.marquee`/`marqueeDrawings`, `plan_pick.rs`); hier bleiben die
// Rechteck-Tests für die kompakte Unterlage (`underlayAccess.ts`).
/** Orientierung des Tripels (a,b,c): >0 CCW, <0 CW, 0 kollinear. */
function cross3(a: Vec2, b: Vec2, c: Vec2): number {
+18 -2
View File
@@ -1,5 +1,5 @@
/**
* `marqueeHitCeilings`/`marqueeHitRooms`/`marqueeHitStairs` — Nutzer-Report:
* Rahmen-Auswahl über Decken/Räume/Treppen (`PlanPickIndex.marquee`) — Nutzer-Report:
* "Auswahlrahmen kann nicht alle Elemente anwählen, z.B. Decken, Räume und
* Treppen nicht". Vorher las das Auswahl-Rechteck nur `wallId`/`drawingId`
* aus den Polygon-Primitiven; die anderen ID-Felder (die dieselben
@@ -7,8 +7,24 @@
*/
import { describe, it, expect } from "vitest";
import { marqueeHit, marqueeHitCeilings, marqueeHitRooms, marqueeHitStairs } from "./geometry";
import type { Primitive } from "../generatePlan";
import type { ModelRect } from "./geometry";
import { PlanPickIndex } from "./planPick";
// Rahmen-Auswahl im Kern ([K3d], `plan_pick.rs`) über einen Plan aus diesen Primitiven.
type Field = "wallId" | "ceilingId" | "roomId" | "stairId";
const hit = (field: Field) => (prims: Primitive[], rect: ModelRect, crossing: boolean): string[] => {
const ix = new PlanPickIndex({ primitives: prims, bounds: { minX: 0, minY: 0, maxX: 1, maxY: 1 } });
try {
return ix.marquee(field, rect, crossing);
} finally {
ix.release();
}
};
const marqueeHit = hit("wallId");
const marqueeHitCeilings = hit("ceilingId");
const marqueeHitRooms = hit("roomId");
const marqueeHitStairs = hit("stairId");
const NO_HATCH = { pattern: "none" as const, color: "#000" };
+62 -6
View File
@@ -10,7 +10,9 @@
import type { Vec2 } from "../../model/types";
import type { Plan, Primitive } from "../generatePlan";
import { heldSegs, planParts } from "../planParts";
import { planPrimAt } from "../planLazy";
import { core } from "../../engine/coreWasm";
import type { ModelRect } from "./geometry";
/** Pick-Felder eines Primitivs (Besitzer-Ids). */
export const OWNER_FIELDS = [
@@ -57,19 +59,37 @@ export interface ClientMap {
scale: number;
}
/** Typ-Kennung im Plan-Puffer → `kind` (s. `plan_buf.rs`). */
const TAG_KIND: Record<number, Primitive["kind"]> = {
1: "polygon",
2: "line",
3: "arc",
4: "drawingCircle",
5: "drawingArc",
6: "text",
7: "drawingText",
8: "drawingTextPath",
9: "drawingImage",
};
/** Ids aus einer Kern-Antwort (jede mit `\0` davor). */
const splitIds = (s: string): string[] => (s ? s.split("\0").slice(1) : []);
export class PlanPickIndex {
private id = 0;
readonly prims: readonly Primitive[];
constructor(private readonly plan: Plan) {
this.prims = plan.primitives;
constructor(readonly plan: Plan) {}
/** Primitiv `i` des Plans (bei einem lazy Plan nur dieser Eintrag gelesen). */
prim(i: number): Primitive | undefined {
return planPrimAt(this.plan, i);
}
/** Kern-Index (lazy beim ersten Abfragen gebaut). */
/** Kern-Index (lazy beim ersten Abfragen gebaut). Texte/Bilder mit JSON (Rahmen-Treffer). */
private ix(): number {
if (this.id) return this.id;
const c = core();
const parts = planParts(this.plan);
const parts = planParts(this.plan, true);
this.id = c.pick_index_build(heldSegs(parts, false));
if (!this.id) this.id = c.pick_index_build(heldSegs(parts, true));
return this.id;
@@ -144,6 +164,42 @@ export class PlanPickIndex {
const list = [...ids];
if (list.length === 0) return [];
const hits = core().pick_owned_by(this.ix(), KIND[field], list.map((s) => "\u0000" + s).join(""));
return Array.from(hits, (i) => this.prims[i]);
return Array.from(hits, (i) => planPrimAt(this.plan, i)!);
}
/** Erster Einzeltext (`drawingText` mit `drawingId`), dessen Rahmen `m` enthält, oder null. */
drawingTextAt(m: Vec2): number | null {
const i = core().pick_drawing_text(this.ix(), m.x, m.y);
return i >= 0 ? i : null;
}
/** Oberstes Bild (`drawingImage` mit `drawingId`) unter `m` oder null. */
drawingImageAt(m: Vec2): number | null {
const i = core().pick_drawing_image(this.ix(), m.x, m.y);
return i >= 0 ? i : null;
}
/** Art des ersten formgebenden Primitivs einer Zeichnung (Linie, Polygon, Text, …) oder null. */
drawingKind(drawingId: string): Primitive["kind"] | null {
return TAG_KIND[core().pick_drawing_kind(this.ix(), drawingId)] ?? null;
}
/**
* Rahmen-Auswahl über Polygone mit Id im Feld `field` (CAD-Konvention): `crossing` = ein Band
* berührt das Rechteck, sonst liegen alle Bänder ganz darin. Ids in Auftreten-Reihenfolge.
*/
marquee(field: "wallId" | "ceilingId" | "roomId" | "stairId" | "columnId" | "roofId", rect: ModelRect, crossing: boolean): string[] {
const r = Float64Array.of(rect.minX, rect.minY, rect.maxX, rect.maxY);
return splitIds(core().pick_marquee_polygons(this.ix(), KIND[field], r, crossing));
}
/**
* Rahmen-Auswahl über 2D-Zeichnungen (alle Punkte je Zeichnung: Linien, Polygone, abgetastete
* Kreise/Bögen, Text-/Bild-Rahmen); `skipIds` prüft der Aufrufer selbst (kompakte Unterlage).
*/
marqueeDrawings(rect: ModelRect, crossing: boolean, skipIds?: Iterable<string>): string[] {
const r = Float64Array.of(rect.minX, rect.minY, rect.maxX, rect.maxY);
const skip = skipIds ? [...skipIds].map((s) => "\0" + s).join("") : "";
return splitIds(core().pick_marquee_drawings(this.ix(), r, crossing, skip));
}
}
+3 -3
View File
@@ -4,7 +4,6 @@
import { describe, it, expect } from "vitest";
import type { Drawing2D, Project } from "../../model/types";
import { generatePlan, materializeUnderlay } from "../generatePlan";
import { marqueeHitDrawings } from "./geometry";
import { PlanPickIndex } from "./planPick";
import { buildDrawingIndex, marqueeHitUnderlay, nearestInDrawings } from "./underlayAccess";
@@ -63,13 +62,14 @@ describe("underlayAccess == Primitiv-Varianten", () => {
}
});
it("Marquee (crossing + window) == marqueeHitDrawings über die Primitive", () => {
it("Marquee (crossing + window) == Rahmen-Auswahl im Kern über die Primitive", () => {
const matIx = new PlanPickIndex(mat);
for (const crossing of [true, false]) {
for (let k = 0; k < 40; k++) {
const x = rnd() * 450, y = rnd() * 450, w = 5 + rnd() * 120, h = 5 + rnd() * 120;
const rect = { minX: x, minY: y, maxX: x + w, maxY: y + h };
const a = new Set(marqueeHitUnderlay(under, rect, crossing));
const b = new Set(marqueeHitDrawings(mat.primitives, rect, crossing));
const b = new Set(matIx.marqueeDrawings(rect, crossing));
expect([...a].sort()).toEqual([...b].sort());
}
}
+3 -3
View File
@@ -19,6 +19,7 @@ import { docToLines, wrapDocToLines } from "../text/renderHtml";
import { docFromText } from "../text/richText";
import { core } from "../engine/coreWasm";
import { greyedFlat, planParts, withPlanParts } from "./planParts";
import { planTextEntries } from "./planLazy";
export type RPoint = [number, number];
export type RRgba = [number, number, number, number];
@@ -194,9 +195,8 @@ export function planSceneTexts(plan: Plan, paperScaleN: number = STAMP_DEFAULT_N
const texts: RText[] = [];
const images: RImage[] = [];
const ranges = plan.greyedRanges;
const prims = plan.primitives;
for (let i = 0; i < prims.length; i++) {
const p = prims[i];
// Nur die Text-/Bild-Einträge ([K3d], aus den Typ-Kennungen des Plan-Puffers).
for (const { i, p } of planTextEntries(plan)) {
if (p.kind === "text") {
const greyed = p.greyed || inGreyedRange(ranges, i);
const defCol = greyedColor(toRgba(p.color, 1) ?? [0.1, 0.1, 0.1, 1], greyed);