Skip to content

Repository files navigation

@tscircuit/implicit-copper-pour-solver

Generate implicit pcb_copper_pour polygon elements for power nets in Circuit JSON.

The solver follows the power-trace-expansion algorithm from the supplied JSX artifact:

  1. Sample a regular grid on each selected copper layer.
  2. Assign every in-board sample to its nearest net-owned pad, trace, or via.
  3. Group four-connected cells with the same nearest net.
  4. Discard regions below the configured minimum area.
  5. Trace each surviving grid region into a rectilinear polygon.
  6. Emit polygons only when the owning source_net has is_power, is_ground, or is_positive_voltage_source set.

Usage

import { ImplicitCopperPourPipelineSolver } from "@tscircuit/implicit-copper-pour-solver"

const solver = new ImplicitCopperPourPipelineSolver({
  circuitJson,
  gridPitch: 0.25,
  minRegionArea: 2,
  layers: ["top", "bottom"],
})

solver.solve()
const copperPourElements = solver.getOutput()
const circuitJsonWithPours = [...circuitJson, ...copperPourElements]

The class extends BasePipelineSolver from @tscircuit/solver-utils and uses three debugger-visible stages: Circuit JSON preparation, nearest-net grid assignment, and power polygon tracing.

Development

bun install
bun test
bun run typecheck
bun run format:check
bun run start

Visual snapshot tests

The nRF52810 fixture is rendered as a full board before and after solving. The solved result is also rendered separately for every copper layer. These images are compared with committed SVG snapshots in tests/__snapshots__. Snapshot mismatches generate .diff.png files, which CI uploads as artifacts.

Update approved snapshots with:

bun run test:update-snapshots

Releases

Packages

Contributors

Languages