diff --git a/lib/components/normal-components/Board.ts b/lib/components/normal-components/Board.ts index 1979f6699..a06ace615 100644 --- a/lib/components/normal-components/Board.ts +++ b/lib/components/normal-components/Board.ts @@ -118,8 +118,8 @@ export class Board extends Group { const { db } = this.root! const { _parsedProps: props } = this - // Skip if width and height are explicitly provided - if (props.width && props.height) return + // Skip if width and height are explicitly provided or if outline is provided + if ((props.width && props.height) || props.outline) return let minX = Infinity let minY = Infinity @@ -182,7 +182,7 @@ export class Board extends Group { const computedHeight = hasComponents ? maxY - minY + padding * 2 : 0 // Center the board around the components or use (0,0) for empty boards - let center = { + const center = { x: hasComponents ? (minX + maxX) / 2 + (props.outlineOffsetX ?? 0) : (props.outlineOffsetX ?? 0), @@ -195,7 +195,7 @@ export class Board extends Group { const finalWidth = props.width ?? computedWidth const finalHeight = props.height ?? computedHeight - let outline = props.outline + let outline = props.outline as { x: number; y: number }[] | undefined if ( !outline && props.borderRadius != null && diff --git a/tests/components/normal-components/__snapshots__/board-outline-dimension-pcb.snap.svg b/tests/components/normal-components/__snapshots__/board-outline-dimension-pcb.snap.svg new file mode 100644 index 000000000..1b14f178c --- /dev/null +++ b/tests/components/normal-components/__snapshots__/board-outline-dimension-pcb.snap.svg @@ -0,0 +1 @@ +R1C1 \ No newline at end of file diff --git a/tests/components/normal-components/board-outline-dimension.test.tsx b/tests/components/normal-components/board-outline-dimension.test.tsx new file mode 100644 index 000000000..91e14b818 --- /dev/null +++ b/tests/components/normal-components/board-outline-dimension.test.tsx @@ -0,0 +1,28 @@ +import { test, expect } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" + +test("board outline dimension is calculated correctly", () => { + const { circuit } = getTestFixture() + + circuit.add( + + + + , + ) + + circuit.render() + + const pcb_board = circuit.db.pcb_board.list()[0] + expect(pcb_board.width).toBe(16) + expect(pcb_board.height).toBe(16) + + expect(circuit).toMatchPcbSnapshot(import.meta.path) +})