Skip to content

Commit

Permalink
Merge pull request #588 from tscircuit/fix/schematic-props
Browse files Browse the repository at this point in the history
fix: schematic x and y props using parsed value in mm
  • Loading branch information
imrishabh18 authored Jan 30, 2025
2 parents 7fe32b3 + ecf147e commit 8d81141
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/components/base-components/PrimitiveComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ export abstract class PrimitiveComponent<
* schematic components
*/
computeSchematicPropsTransform(): Matrix {
return compose(translate(this.props.schX ?? 0, this.props.schY ?? 0))
const { _parsedProps: props } = this
return compose(translate(props.schX ?? 0, props.schY ?? 0))
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/repros/__snapshots__/repo8-resistor-schX-schematic.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions tests/repros/repo8-resistor-schX.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { test, expect } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

test("board with resistor being passed schX and pcbX in mm", () => {
const { circuit } = getTestFixture()

circuit.add(
<board width="10mm" height="10mm">
<resistor
resistance="1k"
footprint="0402"
name="R1"
schX="2mm"
pcbX="-2mm"
/>
</board>,
)

circuit.render()

expect(circuit.db.schematic_component.list()).toMatchInlineSnapshot(`
[
{
"center": {
"x": 2,
"y": 0,
},
"rotation": 0,
"schematic_component_id": "schematic_component_0",
"size": {
"height": 0.388910699999999,
"width": 1.0583332999999997,
},
"source_component_id": "source_component_0",
"symbol_display_value": "1kΩ",
"symbol_name": "boxresistor_right",
"type": "schematic_component",
},
]
`)

expect(circuit.db.pcb_component.list()).toMatchInlineSnapshot(`
[
{
"center": {
"x": -2,
"y": 0,
},
"height": 0.6000000000000001,
"layer": "top",
"pcb_component_id": "pcb_component_0",
"rotation": 0,
"source_component_id": "source_component_0",
"subcircuit_id": "subcircuit_source_group_0",
"type": "pcb_component",
"width": 1.5999999999999999,
},
]
`)

expect(circuit).toMatchSchematicSnapshot(import.meta.path)
})

0 comments on commit 8d81141

Please sign in to comment.