diff --git a/lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/solvePortOnlyPin.ts b/lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/solvePortOnlyPin.ts index dc67d6c..0c6633c 100644 --- a/lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/solvePortOnlyPin.ts +++ b/lib/solvers/NetLabelPlacementSolver/SingleNetLabelPlacementSolver/solvePortOnlyPin.ts @@ -14,6 +14,8 @@ import { } from "./geometry" import { rectIntersectsAnyTrace } from "./collisions" +const NET_LABEL_EDGE_OFFSET = 0.01 + export function solveNetLabelPlacementForPortOnlyPin(params: { inputProblem: InputProblem inputTraceMap: Record @@ -51,16 +53,22 @@ export function solveNetLabelPlacementForPortOnlyPin(params: { } } - // Find pin coordinates + // Find pin coordinates and chip bounds let pin: { x: number; y: number } | null = null + let pinChip: { + center: { x: number; y: number } + width: number + height: number + } | null = null for (const chip of inputProblem.chips) { const p = chip.pins.find((pp) => pp.pinId === pinId) if (p) { pin = { x: p.x, y: p.y } + pinChip = { center: chip.center, width: chip.width, height: chip.height } break } } - if (!pin) { + if (!pin || !pinChip) { return { placement: null, testedCandidates: [], @@ -73,7 +81,6 @@ export function solveNetLabelPlacementForPortOnlyPin(params: { ? availableOrientations : (["x+", "x-", "y+", "y-"] as FacingDirection[]) - const anchor = { x: pin.x, y: pin.y } const outwardOf = (o: FacingDirection) => o === "x+" ? { x: 1, y: 0 } @@ -94,18 +101,50 @@ export function solveNetLabelPlacementForPortOnlyPin(params: { hostSegIndex: number }> = [] + const chipBounds = { + minX: pinChip.center.x - pinChip.width / 2, + maxX: pinChip.center.x + pinChip.width / 2, + minY: pinChip.center.y - pinChip.height / 2, + maxY: pinChip.center.y + pinChip.height / 2, + } + for (const orientation of orientations) { const { width, height } = getDimsForOrientation(orientation) - // Place label fully outside the chip: shift center slightly outward + + const anchor: { x: number; y: number } = { x: pin.x, y: pin.y } + + const distanceToEdge = + orientation === "x+" + ? chipBounds.maxX - pin.x + : orientation === "x-" + ? pin.x - chipBounds.minX + : orientation === "y+" + ? chipBounds.maxY - pin.y + : pin.y - chipBounds.minY + const baseCenter = getCenterFromAnchor(anchor, orientation, width, height) const outward = outwardOf(orientation) - const offset = 1e-3 + const offset = distanceToEdge + NET_LABEL_EDGE_OFFSET + + console.debug( + "[solvePortOnlyPin] orientation", + orientation, + "anchor", + anchor, + "distanceToEdge", + distanceToEdge, + "offset", + offset, + ) + const center = { x: baseCenter.x + outward.x * offset, y: baseCenter.y + outward.y * offset, } const bounds = getRectBounds(center, width, height) + console.debug("[solvePortOnlyPin] center", center, "bounds", bounds) + // Chip collision check const chips = chipObstacleSpatialIndex.getChipsInBounds(bounds) if (chips.length > 0) { @@ -119,6 +158,7 @@ export function solveNetLabelPlacementForPortOnlyPin(params: { status: "chip-collision", hostSegIndex: -1, }) + console.debug("[solvePortOnlyPin] chip collision") continue } @@ -141,6 +181,7 @@ export function solveNetLabelPlacementForPortOnlyPin(params: { status: "trace-collision", hostSegIndex: -1, }) + console.debug("[solvePortOnlyPin] trace collision") continue } @@ -156,6 +197,8 @@ export function solveNetLabelPlacementForPortOnlyPin(params: { hostSegIndex: -1, }) + console.debug("[solvePortOnlyPin] found valid placement") + const placement: NetLabelPlacement = { globalConnNetId: overlappingSameNetTraceGroup.globalConnNetId, dcConnNetId: undefined, diff --git a/tests/examples/__snapshots__/example01.snap.svg b/tests/examples/__snapshots__/example01.snap.svg index 3e85213..aa75edf 100644 --- a/tests/examples/__snapshots__/example01.snap.svg +++ b/tests/examples/__snapshots__/example01.snap.svg @@ -2,100 +2,100 @@ +x-" data-x="-0.8" data-y="0.2" cx="390.63520871143373" cy="299.6733212341198" r="3" fill="hsl(319, 100%, 50%, 0.8)" /> +x-" data-x="-0.8" data-y="0" cx="390.63520871143373" cy="320" r="3" fill="hsl(320, 100%, 50%, 0.8)" /> +x-" data-x="-0.8" data-y="-0.2" cx="390.63520871143373" cy="340.3266787658802" r="3" fill="hsl(321, 100%, 50%, 0.8)" /> +x+" data-x="0.8" data-y="-0.2" cx="553.2486388384755" cy="340.3266787658802" r="3" fill="hsl(322, 100%, 50%, 0.8)" /> +x+" data-x="0.8" data-y="0" cx="553.2486388384755" cy="320" r="3" fill="hsl(323, 100%, 50%, 0.8)" /> +x+" data-x="0.8" data-y="0.2" cx="553.2486388384755" cy="299.6733212341198" r="3" fill="hsl(324, 100%, 50%, 0.8)" /> +y+" data-x="-2" data-y="0.5" cx="268.67513611615243" cy="269.1833030852995" r="3" fill="hsl(121, 100%, 50%, 0.8)" /> +y-" data-x="-2" data-y="-0.5" cx="268.67513611615243" cy="370.8166969147005" r="3" fill="hsl(122, 100%, 50%, 0.8)" /> +y+" data-x="-4" data-y="0.5" cx="65.40834845735026" cy="269.1833030852995" r="3" fill="hsl(2, 100%, 50%, 0.8)" /> +y-" data-x="-4" data-y="-0.5" cx="65.40834845735026" cy="370.8166969147005" r="3" fill="hsl(3, 100%, 50%, 0.8)" /> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +