@tscircuit/schematic-trace-solver 0.0.176 → 0.0.178

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.
@@ -0,0 +1,27 @@
1
+ import { expect, test } from "bun:test"
2
+ import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
3
+ import type { InputProblem } from "lib/types/InputProblem"
4
+ import "tests/fixtures/matcher"
5
+ import inputProblem from "./assets/repro-smartwatch-power-sheet.input.json"
6
+
7
+ test("smartwatch power sheet", () => {
8
+ const solver = new SchematicTracePipelineSolver(
9
+ inputProblem as unknown as InputProblem,
10
+ {
11
+ hideRatsNet: true,
12
+ },
13
+ )
14
+ solver.solve()
15
+
16
+ const connectorGroundPinIds = new Set([
17
+ "schematic_port_0",
18
+ "schematic_port_11",
19
+ ])
20
+ const connectorGroundLabels = solver
21
+ .netLabelToTraceSolver!.getOutput()
22
+ .netLabelPlacements.filter((label) =>
23
+ label.pinIds.some((pinId) => connectorGroundPinIds.has(pinId)),
24
+ )
25
+ expect(connectorGroundLabels).toHaveLength(1)
26
+ expect(solver).toMatchSolverSnapshot(import.meta.path)
27
+ })
@@ -56,6 +56,17 @@ test("marked ground nets retain explicit islands even with identical netIds", ()
56
56
  )
57
57
  })
58
58
 
