Skip to content

Add semantic pin 1 locations to PCB components - #684

Merged
seveibar merged 4 commits into
mainfrom
feat/pcb-component-pin1-locations
Aug 3, 2026
Merged

Add semantic pin 1 locations to PCB components#684
seveibar merged 4 commits into
mainfrom
feat/pcb-component-pin1-locations

Conversation

@seveibar

@seveibar seveibar commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add the shared PcbPin1Location semantic orientation type
  • add pcb_component.pin1_location for the rendered footprint
  • add pcb_component.supplier_pin1_location_map keyed by supplier so multiple assembly providers can coexist
  • add getRotationBetweenPcbPin1Locations for deriving transient quarter-turn corrections while rejecting reflected topology
  • validate and export the new fields, supplier map type, and helper

Both values describe unrotated, top-view footprints. Rotation offsets remain derived export data and are not persisted.

Testing

  • bun test
  • bun run build
  • bun run lint:zod
  • bun run check-snake-case
  • git diff --check

Comment on lines +22 to +47
test("maps every rotation-compatible pin 1 location pair", () => {
for (const cycle of rotationCycles) {
for (let fromIndex = 0; fromIndex < cycle.length; fromIndex++) {
for (let toIndex = 0; toIndex < cycle.length; toIndex++) {
const expectedRotation =
((toIndex - fromIndex + cycle.length) % cycle.length) * 90

expect(
getRotationBetweenPcbPin1Locations(
cycle[fromIndex],
cycle[toIndex],
),
).toBe(expectedRotation)
}
}
}
})

test("returns null when pin 1 locations differ by reflection", () => {
for (const from of rotationCycles[0]) {
for (const to of rotationCycles[1]) {
expect(getRotationBetweenPcbPin1Locations(from, to)).toBeNull()
expect(getRotationBetweenPcbPin1Locations(to, from)).toBeNull()
}
}
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A *.test.ts file may have AT MOST one test(...). This new file pcb_pin1_location.test.ts contains two test(...) calls (at lines 22 and 40). These should be split into separate numbered files, e.g. pcb_pin1_location1.test.ts and pcb_pin1_location2.test.ts.

Spotted by Graphite (based on custom rule: Custom rule)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +178 to +209
test("pcb_component allows semantic pin 1 locations", () => {
const parsed = pcb_component.parse({
...baseComponent,
pin1_location: "leftside_top",
supplier_pin1_location_map: {
jlcpcb: "topside_left",
pcbway: "rightside_bottom",
},
})

expect(parsed.pin1_location).toBe("leftside_top")
expect(parsed.supplier_pin1_location_map).toEqual({
jlcpcb: "topside_left",
pcbway: "rightside_bottom",
})
})

test("pcb_component rejects invalid semantic pin 1 locations", () => {
expect(() =>
pcb_component.parse({
...baseComponent,
pin1_location: "top_left",
}),
).toThrowError()

expect(() =>
pcb_component.parse({
...baseComponent,
supplier_pin1_location_map: { jlcpcb: "top_left" },
}),
).toThrowError()
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This file now contains multiple test(...) calls. The rule states that a *.test.ts file may have AT MOST one test(...). Two new tests were added here ('pcb_component allows semantic pin 1 locations' at line 178 and 'pcb_component rejects invalid semantic pin 1 locations' at line 195), on top of the existing tests already in the file. These new tests should be split into separate, numbered files, e.g. pcb_component_position_mode1.test.ts, pcb_component_position_mode2.test.ts, etc.

Spotted by Graphite (based on custom rule: Custom rule)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@seveibar
seveibar merged commit 68b8170 into main Aug 3, 2026
5 checks passed
@seveibar
seveibar deleted the feat/pcb-component-pin1-locations branch August 3, 2026 19:32
@tscircuitbot

Copy link
Copy Markdown
Contributor

Thank you for your contribution! 🎉

PR Rating: ⭐⭐⭐
Impact: Major

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


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.

2 participants