Check PCB trace maximum lengths during routing DRC#174
Conversation
| test("warns when a PCB trace exceeds its source trace maximum length", () => { | ||
| expect(checkPcbTraceLengths(circuitJson)).toEqual([ | ||
| { | ||
| type: "pcb_trace_too_long_warning", | ||
| pcb_trace_too_long_warning_id: | ||
| "pcb_trace_too_long_warning_overlength_pcb_trace", | ||
| warning_type: "pcb_trace_too_long_warning", | ||
| message: "PCB trace is 12.00mm long, exceeding the 10mm maximum", | ||
| pcb_trace_id: "overlength_pcb_trace", | ||
| source_trace_id: "overlength_source_trace", | ||
| source_net_id: "signal_net", | ||
| actual_trace_length: 12, | ||
| maximum_trace_length: 10, | ||
| subcircuit_id: "board", | ||
| }, | ||
| ]) | ||
| }) | ||
|
|
||
| test("is included in the routing check pipeline", async () => { | ||
| const results = await runAllRoutingChecks(circuitJson) | ||
|
|
||
| expect( | ||
| results.filter((result) => result.type === "pcb_trace_too_long_warning"), | ||
| ).toEqual(checkPcbTraceLengths(circuitJson)) | ||
| }) |
There was a problem hiding this comment.
This file contains two test(...) calls (lines 54 and 72), which violates the rule that a *.test.ts file may have AT MOST one test(...). Please split this into two separate numbered files, e.g. check-pcb-trace-lengths1.test.ts (for the 'warns when a PCB trace exceeds its source trace maximum length' test) and check-pcb-trace-lengths2.test.ts (for the 'is included in the routing check pipeline' test).
Spotted by Graphite (based on custom rule: Custom rule)
Is this helpful? React 👍 or 👎 to let us know.
| if (routePoint.route_type === "via") { | ||
| traceLength += DEFAULT_VIA_LENGTH_MM | ||
| continue | ||
| } |
There was a problem hiding this comment.
Critical bug: The continue statement skips calculating the distance from the via to the next route point. This causes traces with vias to report shorter lengths than actual, potentially missing length violations.
Impact: Traces containing vias will have their lengths underreported by the distance between the via and the next route point, causing the check to miss traces that actually exceed their maximum length.
Fix: Remove the continue statement and let the code fall through to calculate the distance to the next point:
if (routePoint.route_type === "via") {
traceLength += DEFAULT_VIA_LENGTH_MM
// Don't continue - still need to calculate distance to next point
}| if (routePoint.route_type === "via") { | |
| traceLength += DEFAULT_VIA_LENGTH_MM | |
| continue | |
| } | |
| if (routePoint.route_type === "via") { | |
| traceLength += DEFAULT_VIA_LENGTH_MM | |
| // Don't continue - still need to calculate distance to next point | |
| } | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
|
Thank you for your contribution! 🎉 PR Rating: ⭐⭐ Track your contributions and see the leaderboard at: tscircuit Contribution Tracker |
Summary
pcb_tracelength with its source trace'smax_lengthpcb_trace_too_long_warningthroughrunAllRoutingCheckstrace_lengthwhen available and compute it from route points otherwisenullmaximum lengthsArchitecture
This check deliberately has no crystal-specific logic. Core is responsible for teeing up Circuit JSON by assigning component-derived limits to
source_trace.max_length; the normal routing DRC pipeline is responsible for producing warnings.Companion: tscircuit/core#2781
Validation
bun test(132 passing)bunx tsc --noEmitbun run buildgit diff --checkpass