@tscircuit/core 0.0.1154 → 0.0.1156

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
@@ -64,6 +64,7 @@ type Obstacle = {
64
64
  obstacleId?: string;
65
65
  type: "rect";
66
66
  layers: string[];
67
+ zLayers?: number[];
67
68
  center: {
68
69
  x: number;
69
70
  y: number;
@@ -71,6 +72,7 @@ type Obstacle = {
71
72
  width: number;
72
73
  height: number;
73
74
  connectedTo: string[];
75
+ isCopperPour?: boolean;
74
76
  netIsAssignable?: boolean;
75
77
  offBoardConnectsTo?: string[];
76
78
  };
@@ -950,6 +952,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
950
952
  name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
951
953
  } | undefined;
952
954
  }>, z.ZodString]>, "many">, "many">>;
955
+ routingPhaseIndex: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
953
956
  pcbStraightLine: z.ZodOptional<z.ZodBoolean>;
954
957
  schDisplayLabel: z.ZodOptional<z.ZodString>;
955
958
  schStroke: z.ZodOptional<z.ZodString>;
@@ -972,6 +975,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
972
975
  width?: number | undefined;
973
976
  maxLength?: number | undefined;
974
977
  connectsTo?: string | string[] | undefined;
978
+ routingPhaseIndex?: number | null | undefined;
975
979
  schematicRouteHints?: {
976
980
  x: number;
977
981
  y: number;
@@ -1011,6 +1015,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
1011
1015
  width?: string | number | undefined;
1012
1016
  maxLength?: string | number | undefined;
1013
1017
  connectsTo?: string | string[] | undefined;
1018
+ routingPhaseIndex?: number | null | undefined;
1014
1019
  schematicRouteHints?: {
1015
1020
  x: string | number;
1016
1021
  y: string | number;
@@ -1206,6 +1211,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
1206
1211
  name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
1207
1212
  } | undefined;
1208
1213
  }>, z.ZodString]>, "many">, "many">>;
1214
+ routingPhaseIndex: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
1209
1215
  pcbStraightLine: z.ZodOptional<z.ZodBoolean>;
1210
1216
  schDisplayLabel: z.ZodOptional<z.ZodString>;
1211
1217
  schStroke: z.ZodOptional<z.ZodString>;
@@ -1236,6 +1242,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
1236
1242
  width?: number | undefined;
1237
1243
  maxLength?: number | undefined;
1238
1244
  connectsTo?: string | string[] | undefined;
