[K4][G10] Merge: Aufräumen (tote TS-/Rust-Doppelspuren), id-Index, Commit ohne Kopie, Punkttyp im Kern; Tests unter Last stabil
CLAUDE.md: Dokument im Kern, Modulkarte nachgeführt. Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
53 files changed
+1293
-1043
No files matched your search
@@ -120,21 +120,6 @@ export function arcThroughPoints(a: Vec2, through: Vec2, b: Vec2): ArcParams | n
|
||||
return toArcParams(core().arc_through_points(a.x, a.y, through.x, through.y, b.x, b.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulge-Wert für den Teilbogen desselben Kreises (center, r) von Winkel `aFrom` zu `aTo`, in der
|
||||
* durch `sweepSign` vorgegebenen Schwenkrichtung (+1 = CCW, −1 = CW), z. B. beim Zuschneiden/
|
||||
* Offsetten eines Bogen-Segments.
|
||||
*/
|
||||
export function bulgeBetweenAngles(
|
||||
center: Vec2,
|
||||
r: number,
|
||||
aFrom: number,
|
||||
aTo: number,
|
||||
sweepSign: 1 | -1,
|
||||
): number {
|
||||
return core().bulge_between_angles(center.x, center.y, r, aFrom, aTo, sweepSign);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kreisbogen durch zwei Endpunkte `a`→`b` mit vorgegebenem Radius `r` (Methode „Start-Ende-
|
||||
* Radius"). `near` (typischerweise der Cursor) wählt die Seite der Sehne; es entsteht immer der
|
||||
|
||||
@@ -32,44 +32,11 @@ export function normalizeOutline(pts: Vec2[]): Vec2[] | null {
|
||||
return isCCW(clean) ? clean : clean.slice().reverse();
|
||||
}
|
||||
|
||||
/** Ob ein Umriss ein gültiges (nicht entartetes) Deckenpolygon bildet. */
|
||||
export function isValidOutline(pts: Vec2[]): boolean {
|
||||
const norm = normalizeOutline(pts);
|
||||
return norm != null && ceilingArea(norm) >= MIN_CEILING_AREA;
|
||||
}
|
||||
|
||||
/** Fläche eines Deckenumrisses in m² (immer positiv). */
|
||||
export function ceilingArea(pts: Vec2[]): number {
|
||||
return Math.abs(signedArea(pts));
|
||||
}
|
||||
|
||||
/** Schwerpunkt (Zentroid) des Umriss-Polygons (für HUD/Beschriftung). */
|
||||
export function outlineCentroid(pts: Vec2[]): Vec2 {
|
||||
const a = signedArea(pts);
|
||||
if (Math.abs(a) < 1e-12) {
|
||||
// Entartet: einfacher Mittelwert der Punkte.
|
||||
let sx = 0,
|
||||
sy = 0;
|
||||
for (const p of pts) {
|
||||
sx += p.x;
|
||||
sy += p.y;
|
||||
}
|
||||
const n = pts.length || 1;
|
||||
return { x: sx / n, y: sy / n };
|
||||
}
|
||||
let cx = 0,
|
||||
cy = 0;
|
||||
for (let i = 0; i < pts.length; i++) {
|
||||
const p = pts[i];
|
||||
const q = pts[(i + 1) % pts.length];
|
||||
const cr = p.x * q.y - q.x * p.y;
|
||||
cx += (p.x + q.x) * cr;
|
||||
cy += (p.y + q.y) * cr;
|
||||
}
|
||||
const f = 1 / (6 * a);
|
||||
return { x: cx * f, y: cy * f };
|
||||
}
|
||||
|
||||
/**
|
||||
* Punkt-in-Polygon-Test (Ray-Casting) für einen geschlossenen Umriss — dient dem
|
||||
* Body-Select einer Decke im Grundriss/3D. Randpunkte gelten als innen genug.
|
||||
|
||||
@@ -28,6 +28,7 @@ export type GripRequest =
|
||||
| { op: "ceilingEdge" | "roomEdge"; id: string; a: number; b: number; delta: P }
|
||||
| { op: "insertPoint"; id: string; seg: number; pt: P }
|
||||
| { op: "deletePoint"; id: string; index: number }
|
||||
| { op: "vertexType"; id: string; index: number; vertexType: "corner" | "arc" | "spline" }
|
||||
| { op: "wallThickness" | "ceilingThickness"; id: string; thickness: number; newId: string; newName: string };
|
||||
|
||||
/** Punkt als Anfrage-Paar. */
|
||||
@@ -112,8 +113,8 @@ export interface VerticalExtent {
|
||||
}
|
||||
|
||||
/**
|
||||
* UK/OK von Wänden und Decken aus dem Kern (`selection_info.rs::vertical_extents`, Regeln wie
|
||||
* `wallVerticalExtent`/`ceilingVerticalExtent`): Geschoss-Bindungen und Deckentypen aus `project`, die
|
||||
* UK/OK von Wänden und Decken aus dem Kern (`selection_info.rs::vertical_extents`, Regeln
|
||||
* `model/helpers.rs::heights`): Geschoss-Bindungen und Deckentypen aus `project`, die
|
||||
* Elemente selbst als ganze Fassung (auch gerade gezogene, noch nicht übernommene — 3D-Griffe).
|
||||
*/
|
||||
export function verticalExtents(
|
||||
|
||||
+4
-34
@@ -1,7 +1,7 @@
|
||||
// Geometrie-Helfer für Öffnungen (Fenster/Türen) — reine Funktionen, die eine
|
||||
// `Opening` relativ zu ihrer Wirts-Wand in konkrete Welt-Geometrie auflösen:
|
||||
// • die Öffnungs-Lücke entlang der Wandachse (from/to in Metern),
|
||||
// • die vertikale Lage (UK/OK der Öffnung, absolut in Metern).
|
||||
// • die Öffnungs-Lücke entlang der Wandachse (from/to in Metern), die Pfosten.
|
||||
// (Die vertikale Lage rechnet der Kern: `model3d.rs`/`plan/section.rs`, UK/OK der Wand: `model/helpers.rs::heights`.)
|
||||
//
|
||||
// Da JEDE Größe aus der aktuellen Wandachse (`wall.start`/`wall.end`) abgeleitet
|
||||
// wird, folgt eine Öffnung ihrer Wand automatisch, sobald die Wand bewegt wird —
|
||||
@@ -9,9 +9,8 @@
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { Opening, Project, Vec2, Wall } from "../model/types";
|
||||
import { along, leftNormal, normalize, sub } from "../model/geometry";
|
||||
import { wallVerticalExtent } from "../model/wall";
|
||||
import type { Opening, Vec2, Wall } from "../model/types";
|
||||
import { along } from "../model/geometry";
|
||||
|
||||
/** Achslänge einer Wand (Meter). */
|
||||
export function wallAxisLength(wall: Wall): number {
|
||||
@@ -34,29 +33,6 @@ export function openingInterval(
|
||||
return { from, to };
|
||||
}
|
||||
|
||||
/**
|
||||
* Vertikale Lage einer Öffnung (absolute Z-Werte in Metern) relativ zur Wand-UK.
|
||||
* Türen sitzen am Boden (sillHeight 0); Fenster ab Brüstung. Die OK wird auf die
|
||||
* Wand-OK geklemmt, damit die Öffnung nie über den Wandkopf hinausragt.
|
||||
*/
|
||||
export function openingVerticalExtent(
|
||||
project: Project,
|
||||
wall: Wall,
|
||||
o: Opening,
|
||||
): { zBottom: number; zTop: number } {
|
||||
const { zBottom, zTop } = wallVerticalExtent(project, wall);
|
||||
const sill = Math.max(0, o.sillHeight);
|
||||
const oBottom = zBottom + sill;
|
||||
const oTop = Math.min(zTop, oBottom + o.height);
|
||||
return { zBottom: oBottom, zTop: oTop };
|
||||
}
|
||||
|
||||
/** Einheits-Laufrichtung (u) und linke Normale (n) der Wandachse. */
|
||||
export function wallAxisFrame(wall: Wall): { u: Vec2; n: Vec2 } {
|
||||
const u = normalize(sub(wall.end, wall.start));
|
||||
return { u, n: leftNormal(u) };
|
||||
}
|
||||
|
||||
/** Die beiden Pfosten-Punkte (auf der Achse) einer Öffnung im Grundriss. */
|
||||
export function openingJambs(
|
||||
wall: Wall,
|
||||
@@ -70,9 +46,3 @@ export function openingJambs(
|
||||
};
|
||||
}
|
||||
|
||||
/** Mittelpunkt einer Öffnung im Grundriss (Achse) — für HUD/Auswahl-Anker. */
|
||||
export function openingCenter(wall: Wall, o: Opening): Vec2 | null {
|
||||
const iv = openingInterval(wall, o);
|
||||
if (!iv) return null;
|
||||
return along(wall.start, wall.end, (iv.from + iv.to) / 2);
|
||||
}
|
||||
@@ -1,59 +1,61 @@
|
||||
// Punkttypen einer Polylinie: Rechnung im Kern (`polyline_vertex.rs`, eigene Rust-Tests); hier die
|
||||
// Fassade für das Kontextmenü und die Store-Aktion `setPolylineVertexType` (Griff-Änderung im Kern).
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { bulgeArc, bulgeArcPoints } from "./bulge";
|
||||
import { canSetVertexType, vertexTypeOf, withVertexType } from "./polylineVertexType";
|
||||
import { canSetVertexType, vertexTypeOf } from "./polylineVertexType";
|
||||
import { getState } from "../state/appStore";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Drawing2D, Vec2 } from "../model/types";
|
||||
|
||||
const g = { pts: [{ x: 0, y: 0 }, { x: 2, y: 1 }, { x: 4, y: 0 }, { x: 6, y: 1 }], closed: false };
|
||||
|
||||
/** Setzt den Punkttyp über den Store und liefert die Bulges (fehlend = alle gerade). */
|
||||
function setType(pts: Vec2[], closed: boolean, i: number, type: "corner" | "arc" | "spline", bulge?: number[]): number[] | undefined {
|
||||
const d = { id: "pl", levelId: sampleProject.drawingLevels[0].id, categoryCode: "01", geom: { shape: "polyline", pts, closed, ...(bulge ? { bulge } : {}) } };
|
||||
getState().loadProject({ ...structuredClone(sampleProject), drawings2d: [d as Drawing2D] });
|
||||
getState().setPolylineVertexType("pl", i, type);
|
||||
const geom = getState().project.drawings2d[0].geom;
|
||||
return geom.shape === "polyline" ? geom.bulge : undefined;
|
||||
}
|
||||
|
||||
describe("Punkttypen einer Polylinie", () => {
|
||||
it("Eckpunkt setzt beide Nachbarsegmente gerade", () => {
|
||||
const b = withVertexType({ ...g, bulge: [0.3, -0.2, 0.1] }, 1, "corner");
|
||||
expect(b).toEqual([0, 0, 0.1]);
|
||||
expect(setType(g.pts, false, 1, "corner", [0.3, -0.2, 0.1])).toEqual([0, 0, 0.1]);
|
||||
expect(setType(g.pts, false, 1, "corner", [0.3, -0.2, 0])).toBeUndefined();
|
||||
});
|
||||
|
||||
it("Bogenpunkt: beide Segmente liegen auf EINEM Kreis durch die drei Punkte", () => {
|
||||
const b = withVertexType(g, 1, "arc");
|
||||
const b = setType(g.pts, false, 1, "arc")!;
|
||||
const a1 = bulgeArc(g.pts[0], g.pts[1], b[0])!;
|
||||
const a2 = bulgeArc(g.pts[1], g.pts[2], b[1])!;
|
||||
expect(a1).not.toBeNull();
|
||||
expect(Math.hypot(a1.center.x - a2.center.x, a1.center.y - a2.center.y)).toBeLessThan(1e-6);
|
||||
expect(a1.r).toBeCloseTo(a2.r, 6);
|
||||
expect(vertexTypeOf({ ...g, bulge: b }, 1)).toBe("arc");
|
||||
// Die Bögen bauchen NACH OBEN aus (Punkt 1 liegt oben) — kein Zickzack über den Kreis
|
||||
const mid1 = bulgeArcPoints(g.pts[0], g.pts[1], b[0]);
|
||||
const apex = mid1[mid1.length / 2 | 0];
|
||||
expect(apex.y).toBeGreaterThan(0.5);
|
||||
expect(mid1[(mid1.length / 2) | 0].y).toBeGreaterThan(0.5);
|
||||
});
|
||||
|
||||
it("Splinepunkt: Tangenten beider Segmente im Punkt stimmen überein", () => {
|
||||
const g = { pts: [{ x: 0, y: 0 }, { x: 2, y: 1 }, { x: 5, y: 0.2 }], closed: false };
|
||||
const b = withVertexType(g, 1, "spline");
|
||||
// exakte Tangenten aus den Bögen (senkrecht zum Radius, Richtung nach Umlaufsinn)
|
||||
const tan = (a: { x: number; y: number }, c: { x: number; y: number }, bb: number, atEnd: boolean) => {
|
||||
const arc = bulgeArc(a, c, bb)!;
|
||||
const ang = atEnd ? arc.a0 + arc.sweep : arc.a0;
|
||||
const sg = Math.sign(arc.sweep);
|
||||
return Math.atan2(Math.cos(ang) * sg, -Math.sin(ang) * sg);
|
||||
};
|
||||
const t1 = tan(g.pts[0], g.pts[1], b[0], true);
|
||||
const t2 = tan(g.pts[1], g.pts[2], b[1], false);
|
||||
expect(Math.abs(t1 - t2)).toBeLessThan(1e-6);
|
||||
// Tangente = Richtung Vorgänger→Nachfolger
|
||||
expect(Math.abs(t2 - Math.atan2(0.2, 5))).toBeLessThan(1e-6);
|
||||
expect(vertexTypeOf({ ...g, bulge: b }, 1)).toBe("spline");
|
||||
});
|
||||
|
||||
it("offene Enden: Bogen/Spline nicht möglich, Ecke schon", () => {
|
||||
it("Splinepunkt: Typ wird erkannt, offene Enden lassen nur die Ecke zu", () => {
|
||||
const pts = [{ x: 0, y: 0 }, { x: 2, y: 1 }, { x: 5, y: 0.2 }];
|
||||
expect(vertexTypeOf({ pts, closed: false, bulge: setType(pts, false, 1, "spline") }, 1)).toBe("spline");
|
||||
expect(vertexTypeOf(g, 1)).toBe("corner");
|
||||
expect(canSetVertexType(g, 0, "arc")).toBe(false);
|
||||
expect(canSetVertexType(g, 3, "spline")).toBe(false);
|
||||
expect(canSetVertexType(g, 0, "corner")).toBe(true);
|
||||
expect(canSetVertexType(g, 1, "spline")).toBe(true);
|
||||
});
|
||||
|
||||
it("geschlossene Polylinie: erster Punkt hat beide Nachbarn", () => {
|
||||
const sq = { pts: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 1 }, { x: 0, y: 1 }], closed: true };
|
||||
const b = withVertexType(sq, 0, "arc");
|
||||
it("geschlossene Polylinie: erster Punkt hat beide Nachbarn; gesperrt ändert nichts", () => {
|
||||
const sq = [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 1 }, { x: 0, y: 1 }];
|
||||
const b = setType(sq, true, 0, "arc")!;
|
||||
expect(b.length).toBe(4);
|
||||
expect(b[3]).not.toBe(0);
|
||||
expect(b[0]).not.toBe(0);
|
||||
expect(b[1]).toBe(0);
|
||||
const depth = getState().undoDepth;
|
||||
getState().updateDrawing2D("pl", { locked: true });
|
||||
getState().setPolylineVertexType("pl", 0, "corner");
|
||||
expect(getState().undoDepth).toBe(depth + 1);
|
||||
});
|
||||
});
|
||||
@@ -1,19 +1,11 @@
|
||||
// Punkttypen einer Polylinie (ArchiCAD/Vectorworks-artig): Eckpunkt, Bogenpunkt,
|
||||
// Splinepunkt. Rein als Umrechnung der Segment-Bögen (`bulge`) der beiden am Punkt
|
||||
// anliegenden Segmente — alle Renderer/Exporte verstehen Bulges bereits, es gibt
|
||||
// also kein neues Geometrie-Feld.
|
||||
//
|
||||
// • Eckpunkt: beide Segmente gerade (bulge 0).
|
||||
// • Bogenpunkt: EIN Kreisbogen durch Vorgänger, Punkt und Nachfolger.
|
||||
// • Splinepunkt: tangential glatter Übergang — die Tangente im Punkt ist parallel
|
||||
// zur Verbindung Vorgänger→Nachfolger (wie bei einer Catmull-Rom-Kurve), beide
|
||||
// Segmente werden zu Bögen, die diese Tangente teilen.
|
||||
//
|
||||
// Die Bögen werden über ihren SCHEITELPUNKT bestimmt und mit `bulgeFromSagittaPoint`
|
||||
// in einen Bulge übersetzt — so bleibt die Vorzeichen-Konvention an EINER Stelle.
|
||||
// Punkttypen einer Polylinie (ArchiCAD/Vectorworks-artig): Eckpunkt, Bogenpunkt, Splinepunkt — als
|
||||
// Umrechnung der Segment-Bögen (`bulge`) der beiden am Punkt anliegenden Segmente. Gerechnet im
|
||||
// Rust-Kern (`src-tauri/core/src/polyline_vertex.rs`): das Setzen als Griff-Änderung auf dem Dokument
|
||||
// (Store `setPolylineVertexType`, Anfrage `vertexType`), die Abfrage für das Kontextmenü hier über die
|
||||
// Bindung `polyline_vertex_info`.
|
||||
|
||||
import type { Vec2 } from "../model/types";
|
||||
import { bulgeArc, bulgeFromSagittaPoint } from "./bulge";
|
||||
import { core } from "../engine/coreWasm";
|
||||
|
||||
export type PolylineVertexType = "corner" | "arc" | "spline";
|
||||
|
||||
@@ -23,160 +15,24 @@ interface PolylineLike {
|
||||
bulge?: number[];
|
||||
}
|
||||
|
||||
const EPS = 1e-9;
|
||||
const TYPES: PolylineVertexType[] = ["corner", "arc", "spline"];
|
||||
|
||||
/** Indizes des ein- und ausgehenden Segments von Punkt `i` (null = keins). */
|
||||
function adjacentSegments(n: number, closed: boolean, i: number): { inSeg: number | null; outSeg: number | null } {
|
||||
const inSeg = i > 0 ? i - 1 : closed ? n - 1 : null;
|
||||
const outSeg = i < n - 1 ? i : closed ? n - 1 : null;
|
||||
return { inSeg, outSeg };
|
||||
}
|
||||
|
||||
/** Nachbarpunkte von `i` (null an offenen Enden). */
|
||||
function neighbors(g: PolylineLike, i: number): { prev: Vec2 | null; next: Vec2 | null } {
|
||||
const n = g.pts.length;
|
||||
const prev = i > 0 ? g.pts[i - 1] : g.closed ? g.pts[n - 1] : null;
|
||||
const next = i < n - 1 ? g.pts[i + 1] : g.closed ? g.pts[0] : null;
|
||||
return { prev, next };
|
||||
}
|
||||
|
||||
const cross = (a: Vec2, b: Vec2) => a.x * b.y - a.y * b.x;
|
||||
const sub = (a: Vec2, b: Vec2): Vec2 => ({ x: a.x - b.x, y: a.y - b.y });
|
||||
|
||||
/** Umkreismittelpunkt von a,b,c (null bei kollinearen Punkten). */
|
||||
function circumcenter(a: Vec2, b: Vec2, c: Vec2): Vec2 | null {
|
||||
const d = 2 * (a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y));
|
||||
if (Math.abs(d) < EPS) return null;
|
||||
const a2 = a.x * a.x + a.y * a.y, b2 = b.x * b.x + b.y * b.y, c2 = c.x * c.x + c.y * c.y;
|
||||
return {
|
||||
x: (a2 * (b.y - c.y) + b2 * (c.y - a.y) + c2 * (a.y - b.y)) / d,
|
||||
y: (a2 * (c.x - b.x) + b2 * (a.x - c.x) + c2 * (b.x - a.x)) / d,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulge des Kreisbogens a→b auf dem Kreis um `c`, und zwar des Bogens, der NICHT
|
||||
* durch `other` läuft (Scheitel auf der anderen Seite der Sehne als `other`).
|
||||
*/
|
||||
function bulgeOnCircle(a: Vec2, b: Vec2, c: Vec2, other: Vec2): number {
|
||||
const r = Math.hypot(a.x - c.x, a.y - c.y);
|
||||
const mid = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
||||
let u = sub(mid, c);
|
||||
let len = Math.hypot(u.x, u.y);
|
||||
if (len < EPS) {
|
||||
const d = sub(b, a);
|
||||
u = { x: -d.y, y: d.x };
|
||||
len = Math.hypot(u.x, u.y);
|
||||
/** `[typ, ecke, bogen, spline]` des Kerns (typ −1 = gemischt/kein Punkt; danach setzbar 1/0). */
|
||||
function info(g: PolylineLike, i: number): Float64Array {
|
||||
const pts = new Float64Array(g.pts.length * 2);
|
||||
for (let k = 0; k < g.pts.length; k++) {
|
||||
pts[2 * k] = g.pts[k].x;
|
||||
pts[2 * k + 1] = g.pts[k].y;
|
||||
}
|
||||
u = { x: u.x / len, y: u.y / len };
|
||||
const side = (p: Vec2) => Math.sign(cross(sub(b, a), sub(p, a)));
|
||||
const cand1 = { x: c.x + u.x * r, y: c.y + u.y * r };
|
||||
const cand2 = { x: c.x - u.x * r, y: c.y - u.y * r };
|
||||
const apex = side(cand1) !== side(other) ? cand1 : cand2;
|
||||
return bulgeFromSagittaPoint(a, b, apex);
|
||||
}
|
||||
|
||||
/** Tangente (Fahrtrichtung a→b) des Bulge-Bogens am Anfang bzw. Ende. */
|
||||
function arcTangent(a: Vec2, b: Vec2, bulge: number, atEnd: boolean): Vec2 {
|
||||
const arc = bulgeArc(a, b, bulge);
|
||||
if (!arc) {
|
||||
const d = sub(b, a);
|
||||
const l = Math.hypot(d.x, d.y) || 1;
|
||||
return { x: d.x / l, y: d.y / l };
|
||||
}
|
||||
const ang = atEnd ? arc.a0 + arc.sweep : arc.a0;
|
||||
const s = Math.sign(arc.sweep) || 1;
|
||||
return { x: -Math.sin(ang) * s, y: Math.cos(ang) * s };
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulge des Bogens a→b mit gegebener Tangente `t` am Ende (atEnd) bzw. Anfang.
|
||||
* Betrag aus dem Winkel Sehne↔Tangente, Vorzeichen NUMERISCH gewählt (die
|
||||
* Variante, deren tatsächliche Tangente zu `t` passt).
|
||||
*/
|
||||
function bulgeWithTangent(a: Vec2, b: Vec2, t: Vec2, atEnd: boolean): number {
|
||||
const c = sub(b, a);
|
||||
const ang = Math.abs(Math.atan2(cross(c, t), c.x * t.x + c.y * t.y));
|
||||
const mag = Math.abs(bulgeFromApexAngle(a, b, ang));
|
||||
if (mag < 1e-9) return 0;
|
||||
const dot = (v: Vec2) => v.x * t.x + v.y * t.y;
|
||||
return dot(arcTangent(a, b, mag, atEnd)) >= dot(arcTangent(a, b, -mag, atEnd)) ? mag : -mag;
|
||||
}
|
||||
|
||||
const bulgeWithEndTangent = (a: Vec2, b: Vec2, t: Vec2) => bulgeWithTangent(a, b, t, true);
|
||||
const bulgeWithStartTangent = (a: Vec2, b: Vec2, t: Vec2) => bulgeWithTangent(a, b, t, false);
|
||||
|
||||
/**
|
||||
* Bogen über der Sehne a→b mit halbem Öffnungswinkel |half| (Sehne↔Tangente);
|
||||
* Vorzeichen: >0 Scheitel links der Sehne, <0 rechts. Über den Scheitelpunkt in
|
||||
* einen Bulge übersetzt.
|
||||
*/
|
||||
function bulgeFromApexAngle(a: Vec2, b: Vec2, half: number): number {
|
||||
if (Math.abs(half) < 1e-6) return 0;
|
||||
// Begrenzen: knapp unter einem Halbkreis je Segment (sonst kippt der Bogen).
|
||||
const h2 = Math.max(-Math.PI / 2 + 0.01, Math.min(Math.PI / 2 - 0.01, half));
|
||||
const d = sub(b, a);
|
||||
const chord = Math.hypot(d.x, d.y);
|
||||
if (chord < EPS) return 0;
|
||||
const left = { x: -d.y / chord, y: d.x / chord };
|
||||
const s = (chord / 2) * Math.tan(h2 / 2); // Pfeilhöhe
|
||||
const apex = { x: (a.x + b.x) / 2 + left.x * s, y: (a.y + b.y) / 2 + left.y * s };
|
||||
return bulgeFromSagittaPoint(a, b, apex);
|
||||
return core().polyline_vertex_info(pts, Float64Array.from(g.bulge ?? []), !!g.closed, i);
|
||||
}
|
||||
|
||||
/** Ist Punkttyp `type` am Punkt `i` möglich? (Bogen/Spline brauchen beide Nachbarn.) */
|
||||
export function canSetVertexType(g: PolylineLike, i: number, type: PolylineVertexType): boolean {
|
||||
if (i < 0 || i >= g.pts.length) return false;
|
||||
if (type === "corner") return true;
|
||||
const { prev, next } = neighbors(g, i);
|
||||
return !!prev && !!next;
|
||||
return info(g, i)[1 + TYPES.indexOf(type)] === 1;
|
||||
}
|
||||
|
||||
/** Aktueller Typ (Heuristik): beide Nachbarsegmente gerade → Eckpunkt, sonst null (gemischt). */
|
||||
export function vertexTypeOf(g: PolylineLike, i: number): PolylineVertexType | null {
|
||||
const { inSeg, outSeg } = adjacentSegments(g.pts.length, g.closed, i);
|
||||
const b = (k: number | null) => (k === null ? 0 : g.bulge?.[k] ?? 0);
|
||||
if (Math.abs(b(inSeg)) < 1e-9 && Math.abs(b(outSeg)) < 1e-9) return "corner";
|
||||
const { prev, next } = neighbors(g, i);
|
||||
if (!prev || !next || inSeg === null || outSeg === null) return null;
|
||||
const a1 = bulgeArc(prev, g.pts[i], b(inSeg));
|
||||
const a2 = bulgeArc(g.pts[i], next, b(outSeg));
|
||||
if (a1 && a2 && Math.hypot(a1.center.x - a2.center.x, a1.center.y - a2.center.y) < 1e-6 * (1 + a1.r)) return "arc";
|
||||
return "spline";
|
||||
}
|
||||
|
||||
/** Neue Bulge-Liste mit Punkttyp `type` an Punkt `i` (Eingabe bleibt unverändert). */
|
||||
export function withVertexType(g: PolylineLike, i: number, type: PolylineVertexType): number[] {
|
||||
const n = g.pts.length;
|
||||
const segCount = g.closed ? n : n - 1;
|
||||
const bulge = Array.from({ length: segCount }, (_, k) => g.bulge?.[k] ?? 0);
|
||||
if (!canSetVertexType(g, i, type)) return bulge;
|
||||
const { inSeg, outSeg } = adjacentSegments(n, g.closed, i);
|
||||
const q = g.pts[i];
|
||||
const { prev, next } = neighbors(g, i);
|
||||
if (type === "corner") {
|
||||
if (inSeg !== null) bulge[inSeg] = 0;
|
||||
if (outSeg !== null) bulge[outSeg] = 0;
|
||||
return bulge;
|
||||
}
|
||||
const p = prev!, r = next!;
|
||||
if (type === "arc") {
|
||||
const c = circumcenter(p, q, r);
|
||||
if (!c) {
|
||||
bulge[inSeg!] = 0;
|
||||
bulge[outSeg!] = 0;
|
||||
return bulge;
|
||||
}
|
||||
bulge[inSeg!] = bulgeOnCircle(p, q, c, r);
|
||||
bulge[outSeg!] = bulgeOnCircle(q, r, c, p);
|
||||
return bulge;
|
||||
}
|
||||
// spline: Tangente parallel zu prev→next
|
||||
const t = sub(r, p);
|
||||
const tl = Math.hypot(t.x, t.y);
|
||||
if (tl < EPS) return bulge;
|
||||
const tu = { x: t.x / tl, y: t.y / tl };
|
||||
bulge[inSeg!] = bulgeWithEndTangent(p, q, tu);
|
||||
bulge[outSeg!] = bulgeWithStartTangent(q, r, tu);
|
||||
return bulge;
|
||||
return TYPES[info(g, i)[0]] ?? null;
|
||||
}
|
||||
@@ -19,8 +19,6 @@
|
||||
import type { Stair, Vec2 } from "../model/types";
|
||||
import { core } from "../engine/coreWasm";
|
||||
|
||||
/** SIA-nahe Schrittregel: gute Steigungshöhe ≈ 0.17 m, Auftritt ≈ 0.29 m. */
|
||||
export const IDEAL_RISER = 0.17;
|
||||
export const IDEAL_TREAD = 0.29;
|
||||
export const MIN_STEPS = 2;
|
||||
|
||||
|
||||
Reference in new issue
Block a user