Skip to content

Fix per-layer PCB trace rendering for via routes and add minimal plated-hole/via repro fixture#699

Merged
seveibar merged 1 commit intotscircuit:mainfrom
rushabhcodes:fix/pcb-trace-layer-filtering-via-fixture
Mar 13, 2026
Merged

Fix per-layer PCB trace rendering for via routes and add minimal plated-hole/via repro fixture#699
seveibar merged 1 commit intotscircuit:mainfrom
rushabhcodes:fix/pcb-trace-layer-filtering-via-fixture

Conversation

@rushabhcodes
Copy link
Copy Markdown
Contributor

@rushabhcodes rushabhcodes commented Mar 13, 2026

This pull request introduces a new SparkfunBoards fixture for PCB visualization and refactors the PCB trace drawing logic to improve type safety and layer filtering. The main focus is on enhancing how PCB traces are filtered and rendered per layer, leading to more maintainable and robust code.

image

Before

image

https://tscircuit--sparkfun-boards-v0-0-8-pr272-15835086.tscircuit.app/

PCB Trace Drawing Improvements:

  • Refactored the isPcbTrace type guard to use a TypeScript type predicate, improving type safety when distinguishing PcbTrace elements.
  • Added a new filterTraceByLayers function to filter trace segments by the target copper layers, ensuring only relevant wire segments are drawn for the selected layers.
  • Updated the drawPcbTraceElementsForLayer function to use filterTraceByLayers and improved the logic for separating highlighted and non-highlighted traces, enhancing clarity and correctness. [1] [2]

Fixture Addition:

  • Added a new SparkfunBoards React component in sparkfun-boards.fixture.tsx to showcase PCB visualization with plated holes, traces, and vias, using the PCBViewer component.

Type Imports:

  • Updated type imports in draw-pcb-trace.ts to include PcbTrace for stronger typing throughout the file.

Copilot AI review requested due to automatic review settings March 13, 2026 14:43
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pcb-viewer Ready Ready Preview, Comment Mar 13, 2026 2:43pm

Request Review

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates PCB trace rendering to better handle per-layer drawing/highlighting, and adds a new 2026 fixture intended to reproduce/validate Sparkfun-style board routing (including via transitions).

Changes:

  • Strengthen isPcbTrace typing and introduce route filtering for traces by target copper layers during rendering.
  • Refactor highlighted vs non-highlighted trace partitioning to a single-pass loop.
  • Add SparkfunBoards example fixture with a small trace + via scenario.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/lib/draw-pcb-trace.ts Adds per-layer trace route filtering and minor highlight partition refactor for trace drawing.
src/examples/2026/sparkfun-boards.fixture.tsx New fixture to render a small Sparkfun-like route including a via and top/bottom segments.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +53
const filteredRoute = trace.route.filter(
(segment) =>
segment.route_type === "wire" &&
"layer" in segment &&
targetLayers.has(segment.layer),
)

if (filteredRoute.length === 0) return null

return {
...trace,
route: filteredRoute,
}
Comment on lines +6 to +10
return (
<div style={{ backgroundColor: "black", width: "100%", height: "700px" }}>
<PCBViewer circuitJson={[
{
"type": "pcb_plated_hole",
Copy link
Copy Markdown
Contributor

@Abse2001 Abse2001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait for Seve's review , and after this we need to make vias and plated holes color blue like bottom traces when switching to bottom layer on the viewere

@rushabhcodes
Copy link
Copy Markdown
Contributor Author

wait for Seve's review , and after this we need to make vias and plated holes color blue like bottom traces when switching to bottom layer on the viewere

I am working on that too

@seveibar seveibar merged commit d8b4c79 into tscircuit:main Mar 13, 2026
9 checks passed
@rushabhcodes rushabhcodes deleted the fix/pcb-trace-layer-filtering-via-fixture branch March 13, 2026 17:22
@tscircuitbot
Copy link
Copy Markdown
Contributor


Thank you for your contribution! 🎉

PR Rating: ⭐⭐
Impact: Minor

Track your contributions and see the leaderboard at: tscircuit Contribution Tracker


@rushabhcodes
Copy link
Copy Markdown
Contributor Author

@seveibar
Copy link
Copy Markdown
Contributor

This broke so much stuff @rushabhcodes....

@seveibar
Copy link
Copy Markdown
Contributor

i have to completely redo this

image

@seveibar
Copy link
Copy Markdown
Contributor

/sabotage

@seveibar
Copy link
Copy Markdown
Contributor

corrected version

image

@seveibar
Copy link
Copy Markdown
Contributor

#725

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants