2D: Kreis/Bogen-Zeichenelemente vollständig anwählbar und editierbar
Seit der Umstellung auf echte SVG-Kreis-/Bogen-Primitive (drawingCircle/ drawingArc statt 64-Ecken-Polygon-Annäherung) wurde die Interaktionsschicht nie nachgezogen — betraf drei unabhängige Stellen mit derselben Ursache: - Einzelklick: pickDrawing() testete nur kind==="line", fiel sonst auf Text-/Bild-Bbox zurück. Neuer distToDrawingRing()-Zweig: Ring-Abstand in Bildschirm-Pixeln (zoom-unabhängig wie die Linien-Toleranz), bei gefüllten Kreisen zählt auch innerhalb als Treffer; Bögen zusätzlich auf ihre Winkel-Spanne begrenzt. grabbedBody() (Körper-Verschieben) profitiert automatisch mit, da es denselben Picker nutzt. - Marquee (Rahmenauswahl): marqueeHitDrawings() sammelte nur line/polygon — drawingCircle/drawingArc UND drawingText/drawingImage fehlten komplett (Text/Bild waren nie per Rahmen erfassbar, unabhängig von der Kreis-Frage). Kreis/Bogen werden für den Punkt-Test auf Ring-Stützpunkte abgetastet (Bogen nur innerhalb seiner Winkel-Spanne, nicht als Vollkreis), Text/Bild über ihre Bounding-Box. - Griffe: drawingVertices() hatte keinen Fall für circle/arc → leeres Array, selbst nach Fix von Klick+Marquee also unverschiebbar/nicht editierbar. Kreis bekommt einen Radius-Griff (Ost), Bogen Start-/End-Winkel-Griffe plus einen Radius-Griff auf halbem Bogen — moveGrip() entsprechend erweitert. 10 neue Tests (drawingVertices/moveGripOf für Kreis/Bogen, marqueeHitDrawings für alle vier zuvor fehlenden Primitive-Arten). tsc -b / vitest run (901/901) / npm run build grün. Der Einzelklick-Pfad selbst (PlanView.tsx- Closures) ist nicht automatisiert testbar — visuell in der Tauri-App prüfen.
This commit is contained in:
1 parent
2154e1ca6c
commit
1c3fb289d0
5 files changed
+297
-10
No files matched your search
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* `marqueeHitDrawings` — Rahmenauswahl von 2D-Zeichenelementen. 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 { Primitive } from "../generatePlan";
|
||||
|
||||
const encloseRect: ModelRect = { minX: -10, minY: -10, maxX: 10, maxY: 10 };
|
||||
const missRect: ModelRect = { minX: 20, minY: 20, maxX: 30, maxY: 30 };
|
||||
|
||||
describe("marqueeHitDrawings — Kreis/Bogen/Text/Bild", () => {
|
||||
it("Kreis vollständig im Rechteck → window-Treffer", () => {
|
||||
const prims: Primitive[] = [
|
||||
{
|
||||
kind: "drawingCircle",
|
||||
center: { x: 0, y: 0 },
|
||||
r: 2,
|
||||
fill: "none",
|
||||
stroke: "#000",
|
||||
weightMm: 0.25,
|
||||
drawingId: "c1",
|
||||
},
|
||||
];
|
||||
expect(marqueeHitDrawings(prims, encloseRect, false)).toEqual(["c1"]);
|
||||
expect(marqueeHitDrawings(prims, missRect, false)).toEqual([]);
|
||||
});
|
||||
|
||||
it("Bogen wird nur auf seiner Winkel-Spanne abgetastet (nicht als Vollkreis)", () => {
|
||||
// Viertelbogen 0..PI/2 bei r=2 um den Ursprung: liegt komplett im 1. Quadranten.
|
||||
const prims: Primitive[] = [
|
||||
{
|
||||
kind: "drawingArc",
|
||||
center: { x: 0, y: 0 },
|
||||
r: 2,
|
||||
a0: 0,
|
||||
a1: Math.PI / 2,
|
||||
stroke: "#000",
|
||||
weightMm: 0.25,
|
||||
drawingId: "a1",
|
||||
},
|
||||
];
|
||||
// Rechteck deckt NUR den 1. Quadranten ab — ein Vollkreis-Sampling würde
|
||||
// hier fälschlich als "nicht enclosed" durchfallen (Punkte im 3. Quadranten
|
||||
// wären ausserhalb), der Viertelbogen muss aber als vollständig erfasst gelten.
|
||||
const q1Rect: ModelRect = { minX: -0.1, minY: -0.1, maxX: 2.1, maxY: 2.1 };
|
||||
expect(marqueeHitDrawings(prims, q1Rect, false)).toEqual(["a1"]);
|
||||
});
|
||||
|
||||
it("Text-Bbox wird erfasst (vorher: gar nicht per Marquee erfassbar)", () => {
|
||||
const prims: Primitive[] = [
|
||||
{
|
||||
kind: "drawingText",
|
||||
at: { x: 1, y: 1 },
|
||||
text: "Hallo",
|
||||
heightM: 0.3,
|
||||
angle: 0,
|
||||
color: "#000",
|
||||
drawingId: "t1",
|
||||
},
|
||||
];
|
||||
expect(marqueeHitDrawings(prims, encloseRect, false)).toEqual(["t1"]);
|
||||
expect(marqueeHitDrawings(prims, missRect, false)).toEqual([]);
|
||||
});
|
||||
|
||||
it("Bild-Bbox wird erfasst (vorher: gar nicht per Marquee erfassbar)", () => {
|
||||
const prims: Primitive[] = [
|
||||
{
|
||||
kind: "drawingImage",
|
||||
min: { x: -1, y: -1 },
|
||||
max: { x: 1, y: 1 },
|
||||
src: "data:image/png;base64,",
|
||||
opacity: 1,
|
||||
drawingId: "i1",
|
||||
},
|
||||
];
|
||||
expect(marqueeHitDrawings(prims, encloseRect, false)).toEqual(["i1"]);
|
||||
expect(marqueeHitDrawings(prims, missRect, false)).toEqual([]);
|
||||
});
|
||||
|
||||
it("crossing-Modus: Kreis, der das Rechteck nur teilweise überlappt, zählt bereits; window-Modus nicht", () => {
|
||||
// Zentrum ausserhalb, Radius reicht bei Winkel 0 klar ins Rechteck hinein
|
||||
// (x=15+6=21, innerhalb [10,20]) — aber nicht der ganze Ring liegt drin.
|
||||
const prims: Primitive[] = [
|
||||
{
|
||||
kind: "drawingCircle",
|
||||
center: { x: 15, y: 0 },
|
||||
r: 6,
|
||||
fill: "none",
|
||||
stroke: "#000",
|
||||
weightMm: 0.25,
|
||||
drawingId: "c2",
|
||||
},
|
||||
];
|
||||
const rightRect: ModelRect = { minX: 10, minY: -10, maxX: 20, maxY: 10 };
|
||||
expect(marqueeHitDrawings(prims, rightRect, true)).toEqual(["c2"]);
|
||||
expect(marqueeHitDrawings(prims, rightRect, false)).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -246,6 +246,34 @@ export function marqueeHit(
|
||||
* 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,
|
||||
@@ -260,6 +288,17 @@ export function marqueeHitDrawings(
|
||||
for (const p of prims) {
|
||||
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) {
|
||||
|
||||
Reference in new issue
Block a user