Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,17 @@ export class NormalComponent<

if (width === 0 && height === 0) return

// Update the schematic component with calculated bounds
// Calculate the center of the bounds
// The schematic_component center should be centered around its contents
const centerX = (bounds.minX + bounds.maxX) / 2
const centerY = (bounds.minY + bounds.maxY) / 2

// Update the schematic component with calculated bounds and center
db.schematic_component.update(this.schematic_component_id!, {
center: {
x: centerX,
y: centerY,
},
size: {
width,
height,
Expand Down
4 changes: 2 additions & 2 deletions lib/components/primitive-components/SchematicRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export class SchematicRect extends PrimitiveComponent<

const schematic_rect = db.schematic_rect.insert({
center: {
x: props.center.x + globalPos.x,
y: props.center.y + globalPos.y,
x: globalPos.x,
y: globalPos.y,
},
width: props.width,
height: props.height,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@tscircuit/matchpack": "^0.0.16",
"@tscircuit/math-utils": "^0.0.21",
"@tscircuit/miniflex": "^0.0.4",
"@tscircuit/props": "0.0.346",
"@tscircuit/props": "0.0.349",
"@tscircuit/schematic-autolayout": "^0.0.6",
"@tscircuit/schematic-match-adapt": "^0.0.16",
"@tscircuit/schematic-trace-solver": "^0.0.40",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test("SchematicArc Test", () => {
{
"center": {
"x": 0,
"y": 0,
"y": 2.5,
},
"is_box_with_pins": false,
"schematic_component_id": "schematic_component_0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ test("SchematicCircle Test", () => {
[
{
"center": {
"x": 0,
"y": 0,
"x": 1,
"y": 2,
},
"is_box_with_pins": false,
"schematic_component_id": "schematic_component_0",
Expand Down
4 changes: 2 additions & 2 deletions tests/components/primitive-components/schematic-line.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ test("SchematicLine Test", () => {
[
{
"center": {
"x": 0,
"y": 0,
"x": 5,
"y": 5,
},
"is_box_with_pins": false,
"schematic_component_id": "schematic_component_0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ test.skip("SchematicRect with traces", async () => {
symbol={
<symbol>
<schematicrect
center={{ x: 0, y: 0 }}
schX={0}
schY={0}
width={2}
height={2}
isFilled={false}
Expand All @@ -25,7 +26,8 @@ test.skip("SchematicRect with traces", async () => {
symbol={
<symbol>
<schematicrect
center={{ x: 5, y: 0 }}
schX={5}
schY={0}
width={2}
height={2}
isFilled={false}
Expand Down
49 changes: 48 additions & 1 deletion tests/components/primitive-components/schematic-rect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ test("SchematicRect Test", () => {
<board width="10mm" height="10mm">
<chip
name="U1"
schX={5}
schY={5}
symbol={
<symbol>
<schematicrect
center={{ x: 2, y: 3 }}
schX={2}
schY={3}
width={6}
height={4}
isFilled={false}
Expand All @@ -24,5 +27,49 @@ test("SchematicRect Test", () => {

circuit.render()

const schematic_component = circuit.db.schematic_component.get(
circuit.selectOne("chip")?.schematic_component_id!,
)
expect(schematic_component).not.toBeNull()
expect(schematic_component).toMatchInlineSnapshot(`
{
"center": {
"x": 7,
"y": 8,
},
"is_box_with_pins": false,
"schematic_component_id": "schematic_component_0",
"schematic_group_id": "schematic_group_0",
"size": {
"height": 4,
"width": 6,
},
"source_component_id": "source_component_0",
"symbol_display_value": undefined,
"type": "schematic_component",
}
`)

const schematic_rect = circuit.db.schematic_rect.list()[0]!
expect(schematic_rect).toMatchInlineSnapshot(`
{
"center": {
"x": 7,
"y": 8,
},
"color": "rgba(132, 0, 0)",
"height": 4,
"is_dashed": false,
"is_filled": false,
"rotation": 0,
"schematic_component_id": "schematic_component_0",
"schematic_rect_id": "schematic_rect_0",
"stroke_width": 0.12,
"subcircuit_id": "subcircuit_source_group_0",
"type": "schematic_rect",
"width": 6,
}
`)

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