[145] clampInside nur noch im Kern (Bindung grip_clamp_inside), TS-Doppelung entfernt; Fassade in src/core

This commit is contained in:
Claude committed 2026-11-09 13:02:30 +00:00
1 parent e7b4f8b2fe
commit cc6de499ba
5 files changed
+30 -27

No files matched your search

+12
View File
@@ -102,6 +102,18 @@ pub fn grip_opening_slide_sheet(sx: f64, sy: f64, ex: f64, ey: f64, bulge: f64,
gd::opening_slide_sheet((sx, sy), (ex, ey), bulge, (ux, uy), position, width, du).map(|(p, d)| vec![p, d]).unwrap_or_default()
}
/// Punkt im Umriss halten (`opening_slide::clamp_inside`, Dach-/Deckenöffnung): `[x, y]`; Ring als
/// flacher Puffer, kaputte Eingabe (NaN, weniger als 3 Ecken) = Punkt unverändert.
#[wasm_bindgen]
pub fn grip_clamp_inside(x: f64, y: f64, ring: &[f64]) -> Vec<f64> {
let r = pts(ring);
if !x.is_finite() || !y.is_finite() || r.len() < 3 || r.iter().any(|p| !p.0.is_finite() || !p.1.is_finite()) {
return vec![x, y];
}
let q = crate::opening_slide::clamp_inside((x, y), &r);
vec![q.0, q.1]
}
/// Bewegpunkt einer Treppe (Zentrum NaN = keines): `[x, y]`.
#[wasm_bindgen]
#[allow(clippy::too_many_arguments)]
+1 -1
View File
@@ -74,7 +74,7 @@ export { drawingVertices, gripPt, openEdges, polylineEdgeGrips, ringEdges } from
export { verticalExtents } from "../geometry/grips";
export type { VerticalExtent } from "../geometry/grips";
export type { GripRequest } from "../geometry/grips";
export { coincidentGripPoints, excavationGripPoints, gripAxisLock, gripEdgeTarget, gripPolar, gripPolarPoint, openingGripPoint, openingSheetSlide, openingTypedPosition, sheetHeightDrag, stairMoveHandle, stairParamPoints, wallGripPoints } from "../geometry/gripDrag";
export { clampInside, coincidentGripPoints, excavationGripPoints, gripAxisLock, gripEdgeTarget, gripPolar, gripPolarPoint, openingGripPoint, openingSheetSlide, openingTypedPosition, sheetHeightDrag, stairMoveHandle, stairParamPoints, wallGripPoints } from "../geometry/gripDrag";
export type { EdgeDrive, GripLocks, SheetHeightKind } from "../geometry/gripDrag";
export { openingPreviewProject, openingPreviewSvgs } from "../plan/openingPreview";
export type { OpeningPreviewSvgs } from "../plan/openingPreview";
+10
View File
@@ -130,6 +130,16 @@ export function openingSheetSlide(
return f.length ? { position: f[0], du: f[1] } : null;
}
/**
* Punkt im Umriss lassen (Dach-/Deckenöffnung): ausserhalb → nächster Randpunkt, 5 cm nach innen gerückt.
* Gerechnet im Kern (`opening_slide::clamp_inside`), derselbe Wert wie beim Verschieben-Befehl.
*/
export function clampInside(pt: Vec2, ring: readonly Vec2[]): Vec2 {
const flat = new Float64Array(ring.length * 2);
ring.forEach((q, i) => { flat[2 * i] = q.x; flat[2 * i + 1] = q.y; });
return v(core().grip_clamp_inside(pt.x, pt.y, flat));
}
/** Bewegpunkt einer Treppe (Mitte des ersten Laufs, Wendeltreppe im Zentrum). */
export function stairMoveHandle(st: Stair): Vec2 {
const c = st.center;
+6 -2
View File
@@ -1,6 +1,7 @@
// [103] Dachfenster bleiben beim Ziehen auf der Dachfläche (`clampInside`).
// [103]/[145] Dachfenster bleiben beim Ziehen auf der Dachfläche; `clampInside` rechnet der Kern
// (`opening_slide::clamp_inside`), dieselbe Klemmung wie beim Verschieben-Befehl.
import { describe, expect, it } from "vitest";
import { clampInside } from "./surfaceOpening";
import { clampInside } from "../core";
const sq = [{ x: 0, y: 0 }, { x: 4, y: 0 }, { x: 4, y: 3 }, { x: 0, y: 3 }];
@@ -14,4 +15,7 @@ describe("clampInside", () => {
expect(q.x).toBeGreaterThan(3.9);
expect(q.y).toBeCloseTo(1.5, 1);
});
it("zu wenige Ecken: unverändert", () => {
expect(clampInside({ x: 9, y: 9 }, sq.slice(0, 2))).toEqual({ x: 9, y: 9 });
});
});
+1 -24
View File
@@ -4,6 +4,7 @@
import type { Project } from "../model/types";
import { documentFor } from "../core/document";
import { clampInside } from "../geometry/gripDrag";
type V3 = [number, number, number];
type P = { x: number; y: number };
@@ -63,27 +64,3 @@ export function surfaceOpeningGripPatch(
const r = Math.round(v * 1000) / 1000;
return index === 1 ? { width: r } : { height: r };
}
/** Punkt im Umriss lassen: ausserhalb → nächster Randpunkt, 5 cm nach innen gerückt (zum Schwerpunkt der Ecken). */
export function clampInside(pt: P, ring: readonly P[]): P {
let inside = false;
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
const a = ring[i], b = ring[j];
if (a.y > pt.y !== b.y > pt.y && pt.x < ((b.x - a.x) * (pt.y - a.y)) / (b.y - a.y) + a.x) inside = !inside;
}
if (inside) return { x: pt.x, y: pt.y };
let best = { x: ring[0].x, y: ring[0].y };
let bestD = Infinity;
for (let i = 0; i < ring.length; i++) {
const a = ring[i], b = ring[(i + 1) % ring.length];
const dx = b.x - a.x, dy = b.y - a.y;
const l2 = dx * dx + dy * dy;
const t = l2 > 0 ? Math.max(0, Math.min(1, ((pt.x - a.x) * dx + (pt.y - a.y) * dy) / l2)) : 0;
const q = { x: a.x + dx * t, y: a.y + dy * t };
const dd = (q.x - pt.x) ** 2 + (q.y - pt.y) ** 2;
if (dd < bestD) { bestD = dd; best = q; }
}
const cx = ring.reduce((s, q) => s + q.x, 0) / ring.length, cy = ring.reduce((s, q) => s + q.y, 0) / ring.length;
const l = Math.hypot(cx - best.x, cy - best.y);
return l > 0.05 ? { x: best.x + ((cx - best.x) / l) * 0.05, y: best.y + ((cy - best.y) / l) * 0.05 } : best;
}