[C1][C2] Merge: Kataster in LV95 editierbar (Griffe als Vieleck, Griff-Grenze nur bei Mehrfachauswahl, Bögen bleiben Bögen)
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
18 files changed
+2108
-38
No files matched your search
@@ -41,6 +41,8 @@ import {
|
||||
greyColor,
|
||||
} from "./planView/primitives";
|
||||
import { DraftOverlay } from "./planView/overlays";
|
||||
import { visibleGripIndices } from "./planView/gripCull";
|
||||
import { VbCircle } from "./planView/vbCircle";
|
||||
import { PlanRulers } from "./planView/PlanRulers";
|
||||
import { PlanGrid } from "./planView/PlanGrid";
|
||||
import { expandRegion, indexedInRegion, regionContains, type Bounds } from "../../core";
|
||||
@@ -3320,7 +3322,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
pointerEvents="none"
|
||||
/>
|
||||
{corners.map((s, i) => (
|
||||
<circle
|
||||
<VbCircle
|
||||
key={`gbb-${i}`}
|
||||
className="plan-grip plan-group-bbox-corner"
|
||||
cx={s.x}
|
||||
@@ -3415,11 +3417,12 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
{gripsActive && (
|
||||
<LiveMeet store={meetStore} base={meetScale(view, canvasRef.current ?? svgRef.current) ?? 1}>
|
||||
{(meet) =>
|
||||
grips!.map((g, i) => {
|
||||
const s = toScreen(g);
|
||||
// Viele Griffe (Kataster): nur die sichtbaren zeichnen (gripCull.ts).
|
||||
(visibleGripIndices(grips!, toScreen, view, meet) ?? grips!.map((_, i) => i)).map((i) => {
|
||||
const s = toScreen(grips![i]);
|
||||
const size = (4.5 * gripK(meet)) / meet;
|
||||
return (
|
||||
<circle
|
||||
<VbCircle
|
||||
key={`grip-${i}`}
|
||||
className="plan-grip"
|
||||
cx={s.x}
|
||||
@@ -3461,7 +3464,8 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
{edgeGripsActive && (
|
||||
<LiveMeet store={meetStore} base={meetScale(view, canvasRef.current ?? svgRef.current) ?? 1}>
|
||||
{(s) =>
|
||||
edgeGrips!.map((eg, i) => {
|
||||
(visibleGripIndices(edgeGrips!.map((g) => g.mid), toScreen, view, s) ?? edgeGrips!.map((_, i) => i)).map((i) => {
|
||||
const eg = edgeGrips![i];
|
||||
const m = toScreen(eg.mid);
|
||||
// Normale in den Bildschirmraum (Y spiegeln); auf Bildschirm-px-Größen.
|
||||
const sn = screenNormal(eg.normal);
|
||||
@@ -3522,7 +3526,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
{pts.map((pt, i) => {
|
||||
const s = toScreen(pt);
|
||||
return (
|
||||
<circle
|
||||
<VbCircle
|
||||
key={i}
|
||||
cx={s.x}
|
||||
cy={s.y}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { GRIP_CULL_FROM, GRIP_DRAW_MAX, visibleGripIndices } from "./gripCull";
|
||||
|
||||
const id = (p: { x: number; y: number }) => p;
|
||||
|
||||
describe("visibleGripIndices", () => {
|
||||
it("wenige Griffe: alle zeichnen (normale Pläne unverändert)", () => {
|
||||
const pts = [{ x: 1e9, y: 1e9 }, { x: 0, y: 0 }, { x: 0, y: 0 }];
|
||||
expect(visibleGripIndices(pts, id, { x: 0, y: 0, w: 10, h: 10 }, 1)).toBeNull();
|
||||
});
|
||||
|
||||
it("viele Griffe: nur die im Ausschnitt (mit Rand), in Reihenfolge", () => {
|
||||
// Kataster in LV95 (viewBox-Einheiten = Meter · 90): Griffe entlang einer langen Strasse.
|
||||
const pts = Array.from({ length: GRIP_CULL_FROM + 100 }, (_, i) => ({ x: 2.34e8 + i * 100, y: -1.08e8 }));
|
||||
const view = { x: 2.34e8, y: -1.08e8 - 500, w: 1000, h: 1000 };
|
||||
const idx = visibleGripIndices(pts, id, view, 1)!;
|
||||
expect(idx).not.toBeNull();
|
||||
expect(idx[0]).toBe(0);
|
||||
// Ausschnitt 1000 breit, Rand = max(w, h) je Seite → x bis 2.34e8 + 2000 → Index 0..20.
|
||||
expect(idx).toEqual(Array.from({ length: 21 }, (_, i) => i));
|
||||
});
|
||||
|
||||
it("dicht liegende Griffe werden je Bildschirmzelle nur einmal gezeichnet", () => {
|
||||
const pts = Array.from({ length: GRIP_CULL_FROM + 1 }, (_, i) => ({ x: i * 0.01, y: 0 }));
|
||||
// meet 1 px/Einheit: 0.01 Einheiten Abstand → alle in derselben 3-px-Zelle (bis auf Zellgrenzen).
|
||||
const idx = visibleGripIndices(pts, id, { x: 0, y: -50, w: 100, h: 100 }, 1)!;
|
||||
expect(idx.length).toBeLessThan(10);
|
||||
expect(idx[0]).toBe(0);
|
||||
});
|
||||
|
||||
it("Obergrenze der gezeichneten Griffe", () => {
|
||||
const n = GRIP_DRAW_MAX * 2;
|
||||
const pts = Array.from({ length: n }, (_, i) => ({ x: (i % 1000) * 10, y: Math.floor(i / 1000) * 10 }));
|
||||
const idx = visibleGripIndices(pts, id, { x: 0, y: 0, w: 10_000, h: 10_000 }, 1)!;
|
||||
expect(idx.length).toBe(GRIP_DRAW_MAX);
|
||||
});
|
||||
|
||||
it("unsinniger Massstab: nichts verwerfen ausser ausserhalb", () => {
|
||||
const pts = Array.from({ length: GRIP_CULL_FROM + 1 }, (_, i) => ({ x: i, y: 0 }));
|
||||
const idx = visibleGripIndices(pts, id, { x: 0, y: -10, w: 10_000, h: 20 }, Number.NaN)!;
|
||||
expect(idx.length).toBe(GRIP_CULL_FROM + 1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
// Welche Editier-Griffe die Plan-Ansicht zeichnet, wenn ein Element sehr viele Stützpunkte hat
|
||||
// (Kataster: Strassenparzellen, Bodenbedeckung mit tausenden Ecken; Fehlerbericht 29.10.). Je Griff
|
||||
// ein SVG-Element wären dann zehntausende DOM-Knoten. Gezeichnet werden nur die Griffe im Ausschnitt
|
||||
// (mit Rand, damit kleines Schwenken nichts abschneidet) und je Bildschirmzelle nur einer —
|
||||
// übereinanderliegende Griffe sähe man ohnehin nicht. Das Treffen eines Griffs (Ziehen) rechnet
|
||||
// weiter über alle Griffe, unabhängig davon, was gezeichnet ist.
|
||||
//
|
||||
// Unterhalb von `GRIP_CULL_FROM` Griffen ändert sich nichts: alle werden gezeichnet.
|
||||
|
||||
import type { Vec2 } from "../../../model/types";
|
||||
import type { ViewBox__plan_planView_geometry as ViewBox } from "../../../core";
|
||||
|
||||
/** Ab so vielen Griffen wird ausgedünnt. */
|
||||
export const GRIP_CULL_FROM = 400;
|
||||
/** Höchstens so viele Griffe gleichzeitig im DOM. */
|
||||
export const GRIP_DRAW_MAX = 4000;
|
||||
/** Kantenlänge einer Bildschirmzelle in px (Griff-Radius ≈ 4.5 px). */
|
||||
const CELL_PX = 3;
|
||||
|
||||
/**
|
||||
* Indizes der zu zeichnenden Griffe in Reihenfolge, oder `null` = alle zeichnen (wenige Griffe).
|
||||
* `toVb` bildet Modell → viewBox-Einheiten ab (`toScreen`), `view` ist der aktuelle Ausschnitt,
|
||||
* `meet` Bildschirm-px je viewBox-Einheit.
|
||||
*/
|
||||
export function visibleGripIndices(
|
||||
pts: readonly Vec2[],
|
||||
toVb: (p: Vec2) => Vec2,
|
||||
view: ViewBox,
|
||||
meet: number,
|
||||
): number[] | null {
|
||||
if (pts.length < GRIP_CULL_FROM) return null;
|
||||
// Rand = grössere Ausschnitt-Kante je Seite: deckt auch die Streifen ab, die `meet` bei anderem
|
||||
// Seitenverhältnis des Fensters zusätzlich zeigt.
|
||||
const pad = Math.max(view.w, view.h);
|
||||
const x0 = view.x - pad;
|
||||
const x1 = view.x + view.w + pad;
|
||||
const y0 = view.y - pad;
|
||||
const y1 = view.y + view.h + pad;
|
||||
const cell = meet > 0 && Number.isFinite(meet) ? CELL_PX / meet : 0;
|
||||
const seen = new Set<string>();
|
||||
const out: number[] = [];
|
||||
for (let i = 0; i < pts.length && out.length < GRIP_DRAW_MAX; i++) {
|
||||
const s = toVb(pts[i]);
|
||||
if (!(s.x >= x0 && s.x <= x1 && s.y >= y0 && s.y <= y1)) continue;
|
||||
if (cell > 0) {
|
||||
// Zelle relativ zum Ausschnitt: bei LV95 (≈ 2.3e8 Einheiten) bleiben die Schlüssel klein.
|
||||
const key = `${Math.floor((s.x - x0) / cell)},${Math.floor((s.y - y0) / cell)}`;
|
||||
if (seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
}
|
||||
out.push(i);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
import type { Vec2 } from "../../../model/types";
|
||||
import type { SnapResult, ToolDraft } from "../../../tools/types";
|
||||
import { hudSegments, type HudFieldsState } from "../../../tools/hudFormat";
|
||||
import { VbCircle } from "./vbCircle";
|
||||
|
||||
/**
|
||||
* Zeichnet die Werkzeug-Vorschau: Vorschau-Formen (gestrichelte Akzentlinien /
|
||||
@@ -58,7 +59,7 @@ export function DraftOverlay({
|
||||
{draft.vertices.map((v, i) => {
|
||||
const s = toScreen(v);
|
||||
return (
|
||||
<circle
|
||||
<VbCircle
|
||||
key={`v${i}`}
|
||||
className="tool-vertex"
|
||||
cx={s.x}
|
||||
@@ -289,7 +290,7 @@ function SnapMarker({
|
||||
/>
|
||||
)}
|
||||
{snap.kind === "grid" && (
|
||||
<circle
|
||||
<VbCircle
|
||||
className="snap-glyph snap-fill"
|
||||
cx={s.x}
|
||||
cy={s.y}
|
||||
@@ -327,7 +328,7 @@ function SnapMarker({
|
||||
</>
|
||||
)}
|
||||
{(snap.kind === "center" || snap.kind === "quadrant") && (
|
||||
<circle className="snap-glyph" cx={s.x} cy={s.y} r={r} style={glyphStyle} vectorEffect="non-scaling-stroke" />
|
||||
<VbCircle className="snap-glyph" cx={s.x} cy={s.y} r={r} style={glyphStyle} vectorEffect="non-scaling-stroke" />
|
||||
)}
|
||||
{snap.kind === "onEdge" && (
|
||||
<polygon
|
||||
@@ -352,7 +353,7 @@ function SnapMarker({
|
||||
{/* Tangente: kleiner Kreis (wie „center") plus eine kurze Berührlinie. */}
|
||||
{snap.kind === "tangent" && (
|
||||
<>
|
||||
<circle className="snap-glyph" cx={s.x} cy={s.y} r={r * 0.7} style={glyphStyle} vectorEffect="non-scaling-stroke" />
|
||||
<VbCircle className="snap-glyph" cx={s.x} cy={s.y} r={r * 0.7} style={glyphStyle} vectorEffect="non-scaling-stroke" />
|
||||
<line
|
||||
className="snap-glyph"
|
||||
x1={s.x - r}
|
||||
@@ -372,7 +373,7 @@ function SnapMarker({
|
||||
</>
|
||||
)}
|
||||
{(snap.kind === "endpoint" || snap.kind === "ortho" || snap.kind === "extension") && (
|
||||
<circle
|
||||
<VbCircle
|
||||
className="snap-glyph"
|
||||
cx={s.x}
|
||||
cy={s.y}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { circlePoints } from "./vbCircle";
|
||||
|
||||
describe("circlePoints", () => {
|
||||
it("Vieleck um den Mittelpunkt, auch bei LV95-viewBox-Koordinaten (≈ 2.3e8)", () => {
|
||||
const cx = 2_600_068 * 90;
|
||||
const cy = -1_200_068 * 90;
|
||||
const pts = circlePoints(cx, cy, 4).split(" ").map((p) => p.split(",").map(Number));
|
||||
expect(pts).toHaveLength(24);
|
||||
for (const [x, y] of pts) expect(Math.hypot(x - cx, y - cy)).toBeCloseTo(4, 6);
|
||||
});
|
||||
|
||||
it("unsinnige Eingaben ergeben kein Vieleck", () => {
|
||||
expect(circlePoints(Number.NaN, 0, 1)).toBe("");
|
||||
expect(circlePoints(0, 0, -1)).toBe("");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
// Kleiner Kreis im Plan-SVG als Vieleck (`<polygon points>`) statt `<circle cx cy r>`.
|
||||
//
|
||||
// Grund (Kataster-Fund 29.10.): `cx`/`cy`/`r` sind in SVG 2 CSS-Eigenschaften; Chromium und WebKit
|
||||
// klemmen CSS-Längen auf ±33 554 429 (LayoutUnit-Bereich). Die viewBox-Einheiten des Plans sind
|
||||
// Meter · 90 (`toScreen`), Landeskoordinaten LV95 (≈ 2.6e6 m) liegen also bei ≈ 2.3e8 — ein
|
||||
// `<circle>` dort landet weit ausserhalb des Bildes: Editier-Griffe und Fang-Marken eines
|
||||
// importierten Katasters waren unsichtbar („keine Eckpunkte"). Die Punkte eines `<polygon>` sind
|
||||
// keine CSS-Längen und werden nicht geklemmt (ab ~370 km vom Modell-Ursprung betroffen, auch LV03).
|
||||
//
|
||||
// Rest: Der Browser rechnet SVG-Koordinaten in f32 (bei 2.3e8 auf ±8 viewBox-Einheiten genau); bei
|
||||
// starkem Zoom liegt ein Griff dann einige Pixel neben der Ecke (Treffer rechnet PlanView in f64).
|
||||
|
||||
import type { CSSProperties } from "react";
|
||||
|
||||
/** Eckenzahl des Vielecks (bei Griff-Grösse ~5 px nicht von einem Kreis zu unterscheiden). */
|
||||
const SIDES = 24;
|
||||
|
||||
/** `points`-Attribut eines Kreis-Vielecks; leer bei unsinniger Eingabe. */
|
||||
export function circlePoints(cx: number, cy: number, r: number): string {
|
||||
if (!(Number.isFinite(cx) && Number.isFinite(cy) && Number.isFinite(r) && r > 0)) return "";
|
||||
const out: string[] = new Array(SIDES);
|
||||
for (let i = 0; i < SIDES; i++) {
|
||||
const a = (2 * Math.PI * i) / SIDES;
|
||||
out[i] = `${cx + r * Math.cos(a)},${cy + r * Math.sin(a)}`;
|
||||
}
|
||||
return out.join(" ");
|
||||
}
|
||||
|
||||
/** Ersatz für `<circle>` im Plan-SVG (gleiche Klassen/Stile), s. Dateikopf. */
|
||||
export function VbCircle(props: {
|
||||
cx: number;
|
||||
cy: number;
|
||||
r: number;
|
||||
className?: string;
|
||||
style?: CSSProperties;
|
||||
vectorEffect?: "non-scaling-stroke";
|
||||
pointerEvents?: "none";
|
||||
}) {
|
||||
const { cx, cy, r, ...rest } = props;
|
||||
return <polygon points={circlePoints(cx, cy, r)} {...rest} />;
|
||||
}
|
||||
Reference in new issue
Block a user