@tscircuit/schematic-trace-solver 0.0.158 → 0.0.160

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 (27) hide show
  1. package/dist/index.d.ts +41 -9
  2. package/dist/index.js +762 -110
  3. package/lib/solvers/InlineNetLabelSolver/InlineNetLabelSolver.ts +536 -94
  4. package/lib/solvers/InlineNetLabelSolver/pushAnchoredNetLabelsAwayFromInlineLabels.ts +9 -7
  5. package/lib/solvers/InlineNetLabelSolver/pushInlineTerminalLabelsAwayFromAnchoredLabels.ts +295 -0
  6. package/lib/solvers/LongDistancePairSolver/LongDistancePairSolver.ts +15 -8
  7. package/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts +5 -0
  8. package/lib/solvers/MspConnectionPairSolver/getGroundConnectionPolicy.ts +83 -0
  9. package/lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver.ts +7 -35
  10. package/lib/solvers/SameNetJunctionAlignmentSolver/SameNetJunctionAlignmentSolver.ts +6 -1
  11. package/lib/solvers/SameNetJunctionAlignmentSolver/placeGroundRailLabelsAtOuterEnd.ts +122 -0
  12. package/lib/solvers/SchematicTraceLinesSolver/getTraceConnectedPinComponents.ts +60 -0
  13. package/lib/types/InputProblem.ts +5 -4
  14. package/package.json +1 -1
  15. package/tests/bug-reports/bug-report-20260826T072956Z/__snapshots__/bug-report-20260826T072956Z.snap.svg +600 -783
  16. package/tests/bug-reports/bug-report-20260826T072956Z/bug-report-20260826T072956Z.test.ts +66 -1
  17. package/tests/fixtures/parallel-ground-rail.ts +53 -0
  18. package/tests/repros/__snapshots__/repro-mspm0l1306-capacitor-symmetry.snap.svg +34 -16
  19. package/tests/repros/repro-mspm0l1306-capacitor-symmetry.test.ts +40 -7
  20. package/tests/repros/repro-usb-power-vbus-label-detour.test.ts +14 -0
  21. package/tests/solvers/InlineNetLabelSolver/multi-pin-connected-components.test.ts +252 -0
  22. package/tests/solvers/InlineNetLabelSolver/opposite-side-placement.test.ts +71 -0
  23. package/tests/solvers/InlineNetLabelSolver/push-anchored-net-labels-away.test.ts +8 -2
  24. package/tests/solvers/InlineNetLabelSolver/push-inline-terminal-labels-away.test.ts +91 -0
  25. package/tests/solvers/InlineNetLabelSolver/two-pin-terminal-stubs-atomic.test.ts +7 -1
  26. package/tests/solvers/MspConnectionPairSolver/local-ground-branches.test.ts +105 -0
  27. package/tests/solvers/SameNetJunctionAlignmentSolver/ground-rail-label.test.ts +188 -0
@@ -1,12 +1,77 @@
1
1
  import { expect, test } from "bun:test"
2
+ import { estimateInlineNetLabelWidth } from "lib/solvers/InlineNetLabelSolver/InlineNetLabelSolver"
2
3
  import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
4
+ import type { InputProblem } from "lib/types/InputProblem"
3
5
  import inputProblem from "./bug-report-20260826T072956Z.json"
4
6
  import "tests/fixtures/matcher"
5
7
 