1245
+ routingPhaseIndex?: number | null | undefined;
1239
1246
  schematicRouteHints?: {
1240
1247
  x: number;
1241
1248
  y: number;
@@ -1278,6 +1285,7 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
1278
1285
  width?: string | number | undefined;
1279
1286
  maxLength?: string | number | undefined;
1280
1287
  connectsTo?: string | string[] | undefined;
1288
+ routingPhaseIndex?: number | null | undefined;
1281
1289
  schematicRouteHints?: {
1282
1290
  x: string | number;
1283
1291
  y: string | number;
@@ -82901,6 +82909,7 @@ declare class CopperPour extends PrimitiveComponent<typeof copperPourProps> {
82901
82909
  name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
82902
82910
  }>;
82903
82911
  connectsTo: zod.ZodString;
82912
+ unbroken: zod.ZodOptional<zod.ZodBoolean>;
82904
82913
  padMargin: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
82905
82914
  traceMargin: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
82906
82915
  clearance: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
@@ -82926,6 +82935,7 @@ declare class CopperPour extends PrimitiveComponent<typeof copperPourProps> {
82926
82935
  x: number;
82927
82936
  y: number;
82928
82937
  }[] | undefined;
82938
+ unbroken?: boolean | undefined;
82929
82939
  padMargin?: number | undefined;
82930
82940
  traceMargin?: number | undefined;
82931
82941
  clearance?: number | undefined;
@@ -82942,6 +82952,7 @@ declare class CopperPour extends PrimitiveComponent<typeof copperPourProps> {
82942
82952
  y: string | number;
82943
82953
  }[] | undefined;
82944
82954
  coveredWithSolderMask?: boolean | undefined;
82955
+ unbroken?: boolean | undefined;
82945
82956
  padMargin?: string | number | undefined;
82946
82957
  traceMargin?: string | number | undefined;
82947
82958
  clearance?: string | number | undefined;
@@ -151818,12 +151829,15 @@ declare const applyEditEvents: ({ circuitJson, editEvents, }: {
151818
151829
  /**
151819
151830
  * This function can only be called in the PcbTraceRender phase or later
151820
151831
  */
151821
- declare const getSimpleRouteJsonFromCircuitJson: ({ db, circuitJson, subcircuit_id, minTraceWidth, nominalTraceWidth, }: {
151832
+ declare const getSimpleRouteJsonFromCircuitJson: ({ db, circuitJson, subcircuit_id, minTraceWidth, nominalTraceWidth, subcircuitComponent, }: {
151822
151833
  db?: CircuitJsonUtilObjects;
151823
151834
  circuitJson?: AnyCircuitElement[];
151824
151835
  subcircuit_id?: string | null;
151825
151836
  minTraceWidth?: number;
151826
151837
  nominalTraceWidth?: number;
151838
+ subcircuitComponent?: {
151839
+ selectAll(selector: string): unknown[];
151840
+ };
151827
151841
  }) => {
151828
151842
  simpleRouteJson: SimpleRouteJson;
151829
151843
  connMap: ConnectivityMap;
package/dist/index.js CHANGED
@@ -2679,6 +2679,25 @@ function fillCircleWithRects(circle, options = {}) {
2679
2679
 
2680
2680
  // lib/utils/obstacles/getObstaclesFromCircuitJson.ts
2681
2681
  var EVERY_LAYER = ["top", "inner1", "inner2", "bottom"];
2682
+ var QUARTER_TURN_TOLERANCE_DEGREES = 0.01;
2683
+ var getAxisAlignedRectFromRotatedRect = (rotatedRect) => {
2684
+ const normalizedRotation = (rotatedRect.rotation % 360 + 360) % 360;
2685
+ const axisAlignedAngles = [0, 90, 180, 270];
2686
+ for (const angle of axisAlignedAngles) {
2687
+ const angularDistance = Math.min(
2688
+ Math.abs(normalizedRotation - angle),
2689
+ 360 - Math.abs(normalizedRotation - angle)
2690
+ );
2691
+ if (angularDistance > QUARTER_TURN_TOLERANCE_DEGREES) continue;
2692
+ const isVertical = angle === 90 || angle === 270;
2693
+ return {
2694
+ center: rotatedRect.center,
2695
+ width: isVertical ? rotatedRect.height : rotatedRect.width,
2696
+ height: isVertical ? rotatedRect.width : rotatedRect.height
2697
+ };
2698
+ }
2699
+ return null;
2700
+ };
2682
2701
  var getObstaclesFromCircuitJson = (soup, connMap) => {
2683
2702
  const withNetId = (idList) => connMap ? idList.concat(
2684
2703
  idList.map((id) => connMap?.getNetConnectedToId(id)).filter(Boolean)
@@ -2718,8 +2737,9 @@ var getObstaclesFromCircuitJson = (soup, connMap) => {
2718
2737
  height: element.height,
2719
2738
  rotation: element.ccw_rotation
2720
2739
  };
2721
- const approximatingRects = generateApproximatingRects(rotatedRect);
2722
- for (const rect of approximatingRects) {
2740
+ const singleRect = getAxisAlignedRectFromRotatedRect(rotatedRect);
2741
+ const rects = singleRect ? [singleRect] : generateApproximatingRects(rotatedRect);
2742
+ for (const rect of rects) {
2723
2743
  obstacles.push({
2724
2744
  type: "rect",
2725
2745
  layers: [element.layer],
@@ -13120,12 +13140,127 @@ import { su as su4 } from "@tscircuit/circuit-json-util";
13120
13140
  import {
13121
13141
  getFullConnectivityMapFromCircuitJson as getFullConnectivityMapFromCircuitJson3
13122
13142
  } from "circuit-json-to-connectivity-map";
13143
+
13144
+ // lib/utils/autorouting/getUnbrokenCopperPourObstacles.ts
13145
+ var COPPER_POUR_RECT_HEIGHT = 0.5;
13146
+ var dedupeStrings = (values) => Array.from(new Set(values.filter((value) => Boolean(value))));
13147
+ var getLayerName = (layer) => typeof layer === "string" ? layer : layer.name;
13148
+ var createCopperPourObstacle = ({
13149
+ layer,
13150
+ connectedTo,
13151
+ center,
13152
+ width,
13153
+ height
13154
+ }) => ({
13155
+ type: "rect",
13156
+ layers: [layer],
13157
+ center,
13158
+ width,
13159
+ height,
13160
+ connectedTo,
13161
+ isCopperPour: true
13162
+ });
13163
+ var getCopperPourBoundary = ({
13164
+ outline,
13165
+ group,
13166
+ board
13167
+ }) => {
13168
+ if (outline && outline.length >= 3) return outline;
13169
+ if (group?.outline && group.outline.length >= 3) return group.outline;
13170
+ if (board?.outline && board.outline.length >= 3) return board.outline;
13171
+ return null;
13172
+ };
13173
+ var getCopperPourBoundsRect = ({
13174
+ group,
13175
+ board
13176
+ }) => {
13177
+ if (group?.width && group.height) {
13178
+ return {
13179
+ center: group.center,
13180
+ width: group.width,
13181
+ height: group.height
13182
+ };
13183
+ }
13184
+ if (board?.width && board.height) {
13185
+ return {
13186
+ center: board.center,
13187
+ width: board.width,
13188
+ height: board.height
13189
+ };
13190
+ }
13191
+ return null;
13192
+ };
13193
+ var getCopperPourConnectedTo = (net, connMap) => dedupeStrings([
13194
+ net.source_net_id,
13195
+ net.subcircuit_connectivity_map_key,
13196
+ net.source_net_id ? connMap.getNetConnectedToId(net.source_net_id) : null
13197
+ ]);
13198
+ var getUnbrokenCopperPourObstacles = ({
13199
+ connMap,
13200
+ subcircuitComponent,
13201
+ board,
13202
+ group
13203
+ }) => {
13204
+ if (!subcircuitComponent) return [];
13205
+ const obstacles = [];
13206
+ const copperPours = subcircuitComponent.selectAll(
13207
+ "copperpour"
13208
+ );
13209
+ for (const copperPour of copperPours) {
13210
+ const props = copperPour._parsedProps;
13211
+ if (!props.unbroken) continue;
13212
+ const net = copperPour.getSubcircuit().selectOne(props.connectsTo);
13213
+ if (!net?.source_net_id) continue;
13214
+ const layer = getLayerName(props.layer);
13215
+ const connectedTo = getCopperPourConnectedTo(net, connMap);
13216
+ if (connectedTo.length === 0) continue;
13217
+ const boundary = getCopperPourBoundary({
13218
+ outline: props.outline,
13219
+ group,
13220
+ board
13221
+ });
13222
+ if (boundary) {
13223
+ const rects = fillPolygonWithRects(boundary, {
13224
+ rectHeight: COPPER_POUR_RECT_HEIGHT
13225
+ });
13226
+ if (rects.length > 0) {
13227
+ obstacles.push(
13228
+ ...rects.map(
13229
+ (rect) => createCopperPourObstacle({
13230
+ layer,
13231
+ connectedTo,
13232
+ center: rect.center,
13233
+ width: rect.width,
13234
+ height: rect.height
13235
+ })
13236
+ )
13237
+ );
13238
+ continue;
13239
+ }
13240
+ }
13241
+ const boundsRect = getCopperPourBoundsRect({ group, board });
13242
+ if (!boundsRect) continue;
13243
+ obstacles.push(
13244
+ createCopperPourObstacle({
13245
+ layer,
13246
+ connectedTo,
13247
+ center: boundsRect.center,
13248
+ width: boundsRect.width,
13249
+ height: boundsRect.height
13250
+ })
13251
+ );
13252
+ }
13253
+ return obstacles;
13254
+ };
13255
+
13256
+ // lib/utils/autorouting/getSimpleRouteJsonFromCircuitJson.ts
13123
13257
  var getSimpleRouteJsonFromCircuitJson = ({
13124
13258
  db,
13125
13259
  circuitJson,
13126
13260
  subcircuit_id,
13127
13261
  minTraceWidth = 0.1,
13128
- nominalTraceWidth
13262
+ nominalTraceWidth,
13263
+ subcircuitComponent
13129
13264
  }) => {
13130
13265
  if (!db && circuitJson) {
13131
13266
  db = su4(circuitJson);
@@ -13161,6 +13296,7 @@ var getSimpleRouteJsonFromCircuitJson = ({
13161
13296
  board = db.pcb_board.list()[0];
13162
13297
  }
13163
13298
  db = su4(subcircuitElements);
13299
+ const pcbGroup = subcircuit_id ? db.pcb_group.getWhere({ subcircuit_id }) : void 0;
13164
13300
  const connMap = getFullConnectivityMapFromCircuitJson3(subcircuitElements);
13165
13301
  const obstacles = getObstaclesFromCircuitJson(
13166
13302
  [
@@ -13177,6 +13313,14 @@ var getSimpleRouteJsonFromCircuitJson = ({
13177
13313
  ),
13178
13314
  connMap
13179
13315
  );
13316
+ obstacles.push(
13317
+ ...getUnbrokenCopperPourObstacles({
13318
+ connMap,
13319
+ subcircuitComponent,
13320
+ board,
13321
+ group: pcbGroup
13322
+ })
13323
+ );
13180
13324
  for (const obstacle of obstacles) {
13181
13325
  const additionalIds = obstacle.connectedTo.flatMap(
13182
13326
  (id) => connMap.getIdsConnectedToNet(id)
@@ -13255,22 +13399,19 @@ var getSimpleRouteJsonFromCircuitJson = ({
13255
13399
  maxY: Math.max(...allPoints.map((p) => p.y)) + 1
13256
13400
  };
13257
13401
  }
13258
- if (subcircuit_id) {
13259
- const group = db.pcb_group.getWhere({ subcircuit_id });
13260
- if (group?.width && group.height) {
13261
- const groupBounds = {
13262
- minX: group.center.x - group.width / 2,
13263
- maxX: group.center.x + group.width / 2,
13264
- minY: group.center.y - group.height / 2,
13265
- maxY: group.center.y + group.height / 2
13266
- };
13267
- bounds = {
13268
- minX: Math.min(bounds.minX, groupBounds.minX),
13269
- maxX: Math.max(bounds.maxX, groupBounds.maxX),
13270
- minY: Math.min(bounds.minY, groupBounds.minY),
13271
- maxY: Math.max(bounds.maxY, groupBounds.maxY)
13272
- };
13273
- }
13402
+ if (pcbGroup?.width && pcbGroup.height) {
13403
+ const groupBounds = {
13404
+ minX: pcbGroup.center.x - pcbGroup.width / 2,
13405
+ maxX: pcbGroup.center.x + pcbGroup.width / 2,
13406
+ minY: pcbGroup.center.y - pcbGroup.height / 2,
13407
+ maxY: pcbGroup.center.y + pcbGroup.height / 2
13408
+ };
13409
+ bounds = {
13410
+ minX: Math.min(bounds.minX, groupBounds.minX),
13411
+ maxX: Math.max(bounds.maxX, groupBounds.maxX),
13412
+ minY: Math.min(bounds.minY, groupBounds.minY),
13413
+ maxY: Math.max(bounds.maxY, groupBounds.maxY)
13414
+ };
13274
13415
  }
13275
13416
  const routedTraceIds = new Set(
13276
13417
  db.pcb_trace.list().map((t) => t.source_trace_id).filter((id) => Boolean(id))
@@ -17760,7 +17901,8 @@ var Group6 = class extends NormalComponent3 {
17760
17901
  db,
17761
17902
  minTraceWidth: this.props.autorouter?.minTraceWidth ?? 0.15,
17762
17903
  nominalTraceWidth: this.props.nominalTraceWidth,
17763
- subcircuit_id: this.subcircuit_id
17904
+ subcircuit_id: this.subcircuit_id,
17905
+ subcircuitComponent: this
17764
17906
  }).simpleRouteJson,
17765
17907
  subcircuit_id: this.subcircuit_id
17766
17908
  }),
@@ -17865,7 +18007,8 @@ var Group6 = class extends NormalComponent3 {
17865
18007
  db,
17866
18008
  minTraceWidth: this.props.autorouter?.minTraceWidth ?? 0.15,
17867
18009
  nominalTraceWidth: this.props.nominalTraceWidth,
17868
- subcircuit_id: this.subcircuit_id
18010
+ subcircuit_id: this.subcircuit_id,
18011
+ subcircuitComponent: this
17869
18012
  });
17870
18013
  if (isAutoJumperPreset) {
17871
18014
  simpleRouteJson.allowJumpers = true;
@@ -19153,7 +19296,7 @@ import { identity as identity5 } from "transformation-matrix";
19153
19296
  var package_default = {
19154
19297
  name: "@tscircuit/core",
19155
19298
  type: "module",
19156
- version: "0.0.1153",
19299
+ version: "0.0.1155",
19157
19300
  types: "dist/index.d.ts",
19158
19301
  main: "dist/index.js",
19159
19302
  module: "dist/index.js",
@@ -19185,7 +19328,7 @@ var package_default = {
19185
19328
  "@biomejs/biome": "^1.8.3",
19186
19329
  "@resvg/resvg-js": "^2.6.2",
19187
19330
  "@tscircuit/alphabet": "0.0.25",
19188
- "@tscircuit/capacity-autorouter": "^0.0.414",
19331
+ "@tscircuit/capacity-autorouter": "^0.0.425",
19189
19332
  "@tscircuit/checks": "0.0.116",
19190
19333
  "@tscircuit/circuit-json-util": "^0.0.92",
19191
19334
  "@tscircuit/common": "^0.0.20",
@@ -19198,7 +19341,7 @@ var package_default = {
19198
19341
  "@tscircuit/math-utils": "^0.0.36",
19199
19342
  "@tscircuit/miniflex": "^0.0.4",
19200
19343
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
19201
- "@tscircuit/props": "^0.0.502",
19344
+ "@tscircuit/props": "^0.0.504",
19202
19345
  "@tscircuit/schematic-match-adapt": "^0.0.16",
19203
19346
  "@tscircuit/schematic-trace-solver": "^v0.0.45",
19204
19347
  "@tscircuit/solver-utils": "^0.0.3",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1154",
4
+ "version": "0.0.1156",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -33,7 +33,7 @@
33
33
  "@biomejs/biome": "^1.8.3",
34
34
  "@resvg/resvg-js": "^2.6.2",
35
35
  "@tscircuit/alphabet": "0.0.25",
36
- "@tscircuit/capacity-autorouter": "^0.0.414",
36
+ "@tscircuit/capacity-autorouter": "^0.0.425",
37
37
  "@tscircuit/checks": "0.0.116",
38
38
  "@tscircuit/circuit-json-util": "^0.0.92",
39
39
  "@tscircuit/common": "^0.0.20",
@@ -46,7 +46,7 @@
46
46
  "@tscircuit/math-utils": "^0.0.36",
47
47
  "@tscircuit/miniflex": "^0.0.4",
48
48
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
49
- "@tscircuit/props": "^0.0.502",
49
+ "@tscircuit/props": "^0.0.504",
50
50
  "@tscircuit/schematic-match-adapt": "^0.0.16",
51
51
  "@tscircuit/schematic-trace-solver": "^v0.0.45",
52
52
  "@tscircuit/solver-utils": "^0.0.3",