Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
164 changes: 164 additions & 0 deletions tests/repros/assets/repro-rp2040-usb-cc2-ground-overlap.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"chips": [
{
"chipId": "schematic_component_16",
"center": {
"x": -13.9425,
"y": -18.14
},
"width": 5.199999999999999,
"height": 2,
"pins": [
{
"pinId": "schematic_port_83",
"x": -11.342500000000001,
"y": -17.29
},
{
"pinId": "schematic_port_84",
"x": -11.342500000000001,
"y": -17.490000000000002
},
{
"pinId": "schematic_port_85",
"x": -11.342500000000001,
"y": -17.69
},
{
"pinId": "schematic_port_86",
"x": -11.342500000000001,
"y": -18.04
},
{
"pinId": "schematic_port_87",
"x": -11.342500000000001,
"y": -18.240000000000002
},
{
"pinId": "schematic_port_88",
"x": -11.342500000000001,
"y": -18.59
},
{
"pinId": "schematic_port_89",
"x": -11.342500000000001,
"y": -18.79
},
{
"pinId": "schematic_port_90",
"x": -11.342500000000001,
"y": -18.990000000000002
}
],
"sectionId": "usb"
},
{
"chipId": "schematic_component_17",
"center": {
"x": -9.580000000000002,
"y": -18.515
},
"width": 1.084999999999999,
"height": 0.6000000000000014,
"pins": [
{
"pinId": "schematic_port_91",
"x": -9.797500000000001,
"y": -18.215,
"_facingDirection": "y+"
},
{
"pinId": "schematic_port_92",
"x": -9.797500000000001,
"y": -18.815,
"_facingDirection": "y-"
}
],
"sectionId": "usb"
},
{
"chipId": "schematic_component_18",
"center": {
"x": -9.580000000000002,
"y": -20.325000000000003
},
"width": 1.084999999999999,
"height": 0.6000000000000014,
"pins": [
{
"pinId": "schematic_port_93",
"x": -9.797500000000001,
"y": -20.025000000000002,
"_facingDirection": "y+"
},
{
"pinId": "schematic_port_94",
"x": -9.797500000000001,
"y": -20.625000000000004,
"_facingDirection": "y-"
}
],
"sectionId": "usb"
}
],
"directConnections": [],
"netConnections": [
{
"netId": "GND",
"netLabelWidth": 0.42,
"netLabelHeight": 0.48,
"pinIds": [
"schematic_port_90",
"schematic_port_92",
"schematic_port_94"
]
},
{
"netId": "D_MINUS",
"netLabelWidth": 0.96,
"pinIds": ["schematic_port_85"]
},
{
"netId": "D_PLUS",
"netLabelWidth": 0.84,
"pinIds": ["schematic_port_84"]
},
{
"netId": "VBUS",
"netLabelWidth": 0.42,
"netLabelHeight": 0.6,
"pinIds": ["schematic_port_83"]
},
{
"netId": "CC1",
"netLabelWidth": 0.48,
"pinIds": ["schematic_port_86", "schematic_port_91"]
},
{
"netId": "CC2",
"netLabelWidth": 0.48,
"pinIds": ["schematic_port_87", "schematic_port_93"]
}
],
"textBoxes": [
{
"chipId": "schematic_component_16",
"center": {
"x": -16.0225,
"y": -17.025000000000002
},
"width": 0.35999999999999943,
"height": 0.25,
"text": "U3"
}
],
"availableNetLabelOrientations": {
"D_MINUS": ["x-", "x+"],
"D_PLUS": ["x-", "x+"],
"GND": ["y-"],
"VBUS": ["y+"],
"CC1": ["x-", "x+"],
"CC2": ["x-", "x+"]
},
"maxMspPairDistance": 2.4
}
98 changes: 98 additions & 0 deletions tests/repros/repro-rp2040-usb-cc2-ground-overlap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { expect, test } from "bun:test"
import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver"
import type { SolvedTracePath } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver"
import inputProblem from "./assets/repro-rp2040-usb-cc2-ground-overlap.input.json"

const EPS = 1e-6

const pathsHavePositiveLengthCollinearOverlap = (
first: SolvedTracePath,
second: SolvedTracePath,
) => {
for (
let firstIndex = 0;
firstIndex < first.tracePath.length - 1;
firstIndex++
) {
const firstStart = first.tracePath[firstIndex]!
const firstEnd = first.tracePath[firstIndex + 1]!
const firstIsVertical = Math.abs(firstStart.x - firstEnd.x) < EPS
const firstIsHorizontal = Math.abs(firstStart.y - firstEnd.y) < EPS

for (
let secondIndex = 0;
secondIndex < second.tracePath.length - 1;
secondIndex++
) {
const secondStart = second.tracePath[secondIndex]!
const secondEnd = second.tracePath[secondIndex + 1]!
const secondIsVertical = Math.abs(secondStart.x - secondEnd.x) < EPS
const secondIsHorizontal = Math.abs(secondStart.y - secondEnd.y) < EPS

if (
firstIsVertical &&
secondIsVertical &&
Math.abs(firstStart.x - secondStart.x) < EPS
) {
const overlapLength =
Math.min(
Math.max(firstStart.y, firstEnd.y),
Math.max(secondStart.y, secondEnd.y),
) -
Math.max(
Math.min(firstStart.y, firstEnd.y),
Math.min(secondStart.y, secondEnd.y),
)
if (overlapLength > EPS) return true
}

if (
firstIsHorizontal &&
secondIsHorizontal &&
Math.abs(firstStart.y - secondStart.y) < EPS
) {
const overlapLength =
Math.min(
Math.max(firstStart.x, firstEnd.x),
Math.max(secondStart.x, secondEnd.x),
) -
Math.max(
Math.min(firstStart.x, firstEnd.x),
Math.min(secondStart.x, secondEnd.x),
)
if (overlapLength > EPS) return true
}
}
}

return false
}

test("reproduces RP2040 USB-C CC2 label connector overlapping GND", () => {
const solver = new SchematicTracePipelineSolver(inputProblem as any)

solver.solve()
expect(solver).toMatchSolverSnapshot(import.meta.path)

const traces = solver.netLabelTraceCollisionSolver!.getOutput().traces
const cc2LabelConnector = traces.find(
(trace) =>
trace.userNetId === "CC2" &&
trace.mspPairId.startsWith("available-net-orientation-"),
)

expect(cc2LabelConnector).toBeDefined()

const overlappingDifferentNetTraceIds = traces
.filter(
(trace) =>
trace.globalConnNetId !== cc2LabelConnector!.globalConnNetId &&
pathsHavePositiveLengthCollinearOverlap(trace, cc2LabelConnector!),
)
.map((trace) => trace.mspPairId)

expect(overlappingDifferentNetTraceIds).toEqual([
"schematic_port_92-schematic_port_90",
"schematic_port_94-schematic_port_92",
])
})
Loading