@tscircuit/schematic-trace-solver 0.0.36 → 0.0.38

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.
Files changed (36) hide show
  1. package/dist/index.d.ts +26 -1
  2. package/dist/index.js +936 -23
  3. package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2.ts +15 -3
  4. package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/collisions.ts +17 -0
  5. package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/pathOps.ts +31 -12
  6. package/lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver.ts +40 -0
  7. package/lib/solvers/TraceLabelOverlapAvoidanceSolver/TraceLabelOverlapAvoidanceSolver.ts +247 -0
  8. package/lib/solvers/TraceLabelOverlapAvoidanceSolver/balanceLShapes.ts +207 -0
  9. package/lib/solvers/TraceLabelOverlapAvoidanceSolver/countTurns.ts +18 -0
  10. package/lib/solvers/TraceLabelOverlapAvoidanceSolver/detectTraceLabelOverlap.ts +38 -0
  11. package/lib/solvers/TraceLabelOverlapAvoidanceSolver/hasCollisions.ts +26 -0
  12. package/lib/solvers/TraceLabelOverlapAvoidanceSolver/index.ts +1 -0
  13. package/lib/solvers/TraceLabelOverlapAvoidanceSolver/rerouteCollidingTrace.ts +73 -0
  14. package/lib/solvers/TraceLabelOverlapAvoidanceSolver/simplifyPath.ts +41 -0
  15. package/lib/solvers/TraceLabelOverlapAvoidanceSolver/trySnipAndReconnect.ts +229 -0
  16. package/lib/solvers/TraceLabelOverlapAvoidanceSolver/turnMinimization.ts +305 -0
  17. package/lib/solvers/TraceLabelOverlapAvoidanceSolver/violation.ts +25 -0
  18. package/package.json +1 -1
  19. package/site/examples/example20.page.tsx +103 -0
  20. package/site/examples/example21.page.tsx +177 -0
  21. package/site/examples/example22.page.tsx +108 -0
  22. package/site/examples/example23.page.tsx +137 -0
  23. package/site/examples/example24.page.tsx +128 -0
  24. package/tests/examples/__snapshots__/example16.snap.svg +27 -27
  25. package/tests/examples/__snapshots__/example21.snap.svg +272 -0
  26. package/tests/examples/__snapshots__/example22.snap.svg +137 -0
  27. package/tests/examples/__snapshots__/example23.snap.svg +137 -0
  28. package/tests/examples/__snapshots__/example24.snap.svg +143 -0
  29. package/tests/examples/__snapshots__/example25.snap.svg +165 -0
  30. package/tests/examples/__snapshots__/example26.snap.svg +157 -0
  31. package/tests/examples/example21.test.tsx +183 -0
  32. package/tests/examples/example22.test.tsx +109 -0
  33. package/tests/examples/example23.test.tsx +109 -0
  34. package/tests/examples/example24.test.tsx +114 -0
  35. package/tests/examples/example25.test.tsx +143 -0
  36. package/tests/examples/example26.test.tsx +134 -0
