From 7cf4cedd7311d942cd245a6240052fa94167ca60 Mon Sep 17 00:00:00 2001 From: seveibar Date: Sun, 1 Sep 2024 11:01:01 -0700 Subject: [PATCH 1/5] fix trace overlapping --- bun.lockb | Bin 120714 -> 120714 bytes package.json | 2 +- tests/__snapshots__/example1.snap.svg | 4 ++-- tests/examples/example1.test.tsx | 20 +++++++++++++++++--- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/bun.lockb b/bun.lockb index 05aaa28bf7ad580437da0e2165b142068297f62a..493b51d3a8eb7b24e2d1237a6837b1072e38bae6 100755 GIT binary patch delta 145 zcmV;C0B-+^uLp{+2aqlxmr0~w^4MhNIW8)o;Fc@n*^`L29U63hVu}E6d;s%m;7CB#RYKtKfbfwhAhJd0WdBwE;Y9gN&&k%0X4VFgaN-&qb)vm diff --git a/package.json b/package.json index f24b295..0cfe2e3 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "typescript": "^5.0.0" }, "dependencies": { - "@tscircuit/infgrid-ijump-astar": "0.0.5", + "@tscircuit/infgrid-ijump-astar": "^0.0.6", "@tscircuit/props": "^0.0.49", "@tscircuit/soup": "^0.0.58", "@tscircuit/soup-util": "0.0.18", diff --git a/tests/__snapshots__/example1.snap.svg b/tests/__snapshots__/example1.snap.svg index ace0129..5510675 100644 --- a/tests/__snapshots__/example1.snap.svg +++ b/tests/__snapshots__/example1.snap.svg @@ -3,5 +3,5 @@ .pcb-trace { stroke: #FF0000; stroke-width: 0.3; fill: none; } .pcb-hole { fill: #FF00FF; } .pcb-pad { fill: #FF0000; } - .pcb-boundary { fill: none; stroke: #f2eda1; stroke-width: 5; } - \ No newline at end of file + .pcb-boundary { fill: none; stroke: #f2eda1; stroke-width: 4.800000000000001; } + \ No newline at end of file diff --git a/tests/examples/example1.test.tsx b/tests/examples/example1.test.tsx index 0c6451f..e93dd63 100644 --- a/tests/examples/example1.test.tsx +++ b/tests/examples/example1.test.tsx @@ -9,6 +9,8 @@ test("example1", async () => { name="U1" footprint="soic8" pinLabels={{ pin1: "PWR", pin8: "GND" }} + pcbX={0} + pcbY={0} /> { resistance="10k" pullupFor=".U1 port.2" pullupTo="net.5v" + pcbX={4} + pcbY={0} + pcbRotation={90} /> { footprint="0603" decouplingFor=".U1 port.PWR" decouplingTo="net.GND" + pcbX={-5} + pcbY={0} + pcbRotation={90} + /> + - - {/* + - */} + , ) From 28210d208ecfcefb2805eea59217461e6f930503 Mon Sep 17 00:00:00 2001 From: seveibar Date: Sun, 1 Sep 2024 11:34:50 -0700 Subject: [PATCH 2/5] fix smtpads not rotating --- .../base-components/NormalComponent.ts | 2 +- .../base-components/PrimitiveComponent.ts | 11 +++++++-- lib/components/primitive-components/SmtPad.ts | 10 +++++--- tests/__snapshots__/example1.snap.svg | 2 +- .../primitive-components-pcb.snap.svg | 7 ++++++ .../pcb-rotation.test.tsx | 23 +++++++++++++++++++ tests/examples/example1.test.tsx | 8 ++++++- tests/fixtures/get-test-fixture.ts | 4 ++-- 8 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 tests/components/__snapshots__/primitive-components-pcb.snap.svg create mode 100644 tests/components/primitive-components/pcb-rotation.test.tsx diff --git a/lib/components/base-components/NormalComponent.ts b/lib/components/base-components/NormalComponent.ts index 2f7e554..baa0ee8 100644 --- a/lib/components/base-components/NormalComponent.ts +++ b/lib/components/base-components/NormalComponent.ts @@ -197,7 +197,7 @@ export class NormalComponent< width: 0, height: 0, layer: props.layer ?? "top", - rotation: props.rotation ?? 0, + rotation: props.pcbRotation ?? 0, source_component_id: this.source_component_id!, }) this.pcb_component_id = pcb_component.pcb_component_id diff --git a/lib/components/base-components/PrimitiveComponent.ts b/lib/components/base-components/PrimitiveComponent.ts index 2f939a9..5214c1b 100644 --- a/lib/components/base-components/PrimitiveComponent.ts +++ b/lib/components/base-components/PrimitiveComponent.ts @@ -10,6 +10,7 @@ import { applyToPoint, compose, identity, + rotate, translate, type Matrix, } from "transformation-matrix" @@ -97,8 +98,14 @@ export abstract class PrimitiveComponent< * components */ computePcbPropsTransform(): Matrix { - // TODO rotations - return translate(this.props.pcbX ?? 0, this.props.pcbY ?? 0) + const { _parsedProps: props } = this + + const matrix = compose( + translate(props.pcbX ?? 0, props.pcbY ?? 0), + rotate(((props.pcbRotation ?? 0) * Math.PI) / 180), + ) + + return matrix } /** diff --git a/lib/components/primitive-components/SmtPad.ts b/lib/components/primitive-components/SmtPad.ts index 4b3c078..35a507d 100644 --- a/lib/components/primitive-components/SmtPad.ts +++ b/lib/components/primitive-components/SmtPad.ts @@ -3,6 +3,7 @@ import { smtPadProps } from "@tscircuit/props" import type { Port } from "./Port" import type { RenderPhaseFn } from "../base-components/Renderable" import type { PCBSMTPad } from "@tscircuit/soup" +import { decomposeTSR } from "transformation-matrix" export class SmtPad extends PrimitiveComponent { pcb_smtpad_id: string | null = null @@ -40,6 +41,9 @@ export class SmtPad extends PrimitiveComponent { const { _parsedProps: props } = this if (!props.portHints) return const position = this.getGlobalPcbPosition() + const decomposedMat = decomposeTSR(this.computePcbGlobalTransform()) + const isRotated90 = + Math.abs(decomposedMat.rotation.angle * (180 / Math.PI) - 90) < 0.01 let pcb_smtpad: PCBSMTPad | null = null if (props.shape === "circle") { pcb_smtpad = db.pcb_smtpad.insert({ @@ -63,9 +67,9 @@ export class SmtPad extends PrimitiveComponent { layer: props.layer ?? "top", shape: "rect", - // @ts-ignore: no idea why this is triggering - width: props.width, - height: props.height, + ...(isRotated90 + ? { width: props.height, height: props.width } + : { width: props.width, height: props.height }), port_hints: props.portHints.map((ph) => ph.toString()), diff --git a/tests/__snapshots__/example1.snap.svg b/tests/__snapshots__/example1.snap.svg index 5510675..ee96195 100644 --- a/tests/__snapshots__/example1.snap.svg +++ b/tests/__snapshots__/example1.snap.svg @@ -4,4 +4,4 @@ .pcb-hole { fill: #FF00FF; } .pcb-pad { fill: #FF0000; } .pcb-boundary { fill: none; stroke: #f2eda1; stroke-width: 4.800000000000001; } - \ No newline at end of file + \ No newline at end of file diff --git a/tests/components/__snapshots__/primitive-components-pcb.snap.svg b/tests/components/__snapshots__/primitive-components-pcb.snap.svg new file mode 100644 index 0000000..09bc4a2 --- /dev/null +++ b/tests/components/__snapshots__/primitive-components-pcb.snap.svg @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/tests/components/primitive-components/pcb-rotation.test.tsx b/tests/components/primitive-components/pcb-rotation.test.tsx new file mode 100644 index 0000000..dcdb786 --- /dev/null +++ b/tests/components/primitive-components/pcb-rotation.test.tsx @@ -0,0 +1,23 @@ +import { test, expect } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" + +test("pcb rotation", async () => { + const { project, logSoup } = getTestFixture() + + project.add( + + + + , + ) + + project.render() + + expect(project.getCircuitJson()).toMatchPcbSnapshot(import.meta.dir) +}) diff --git a/tests/examples/example1.test.tsx b/tests/examples/example1.test.tsx index e93dd63..5a35d6c 100644 --- a/tests/examples/example1.test.tsx +++ b/tests/examples/example1.test.tsx @@ -2,7 +2,7 @@ import { test, expect } from "bun:test" import { getTestFixture } from "tests/fixtures/get-test-fixture" test("example1", async () => { - const { project } = getTestFixture() + const { project, logSoup } = getTestFixture() project.add( { project.render() + // console.log(project.db.pcb_component.list()) + + console.log(project.selectOne(".R1").children) + + // await logSoup("example1") + await expect( project.getSvg({ view: "pcb", diff --git a/tests/fixtures/get-test-fixture.ts b/tests/fixtures/get-test-fixture.ts index dc67707..faa1082 100644 --- a/tests/fixtures/get-test-fixture.ts +++ b/tests/fixtures/get-test-fixture.ts @@ -8,12 +8,12 @@ export const getTestFixture = () => { return { project, - logSoup: async (lgn: string) => { + logSoup: async (nameOfTest: string) => { if (process.env.CI) return if (!project.rootComponent?.renderPhaseStates.SourceRender.initialized) { project.render() } - await logSoup(`core_${lgn}`, project.getSoup()) + await logSoup(`core_${nameOfTest}`, project.getSoup()) }, } } From 01d4bb9585a8efa96474a73d89926401c5d08a8b Mon Sep 17 00:00:00 2001 From: seveibar Date: Sun, 1 Sep 2024 11:37:13 -0700 Subject: [PATCH 3/5] silkscreen path transforming properly --- .../primitive-components/SilkscreenPath.ts | 15 ++++++++++++++- .../primitive-components-pcb.snap.svg | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/components/primitive-components/SilkscreenPath.ts b/lib/components/primitive-components/SilkscreenPath.ts index 3f1e630..b18f26d 100644 --- a/lib/components/primitive-components/SilkscreenPath.ts +++ b/lib/components/primitive-components/SilkscreenPath.ts @@ -1,5 +1,6 @@ import { silkscreenPathProps } from "@tscircuit/props" import { PrimitiveComponent } from "../base-components/PrimitiveComponent" +import { applyToPoint } from "transformation-matrix" export class SilkscreenPath extends PrimitiveComponent< typeof silkscreenPathProps @@ -23,10 +24,22 @@ export class SilkscreenPath extends PrimitiveComponent< ) } + const transform = this.computePcbGlobalTransform() + const pcb_silkscreen_path = db.pcb_silkscreen_path.insert({ pcb_component_id: this.parent?.pcb_component_id!, layer, - route: props.route, + route: props.route.map((p) => { + const transformedPosition = applyToPoint(transform, { + x: p.x, + y: p.y, + }) + return { + ...p, + x: transformedPosition.x, + y: transformedPosition.y, + } + }), stroke_width: props.strokeWidth ?? 0.1, }) diff --git a/tests/components/__snapshots__/primitive-components-pcb.snap.svg b/tests/components/__snapshots__/primitive-components-pcb.snap.svg index 09bc4a2..746f4a9 100644 --- a/tests/components/__snapshots__/primitive-components-pcb.snap.svg +++ b/tests/components/__snapshots__/primitive-components-pcb.snap.svg @@ -3,5 +3,5 @@ .pcb-trace { stroke: #FF0000; stroke-width: 0.3; fill: none; } .pcb-hole { fill: #FF00FF; } .pcb-pad { fill: #FF0000; } - .pcb-boundary { fill: none; stroke: #f2eda1; stroke-width: 4.982871379632513; } - \ No newline at end of file + .pcb-boundary { fill: none; stroke: #f2eda1; stroke-width: 4.891470498318557; } + \ No newline at end of file From 0061f3ce0a9e4cee8e11a664e53c6c04dc508afd Mon Sep 17 00:00:00 2001 From: seveibar Date: Sun, 1 Sep 2024 11:40:42 -0700 Subject: [PATCH 4/5] adjust rotation for jumper --- tests/__snapshots__/example1.snap.svg | 2 +- tests/examples/example1.test.tsx | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/__snapshots__/example1.snap.svg b/tests/__snapshots__/example1.snap.svg index ee96195..2847a93 100644 --- a/tests/__snapshots__/example1.snap.svg +++ b/tests/__snapshots__/example1.snap.svg @@ -4,4 +4,4 @@ .pcb-hole { fill: #FF00FF; } .pcb-pad { fill: #FF0000; } .pcb-boundary { fill: none; stroke: #f2eda1; stroke-width: 4.800000000000001; } - \ No newline at end of file + \ No newline at end of file diff --git a/tests/examples/example1.test.tsx b/tests/examples/example1.test.tsx index 5a35d6c..c743b24 100644 --- a/tests/examples/example1.test.tsx +++ b/tests/examples/example1.test.tsx @@ -32,13 +32,7 @@ test("example1", async () => { pcbY={0} pcbRotation={90} /> - + @@ -51,7 +45,7 @@ test("example1", async () => { // console.log(project.db.pcb_component.list()) - console.log(project.selectOne(".R1").children) + // console.log(project.selectOne(".R1").children) // await logSoup("example1") From 5adfe98b5abc745f3f9e47359239ebffa4acb9e4 Mon Sep 17 00:00:00 2001 From: Severin Ibarluzea Date: Sun, 1 Sep 2024 11:43:29 -0700 Subject: [PATCH 5/5] Update tests/examples/example1.test.tsx --- tests/examples/example1.test.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/examples/example1.test.tsx b/tests/examples/example1.test.tsx index c743b24..946436a 100644 --- a/tests/examples/example1.test.tsx +++ b/tests/examples/example1.test.tsx @@ -43,12 +43,6 @@ test("example1", async () => { project.render() - // console.log(project.db.pcb_component.list()) - - // console.log(project.selectOne(".R1").children) - - // await logSoup("example1") - await expect( project.getSvg({ view: "pcb",