Skip to content

Commit

Permalink
fix port association failure when traceWidth makes them overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Jul 28, 2024
1 parent 63b0a8e commit 1e6078f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/add-start-and-end-port-ids-if-missing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ export const addStartAndEndPortIdsIfMissing = (
x: number
y: number
},
options: { isFirstOrLastPoint?: boolean } = {},
options: { isFirstOrLastPoint?: boolean; traceWidth?: number } = {},
): string | null {
const traceWidth = options.traceWidth || 0
const directPort = pcbPorts.find(
(port) => distance(port.x, port.y, point.x, point.y) < 0.01,
)
Expand All @@ -41,8 +42,8 @@ export const addStartAndEndPortIdsIfMissing = (
const smtPad = pcbSmtPads.find((pad) => {
if (pad.shape === "rect") {
return (
Math.abs(point.x - pad.x) < pad.width / 2 &&
Math.abs(point.y - pad.y) < pad.height / 2
Math.abs(point.x - pad.x) < pad.width / 2 + traceWidth / 2 &&
Math.abs(point.y - pad.y) < pad.height / 2 + traceWidth / 2
)
// biome-ignore lint/style/noUselessElse: <explanation>
} else if (pad.shape === "circle") {
Expand All @@ -64,6 +65,7 @@ export const addStartAndEndPortIdsIfMissing = (
if (!segment.start_pcb_port_id && index === 0) {
const startPortId = findPortIdOverlappingPoint(segment, {
isFirstOrLastPoint,
traceWidth: segment.width,
})
if (startPortId) {
segment.start_pcb_port_id = startPortId
Expand All @@ -72,6 +74,7 @@ export const addStartAndEndPortIdsIfMissing = (
if (!segment.end_pcb_port_id && index === trace.route.length - 1) {
const endPortId = findPortIdOverlappingPoint(segment, {
isFirstOrLastPoint,
traceWidth: segment.width,
})
if (endPortId) {
segment.end_pcb_port_id = endPortId
Expand Down

0 comments on commit 1e6078f

Please sign in to comment.