Skip to content

Commit

Permalink
fix 3d model always being at (0,0)
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Sep 22, 2024
1 parent 2160ac8 commit f6a9812
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/components/normal-components/Chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,28 @@ export class Chip<PinLabels extends string = never> extends NormalComponent<

this.pcb_component_id = pcb_component.pcb_component_id
}

_getPcbCircuitJsonBounds(): {
center: { x: number; y: number }
bounds: { left: number; top: number; right: number; bottom: number }
width: number
height: number
} {
const { db } = this.root!
if (!this.pcb_component_id) return super._getPcbCircuitJsonBounds()

const pcb_component = db.pcb_component.get(this.pcb_component_id)!

return {
center: { x: pcb_component.center.x, y: pcb_component.center.y },
bounds: {
left: pcb_component.center.x - pcb_component.width / 2,
top: pcb_component.center.y - pcb_component.height / 2,
right: pcb_component.center.x + pcb_component.width / 2,
bottom: pcb_component.center.y + pcb_component.height / 2,
},
width: pcb_component.width,
height: pcb_component.height,
}
}
}
2 changes: 2 additions & 0 deletions tests/components/normal-components/chip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ it("should create a Chip component with cadModel prop", async () => {
<board width="10mm" height="10mm">
<chip
name="U1"
pcbX={4}
footprint="soic8"
cadModel={{
stlUrl: "https://example.com/chip.stl",
Expand All @@ -82,5 +83,6 @@ it("should create a Chip component with cadModel prop", async () => {

const cadComponents = circuit.db.cad_component.list()
expect(cadComponents).toHaveLength(1)
expect(cadComponents[0].position.x).toBeCloseTo(4)
expect(cadComponents[0].model_stl_url).toBe("https://example.com/chip.stl")
})

0 comments on commit f6a9812

Please sign in to comment.