From 5a6dd31a38540d7f56eaac9e951822db0d4a4a60 Mon Sep 17 00:00:00 2001 From: imrishabh18 Date: Thu, 16 Oct 2025 17:49:45 +0530 Subject: [PATCH 1/3] fix: calculation of the dimension of the board when width and height is not passed and rather outline is passed --- lib/components/normal-components/Board.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/components/normal-components/Board.ts b/lib/components/normal-components/Board.ts index 1979f6699..8052f7dd0 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 From 47761e95ff92b9a7d0713d35451d154325091633 Mon Sep 17 00:00:00 2001 From: imrishabh18 Date: Thu, 16 Oct 2025 17:50:17 +0530 Subject: [PATCH 2/3] add the test --- .../board-outline-dimension-pcb.snap.svg | 1 + .../board-outline-dimension.test.tsx | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/components/normal-components/__snapshots__/board-outline-dimension-pcb.snap.svg create mode 100644 tests/components/normal-components/board-outline-dimension.test.tsx 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) +}) From 117ce456a78f96b9599c6a75e82c0165c2db7c25 Mon Sep 17 00:00:00 2001 From: imrishabh18 Date: Thu, 16 Oct 2025 17:52:50 +0530 Subject: [PATCH 3/3] fix type --- lib/components/normal-components/Board.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/components/normal-components/Board.ts b/lib/components/normal-components/Board.ts index 8052f7dd0..a06ace615 100644 --- a/lib/components/normal-components/Board.ts +++ b/lib/components/normal-components/Board.ts @@ -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 &&