[128] Griffe: useGripEditing nutzt die Kern-Rechnung grip_drag (Zwischenstand)
This commit is contained in:
5 files changed
+330
-304
No files matched your search
@@ -0,0 +1,67 @@
|
||||
// Fassade der Griff-Zug-Rechnung ([128], Kern `grip_drag.rs`): Übergabe an den Kern und zurück.
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
coincidentGripPoints,
|
||||
gripAxisLock,
|
||||
gripEdgeTarget,
|
||||
gripPolar,
|
||||
gripPolarPoint,
|
||||
openingGripPoint,
|
||||
openingSheetSlide,
|
||||
openingSlidePosition,
|
||||
sheetHeightDrag,
|
||||
wallGripPoints,
|
||||
} from "./gripDrag";
|
||||
|
||||
const wall = { start: { x: 0, y: 0 }, end: { x: 5, y: 0 } };
|
||||
|
||||
describe("Griff-Zug (Kern)", () => {
|
||||
it("Länge/Winkel und Punkt aus Locks", () => {
|
||||
expect(gripPolar({ x: 1, y: 1 }, { x: 1, y: 3 }, { x: 0, y: 1 })).toEqual({ length: 2, angleDeg: 90, offset: 2 });
|
||||
const p = gripPolarPoint({ x: 0, y: 0 }, { length: 5 }, { x: 3, y: 0 });
|
||||
expect(p.x).toBeCloseTo(5, 12);
|
||||
expect(p.y).toBeCloseTo(0, 12);
|
||||
});
|
||||
|
||||
it("Shift-Achsen-Lock: Flucht der Nachbarkante, ohne Ring nur H/V", () => {
|
||||
const ring = [{ x: 0, y: 0 }, { x: 1, y: 1 }, { x: 1, y: 3 }];
|
||||
const p = gripAxisLock({ x: 2.1, y: 1.9 }, { x: 0, y: 0 }, { x: 1, y: 1 }, ring, 1, false);
|
||||
expect(p.x).toBeCloseTo(2, 12);
|
||||
expect(p.y).toBeCloseTo(2, 12);
|
||||
expect(gripAxisLock({ x: 3, y: 0.4 }, { x: 0, y: 0 }, null, null, -1, false)).toEqual({ x: 3, y: 0 });
|
||||
});
|
||||
|
||||
it("Kanten-Ziel: geführt mit Raster/Snap, frei mit Ortho, gelockt", () => {
|
||||
const guided = { mid: { x: 0, y: 0 }, normal: { x: 0, y: 1 }, aIndex: 0, bIndex: 1 };
|
||||
expect(gripEdgeTarget(guided, { x: 7, y: 1.3 }, { grid: 0.5 })).toEqual({ x: 0, y: 1.5 });
|
||||
expect(gripEdgeTarget(guided, { x: 7, y: 1.3 }, { grid: 0.5, snapped: { x: 2, y: 1.27 } })).toEqual({ x: 0, y: 1.27 });
|
||||
expect(gripEdgeTarget(guided, { x: 7, y: 1.3 }, { locks: { length: 0.25 } })).toEqual({ x: 0, y: 0.25 });
|
||||
const free = { ...guided, mid: { x: 1, y: 1 }, free: true };
|
||||
expect(gripEdgeTarget(free, { x: 3.2, y: 1.4 }, { shift: true })).toEqual({ x: 3.2, y: 1 });
|
||||
});
|
||||
|
||||
it("Höhen-Griffe: Patch je Art", () => {
|
||||
expect(sheetHeightDrag("wallTop", { base: 3, top: 5.6, bottom: 3 }, 5.7349, false)).toEqual({ top: 5.73, bottom: 3, patch: { height: 2.73 } });
|
||||
const r = sheetHeightDrag("openingBottom", { base: 0, top: 2.1, bottom: 0.9 }, 0.6, false);
|
||||
expect(r.patch).toEqual({ sillHeight: 0.6, height: 1.5 });
|
||||
});
|
||||
|
||||
it("Öffnung entlang der Wand und im Schnitt", () => {
|
||||
expect(openingGripPoint(wall, { position: 1, width: 1.2 })).toEqual({ x: 1.6, y: 0 });
|
||||
expect(openingSlidePosition(wall, { width: 1.2 }, { x: 2.6, y: 3 })).toBe(2);
|
||||
expect(openingSlidePosition({ start: wall.start, end: wall.start }, { width: 1.2 }, { x: 1, y: 0 })).toBeNull();
|
||||
expect(openingSheetSlide(wall, { position: 1, width: 1.2 }, { x: -1, y: 0 }, 0.5)).toEqual({ position: 0.5, du: 0.5 });
|
||||
expect(openingSheetSlide(wall, { position: 1, width: 1.2 }, { x: 0.1, y: 0.995 }, 1)).toBeNull();
|
||||
});
|
||||
|
||||
it("Wand-Griffe und koinzidente Ecken", () => {
|
||||
expect(wallGripPoints({ ...wall })).toHaveLength(2);
|
||||
const g = wallGripPoints({ start: { x: 0, y: 0 }, end: { x: 4, y: 0 }, bulge: 0.5 });
|
||||
expect(g[2].x).toBeCloseTo(2, 12);
|
||||
expect(g[2].y).toBeCloseTo(1, 12);
|
||||
const corners = [{ x: 0, y: 0 }, { x: 4, y: 0 }];
|
||||
const groups = [[{ x: 4.03, y: 0 }, { x: 4, y: 3 }], [], [{ x: 0, y: 0.04 }]];
|
||||
expect(coincidentGripPoints(corners, groups)).toEqual([{ group: 2, index: 0 }, { group: 0, index: 0 }]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,160 @@
|
||||
// Griff-Zug-Rechnung ([128]): dünne Fassade über den Rust-Kern (`src-tauri/core/src/grip_drag.rs`,
|
||||
// Bindungen `web/grip_drag.rs`). Wohin ein gezogener Griff fällt (Länge/Winkel-Felder, Shift-Achsen-Lock,
|
||||
// Kanten-Griffe, Höhen-Griffe im Schnitt, Öffnung entlang der Wand, koinzidente Ecken) rechnet der Kern;
|
||||
// `state/useGripEditing.ts` hält nur Zustand und Vorschau.
|
||||
|
||||
import type { EdgeGrip, Excavation, Opening, Stair, Vec2, Wall } from "../model/types";
|
||||
import { core } from "../engine/coreWasm";
|
||||
|
||||
const v = (f: ArrayLike<number>, i = 0): Vec2 => ({ x: f[i], y: f[i + 1] });
|
||||
|
||||
function flat(pts: readonly Vec2[]): Float64Array {
|
||||
const f = new Float64Array(pts.length * 2);
|
||||
for (let i = 0; i < pts.length; i++) {
|
||||
f[2 * i] = pts[i].x;
|
||||
f[2 * i + 1] = pts[i].y;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
function points(f: ArrayLike<number>): Vec2[] {
|
||||
const out: Vec2[] = new Array(f.length >> 1);
|
||||
for (let i = 0; i < out.length; i++) out[i] = v(f, 2 * i);
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Gelockte Länge (m) / Winkel (Grad) des Feld-Controllers; fehlend = folgt dem Cursor. */
|
||||
export interface GripLocks {
|
||||
length?: number;
|
||||
angle?: number;
|
||||
}
|
||||
|
||||
/** Länge, Winkel (Grad, [0, 360)) und Abstand entlang `normal` von `anchor` nach `p` (Felder, HUD). */
|
||||
export function gripPolar(anchor: Vec2, p: Vec2, normal: Vec2 = { x: 0, y: 0 }): { length: number; angleDeg: number; offset: number } {
|
||||
const f = core().grip_polar(anchor.x, anchor.y, p.x, p.y, normal.x, normal.y);
|
||||
return { length: f[0], angleDeg: f[1], offset: f[2] };
|
||||
}
|
||||
|
||||
/** Punkt aus Anker + gelockter Länge/Winkel; ungelockte Werte folgen dem rohen Cursor `raw`. */
|
||||
export function gripPolarPoint(anchor: Vec2, locks: GripLocks, raw: Vec2): Vec2 {
|
||||
return v(core().grip_polar_point(anchor.x, anchor.y, locks.length ?? NaN, locks.angle ?? NaN, raw.x, raw.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift-Achsen-Lock eines Punkt-Griffs: Welt-H/V durch den Nachbar-Griff `anchor`, bei einem Vielecks-
|
||||
* Eckpunkt (`ring` = Punkte des Elements, `index` darin, `origin` = Lage vor dem Zug) zusätzlich die Flucht
|
||||
* der beiden fixen Nachbarkanten. Die nächstliegende Achse gewinnt.
|
||||
*/
|
||||
export function gripAxisLock(raw: Vec2, anchor: Vec2, origin: Vec2 | null, ring: readonly Vec2[] | null, index: number, closed: boolean): Vec2 {
|
||||
const f = ring && origin ? flat(ring) : new Float64Array();
|
||||
return v(core().grip_axis_lock(raw.x, raw.y, anchor.x, anchor.y, origin?.x ?? NaN, origin?.y ?? NaN, f, index, closed));
|
||||
}
|
||||
|
||||
/** Führung eines Kanten-Zugs (s. {@link gripEdgeTarget}). */
|
||||
export interface EdgeDrive {
|
||||
/** Feld-Controller offen: Ziel aus Anker + Locks, ohne Raster/Ortho. */
|
||||
locks?: GripLocks | null;
|
||||
shift?: boolean;
|
||||
/** Rasterweite (0 = aus). */
|
||||
grid?: number;
|
||||
/** Gefangener Geometrie-Snap (nur geführte Kanten). */
|
||||
snapped?: Vec2 | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zielpunkt eines Kanten-Zugs relativ zum Anker `edge.mid`: geführte Kante nur entlang der Normale
|
||||
* (Geometrie-Snap vor Raster), freie Kante (`edge.free`) voller Cursor mit Ortho/Raster.
|
||||
*/
|
||||
export function gripEdgeTarget(edge: EdgeGrip, raw: Vec2, d: EdgeDrive = {}): Vec2 {
|
||||
const { mid, normal } = edge;
|
||||
const l = d.locks;
|
||||
const s = d.snapped;
|
||||
return v(
|
||||
core().grip_edge_target(
|
||||
mid.x, mid.y, normal.x, normal.y, !!edge.free, raw.x, raw.y,
|
||||
!!l, l?.length ?? NaN, l?.angle ?? NaN, !!d.shift, d.grid ?? 0, s?.x ?? NaN, s?.y ?? NaN,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/** Art eines Höhen-Griffs im Schnitt/in der Ansicht. */
|
||||
export type SheetHeightKind = "wallTop" | "openingTop" | "openingBottom";
|
||||
|
||||
/**
|
||||
* Höhen-Griff auf die Blatt-Höhe `y` ziehen (1-cm-Raster, `free` = ohne): neue Ober-/Unterkante im Blatt und
|
||||
* der Patch fürs Bauteil (`height`, Fenster-Unterkante zusätzlich `sillHeight`; mm-genau).
|
||||
*/
|
||||
export function sheetHeightDrag(
|
||||
kind: SheetHeightKind,
|
||||
g: { base: number; top: number; bottom: number },
|
||||
y: number,
|
||||
free: boolean,
|
||||
): { top: number; bottom: number; patch: Record<string, number> } {
|
||||
const k = kind === "wallTop" ? 0 : kind === "openingTop" ? 1 : 2;
|
||||
const f = core().grip_sheet_height(k, g.base, g.top, g.bottom, y, free);
|
||||
const patch: Record<string, number> = kind === "openingBottom" ? { sillHeight: f[3], height: f[2] } : { height: f[2] };
|
||||
return { top: f[0], bottom: f[1], patch };
|
||||
}
|
||||
|
||||
/** Mittelpunkt-Griff einer Öffnung auf der Achse ihrer Wirtswand. */
|
||||
export function openingGripPoint(w: Pick<Wall, "start" | "end">, op: Pick<Opening, "position" | "width">): Vec2 {
|
||||
return v(core().grip_opening_point(w.start.x, w.start.y, w.end.x, w.end.y, op.position, op.width));
|
||||
}
|
||||
|
||||
/** Neue `position` beim Ziehen des Öffnungs-Griffs nach `pt` (auf die Wand geklemmt); null = Wand ohne Länge. */
|
||||
export function openingSlidePosition(w: Pick<Wall, "start" | "end">, op: Pick<Opening, "width">, pt: Vec2): number | null {
|
||||
const f = core().grip_opening_slide(w.start.x, w.start.y, w.end.x, w.end.y, op.width, pt.x, pt.y);
|
||||
return f.length ? f[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffnung im Schnitt-Blatt waagrecht ziehen: Blatt-Delta `du` (gesamt, entlang `uAxis`) → neue `position`
|
||||
* und das wirksame Delta (nach dem Klemmen); null, wenn die Wand fast quer zur Schnittlinie steht.
|
||||
*/
|
||||
export function openingSheetSlide(
|
||||
w: Pick<Wall, "start" | "end">,
|
||||
op: Pick<Opening, "position" | "width">,
|
||||
uAxis: Vec2,
|
||||
du: number,
|
||||
): { position: number; du: number } | null {
|
||||
const f = core().grip_opening_slide_sheet(w.start.x, w.start.y, w.end.x, w.end.y, uAxis.x, uAxis.y, op.position, op.width, du);
|
||||
return f.length ? { position: f[0], du: f[1] } : null;
|
||||
}
|
||||
|
||||
/** Bewegpunkt einer Treppe (Mitte des ersten Laufs, Wendeltreppe im Zentrum). */
|
||||
export function stairMoveHandle(st: Stair): Vec2 {
|
||||
const c = st.center;
|
||||
return v(core().grip_stair_handle(st.shape === "spiral", c?.x ?? NaN, c?.y ?? NaN, st.start.x, st.start.y, st.dir?.x ?? 0, st.dir?.y ?? 0, st.runLength));
|
||||
}
|
||||
|
||||
/** Griffe einer Wand: Start, Ende, bei einer Bogenwand ([T2]) der Bogenscheitel. */
|
||||
export function wallGripPoints(w: Pick<Wall, "start" | "end" | "bulge">): Vec2[] {
|
||||
return points(core().grip_wall_points(w.start.x, w.start.y, w.end.x, w.end.y, w.bulge ?? 0));
|
||||
}
|
||||
|
||||
/** Griff-Punkte einer Baugrube: Umriss-Ecken, dann der Sohlen-Griff (Schwerpunkt, y + Sohlenhöhe). */
|
||||
export function excavationGripPoints(e: Excavation): Vec2[] {
|
||||
return points(core().grip_excavation_points(flat(e.outline), e.bottom));
|
||||
}
|
||||
|
||||
/**
|
||||
* Koinzidente Punkte anderer Elemente (`groups`, je Element seine Griff-Punkte) an den Ecken `corners` des
|
||||
* verschobenen Elements (Toleranz 5 cm): `{group, index}` je Punkt, ohne Doppel.
|
||||
*/
|
||||
export function coincidentGripPoints(corners: readonly Vec2[], groups: readonly (readonly Vec2[])[]): { group: number; index: number }[] {
|
||||
if (corners.length === 0 || groups.length === 0) return [];
|
||||
const n = groups.reduce((a, g) => a + 1 + 2 * g.length, 0);
|
||||
const f = new Float64Array(n);
|
||||
let k = 0;
|
||||
for (const g of groups) {
|
||||
f[k++] = g.length;
|
||||
for (const p of g) {
|
||||
f[k++] = p.x;
|
||||
f[k++] = p.y;
|
||||
}
|
||||
}
|
||||
const r = core().grip_coincident(flat(corners), f);
|
||||
const out: { group: number; index: number }[] = [];
|
||||
for (let i = 0; i + 1 < r.length; i += 2) out.push({ group: r[i], index: r[i + 1] });
|
||||
return out;
|
||||
}
|
||||
Reference in new issue
Block a user