Skip to content

Specialized decoupling-cap layout with VCC-pin alignment (#15)#94

Open
s300169140 wants to merge 1 commit into
tscircuit:mainfrom
s300169140:fix/15-decoupling-caps-layout
Open

Specialized decoupling-cap layout with VCC-pin alignment (#15)#94
s300169140 wants to merge 1 commit into
tscircuit:mainfrom
s300169140:fix/15-decoupling-caps-layout

Conversation

@s300169140
Copy link
Copy Markdown

Closes #15.

What

Adds a dedicated layout path for partitions tagged `partitionType: "decoupling_caps"`. Caps are placed in a centered horizontal row, each rotated so its positive-voltage pin consistently faces the same direction across the row.

Why rotation alignment matters

In a clean schematic, all decoupling caps in a row should be oriented identically — every VCC pin pointing the same way (typically up). Mixed orientations make the schematic look messy even when the geometry is otherwise correct.

The straightforward "linear row" approach (which is also what #59 implements) just calls `availableRotations[0]` per cap. That works when all caps happen to be wired with VCC on the same pin number, but breaks the moment one cap is wired backwards (which happens whenever a maintainer drops in a cap from a different reference design).

This PR adds the bit that makes the row look uniform: it picks each cap's rotation based on which pin is actually connected to a positive-voltage net.

Algorithm

  1. For each cap, find which pin (if any) is connected to a net with `isPositiveVoltageSource: true` (the existing `netMap` already carries that flag — `IdentifyDecouplingCapsSolver` uses the same data).
  2. Pick a target side via majority vote of the caps' natural-rotation positions (preferring `y+` on ties). This minimizes the number of caps that need to be flipped from their input orientation.
  3. For each cap, pick the rotation from `availableRotations` that puts its positive pin on the target side. Fall back to `availableRotations[0]` when the cap has no voltage signal.

Caps are then laid out left-to-right using `decouplingCapsGap` (or `chipGap`) and the row is centered on x=0.

Tests

  • `tests/PackInnerPartitionsSolver/DecouplingCapsLayout.test.ts`:
    • happy-path: three caps where one is wired backwards (VCC on bottom pin instead of top). Verifies it gets flipped 180° while the others keep their natural rotation.
    • no-voltage-signal: a cap with no positive-voltage net falls back cleanly to `availableRotations[0]`.

Relationship to #59

#59 (h/t @Ojas2095) implements the same overall pattern (special-case for `decoupling_caps` → linear row) and is a good baseline. The differences are:

If you'd prefer #59's broader changes plus the rotation alignment from this PR, happy to rebase mine on top.

Verification

  • `bunx tsc --noEmit` — clean
  • `bun run format:check` — clean
  • `bun test` — 19 pass / 1 skip / 1 fail. The single failure is the pre-existing `IdentifyDecouplingCapsSolver06.test.ts` import error from the linked `.page.tsx` (also fails on `main`); this PR doesn't touch that path.

…it#15)

closes tscircuit#15

Adds a specialized layout path for partitions tagged
\`partitionType: "decoupling_caps"\`. Instead of running them through the
generic \`PackSolver2\`, the caps are placed in a centered horizontal row,
each rotated so its positive-voltage pin consistently faces the same
direction across the row.

Why rotation alignment matters: a hand-drawn schematic of decoupling
caps always has every cap oriented identically (VCC up, GND down, or the
opposite) — never alternating. The previous layout code (and an
alternative attempt in tscircuit#59) just used \`availableRotations[0]\`, which
left mixed orientations whenever the input was wired with VCC on
different pins of different caps.

Algorithm:

1. For each cap in the partition, find which pin (if any) is connected
   to a positive-voltage net (\`netMap[netId].isPositiveVoltageSource\`)
2. Pick a target side for that pin via majority vote of the caps'
   natural-rotation positions (preferring \`y+\` on ties), so already-
   correctly-oriented caps don't get unnecessarily rotated
3. For each cap, pick the rotation from \`availableRotations\` that puts
   its positive pin on the target side; fall back to the first allowed
   rotation when the cap has no voltage signal

Caps are then laid out left-to-right with \`decouplingCapsGap\` (or
\`chipGap\` as fallback) and the resulting row is centered on x=0.

Tests added:
- happy-path: three caps where one is wired backwards; verifies it gets
  flipped 180° while the others keep their natural rotation
- no-voltage-signal: cap with no positive-voltage net falls back to
  \`availableRotations[0]\`

Note: the existing test \`IdentifyDecouplingCapsSolver06.test.ts\` fails
on \`main\` due to an unrelated import error in the linked
\`LayoutPipelineSolver06.page.tsx\`. That failure is unchanged by this
PR.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

@s300169140 is attempting to deploy a commit to the tscircuit Team on Vercel.

A member of the Team first needs to authorize it.

@s300169140
Copy link
Copy Markdown
Author

Heads up on the red 'test' check — that failure is pre-existing on main, unrelated to this PR.

The error is a transitive dep version mismatch:

SyntaxError: Export named 'convertCircuitJsonToSchematicSimulationSvg' not found in module circuit-to-svg

@tscircuit/schematic-viewer@2.0.61 (pinned by ^2.0.26 in package.json) references that symbol, but the resolved circuit-to-svg@0.0.174 doesn't export it. Triggered by tests/IdentifyDecouplingCapsSolver/IdentifyDecouplingCapsSolver06.test.ts importing problem from a .page.tsx that pulls in schematic-viewer via LayoutPipelineDebugger.

You can confirm by running bun test on main directly — same single failure, same module.

I deliberately didn't touch deps in this PR to keep the diff minimal and focused on #15. Two clean follow-up options when you're ready:

  1. Bump @tscircuit/schematic-viewer to a version compatible with the installed circuit-to-svg (or pin both)
  2. Add the missing export in circuit-to-svg and release a patch

Happy to send the fix as a separate PR if helpful. Just wanted to make sure the red badge doesn't read as 'this PR broke tests' — the new tests I added (tests/PackInnerPartitionsSolver/DecouplingCapsLayout.test.ts) both pass cleanly:

(pass) decoupling-caps partition lays caps in a centered horizontal row
(pass) decoupling-caps with no positive-voltage pin info falls back to first available rotation

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.

Specialized Layout for Decoupling Capacitors

1 participant