@@ -0,0 +1,109 @@
1
+ import { expect } from "bun:test"
2
+ import { test } from "bun:test"
3
+ import { SchematicTracePipelineSolver, type InputProblem } from "lib/index"
4
+ import "tests/fixtures/matcher"
5
+
6
+ const inputProblem = {
7
+ chips: [
8
+ {
9
+ chipId: "schematic_component_0",
10
+ center: {
11
+ x: 0,
12
+ y: 0,
13
+ },
14
+ width: 2.4000000000000004,
15
+ height: 1,
16
+ pins: [
17
+ {
18
+ pinId: "U1.1",
19
+ x: 1.2000000000000002,
20
+ y: -0.30000000000000004,
21
+ },
22
+ {
23
+ pinId: "U1.2",
24
+ x: -1.2000000000000002,
25
+ y: -0.30000000000000004,
26
+ },
27
+ {
28
+ pinId: "U1.3",
29
+ x: 1.2000000000000002,
30
+ y: 0.09999999999999998,
31
+ },
32
+ {
33
+ pinId: "U1.4",
34
+ x: -1.2000000000000002,
35
+ y: 0.30000000000000004,
36
+ },
37
+ {
38
+ pinId: "U1.5",
39
+ x: -1.2000000000000002,
40
+ y: 0.10000000000000003,
41
+ },
42
+ {
43
+ pinId: "U1.6",
44
+ x: -1.2000000000000002,
45
+ y: -0.09999999999999998,
46
+ },
47
+ {
48
+ pinId: "U1.7",
49
+ x: 1.2000000000000002,
50
+ y: -0.10000000000000003,
51
+ },
52
+ {
53
+ pinId: "U1.8",
54
+ x: 1.2000000000000002,
55
+ y: 0.30000000000000004,
56
+ },
57
+ ],
58
+ },
59
+ {
60
+ chipId: "schematic_component_1",
61
+ center: {
62
+ x: 2.7,
63
+ y: 1.9049999999999998,
64
+ },
65
+ width: 2.2,
66
+ height: 0.8,
67
+ pins: [
68
+ {
69
+ pinId: "J1.1",
70
+ x: 1.6,
71
+ y: 2.105,
72
+ },
73
+ {
74
+ pinId: "J1.2",
75
+ x: 1.6,
76
+ y: 1.9049999999999998,
77
+ },
78
+ {
79
+ pinId: "J1.3",
80
+ x: 1.6,
81
+ y: 1.7049999999999998,
82
+ },
83
+ ],
84
+ },
85
+ ],
86
+ directConnections: [],
87
+ netConnections: [
88
+ {
89
+ netId: "GND",
90
+ pinIds: ["U1.1", "J1.3"],
91
+ },
92
+ {
93
+ netId: "VCC",
94
+ pinIds: ["U1.8", "J1.1"],
95
+ },
96
+ ],
97
+ availableNetLabelOrientations: {
98
+ VCC: ["y+"],
99
+ OUT: ["x-", "x+"],
100
+ GND: ["y-"],
101
+ },
102
+ maxMspPairDistance: 2.4,
103
+ } as InputProblem
104
+
105
+ test("example22", () => {
106
+ const solver = new SchematicTracePipelineSolver(inputProblem)
107
+ solver.solve()
108
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
109
+ })
@@ -0,0 +1,109 @@
1
+ import { expect } from "bun:test"
2
+ import { test } from "bun:test"
3
+ import { SchematicTracePipelineSolver, type InputProblem } from "lib/index"
4
+ import "tests/fixtures/matcher"
5
+
6
+ const inputProblem = {
7
+ chips: [
8
+ {
9
+ chipId: "schematic_component_0",
10
+ center: {
11
+ x: 0,
12
+ y: 0,
13
+ },
14
+ width: 2.4000000000000004,
15
+ height: 1,
16
+ pins: [
17
+ {
18
+ pinId: "U1.1",
19
+ x: 1.2000000000000002,
20
+ y: -0.30000000000000004,
21
+ },
22
+ {
23
+ pinId: "U1.2",
24
+ x: -1.2000000000000002,
25
+ y: -0.30000000000000004,
26
+ },
27
+ {
28
+ pinId: "U1.3",
29
+ x: 1.2000000000000002,
30
+ y: 0.09999999999999998,
31
+ },
32
+ {
33
+ pinId: "U1.4",
34
+ x: -1.2000000000000002,
35
+ y: 0.30000000000000004,
36
+ },
37
+ {
38
+ pinId: "U1.5",
39
+ x: -1.2000000000000002,
40
+ y: 0.10000000000000003,
41
+ },
42
+ {
43
+ pinId: "U1.6",
44
+ x: -1.2000000000000002,
45
+ y: -0.09999999999999998,
46
+ },
47
+ {
48
+ pinId: "U1.7",
49
+ x: 1.2000000000000002,
50
+ y: -0.10000000000000003,
51
+ },
52
+ {
53
+ pinId: "U1.8",
54
+ x: 1.2000000000000002,
55
+ y: 0.30000000000000004,
56
+ },
57
+ ],
58
+ },
59
+ {
60
+ chipId: "schematic_component_1",
61
+ center: {
62
+ x: 2.7,
63
+ y: -2.0950000000000002, // Moved below component 0
64
+ },
65
+ width: 2.2,
66
+ height: 0.8,
67
+ pins: [
68
+ {
69
+ pinId: "J1.1",
70
+ x: 1.6,
71
+ y: -1.895, // Adjusted y position
72
+ },
73
+ {
74
+ pinId: "J1.2",
75
+ x: 1.6,
76
+ y: -2.0950000000000002, // Adjusted y position
77
+ },
78
+ {
79
+ pinId: "J1.3",
80
+ x: 1.6,
81
+ y: -2.295, // Adjusted y position
82
+ },
83
+ ],
84
+ },
85
+ ],
86
+ directConnections: [],
87
+ netConnections: [
88
+ {
89
+ netId: "GND",
90
+ pinIds: ["U1.1", "J1.3"], // U1.1 connects to J1.3
91
+ },
92
+ {
93
+ netId: "VCC",
94
+ pinIds: ["U1.8", "J1.1"], // U1.8 connects to J1.1
95
+ },
96
+ ],
97
+ availableNetLabelOrientations: {
98
+ VCC: ["y-"], // Changed to y- since trace now goes downward
99
+ OUT: ["x-", "x+"],
100
+ GND: ["y-"], // Changed to y- since trace now goes downward
101
+ },
102
+ maxMspPairDistance: 2.4,
103
+ } as InputProblem
104
+
105
+ test("example23", () => {
106
+ const solver = new SchematicTracePipelineSolver(inputProblem)
107
+ solver.solve()
108
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
109
+ })
@@ -0,0 +1,114 @@
1
+ import { expect } from "bun:test"
2
+ import { test } from "bun:test"
3
+ import { SchematicTracePipelineSolver, type InputProblem } from "lib/index"
4
+ import "tests/fixtures/matcher"
5
+
6
+ const inputProblem = {
7
+ chips: [
8
+ {
9
+ chipId: "schematic_component_0",
10
+ center: {
11
+ x: 0,
12
+ y: 0,
13
+ },
14
+ width: 2.4000000000000004,
15
+ height: 1,
16
+ pins: [
17
+ {
18
+ pinId: "U1.1",
19
+ x: 1.2000000000000002,
20
+ y: -0.30000000000000004,
21
+ },
22
+ {
23
+ pinId: "U1.2",
24
+ x: -1.2000000000000002,
25
+ y: -0.30000000000000004,
26
+ },
27
+ {
28
+ pinId: "U1.3",
29
+ x: 1.2000000000000002,
30
+ y: 0.09999999999999998,
31
+ },
32
+ {
33
+ pinId: "U1.4",
34
+ x: -1.2000000000000002,
35
+ y: 0.30000000000000004,
36
+ },
37
+ {
38
+ pinId: "U1.5",
39
+ x: -1.2000000000000002,
40
+ y: 0.10000000000000003,
41
+ },
42
+ {
43
+ pinId: "U1.6",
44
+ x: -1.2000000000000002,
45
+ y: -0.09999999999999998,
46
+ },
47
+ {
48
+ pinId: "U1.7",
49
+ x: 1.2000000000000002,
50
+ y: -0.10000000000000003,
51
+ },
52
+ {
53
+ pinId: "U1.8",
54
+ x: 1.2000000000000002,
55
+ y: 0.30000000000000004,
56
+ },
57
+ ],
58
+ },
59
+ {
60
+ chipId: "schematic_component_1",
61
+ center: {
62
+ x: 2.7,
63
+ y: -2.0950000000000002, // Moved below component 0
64
+ },
65
+ width: 2.2,
66
+ height: 0.8,
67
+ pins: [
68
+ {
69
+ pinId: "J1.1",
70
+ x: 1.6,
71
+ y: -1.895, // Adjusted y position
72
+ },
73
+ {
74
+ pinId: "J1.2",
75
+ x: 1.6,
76
+ y: -2.0950000000000002, // Adjusted y position
77
+ },
78
+ {
79
+ pinId: "J1.3",
80
+ x: 1.6,
81
+ y: -2.295, // Adjusted y position
82
+ },
83
+ ],
84
+ },
85
+ ],
86
+ directConnections: [],
87
+ netConnections: [
88
+ {
89
+ netId: "GND",
90
+ pinIds: ["U1.1", "J1.3"], // U1.1 connects to J1.3
91
+ },
92
+ {
93
+ netId: "VCC",
94
+ pinIds: ["U1.8", "J1.1"], // U1.8 connects to J1.1
95
+ },
96
+ {
97
+ netId: "MMM",
98
+ pinIds: ["J1.2"], // U1.8 connects to J1.1
99
+ },
100
+ ],
101
+ availableNetLabelOrientations: {
102
+ VCC: ["y-"], // Changed to y- since trace now goes downward
103
+ OUT: ["x-", "x+"],
104
+ GND: ["y-"], // Changed to y- since trace now goes downward
105
+ MMM: ["x+", "x-"],
106
+ },
107
+ maxMspPairDistance: 2.4,
108
+ } as InputProblem
109
+
110
+ test("example24", () => {
111
+ const solver = new SchematicTracePipelineSolver(inputProblem)
112
+ solver.solve()
113
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
114
+ })
@@ -0,0 +1,143 @@
1
+ import { expect } from "bun:test"
2
+ import { test } from "bun:test"
3
+ import { SchematicTracePipelineSolver, type InputProblem } from "lib/index"
4
+ import "tests/fixtures/matcher"
5
+
6
+ const inputProblem = {
7
+ chips: [
8
+ {
9
+ chipId: "schematic_component_0",
10
+ center: {
11
+ x: -3,
12
+ y: 0,
13
+ },
14
+ width: 2.4000000000000004,
15
+ height: 1,
16
+ pins: [
17
+ {
18
+ pinId: "U1.1",
19
+ x: -1.8,
20
+ y: -0.30000000000000004,
21
+ },
22
+ {
23
+ pinId: "U1.2",
24
+ x: -4.2,
25
+ y: -0.30000000000000004,
26
+ },
27
+ {
28
+ pinId: "U1.3",
29
+ x: -1.8,
30
+ y: 0.09999999999999998,
31
+ },
32
+ {
33
+ pinId: "U1.4",
34
+ x: -4.2,
35
+ y: 0.30000000000000004,
36
+ },
37
+ {
38
+ pinId: "U1.5",
39
+ x: -4.2,
40
+ y: 0.10000000000000003,
41
+ },
42
+ {
43
+ pinId: "U1.6",
44
+ x: -4.2,
45
+ y: -0.09999999999999998,
46
+ },
47
+ {
48
+ pinId: "U1.7",
49
+ x: -1.8,
50
+ y: -0.10000000000000003,
51
+ },
52
+ {
53
+ pinId: "U1.8",
54
+ x: -1.8,
55
+ y: 0.30000000000000004,
56
+ },
57
+ ],
58
+ },
59
+ {
60
+ chipId: "schematic_component_1",
61
+ center: {
62
+ x: 3,
63
+ y: 0,
64
+ },
65
+ width: 2.2,
66
+ height: 0.8,
67
+ pins: [
68
+ {
69
+ pinId: "J1.1",
70
+ x: 1.9,
71
+ y: 0.2,
72
+ },
73
+ {
74
+ pinId: "J1.2",
75
+ x: 1.9,
76
+ y: 0,
77
+ },
78
+ {
79
+ pinId: "J1.3",
80
+ x: 1.9,
81
+ y: -0.2,
82
+ },
83
+ ],
84
+ },
85
+ {
86
+ chipId: "schematic_component_2",
87
+ center: {
88
+ x: 0,
89
+ y: -2, // Moved down so component body doesn't block horizontal traces
90
+ },
91
+ width: 1.2,
92
+ height: 3,
93
+ pins: [
94
+ {
95
+ pinId: "U2.1",
96
+ x: -0.4,
97
+ y: -0.5, // Top pin
98
+ },
99
+ {
100
+ pinId: "U2.2",
101
+ x: 0.4,
102
+ y: -0.6,
103
+ },
104
+ {
105
+ pinId: "U2.3",
106
+ x: -0.4,
107
+ y: -2.8, // Bottom pin
108
+ },
109
+ {
110
+ pinId: "U2.4",
111
+ x: 0.4,
112
+ y: -2.8,
113
+ },
114
+ ],
115
+ },
116
+ ],
117
+ directConnections: [
118
+ {
119
+ pinIds: ["U1.1", "J1.3"],
120
+ },
121
+ {
122
+ pinIds: ["U1.8", "J1.1"],
123
+ },
124
+ ],
125
+ netConnections: [
126
+ {
127
+ netId: "SIGNAL1",
128
+ pinIds: ["U2.2"],
129
+ },
130
+ {
131
+ netId: "SIGNAL2",
132
+ pinIds: ["U2.1"],
133
+ },
134
+ ],
135
+ availableNetLabelOrientations: {},
136
+ maxMspPairDistance: 6.5,
137
+ } as InputProblem
138
+
139
+ test("example25", () => {
140
+ const solver = new SchematicTracePipelineSolver(inputProblem)
141
+ solver.solve()
142
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
143
+ })
@@ -0,0 +1,134 @@
1
+ import { expect } from "bun:test"
2
+ import { test } from "bun:test"
3
+ import { SchematicTracePipelineSolver, type InputProblem } from "lib/index"
4
+ import "tests/fixtures/matcher"
5
+
6
+ const inputProblem = {
7
+ chips: [
8
+ {
9
+ chipId: "schematic_component_0",
10
+ center: {
11
+ x: -3,
12
+ y: 0,
13
+ },
14
+ width: 2.4000000000000004,
15
+ height: 1,
16
+ pins: [
17
+ {
18
+ pinId: "U1.1",
19
+ x: -1.8,
20
+ y: -0.30000000000000004,
21
+ },
22
+ {
23
+ pinId: "U1.2",
24
+ x: -4.2,
25
+ y: -0.30000000000000004,
26
+ },
27
+ {
28
+ pinId: "U1.3",
29
+ x: -1.8,
30
+ y: 0.09999999999999998,
31
+ },
32
+ {
33
+ pinId: "U1.4",
34
+ x: -4.2,
35
+ y: 0.30000000000000004,
36
+ },
37
+ {
38
+ pinId: "U1.5",
39
+ x: -4.2,
40
+ y: 0.10000000000000003,
41
+ },
42
+ {
43
+ pinId: "U1.6",
44
+ x: -4.2,
45
+ y: -0.09999999999999998,
46
+ },
47
+ {
48
+ pinId: "U1.7",
49
+ x: -1.8,
50
+ y: -0.10000000000000003,
51
+ },
52
+ {
53
+ pinId: "U1.8",
54
+ x: -1.8,
55
+ y: 0.30000000000000004,
56
+ },
57
+ ],
58
+ },
59
+ {
60
+ chipId: "schematic_component_1",
61
+ center: {
62
+ x: 3,
63
+ y: 0,
64
+ },
65
+ width: 2.2,
66
+ height: 0.8,
67
+ pins: [
68
+ {
69
+ pinId: "J1.1",
70
+ x: 1.9,
71
+ y: 0.2,
72
+ },
73
+ {
74
+ pinId: "J1.2",
75
+ x: 1.9,
76
+ y: 0,
77
+ },
78
+ {
79
+ pinId: "J1.3",
80
+ x: 1.9,
81
+ y: -0.2,
82
+ },
83
+ ],
84
+ },
85
+ {
86
+ chipId: "schematic_component_2",
87
+ center: {
88
+ x: 0,
89
+ y: 1, // Moved down so component body doesn't block horizontal traces
90
+ },
91
+ width: 1,
92
+ height: 1,
93
+ pins: [
94
+ {
95
+ pinId: "U2.3",
96
+ x: -0.4,
97
+ y: 0.5, // Bottom pin
98
+ },
99
+ {
100
+ pinId: "U2.4",
101
+ x: 0.4,
102
+ y: 0.5,
103
+ },
104
+ ],
105
+ },
106
+ ],
107
+ directConnections: [],
108
+ netConnections: [
109
+ {
110
+ netId: "SIGNAL1",
111
+ pinIds: ["U2.3"],
112
+ },
113
+ {
114
+ netId: "SIGNAL2",
115
+ pinIds: ["U2.4"],
116
+ },
117
+ {
118
+ netId: "SSH",
119
+ pinIds: ["U1.1", "J1.3"],
120
+ },
121
+ {
122
+ netId: "BHH",
123
+ pinIds: ["J1.1", "U1.3"],
124
+ },
125
+ ],
126
+ availableNetLabelOrientations: {},
127
+ maxMspPairDistance: 6.5,
128
+ } as InputProblem
129
+
130
+ test("example26", () => {
131
+ const solver = new SchematicTracePipelineSolver(inputProblem)
132
+ solver.solve()
133
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
134
+ })