2D: Höhenkoten-Werkzeug + Masskette bleibt gerade + Punkt-Notation

Neues Werkzeug "Höhenkote" (SIA 400 B.5.4, Figur 18): Dreieck-Symbol +
Höhenwert an einem Punkt. Vier Varianten (OK/UK × fertig/roh) bestimmen
Dreieck-Richtung und Füllung, per Option umschaltbar. Die Norm ordnet
Zahlen UNTERHALB einer Masslinie explizit Höhenmassen zu — das war der
eigentliche Grund, warum ein separater Typ statt einer Bemassungs-Variante
nötig war.

Bemassungs-Korrektur: eine Masskette bleibt beim Zeichnen immer eine
GERADE Linie (Klicks ab dem dritten Punkt werden auf die durch Punkt 1/2
festgelegte Gerade projiziert), auch wenn die Bedienung wie eine Polylinie
funktioniert — vorher konnte man versehentlich einen Zickzack-Pfad
erzeugen.

Ausserdem: Masszahlen nutzen jetzt Punkt- statt Komma-Notation ("3.96"
statt "3,96") — die tatsächlich gezeichneten Beispiele in der Norm
(Figur 13/14/18) verwenden durchgängig den Punkt, nicht das Komma aus der
abstrakten B.5.2-Beispielliste.
This commit is contained in:
karim committed 2026-08-22 02:32:11 +02:00
1 parent 4c7fc99eb8
commit 2dc57d01a5
21 files changed
+433 -19

No files matched your search

