Skip to content
Draft
Show file tree
Hide file tree
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
Expand Up @@ -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<MspConnectionPairId, SolvedTracePath>
Expand Down Expand Up @@ -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: [],
Expand All @@ -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 }
Expand All @@ -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) {
Expand All @@ -119,6 +158,7 @@ export function solveNetLabelPlacementForPortOnlyPin(params: {
status: "chip-collision",
hostSegIndex: -1,
})
console.debug("[solvePortOnlyPin] chip collision")
continue
}

Expand All @@ -141,6 +181,7 @@ export function solveNetLabelPlacementForPortOnlyPin(params: {
status: "trace-collision",
hostSegIndex: -1,
})
console.debug("[solvePortOnlyPin] trace collision")
continue
}

Expand All @@ -156,6 +197,8 @@ export function solveNetLabelPlacementForPortOnlyPin(params: {
hostSegIndex: -1,
})

console.debug("[solvePortOnlyPin] found valid placement")

const placement: NetLabelPlacement = {
globalConnNetId: overlappingSameNetTraceGroup.globalConnNetId,
dcConnNetId: undefined,
Expand Down
64 changes: 32 additions & 32 deletions tests/examples/__snapshots__/example01.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading