@tscircuit/core 0.0.1362 → 0.0.1363

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
@@ -3084,6 +3084,7 @@ declare class Board extends Group<typeof boardProps> implements BoardI, Subcircu
3084
3084
  outlineOffsetY: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
3085
3085
  circuitJson: zod.ZodOptional<zod.ZodArray<zod.ZodAny, "many">>;
3086
3086
  exposedNets: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
3087
+ exposeNets: zod.ZodOptional<zod.ZodBoolean>;
3087
3088
  minTraceWidth: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
3088
3089
  minViaHoleEdgeToViaHoleEdgeClearance: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
3089
3090
  minViaEdgeToPadEdgeClearance: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
@@ -3558,6 +3559,7 @@ declare class Board extends Group<typeof boardProps> implements BoardI, Subcircu
3558
3559
  autorouterVersion?: "v1" | "v2" | "v3" | "v4" | "v5" | "v6" | "latest" | undefined;
3559
3560
  circuitJson?: any[] | undefined;
3560
3561
  exposedNets?: string[] | undefined;
3562
+ exposeNets?: boolean | undefined;
3561
3563
  schAutoLayoutEnabled?: boolean | undefined;
3562
3564
  schTraceAutoLabelEnabled?: boolean | undefined;
3563
3565
  schMaxTraceDistance?: number | undefined;
@@ -3894,6 +3896,7 @@ declare class Board extends Group<typeof boardProps> implements BoardI, Subcircu
3894
3896
  autorouterVersion?: "v1" | "v2" | "v3" | "v4" | "v5" | "v6" | "latest" | undefined;
3895
3897
  circuitJson?: any[] | undefined;
3896
3898
  exposedNets?: string[] | undefined;
3899
+ exposeNets?: boolean | undefined;
3897
3900
  schAutoLayoutEnabled?: boolean | undefined;
3898
3901
  schTraceAutoLabelEnabled?: boolean | undefined;
3899
3902
  schMaxTraceDistance?: string | number | undefined;
@@ -4021,6 +4024,7 @@ declare class Subcircuit extends Group<typeof subcircuitProps> implements Subcir
4021
4024
  doInitialRenderIsolatedSubcircuits(): void;
4022
4025
  doInitialCreateNetsFromProps(): void;
4023
4026
  private _createTracesForExposedNets;
