@tscircuit/infer-cable-insertion-point
v0.0.2
Published
Infer a likely cable insertion center for USB connector footprints from `CircuitJson` PCB geometry.
Readme
@tscircuit/infer-cable-insertion-point
Infer a likely cable insertion center for USB connector footprints from CircuitJson PCB geometry.
Install
bun add @tscircuit/infer-cable-insertion-pointUsage
import { Circuit } from "tscircuit"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import {
addCableInsertNoteRect,
guessCableInsertCenter,
} from "@tscircuit/infer-cable-insertion-point"
const circuit = new Circuit()
// circuit.add(<ImportedUsbConnector name="U1" />)
await circuit.renderUntilSettled()
const circuitJson = await circuit.getCircuitJson()
const guess = guessCableInsertCenter(circuitJson)
console.log(guess)
// { x, y, side, pcbComponentId }
const { circuitJsonWithNote } = addCableInsertNoteRect(circuitJson)
const pcbSvg = convertCircuitJsonToPcbSvg(circuitJsonWithNote)addCableInsertNoteRect appends a pcb_note_rect at the inferred insertion point, with dashed stroke and label (cable-insert:<side>), so it is easy to inspect visually in rendered PCB SVGs.
How it works
- Finds the primary
pcb_componentin Circuit JSON. - Computes footprint bounds using pads, holes, and silkscreen geometry.
- Compares pad envelope to overall footprint envelope.
- Chooses the side with the largest non-pad margin (
top,bottom,left, orright). - Places the insertion center slightly outside that side.
Visual fixtures
The screenshots below come from the generated test fixtures in tests/usb-connectors/__snapshots__. In each image, the green dashed rectangle is the inferred cable insertion center.
For the complete fixture set, see all generated snapshots under tests/usb-connectors/__snapshots__.
