@tscircuit/schematic-trace-solver 0.0.11 → 0.0.13

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
@@ -5264,11 +5264,13 @@ var ConnectivityMap = class {
5264
5264
  var getConnectivityMapsFromInputProblem = (inputProblem) => {
5265
5265
  const directConnMap = new ConnectivityMap({});
5266
5266
  for (const directConn of inputProblem.directConnections) {
5267
- directConnMap.addConnections([directConn.pinIds]);
5267
+ directConnMap.addConnections([
5268
+ directConn.netId ? [directConn.netId, ...directConn.pinIds] : directConn.pinIds
5269
+ ]);
5268
5270
  }
5269
5271
  const netConnMap = new ConnectivityMap(directConnMap.netMap);
5270
5272
  for (const netConn of inputProblem.netConnections) {
5271
- netConnMap.addConnections([netConn.pinIds]);
5273
+ netConnMap.addConnections([[netConn.netId, ...netConn.pinIds]]);
5272
5274
  }
5273
5275
  return { directConnMap, netConnMap };
5274
5276
  };
@@ -5481,7 +5483,7 @@ var MspConnectionPairSolver = class extends BaseSolver {
5481
5483
  this.userNetIdByPinId[pid] = nc.netId;
5482
5484
  }
5483
5485
  }
5484
- this.queuedDcNetIds = Object.keys(directConnMap.netMap);
5486
+ this.queuedDcNetIds = Object.keys(netConnMap.netMap);
5485
5487
  }
