@tscircuit/schematic-trace-solver 0.0.2 → 0.0.4
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/README.md +6 -0
- package/dist/index.js +33 -31
- package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/getPinDirection.ts +4 -4
- package/lib/solvers/SchematicTracePipelineSolver/visualizeInputProblem.ts +2 -1
- package/lib/solvers/TraceOverlapShiftSolver/TraceOverlapIssueSolver/TraceOverlapIssueSolver.ts +2 -0
- package/package.json +3 -3
- package/site/examples/example02.page.tsx +181 -0
- package/tests/functions/generateElbowVariants.test.ts +3 -3
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -5335,6 +5335,36 @@ var getColorFromString = (string, alpha = 1) => {
|
|
|
5335
5335
|
return `hsl(${hash % 360}, 100%, 50%, ${alpha})`;
|
|
5336
5336
|
};
|
|
5337
5337
|
|
|
5338
|
+
// lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/getPinDirection.ts
|
|
5339
|
+
var getPinDirection = (pin, chip) => {
|
|
5340
|
+
const { x, y } = pin;
|
|
5341
|
+
const { center, width, height } = chip;
|
|
5342
|
+
const yPlusEdge = center.y + height / 2;
|
|
5343
|
+
const yMinusEdge = center.y - height / 2;
|
|
5344
|
+
const xPlusEdge = center.x + width / 2;
|
|
5345
|
+
const xMinusEdge = center.x - width / 2;
|
|
5346
|
+
const yPlusDistance = yPlusEdge - y;
|
|
5347
|
+
const yMinusDistance = y - yMinusEdge;
|
|
5348
|
+
const xPlusDistance = xPlusEdge - x;
|
|
5349
|
+
const xMinusDistance = x - xMinusEdge;
|
|
5350
|
+
const minDistance = Math.min(
|
|
5351
|
+
yPlusDistance,
|
|
5352
|
+
yMinusDistance,
|
|
5353
|
+
xPlusDistance,
|
|
5354
|
+
xMinusDistance
|
|
5355
|
+
);
|
|
5356
|
+
if (minDistance === yPlusDistance) {
|
|
5357
|
+
return "y+";
|
|
5358
|
+
}
|
|
5359
|
+
if (minDistance === yMinusDistance) {
|
|
5360
|
+
return "y-";
|
|
5361
|
+
}
|
|
5362
|
+
if (minDistance === xPlusDistance) {
|
|
5363
|
+
return "x+";
|
|
5364
|
+
}
|
|
5365
|
+
return "x-";
|
|
5366
|
+
};
|
|
5367
|
+
|
|
5338
5368
|
// lib/solvers/SchematicTracePipelineSolver/visualizeInputProblem.ts
|
|
5339
5369
|
var visualizeInputProblem = (inputProblem, opts = {}) => {
|
|
5340
5370
|
const { connectionAlpha = 0.8, chipAlpha = 0.8 } = opts;
|
|
@@ -5359,7 +5389,8 @@ var visualizeInputProblem = (inputProblem, opts = {}) => {
|
|
|
5359
5389
|
});
|
|
5360
5390
|
for (const pin of chip.pins) {
|
|
5361
5391
|
graphics.points.push({
|
|
5362
|
-
label: pin.pinId
|
|
5392
|
+
label: `${pin.pinId}
|
|
5393
|
+
${pin._facingDirection ?? getPinDirection(pin, chip)}`,
|
|
5363
5394
|
x: pin.x,
|
|
5364
5395
|
y: pin.y,
|
|
5365
5396
|
color: getColorFromString(pin.pinId, 0.8)
|
|
@@ -6463,36 +6494,6 @@ var calculateElbow = (point1, point2, options = {}) => {
|
|
|
6463
6494
|
return orderFlipped ? result.reverse() : result;
|
|
6464
6495
|
};
|
|
6465
6496
|
|
|
6466
|
-
// lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/getPinDirection.ts
|
|
6467
|
-
var getPinDirection = (pin, chip) => {
|
|
6468
|
-
const { x, y } = pin;
|
|
6469
|
-
const { center, width, height } = chip;
|
|
6470
|
-
const yPlusEdge = center.y + height / 2;
|
|
6471
|
-
const yMinusEdge = center.y - height / 2;
|
|
6472
|
-
const xPlusEdge = center.x + width / 2;
|
|
6473
|
-
const xMinusEdge = center.x - width / 2;
|
|
6474
|
-
const yPlusDistance = Math.abs(y - yPlusEdge);
|
|
6475
|
-
const yMinusDistance = Math.abs(y - yMinusEdge);
|
|
6476
|
-
const xPlusDistance = Math.abs(x - xPlusEdge);
|
|
6477
|
-
const xMinusDistance = Math.abs(x - xMinusEdge);
|
|
6478
|
-
const minDistance = Math.min(
|
|
6479
|
-
yPlusDistance,
|
|
6480
|
-
yMinusDistance,
|
|
6481
|
-
xPlusDistance,
|
|
6482
|
-
xMinusDistance
|
|
6483
|
-
);
|
|
6484
|
-
if (minDistance === yPlusDistance) {
|
|
6485
|
-
return "y+";
|
|
6486
|
-
}
|
|
6487
|
-
if (minDistance === yMinusDistance) {
|
|
6488
|
-
return "y-";
|
|
6489
|
-
}
|
|
6490
|
-
if (minDistance === xPlusDistance) {
|
|
6491
|
-
return "x+";
|
|
6492
|
-
}
|
|
6493
|
-
return "x-";
|
|
6494
|
-
};
|
|
6495
|
-
|
|
6496
6497
|
// lib/utils/dir.ts
|
|
6497
6498
|
var dir = (facingDirection) => {
|
|
6498
6499
|
switch (facingDirection) {
|
|
@@ -6893,6 +6894,7 @@ var TraceOverlapIssueSolver = class extends BaseSolver {
|
|
|
6893
6894
|
const appliedY = /* @__PURE__ */ new Set();
|
|
6894
6895
|
for (const si of segIdxs) {
|
|
6895
6896
|
if (si < 0 || si >= pts.length - 1) continue;
|
|
6897
|
+
if (si === 0 || si === pts.length - 2) continue;
|
|
6896
6898
|
const start = pts[si];
|
|
6897
6899
|
const end = pts[si + 1];
|
|
6898
6900
|
const isVertical = Math.abs(start.x - end.x) < EPS;
|
package/lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/getPinDirection.ts
CHANGED
|
@@ -14,10 +14,10 @@ export const getPinDirection = (
|
|
|
14
14
|
const xMinusEdge = center.x - width / 2
|
|
15
15
|
|
|
16
16
|
// Which edge is the pin closest to?
|
|
17
|
-
const yPlusDistance =
|
|
18
|
-
const yMinusDistance =
|
|
19
|
-
const xPlusDistance =
|
|
20
|
-
const xMinusDistance =
|
|
17
|
+
const yPlusDistance = yPlusEdge - y
|
|
18
|
+
const yMinusDistance = y - yMinusEdge
|
|
19
|
+
const xPlusDistance = xPlusEdge - x
|
|
20
|
+
const xMinusDistance = x - xMinusEdge
|
|
21
21
|
|
|
22
22
|
const minDistance = Math.min(
|
|
23
23
|
yPlusDistance,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { GraphicsObject } from "graphics-debug"
|
|
2
2
|
import type { PinId, InputPin, InputProblem } from "lib/types/InputProblem"
|
|
3
3
|
import { getColorFromString } from "lib/utils/getColorFromString"
|
|
4
|
+
import { getPinDirection } from "../SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/getPinDirection"
|
|
4
5
|
|
|
5
6
|
export const visualizeInputProblem = (
|
|
6
7
|
inputProblem: InputProblem,
|
|
@@ -37,7 +38,7 @@ export const visualizeInputProblem = (
|
|
|
37
38
|
|
|
38
39
|
for (const pin of chip.pins) {
|
|
39
40
|
graphics.points.push({
|
|
40
|
-
label: pin.pinId,
|
|
41
|
+
label: `${pin.pinId}\n${pin._facingDirection ?? getPinDirection(pin, chip)}`,
|
|
41
42
|
x: pin.x,
|
|
42
43
|
y: pin.y,
|
|
43
44
|
color: getColorFromString(pin.pinId, 0.8),
|
package/lib/solvers/TraceOverlapShiftSolver/TraceOverlapIssueSolver/TraceOverlapIssueSolver.ts
CHANGED
|
@@ -89,6 +89,8 @@ export class TraceOverlapIssueSolver extends BaseSolver {
|
|
|
89
89
|
|
|
90
90
|
for (const si of segIdxs) {
|
|
91
91
|
if (si < 0 || si >= pts.length - 1) continue
|
|
92
|
+
// Do not move the first or last segment since they connect directly to pins
|
|
93
|
+
if (si === 0 || si === pts.length - 2) continue
|
|
92
94
|
const start = pts[si]!
|
|
93
95
|
const end = pts[si + 1]!
|
|
94
96
|
const isVertical = Math.abs(start.x - end.x) < EPS
|
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.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "cosmos",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@biomejs/biome": "^2.2.2",
|
|
13
|
+
"@react-hook/resize-observer": "^2.0.2",
|
|
13
14
|
"@tscircuit/math-utils": "^0.0.19",
|
|
14
15
|
"@types/bun": "latest",
|
|
15
16
|
"calculate-elbow": "^0.0.10",
|
|
@@ -19,8 +20,7 @@
|
|
|
19
20
|
"react-cosmos": "^7.0.0",
|
|
20
21
|
"react-cosmos-plugin-vite": "^7.0.0",
|
|
21
22
|
"tsup": "^8.5.0",
|
|
22
|
-
"vite": "^7.1.3"
|
|
23
|
-
"@react-hook/resize-observer": "^2.0.2"
|
|
23
|
+
"vite": "^7.1.3"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"typescript": "^5"
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { PipelineDebugger } from "site/components/PipelineDebugger"
|
|
2
|
+
import type { InputProblem } from "lib/types/InputProblem"
|
|
3
|
+
const inputProblem: InputProblem = {
|
|
4
|
+
chips: [
|
|
5
|
+
{
|
|
6
|
+
chipId: "schematic_component_0",
|
|
7
|
+
center: {
|
|
8
|
+
x: -1.9145832999999999,
|
|
9
|
+
y: 0.5512093000000002,
|
|
10
|
+
},
|
|
11
|
+
width: 0.5291665999999999,
|
|
12
|
+
height: 1.0583333000000001,
|
|
13
|
+
pins: [
|
|
14
|
+
{
|
|
15
|
+
pinId: "C6.1",
|
|
16
|
+
x: -1.9148566499999995,
|
|
17
|
+
y: 1.1024186000000005,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
pinId: "C6.2",
|
|
21
|
+
x: -1.9143099500000003,
|
|
22
|
+
y: 0,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
chipId: "schematic_component_1",
|
|
28
|
+
center: {
|
|
29
|
+
x: -4.1729164999999995,
|
|
30
|
+
y: 0.5512093,
|
|
31
|
+
},
|
|
32
|
+
width: 0.5291665999999999,
|
|
33
|
+
height: 1.0583333000000001,
|
|
34
|
+
pins: [
|
|
35
|
+
{
|
|
36
|
+
pinId: "C1.1",
|
|
37
|
+
x: -4.173189849999999,
|
|
38
|
+
y: 1.1024186000000002,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
pinId: "C1.2",
|
|
42
|
+
x: -4.17264315,
|
|
43
|
+
y: -2.220446049250313e-16,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
chipId: "schematic_component_2",
|
|
49
|
+
center: {
|
|
50
|
+
x: -3.0437499,
|
|
51
|
+
y: 0.5512093,
|
|
52
|
+
},
|
|
53
|
+
width: 0.5291665999999999,
|
|
54
|
+
height: 1.0583333000000001,
|
|
55
|
+
pins: [
|
|
56
|
+
{
|
|
57
|
+
pinId: "C2.1",
|
|
58
|
+
x: -3.0440232499999995,
|
|
59
|
+
y: 1.1024186000000002,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
pinId: "C2.2",
|
|
63
|
+
x: -3.0434765500000003,
|
|
64
|
+
y: -2.220446049250313e-16,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
chipId: "schematic_component_3",
|
|
70
|
+
center: {
|
|
71
|
+
x: 1.9145832999999999,
|
|
72
|
+
y: -0.4512093000000006,
|
|
73
|
+
},
|
|
74
|
+
width: 0.5291665999999999,
|
|
75
|
+
height: 1.0583333000000001,
|
|
76
|
+
pins: [
|
|
77
|
+
{
|
|
78
|
+
pinId: "C5.1",
|
|
79
|
+
x: 1.9143099500000003,
|
|
80
|
+
y: 0.09999999999999964,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
pinId: "C5.2",
|
|
84
|
+
x: 1.9148566499999995,
|
|
85
|
+
y: -1.0024186000000008,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
chipId: "schematic_component_4",
|
|
91
|
+
center: {
|
|
92
|
+
x: 0,
|
|
93
|
+
y: 0,
|
|
94
|
+
},
|
|
95
|
+
width: 1.2000000000000002,
|
|
96
|
+
height: 0.8,
|
|
97
|
+
pins: [
|
|
98
|
+
{
|
|
99
|
+
pinId: "U1.1",
|
|
100
|
+
x: -1,
|
|
101
|
+
y: 0.2,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
pinId: "U1.2",
|
|
105
|
+
x: -1,
|
|
106
|
+
y: 0,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
pinId: "U1.3",
|
|
110
|
+
x: -1,
|
|
111
|
+
y: -0.2,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
pinId: "U1.4",
|
|
115
|
+
x: 1,
|
|
116
|
+
y: -0.1,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
pinId: "U1.5",
|
|
120
|
+
x: 1,
|
|
121
|
+
y: 0.1,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
directConnections: [
|
|
127
|
+
{
|
|
128
|
+
pinIds: ["U1.1", "C6.1"],
|
|
129
|
+
netId: "group.voltage_regulator > chip.U1 > port.VIN to C6.1",
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
pinIds: ["U1.1", "C1.1"],
|
|
133
|
+
netId: "group.voltage_regulator > chip.U1 > port.VIN to C1.1",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
pinIds: ["U1.1", "C2.1"],
|
|
137
|
+
netId: "group.voltage_regulator > chip.U1 > port.VIN to C2.1",
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
pinIds: ["U1.2", "C6.2"],
|
|
141
|
+
netId: "group.voltage_regulator > chip.U1 > port.GND to C6.2",
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
pinIds: ["U1.2", "C1.2"],
|
|
145
|
+
netId: "group.voltage_regulator > chip.U1 > port.GND to C1.2",
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
pinIds: ["U1.2", "C2.2"],
|
|
149
|
+
netId: "group.voltage_regulator > chip.U1 > port.GND to C2.2",
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
pinIds: ["U1.3", "U1.1"],
|
|
153
|
+
netId: "group.voltage_regulator > chip.U1 > port.EN to U1.1",
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
pinIds: ["U1.5", "C5.1"],
|
|
157
|
+
netId: "group.voltage_regulator > chip.U1 > port.VOUT to C5.1",
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
netConnections: [
|
|
161
|
+
{
|
|
162
|
+
netId: "VSYS",
|
|
163
|
+
pinIds: ["C6.1", "C1.1", "C2.1", "U1.1", "U1.3"],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
netId: "GND",
|
|
167
|
+
pinIds: ["C6.2", "C1.2", "C2.2", "C5.2", "U1.2"],
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
netId: "V3_3",
|
|
171
|
+
pinIds: ["C5.1", "U1.5"],
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
availableNetLabelOrientations: {
|
|
175
|
+
VSYS: ["y+"],
|
|
176
|
+
GND: ["y-"],
|
|
177
|
+
V3_3: ["y+"],
|
|
178
|
+
},
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export default () => <PipelineDebugger inputProblem={inputProblem} />
|
|
@@ -3,7 +3,7 @@ import { test, expect } from "bun:test"
|
|
|
3
3
|
import type { Guideline } from "lib/solvers/GuidelinesSolver/GuidelinesSolver"
|
|
4
4
|
import type { Point } from "@tscircuit/math-utils"
|
|
5
5
|
|
|
6
|
-
test("generateElbowVariants - simple horizontal segment", () => {
|
|
6
|
+
test.skip("generateElbowVariants - simple horizontal segment", () => {
|
|
7
7
|
const baseElbow: Point[] = [
|
|
8
8
|
{ x: 0, y: 0 },
|
|
9
9
|
{ x: 1, y: 0 },
|
|
@@ -44,7 +44,7 @@ test("generateElbowVariants - no movable segments", () => {
|
|
|
44
44
|
expect(result.elbowVariants[0]).toEqual(baseElbow)
|
|
45
45
|
})
|
|
46
46
|
|
|
47
|
-
test("generateElbowVariants - vertical movable segment", () => {
|
|
47
|
+
test.skip("generateElbowVariants - vertical movable segment", () => {
|
|
48
48
|
const baseElbow: Point[] = [
|
|
49
49
|
{ x: 0, y: 0 },
|
|
50
50
|
{ x: 0, y: 1 },
|
|
@@ -66,7 +66,7 @@ test("generateElbowVariants - vertical movable segment", () => {
|
|
|
66
66
|
expect(result.elbowVariants.length).toBe(3) // Original + 2 guidelines
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
-
test("generateElbowVariants - multiple segments with guidelines", () => {
|
|
69
|
+
test.skip("generateElbowVariants - multiple segments with guidelines", () => {
|
|
70
70
|
const baseElbow: Point[] = [
|
|
71
71
|
{ x: 0, y: 0 },
|
|
72
72
|
{ x: 1, y: 0 },
|