[K4] Merge: Griffe und Objekt-Info im Kern (grips.rs, selection_info.rs), 3D-Griffhöhen
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
46 files changed
+3352
-2427
No files matched your search
@@ -43,30 +43,6 @@ export function ceilingArea(pts: Vec2[]): number {
|
||||
return Math.abs(signedArea(pts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Achsparallele Bounding-Box eines Umrisses (Modell-Meter). Leerer/entarteter
|
||||
* Umriss → Null-Box.
|
||||
*/
|
||||
export function outlineBBox(pts: Vec2[]): {
|
||||
minX: number;
|
||||
minY: number;
|
||||
maxX: number;
|
||||
maxY: number;
|
||||
} {
|
||||
let minX = Infinity,
|
||||
minY = Infinity,
|
||||
maxX = -Infinity,
|
||||
maxY = -Infinity;
|
||||
for (const p of pts) {
|
||||
minX = Math.min(minX, p.x);
|
||||
minY = Math.min(minY, p.y);
|
||||
maxX = Math.max(maxX, p.x);
|
||||
maxY = Math.max(maxY, p.y);
|
||||
}
|
||||
if (!isFinite(minX)) return { minX: 0, minY: 0, maxX: 0, maxY: 0 };
|
||||
return { minX, minY, maxX, maxY };
|
||||
}
|
||||
|
||||
/** Schwerpunkt (Zentroid) des Umriss-Polygons (für HUD/Beschriftung). */
|
||||
export function outlineCentroid(pts: Vec2[]): Vec2 {
|
||||
const a = signedArea(pts);
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { drawingVertices, openEdges, polylineEdgeGrips, ringEdges } from "./grips";
|
||||
import { documentFor } from "../core/document";
|
||||
import type { Drawing2D, Project } from "../model/types";
|
||||
|
||||
// ── Bemassung: Masszahl-Griffe (Lage und Einrasten rechnet der Kern, `grips.rs`) ──
|
||||
|
||||
const dim = (pts: { x: number; y: number }[], offset: number, textOffsetsMm?: { along: number; perp: number }[]): Drawing2D =>
|
||||
({ id: "m", type: "drawing2d", levelId: "f", categoryCode: "1", geom: { shape: "dimension", pts, offset, textHeightMm: 4, ...(textOffsetsMm ? { textOffsetsMm } : {}) } }) as Drawing2D;
|
||||
const A = { x: 0, y: 0 };
|
||||
const B = { x: 4, y: 0 };
|
||||
/** Schrifthöhe 4 mm bei 1:50 in Modell-Metern. */
|
||||
const H = 0.2;
|
||||
|
||||
describe("Bemassung: Griffe der Masszahl", () => {
|
||||
it("Standardlage: mittig über der Masslinie (Offset eingerechnet), Reihenfolge Punkte · Masslinie · Zahl", () => {
|
||||
const v = drawingVertices(dim([A, B], 1), 50);
|
||||
expect(v).toHaveLength(4);
|
||||
expect(v[2]).toEqual({ x: 2, y: 1 });
|
||||
expect(v[3].x).toBeCloseTo(2, 9);
|
||||
expect(v[3].y).toBeCloseTo(1 + H * 0.6, 9);
|
||||
});
|
||||
|
||||
it("Leserichtung nie kopfüber — auch bei rückwärts laufender Kette", () => {
|
||||
const fwd = drawingVertices(dim([A, B], 0), 50)[3];
|
||||
const back = drawingVertices(dim([B, A], 0), 50)[3];
|
||||
expect(back.x).toBeCloseTo(fwd.x, 9);
|
||||
expect(back.y).toBeCloseTo(fwd.y, 9);
|
||||
});
|
||||
|
||||
it("Versatz (Papier-mm) wirkt entlang der Leserichtung und quer dazu", () => {
|
||||
const base = drawingVertices(dim([A, B], 0), 50)[3];
|
||||
// 20 mm / 40 mm bei 1:50 = 1 m / 2 m.
|
||||
const p = drawingVertices(dim([A, B], 0, [{ along: 20, perp: 40 }]), 50)[3];
|
||||
expect(p.x).toBeCloseTo(base.x + 1, 9);
|
||||
expect(p.y).toBeCloseTo(base.y + 2, 9);
|
||||
});
|
||||
|
||||
const drag = (d: Drawing2D, pt: { x: number; y: number }) => {
|
||||
const p = { drawings2d: [d], walls: [] } as unknown as Project;
|
||||
const res = documentFor(p).gripOps({ op: "moveGrip", drawingId: "m", wallId: null, index: d.geom.shape === "dimension" ? d.geom.pts.length + 1 : 0, pt: [pt.x, pt.y], scale: 50 });
|
||||
const e = res.ops[0] as unknown as { entity: Drawing2D };
|
||||
return (e.entity.geom as { textOffsetsMm: { along: number; perp: number }[] }).textOffsetsMm[0];
|
||||
};
|
||||
|
||||
it("nahe der Standardlage rastet BEIDES auf 0 ein", () => {
|
||||
const base = drawingVertices(dim([A, B], 0), 50)[3];
|
||||
expect(drag(dim([A, B], 0), { x: base.x + H * 0.2, y: base.y - H * 0.2 })).toEqual({ along: 0, perp: 0 });
|
||||
});
|
||||
|
||||
it("die Achsen rasten UNABHÄNGIG ein (seitlich verschoben, Höhe exakt Standard)", () => {
|
||||
const base = drawingVertices(dim([A, B], 0), 50)[3];
|
||||
const o = drag(dim([A, B], 0), { x: base.x + 1.5, y: base.y + H * 0.1 });
|
||||
expect(o.along).toBeCloseTo(30, 9);
|
||||
expect(o.perp).toBe(0);
|
||||
});
|
||||
|
||||
it("ausserhalb des Fangbereichs bleibt der gezogene Wert erhalten", () => {
|
||||
const base = drawingVertices(dim([A, B], 0), 50)[3];
|
||||
const o = drag(dim([A, B], 0), { x: base.x + 0.8, y: base.y + 0.6 });
|
||||
expect(o.along).toBeCloseTo(16, 9);
|
||||
expect(o.perp).toBeCloseTo(12, 9);
|
||||
});
|
||||
|
||||
it("Rundreise: gezogene Position → Versatz → Griff liegt wieder am Punkt", () => {
|
||||
const pt = { x: 3.1, y: 1.4 };
|
||||
const o = drag(dim([A, B], 0.5), pt);
|
||||
const back = drawingVertices(dim([A, B], 0.5, [o]), 50)[3];
|
||||
expect(back.x).toBeCloseTo(pt.x, 9);
|
||||
expect(back.y).toBeCloseTo(pt.y, 9);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Kanten-Griffe von Ringen und Ketten", () => {
|
||||
it("Ring: Normalen nach aussen, auch die Schlusskante; Kette: frei, ohne Schlusskante", () => {
|
||||
const tri = [{ x: 0, y: 0 }, { x: 4, y: 0 }, { x: 0, y: 3 }];
|
||||
const r = ringEdges(tri, {});
|
||||
expect(r.map((e) => [e.aIndex, e.bIndex])).toEqual([[0, 1], [1, 2], [2, 0]]);
|
||||
expect(r[0].normal.x).toBeCloseTo(0, 12);
|
||||
expect(r[0].normal.y).toBe(-1);
|
||||
expect(r[2].normal.x).toBeCloseTo(-1, 12);
|
||||
const o = openEdges(tri, { wallId: "w" });
|
||||
expect(o.map((e) => [e.aIndex, e.bIndex, e.free, e.owner?.wallId])).toEqual([[0, 1, true, "w"], [1, 2, true, "w"]]);
|
||||
expect(ringEdges(tri.slice(0, 2), {})).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
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,128 @@
|
||||
// Griff-Geometrie der Bauteile ([K4] S3): dünne Fassade über den Rust-Kern (`src-tauri/core/src/grips.rs`,
|
||||
// Bindungen `web/grips.rs`). Die Griff-Änderungen selbst (Eckpunkt/Kante ziehen, verschieben, Grösse,
|
||||
// Decke/Dach/Treppe/Raum, Polylinien-Punkte, Dicken) rechnet der Kern auf dem Dokument und wendet sie
|
||||
// gleich an (`ProjectDocument.commitGrip`, Anfrage {@link GripRequest}); hier stehen die Griff-Listen
|
||||
// für die Anzeige (`drawingVertices`, Kanten-Griffe).
|
||||
//
|
||||
// Bewusst TS: die Rahmen-Ecken einer Textspalte (`textFrameCorners` braucht die Schrift-Metrik der
|
||||
// Hülle) — der Kern meldet dafür nur „Textspalte".
|
||||
|
||||
import type { Ceiling, Drawing2D, Drawing2DGeom, EdgeGrip, Project, Vec2, Wall } from "../model/types";
|
||||
import { documentFor } from "../core/document";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { toMarkedJson } from "../core/ops";
|
||||
import { DEFAULT_SCALE_DENOMINATOR } from "../model/dimension";
|
||||
import { textFrameCorners } from "../text/textFrame";
|
||||
|
||||
/** Punkt als `[x, y]` (Anfragen an den Kern). */
|
||||
type P = [number, number];
|
||||
|
||||
/** Eine Griff-Änderung für den Kern (`grips.rs::run`); Zahlen dürfen NaN/±∞ sein (Marken). */
|
||||
export type GripRequest =
|
||||
| { op: "moveGrip"; drawingId: string | null; wallId: string | null; index: number; pt: P; scale: number }
|
||||
| { op: "moveBy"; drawingId: string | null; wallId: string | null; delta: P }
|
||||
| { op: "moveEdge"; drawingId: string | null; wallId: string | null; a: number; b: number; delta: P }
|
||||
| { op: "resize"; kind: string; id: string; w: number; h: number; fx: number; fy: number }
|
||||
| { op: "ceilingGrip" | "roomGrip" | "roofGrip"; id: string; index: number; pt: P }
|
||||
| { op: "ceilingBy" | "roofBy" | "stairBy" | "roomBy" | "roomStamp"; id: string; delta: P }
|
||||
| { 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: "wallThickness" | "ceilingThickness"; id: string; thickness: number; newId: string; newName: string };
|
||||
|
||||
/** Punkt als Anfrage-Paar. */
|
||||
export const gripPt = (p: Vec2): P => [p.x, p.y];
|
||||
|
||||
/**
|
||||
* Editier-Griffe (Eckpunkte) eines 2D-Zeichenelements in Modell-Metern — dieselbe Reihenfolge, in der
|
||||
* der Kern einen Griff-Index auflöst (`moveGrip`). line/polyline/rect: Eckpunkte (Polylinie zusätzlich je
|
||||
* Segment ein Bogen-Mitten-Griff); Kreis Ost/Nord; Bogen Start/Ende/Mitte; Ellipse je Halbachse;
|
||||
* Bemassung Kettenpunkte · Masslinie · je Segment die Masszahl (`scaleDenominator`: Papier-Massstab, die
|
||||
* Masszahl-Lage hängt an der Schrifthöhe in Papier-mm); Text Anker · Knicke · Spitze, Pfadpunkte oder
|
||||
* die vier Rahmen-Ecken einer Textspalte.
|
||||
*/
|
||||
export function drawingVertices(d: Drawing2D, scaleDenominator: number = DEFAULT_SCALE_DENOMINATOR): Vec2[] {
|
||||
const g = d.geom;
|
||||
if (g.shape === "polyline") {
|
||||
// Flach (Kataster-Umrisse mit tausenden Punkten): ein fehlender/null-Bogen ist gerade.
|
||||
const f = core().grip_vertices_polyline(flat(g.pts), Float64Array.from(g.bulge ?? []), !!g.closed);
|
||||
const out: Vec2[] = new Array(f.length >> 1);
|
||||
for (let i = 0; i < out.length; i++) out[i] = { x: f[2 * i], y: f[2 * i + 1] };
|
||||
return out;
|
||||
}
|
||||
// NaN/±∞ als Marken (JSON hätte null daraus gemacht, das rechnet wie 0).
|
||||
const f = core().grip_vertices(toMarkedJson(g), scaleDenominator);
|
||||
if (f[0] === -1 && g.shape === "text") {
|
||||
return textFrameCorners({ at: g.at, text: g.text, heightM: g.height, angle: g.angle, marks: g.marks, doc: g.doc, wrapWidth: g.width });
|
||||
}
|
||||
const n = f[0] ?? 0;
|
||||
const out: Vec2[] = new Array(n);
|
||||
for (let i = 0; i < n; i++) out[i] = { x: f[1 + 2 * i], y: f[2 + 2 * i] };
|
||||
return out;
|
||||
}
|
||||
|
||||
type Owner = { drawingId?: string; wallId?: string };
|
||||
|
||||
function flat(verts: readonly Vec2[]): Float64Array {
|
||||
const f = new Float64Array(verts.length * 2);
|
||||
for (let i = 0; i < verts.length; i++) {
|
||||
f[2 * i] = verts[i].x;
|
||||
f[2 * i + 1] = verts[i].y;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
function edges(verts: readonly Vec2[], closed: boolean, bulge: readonly number[] | null, owner: Owner): EdgeGrip[] {
|
||||
const f = core().edge_grips(flat(verts), closed, Float64Array.from(bulge ?? []), bulge !== null);
|
||||
const out: EdgeGrip[] = [];
|
||||
for (let i = 0; i + 5 < f.length; i += 6) {
|
||||
const e: EdgeGrip = { mid: { x: f[i + 2], y: f[i + 3] }, normal: { x: f[i + 4], y: f[i + 5] }, aIndex: f[i], bIndex: f[i + 1] };
|
||||
if (!closed) e.free = true;
|
||||
e.owner = owner;
|
||||
out.push(e);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Geschlossener Ring → Kanten-Griffe mit Aussennormale (vom Eckpunkt-Mittel weg), inkl. Schlusskante. */
|
||||
export function ringEdges(verts: readonly Vec2[], owner: Owner): EdgeGrip[] {
|
||||
return edges(verts, true, null, owner);
|
||||
}
|
||||
|
||||
/**
|
||||
* Offene Kette (Linie/offene Polylinie) → ein Griff je Segment, OHNE Schlusskante. `normal` dient nur
|
||||
* der Darstellung (linke Normale der Kante); die Bewegung ist frei (`free: true`).
|
||||
*/
|
||||
export function openEdges(verts: readonly Vec2[], owner: Owner): EdgeGrip[] {
|
||||
return edges(verts, false, null, owner);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kanten-Griffe einer Polylinie: nur über die Eckpunkte und nur an geraden Segmenten — ein Bogen hat
|
||||
* seinen Bogen-Mitten-Griff (`drawingVertices`), die Sehnen-Mitte läge neben der Linie.
|
||||
*/
|
||||
export function polylineEdgeGrips(g: Extract<Drawing2DGeom, { shape: "polyline" }>, owner: Owner): EdgeGrip[] {
|
||||
return edges(g.pts, !!g.closed, g.bulge ?? [], owner);
|
||||
}
|
||||
|
||||
/** Unter-/Oberkante (absolutes Z, Meter) eines Bauteils. */
|
||||
export interface VerticalExtent {
|
||||
zBottom: number;
|
||||
zTop: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Elemente selbst als ganze Fassung (auch gerade gezogene, noch nicht übernommene — 3D-Griffe).
|
||||
*/
|
||||
export function verticalExtents(
|
||||
project: Project,
|
||||
walls: readonly Wall[],
|
||||
ceilings: readonly Ceiling[] = [],
|
||||
): { walls: VerticalExtent[]; ceilings: VerticalExtent[] } {
|
||||
if (walls.length === 0 && ceilings.length === 0) return { walls: [], ceilings: [] };
|
||||
const f = documentFor(project).queryRootMarked<number[]>("verticalExtents", toMarkedJson({ walls, ceilings }));
|
||||
const at = (i: number): VerticalExtent => ({ zBottom: f[2 * i], zTop: f[2 * i + 1] });
|
||||
return { walls: walls.map((_, i) => at(i)), ceilings: ceilings.map((_, i) => at(walls.length + i)) };
|
||||
}
|
||||
+2
-25
@@ -10,9 +10,8 @@
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { Opening, Project, Vec2, Wall } from "../model/types";
|
||||
import { getWallType, wallTypeThickness } from "../model/types";
|
||||
import { add, along, leftNormal, normalize, scale, sub } from "../model/geometry";
|
||||
import { wallReferenceOffset, wallVerticalExtent } from "../model/wall";
|
||||
import { along, leftNormal, normalize, sub } from "../model/geometry";
|
||||
import { wallVerticalExtent } from "../model/wall";
|
||||
|
||||
/** Achslänge einer Wand (Meter). */
|
||||
export function wallAxisLength(wall: Wall): number {
|
||||
@@ -71,28 +70,6 @@ export function openingJambs(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Lücken-Rechteck-Ecken (über die volle Wanddicke), z. B. um im Plan die
|
||||
* Öffnung als Aussparung zu markieren (Auswahl-Highlight). Reihenfolge:
|
||||
* jambStart(+n/2) → jambEnd(+n/2) → jambEnd(−n/2) → jambStart(−n/2).
|
||||
*/
|
||||
export function openingGapQuad(project: Project, wall: Wall, o: Opening): Vec2[] | null {
|
||||
const jambs = openingJambs(wall, o);
|
||||
if (!jambs) return null;
|
||||
const { n } = wallAxisFrame(wall);
|
||||
const total = wallTypeThickness(getWallType(project, wall));
|
||||
const refOff = wallReferenceOffset(wall, total);
|
||||
const outer = refOff + total / 2;
|
||||
const inner = refOff - total / 2;
|
||||
const { jambStart, jambEnd } = jambs;
|
||||
return [
|
||||
add(jambStart, scale(n, outer)),
|
||||
add(jambEnd, scale(n, outer)),
|
||||
add(jambEnd, scale(n, inner)),
|
||||
add(jambStart, scale(n, inner)),
|
||||
];
|
||||
}
|
||||
|
||||
/** 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);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//
|
||||
// Bogen-Segmente (`bulge`) werden bewusst über ihre SEHNE gemessen: für die
|
||||
// Frage „welches Segment ist gemeint" reicht das, und der eingefügte Punkt
|
||||
// landet ohnehin exakt auf dem Bogen (s. `projectSlice.insertDrawingPoint`).
|
||||
// landet ohnehin exakt auf dem Bogen (s. `insert_point` im Kern, `grips.rs`).
|
||||
|
||||
import type { Vec2 } from "../model/types";
|
||||
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { roofGeometry, roofBBox, roofUndersideAt } from "./roof";
|
||||
import { roofGeometry, roofUndersideAt } from "./roof";
|
||||
import type { Roof, Vec2 } from "../model/types";
|
||||
|
||||
/** Bounding-Box eines Umrisses (Prüfhilfe). */
|
||||
function roofBBox(outline: Vec2[]): { x0: number; y0: number; x1: number; y1: number } {
|
||||
const xs = outline.map((p) => p.x);
|
||||
const ys = outline.map((p) => p.y);
|
||||
return { x0: Math.min(...xs), y0: Math.min(...ys), x1: Math.max(...xs), y1: Math.max(...ys) };
|
||||
}
|
||||
|
||||
// Rechteck 6×4 (x:0..6, y:0..4), Neigung 45° (tan=1), Traufhöhe 10, kein Überstand.
|
||||
const RECT: Vec2[] = [
|
||||
{ x: 0, y: 0 },
|
||||
@@ -35,12 +42,6 @@ function allZ(g: ReturnType<typeof roofGeometry>): number[] {
|
||||
return zs;
|
||||
}
|
||||
|
||||
describe("roofBBox", () => {
|
||||
it("liefert die Bounding-Box", () => {
|
||||
expect(roofBBox(RECT)).toEqual({ x0: 0, y0: 0, x1: 6, y1: 4 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("roofGeometry — Formen (6×4, 45°, First entlang X)", () => {
|
||||
it("flach: eine waagrechte Fläche auf Traufhöhe, kein First", () => {
|
||||
const g = roofGeometry(roof({ shape: "flach" }), E);
|
||||
|
||||
@@ -39,21 +39,6 @@ export interface RoofGeometry {
|
||||
ridgeHeight: number;
|
||||
}
|
||||
|
||||
/** Bounding-Box eines Umrisses. */
|
||||
export function roofBBox(outline: Vec2[]): { x0: number; y0: number; x1: number; y1: number } {
|
||||
let x0 = Infinity;
|
||||
let y0 = Infinity;
|
||||
let x1 = -Infinity;
|
||||
let y1 = -Infinity;
|
||||
for (const p of outline) {
|
||||
if (p.x < x0) x0 = p.x;
|
||||
if (p.y < y0) y0 = p.y;
|
||||
if (p.x > x1) x1 = p.x;
|
||||
if (p.y > y1) y1 = p.y;
|
||||
}
|
||||
return { x0, y0, x1, y1 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Traufhöhe (absolutes Z) eines Dachs: `baseElevation`, sonst die OBERKANTE des
|
||||
* zugehörigen Geschosses (baseElevation + floorHeight) — das Dach sitzt also
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Kanten und Höfe eines Dachs ([26]): Liste, Änderung der Kantenneigung, Hof hinzufügen/entfernen.
|
||||
// Kanten und Höfe eines Dachs ([26]): Änderung der Kantenneigung, Hof hinzufügen/entfernen (die
|
||||
// Kantenliste rechnet der Kern, Test in `state/selectionInfo.test.ts`).
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { Roof, Vec2 } from "../model/types";
|
||||
import { addRoofHole, removeRoofHole, roofEdgeList, roofHoleWorks, setRoofEdge } from "./roofEdges";
|
||||
import { addRoofHole, removeRoofHole, roofHoleWorks, setRoofEdge } from "./roofEdges";
|
||||
|
||||
const rect = (x: number, y: number, w: number, h: number): Vec2[] => [
|
||||
{ x, y },
|
||||
@@ -26,27 +27,6 @@ const roof = (extra: Partial<Roof> = {}): Roof => ({
|
||||
|
||||
const court = rect(4, 2, 4, 4);
|
||||
|
||||
describe("roofEdgeList", () => {
|
||||
it("Umrisskanten, dann Hofkanten; Standard ohne Feld", () => {
|
||||
const list = roofEdgeList(roof({ holes: [court] }));
|
||||
expect(list).toHaveLength(8);
|
||||
expect(list.map((e) => e.ring)).toEqual([0, 0, 0, 0, 1, 1, 1, 1]);
|
||||
expect(list[0]).toMatchObject({ index: 0, spec: { kind: "default" }, length: 12 });
|
||||
expect(list[5].index).toBe(5);
|
||||
});
|
||||
|
||||
it("liest Giebel, Neigung und negativ = Standard; Sattel: Giebelregel zeigt sich als Vorgabe", () => {
|
||||
const list = roofEdgeList(roof({ edgePitchDeg: [20, null, -1] }));
|
||||
expect(list[0].spec).toEqual({ kind: "pitch", deg: 20 });
|
||||
expect(list[1].spec).toEqual({ kind: "gable" });
|
||||
expect(list[2].spec).toEqual({ kind: "default" });
|
||||
expect(list[3].spec).toEqual({ kind: "default" });
|
||||
const sattel = roofEdgeList(roof({ shape: "sattel" }));
|
||||
expect(sattel.map((e) => e.defaultGable)).toEqual([false, true, false, true]);
|
||||
expect(roofEdgeList(roof()).every((e) => !e.defaultGable)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("setRoofEdge", () => {
|
||||
it("setzt Neigung/Giebel, füllt mit Standard auf, entfernt das Feld wenn alles Standard", () => {
|
||||
const a = setRoofEdge(roof(), 2, { kind: "pitch", deg: 25 });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Kanten und Höfe eines Dachs ([26]): die Kantenliste fürs Objekt-Info (Neigung je Kante, Giebel),
|
||||
// Kanten und Höfe eines Dachs ([26]): Typen der Kantenliste (gerechnet im Kern, `selection_info.rs`),
|
||||
// Änderungen als Teilobjekt (`Partial<Roof>`, für `updateRoof`/`patchItem` — ein Undo-Schritt) und
|
||||
// die Prüfung, ob ein Hof wirkt. Die Geometrie selbst rechnet der Rust-Kern (`roof.rs`).
|
||||
//
|
||||
@@ -31,46 +31,6 @@ export interface RoofEdge {
|
||||
|
||||
const MAX_PITCH = 89;
|
||||
|
||||
/** Die Vorgabe aus einem Eintrag von `edgePitchDeg`. */
|
||||
function specOf(v: number | null | undefined): EdgeSpec {
|
||||
if (v === null) return { kind: "gable" };
|
||||
if (v === undefined || !Number.isFinite(v) || v < 0) return { kind: "default" };
|
||||
return { kind: "pitch", deg: v };
|
||||
}
|
||||
|
||||
/** Giebelt der Standard dieser Dachform die Kante a→b (quer zur Firstrichtung)? */
|
||||
function defaultGableEdge(roof: Roof, a: Vec2, b: Vec2): boolean {
|
||||
const gabled = roof.shape === "sattel" || (roof.shape === "mansarde" && (roof.mansardType ?? "giebel") === "giebel");
|
||||
if (!gabled) return false;
|
||||
const dx = Math.abs(b.x - a.x);
|
||||
const dy = Math.abs(b.y - a.y);
|
||||
return roof.ridgeAxis === "y" ? dy < dx : dx < dy;
|
||||
}
|
||||
|
||||
/** Alle Kanten des Dachs (Umriss, dann Höfe) mit ihrer Vorgabe. */
|
||||
export function roofEdgeList(roof: Roof): RoofEdge[] {
|
||||
const rings: Vec2[][] = [roof.outline, ...(roof.holes ?? [])];
|
||||
const out: RoofEdge[] = [];
|
||||
let index = 0;
|
||||
rings.forEach((ring, r) => {
|
||||
ring.forEach((a, edge) => {
|
||||
const b = ring[(edge + 1) % ring.length];
|
||||
out.push({
|
||||
index,
|
||||
ring: r,
|
||||
edge,
|
||||
a,
|
||||
b,
|
||||
length: Math.hypot(b.x - a.x, b.y - a.y),
|
||||
spec: specOf(roof.edgePitchDeg?.[index]),
|
||||
defaultGable: defaultGableEdge(roof, a, b),
|
||||
});
|
||||
index++;
|
||||
});
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/** `edgePitchDeg` ohne Standard-Einträge am Ende; alles Standard ⇒ `undefined` (Feld entfällt). */
|
||||
function normalized(values: (number | null)[]): (number | null)[] | undefined {
|
||||
const v = values.slice();
|
||||
@@ -80,7 +40,7 @@ function normalized(values: (number | null)[]): (number | null)[] | undefined {
|
||||
|
||||
/** Teilobjekt für `updateRoof`: Kante `index` auf `spec` setzen. */
|
||||
export function setRoofEdge(roof: Roof, index: number, spec: EdgeSpec): Pick<Roof, "edgePitchDeg"> {
|
||||
const total = roofEdgeList(roof).length;
|
||||
const total = roof.outline.length + (roof.holes ?? []).reduce((n, h) => n + h.length, 0);
|
||||
const values: (number | null)[] = Array.from({ length: total }, (_, i) => {
|
||||
const v = roof.edgePitchDeg?.[i];
|
||||
return v === undefined ? -1 : v;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Referenz, Schnitt, Rahmen und Unsinn-Eingaben (Rust-Tests decken die Mathematik je Fall ab).
|
||||
*/
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { defaultStepCount, stairBBox, stairCut, stairGeometry, stairOutline } from "./stair";
|
||||
import { defaultStepCount, stairCut, stairGeometry, stairOutline } from "./stair";
|
||||
import type { Stair } from "../model/types";
|
||||
|
||||
const base: Stair = {
|
||||
@@ -51,11 +51,10 @@ describe("stairGeometry", () => {
|
||||
expect(stairGeometry(base, NaN).treads).toEqual([]);
|
||||
expect(stairGeometry({ ...base, stepCount: 0 }, 2.8).treads).toHaveLength(2);
|
||||
expect(stairOutline({ ...base, runLength: NaN }, 0)).toEqual({ polygon: null, spiral: null });
|
||||
expect(stairBBox(stairGeometry(base, NaN))).toEqual({ minX: 0, minY: 0, maxX: 0, maxY: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("stairCut / stairBBox / defaultStepCount", () => {
|
||||
describe("stairCut / defaultStepCount", () => {
|
||||
it("Schnitt teilt die Tritte und legt eine Doppel-Bruchlinie", () => {
|
||||
const g = stairGeometry(base, 2.8);
|
||||
const c = stairCut(g, 1.0);
|
||||
@@ -66,12 +65,6 @@ describe("stairCut / stairBBox / defaultStepCount", () => {
|
||||
expect(stairCut(stairGeometry(base, NaN), 1)).toEqual({ belowIndices: [], aboveIndices: [], breakLine: null });
|
||||
});
|
||||
|
||||
it("BBox über Tritte", () => {
|
||||
const b = stairBBox(stairGeometry(base, 2.8));
|
||||
expect(b.maxX).toBeCloseTo(3, 12);
|
||||
expect(b.minY).toBeCloseTo(-0.6, 12);
|
||||
});
|
||||
|
||||
it("Vorgabe-Stufenzahl: Steighöhe 0.17, gedeckelt durch die Lauflänge, mind. 2", () => {
|
||||
expect(defaultStepCount(2.8, 10)).toBe(16);
|
||||
expect(defaultStepCount(2.8, 3)).toBe(13);
|
||||
|
||||
+2
-14
@@ -152,8 +152,8 @@ function encodeGeometry(g: StairGeometry): Float64Array {
|
||||
|
||||
/**
|
||||
* Leitet die vollständige Geometrie einer Treppe ab. `totalRise` MUSS vom
|
||||
* Aufrufer aufgelöst übergeben werden (Geschosshöhe-Default liegt in
|
||||
* `stairVerticalExtent`), damit dieses Modul modellfrei bleibt.
|
||||
* Aufrufer aufgelöst übergeben werden (Geschosshöhe-Default liegt im Kern,
|
||||
* `stair_vertical_extent` in `model/helpers.rs`), damit dieses Modul modellfrei bleibt.
|
||||
*/
|
||||
export function stairGeometry(stair: Stair, totalRise: number): StairGeometry {
|
||||
return decodeGeometry(core().stair_geometry_flat(encodeStair(stair), totalRise));
|
||||
@@ -199,18 +199,6 @@ export function stairCut(geo: StairGeometry, cutRise: number): StairCut {
|
||||
return { belowIndices, aboveIndices, breakLine };
|
||||
}
|
||||
|
||||
/** Achsparallele Bounding-Box aller Tritte (+ Podest) einer Treppengeometrie. */
|
||||
export function stairBBox(geo: StairGeometry): {
|
||||
minX: number;
|
||||
minY: number;
|
||||
maxX: number;
|
||||
maxY: number;
|
||||
} {
|
||||
const f = core().stair_bbox_flat(encodeGeometry(geo));
|
||||
if (f.length < 4) return { minX: 0, minY: 0, maxX: 0, maxY: 0 };
|
||||
return { minX: f[0], minY: f[1], maxX: f[2], maxY: f[3] };
|
||||
}
|
||||
|
||||
/**
|
||||
* Spiral-Outline: Innenbogen + Aussenbogen + zwei radiale Schliesslinien.
|
||||
* Die Bögen werden als Kreisbogen-Parameter geliefert (cx/cy/r/a0/a1), die
|
||||
|
||||
Reference in new issue
Block a user