5486
5488
  getConstructorParams() {
5487
5489
  return {
@@ -5494,8 +5496,9 @@ var MspConnectionPairSolver = class extends BaseSolver {
5494
5496
  return;
5495
5497
  }
5496
5498
  const dcNetId = this.queuedDcNetIds.shift();
5497
- const directlyConnectedPins = this.dcConnMap.getIdsConnectedToNet(dcNetId);
5498
- if (directlyConnectedPins.length === 1) {
5499
+ const allIds = this.globalConnMap.getIdsConnectedToNet(dcNetId);
5500
+ const directlyConnectedPins = allIds.filter((id) => !!this.pinMap[id]);
5501
+ if (directlyConnectedPins.length <= 1) {
5499
5502
  return;
5500
5503
  }
5501
5504
  if (directlyConnectedPins.length === 2) {
@@ -5512,7 +5515,7 @@ var MspConnectionPairSolver = class extends BaseSolver {
5512
5515
  return;
5513
5516
  }
5514
5517
  const msp = getOrthogonalMinimumSpanningTree(
5515
- directlyConnectedPins.map((p) => this.pinMap[p]),
5518
+ directlyConnectedPins.map((p) => this.pinMap[p]).filter(Boolean),
5516
5519
  { maxDistance: this.maxMspPairDistance }
5517
5520
  );
5518
5521
  for (const [pin1, pin2] of msp) {
@@ -7933,7 +7936,26 @@ function getVerticalGuidelineX(chip1Bounds, chip2Bounds) {
7933
7936
  return (overlapMinX + overlapMaxX) / 2;
7934
7937
  }
7935
7938
 
7939
+ // lib/solvers/GuidelinesSolver/getInputProblemBounds.ts
7940
+ var getInputProblemBounds = (inputProblem) => {
7941
+ const bounds = {
7942
+ minX: Infinity,
7943
+ maxX: -Infinity,
7944
+ minY: Infinity,
7945
+ maxY: -Infinity
7946
+ };
7947
+ for (const chip of inputProblem.chips) {
7948
+ const chipBounds = getInputChipBounds(chip);
7949
+ bounds.minX = Math.min(bounds.minX, chipBounds.minX);
7950
+ bounds.maxX = Math.max(bounds.maxX, chipBounds.maxX);
7951
+ bounds.minY = Math.min(bounds.minY, chipBounds.minY);
7952
+ bounds.maxY = Math.max(bounds.maxY, chipBounds.maxY);
7953
+ }
7954
+ return bounds;
7955
+ };
7956
+
7936
7957
  // lib/solvers/GuidelinesSolver/GuidelinesSolver.ts
7958
+ var GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS = 0.1;
7937
7959
  var GuidelinesSolver = class extends BaseSolver {
7938
7960
  inputProblem;
7939
7961
  guidelines;
@@ -7943,7 +7965,29 @@ var GuidelinesSolver = class extends BaseSolver {
7943
7965
  constructor(params) {
7944
7966
  super();
7945
7967
  this.inputProblem = params.inputProblem;
7946
- this.guidelines = [];
7968
+ const inputProblemBounds = getInputProblemBounds(this.inputProblem);
7969
+ this.guidelines = [
7970
+ {
7971
+ orientation: "horizontal",
7972
+ y: inputProblemBounds.minY - GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS,
7973
+ x: void 0
7974
+ },
7975
+ {
7976
+ orientation: "horizontal",
7977
+ y: inputProblemBounds.maxY + GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS,
7978
+ x: void 0
7979
+ },
7980
+ {
7981
+ orientation: "vertical",
7982
+ y: void 0,
7983
+ x: inputProblemBounds.minX - GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS
7984
+ },
7985
+ {
7986
+ orientation: "vertical",
7987
+ y: void 0,
7988
+ x: inputProblemBounds.maxX + GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS
7989
+ }
7990
+ ];
7947
7991
  this.chipPairsGenerator = getGeneratorForAllChipPairs(
7948
7992
  this.inputProblem.chips
7949
7993
  );
@@ -6,6 +6,7 @@ import { getGeneratorForAllChipPairs } from "./getGeneratorForAllChipPairs"
6
6
  import { getInputChipBounds } from "./getInputChipBounds"
7
7
  import { getHorizontalGuidelineY } from "./getHorizontalGuidelineY"
8
8
  import { getVerticalGuidelineX } from "./getVerticalGuidelineX"
9
+ import { getInputProblemBounds } from "./getInputProblemBounds"
9
10
 
10
11
  export type Guideline =
11
12
  | {
@@ -19,6 +20,8 @@ export type Guideline =
19
20
  x: number
20
21
  }
21
22
 
23
+ const GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS = 0.1
24
+
22
25
  export class GuidelinesSolver extends BaseSolver {
23
26
  inputProblem: InputProblem
24
27
  guidelines: Guideline[]
@@ -33,7 +36,29 @@ export class GuidelinesSolver extends BaseSolver {
33
36
  }) {
34
37
  super()
35
38
  this.inputProblem = params.inputProblem
36
- this.guidelines = []
39
+ const inputProblemBounds = getInputProblemBounds(this.inputProblem)
40
+ this.guidelines = [
41
+ {
42
+ orientation: "horizontal",
43
+ y: inputProblemBounds.minY - GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS,
44
+ x: undefined,
45
+ },
46
+ {
47
+ orientation: "horizontal",
48
+ y: inputProblemBounds.maxY + GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS,
49
+ x: undefined,
50
+ },
51
+ {
52
+ orientation: "vertical",
53
+ y: undefined,
54
+ x: inputProblemBounds.minX - GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS,
55
+ },
56
+ {
57
+ orientation: "vertical",
58
+ y: undefined,
59
+ x: inputProblemBounds.maxX + GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS,
60
+ },
61
+ ]
37
62
  this.chipPairsGenerator = getGeneratorForAllChipPairs(
38
63
  this.inputProblem.chips,
39
64
  )
@@ -0,0 +1,19 @@
1
+ import type { InputProblem } from "lib/types/InputProblem"
2
+ import { getInputChipBounds } from "./getInputChipBounds"
3
+
4
+ export const getInputProblemBounds = (inputProblem: InputProblem) => {
5
+ const bounds = {
6
+ minX: Infinity,
7
+ maxX: -Infinity,
8
+ minY: Infinity,
9
+ maxY: -Infinity,
10
+ }
11
+ for (const chip of inputProblem.chips) {
12
+ const chipBounds = getInputChipBounds(chip)
13
+ bounds.minX = Math.min(bounds.minX, chipBounds.minX)
14
+ bounds.maxX = Math.max(bounds.maxX, chipBounds.maxX)
15
+ bounds.minY = Math.min(bounds.minY, chipBounds.minY)
16
+ bounds.maxY = Math.max(bounds.maxY, chipBounds.maxY)
17
+ }
18
+ return bounds
19
+ }
@@ -68,7 +68,7 @@ export class MspConnectionPairSolver extends BaseSolver {
68
68
  }
69
69
  }
70
70
 
71
- this.queuedDcNetIds = Object.keys(directConnMap.netMap)
71
+ this.queuedDcNetIds = Object.keys(netConnMap.netMap)
72
72
  }
73
73
 
74
74
  override getConstructorParams(): ConstructorParameters<
@@ -87,9 +87,10 @@ export class MspConnectionPairSolver extends BaseSolver {
87
87
 
88
88
  const dcNetId = this.queuedDcNetIds.shift()!
89
89
 
90
- const directlyConnectedPins = this.dcConnMap.getIdsConnectedToNet(dcNetId)
90
+ const allIds = this.globalConnMap.getIdsConnectedToNet(dcNetId) as string[]
91
+ const directlyConnectedPins = allIds.filter((id) => !!this.pinMap[id])
91
92
 
92
- if (directlyConnectedPins.length === 1) {
93
+ if (directlyConnectedPins.length <= 1) {
93
94
  return
94
95
  }
95
96
 
@@ -113,7 +114,7 @@ export class MspConnectionPairSolver extends BaseSolver {
113
114
  // There are more than 3 pins, so we need to run MSP to find the best pairs
114
115
 
115
116
  const msp = getOrthogonalMinimumSpanningTree(
116
- directlyConnectedPins.map((p) => this.pinMap[p]!),
117
+ directlyConnectedPins.map((p) => this.pinMap[p]!).filter(Boolean),
117
118
  { maxDistance: this.maxMspPairDistance },
118
119
  )
119
120
 
@@ -7,13 +7,17 @@ export const getConnectivityMapsFromInputProblem = (
7
7
  const directConnMap = new ConnectivityMap({})
8
8
 
9
9
  for (const directConn of inputProblem.directConnections) {
10
- directConnMap.addConnections([directConn.pinIds])
10
+ directConnMap.addConnections([
11
+ directConn.netId
12
+ ? [directConn.netId, ...directConn.pinIds]
13
+ : directConn.pinIds,
14
+ ])
11
15
  }
12
16
 
13
17
  const netConnMap = new ConnectivityMap(directConnMap.netMap)
14
18
 
15
19
  for (const netConn of inputProblem.netConnections) {
16
- netConnMap.addConnections([netConn.pinIds])
20
+ netConnMap.addConnections([[netConn.netId, ...netConn.pinIds]])
17
21
  }
18
22
 
19
23
  return { directConnMap, netConnMap }
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.11",
4
+ "version": "0.0.13",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "cosmos",
@@ -0,0 +1,16 @@
1
+ import { MspConnectionPairSolver } from "lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver"
2
+ import inputParams from "./MspConnectionPairSolver01_params.json"
3
+ import { GenericSolverDebugger } from "site/components/GenericSolverDebugger"
4
+ import { useMemo } from "react"
5
+ import type { InputProblem } from "lib/types/InputProblem"
6
+
7
+ export default () => {
8
+ const solver = useMemo(
9
+ () =>
10
+ new MspConnectionPairSolver({
11
+ inputProblem: inputParams.inputProblem as unknown as InputProblem,
12
+ }),
13
+ [],
14
+ )
15
+ return <GenericSolverDebugger solver={solver} />
16
+ }
@@ -0,0 +1,111 @@
1
+ {
2
+ "inputProblem": {
3
+ "chips": [
4
+ {
5
+ "chipId": "U1",
6
+ "center": {
7
+ "x": 0,
8
+ "y": 0
9
+ },
10
+ "width": 1.6,
11
+ "height": 0.6,
12
+ "pins": [
13
+ {
14
+ "pinId": "U1.1",
15
+ "x": -0.8,
16
+ "y": 0.2
17
+ },
18
+ {
19
+ "pinId": "U1.2",
20
+ "x": -0.8,
21
+ "y": 0
22
+ },
23
+ {
24
+ "pinId": "U1.3",
25
+ "x": -0.8,
26
+ "y": -0.2
27
+ },
28
+ {
29
+ "pinId": "U1.4",
30
+ "x": 0.8,
31
+ "y": -0.2
32
+ },
33
+ {
34
+ "pinId": "U1.5",
35
+ "x": 0.8,
36
+ "y": 0
37
+ },
38
+ {
39
+ "pinId": "U1.6",
40
+ "x": 0.8,
41
+ "y": 0.2
42
+ }
43
+ ]
44
+ },
45
+ {
46
+ "chipId": "C1",
47
+ "center": {
48
+ "x": -2,
49
+ "y": 0
50
+ },
51
+ "width": 0.5,
52
+ "height": 1,
53
+ "pins": [
54
+ {
55
+ "pinId": "C1.1",
56
+ "x": -2,
57
+ "y": 0.5
58
+ },
59
+ {
60
+ "pinId": "C1.2",
61
+ "x": -2,
62
+ "y": -0.5
63
+ }
64
+ ]
65
+ },
66
+ {
67
+ "chipId": "C2",
68
+ "center": {
69
+ "x": -4,
70
+ "y": 0
71
+ },
72
+ "width": 0.5,
73
+ "height": 1,
74
+ "pins": [
75
+ {
76
+ "pinId": "C2.1",
77
+ "x": -4,
78
+ "y": 0.5
79
+ },
80
+ {
81
+ "pinId": "C2.2",
82
+ "x": -4,
83
+ "y": -0.5
84
+ }
85
+ ]
86
+ }
87
+ ],
88
+ "directConnections": [
89
+ {
90
+ "pinIds": ["U1.1", "C1.1"],
91
+ "netId": "VCC"
92
+ },
93
+ {
94
+ "pinIds": ["U1.2", "C2.1"],
95
+ "netId": "EN"
96
+ }
97
+ ],
98
+ "netConnections": [
99
+ {
100
+ "pinIds": ["U1.3", "C2.2", "C1.2"],
101
+ "netId": "GND"
102
+ }
103
+ ],
104
+ "availableNetLabelOrientations": {
105
+ "VCC": ["y+"],
106
+ "EN": ["x+", "x-"],
107
+ "GND": ["y-"]
108
+ },
109
+ "maxMspPairDistance": 2
110
+ }
111
+ }
@@ -0,0 +1,14 @@
1
+ import inputParams from "site/MspConnectionPairSolver/MspConnectionPairSolver01_params.json"
2
+ import { test, expect } from "bun:test"
3
+ import { MspConnectionPairSolver } from "lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver"
4
+ import type { InputProblem } from "lib/types/InputProblem"
5
+
6
+ test("MspConnectionPairSolver_repro1", () => {
7
+ const solver = new MspConnectionPairSolver({
8
+ inputProblem: inputParams.inputProblem as unknown as InputProblem,
9
+ })
10
+
11
+ solver.solve()
12
+
13
+ expect(solver.mspConnectionPairs.length).toBe(4)
14
+ })
@@ -0,0 +1,111 @@
1
+ import type { InputProblem } from "lib/types/InputProblem"
2
+ import { test, expect } from "bun:test"
3
+ import { SchematicTracePipelineSolver } from "lib/index"
4
+
5
+ const inputProblem: InputProblem = {
6
+ chips: [
7
+ {
8
+ chipId: "U1",
9
+ center: { x: 0, y: 0 },
10
+ width: 1.6,
11
+ height: 0.6,
12
+ pins: [
13
+ {
14
+ pinId: "U1.1",
15
+ x: -0.8,
16
+ y: 0.2,
17
+ },
18
+ {
19
+ pinId: "U1.2",
20
+ x: -0.8,
21
+ y: 0,
22
+ },
23
+ {
24
+ pinId: "U1.3",
25
+ x: -0.8,
26
+ y: -0.2,
27
+ },
28
+ {
29
+ pinId: "U1.4",
30
+ x: 0.8,
31
+ y: -0.2,
32
+ },
33
+ {
34
+ pinId: "U1.5",
35
+ x: 0.8,
36
+ y: 0,
37
+ },
38
+ {
39
+ pinId: "U1.6",
40
+ x: 0.8,
41
+ y: 0.2,
42
+ },
43
+ ],
44
+ },
45
+ {
46
+ chipId: "C1",
47
+ center: { x: -2, y: 0 },
48
+ width: 0.5,
49
+ height: 1,
50
+ pins: [
51
+ {
52
+ pinId: "C1.1",
53
+ x: -2,
54
+ y: 0.5,
55
+ },
56
+ {
57
+ pinId: "C1.2",
58
+ x: -2,
59
+ y: -0.5,
60
+ },
61
+ ],
62
+ },
63
+ {
64
+ chipId: "C2",
65
+ center: { x: -4, y: 0 },
66
+ width: 0.5,
67
+ height: 1,
68
+ pins: [
69
+ {
70
+ pinId: "C2.1",
71
+ x: -4,
72
+ y: 0.5,
73
+ },
74
+ {
75
+ pinId: "C2.2",
76
+ x: -4,
77
+ y: -0.5,
78
+ },
79
+ ],
80
+ },
81
+ ],
82
+ directConnections: [
83
+ {
84
+ pinIds: ["U1.1", "C1.1"],
85
+ netId: "VCC",
86
+ },
87
+ {
88
+ pinIds: ["U1.2", "C2.1"],
89
+ netId: "EN",
90
+ },
91
+ ],
92
+ netConnections: [
93
+ {
94
+ pinIds: ["U1.3", "C2.2", "C1.2"],
95
+ netId: "GND",
96
+ },
97
+ ],
98
+ availableNetLabelOrientations: {
99
+ VCC: ["y+"],
100
+ EN: ["x+", "x-"],
101
+ GND: ["y-"],
102
+ },
103
+ maxMspPairDistance: 2,
104
+ }
105
+
106
+ test("SchematicTracePipelineSolver_repro01", () => {
107
+ const solver = new SchematicTracePipelineSolver(inputProblem)
108
+ solver.solve()
109
+
110
+ // console.log(solver.schematicTraceLinesSolver!.solvedTracePaths)
111
+ })