59
+ test("unwired same-component ground pins share a local connection", () => {
60
+ const inputProblem = createInput()
61
+ inputProblem.chips[4]!.pins.push({ pinId: "F", x: 2.2, y: 0.1 })
62
+ inputProblem.netConnections[0]!.pinIds.push("F")
63
+
64
+ const solver = new MspConnectionPairSolver({ inputProblem })
65
+ solver.solve()
66
+
67
+ expect(pairKeys(solver)).toEqual(["A-B", "C-D", "E-F"])
68
+ })
69
+
59
70
  test.each([false, undefined])(
60
71
  "isGround=%s preserves automatic net routing",
61
72
  (isGround) => {
@@ -35,8 +35,10 @@ test("pipeline does not stretch a real loop toward a generated label connector",
35
35
 
36
36
  const traces = solver.traceCleanupSolver2!.getOutput().traces
37
37
  const realTrace = traces.find((trace) => trace.mspPairId === "U3.3-U3.7")!
38
- const labelConnector = traces.find((trace) =>
39
- trace.mspPairId.startsWith("available-net-orientation-"),
38
+ const [labelConnectorTraceId] =
39
+ solver.availableNetOrientationSolver!.netLabelConnectorTraceIds
40
+ const labelConnector = traces.find(
41
+ (trace) => trace.mspPairId === labelConnectorTraceId,
40
42
  )!
41
43
  expect(realTrace.tracePath).toEqual([
42
44
  { x: 1.4, y: -0.3 },
@@ -0,0 +1,160 @@
1
+ import { expect, test } from "bun:test"
2
+ import { getPathLength } from "lib/solvers/Example28Solver/geometry"
3
+ import type { SolvedTracePath } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver"
4
+ import { rerouteGeneratedNetLabelConnectorCrossings } from "lib/solvers/TraceCleanupSolver/rerouteGeneratedNetLabelConnectorCrossings"
5
+ import { findPerpendicularPathCrossings } from "lib/solvers/TraceCleanupSolver/sub-solver/findIntersectionsWithObstacles"
6
+
7
+ const makeTrace = ({
8
+ mspPairId,
9
+ globalConnNetId,
10
+ tracePath,
11
+ pinIds,
12
+ }: {
13
+ mspPairId: string
14
+ globalConnNetId: string
15
+ tracePath: Array<{ x: number; y: number }>
16
+ pinIds: string[]
17
+ }): SolvedTracePath => {
18
+ const firstPoint = tracePath[0]!
19
+ const lastPoint = tracePath.at(-1)!
20
+ return {
21
+ mspPairId,
22
+ dcConnNetId: globalConnNetId,
23
+ globalConnNetId,
24
+ pins: [
25
+ {
26
+ pinId: pinIds[0]!,
27
+ chipId: `${mspPairId}-start-chip`,
28
+ ...firstPoint,
29
+ },
30
+ {
31
+ pinId: pinIds[1] ?? pinIds[0]!,
32
+ chipId: `${mspPairId}-end-chip`,
33
+ ...lastPoint,
34
+ },
35
+ ],
36
+ pinIds,
37
+ mspConnectionPairIds: [mspPairId],
38
+ tracePath,
39
+ }
40
+ }
41
+
42
+ const signalTrace = makeTrace({
43
+ mspPairId: "signal-trace",
44
+ globalConnNetId: "signal-net",
45
+ pinIds: ["signal-a", "signal-b"],
46
+ tracePath: [
47
+ { x: 1, y: 3 },
48
+ { x: 2, y: 3 },
49
+ { x: 2, y: 0 },
50
+ { x: -6, y: 0 },
51
+ ],
52
+ })
53
+
54
+ const connectorTrace = makeTrace({
55
+ mspPairId: "vbat-label-connector",
56
+ globalConnNetId: "vbat-net",
57
+ pinIds: ["vbat"],
58
+ tracePath: [
59
+ { x: 3, y: 1 },
60
+ { x: 1.5, y: 1 },
61
+ { x: 1.5, y: 1.5 },
62
+ ],
63
+ })
64
+
65
+ const vbatLabel = {
66
+ globalConnNetId: "vbat-net",
67
+ pinIds: ["vbat"],
68
+ anchorPoint: { x: 1.5, y: 1.5 },
69
+ center: { x: 1.5, y: 1.7 },
70
+ width: 1,
71
+ height: 0.4,
72
+ }
73
+
74
+ const inputProblem = { chips: [], textBoxes: [] } as any
75
+
76
+ test("reroutes a component trace through an equally short clean corridor", () => {
77
+ const result = rerouteGeneratedNetLabelConnectorCrossings({
78
+ inputProblem,
79
+ traces: [signalTrace, connectorTrace],
80
+ netLabelPlacements: [vbatLabel as any],
81
+ mergedLabelNetIdMap: {},
82
+ clearance: 0.1,
83
+ eligibleTraceIds: new Set([signalTrace.mspPairId]),
84
+ connectorTraceIds: new Set([connectorTrace.mspPairId]),
85
+ })
86
+
87
+ expect(result.reroutedTraceCount).toBe(1)
88
+ expect(result.traces[1]!.tracePath).toEqual(connectorTrace.tracePath)
89
+ expect(getPathLength(result.traces[0]!.tracePath)).toBeLessThanOrEqual(
90
+ getPathLength(signalTrace.tracePath),
91
+ )
92
+ expect(
93
+ findPerpendicularPathCrossings(
94
+ result.traces[0]!.tracePath,
95
+ result.traces[1]!.tracePath,
96
+ { includeTerminalSegments: true },
97
+ ),
98
+ ).toEqual([])
99
+ })
100
+
101
+ test("preserves a crossing when avoiding it would lengthen the routed trace", () => {
102
+ const straightSignal = makeTrace({
103
+ mspPairId: "straight-signal",
104
+ globalConnNetId: "signal-net",
105
+ pinIds: ["signal-a", "signal-b"],
106
+ tracePath: [
107
+ { x: -2, y: 0 },
108
+ { x: 2, y: 0 },
109
+ ],
110
+ })
111
+ const verticalConnector = makeTrace({
112
+ mspPairId: "vertical-label-connector",
113
+ globalConnNetId: "label-net",
114
+ pinIds: ["label-pin"],
115
+ tracePath: [
116
+ { x: 0, y: -1 },
117
+ { x: 0, y: 1 },
118
+ ],
119
+ })
120
+
121
+ const result = rerouteGeneratedNetLabelConnectorCrossings({
122
+ inputProblem,
123
+ traces: [straightSignal, verticalConnector],
124
+ netLabelPlacements: [],
125
+ mergedLabelNetIdMap: {},
126
+ clearance: 0.1,
127
+ eligibleTraceIds: new Set([straightSignal.mspPairId]),
128
+ connectorTraceIds: new Set([verticalConnector.mspPairId]),
129
+ })
130
+
131
+ expect(result.reroutedTraceCount).toBe(0)
132
+ expect(result.traces[0]!.tracePath).toEqual(straightSignal.tracePath)
133
+ })
134
+
135
+ test("allows crossings between generated label connectors", () => {
136
+ const otherConnector = makeTrace({
137
+ mspPairId: "other-label-connector",
138
+ globalConnNetId: "other-label-net",
139
+ pinIds: ["other-label-pin"],
140
+ tracePath: [
141
+ { x: 2, y: 0 },
142
+ { x: 2, y: 2 },
143
+ ],
144
+ })
145
+
146
+ const result = rerouteGeneratedNetLabelConnectorCrossings({
147
+ inputProblem,
148
+ traces: [connectorTrace, otherConnector],
149
+ netLabelPlacements: [vbatLabel as any],
150
+ mergedLabelNetIdMap: {},
151
+ clearance: 0.1,
152
+ connectorTraceIds: new Set([
153
+ connectorTrace.mspPairId,
154
+ otherConnector.mspPairId,
155
+ ]),
156
+ })
157
+
158
+ expect(result.reroutedTraceCount).toBe(0)
159
+ expect(result.traces).toEqual([connectorTrace, otherConnector])
160
+ })