[288] Fangpunkte und Griffe wie Vectorworks: Fangsymbol je Art mit Kontrastrand und Hinweis-Schildchen, Auswahlgriffe als Quadrate, Kanten-Anfasser erst nach Kantenauswahl (zweiter Klick, Esc hebt auf)
This commit is contained in:
22 files changed
+569
-213
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { snapGlyph, snapTipKey, snapTipText } from "./snapGlyph";
|
||||
import type { SnapKind } from "./types";
|
||||
import { PAPER_UNITS } from "./displayUnits";
|
||||
|
||||
describe("[288] Fangart → Symbol und Kurzhinweis", () => {
|
||||
it("jede wichtige Fangart hat ein eigenes Symbol", () => {
|
||||
const kinds: SnapKind[] = ["endpoint", "midpoint", "intersection", "perpendicular", "center", "onEdge"];
|
||||
const glyphs = kinds.map(snapGlyph);
|
||||
expect(glyphs).toEqual(["square", "triangle", "cross", "perp", "circle", "diamond"]);
|
||||
expect(new Set(glyphs).size).toBe(kinds.length);
|
||||
expect(snapGlyph("angle")).toBe("none");
|
||||
});
|
||||
|
||||
it("Kurzhinweis über t() (de)", () => {
|
||||
const at = { x: 1, y: 2 };
|
||||
expect(snapTipText({ point: at, kind: "endpoint", distPx: 0 })).toBe("Endpunkt");
|
||||
expect(snapTipText({ point: at, kind: "midpoint", distPx: 0 })).toBe("Mitte");
|
||||
expect(snapTipText({ point: at, kind: "intersection", distPx: 0 })).toBe("Schnittpunkt");
|
||||
expect(snapTipText({ point: at, kind: "perpendicular", distPx: 0 })).toBe("Lot");
|
||||
expect(snapTipText({ point: at, kind: "onEdge", distPx: 0 })).toBe("Auf Kante");
|
||||
expect(snapTipKey("angle")).toBeNull();
|
||||
});
|
||||
|
||||
it("Hilfslinien mit Abstand bzw. Richtung", () => {
|
||||
const refA = { x: 0, y: 0 };
|
||||
expect(snapTipText({ point: { x: 0, y: 2.5 }, refA, kind: "ortho", distPx: 0 })).toBe("Ortho 90° · 2.500m");
|
||||
expect(snapTipText({ point: { x: -1.25, y: 0 }, refA, kind: "extension", distPx: 0 })).toBe("Verlängerung · 1.250m");
|
||||
expect(snapTipText({ point: { x: 0.1, y: 0 }, refA, kind: "extension", distPx: 0 }, PAPER_UNITS)).toBe("Verlängerung · 100.0mm");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
// [288] Fangpunkt-Darstellung (Vectorworks-Smart-Cursor als Leitbild): je Fangart ein eigenes Symbol und ein kurzer
|
||||
// Hinweis neben dem Zeiger („Endpunkt", „Mitte" …; bei Hilfslinien mit Abstand bzw. Winkel). Reine Zuordnung, die
|
||||
// Zeichnung macht `views/plan/planView/overlays.tsx` (2D); Beschriftung über `t()` (de/en).
|
||||
|
||||
import { t } from "../i18n";
|
||||
import type { TranslationKey } from "../i18n";
|
||||
import { MODEL_UNITS, fmtLength, type DisplayUnits } from "./displayUnits";
|
||||
import type { SnapKind, SnapResult } from "./types";
|
||||
|
||||
/** Symbol je Fangart. */
|
||||
export type SnapGlyph =
|
||||
| "square" // Endpunkt
|
||||
| "triangle" // Mitte
|
||||
| "cross" // Schnittpunkt (X)
|
||||
| "perp" // Lot / senkrecht (rechter Winkel)
|
||||
| "circle" // Zentrum / Quadrant
|
||||
| "diamond" // auf Kante (hohle Raute)
|
||||
| "diamondFill" // Teilpunkt (gefüllte Raute)
|
||||
| "tangent" // Tangente (Kreis + Berührlinie)
|
||||
| "parallel" // parallel (∥)
|
||||
| "plus" // Ortho / Verlängerung (Punkt auf einer Hilfslinie)
|
||||
| "dot" // Raster
|
||||
| "none"; // Winkel-Fang (eigene Führungslinie + Winkel-Badge)
|
||||
|
||||
const GLYPH: Record<SnapKind, SnapGlyph> = {
|
||||
endpoint: "square",
|
||||
midpoint: "triangle",
|
||||
intersection: "cross",
|
||||
center: "circle",
|
||||
quadrant: "circle",
|
||||
onEdge: "diamond",
|
||||
grid: "dot",
|
||||
ortho: "plus",
|
||||
extension: "plus",
|
||||
angle: "none",
|
||||
divide: "diamondFill",
|
||||
perpendicular: "perp",
|
||||
tangent: "tangent",
|
||||
parallel: "parallel",
|
||||
};
|
||||
|
||||
export function snapGlyph(kind: SnapKind): SnapGlyph {
|
||||
return GLYPH[kind] ?? "square";
|
||||
}
|
||||
|
||||
/** Übersetzungsschlüssel des Kurzhinweises; null = keiner (Winkel-Fang hat sein eigenes Badge). */
|
||||
export function snapTipKey(kind: SnapKind): TranslationKey | null {
|
||||
return kind === "angle" ? null : (`snap.tip.${kind}` as TranslationKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kurzhinweis am Zeiger. Bei Hilfslinien (Ortho, Verlängerung) mit Abstand zum Bezugspunkt, Ortho zusätzlich mit
|
||||
* Richtung in Grad (0/90/180/270).
|
||||
*/
|
||||
export function snapTipText(snap: SnapResult, units: DisplayUnits = MODEL_UNITS): string | null {
|
||||
const key = snapTipKey(snap.kind);
|
||||
if (!key) return null;
|
||||
const label = t(key);
|
||||
if ((snap.kind === "ortho" || snap.kind === "extension") && snap.refA) {
|
||||
const dx = snap.point.x - snap.refA.x;
|
||||
const dy = snap.point.y - snap.refA.y;
|
||||
const d = Math.hypot(dx, dy);
|
||||
if (d < 1e-9) return label;
|
||||
if (snap.kind === "ortho") {
|
||||
const deg = ((Math.round((Math.atan2(dy, dx) * 180) / Math.PI) % 360) + 360) % 360;
|
||||
return `${label} ${deg}° · ${fmtLength(units, d)}`;
|
||||
}
|
||||
return `${label} · ${fmtLength(units, d)}`;
|
||||
}
|
||||
return label;
|
||||
}
|
||||
Reference in new issue
Block a user