8
+ const multiPinSignalNetIds = [
9
+ "ISNS_A",
10
+ "ISNS_B",
11
+ "ISNS_C",
12
+ "MOT_A",
13
+ "MOT_B",
14
+ "MOT_C",
15
+ "S1_N",
16
+ "S1_P",
17
+ "S2_N",
18
+ "S2_P",
19
+ "S3_N",
20
+ "S3_P",
21
+ "SL_A",
22
+ "SL_B",
23
+ "SL_C",
24
+ ]
25
+
6
26
  test("bug-report-20260826T072956Z", () => {
7
- const solver = new SchematicTracePipelineSolver(inputProblem as any)
27
+ const problem = structuredClone(inputProblem) as unknown as InputProblem
28
+ for (const connection of problem.netConnections) {
29
+ if (!multiPinSignalNetIds.includes(connection.netId)) continue
30
+ connection.allowInlineNetLabel = true
31
+ connection.inlineNetLabelHeight = 0.12
32
+ connection.inlineNetLabelWidth = estimateInlineNetLabelWidth(
33
+ connection.netId,
34
+ connection.inlineNetLabelHeight,
35
+ )
36
+ }
37
+
38
+ const solver = new SchematicTracePipelineSolver(problem, {
39
+ hideRatsNet: true,
40
+ })
8
41
 
9
42
  solver.solve()
10
43
 
44
+ const output = solver.inlineNetLabelSolver!.getOutput()
45
+ const expectedInlineNetIds = ["GH_B", ...multiPinSignalNetIds]
46
+ expect(
47
+ new Set(
48
+ output.inlineNetLabelPlacements
49
+ .filter((placement) =>
50
+ expectedInlineNetIds.includes(placement.netId ?? ""),
51
+ )
52
+ .map((placement) => placement.netId),
53
+ ),
54
+ ).toEqual(new Set(expectedInlineNetIds))
55
+ expect(
56
+ output.netLabelPlacements.filter((placement) =>
57
+ expectedInlineNetIds.includes(placement.netId ?? ""),
58
+ ),
59
+ ).toHaveLength(0)
60
+ expect(
61
+ output.inlineNetLabelPlacements.some(
62
+ (placement) => placement.netId === "GH_B" && placement.side === "y-",
63
+ ),
64
+ ).toBe(true)
65
+ for (const supersededConnectorTraceId of [
66
+ "schematic_port_152-schematic_port_150",
67
+ "schematic_port_151-schematic_port_148",
68
+ "schematic_port_149-schematic_port_147",
69
+ ]) {
70
+ expect(
71
+ output.traces.some(
72
+ (trace) => trace.mspPairId === supersededConnectorTraceId,
73
+ ),
74
+ ).toBe(false)
75
+ }
11
76
  expect(solver).toMatchSolverSnapshot(import.meta.path)
12
77
  })
@@ -0,0 +1,53 @@
1
+ import type { InputProblem } from "lib/types/InputProblem"
2
+
3
+ export const createParallelGroundRailProblem = (): InputProblem => ({
4
+ chips: [
5
+ ...[
6
+ ["A", 0, 1],
7
+ ["B", 1, 1],
8
+ ["C", 1, -2],
9
+ ["D", -1, -3.5],
10
+ ].map(([id, x, y]) => ({
11
+ chipId: String(id),
12
+ center: { x: Number(x), y: Number(y) + 0.4 },
13
+ width: 0.4,
14
+ height: 0.8,
15
+ pins: [
16
+ {
17
+ pinId: `${id}.1`,
18
+ x: Number(x),
19
+ y: Number(y) + 0.8,
20
+ _facingDirection: "y+" as const,
21
+ },
22
+ {
23
+ pinId: `${id}.2`,
24
+ x: Number(x),
25
+ y: Number(y),
26
+ _facingDirection: "y-" as const,
27
+ },
28
+ ],
29
+ })),
30
+ {
31
+ chipId: "U",
32
+ center: { x: 2.5, y: 1.5 },
33
+ width: 1,
34
+ height: 3,
35
+ pins: [
36
+ { pinId: "U.GND", x: 2, y: 0.6, _facingDirection: "x-" },
37
+ { pinId: "U.VIN", x: 2, y: 2, _facingDirection: "x-" },
38
+ { pinId: "U.IO", x: 2, y: 2.4, _facingDirection: "x-" },
39
+ ],
40
+ },
41
+ ],
42
+ directConnections: [{ pinIds: ["A.2", "B.2"] }, { pinIds: ["A.2", "U.GND"] }],
43
+ netConnections: [
44
+ {
45
+ netId: "GND",
46
+ pinIds: ["U.GND", "A.2", "B.2", "C.2", "D.2"],
47
+ netLabelWidth: 0.42,
48
+ netLabelHeight: 0.48,
49
+ },
50
+ ],
51
+ availableNetLabelOrientations: { GND: ["y-"] },
52
+ maxMspPairDistance: 6,
53
+ })