Skip to content

Commit

Permalink
Merge pull request #201 from tscircuit/fix/shifting-port-position
Browse files Browse the repository at this point in the history
fix: undefined pin skip
  • Loading branch information
imrishabh18 authored Oct 25, 2024
2 parents 909f351 + eeb17e7 commit 3732a52
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
Binary file modified bun.lockb
Binary file not shown.
40 changes: 30 additions & 10 deletions lib/utils/schematic/getAllDimensionsForSchematicBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ interface Params {

type Side = "left" | "right" | "top" | "bottom"

type PortInfo = {
trueIndex: number
pinNumber: number
side: "left" | "right" | "top" | "bottom" | "center"
distanceFromEdge: number
x: number
y: number
}

function isExplicitPinMappingArrangement(
arrangement: PortArrangement,
): arrangement is ExplicitPinMappingArrangement {
Expand All @@ -75,7 +84,7 @@ function isExplicitPinMappingArrangement(
*/
export interface SchematicBoxDimensions {
pinCount: number
getPortPositionByPinNumber(pinNumber: number): { x: number; y: number }
getPortPositionByPinNumber(pinNumber: number): PortInfo
getSize(): { width: number; height: number }
}

Expand Down Expand Up @@ -148,12 +157,7 @@ export const getAllDimensionsForSchematicBox = (
return (sideLength - totalMargin) / (sideSize - 1)
}

const orderedTruePorts: Array<{
trueIndex: number
pinNumber: number
side: "left" | "right" | "top" | "bottom"
distanceFromEdge: number
}> = []
const orderedTruePorts: PortInfo[] = []

let truePinIndex = 0

Expand Down Expand Up @@ -229,6 +233,8 @@ export const getAllDimensionsForSchematicBox = (
pinNumber,
side,
distanceFromEdge: currentDistanceFromEdge,
x: 0,
y: 0,
})

if (pinStyle) {
Expand Down Expand Up @@ -351,23 +357,37 @@ export const getAllDimensionsForSchematicBox = (

const truePortsWithPositions = orderedTruePorts.map((p) => {
const { distanceFromEdge, side } = p
if (side === "center") {
return {
...p,
x: 0,
y: 0,
}
}
const edgePos = trueEdgePositions[side]
const edgeDir = trueEdgeTraversalDirections[side]

return {
...p,
x: edgePos.x + distanceFromEdge * edgeDir.x,
y: edgePos.y + distanceFromEdge * edgeDir.y,
...p,
}
})

return {
getPortPositionByPinNumber(pinNumber: number): { x: number; y: number } {
getPortPositionByPinNumber(pinNumber: number): PortInfo {
const port = truePortsWithPositions.find(
(p) => p.pinNumber.toString() === pinNumber.toString(),
)
if (!port) {
return { x: 0, y: 0 }
return {
trueIndex: -1, // Use -1 for non-existent ports
pinNumber: pinNumber,
side: "center",
distanceFromEdge: 0,
x: 0,
y: 0,
}
}
return port
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@tscircuit/soup-util": "^0.0.33",
"circuit-json": "^0.0.91",
"circuit-json-to-connectivity-map": "^0.0.17",
"circuit-to-svg": "^0.0.54",
"circuit-to-svg": "^0.0.55",
"nanoid": "^5.0.7",
"performance-now": "^2.1.0",
"react": "^18.3.1",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3732a52

Please sign in to comment.