@tscircuit/schematic-trace-solver 0.0.12 → 0.0.14
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 +2 -0
- package/dist/index.js +52 -5
- 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/lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver.ts +8 -1
- 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.d.ts
CHANGED
|
@@ -180,6 +180,8 @@ declare class SchematicTraceSingleLineSolver extends BaseSolver {
|
|
|
180
180
|
|
|
181
181
|
interface SolvedTracePath extends MspConnectionPair {
|
|
182
182
|
tracePath: Point[];
|
|
183
|
+
mspConnectionPairIds: MspConnectionPairId[];
|
|
184
|
+
pinIds: PinId[];
|
|
183
185
|
}
|
|
184
186
|
declare class SchematicTraceLinesSolver extends BaseSolver {
|
|
185
187
|
inputProblem: InputProblem;
|
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) {
|
|
@@ -6852,7 +6853,12 @@ var SchematicTraceLinesSolver = class extends BaseSolver {
|
|
|
6852
6853
|
if (this.activeSubSolver?.solved) {
|
|
6853
6854
|
this.solvedTracePaths.push({
|
|
6854
6855
|
...this.currentConnectionPair,
|
|
6855
|
-
tracePath: this.activeSubSolver.solvedTracePath
|
|
6856
|
+
tracePath: this.activeSubSolver.solvedTracePath,
|
|
6857
|
+
mspConnectionPairIds: [this.currentConnectionPair.mspPairId],
|
|
6858
|
+
pinIds: [
|
|
6859
|
+
this.currentConnectionPair.pins[0].pinId,
|
|
6860
|
+
this.currentConnectionPair.pins[1].pinId
|
|
6861
|
+
]
|
|
6856
6862
|
});
|
|
6857
6863
|
this.activeSubSolver = null;
|
|
6858
6864
|
this.currentConnectionPair = null;
|
|
@@ -7935,7 +7941,26 @@ function getVerticalGuidelineX(chip1Bounds, chip2Bounds) {
|
|
|
7935
7941
|
return (overlapMinX + overlapMaxX) / 2;
|
|
7936
7942
|
}
|
|
7937
7943
|
|
|
7944
|
+
// lib/solvers/GuidelinesSolver/getInputProblemBounds.ts
|
|
7945
|
+
var getInputProblemBounds = (inputProblem) => {
|
|
7946
|
+
const bounds = {
|
|
7947
|
+
minX: Infinity,
|
|
7948
|
+
maxX: -Infinity,
|
|
7949
|
+
minY: Infinity,
|
|
7950
|
+
maxY: -Infinity
|
|
7951
|
+
};
|
|
7952
|
+
for (const chip of inputProblem.chips) {
|
|
7953
|
+
const chipBounds = getInputChipBounds(chip);
|
|
7954
|
+
bounds.minX = Math.min(bounds.minX, chipBounds.minX);
|
|
7955
|
+
bounds.maxX = Math.max(bounds.maxX, chipBounds.maxX);
|
|
7956
|
+
bounds.minY = Math.min(bounds.minY, chipBounds.minY);
|
|
7957
|
+
bounds.maxY = Math.max(bounds.maxY, chipBounds.maxY);
|
|
7958
|
+
}
|
|
7959
|
+
return bounds;
|
|
7960
|
+
};
|
|
7961
|
+
|
|
7938
7962
|
// lib/solvers/GuidelinesSolver/GuidelinesSolver.ts
|
|
7963
|
+
var GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS = 0.1;
|
|
7939
7964
|
var GuidelinesSolver = class extends BaseSolver {
|
|
7940
7965
|
inputProblem;
|
|
7941
7966
|
guidelines;
|
|
@@ -7945,7 +7970,29 @@ var GuidelinesSolver = class extends BaseSolver {
|
|
|
7945
7970
|
constructor(params) {
|
|
7946
7971
|
super();
|
|
7947
7972
|
this.inputProblem = params.inputProblem;
|
|
7948
|
-
|
|
7973
|
+
const inputProblemBounds = getInputProblemBounds(this.inputProblem);
|
|
7974
|
+
this.guidelines = [
|
|
7975
|
+
{
|
|
7976
|
+
orientation: "horizontal",
|
|
7977
|
+
y: inputProblemBounds.minY - GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS,
|
|
7978
|
+
x: void 0
|
|
7979
|
+
},
|
|
7980
|
+
{
|
|
7981
|
+
orientation: "horizontal",
|
|
7982
|
+
y: inputProblemBounds.maxY + GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS,
|
|
7983
|
+
x: void 0
|
|
7984
|
+
},
|
|
7985
|
+
{
|
|
7986
|
+
orientation: "vertical",
|
|
7987
|
+
y: void 0,
|
|
7988
|
+
x: inputProblemBounds.minX - GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS
|
|
7989
|
+
},
|
|
7990
|
+
{
|
|
7991
|
+
orientation: "vertical",
|
|
7992
|
+
y: void 0,
|
|
7993
|
+
x: inputProblemBounds.maxX + GUIDELINE_PADDING_FROM_PROBLEM_BOUNDS
|
|
7994
|
+
}
|
|
7995
|
+
];
|
|
7949
7996
|
this.chipPairsGenerator = getGeneratorForAllChipPairs(
|
|
7950
7997
|
this.inputProblem.chips
|
|
7951
7998
|
);
|
|
@@ -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
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseSolver } from "lib/solvers/BaseSolver/BaseSolver"
|
|
2
2
|
import { visualizeInputProblem } from "../SchematicTracePipelineSolver/visualizeInputProblem"
|
|
3
3
|
import { getBounds, type GraphicsObject } from "graphics-debug"
|
|
4
|
-
import type { InputChip, InputProblem } from "lib/types/InputProblem"
|
|
4
|
+
import type { InputChip, InputProblem, PinId } from "lib/types/InputProblem"
|
|
5
5
|
import type {
|
|
6
6
|
MspConnectionPair,
|
|
7
7
|
MspConnectionPairId,
|
|
@@ -14,6 +14,8 @@ import type { Point } from "@tscircuit/math-utils"
|
|
|
14
14
|
|
|
15
15
|
export interface SolvedTracePath extends MspConnectionPair {
|
|
16
16
|
tracePath: Point[]
|
|
17
|
+
mspConnectionPairIds: MspConnectionPairId[]
|
|
18
|
+
pinIds: PinId[]
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export class SchematicTraceLinesSolver extends BaseSolver {
|
|
@@ -71,6 +73,11 @@ export class SchematicTraceLinesSolver extends BaseSolver {
|
|
|
71
73
|
this.solvedTracePaths.push({
|
|
72
74
|
...this.currentConnectionPair!,
|
|
73
75
|
tracePath: this.activeSubSolver!.solvedTracePath!,
|
|
76
|
+
mspConnectionPairIds: [this.currentConnectionPair!.mspPairId],
|
|
77
|
+
pinIds: [
|
|
78
|
+
this.currentConnectionPair!.pins[0].pinId,
|
|
79
|
+
this.currentConnectionPair!.pins[1].pinId,
|
|
80
|
+
],
|
|
74
81
|
})
|
|
75
82
|
this.activeSubSolver = null
|
|
76
83
|
this.currentConnectionPair = null
|
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
|
+
})
|