From a7f835c7ec8eb97d0c13c613641e7eb62c3401d8 Mon Sep 17 00:00:00 2001 From: mendarb Date: Sat, 21 Mar 2026 00:43:22 +0100 Subject: [PATCH] Add missing step and layer properties to Arrow type The Arrow interface was missing step and layer properties that all other graphic element types (Point, Line, Rect, Circle, Polygon, Text) have. This also adds arrow handling to setStepOfAllObjects which was previously skipping arrows, and adds tests for setStepOfAllObjects. Closes #75 Co-Authored-By: Claude Opus 4.6 --- lib/setStepOfAllObjects.ts | 5 +++ lib/types.ts | 2 + tests/setStepOfAllObjects.test.ts | 67 +++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 tests/setStepOfAllObjects.test.ts diff --git a/lib/setStepOfAllObjects.ts b/lib/setStepOfAllObjects.ts index fa0e241..d4ff177 100644 --- a/lib/setStepOfAllObjects.ts +++ b/lib/setStepOfAllObjects.ts @@ -34,6 +34,11 @@ export function setStepOfAllObjects( circle.step = step } } + if (graphics.arrows) { + for (const arrow of graphics.arrows) { + arrow.step = step + } + } if (graphics.texts) { for (const text of graphics.texts) { text.step = step diff --git a/lib/types.ts b/lib/types.ts index 1eeb7a6..6b18573 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -68,6 +68,8 @@ export interface Arrow { color?: string label?: string inlineLabel?: string + layer?: string + step?: number } export type NinePointAnchor = diff --git a/tests/setStepOfAllObjects.test.ts b/tests/setStepOfAllObjects.test.ts new file mode 100644 index 0000000..1a0363a --- /dev/null +++ b/tests/setStepOfAllObjects.test.ts @@ -0,0 +1,67 @@ +import { describe, expect, test } from "bun:test" +import { setStepOfAllObjects } from "../lib/setStepOfAllObjects" +import type { GraphicsObject } from "../lib/types" + +describe("setStepOfAllObjects", () => { + test("sets step on all element types including arrows", () => { + const graphics: GraphicsObject = { + points: [{ x: 0, y: 0 }], + lines: [ + { + points: [ + { x: 0, y: 0 }, + { x: 1, y: 1 }, + ], + }, + ], + infiniteLines: [ + { + origin: { x: 0, y: 0 }, + directionVector: { x: 1, y: 0 }, + }, + ], + rects: [{ center: { x: 0, y: 0 }, width: 1, height: 1 }], + circles: [{ center: { x: 0, y: 0 }, radius: 1 }], + polygons: [ + { + points: [ + { x: 0, y: 0 }, + { x: 1, y: 0 }, + { x: 0.5, y: 1 }, + ], + }, + ], + arrows: [ + { + start: { x: 0, y: 0 }, + end: { x: 5, y: 5 }, + label: "arrow1", + }, + { + start: { x: 1, y: 1 }, + end: { x: 3, y: 3 }, + doubleSided: true, + }, + ], + texts: [{ x: 0, y: 0, text: "hello" }], + } + + setStepOfAllObjects(graphics, 3) + + expect(graphics.points![0].step).toBe(3) + expect(graphics.lines![0].step).toBe(3) + expect(graphics.infiniteLines![0].step).toBe(3) + expect(graphics.rects![0].step).toBe(3) + expect(graphics.circles![0].step).toBe(3) + expect(graphics.polygons![0].step).toBe(3) + expect(graphics.arrows![0].step).toBe(3) + expect(graphics.arrows![1].step).toBe(3) + expect(graphics.texts![0].step).toBe(3) + }) + + test("handles empty graphics object", () => { + const graphics: GraphicsObject = {} + const result = setStepOfAllObjects(graphics, 1) + expect(result).toEqual({}) + }) +})