@tscircuit/core 0.0.386 → 0.0.388

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.
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ import * as _tscircuit_layout from '@tscircuit/layout';
12
12
  import { ConnectivityMap } from 'circuit-json-to-connectivity-map';
13
13
  import { GraphicsObject } from 'graphics-debug';
14
14
 
15
- declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InitializePortsFromChildren", "CreateNetsFromProps", "CreateTracesFromProps", "CreateTraceHintsFromProps", "SourceRender", "SourceParentAttachment", "PortMatching", "OptimizeSelectorCache", "SourceTraceRender", "SourceAddConnectivityMapKey", "SchematicComponentRender", "SchematicPortRender", "SchematicLayout", "SchematicTraceRender", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbLayout", "PcbComponentSizeCalculation", "PcbBoardAutoSize", "PcbTraceRender", "PcbTraceHintRender", "PcbRouteNetIslands", "PcbDesignRuleChecks", "CadModelRender", "PartsEngineRender"];
15
+ declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InitializePortsFromChildren", "CreateNetsFromProps", "CreateTracesFromProps", "CreateTraceHintsFromProps", "SourceRender", "SourceParentAttachment", "PortMatching", "OptimizeSelectorCache", "SourceTraceRender", "SourceAddConnectivityMapKey", "SchematicComponentRender", "SchematicPortRender", "SchematicLayout", "SchematicTraceRender", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbLayout", "PcbComponentSizeCalculation", "PcbBoardAutoSize", "PcbTraceHintRender", "PcbTraceRender", "PcbRouteNetIslands", "PcbDesignRuleChecks", "CadModelRender", "PartsEngineRender"];
16
16
  type RenderPhase = (typeof orderedRenderPhases)[number];
17
17
  type RenderPhaseFn<K extends RenderPhase = RenderPhase> = `doInitial${K}` | `update${K}` | `remove${K}`;
18
18
  type RenderPhaseStates = Record<RenderPhase, {
package/dist/index.js CHANGED
@@ -94,8 +94,8 @@ var orderedRenderPhases = [
94
94
  "PcbLayout",
95
95
  "PcbComponentSizeCalculation",
96
96
  "PcbBoardAutoSize",
97
- "PcbTraceRender",
98
97
  "PcbTraceHintRender",
98
+ "PcbTraceRender",
99
99
  "PcbRouteNetIslands",
100
100
  "PcbDesignRuleChecks",
101
101
  "CadModelRender",
@@ -3769,7 +3769,7 @@ var createSchematicTraceJunctions = ({
3769
3769
  return [];
3770
3770
  };
3771
3771
 
3772
- // lib/components/primitive-components/Trace/get-max-length-from-conn ected-capacitors.ts
3772
+ // lib/components/primitive-components/Trace/get-max-length-from-connected-capacitors.ts
3773
3773
  var getMaxLengthFromConnectedCapacitors = (ports, { db }) => {
3774
3774
  const capacitorMaxLengths = ports.map((port) => {
3775
3775
  const sourcePort = db.source_port.get(port.source_port_id);
@@ -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
 
@@ -5910,6 +6001,7 @@ var getSimpleRouteJsonFromCircuitJson = ({
5910
6001
  if (!db) {
5911
6002
  throw new Error("db or circuitJson is required");
5912
6003
  }
6004
+ const traceHints = db.pcb_trace_hint.list();
5913
6005
  const relevantSubcircuitIds = subcircuit_id ? /* @__PURE__ */ new Set([subcircuit_id]) : null;
5914
6006
  if (subcircuit_id) {
5915
6007
  const descendantSubcircuitIds = getDescendantSubcircuitIds(
@@ -5982,16 +6074,40 @@ var getSimpleRouteJsonFromCircuitJson = ({
5982
6074
  };
5983
6075
  });
5984
6076
  if (connectedPorts.length < 2) return null;
6077
+ const [portA, portB] = connectedPorts;
6078
+ const layerA = portA.layers?.[0] ?? "top";
6079
+ const layerB = portB.layers?.[0] ?? "top";
6080
+ const matchingHints = traceHints.filter(
6081
+ (hint) => hint.pcb_port_id === portA.pcb_port_id || hint.pcb_port_id === portB.pcb_port_id
6082
+ );
6083
+ const hintPoints = [];
6084
+ for (const hint of matchingHints) {
6085
+ const port = db.pcb_port.get(hint.pcb_port_id);
6086
+ const layer = port?.layers?.[0] ?? "top";
6087
+ for (const pt of hint.route) {
6088
+ hintPoints.push({
6089
+ x: pt.x,
6090
+ y: pt.y,
6091
+ layer
6092
+ });
6093
+ }
6094
+ }
5985
6095
  return {
5986
6096
  name: trace.source_trace_id ?? connMap.getNetConnectedToId(trace.source_trace_id) ?? "",
5987
6097
  source_trace_id: trace.source_trace_id,
5988
- pointsToConnect: connectedPorts.map((port) => {
5989
- return {
5990
- x: port.x,
5991
- y: port.y,
5992
- layer: port.layers?.[0] ?? "top"
5993
- };
5994
- })
6098
+ pointsToConnect: [
6099
+ {
6100
+ x: portA.x,
6101
+ y: portA.y,
6102
+ layer: layerA
6103
+ },
6104
+ ...hintPoints,
6105
+ {
6106
+ x: portB.x,
6107
+ y: portB.y,
6108
+ layer: layerB
6109
+ }
6110
+ ]
5995
6111
  };
5996
6112
  }).filter((c) => c !== null);
5997
6113
  const source_nets = db.source_net.list().filter(
@@ -7800,7 +7916,7 @@ import { identity as identity4 } from "transformation-matrix";
7800
7916
  var package_default = {
7801
7917
  name: "@tscircuit/core",
7802
7918
  type: "module",
7803
- version: "0.0.385",
7919
+ version: "0.0.387",
7804
7920
  types: "dist/index.d.ts",
7805
7921
  main: "dist/index.js",
7806
7922
  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.388",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",