[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:
13 files changed
+594
-264
No files matched your search
@@ -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,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 {
|
||||
|
||||
@@ -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" };
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user