diff --git a/README.md b/README.md index 88a75917..29afa111 100644 --- a/README.md +++ b/README.md @@ -1652,6 +1652,7 @@ interface PcbNoteText { font: "tscircuit2024" font_size: Length text?: string + ccw_rotation?: Rotation anchor_position: Point anchor_alignment: | "center" diff --git a/docs/PCB_COMPONENT_OVERVIEW.md b/docs/PCB_COMPONENT_OVERVIEW.md index 5060abf8..6f02d0d6 100644 --- a/docs/PCB_COMPONENT_OVERVIEW.md +++ b/docs/PCB_COMPONENT_OVERVIEW.md @@ -371,6 +371,7 @@ export interface PcbNoteText { font: "tscircuit2024" font_size: Length text?: string + ccw_rotation?: Rotation anchor_position: Point anchor_alignment: | "center" diff --git a/src/pcb/pcb_note_text.ts b/src/pcb/pcb_note_text.ts index fef15f5f..94a0c2af 100644 --- a/src/pcb/pcb_note_text.ts +++ b/src/pcb/pcb_note_text.ts @@ -1,7 +1,7 @@ import { z } from "zod" import { point, type Point, getZodPrefixedIdWithDefault } from "src/common" import { visible_layer, type VisibleLayer } from "src/pcb/properties/layer_ref" -import { distance, type Length } from "src/units" +import { distance, rotation, type Length, type Rotation } from "src/units" import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_note_text = z @@ -15,6 +15,7 @@ export const pcb_note_text = z font: z.literal("tscircuit2024").default("tscircuit2024"), font_size: distance.default("1mm"), text: z.string().optional(), + ccw_rotation: rotation.optional(), anchor_position: point.default({ x: 0, y: 0 }), anchor_alignment: z .enum(["center", "top_left", "top_right", "bottom_left", "bottom_right"]) @@ -40,6 +41,7 @@ export interface PcbNoteText { font: "tscircuit2024" font_size: Length text?: string + ccw_rotation?: Rotation anchor_position: Point anchor_alignment: | "center" diff --git a/tests/pcb_note_components.test.ts b/tests/pcb_note_components.test.ts index b61e627a..e7fec0d4 100644 --- a/tests/pcb_note_components.test.ts +++ b/tests/pcb_note_components.test.ts @@ -93,3 +93,23 @@ test("pcb note text allows optional name and text", () => { expect(note.name).toBe("Callout") expect(note.text).toBeUndefined() }) + +test("pcb note text allows optional ccw rotation", () => { + const note = pcb_note_text.parse({ + type: "pcb_note_text", + text: "Rotate me", + ccw_rotation: 45, + }) + + expect(note.ccw_rotation).toBe(45) +}) + +test("pcb note text allows unit-suffixed ccw rotation", () => { + const note = pcb_note_text.parse({ + type: "pcb_note_text", + text: "Rotate me too", + ccw_rotation: "0.5rad", + }) + + expect(note.ccw_rotation).toBeCloseTo((0.5 * 180) / Math.PI) +})