diff --git a/src/views/plan/PlanView.tsx b/src/views/plan/PlanView.tsx index b770a8b3..5d9b91db 100644 --- a/src/views/plan/PlanView.tsx +++ b/src/views/plan/PlanView.tsx @@ -38,7 +38,7 @@ import { planTextEntries } from "../../core"; import { EMPTY_SELECTION, single } from "../../state/selection"; import { useCursorValue, type CursorStore } from "../../state/cursorStore"; import type { HatchedPoly, PlanViewHandle, PlanViewProps } from "./planView/types"; -import { IS_MAC, gripSquareHalfPx } from "./planView/constants"; +import { IS_MAC, gripSquareHalfPx, gripCrowdK, minPairDistance } from "./planView/constants"; import { usePlanEngine } from "./planView/usePlanEngine"; import { usePlanCoords } from "./planView/usePlanCoords"; import { usePlanPicking } from "./planView/usePlanPicking"; @@ -1070,7 +1070,7 @@ export const PlanView = forwardRef( const c2 = toLocal({ x: groupBBox.maxX, y: groupBBox.minY }); const c3 = toLocal({ x: groupBBox.maxX, y: groupBBox.maxY }); const c4 = toLocal({ x: groupBBox.minX, y: groupBBox.maxY }); - const half = gripSquareHalfPx(false, false) / meet; + const half = (gripSquareHalfPx(false, false) * gripK(meet)) / meet; // [314] zoomabhängig const corners = [c1, c2, c3, c4]; return ( <> @@ -1174,13 +1174,18 @@ export const PlanView = forwardRef( kleinere hohle Quadrate. Sichtbare Form bewusst kleiner als der Treffer-Radius (GRIP_HIT_PX). */} {gripsActive && ( - {(meet) => + {(meet) => { // Viele Griffe (Kataster): nur die sichtbaren zeichnen (gripCull.ts). - (visibleGripIndices(grips!, toScreen, view, meet) ?? grips!.map((_, i) => i)).map((i) => { + const idx = visibleGripIndices(grips!, toScreen, view, meet) ?? grips!.map((_, i) => i); + // [314] Grösse: zoomabhängig (gripK) und bei eng liegenden Griffen (kleines Element, weit herausgezoomt) + // zusätzlich kleiner, statt dass die Quadrate das Element zudecken. Abstand in Bildschirm-px. + const k = gripK(meet); + const crowd = gripCrowdK(minPairDistance(idx.map((i) => toLocal(grips![i]))) * meet, gripSquareHalfPx(false, false) * k); + return idx.map((i) => { const s = toLocal(grips![i]); const insert = !!(grips![i] as { insert?: boolean }).insert; const hover = hoverGrip === i; - const half = gripSquareHalfPx(insert, hover) / meet; + const half = (gripSquareHalfPx(insert, hover) * k * (hover ? 1 : crowd)) / meet; return ( ( pointerEvents="none" /> ); - }) - } + }); + }} )} {/* Raum-Stempel-Griff: eine ziehbare Raute am Anker des gewählten Raums. diff --git a/src/views/plan/planView/constants.ts b/src/views/plan/planView/constants.ts index eec8a23b..1bc00b2b 100644 --- a/src/views/plan/planView/constants.ts +++ b/src/views/plan/planView/constants.ts @@ -75,6 +75,39 @@ export function gripSquareHalfPx(insert: boolean, hover: boolean): number { const base = insert ? 3 : 4; return hover ? base + 1.5 : base; } + +/** + * [314] Zoom-Faktor der Griffe (Eckpunkte, Kanten-Dreiecke): beim Herauszoomen kleiner, beim Hineinzoomen leicht + * grösser — `meet` = Pixel je Planeinheit jetzt, `ref` = in der eingepassten Ansicht. Vorher Exponent 0.2 und + * Untergrenze 0.7: herausgezoomt blieben die Quadrate fast gleich gross und deckten kleine Elemente zu. + */ +export function gripZoomK(meet: number, ref: number): number { + if (!(meet > 0 && ref > 0)) return 1; + return Math.min(1.25, Math.max(0.4, Math.pow(meet / ref, 0.35))); +} + +/** + * [314] Dichte-Faktor: liegen Griffe auf dem Bildschirm enger als etwa fünf Quadrat-Halbbreiten beieinander + * (kleines Element weit herausgezoomt), werden sie entsprechend kleiner (bis 40 %), statt sich zu überdecken. + * `minDistPx` = kleinster Bildschirmabstand zweier Griffe, `halfPx` = Halbbreite ohne Dichte-Faktor. + */ +export function gripCrowdK(minDistPx: number, halfPx: number): number { + if (!(minDistPx >= 0) || !(halfPx > 0) || !Number.isFinite(minDistPx)) return 1; + return Math.min(1, Math.max(0.4, minDistPx / (5 * halfPx))); +} + +/** Kleinster Abstand zweier Punkte (gleiche Einheit wie die Eingabe); bei mehr als `max` Punkten `Infinity`. */ +export function minPairDistance(pts: readonly { x: number; y: number }[], max = 300): number { + if (pts.length < 2 || pts.length > max) return Infinity; + let m = Infinity; + for (let i = 0; i < pts.length; i++) { + for (let j = i + 1; j < pts.length; j++) { + const d = Math.hypot(pts[i].x - pts[j].x, pts[i].y - pts[j].y); + if (d > 1e-9 && d < m) m = d; + } + } + return m; +} // Toleranz (Bildschirm-Pixel) für die Linien-Auswahl von 2D-Zeichenelementen. export const LINE_PICK_PX = 6; diff --git a/src/views/plan/planView/gripScale.test.ts b/src/views/plan/planView/gripScale.test.ts new file mode 100644 index 00000000..91294399 --- /dev/null +++ b/src/views/plan/planView/gripScale.test.ts @@ -0,0 +1,25 @@ +// [314] Griffgrösse: zoomabhängig und bei eng liegenden Griffen kleiner. +import { describe, expect, it } from "vitest"; +import { gripCrowdK, gripZoomK, minPairDistance } from "./constants"; + +describe("[314] Griffgrösse", () => { + it("herausgezoomt deutlich kleiner, hineingezoomt kaum grösser, begrenzt", () => { + expect(gripZoomK(1, 1)).toBe(1); + expect(gripZoomK(0.1, 1)).toBeLessThan(0.5); + expect(gripZoomK(0.0001, 1)).toBe(0.4); + expect(gripZoomK(10, 1)).toBeLessThanOrEqual(1.25); + expect(gripZoomK(Number.NaN, 1)).toBe(1); + }); + it("eng liegende Griffe werden kleiner, weit liegende nicht", () => { + expect(gripCrowdK(100, 4)).toBe(1); + expect(gripCrowdK(10, 4)).toBeCloseTo(0.5); + expect(gripCrowdK(1, 4)).toBe(0.4); + expect(gripCrowdK(Infinity, 4)).toBe(1); + }); + it("kleinster Abstand, doppelte Punkte zählen nicht, zu viele Punkte = Infinity", () => { + expect(minPairDistance([{ x: 0, y: 0 }, { x: 3, y: 4 }, { x: 0, y: 1 }])).toBe(1); + expect(minPairDistance([{ x: 0, y: 0 }, { x: 0, y: 0 }, { x: 2, y: 0 }])).toBe(2); + expect(minPairDistance([{ x: 0, y: 0 }])).toBe(Infinity); + expect(minPairDistance(Array.from({ length: 5 }, (_, i) => ({ x: i, y: 0 })), 3)).toBe(Infinity); + }); +}); diff --git a/src/views/plan/planView/usePlanPointer.ts b/src/views/plan/planView/usePlanPointer.ts index 1a2a2389..de7a5311 100644 --- a/src/views/plan/planView/usePlanPointer.ts +++ b/src/views/plan/planView/usePlanPointer.ts @@ -3,7 +3,7 @@ // Standard-Auswahl (`defaultPick`). Aufgerufen einmal von `PlanView`. import type { MeetStore, ValueStore } from "./liveMeet"; -import { cycleModifier, MARQUEE_THRESHOLD_PX, EMPTY_PICK } from "./constants"; +import { cycleModifier, MARQUEE_THRESHOLD_PX, EMPTY_PICK, gripZoomK } from "./constants"; import { useRef, useEffect } from "react"; import type { ViewBox__plan_planView_geometry as ViewBox } from "../../../core"; import { localViewBoxAttr } from "./overlayOrigin"; @@ -423,13 +423,12 @@ export function usePlanPointer(inp: UsePlanPointerArgs) { } }, [view, meetStore, viewStore]); /** - * Griff-Grösse in Bildschirm-px: bewusst nur SCHWACH zoomabhängig (Exponent 0.2, - * begrenzt) — kein hartes Konstant-Bleiben, damit man an den Griffen noch merkt, - * ob man nah oder weit weg ist, aber ohne dass sie beim Zoomen mitwachsen. + * Griff-Faktor auf die Bildschirm-px-Grösse: zoomabhängig ([314] `gripZoomK`, Exponent 0.35, 0.4…1.25) — + * herausgezoomt deutlich kleiner, damit die Griffe kleine Elemente nicht zudecken; hineingezoomt kaum grösser. */ const gripK = (meet: number): number => { const ref = meetScale(defaultView, canvasRef.current ?? svgRef.current) ?? meet; - return Math.min(1.4, Math.max(0.7, Math.pow(meet / ref, 0.2))); + return gripZoomK(meet, ref); // [314] herausgezoomt deutlich kleiner (vorher Exponent 0.2, min 0.7) }; /** Anhängigen imperativen Pan in React-State übernehmen (+ Transform lösen). */ const commitPan = () => {