@tscircuit/core 0.0.386 → 0.0.387

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +92 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3788,6 +3788,95 @@ var getMaxLengthFromConnectedCapacitors = (ports, { db }) => {
3788
3788
 
3789
3789
  // lib/components/primitive-components/Trace/get-obstacles-for-trace.ts
3790
3790
  import { getUnitVectorFromDirection } from "@tscircuit/math-utils";
3791
+
3792
+ // lib/utils/autorouting/getBoundsForSchematic.ts
3793
+ function getBoundsForSchematic(db) {
3794
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
3795
+ for (const elm of db) {
3796
+ let cx, cy, w, h;
3797
+ if (elm.type === "schematic_component") {
3798
+ cx = elm.center?.x;
3799
+ cy = elm.center?.y;
3800
+ w = elm.size?.width;
3801
+ h = elm.size?.height;
3802
+ } else if (elm.type === "schematic_box") {
3803
+ cx = elm.x;
3804
+ cy = elm.y;
3805
+ w = elm.width;
3806
+ h = elm.height;
3807
+ } else if (elm.type === "schematic_port") {
3808
+ cx = elm.center?.x;
3809
+ cy = elm.center?.y;
3810
+ w = 0.2;
3811
+ h = 0.2;
3812
+ } else if (elm.type === "schematic_text") {
3813
+ cx = elm.position?.x;
3814
+ cy = elm.position?.y;
3815
+ w = (elm.text?.length ?? 0) * 0.1;
3816
+ h = 0.2;
3817
+ }
3818
+ if (typeof cx === "number" && typeof cy === "number" && typeof w === "number" && typeof h === "number") {
3819
+ minX = Math.min(minX, cx - w / 2);
3820
+ maxX = Math.max(maxX, cx + w / 2);
3821
+ minY = Math.min(minY, cy - h / 2);
3822
+ maxY = Math.max(maxY, cy + h / 2);
3823
+ }
3824
+ }
3825
+ return { minX, maxX, minY, maxY };
3826
+ }
3827
+
3828
+ // lib/utils/autorouting/getObstaclesFromBounds.ts
3829
+ function getObstaclesFromBounds(bounds, opts = {}) {
3830
+ const { minX, maxX, minY, maxY } = bounds;
3831
+ const PADDING = opts.padding ?? 1;
3832
+ if (!isFinite(minX) || !isFinite(maxX) || !isFinite(minY) || !isFinite(maxY))
3833
+ return [];
3834
+ const left = minX - PADDING;
3835
+ const right = maxX + PADDING;
3836
+ const top = maxY + PADDING;
3837
+ const bottom = minY - PADDING;
3838
+ const thickness = 0.01;
3839
+ return [
3840
+ // Top border (horizontal)
3841
+ {
3842
+ type: "rect",
3843
+ layers: ["top"],
3844
+ center: { x: (left + right) / 2, y: top },
3845
+ width: right - left,
3846
+ height: thickness,
3847
+ connectedTo: []
3848
+ },
3849
+ // Bottom border (horizontal)
3850
+ {
3851
+ type: "rect",
3852
+ layers: ["top"],
3853
+ center: { x: (left + right) / 2, y: bottom },
3854
+ width: right - left,
3855
+ height: thickness,
3856
+ connectedTo: []
3857
+ },
3858
+ // Left border (vertical)
3859
+ {
3860
+ type: "rect",
3861
+ layers: ["top"],
3862
+ center: { x: left, y: (top + bottom) / 2 },
3863
+ width: thickness,
3864
+ height: top - bottom,
3865
+ connectedTo: []
3866
+ },
3867
+ // Right border (vertical)
3868
+ {
3869
+ type: "rect",
3870
+ layers: ["top"],
3871
+ center: { x: right, y: (top + bottom) / 2 },
3872
+ width: thickness,
3873
+ height: top - bottom,
3874
+ connectedTo: []
3875
+ }
3876
+ ];
3877
+ }
3878
+
3879
+ // lib/components/primitive-components/Trace/get-obstacles-for-trace.ts
3791
3880
  var getSchematicObstaclesForTrace = (trace) => {
3792
3881
  const db = trace.root.db;
3793
3882
  const connectedPorts = trace._findConnectedPorts().ports ?? [];
@@ -3849,6 +3938,8 @@ var getSchematicObstaclesForTrace = (trace) => {
3849
3938
  });
3850
3939
  }
3851
3940
  }
3941
+ const bounds = getBoundsForSchematic(db.toArray());
3942
+ obstacles.push(...getObstaclesFromBounds(bounds, { padding: 1 }));
3852
3943
  return obstacles;
3853
3944
  };
3854
3945
 
@@ -7800,7 +7891,7 @@ import { identity as identity4 } from "transformation-matrix";
7800
7891
  var package_default = {
7801
7892
  name: "@tscircuit/core",
7802
7893
  type: "module",
7803
- version: "0.0.385",
7894
+ version: "0.0.386",
7804
7895
  types: "dist/index.d.ts",
7805
7896
  main: "dist/index.js",
7806
7897
  module: "dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.386",
4
+ "version": "0.0.387",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",