@tscircuit/schematic-trace-solver 0.0.12 → 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 +46 -4
- package/lib/solvers/GuidelinesSolver/GuidelinesSolver.ts +26 -1
- package/lib/solvers/GuidelinesSolver/getInputProblemBounds.ts +19 -0
- package/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts +4 -3
- package/package.json +1 -1
- package/site/MspConnectionPairSolver/MspConnectionPairSolver01.page.tsx +16 -0
- package/site/MspConnectionPairSolver/MspConnectionPairSolver01_params.json +111 -0
- package/tests/solvers/MspConnectionPairSolver/MspConnectionPairSolver_repro1.test.ts +14 -0
package/dist/index.js
CHANGED
|
@@ -5483,7 +5483,7 @@ var MspConnectionPairSolver = class extends BaseSolver {
|
|
|
5483
5483
|
this.userNetIdByPinId[pid] = nc.netId;
|
|
5484
5484
|
}
|
|
5485
5485
|
}
|
|
5486
|
-
this.queuedDcNetIds = Object.keys(
|
|
5486
|
+
this.queuedDcNetIds = Object.keys(netConnMap.netMap);
|
|
5487
5487
|
}
|
|
5488
5488
|
getConstructorParams() {
|
|
5489
5489
|
return {
|
|
@@ -5496,8 +5496,9 @@ var MspConnectionPairSolver = class extends BaseSolver {
|
|
|
5496
5496
|
return;
|
|
5497
5497
|
}
|
|
5498
5498
|
const dcNetId = this.queuedDcNetIds.shift();
|
|
5499
|
-
const
|
|
5500
|
-
|
|
5499
|
+
const allIds = this.globalConnMap.getIdsConnectedToNet(dcNetId);
|
|
5500
|
+
const directlyConnectedPins = allIds.filter((id) => !!this.pinMap[id]);
|
|
5501
|
+
if (directlyConnectedPins.length <= 1) {
|
|
5501
5502
|
return;
|
|
5502
5503
|
}
|
|
5503
5504
|
if (directlyConnectedPins.length === 2) {
|
|
@@ -7935,7 +7936,26 @@ function getVerticalGuidelineX(chip1Bounds, chip2Bounds) {
|
|
|
7935
7936
|
return (overlapMinX + overlapMaxX) / 2;
|
|
7936
7937
|
}
|
|
7937
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
|
+
|
|
7938
7957
|
// lib/solvers/GuidelinesSolver/GuidelinesSolver.ts
|
|
7958
|
+
var GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS = 0.1;
|
|
7939
7959
|
var GuidelinesSolver = class extends BaseSolver {
|
|
7940
7960
|
inputProblem;
|
|
7941
7961
|
guidelines;
|
|
@@ -7945,7 +7965,29 @@ var GuidelinesSolver = class extends BaseSolver {
|
|
|
7945
7965
|
constructor(params) {
|
|
7946
7966
|
super();
|
|
7947
7967
|
this.inputProblem = params.inputProblem;
|
|
7948
|
-
|
|
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
|
+
];
|
|
7949
7991
|
this.chipPairsGenerator = getGeneratorForAllChipPairs(
|
|
7950
7992
|
this.inputProblem.chips
|
|
7951
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
|
-
|
|
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(
|
|
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
|
|
90
|
+
const allIds = this.globalConnMap.getIdsConnectedToNet(dcNetId) as string[]
|
|
91
|
+
const directlyConnectedPins = allIds.filter((id) => !!this.pinMap[id])
|
|
91
92
|
|
|
92
|
-
if (directlyConnectedPins.length
|
|
93
|
+
if (directlyConnectedPins.length <= 1) {
|
|
93
94
|
return
|
|
94
95
|
}
|
|
95
96
|
|
package/package.json
CHANGED
|
@@ -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
|
+
})
|