@tscircuit/schematic-trace-solver 0.0.22 → 0.0.23

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.js CHANGED
@@ -5503,6 +5503,12 @@ var MspConnectionPairSolver = class extends BaseSolver {
5503
5503
  }
5504
5504
  if (directlyConnectedPins.length === 2) {
5505
5505
  const [pin1, pin2] = directlyConnectedPins;
5506
+ const p1 = this.pinMap[pin1];
5507
+ const p2 = this.pinMap[pin2];
5508
+ const manhattanDist = Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y);
5509
+ if (manhattanDist > this.maxMspPairDistance) {
5510
+ return;
5511
+ }
5506
5512
  const globalConnNetId = this.globalConnMap.getNetConnectedToId(pin1);
5507
5513
  const userNetId = this.userNetIdByPinId[pin1] ?? this.userNetIdByPinId[pin2];
5508
5514
  this.mspConnectionPairs.push({
@@ -5510,7 +5516,7 @@ var MspConnectionPairSolver = class extends BaseSolver {
5510
5516
  dcConnNetId: dcNetId,
5511
5517
  globalConnNetId,
5512
5518
  userNetId,
5513
- pins: [this.pinMap[pin1], this.pinMap[pin2]]
5519
+ pins: [p1, p2]
5514
5520
  });
5515
5521
  return;
5516
5522
  }
@@ -96,6 +96,15 @@ export class MspConnectionPairSolver extends BaseSolver {
96
96
 
97
97
  if (directlyConnectedPins.length === 2) {
98
98
  const [pin1, pin2] = directlyConnectedPins
99
+ const p1 = this.pinMap[pin1!]!
100
+ const p2 = this.pinMap[pin2!]!
101
+ // Enforce max pair distance (use Manhattan to match orthogonal routing metric)
102
+ const manhattanDist = Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y)
103
+ if (manhattanDist > this.maxMspPairDistance) {
104
+ // Too far apart; skip creating an MSP pair for this net
105
+ return
106
+ }
107
+
99
108
  const globalConnNetId = this.globalConnMap.getNetConnectedToId(pin1!)!
100
109
  const userNetId =
101
110
  this.userNetIdByPinId[pin1!] ?? this.userNetIdByPinId[pin2!]
@@ -105,7 +114,7 @@ export class MspConnectionPairSolver extends BaseSolver {
105
114
  dcConnNetId: dcNetId,
106
115
  globalConnNetId,
107
116
  userNetId,
108
- pins: [this.pinMap[pin1!]!, this.pinMap[pin2!]!],
117
+ pins: [p1, p2],
109
118
  })
110
119
 
111
120
  return
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/schematic-trace-solver",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.22",
4
+ "version": "0.0.23",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "cosmos",
@@ -106,6 +106,6 @@
106
106
  "EN": ["x+", "x-"],
107
107
  "GND": ["y-"]
108
108
  },
109
- "maxMspPairDistance": 2
109
+ "maxMspPairDistance": 5
110
110
  }
111
111
  }
@@ -99,7 +99,7 @@ const inputProblem: InputProblem = {
99
99
  EN: ["x+", "x-"],
100
100
  GND: ["y-"],
101
101
  },
102
- maxMspPairDistance: 2,
102
+ maxMspPairDistance: 5,
103
103
  }
104
104
 
105
105
  export default () => <PipelineDebugger inputProblem={inputProblem} />
@@ -174,7 +174,7 @@ const inputProblem: InputProblem = {
174
174
  ],
175
175
  netConnections: [],
176
176
  availableNetLabelOrientations: {},
177
- maxMspPairDistance: 2,
177
+ maxMspPairDistance: 10,
178
178
  }
179
179
 
180
180
  export default function Example05Page() {
@@ -54,7 +54,7 @@ const inputProblem: InputProblem = {
54
54
  ],
55
55
  netConnections: [],
56
56
  availableNetLabelOrientations: {},
57
- maxMspPairDistance: 2,
57
+ maxMspPairDistance: 10,
58
58
  }
59
59
 
60
60
  export default () => <PipelineDebugger inputProblem={inputProblem} />