+23
View File
@@ -104,6 +104,29 @@ describe("dimensionCommand", () => {
expect(segs[1]).toMatchObject({ a: { x: 4, y: 0 }, b: { x: 10, y: 0 }, offset: 2 });
});
it("dritter Punkt ausserhalb der Geraden wird auf sie projiziert (keine Polylinie, immer gerade)", () => {
const p = project();
const ctx = makeCtx(p);
let [state] = dimensionCommand.onInput(
dimensionCommand.init(),
{ kind: "point", point: { x: 0, y: 0 } },
ctx,
);
// Richtung: entlang +x (y=0).
[state] = dimensionCommand.onInput(state, { kind: "point", point: { x: 4, y: 0 } }, ctx);
// Dritter Klick liegt bewusst NICHT auf der Geraden (y=3) → wird projiziert.
[state] = dimensionCommand.onInput(state, { kind: "point", point: { x: 10, y: 3 } }, ctx);
[state] = dimensionCommand.onConfirm(state, ctx);
const [, result] = dimensionCommand.onInput(state, { kind: "number", value: 1 }, ctx);
const next = result.commit!(p);
expect(next.drawings2d.length).toBe(2);
const second = next.drawings2d[1].geom;
if (second.shape === "dimension") {
expect(second.b.y).toBeCloseTo(0, 6); // auf die Gerade y=0 projiziert
expect(second.b.x).toBeCloseTo(10, 6); // x-Komponente bleibt (Projektion entlang x)
}
});
it("Zurück-Option entfernt den letzten Punkt", () => {
const p = project();
const ctx = makeCtx(p);
+25 -10
View File
@@ -1,10 +1,13 @@
// Bemassung (lineare Masslinie(n), SIA 400 B.5.3, Figur 14 „Reihenbemassung").
// Wie eine Polylinie: beliebig viele Punkte, dann EIN weiterer Klick für die
// Lage der Masslinie(n) — erzeugt eine ganze Massketten in einer Geste.
// Schritte:
// Bedienung wie eine Polylinie (beliebig viele Klicks, Doppelklick/Enter
// beendet), das ERGEBNIS ist aber IMMER eine GERADE Punktreihe: der erste
// Klick setzt den Startpunkt, der zweite legt die Richtung fest — jeder
// weitere Klick wird auf diese Gerade projiziert (Reihenbemassung misst
// mehrere Punkte entlang EINER Referenzlinie, z. B. einer Wand, nie einen
// Zickzack-Pfad). Schritte:
// 1) „Erster Punkt:" → Punkt
// 2) „Nächster Punkt ( Fertig Zurück ):" → Punkt … (Doppelklick/Enter
// beendet die Punktreihe, sobald ≥2 Punkte gesetzt sind)
// 2) „Nächster Punkt ( Fertig Zurück ):" → Punkt … (ab dem 3. Punkt auf die
// durch Punkt 1/2 definierte Gerade projiziert)
// 3) „Lage der Masslinie:" → Punkt/Zahl (EIN Normalabstand
// für ALLE Segmente) → commit: je aufeinanderfolgendem Punktpaar EIN
// `shape:"dimension"`-Element (unabhängig editierbar, teilt nur den
@@ -40,6 +43,15 @@ function signedOffset(a: Vec2, b: Vec2, pt: Vec2): number {
return (pt.x - a.x) * nx + (pt.y - a.y) * ny;
}
/** Projiziert `pt` auf die Gerade durch `p0` in Richtung `p1` (Kette bleibt gerade ab Punkt 3). */
function projectOnLine(p0: Vec2, p1: Vec2, pt: Vec2): Vec2 {
const dx = p1.x - p0.x, dy = p1.y - p0.y;
const len2 = dx * dx + dy * dy;
if (len2 < EPS) return pt;
const t = ((pt.x - p0.x) * dx + (pt.y - p0.y) * dy) / len2;
return { x: p0.x + dx * t, y: p0.y + dy * t };
}
/** Endpunkte der um `offset` parallel verschobenen Masslinie (Strecke a-b). */
function offsetPoints(a: Vec2, b: Vec2, offset: number): { a: Vec2; b: Vec2 } {
const dx = b.x - a.x, dy = b.y - a.y;
@@ -159,9 +171,11 @@ export const dimensionCommand: Command = {
const ns: DimNext = { phase: "next", pts: [pt], cursor: pt, lastPoint: pt };
return [ns, { draft: chainDraft([pt], pt) }];
}
const pts = [...s.pts, pt];
const ns: DimNext = { phase: "next", pts, cursor: pt, lastPoint: pt };
return [ns, { draft: chainDraft(pts, pt) }];
// Ab dem dritten Punkt: auf die durch Punkt 1/2 festgelegte Gerade projizieren.
const placed = s.pts.length >= 2 ? projectOnLine(s.pts[0], s.pts[1], pt) : pt;
const pts = [...s.pts, placed];
const ns: DimNext = { phase: "next", pts, cursor: placed, lastPoint: placed };
return [ns, { draft: chainDraft(pts, placed) }];
}
// Offset-Schritt: Zahl = direkter Abstand, Punkt = Abstand zum Cursor.
@@ -179,8 +193,9 @@ export const dimensionCommand: Command = {
onMove: (state, point): [CommandState, CommandResult] => {
const s = state as DimState;
if (s.phase === "next") {
const ns: DimNext = { ...s, cursor: point };
return [ns, { draft: chainDraft(s.pts, point) }];
const cursor = s.pts.length >= 2 ? projectOnLine(s.pts[0], s.pts[1], point) : point;
const ns: DimNext = { ...s, cursor };
return [ns, { draft: chainDraft(s.pts, cursor) }];
}
if (s.phase === "offset") {
// Offset relativ zum ERSTEN Segment (repräsentativ für die ganze Kette).
+86
View File
@@ -0,0 +1,86 @@
/**
* `koteCommand` — Punkt + getippter Höhenwert → `shape:"kote"` (SIA 400
* B.5.4, Figur 18). Default-Art „OK fertig"; per Option zyklisch umschaltbar.
*/
import { describe, it, expect } from "vitest";
import { koteCommand } from "./kote";
import type { CommandContext, Project } from "../types";
function project(): Project {
return {
id: "t",
name: "T",
lineStyles: [],
hatches: [],
components: [],
wallTypes: [],
drawingLevels: [
{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 2.6, cutHeight: 1.0, baseElevation: 0 },
],
layers: [{ code: "20", name: "Zeichnung", color: "#0a0a0a", lw: 0.5, visible: true, locked: false }],
walls: [],
doors: [],
openings: [],
ceilings: [],
stairs: [],
rooms: [],
drawings2d: [],
context: [],
};
}
function makeCtx(p: Project): CommandContext {
return {
project: p,
level: p.drawingLevels[0],
defaultCategoryCode: "20",
activeLineStyleId: "solid",
activeWallTypeId: "aw",
lastPoint: null,
selection: { wallIds: [], drawingId: null },
};
}
describe("koteCommand", () => {
it("Punkt + Zahl → shape:kote mit Default-Art OK fertig, rotation 0", () => {
const p = project();
const ctx = makeCtx(p);
let [state] = koteCommand.onInput(koteCommand.init(), { kind: "point", point: { x: 2, y: 3 } }, ctx);
const [, result] = koteCommand.onInput(state, { kind: "number", value: 3.25 }, ctx);
expect(result.commit).toBeDefined();
const next = result.commit!(p);
expect(next.drawings2d.length).toBe(1);
const g = next.drawings2d[0].geom;
expect(g.shape).toBe("kote");
if (g.shape === "kote") {
expect(g.at).toEqual({ x: 2, y: 3 });
expect(g.value).toBe(3.25);
expect(g.kind).toBe("okFertig");
expect(g.rotation).toBe(0);
}
});
it("Art-Option zyklt OK fertig → UK fertig → OK roh → UK roh → OK fertig", () => {
const p = project();
const ctx = makeCtx(p);
let [state] = koteCommand.onInput(koteCommand.init(), { kind: "point", point: { x: 0, y: 0 } }, ctx);
const seen: string[] = [];
for (let i = 0; i < 4; i++) {
[state] = koteCommand.onInput(state, { kind: "option", id: "kind" }, ctx);
const opts = koteCommand.options(state);
seen.push(opts[0].value!);
}
expect(seen).toEqual(["ukFertig", "okRoh", "ukRoh", "okFertig"]);
});
it("negativer Wert wird unverändert übernommen (Formatierung passiert erst beim Rendern)", () => {
const p = project();
const ctx = makeCtx(p);
let [state] = koteCommand.onInput(koteCommand.init(), { kind: "point", point: { x: 0, y: 0 } }, ctx);
const [, result] = koteCommand.onInput(state, { kind: "number", value: -0.1 }, ctx);
const next = result.commit!(p);
const g = next.drawings2d[0].geom;
if (g.shape === "kote") expect(g.value).toBe(-0.1);
});
});
+111
View File
@@ -0,0 +1,111 @@
// Höhenkote (SIA 400 B.5.4, Figur 18) — Dreieck-Symbol + Höhenwert an einem
// Punkt. Schritte:
// 1) „Punkt:" → Punkt (Dreieck-Spitze)
// 2) „Höhenwert ( Art ):" → Zahl (Meter, z. B. 3.25 oder -0.1) →
// commit. „Art" (Option, zyklisch: OK fertig/UK fertig/OK roh/UK roh)
// wechselt VOR dem Tippen die Dreieck-Variante (Default OK fertig).
import type { Drawing2D } from "../../model/types";
import { uniqueId } from "../../tools/types";
import type {
Command,
CommandContext,
CommandResult,
CommandState,
CmdOption,
DraftShape,
Project,
ToolDraft,
Vec2,
} from "../types";
import type { TranslationKey } from "../../i18n";
type KoteKind = "okFertig" | "ukFertig" | "okRoh" | "ukRoh";
const KIND_ORDER: KoteKind[] = ["okFertig", "ukFertig", "okRoh", "ukRoh"];
const nextKind = (k: KoteKind): KoteKind => KIND_ORDER[(KIND_ORDER.indexOf(k) + 1) % KIND_ORDER.length];
const KIND_LABEL: Record<KoteKind, TranslationKey> = {
okFertig: "cmd.kote.kind.okFertig",
ukFertig: "cmd.kote.kind.ukFertig",
okRoh: "cmd.kote.kind.okRoh",
ukRoh: "cmd.kote.kind.ukRoh",
};
const TRI_SIZE = 0.15; // Modell-Meter, Vorschau-Grösse (Rendering: DIM_… in drawing2d.ts)
const HALF_W = TRI_SIZE * 0.6;
/** Dreieck-Punkte für die Vorschau: `at` = Spitze; OK zeigt nach unten, UK nach oben. */
function triPts(at: Vec2, kind: KoteKind): Vec2[] {
const up = kind === "okFertig" || kind === "okRoh" ? 1 : -1; // Basis liegt in +up-Richtung von `at`
return [
at,
{ x: at.x - HALF_W, y: at.y + up * TRI_SIZE },
{ x: at.x + HALF_W, y: at.y + up * TRI_SIZE },
];
}
interface KotePoint extends CommandState {
phase: "point";
}
interface KoteValue extends CommandState {
phase: "value";
at: Vec2;
kind: KoteKind;
}
type KoteState = KotePoint | KoteValue;
function kindOption(kind: KoteKind): CmdOption {
return { id: "kind", labelKey: KIND_LABEL[kind], value: kind };
}
function valueDraft(at: Vec2, kind: KoteKind): ToolDraft {
const preview: DraftShape[] = [{ kind: "poly", pts: triPts(at, kind), closed: true }];
return { preview, vertices: [at] };
}
function appendKote(p: Project, at: Vec2, value: number, kind: KoteKind, ctx: CommandContext): Project {
const d: Drawing2D = {
id: uniqueId("dr2d"),
type: "drawing2d",
levelId: ctx.level.id,
categoryCode: ctx.defaultCategoryCode,
geom: { shape: "kote", at, value, kind, rotation: 0 },
};
return { ...p, drawings2d: [...p.drawings2d, d] };
}
const idle = (): [CommandState, CommandResult] => [
{ phase: "point", lastPoint: null },
{ draft: null, done: true },
];
export const koteCommand: Command = {
name: "kote",
labelKey: "cmd.kote.label",
prompt: (s) => ((s as KoteState).phase === "value" ? "cmd.kote.value" : "cmd.kote.point"),
accepts: (s) => ((s as KoteState).phase === "value" ? ["number", "option"] : ["point"]),
options: (s) => ((s as KoteState).phase === "value" ? [kindOption((s as KoteValue).kind)] : []),
init: (): KotePoint => ({ phase: "point", lastPoint: null }),
onInput: (state, input, ctx): [CommandState, CommandResult] => {
const s = state as KoteState;
if (s.phase === "point") {
if (input.kind !== "point") return [s, { draft: null }];
const ns: KoteValue = { phase: "value", at: input.point, kind: "okFertig", lastPoint: input.point };
return [ns, { draft: valueDraft(input.point, "okFertig") }];
}
if (input.kind === "option" && input.id === "kind") {
const ns: KoteValue = { ...s, kind: nextKind(s.kind) };
return [ns, { draft: valueDraft(s.at, ns.kind) }];
}
if (input.kind !== "number") return [s, { draft: valueDraft(s.at, s.kind) }];
const { at, kind } = s;
return [
{ phase: "point", lastPoint: null },
{ draft: null, done: true, commit: (p) => appendKote(p, at, input.value, kind, ctx) },
];
},
onMove: (state): [CommandState, CommandResult] => [state, { draft: null }],
onConfirm: (): [CommandState, CommandResult] => idle(),
onCancel: (): [CommandState, CommandResult] => idle(),
};
+4
View File
@@ -21,6 +21,7 @@ import { ellipseCommand } from "./cmds/ellipse";
import { splineCommand } from "./cmds/spline";
import { bezierCommand } from "./cmds/bezier";
import { dimensionCommand } from "./cmds/dimension";
import { koteCommand } from "./cmds/kote";
import { textCommand } from "./cmds/text";
import { textboxCommand } from "./cmds/textbox";
import { moveCommand } from "./cmds/move";
@@ -61,6 +62,7 @@ export const COMMANDS: Record<string, Command> = {
spline: splineCommand,
bezier: bezierCommand,
dimension: dimensionCommand,
kote: koteCommand,
text: textCommand,
textbox: textboxCommand,
move: moveCommand,
@@ -116,6 +118,8 @@ export const ALIASES: Record<string, string> = {
sp: "spline",
dim: "dimension",
bemassung: "dimension",
kt: "kote",
hoehenkote: "kote",
bz: "bezier",
tx: "text",
txt: "text",