[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:
Claude committed 2026-10-29 02:29:43 +00:00
commit c9a39b8c2f
18 files changed
+2108 -38

No files matched your search

+96
View File
@@ -0,0 +1,96 @@
// Kataster-Fund 29.10.: LWPOLYLINE mit Bögen (Bulges) kommen als Polylinie MIT `bulge` in die
// 2D-Zeichnung statt fein zerlegt — wenige Stützpunkte, Griffe an Ecken und Bogen-Mitten.
import { beforeAll, describe, expect, it } from "vitest";
import { parseDxf } from "./dxfParser";
import { loadFileioForTests } from "../engine/fileioWasm.testing";
import { contoursToDrawings } from "./dxfToDrawings";
import { bulgePolylinePoints } from "../geometry/bulge";
import type { Vec2 } from "../model/types";
beforeAll(loadFileioForTests);
function dxf(...entities: string[][]): string {
const lines = ["0", "SECTION", "2", "ENTITIES"];
for (const pairs of entities) lines.push(...pairs);
lines.push("0", "ENDSEC", "0", "EOF");
return lines.join("\n");
}
/** Parzelle in LV95 (30 × 30 m), Unterkante leicht nach aussen gewölbt, Oberkante nach innen. */
const PARZELLE = [
"0", "LWPOLYLINE", "8", "Liegenschaften", "90", "4", "70", "1",
"10", "2600000", "20", "1200000", "42", "0.12",
"10", "2600030", "20", "1200000",
"10", "2600030", "20", "1200030", "42", "-0.25",
"10", "2600000", "20", "1200030",
];
const toDrawings = (src: string) => contoursToDrawings(parseDxf(src).contours, "L", "active", "01", () => "01");
describe("DXF-Import: Polylinien mit Bögen", () => {
it("bleiben eine Polylinie mit den DXF-Stützpunkten und Bulges", () => {
const [d] = toDrawings(dxf(PARZELLE));
expect(d.geom.shape).toBe("polyline");
if (d.geom.shape !== "polyline") return;
expect(d.geom.pts).toEqual([
{ x: 2600000, y: 1200000 },
{ x: 2600030, y: 1200000 },
{ x: 2600030, y: 1200030 },
{ x: 2600000, y: 1200030 },
]);
// Vorzeichen umgekehrt: Modell-Bulge > 0 = Scheitel links der Sehne, DXF > 0 = Gegenuhrzeigersinn.
expect(d.geom.bulge).toEqual([-0.12, 0, 0.25, 0]);
expect(d.geom.closed).toBe(true);
});
it("gleiche Bogen-Seite wie die Tessellierung des Imports (Vorzeichen DXF ↔ Modell)", () => {
const contour = parseDxf(dxf(PARZELLE)).contours[0].contours[0];
const [d] = toDrawings(dxf(PARZELLE));
if (d.geom.shape !== "polyline") throw new Error("Polylinie erwartet");
const ours = bulgePolylinePoints(d.geom.pts, d.geom.bulge, true);
// Jeder Punkt der Import-Tessellierung liegt auf dem Linienzug der Modell-Polylinie (≤ 15 cm: Sehnenfehler der gröberen Modell-Tessellierung; die falsche Seite läge Meter daneben).
const dist = (p: Vec2) => {
let best = Infinity;
for (let i = 0; i < ours.length; i++) {
const a = ours[i];
const b = ours[(i + 1) % ours.length];
const dx = b.x - a.x;
const dy = b.y - a.y;
const t = Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / (dx * dx + dy * dy || 1)));
best = Math.min(best, Math.hypot(a.x + t * dx - p.x, a.y + t * dy - p.y));
}
return best;
};
for (const p of contour.pts) expect(dist(p)).toBeLessThan(0.15);
// Die Unterkante wölbt sich nach aussen (DXF: Bulge > 0 von links nach rechts = Gegenuhrzeigersinn).
expect(Math.min(...ours.map((p) => p.y))).toBeLessThan(1_200_000 - 1);
});
it("offener Bogen aus zwei Punkten wird Polylinie (keine Linie)", () => {
const [d] = toDrawings(
dxf(["0", "LWPOLYLINE", "8", "0", "90", "2", "70", "0", "10", "0", "20", "0", "42", "1", "10", "2", "20", "0"]),
);
expect(d.geom).toEqual({ shape: "polyline", pts: [{ x: 0, y: 0 }, { x: 2, y: 0 }], closed: false, bulge: [-1, 0] });
});
it("Schraffur mit Bogen-Rand: gefüllte Polylinie mit Bulges", () => {
const [d] = toDrawings(
dxf([
"0", "HATCH", "8", "BB", "2", "SOLID", "70", "1", "91", "1", "92", "3", "72", "1", "73", "1", "93", "3",
"10", "0", "20", "0", "42", "0.3", "10", "10", "20", "0", "42", "0", "10", "10", "20", "10", "42", "0", "97", "0",
]),
);
expect(d.fillColor).toBeDefined();
if (d.geom.shape !== "polyline") throw new Error("Polylinie erwartet");
expect(d.geom.pts).toHaveLength(3);
expect(d.geom.bulge).toEqual([-0.3, 0, 0]);
});
it("ohne Bögen unverändert: Linienzug ohne `bulge`", () => {
const [d] = toDrawings(
dxf(["0", "LWPOLYLINE", "8", "0", "90", "3", "70", "0", "10", "0", "20", "0", "10", "1", "20", "0", "10", "1", "20", "1"]),
);
expect(d.geom).toEqual({ shape: "polyline", pts: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 1 }], closed: false });
});
});
+22 -1
View File
@@ -17,7 +17,7 @@
// `parseDxf` ist synchron und verlangt das geladene Modul (`loadFileio()`); die App ruft es im
// Web-Worker (`dxfParserAsync.ts`), Tests laden es per `loadFileioForTests()`.
import type { Contour, ContourSet, ImportedMesh, ImportedText } from "../model/types";
import type { Contour, ContourSet, ImportedMesh, ImportedText, Vec2 } from "../model/types";
import { GENERIC_IMPORT_CATEGORY } from "../model/contextCategories";
import { fileioLoaded } from "../engine/fileioWasm";
@@ -65,6 +65,16 @@ export interface DxfImportResult {
recovered?: boolean;
}
/**
* Kontur aus dem DXF/DWG-Import. Polylinien mit Bögen (LWPOLYLINE/POLYLINE, Schraffur-Rand aus einer
* Polylinie) tragen zusätzlich ihre Stützpunkte mit Bulge (DXF-Konvention = `Drawing2DGeom` polyline
* `bulge`): die 2D-Zeichnung bekommt echte Bögen statt des tessellierten `pts` (Kataster-Fund 29.10.:
* Strassenparzellen mit hunderten Zerlegungspunkten). Nur beim Import gebraucht, nicht im Modell.
*/
export interface ImportContour extends Contour {
bulgePolyline?: { pts: Vec2[]; bulge: number[] };
}
let importSeq = 0;
const nextId = (prefix: string, idPrefix: string) => `${idPrefix}${prefix}-${Date.now()}-${importSeq++}`;
@@ -141,6 +151,17 @@ export function decodeImport(geom: Float64Array, strings: readonly string[], idP
for (let p = 0; p < np; p++) pts[p] = { x: geom[i + 2 * p], y: geom[i + 2 * p + 1] };
i += 2 * np;
c.pts = pts;
if (flags & 8) {
const nv = num();
const vpts: Vec2[] = new Array(nv);
const bulge: number[] = new Array(nv);
for (let v = 0; v < nv; v++) {
vpts[v] = { x: geom[i + 3 * v], y: geom[i + 3 * v + 1] };
bulge[v] = geom[i + 3 * v + 2];
}
i += 3 * nv;
(c as ImportContour).bulgePolyline = { pts: vpts, bulge };
}
contours.push(c);
}
+15
View File
@@ -16,6 +16,7 @@
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
import type { Contour, ContourSet, Drawing2D, Drawing2DGeom, ImportedText, LayerCategory } from "../model/types";
import type { ImportContour } from "./dxfParser";
/** Wie DXF-Layer auf Kategorien abgebildet werden. */
export type CategoryMode = "active" | "byLayer";
@@ -115,6 +116,20 @@ function contourGeom(contour: Contour): Drawing2DGeom | null {
}
return { shape: "arc", center: { x: c.cx, y: c.cy }, r: c.r, a0: c.a0, a1: c.a1 };
}
// Polylinie mit Bögen (DXF-Bulges): Stützpunkte + `bulge` statt des tessellierten Linienzugs.
// VORZEICHEN: In DXF heisst Bulge > 0 „Bogen im Gegenuhrzeigersinn von a nach b" (Scheitel rechts
// der Sehne), im Modell liegt der Scheitel bei Bulge > 0 LINKS der Sehne (`kernel2d/src/bulge.rs`,
// Links-Normale) — also umgekehrt. Geprüft in `dxfBulgeImport.test.ts` gegen die Tessellierung des
// Imports.
const bp = (contour as ImportContour).bulgePolyline;
if (bp && bp.pts.length >= 2 && bp.bulge.length === bp.pts.length) {
return {
shape: "polyline",
pts: bp.pts.map((p) => ({ ...p })),
closed: contour.closed,
bulge: bp.bulge.map((b) => (b === 0 ? 0 : -b)),
};
}
const pts = contour.pts;
if (pts.length < 2) return null;
if (pts.length === 2 && !contour.closed) {
+29
View File
@@ -0,0 +1,29 @@
import { describe, expect, it } from "vitest";
import { MAX_GRIP_DRAWINGS, MAX_GRIP_VERTICES, gripDrawingIdsFor } from "./gripLimits";
describe("gripDrawingIdsFor", () => {
const counts = (n: number) => () => n;
it("ein einzeln gewähltes Element bekommt immer Griffe, auch mit sehr vielen Stützpunkten (Kataster)", () => {
// Fehlerbericht 29.10.: Strassenparzelle/Bodenbedeckung aus DWG mit > 600 Stützpunkten → keine Griffe.
expect(gripDrawingIdsFor(["road"], counts(25_000))).toEqual(["road"]);
});
it("Mehrfachauswahl unter den Grenzen: alle bekommen Griffe", () => {
expect(gripDrawingIdsFor(["a", "b"], counts(10))).toEqual(["a", "b"]);
});
it("Mehrfachauswahl über der Stützpunkt-Grenze: keine Griffe (wie bisher)", () => {
const per = Math.ceil((MAX_GRIP_VERTICES + 1) / 2);
expect(gripDrawingIdsFor(["a", "b"], counts(per))).toEqual([]);
});
it("Mehrfachauswahl über der Objekt-Grenze: keine Griffe (wie bisher)", () => {
const ids = Array.from({ length: MAX_GRIP_DRAWINGS + 1 }, (_, i) => `d${i}`);
expect(gripDrawingIdsFor(ids, counts(1))).toEqual([]);
});
it("leere Auswahl", () => {
expect(gripDrawingIdsFor([], counts(1))).toEqual([]);
});
});
+35
View File
@@ -0,0 +1,35 @@
// Welche gewählten 2D-Zeichnungen Editier-Griffe bekommen (aus `useGripEditing.ts` gelöst, damit
// die Regel ohne React prüfbar ist).
//
// Bei grossen Mehrfachauswahlen (z. B. Rahmen über Katasterdaten) gibt es KEINE Griffe: je
// Stützpunkt ein Eck- und ein Kanten-Griff ergäben zehntausende Griffe und sind bei so vielen
// Punkten nicht bedienbar. Massgebend ist die GESAMTZAHL der Stützpunkte (wenige Objekte können
// riesige Umrisse haben), nicht die Objektzahl. Die Auswahl selbst (Hervorhebung, Verschieben,
// Eigenschaften) bleibt unberührt.
//
// Ein EINZELN gewähltes Element bekommt dagegen immer Griffe, egal wie viele Stützpunkte es hat
// (Fehlerbericht 29.10.: Strassenparzellen und Bodenbedeckungs-Flächen eines Katasters aus DWG haben
// nach dem Tessellieren der Bögen/Schraffur-Ränder schnell über 600 Stützpunkte und waren dann nicht
// mehr editierbar). Die Plan-Ansicht zeichnet bei vielen Griffen nur die sichtbaren
// (`views/plan/planView/gripCull.ts`); das Treffen eines Griffs rechnet über das Array, nicht über DOM.
/** Höchstzahl gewählter Zeichnungen, die bei Mehrfachauswahl noch Griffe bekommen. */
export const MAX_GRIP_DRAWINGS = 50;
/** Höchstzahl Stützpunkte (Summe) einer Mehrfachauswahl, die noch Griffe bekommt. */
export const MAX_GRIP_VERTICES = 600;
/**
* Die Zeichnungs-Ids, die Griffe bekommen: bei genau einer gewählten Zeichnung immer diese, bei
* mehreren alle, solange Objekt- und Stützpunkt-Grenze eingehalten sind, sonst keine.
* `vertexCount(id)` liefert die Griff-Zahl einer Zeichnung (0 für unbekannte Ids).
*/
export function gripDrawingIdsFor(ids: readonly string[], vertexCount: (id: string) => number): string[] {
if (ids.length <= 1) return [...ids];
if (ids.length > MAX_GRIP_DRAWINGS) return [];
let total = 0;
for (const id of ids) {
total += vertexCount(id);
if (total > MAX_GRIP_VERTICES) return [];
}
return [...ids];
}
+7 -18
View File
@@ -10,6 +10,7 @@ import { add, dot, leftNormal, normalize, scale, sub, wallCorners } from "../mod
import type { Ceiling, Drawing2D, EdgeGrip, Project, Room, Stair, Vec2 } from "../model/types";
import { wallTypeThickness } from "../model/types";
import { drawingVertices } from "./projectSlice";
import { gripDrawingIdsFor } from "./gripLimits";
import { areaMovePreview } from "../tools/transform";
import { mvGeom } from "../core";
import { drawingPreviewShapes } from "../tools/drawingPreview";
@@ -172,24 +173,12 @@ export function useGripEditing(opts: {
? [selectedDrawingId]
: [];
// Bei grossen Auswahlen (z. B. Rahmen über Katasterdaten) gibt es KEINE Griffe:
// je Stützpunkt ein Eck- und ein Kanten-Griff ergaben zehntausende DOM-Elemente
// (Sekunden Wartezeit) und sind bei so vielen Punkten nicht bedienbar. Massgebend
// ist die GESAMTZAHL der Stützpunkte (wenige Objekte können riesige Umrisse
// haben), nicht die Objektzahl. Die Auswahl selbst (Hervorhebung, Verschieben,
// Eigenschaften) bleibt unberührt.
const MAX_GRIP_DRAWINGS = 50;
const MAX_GRIP_VERTICES = 600;
const gripDrawingIds = (() => {
if (effectiveDrawingIds.length > MAX_GRIP_DRAWINGS) return [];
let total = 0;
for (const id of effectiveDrawingIds) {
const d = project.drawings2d.find((x) => x.id === id);
if (d) total += drawingVertices(d, scaleDenominator).length;
if (total > MAX_GRIP_VERTICES) return [];
}
return effectiveDrawingIds;
})();
// Griff-Grenzen (s. gripLimits.ts): grosse Mehrfachauswahlen ohne Griffe, ein einzeln gewähltes
// Element immer mit Griffen (Kataster-Parzellen mit tausenden Stützpunkten).
const gripDrawingIds = gripDrawingIdsFor(effectiveDrawingIds, (id) => {
const d = project.drawings2d.find((x) => x.id === id);
return d ? drawingVertices(d, scaleDenominator).length : 0;
});
// ── Höhen-Griffe im Schnitt/in der Ansicht ───────────────────────────────
// Gewählte Wand: Griff an der Oberkante (ändert `height`). Gewähltes Fenster: Griffe
+10 -6
View File
@@ -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}
+43
View File
@@ -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);
});
});
+54
View File
@@ -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;
}
+6 -5
View File
@@ -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}
+17
View File
@@ -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("");
});
});
+41
View File
@@ -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} />;
}