4027
+ private _getNetNamesToExpose;
4024
4028
  /**
4025
4029
  * During this phase, we inflate the subcircuit circuit json into class
4026
4030
  * instances
@@ -4623,6 +4627,7 @@ declare class MountedBoard extends Subcircuit implements BoardI {
4623
4627
  outlineOffsetY: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
4624
4628
  circuitJson: zod.ZodOptional<zod.ZodArray<zod.ZodAny, "many">>;
4625
4629
  exposedNets: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
4630
+ exposeNets: zod.ZodOptional<zod.ZodBoolean>;
4626
4631
  minTraceWidth: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
4627
4632
  minViaHoleEdgeToViaHoleEdgeClearance: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
4628
4633
  minViaEdgeToPadEdgeClearance: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
@@ -5213,6 +5218,7 @@ declare class MountedBoard extends Subcircuit implements BoardI {
5213
5218
  autorouterVersion?: "v1" | "v2" | "v3" | "v4" | "v5" | "v6" | "latest" | undefined;
5214
5219
  circuitJson?: any[] | undefined;
5215
5220
  exposedNets?: string[] | undefined;
5221
+ exposeNets?: boolean | undefined;
5216
5222
  schAutoLayoutEnabled?: boolean | undefined;
5217
5223
  schTraceAutoLabelEnabled?: boolean | undefined;
5218
5224
  schMaxTraceDistance?: number | undefined;
@@ -5572,6 +5578,7 @@ declare class MountedBoard extends Subcircuit implements BoardI {
5572
5578
  autorouterVersion?: "v1" | "v2" | "v3" | "v4" | "v5" | "v6" | "latest" | undefined;
5573
5579
  circuitJson?: any[] | undefined;
5574
5580
  exposedNets?: string[] | undefined;
5581
+ exposeNets?: boolean | undefined;
5575
5582
  schAutoLayoutEnabled?: boolean | undefined;
5576
5583
  schTraceAutoLabelEnabled?: boolean | undefined;
5577
5584
  schMaxTraceDistance?: string | number | undefined;
package/dist/index.js CHANGED
@@ -4327,10 +4327,30 @@ function Trace_doInitialPcbTraceRender(trace) {
4327
4327
  }
4328
4328
  const nets = trace._findConnectedNets().netsWithSelectors;
4329
4329
  if (ports.length === 0 && nets.length === 2) {
4330
- trace.renderError(
4331
- `Trace connects two nets, we haven't implemented a way to route this yet`
4332
- );
4333
- return;
4330
+ const [netA, netB] = nets.map(({ net }) => net);
4331
+ const netAPorts = netA.getAllConnectedPorts();
4332
+ const netBPorts = netB.getAllConnectedPorts();
4333
+ if (netAPorts.length === 0 || netBPorts.length === 0) {
4334
+ console.log(
4335
+ "Nothing to connect this net to, one of the nets is empty. TODO should emit a warning!"
4336
+ );
4337
+ return;
4338
+ }
4339
+ let closestPortPair = [netAPorts[0], netBPorts[0]];
4340
+ let closestDistance = Infinity;
4341
+ for (const netAPort of netAPorts) {
4342
+ const closestNetBPort = getClosest(netAPort, netBPorts);
4343
+ const netAPortPosition = netAPort._getGlobalPcbPositionBeforeLayout();
4344
+ const netBPortPosition = closestNetBPort._getGlobalPcbPositionBeforeLayout();
4345
+ const distance19 = Math.sqrt(
4346
+ (netAPortPosition.x - netBPortPosition.x) ** 2 + (netAPortPosition.y - netBPortPosition.y) ** 2
4347
+ );
4348
+ if (distance19 < closestDistance) {
4349
+ closestDistance = distance19;
4350
+ closestPortPair = [netAPort, closestNetBPort];
4351
+ }
4352
+ }
4353
+ ports.push(...closestPortPair);
4334
4354
  } else if (ports.length === 1 && nets.length === 1) {
4335
4355
  const port = ports[0];
4336
4356
  const portsInNet = nets[0].net.getAllConnectedPorts();
@@ -24286,7 +24306,7 @@ import { identity as identity5 } from "transformation-matrix";
24286
24306
  var package_default = {
24287
24307
  name: "@tscircuit/core",
24288
24308
  type: "module",
24289
- version: "0.0.1361",
24309
+ version: "0.0.1362",
24290
24310
  types: "dist/index.d.ts",
24291
24311
  main: "dist/index.js",
24292
24312
  module: "dist/index.js",
@@ -24335,7 +24355,7 @@ var package_default = {
24335
24355
  "@tscircuit/math-utils": "^0.0.36",
24336
24356
  "@tscircuit/miniflex": "^0.0.4",
24337
24357
  "@tscircuit/ngspice-spice-engine": "^0.0.18",
24338
- "@tscircuit/props": "^0.0.557",
24358
+ "@tscircuit/props": "^0.0.558",
24339
24359
  "@tscircuit/schematic-match-adapt": "^0.0.18",
24340
24360
  "@tscircuit/schematic-trace-solver": "^0.0.72",
24341
24361
  "@tscircuit/solver-utils": "^0.0.16",
@@ -25384,17 +25404,20 @@ var Subcircuit = class extends Group5 {
25384
25404
  this._createTracesForExposedNets();
25385
25405
  }
25386
25406
  _createTracesForExposedNets() {
25387
- const exposedNets = this._parsedProps.exposedNets;
25407
+ const exposedNets = this._getNetNamesToExpose();
25388
25408
  if (!exposedNets?.length) return;
25389
25409
  const parentSubcircuit = this.parent?.getSubcircuit?.();
25390
25410
  if (!parentSubcircuit) return;
25391
25411
  if (!this.name) return;
25392
25412
  for (const exposedNetName of exposedNets) {
25393
25413
  const netName = normalizeExposedNetName(exposedNetName);
25394
- const parentNetSelector = `net.${netName}`;
25414
+ const parentNetSelector = `> net.${netName}`;
25395
25415
  const childNetSelector = `.${this.name} > net.${netName}`;
25396
25416
  const traceName = `exposed_net.${netName}`;
25397
- if (!parentSubcircuit.selectOne(parentNetSelector, { type: "net" })) {
25417
+ const parentHasDirectNet = parentSubcircuit.children.some(
25418
+ (child) => child instanceof Net && child._parsedProps.name === netName
25419
+ );
25420
+ if (!parentHasDirectNet) {
25398
25421
  parentSubcircuit.add(new Net({ name: netName }));
25399
25422
  }
25400
25423
  const existingTrace = parentSubcircuit.children.find(
@@ -25411,6 +25434,12 @@ var Subcircuit = class extends Group5 {
25411
25434
  );
25412
25435
  }
25413
25436
  }
25437
+ _getNetNamesToExpose() {
25438
+ const explicitExposedNets = this._parsedProps.exposedNets ?? [];
25439
+ if (!this._parsedProps.exposeNets) return explicitExposedNets;
25440
+ const childNetNames = this.selectAll("net").filter((net) => net instanceof Net && net.getSubcircuit() === this).map((net) => net._parsedProps.name);
25441
+ return Array.from(/* @__PURE__ */ new Set([...explicitExposedNets, ...childNetNames]));
25442
+ }
25414
25443
  /**
25415
25444
  * During this phase, we inflate the subcircuit circuit json into class
25416
25445
  * instances
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1362",
4
+ "version": "0.0.1363",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -50,7 +50,7 @@
50
50
  "@tscircuit/math-utils": "^0.0.36",
51
51
  "@tscircuit/miniflex": "^0.0.4",
52
52
  "@tscircuit/ngspice-spice-engine": "^0.0.18",
53
- "@tscircuit/props": "^0.0.557",
53
+ "@tscircuit/props": "^0.0.558",
54
54
  "@tscircuit/schematic-match-adapt": "^0.0.18",
55
55
  "@tscircuit/schematic-trace-solver": "^0.0.72",
56
56
  "@tscircuit/solver-utils": "^0.0.16",