@@ -0,0 +1,78 @@
1
+ import { PipelineDebugger } from "site/components/PipelineDebugger"
2
+ import type { InputProblem } from "lib/types/InputProblem"
3
+
4
+ const inputProblem: InputProblem = {
5
+ chips: [
6
+ {
7
+ chipId: "schematic_component_0",
8
+ center: {
9
+ x: -2,
10
+ y: 0,
11
+ },
12
+ width: 0.8122621299999988,
13
+ height: 1.1038501999999986,
14
+ pins: [
15
+ {
16
+ pinId: "Q1_NPN.1",
17
+ x: -2.2855604555,
18
+ y: -0.5519250999999993,
19
+ },
20
+ {
21
+ pinId: "Q1_NPN.2",
22
+ x: -2.2855604555000015,
23
+ y: 0.5519250999999993,
24
+ },
25
+ {
26
+ pinId: "Q1_NPN.3",
27
+ x: -1.5938689350000006,
28
+ y: 0.004526300000001031,
29
+ },
30
+ ],
31
+ },
32
+ {
33
+ chipId: "schematic_component_1",
34
+ center: {
35
+ x: 3.5,
36
+ y: 0,
37
+ },
38
+ width: 0.8122621299999988,
39
+ height: 1.1038501999999986,
40
+ pins: [
41
+ {
42
+ pinId: "Q2_PNP.1",
43
+ x: 3.2144395445,
44
+ y: -0.5519250999999993,
45
+ },
46
+ {
47
+ pinId: "Q2_PNP.2",
48
+ x: 3.2144395444999985,
49
+ y: 0.5519250999999993,
50
+ },
51
+ {
52
+ pinId: "Q2_PNP.3",
53
+ x: 3.9061310649999994,
54
+ y: 0.004526300000001031,
55
+ },
56
+ ],
57
+ },
58
+ ],
59
+ directConnections: [],
60
+ netConnections: [
61
+ {
62
+ netId: "collector",
63
+ pinIds: ["Q1_NPN.1", "Q2_PNP.1"],
64
+ },
65
+ {
66
+ netId: "emitter",
67
+ pinIds: ["Q1_NPN.2", "Q2_PNP.2"],
68
+ },
69
+ {
70
+ netId: "base",
71
+ pinIds: ["Q1_NPN.3", "Q2_PNP.3"],
72
+ },
73
+ ],
74
+ availableNetLabelOrientations: {},
75
+ maxMspPairDistance: 2,
76
+ }
77
+
78
+ export default () => <PipelineDebugger inputProblem={inputProblem} />
@@ -0,0 +1,92 @@
1
+ import { MspConnectionPairSolver } from "lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver"
2
+ import { test, expect } from "bun:test"
3
+
4
+ test("MspConnectionPairSolver should solve problem correctly", () => {
5
+ const input = {
6
+ inputProblem: {
7
+ chips: [
8
+ {
9
+ chipId: "schematic_component_0",
10
+ center: {
11
+ x: -2,
12
+ y: 0,
13
+ },
14
+ width: 0.8122621299999988,
15
+ height: 1.1038501999999986,
16
+ pins: [
17
+ {
18
+ pinId: "Q1_NPN.1",
19
+ x: -2.2855604555,
20
+ y: -0.5519250999999993,
21
+ },
22
+ {
23
+ pinId: "Q1_NPN.2",
24
+ x: -2.2855604555000015,
25
+ y: 0.5519250999999993,
26
+ },
27
+ {
28
+ pinId: "Q1_NPN.3",
29
+ x: -1.5938689350000006,
30
+ y: 0.004526300000001031,
31
+ },
32
+ ],
33
+ },
34
+ {
35
+ chipId: "schematic_component_1",
36
+ center: {
37
+ x: 3.5,
38
+ y: 0,
39
+ },
40
+ width: 0.8122621299999988,
41
+ height: 1.1038501999999986,
42
+ pins: [
43
+ {
44
+ pinId: "Q2_PNP.1",
45
+ x: 3.2144395445,
46
+ y: -0.5519250999999993,
47
+ },
48
+ {
49
+ pinId: "Q2_PNP.2",
50
+ x: 3.2144395444999985,
51
+ y: 0.5519250999999993,
52
+ },
53
+ {
54
+ pinId: "Q2_PNP.3",
55
+ x: 3.9061310649999994,
56
+ y: 0.004526300000001031,
57
+ },
58
+ ],
59
+ },
60
+ ],
61
+ directConnections: [],
62
+ netConnections: [
63
+ {
64
+ netId: "collector",
65
+ pinIds: ["Q1_NPN.1", "Q2_PNP.1"],
66
+ },
67
+ {
68
+ netId: "emitter",
69
+ pinIds: ["Q1_NPN.2", "Q2_PNP.2"],
70
+ },
71
+ {
72
+ netId: "base",
73
+ pinIds: ["Q1_NPN.3", "Q2_PNP.3"],
74
+ },
75
+ ],
76
+ availableNetLabelOrientations: {},
77
+ maxMspPairDistance: 2,
78
+ },
79
+ }
80
+
81
+ const solver = new MspConnectionPairSolver(input as any)
82
+ solver.solve()
83
+
84
+ for (const { pins } of solver.mspConnectionPairs) {
85
+ const [pin1, pin2] = pins
86
+ const dist = Math.sqrt((pin1.x - pin2.x) ** 2 + (pin1.y - pin2.y) ** 2)
87
+ expect(dist).toBeLessThan(input.inputProblem.maxMspPairDistance)
88
+ }
89
+
90
+ // Add more specific assertions based on expected output
91
+ // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
92
+ })