[147] Plan öffnet nicht mehr zu stark gezoomt: Mindestausschnitt 30 m, Neueinpassen bei Projektwechsel

This commit is contained in:
Claude committed 2026-11-06 01:10:42 +00:00
1 parent 4e0a376ef8
commit 39b359fe8e
8 files changed
+129 -14

No files matched your search

+1
View File
@@ -200,6 +200,7 @@ export {
scaleFromView,
toScreen,
viewForCamera,
defaultViewFor,
viewForScale,
visibleEdgeRuns,
} from "../plan/planView/geometry";
+24 -1
View File
@@ -6,7 +6,7 @@
*/
import { describe, it, expect } from "vitest";
import type { ModelRect } from "./geometry";
import { defaultViewFor, MIN_FIT_EXTENT_M, PAD, PX_PER_M, type ModelRect } from "./geometry";
import type { Primitive } from "../generatePlan";
import { PlanPickIndex } from "./planPick";
@@ -111,3 +111,26 @@ describe("marqueeHitDrawings — Kreis/Bogen/Text/Bild", () => {
expect(marqueeHitDrawings(prims, rightRect, false)).toEqual([]);
});
});
describe("defaultViewFor [147]", () => {
it("leeres Projekt (Platzhalter 0,0–1,1) → Standardausschnitt von 30 m statt 1 m", () => {
const v = defaultViewFor({ minX: 0, minY: 0, maxX: 1, maxY: 1 });
expect(v.w).toBeCloseTo(MIN_FIT_EXTENT_M * PX_PER_M + 2 * PAD);
expect(v.h).toBeCloseTo(MIN_FIT_EXTENT_M * PX_PER_M + 2 * PAD);
expect(v.x + v.w / 2).toBeCloseTo(0.5 * PX_PER_M);
expect(v.y + v.h / 2).toBeCloseTo(-0.5 * PX_PER_M);
});
it("ungültige Grenzen (NaN/Infinity) → endlicher Standardausschnitt", () => {
const v = defaultViewFor({ minX: NaN, minY: 0, maxX: Infinity, maxY: 1 });
expect([v.x, v.y, v.w, v.h].every(Number.isFinite)).toBe(true);
expect(v.w).toBeGreaterThan(0);
});
it("normales Modell bleibt unverändert eingepasst (Rand PAD)", () => {
const v = defaultViewFor({ minX: 0, minY: 0, maxX: 40, maxY: 35 });
expect(v).toEqual({ x: -PAD, y: -35 * PX_PER_M - PAD, w: 40 * PX_PER_M + 2 * PAD, h: 35 * PX_PER_M + 2 * PAD });
});
it("ohne Mindestkante (Blatt) keine Erweiterung", () => {
const v = defaultViewFor({ minX: 0, minY: 0, maxX: 2, maxY: 1 }, 0, 0);
expect(v.w).toBeCloseTo(2 * PX_PER_M);
});
});
+32
View File
@@ -14,6 +14,8 @@ export interface ViewBox {
export const PX_PER_M = 90; // viewBox-Einheiten je Meter (Modell → SVG-Benutzerraum)
export const PAD = 60; // Rand in viewBox-Einheiten
/** Kleinste Kantenlänge (m) des Einpass-Bereichs: leeres/winziges Modell öffnet bei ca. 1:100 statt extrem nah ([147]). */
export const MIN_FIT_EXTENT_M = 30;
/**
* Modell-Meter → SVG-Benutzerraum (viewBox-Einheiten) mit FIXEM Welt-Ursprung
@@ -301,3 +303,33 @@ export function polyTouchesRect(poly: Vec2[], r: ModelRect): boolean {
}
return false;
}
/**
* Eingepasste Standard-Ansicht (viewBox) für Modell-Grenzen in Metern. Ist eine Kante kürzer als
* {@link MIN_FIT_EXTENT_M} (leeres Projekt: Platzhalter 0,0–1,1; einzelner Punkt/kurze Linie) oder
* ungültig (NaN/∞), wird der Bereich um den Mittelpunkt auf diese Länge erweitert ([147]).
* `pad` = Rand in viewBox-Einheiten (Standard {@link PAD}).
*/
export function defaultViewFor(
b: { minX: number; minY: number; maxX: number; maxY: number },
pad: number = PAD,
minExtent: number = MIN_FIT_EXTENT_M,
): ViewBox {
const ok = [b.minX, b.minY, b.maxX, b.maxY].every(Number.isFinite);
let { minX, minY, maxX, maxY } = ok ? b : { minX: 0, minY: 0, maxX: 0, maxY: 0 };
if (maxX < minX) [minX, maxX] = [maxX, minX];
if (maxY < minY) [minY, maxY] = [maxY, minY];
const grow = (lo: number, hi: number): [number, number] => {
if (hi - lo >= minExtent) return [lo, hi];
const c = (lo + hi) / 2;
return [c - minExtent / 2, c + minExtent / 2];
};
[minX, maxX] = grow(minX, maxX);
[minY, maxY] = grow(minY, maxY);
return {
x: minX * PX_PER_M - pad,
y: -maxY * PX_PER_M - pad,
w: (maxX - minX) * PX_PER_M + pad * 2,
h: (maxY - minY) * PX_PER_M + pad * 2,
};
}
+5 -2
View File
@@ -77,6 +77,8 @@ import type { NotifyKind } from "./notifySlice";
/** Felder, die diese Slice in den RootState beisteuert. */
export interface ProjectSlice {
project: Project;
/** Zählt Projektwechsel ({@link loadProject}/{@link openProjectFile}); Ansichten passen sich dann neu ein ([147]). */
projectEpoch: number;
// ── Projekt direkt setzen (für Werkzeuge/Transformationen aus App) ────────
/**
@@ -575,6 +577,7 @@ export function createProjectSlice(
// bevor eine der drei Optionen (Neu/Öffnen/Zuletzt) das echte Projekt
// setzt. Der konkrete Wert spielt daher praktisch keine Rolle mehr.
project: sampleProject,
projectEpoch: 0,
setProject,
applyChange,
@@ -604,7 +607,7 @@ export function createProjectSlice(
loadProject: (next) => {
const doc = storeDocument(get().project);
doc.load(next);
set({ project: next, ...historyPatch(doc) });
set({ project: next, projectEpoch: get().projectEpoch + 1, ...historyPatch(doc) });
resetViewTabs(); // [136] neues Projekt: ein Reiter mit der aktuellen Ansicht
},
@@ -612,7 +615,7 @@ export function createProjectSlice(
const doc = storeDocument(get().project);
const r = doc.loadFile(text);
if (r.ok) {
set({ project: r.project, ...historyPatch(doc) });
set({ project: r.project, projectEpoch: get().projectEpoch + 1, ...historyPatch(doc) });
resetViewTabs(); // [136]
}
return r;
+4 -9
View File
@@ -33,7 +33,7 @@ import { LiveMeet, LiveValue, createMeetStore, createValueStore } from "./planVi
import { useWasmPlanRenderer } from "./useWasmPlanRenderer";
import { DEFAULT_MARQUEE_COLOR, DEFAULT_SNAP_COLOR } from "../../theme/accents";
import { PLAN_DASH_VAR } from "../../core";
import { type ViewBox__plan_planView_geometry as ViewBox, PX_PER_M, PAD, toScreen, clamp, meetScale, scaleFromView, viewForScale, viewForCamera, fitBoxFor, type ModelRect } from "../../core";
import { type ViewBox__plan_planView_geometry as ViewBox, PX_PER_M, PAD, toScreen, clamp, meetScale, scaleFromView, viewForScale, viewForCamera, fitBoxFor, defaultViewFor, type ModelRect } from "../../core";
import {
polyUsesPattern,
HatchPattern,
@@ -700,15 +700,10 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
// toScreen-Abbildung. Reset-/Einpassen-Ziel + Bezug für die Zoom-Grenzen; wird
// NICHT automatisch angewandt (nur bei resetKey-Wechsel und „Einpassen").
const defaultView = useMemo<ViewBox>(() => {
const { minX, minY, maxX, maxY } = fitBounds ?? planRaw.bounds;
const b = fitBounds ?? planRaw.bounds;
// Fester Einpass-Bereich (Blatt): Rand relativ zu seiner Grösse statt der festen Modell-Marge.
const pad = fitBounds ? Math.max(maxX - minX, maxY - minY) * PX_PER_M * 0.04 : PAD;
return {
x: minX * PX_PER_M - pad,
y: -maxY * PX_PER_M - pad,
w: (maxX - minX) * PX_PER_M + pad * 2,
h: (maxY - minY) * PX_PER_M + pad * 2,
};
const pad = fitBounds ? Math.max(b.maxX - b.minX, b.maxY - b.minY) * PX_PER_M * 0.04 : PAD;
return defaultViewFor(b, pad, fitBounds ? 0 : undefined);
}, [planRaw, fitBounds]);
// Aktueller Ausschnitt; treibt die viewBox des SVG. Initial = eingepasst.
+4 -2
View File
@@ -768,6 +768,7 @@ function LevelPlanView({
edgeGrips: EdgeGrip[];
gripHandlers: GripHandlers;
}) {
const projectEpoch = useStore((s) => s.projectEpoch);
// Fremd-Art-Referenz-Unterlage (Nutzer-Wunsch: "will mal etwas vom Schnitt
// abzeichnen" — UND umgekehrt "in der Ansicht auch mal einen Grundriss
// zeigen"): jede andere sichtbare Zeichnungsebene ANDERER Art (Auge an,
@@ -861,7 +862,7 @@ function LevelPlanView({
plan={plan}
describePick={describePick}
onPickHint={setPickHint}
resetKey={level.id}
resetKey={`${level.id}#${projectEpoch}`}
onCursor={onCursor}
onScale={onScale}
selection={selection}
@@ -1001,6 +1002,7 @@ function SectionPlanView({
edgeGrips: EdgeGrip[];
gripHandlers: GripHandlers;
}) {
const projectEpoch = useStore((s) => s.projectEpoch);
// Kontext-Objekte hebt der Schnitt (wie bisher) nicht hervor.
const sectionSelection = useMemo(
() => (selection.contextObjects.length ? { ...selection, contextObjects: [] } : selection),
@@ -1222,7 +1224,7 @@ function SectionPlanView({
<PlanView
ref={planViewRef}
plan={plan}
resetKey={level.id}
resetKey={`${level.id}#${projectEpoch}`}
onCursor={onCursor}
onScale={onScale}
selection={sectionSelection}