From cc9ad8555292ae916b5c81aee49d577d0291f65c Mon Sep 17 00:00:00 2001 From: karim Date: Fri, 23 Oct 2026 13:30:42 +0200 Subject: [PATCH] Koerper: Kegelstumpf (B-Rep-Rotationskoerper) --- src/commands/cmds/solid.test.ts | 7 +++++++ src/commands/cmds/solid.ts | 22 +++++++++++++++++++--- src/i18n/de.ts | 2 ++ src/i18n/en.ts | 2 ++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/commands/cmds/solid.test.ts b/src/commands/cmds/solid.test.ts index 5f0d9997..7e2ae767 100644 --- a/src/commands/cmds/solid.test.ts +++ b/src/commands/cmds/solid.test.ts @@ -50,4 +50,11 @@ describe("solid-Befehl", () => { expect(solidFromInputs("torus", { x: 0, y: 0 }, null, [0.3, 0.5])).toBeNull(); expect(solidFromInputs("torus", { x: 0, y: 0 }, null, [2, 0.5])?.height).toBeCloseTo(1, 9); }); + + it("Kegelstumpf: Revolve-Profil aus Radius, Oberradius, Hoehe", () => { + const b = solidFromInputs("frustum", { x: 1, y: 2 }, null, [2, 1, 3]); + expect(b?.height).toBe(3); + expect(b?.spec).toMatchObject({ kind: "revolve", cx: 1, cy: 2, profile: [0, 0, 2, 0, 1, 3, 0, 3] }); + expect(solidFromInputs("frustum", { x: 0, y: 0 }, null, [2, 0, 3])).toBeNull(); + }); }); diff --git a/src/commands/cmds/solid.ts b/src/commands/cmds/solid.ts index 6454ca99..f56c955f 100644 --- a/src/commands/cmds/solid.ts +++ b/src/commands/cmds/solid.ts @@ -25,24 +25,26 @@ import type { Vec2, } from "../types"; -export type SolidShape = "sphere" | "cylinder" | "cone" | "torus" | "cuboid"; +export type SolidShape = "sphere" | "cylinder" | "cone" | "frustum" | "torus" | "cuboid"; const SHAPE_OPTIONS: CmdOption[] = [ { id: "sphere", labelKey: "cmd.solid.shape.sphere" }, { id: "cylinder", labelKey: "cmd.solid.shape.cylinder" }, { id: "cone", labelKey: "cmd.solid.shape.cone" }, + { id: "frustum", labelKey: "cmd.solid.shape.frustum" }, { id: "torus", labelKey: "cmd.solid.shape.torus" }, { id: "cuboid", labelKey: "cmd.solid.shape.cuboid" }, ]; const SHAPE_IDS = new Set(SHAPE_OPTIONS.map((o) => o.id)); -type Step = "center" | "radius" | "height" | "major" | "minor" | "corner2"; +type Step = "center" | "radius" | "topRadius" | "height" | "major" | "minor" | "corner2"; /** Schrittfolge je Form (erste Eingabe ist immer ein Punkt: Mittelpunkt bzw. Ecke). */ const STEPS: Record = { sphere: ["center", "radius"], cylinder: ["center", "radius", "height"], cone: ["center", "radius", "height"], + frustum: ["center", "radius", "topRadius", "height"], torus: ["center", "major", "minor"], cuboid: ["center", "corner2", "height"], }; @@ -50,6 +52,7 @@ const STEPS: Record = { const PROMPT: Record = { center: "cmd.solid.center", radius: "cmd.solid.radius", + topRadius: "cmd.solid.topRadius", height: "cmd.solid.height", major: "cmd.solid.major", minor: "cmd.solid.minor", @@ -114,6 +117,16 @@ export function solidFromInputs( label: `${shape === "cone" ? "Kegel" : "Zylinder"} r=${fmt(r)} h=${fmt(h)}`, }; } + case "frustum": { + const [r, rt, h] = nums; + if (!(r > 1e-6) || !(rt > 1e-6) || !(h > 1e-6)) return null; + return { + points: circlePts(p0, Math.max(r, rt)), + height: h, + spec: { kind: "revolve", cx: p0.x, cy: p0.y, profile: [0, 0, r, 0, rt, h, 0, h] }, + label: `Kegelstumpf r=${fmt(r)}/${fmt(rt)} h=${fmt(h)}`, + }; + } case "torus": { const [major, minor] = nums; if (!(minor > 1e-6) || !(major > minor)) return null; @@ -153,11 +166,14 @@ function draftOf(s: SolidState): ToolDraft | null { hud = s.p1 ? `h = ${(s.nums[0] ?? 0).toFixed(2)} m` : `${Math.abs(b.x - s.p0.x).toFixed(2)} × ${Math.abs(b.y - s.p0.y).toFixed(2)} m`; } else { const r = step === "radius" || step === "major" ? dist : (s.nums[0] ?? dist); + if (s.shape === "frustum" && step !== "radius") { + preview.push({ kind: "poly", pts: circlePts(s.p0, Math.max(step === "topRadius" ? dist : (s.nums[1] ?? dist), 0.01)), closed: true }); + } preview.push({ kind: "poly", pts: circlePts(s.p0, Math.max(r, 0.01)), closed: true }); if (s.shape === "torus" && step === "minor") { preview.push({ kind: "poly", pts: circlePts(s.p0, (s.nums[0] ?? 0) + dist), closed: true }); } - hud = `${step === "height" ? "h" : "r"} = ${dist.toFixed(2)} m`; + hud = `${step === "height" ? "h" : step === "topRadius" ? "r2" : "r"} = ${dist.toFixed(2)} m`; } return { preview, vertices: [s.p0], hud: { at: cur, text: hud } }; } diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 5be2f29c..c42ab4a5 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -1287,6 +1287,8 @@ export const de = { "cmd.solid.shape.sphere": "Kugel", "cmd.solid.shape.cylinder": "Zylinder", "cmd.solid.shape.cone": "Kegel", + "cmd.solid.shape.frustum": "Kegelstumpf", + "cmd.solid.topRadius": "Oberer Radius:", "cmd.solid.shape.torus": "Torus", "cmd.solid.shape.cuboid": "Quader", "cmd.roof.label": "Dach", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 096dba0c..30ac347c 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -1276,6 +1276,8 @@ export const en: Record = { "cmd.solid.shape.sphere": "Sphere", "cmd.solid.shape.cylinder": "Cylinder", "cmd.solid.shape.cone": "Cone", + "cmd.solid.shape.frustum": "Frustum", + "cmd.solid.topRadius": "Top radius:", "cmd.solid.shape.torus": "Torus", "cmd.solid.shape.cuboid": "Cuboid", "cmd.roof.label": "Roof",