[G10][C1] Plan-Overlay relativ zu lokalem Ursprung: Griffe/Lineal/Kreise bei LV95 pixelgenau
Das SVG-Overlay der Plan-Ansicht schrieb absolute viewBox-Einheiten (m · 90) ins DOM; bei Landeskoordinaten (≈ 2.3e8) rechnet der Browser in f32 und klemmt CSS-Längen. Jetzt wählt PlanView einen Ursprung nahe dem Ausschnitt (planView/overlayOrigin.ts, bleibt stehen bis > 64 Ausschnitt-Grössen entfernt, lokale Projekte: (0, 0) wie bisher) und zieht ihn in f64 ab: viewBox (auch beim imperativen Pan), Griffe, Kanten-Griffe, Fang-Marken, Hervorhebung, Vorschau, Texte, Raster, Lineal, HUD, Marquee, Luftbilder. Ausschnitt, Treffer und Fang bleiben absolut. vbCircle entfernt (lokal wieder <circle>). Lineal/Raster-Ticks über ganzzahligen Index (aufsummiert drifteten sie bei LV95). Kanten-Griffe einer Polylinie liefen auch über die Bogen-Mitten-Griffe von drawingVertices (Dreiecke quer im Innern): jetzt nur Eckpunkte, nur gerade Segmente (state/edgeGrips.ts). Plan-Rad: nicht-passiver Listener statt preventDefault im passiven React-onWheel (Chromium-Konsolenfehler). Gemessen (Chromium, e2e kataster.spec.ts, Abstand Griff–Ecke): vorher 1.6 px Übersicht, 5.0 px bei 10 m, 31 px bei 1 m Ausschnitt; nachher ≤ 0.003 px. Lineal und Vorschau-Kreis bei LV95 sichtbar und am Ort. Nicht in Tauri/WKWebView geprüft. Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
13 files changed
+505
-198
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { polylineEdgeGrips } from "./edgeGrips";
|
||||
|
||||
const sq = [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 30, y: 0 },
|
||||
{ x: 30, y: 30 },
|
||||
{ x: 0, y: 30 },
|
||||
];
|
||||
|
||||
describe("polylineEdgeGrips", () => {
|
||||
it("geschlossen, gerade: 4 Kanten auf den Seitenmitten, Normalen nach aussen", () => {
|
||||
const e = polylineEdgeGrips({ shape: "polyline", pts: sq, closed: true }, { drawingId: "d" });
|
||||
expect(e.map((g) => g.mid)).toEqual([
|
||||
{ x: 15, y: 0 },
|
||||
{ x: 30, y: 15 },
|
||||
{ x: 15, y: 30 },
|
||||
{ x: 0, y: 15 },
|
||||
]);
|
||||
expect(e.map((g) => [g.aIndex, g.bIndex])).toEqual([[0, 1], [1, 2], [2, 3], [3, 0]]);
|
||||
expect(e[0].normal.y).toBeCloseTo(-1);
|
||||
expect(e[1].normal.x).toBeCloseTo(1);
|
||||
});
|
||||
|
||||
it("geschlossen mit Bögen: nur gerade Seiten, keine Kanten über die Bogen-Mitten (nichts im Innern)", () => {
|
||||
const e = polylineEdgeGrips(
|
||||
{ shape: "polyline", pts: sq, closed: true, bulge: [0.12, 0, -0.15, 0] },
|
||||
{ drawingId: "d" },
|
||||
);
|
||||
expect(e.map((g) => g.mid)).toEqual([
|
||||
{ x: 30, y: 15 },
|
||||
{ x: 0, y: 15 },
|
||||
]);
|
||||
// Lauter Bögen (Strassenparzelle): keine Kanten-Griffe.
|
||||
expect(polylineEdgeGrips({ shape: "polyline", pts: sq, closed: true, bulge: [0.1, 0.1, 0.1, 0.1] }, {})).toEqual([]);
|
||||
});
|
||||
|
||||
it("offen: je gerades Segment ein freier Griff, ohne Schlusskante", () => {
|
||||
const e = polylineEdgeGrips({ shape: "polyline", pts: sq, closed: false, bulge: [0, 0.3, 0] }, {});
|
||||
expect(e.map((g) => [g.aIndex, g.bIndex, g.free])).toEqual([[0, 1, true], [2, 3, true]]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
// Kanten-Griffe (je Seite ein Anfasser mit Aussennormale) eines gewählten Elements — reine
|
||||
// Geometrie, ausgelagert aus `useGripEditing.ts`.
|
||||
|
||||
import { leftNormal, normalize, scale, sub } from "../model/geometry";
|
||||
import type { Drawing2DGeom, EdgeGrip, Vec2 } from "../model/types";
|
||||
|
||||
type Owner = { drawingId?: string; wallId?: string };
|
||||
|
||||
/** Geschlossener Ring aus Vertices → Kanten-Griffe mit Aussennormale (vom Eckpunkt-Mittel weg). */
|
||||
export function ringEdges(verts: Vec2[], owner: Owner): EdgeGrip[] {
|
||||
const n = verts.length;
|
||||
if (n < 3) return [];
|
||||
// Schwerpunkt (Mittel der Eckpunkte) als Innenbezug.
|
||||
let cx = 0, cy = 0;
|
||||
for (const v of verts) { cx += v.x; cy += v.y; }
|
||||
const centroid: Vec2 = { x: cx / n, y: cy / n };
|
||||
const out: EdgeGrip[] = [];
|
||||
for (let i = 0; i < n; i++) {
|
||||
const a = verts[i];
|
||||
const b = verts[(i + 1) % n];
|
||||
const mid: Vec2 = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
||||
let nrm = normalize(leftNormal(sub(b, a)));
|
||||
// Nach aussen orientieren: Normale soll von centroid → mid weisen.
|
||||
const outward = sub(mid, centroid);
|
||||
if (nrm.x * outward.x + nrm.y * outward.y < 0) nrm = scale(nrm, -1);
|
||||
out.push({ mid, normal: nrm, aIndex: i, bIndex: (i + 1) % n, owner });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offene Kette (Linie/offene Polylinie) → ein Griff je Segment, OHNE Schlusskante. `normal` dient
|
||||
* nur der Darstellung (leftNormal der Kante); die Bewegung ist frei (`free: true`).
|
||||
*/
|
||||
export function openEdges(verts: Vec2[], owner: Owner): EdgeGrip[] {
|
||||
const n = verts.length;
|
||||
if (n < 2) return [];
|
||||
const out: EdgeGrip[] = [];
|
||||
for (let i = 0; i < n - 1; i++) {
|
||||
const a = verts[i];
|
||||
const b = verts[i + 1];
|
||||
const mid: Vec2 = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
||||
const nrm = normalize(leftNormal(sub(b, a)));
|
||||
out.push({ mid, normal: nrm, aIndex: i, bIndex: i + 1, free: true, owner });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kanten-Griffe einer Polylinie: nur über die Eckpunkte (`drawingVertices` hängt dahinter je
|
||||
* Segment einen Bogen-Mitten-Griff an — liefen die Kanten auch über diese, sassen Dreiecke quer im
|
||||
* Innern, Fund 29.10.) und nur an geraden Segmenten: ein Bogen hat seinen Bogen-Mitten-Griff, die
|
||||
* Sehnen-Mitte läge neben der Linie.
|
||||
*/
|
||||
export function polylineEdgeGrips(g: Extract<Drawing2DGeom, { shape: "polyline" }>, owner: Owner): EdgeGrip[] {
|
||||
const all = g.closed ? ringEdges(g.pts, owner) : openEdges(g.pts, owner);
|
||||
return all.filter((e) => Math.abs(g.bulge?.[e.aIndex] ?? 0) <= 1e-9);
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import type { Ceiling, Drawing2D, EdgeGrip, Project, Room, Stair, Vec2 } from ".
|
||||
import { wallTypeThickness } from "../model/types";
|
||||
import { drawingVertices } from "./projectSlice";
|
||||
import { gripDrawingIdsFor } from "./gripLimits";
|
||||
import { openEdges, polylineEdgeGrips, ringEdges } from "./edgeGrips";
|
||||
import { areaMovePreview } from "../tools/transform";
|
||||
import { mvGeom } from "../core";
|
||||
import { drawingPreviewShapes } from "../tools/drawingPreview";
|
||||
@@ -371,45 +372,7 @@ export function useGripEditing(opts: {
|
||||
// Ecken wandern mit, die Nachbar-Segmente dehnen sich nach (Parallel-
|
||||
// Verschieben EINER Kante einer komplexen Polylinie, §Task B).
|
||||
const edgeGrips: EdgeGrip[] = (() => {
|
||||
// Geschlossener Ring aus Vertices → Kanten-Griffe mit Außennormale.
|
||||
const ringEdges = (verts: Vec2[], owner: { drawingId?: string; wallId?: string }): EdgeGrip[] => {
|
||||
const n = verts.length;
|
||||
if (n < 3) return [];
|
||||
// Schwerpunkt (Mittel der Eckpunkte) als Innenbezug.
|
||||
let cx = 0, cy = 0;
|
||||
for (const v of verts) { cx += v.x; cy += v.y; }
|
||||
const centroid: Vec2 = { x: cx / n, y: cy / n };
|
||||
const out: EdgeGrip[] = [];
|
||||
for (let i = 0; i < n; i++) {
|
||||
const a = verts[i];
|
||||
const b = verts[(i + 1) % n];
|
||||
const mid: Vec2 = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
||||
const edge = sub(b, a);
|
||||
let nrm = normalize(leftNormal(edge));
|
||||
// Nach außen orientieren: Normale soll von centroid → mid weisen.
|
||||
const outward = sub(mid, centroid);
|
||||
if (nrm.x * outward.x + nrm.y * outward.y < 0) nrm = scale(nrm, -1);
|
||||
out.push({ mid, normal: nrm, aIndex: i, bIndex: (i + 1) % n, owner });
|
||||
}
|
||||
return out;
|
||||
};
|
||||
// Offene Kette (Linie/offene Polylinie) → ein Griff je Segment, OHNE
|
||||
// Schlusskante. `normal` dient nur der Griff-Darstellung (leftNormal der
|
||||
// Kante); die Bewegung ist frei (volles Delta), nicht auf die Normale
|
||||
// beschränkt — daher `free: true`.
|
||||
const openEdges = (verts: Vec2[], owner: { drawingId?: string; wallId?: string }): EdgeGrip[] => {
|
||||
const n = verts.length;
|
||||
if (n < 2) return [];
|
||||
const out: EdgeGrip[] = [];
|
||||
for (let i = 0; i < n - 1; i++) {
|
||||
const a = verts[i];
|
||||
const b = verts[i + 1];
|
||||
const mid: Vec2 = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
||||
const nrm = normalize(leftNormal(sub(b, a)));
|
||||
out.push({ mid, normal: nrm, aIndex: i, bIndex: i + 1, free: true, owner });
|
||||
}
|
||||
return out;
|
||||
};
|
||||
// ringEdges/openEdges/polylineEdgeGrips: s. edgeGrips.ts.
|
||||
// Decke: geschlossener Ring aus dem Umriss (Auswahl exklusiv, wie bei grips).
|
||||
if (modelEditable && selectedCeiling && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
|
||||
return ringEdges(selectedCeiling.outline, {});
|
||||
@@ -432,8 +395,7 @@ export function useGripEditing(opts: {
|
||||
const g = d.geom;
|
||||
const owner = { drawingId: id };
|
||||
if (g.shape === "rect" || g.shape === "image") out.push(...ringEdges(verts, owner));
|
||||
else if (g.shape === "polyline" && g.closed) out.push(...ringEdges(verts, owner));
|
||||
else if (g.shape === "polyline" && !g.closed) out.push(...openEdges(verts, owner));
|
||||
else if (g.shape === "polyline") out.push(...polylineEdgeGrips(g, owner));
|
||||
else if (g.shape === "spline" && g.closed) out.push(...ringEdges(verts, owner));
|
||||
else if (g.shape === "spline" && !g.closed) out.push(...openEdges(verts, owner));
|
||||
else if (g.shape === "line") out.push(...openEdges(verts, owner));
|
||||
|
||||
Reference in new issue
Block a user