diff --git a/lib/components/base-components/NormalComponent/NormalComponent.ts b/lib/components/base-components/NormalComponent/NormalComponent.ts
index dd6fd64b4..708585406 100644
--- a/lib/components/base-components/NormalComponent/NormalComponent.ts
+++ b/lib/components/base-components/NormalComponent/NormalComponent.ts
@@ -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,
diff --git a/lib/components/primitive-components/SchematicRect.ts b/lib/components/primitive-components/SchematicRect.ts
index 2e5bd6b7e..278ab3d2c 100644
--- a/lib/components/primitive-components/SchematicRect.ts
+++ b/lib/components/primitive-components/SchematicRect.ts
@@ -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,
diff --git a/package.json b/package.json
index a4b3a46d4..1186f2b69 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/tests/components/primitive-components/__snapshots__/schematic-circle-schematic.snap.svg b/tests/components/primitive-components/__snapshots__/schematic-circle-schematic.snap.svg
index 2e8195f26..ae9b7c71a 100644
--- a/tests/components/primitive-components/__snapshots__/schematic-circle-schematic.snap.svg
+++ b/tests/components/primitive-components/__snapshots__/schematic-circle-schematic.snap.svg
@@ -1,4 +1,4 @@
-
\ No newline at end of file
+ -3,-2-3,-1-3,0-3,1-3,2-3,3-3,4-3,5-3,6-2,-2-2,-1-2,0-2,1-2,2-2,3-2,4-2,5-2,6-1,-2-1,-1-1,0-1,1-1,2-1,3-1,4-1,5-1,60,-20,-10,00,10,20,30,40,50,61,-21,-11,01,11,21,31,41,51,62,-22,-12,02,12,22,32,42,52,63,-23,-13,03,13,23,33,43,53,64,-24,-14,04,14,24,34,44,54,65,-25,-15,05,15,25,35,45,55,6
\ No newline at end of file
diff --git a/tests/components/primitive-components/__snapshots__/schematic-line-schematic.snap.svg b/tests/components/primitive-components/__snapshots__/schematic-line-schematic.snap.svg
index c58736786..471cfd25b 100644
--- a/tests/components/primitive-components/__snapshots__/schematic-line-schematic.snap.svg
+++ b/tests/components/primitive-components/__snapshots__/schematic-line-schematic.snap.svg
@@ -1,4 +1,4 @@
-
\ No newline at end of file
+ -1,-1-1,0-1,1-1,2-1,3-1,4-1,5-1,6-1,7-1,8-1,9-1,10-1,110,-10,00,10,20,30,40,50,60,70,80,90,100,111,-11,01,11,21,31,41,51,61,71,81,91,101,112,-12,02,12,22,32,42,52,62,72,82,92,102,113,-13,03,13,23,33,43,53,63,73,83,93,103,114,-14,04,14,24,34,44,54,64,74,84,94,104,115,-15,05,15,25,35,45,55,65,75,85,95,105,116,-16,06,16,26,36,46,56,66,76,86,96,106,117,-17,07,17,27,37,47,57,67,77,87,97,107,118,-18,08,18,28,38,48,58,68,78,88,98,108,119,-19,09,19,29,39,49,59,69,79,89,99,109,1110,-110,010,110,210,310,410,510,610,710,810,910,1010,1111,-111,011,111,211,311,411,511,611,711,811,911,1011,11
\ No newline at end of file
diff --git a/tests/components/primitive-components/__snapshots__/schematic-rect-schematic.snap.svg b/tests/components/primitive-components/__snapshots__/schematic-rect-schematic.snap.svg
index 204f00bf5..9d5ae51c4 100644
--- a/tests/components/primitive-components/__snapshots__/schematic-rect-schematic.snap.svg
+++ b/tests/components/primitive-components/__snapshots__/schematic-rect-schematic.snap.svg
@@ -1,4 +1,4 @@
-
\ No newline at end of file
+ 3,53,63,73,83,93,103,114,54,64,74,84,94,104,115,55,65,75,85,95,105,116,56,66,76,86,96,106,117,57,67,77,87,97,107,118,58,68,78,88,98,108,119,59,69,79,89,99,109,1110,510,610,710,810,910,1010,1111,511,611,711,811,911,1011,11
\ No newline at end of file
diff --git a/tests/components/primitive-components/__snapshots__/schematic-rect2-schematic.snap.svg b/tests/components/primitive-components/__snapshots__/schematic-rect2-schematic.snap.svg
new file mode 100644
index 000000000..d8628ef38
--- /dev/null
+++ b/tests/components/primitive-components/__snapshots__/schematic-rect2-schematic.snap.svg
@@ -0,0 +1,25 @@
+
\ No newline at end of file
diff --git a/tests/components/primitive-components/schematic-arc.test.tsx b/tests/components/primitive-components/schematic-arc.test.tsx
index d9c104111..a88aca6e5 100644
--- a/tests/components/primitive-components/schematic-arc.test.tsx
+++ b/tests/components/primitive-components/schematic-arc.test.tsx
@@ -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",
diff --git a/tests/components/primitive-components/schematic-circle.test.tsx b/tests/components/primitive-components/schematic-circle.test.tsx
index c8f49895d..ccc8e335b 100644
--- a/tests/components/primitive-components/schematic-circle.test.tsx
+++ b/tests/components/primitive-components/schematic-circle.test.tsx
@@ -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",
diff --git a/tests/components/primitive-components/schematic-line.test.tsx b/tests/components/primitive-components/schematic-line.test.tsx
index 308d8397b..db43b943d 100644
--- a/tests/components/primitive-components/schematic-line.test.tsx
+++ b/tests/components/primitive-components/schematic-line.test.tsx
@@ -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",
diff --git a/tests/components/primitive-components/schematic-rect-with-traces.test.tsx b/tests/components/primitive-components/schematic-rect-with-traces.test.tsx
index 09cfc2b67..246e48e18 100644
--- a/tests/components/primitive-components/schematic-rect-with-traces.test.tsx
+++ b/tests/components/primitive-components/schematic-rect-with-traces.test.tsx
@@ -11,7 +11,8 @@ test.skip("SchematicRect with traces", async () => {
symbol={
{
symbol={
{
{
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)
})
diff --git a/tests/components/primitive-components/schematic-rect2.test.tsx b/tests/components/primitive-components/schematic-rect2.test.tsx
new file mode 100644
index 000000000..0240b6c19
--- /dev/null
+++ b/tests/components/primitive-components/schematic-rect2.test.tsx
@@ -0,0 +1,101 @@
+import { test, expect } from "bun:test"
+import { getTestFixture } from "tests/fixtures/get-test-fixture"
+
+test("SchematicRect Test2", () => {
+ const { circuit } = getTestFixture()
+
+ circuit.add(
+
+
+
+
+
+ }
+ />
+ ,
+ )
+
+ 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": 5,
+ "y": 8,
+ },
+ "is_box_with_pins": false,
+ "schematic_component_id": "schematic_component_0",
+ "schematic_group_id": "schematic_group_0",
+ "size": {
+ "height": 2,
+ "width": 6,
+ },
+ "source_component_id": "source_component_0",
+ "symbol_display_value": undefined,
+ "type": "schematic_component",
+ }
+ `)
+
+ const schematic_rect = circuit.db.schematic_rect.list()
+ expect(schematic_rect).toMatchInlineSnapshot(`
+ [
+ {
+ "center": {
+ "x": 7,
+ "y": 8,
+ },
+ "color": "rgba(132, 0, 0)",
+ "height": 2,
+ "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": 2,
+ },
+ {
+ "center": {
+ "x": 3,
+ "y": 8,
+ },
+ "color": "rgba(132, 0, 0)",
+ "height": 2,
+ "is_dashed": false,
+ "is_filled": false,
+ "rotation": 0,
+ "schematic_component_id": "schematic_component_0",
+ "schematic_rect_id": "schematic_rect_1",
+ "stroke_width": 0.12,
+ "subcircuit_id": "subcircuit_source_group_0",
+ "type": "schematic_rect",
+ "width": 2,
+ },
+ ]
+ `)
+
+ expect(circuit).toMatchSchematicSnapshot(import.meta.path)
+})