@tscircuit/schematic-trace-solver 0.0.164 → 0.0.166
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 +5 -1
- package/dist/index.js +370 -24
- package/lib/solvers/NetLabelToTraceSolver/NetLabelToTraceSolver.ts +225 -24
- package/lib/solvers/SameNetJunctionAlignmentSolver/SameNetJunctionAlignmentSolver.ts +11 -5
- package/lib/solvers/SameNetJunctionAlignmentSolver/alignSameNetJunctions.ts +1 -1
- package/lib/solvers/SameNetJunctionAlignmentSolver/collapseSameNetCycles.ts +310 -0
- package/package.json +1 -1
- package/tests/assets/example51.json +6 -0
- package/tests/bug-reports/bug-report-20260721T221026Z/__snapshots__/bug-report-20260721T221026Z.snap.svg +2 -2
- package/tests/examples/__snapshots__/example51.snap.svg +42 -78
- package/tests/examples/example51.test.ts +24 -0
- package/tests/fixtures/convertSolverOutputToCircuitJson.ts +22 -3
- package/tests/repros/__snapshots__/board-1273-trace-overlap-cycle.snap.svg +2 -2
- package/tests/repros/__snapshots__/repro-bluetooth-controller-ground-decoupling-groups.snap.svg +1 -15
- package/tests/repros/__snapshots__/repro-core-ground-inline-label-fallback.snap.svg +2 -16
- package/tests/repros/__snapshots__/repro-isolated-rs485-isow7841.snap.svg +10 -10
- package/tests/repros/__snapshots__/repro-nrf52810-clock-routing.snap.svg +18 -18
- package/tests/repros/__snapshots__/repro-pga300-redundant-ground-traces.snap.svg +1 -15
- package/tests/repros/__snapshots__/repro-pmp11282-isolated-dcdc.snap.svg +33 -47
- package/tests/repros/repro-board-648-esp12f-section.test.ts +3 -0
- package/tests/repros/repro-isolated-rs485-isow7841.test.ts +33 -1
- package/tests/repros/repro-nrf52810-clock-routing.test.ts +26 -1
- package/tests/solvers/SameNetJunctionAlignmentSolver/collapse-same-net-cycles.test.ts +154 -0
|
@@ -10,5 +10,29 @@ test("example51", () => {
|
|
|
10
10
|
|
|
11
11
|
solver.solve()
|
|
12
12
|
|
|
13
|
+
const output = solver.netLabelToTraceSolver!.getOutput()
|
|
14
|
+
const expectedRecoveredPairs = [
|
|
15
|
+
["schematic_port_113", "schematic_port_110"],
|
|
16
|
+
["schematic_port_116", "schematic_port_111"],
|
|
17
|
+
["schematic_port_60", "schematic_port_72"],
|
|
18
|
+
["schematic_port_73", "schematic_port_112"],
|
|
19
|
+
["schematic_port_68", "schematic_port_74"],
|
|
20
|
+
["schematic_port_75", "schematic_port_12"],
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
for (const expectedPair of expectedRecoveredPairs) {
|
|
24
|
+
expect(
|
|
25
|
+
output.traces.some((trace) =>
|
|
26
|
+
expectedPair.every((pinId) => trace.pinIds.includes(pinId)),
|
|
27
|
+
),
|
|
28
|
+
).toBe(true)
|
|
29
|
+
expect(
|
|
30
|
+
output.netLabelPlacements.some(
|
|
31
|
+
(label) =>
|
|
32
|
+
label.pinIds.length === 1 && expectedPair.includes(label.pinIds[0]!),
|
|
33
|
+
),
|
|
34
|
+
).toBe(false)
|
|
35
|
+
}
|
|
36
|
+
|
|
13
37
|
expect(solver).toMatchSolverSnapshot(import.meta.path)
|
|
14
38
|
})
|
|
@@ -17,7 +17,12 @@ import type { InlineNetLabelPlacement } from "lib/solvers/InlineNetLabelSolver/I
|
|
|
17
17
|
import type { NetLabelPlacement } from "lib/solvers/NetLabelPlacementSolver/NetLabelPlacementSolver"
|
|
18
18
|
import type { SolvedTracePath } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver"
|
|
19
19
|
import { getPinDirection } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver/getPinDirection"
|
|
20
|
-
import type {
|
|
20
|
+
import type {
|
|
21
|
+
InputChip,
|
|
22
|
+
InputPin,
|
|
23
|
+
InputProblem,
|
|
24
|
+
NetId,
|
|
25
|
+
} from "lib/types/InputProblem"
|
|
21
26
|
import type { FacingDirection } from "lib/utils/dir"
|
|
22
27
|
import { type SchSymbol, symbols } from "schematic-symbols"
|
|
23
28
|
|
|
@@ -63,6 +68,7 @@ type SolverLike = BaseSolver & {
|
|
|
63
68
|
label?: NetLabelPlacement
|
|
64
69
|
getOutput?: () => SolverOutput
|
|
65
70
|
inlineNetLabelSolver?: { getOutput: () => SolverOutput }
|
|
71
|
+
netLabelToTraceSolver?: { getOutput: () => SolverOutput }
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
const isInputProblem = (value: unknown): value is InputProblem => {
|
|
@@ -92,6 +98,9 @@ export const getInputProblemFromSolver = (
|
|
|
92
98
|
|
|
93
99
|
const safelyGetOutput = (solver: SolverLike): SolverOutput | undefined => {
|
|
94
100
|
try {
|
|
101
|
+
if (solver.netLabelToTraceSolver?.getOutput) {
|
|
102
|
+
return solver.netLabelToTraceSolver.getOutput()
|
|
103
|
+
}
|
|
95
104
|
if (solver.inlineNetLabelSolver?.getOutput) {
|
|
96
105
|
return solver.inlineNetLabelSolver.getOutput()
|
|
97
106
|
}
|
|
@@ -947,6 +956,10 @@ export const convertSolverOutputToCircuitJson = (
|
|
|
947
956
|
}
|
|
948
957
|
|
|
949
958
|
const netNames = new Set<string>()
|
|
959
|
+
const groundNetIds = new Set<NetId>()
|
|
960
|
+
for (const connection of inputProblem.netConnections) {
|
|
961
|
+
if (connection.isGround) groundNetIds.add(connection.netId)
|
|
962
|
+
}
|
|
950
963
|
for (const connection of [
|
|
951
964
|
...inputProblem.directConnections,
|
|
952
965
|
...inputProblem.netConnections,
|
|
@@ -973,7 +986,7 @@ export const convertSolverOutputToCircuitJson = (
|
|
|
973
986
|
source_net_id: sourceNetId,
|
|
974
987
|
name: netName,
|
|
975
988
|
member_source_group_ids: [],
|
|
976
|
-
is_ground:
|
|
989
|
+
is_ground: groundNetIds.has(netName),
|
|
977
990
|
is_power: /(^|[._-])(vcc|vdd|vss|gnd)($|[._-])/i.test(netName),
|
|
978
991
|
} satisfies SourceNet)
|
|
979
992
|
}
|
|
@@ -1055,14 +1068,20 @@ export const convertSolverOutputToCircuitJson = (
|
|
|
1055
1068
|
|
|
1056
1069
|
for (const [labelIndex, label] of snapshotData.netLabelPlacements.entries()) {
|
|
1057
1070
|
const netName = getNetLabelNetName(label)
|
|
1071
|
+
const anchorSide = orientationToAnchorSide(label.orientation)
|
|
1072
|
+
let symbolName: string | undefined
|
|
1073
|
+
if (groundNetIds.has(netName) && anchorSide === "top") {
|
|
1074
|
+
symbolName = "rail_down"
|
|
1075
|
+
}
|
|
1058
1076
|
circuitJson.push({
|
|
1059
1077
|
type: "schematic_net_label",
|
|
1060
1078
|
schematic_net_label_id: `schematic_net_label_${labelIndex}`,
|
|
1061
1079
|
source_net_id: sourceNetIdByName.get(netName)!,
|
|
1062
1080
|
center: label.center,
|
|
1063
1081
|
anchor_position: label.anchorPoint,
|
|
1064
|
-
anchor_side:
|
|
1082
|
+
anchor_side: anchorSide,
|
|
1065
1083
|
text: getNetLabelText(label),
|
|
1084
|
+
symbol_name: symbolName,
|
|
1066
1085
|
} satisfies SchematicNetLabel)
|
|
1067
1086
|
}
|
|
1068
1087
|
|