Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/**
* Packs components within a single partition to create an optimal internal layout.
* Uses a packing algorithm to arrange chips and their connections within the partition.
*
* For decoupling capacitor partitions, uses a specialized horizontal row layout
* instead of the general-purpose PackSolver2.
*/

import type { GraphicsObject } from "graphics-debug"
Expand Down Expand Up @@ -38,6 +41,14 @@ export class SingleInnerPartitionPackingSolver extends BaseSolver {
}

override _step() {
// Specialized layout for decoupling capacitor partitions:
// Arrange caps in a clean horizontal row instead of using PackSolver2
if (this.partitionInputProblem.partitionType === "decoupling_caps") {
this.layout = this.createDecouplingCapLayout()
this.solved = true
return
}

// Initialize PackSolver2 if not already created
if (!this.activeSubSolver) {
const packInput = this.createPackInput()
Expand All @@ -64,6 +75,47 @@ export class SingleInnerPartitionPackingSolver extends BaseSolver {
}
}

/**
* Creates a clean horizontal row layout for decoupling capacitors.
* Caps are placed in a single row with consistent orientation and even spacing.
*/
private createDecouplingCapLayout(): OutputLayout {
const chipEntries = Object.entries(this.partitionInputProblem.chipMap)
const gap = this.partitionInputProblem.decouplingCapsGap ?? 0.5

// Calculate total width needed
let totalWidth = 0
const chipWidths: Array<{ chipId: string; width: number; height: number }> = []

for (const [chipId, chip] of chipEntries) {
const width = chip.size.x
const height = chip.size.y
chipWidths.push({ chipId, width, height })
totalWidth += width
}

// Add gaps between caps
totalWidth += gap * (chipEntries.length - 1)

// Place caps centered around origin in a horizontal row
const chipPlacements: Record<string, Placement> = {}
let currentX = -totalWidth / 2

for (const { chipId, width } of chipWidths) {
chipPlacements[chipId] = {
x: currentX + width / 2,
y: 0,
ccwRotationDegrees: 0,
}
currentX += width + gap
}

return {
chipPlacements,
groupPlacements: {},
}
}

private createPackInput(): PackInput {
// Fall back to filtered mapping (weak + strong)
const pinToNetworkMap = createFilteredNetworkMapping({
Expand Down