Skip to content

feat: add via-to-pad clearance DRC check#154

Open
Timmmmmo wants to merge 1 commit into
tscircuit:mainfrom
Timmmmmo:feat/via-pad-clearance-check
Open

feat: add via-to-pad clearance DRC check#154
Timmmmmo wants to merge 1 commit into
tscircuit:mainfrom
Timmmmmo:feat/via-pad-clearance-check

Conversation

@Timmmmmo

Copy link
Copy Markdown

Summary

Implements check-via-pad-clearance that detects when a via is placed too close to a pad (SMT pad or plated hole) on a different net. Closes #44.

Key design decisions

  • Comprehensive pad shape support: Uses getBoundsOfPcbElements so that all pad shapes (circle, rect, pill, rotated_pill, polygon, etc.) are handled correctly - not just circle and rect
  • Via modeled as circle, pad as circle or bounding-box polygon: Leverages existing distanceBetweenCircleAndCircle / distanceBetweenCircleAndPolygon from circuit-json-util
  • SpatialObjectIndex for efficient lookup: Same pattern as existing clearance checks
  • Connectivity-aware: Vias connected to the same net as the pad are not flagged
  • Exports getCircleShape and getPolygonShape from common.ts: Reuses existing helpers instead of duplicating code
  • Local PcbViaPadClearanceError interface: circuit-json doesn't have this type yet; promoting it upstream would be a natural follow-up
  • Registered in runAllRoutingChecks and index.ts

Test coverage (7 tests)

Test Description
via too close to circle pad Detects violation for circular pad
via far from pad No false positive at distance
via too close to rect pad Detects violation for rectangular pad
via too close to plated hole Detects violation for plated hole
custom minClearance Respects override clearance value
no vias Returns empty for no vias
no pads Returns empty for no pads

All 118 tests pass (7 new + 111 existing).

Implements check-via-pad-clearance that detects when a via is placed too
close to a pad (SMT pad or plated hole) on a different net.

Key design decisions:
- Uses getBoundsOfPcbElements for comprehensive pad shape support
  (circle, rect, pill, rotated_pill, polygon, etc.)
- Via treated as circle, pad as circle or bounding-box polygon
- Uses SpatialObjectIndex for efficient neighbor lookup
- Shares connectivity map with other DRC checks
- Declares local PcbViaPadClearanceError interface (circuit-json
  doesn't have this type yet)

Fixes tscircuit#44
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.

New DRC Check: Check vias aren't too close to pads

1 participant