Skip to content

Commit

Permalink
fix: port offset sometimes not connecting properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Severin Ibarluzea committed Jun 21, 2024
1 parent 1e46bd6 commit 70b1240
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/lib/builder/trace-builder/route-solvers/port-offset-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ export const portOffsetWrapper =
const ot = offsetTerminals[i]

// Find nearest point in the route to the offset terminal
const nearestPoint = edges.reduce(
(nearest, edge) => {
const dist = Math.hypot(edge.from.x - ot.x, edge.from.y - ot.y)
if (dist < nearest.dist) return { dist, point: edge.from }
return nearest
},
{ dist: Infinity, point: { x: 0, y: 0 } }
)
const nearestPoint = edges
.flatMap((edge) => [edge.from, edge.to])
.reduce(
(nearest, p) => {
const dist = Math.hypot(p.x - ot.x, p.y - ot.y)
if (dist < nearest.dist) return { dist, point: p }
return nearest
},
{ dist: Infinity, point: { x: 0, y: 0 } }
)

return {
from: { x: t.x, y: t.y, ti: i },
Expand Down
2 changes: 1 addition & 1 deletion tests/trace-builder/bad-schematic-route-1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test("bad schematic route 1", async (t) => {
rb.setProps({
resistance: 100,
name: "R1",
rotation: "-90deg",
rotation: "90deg",
schX: -2,
schY: -2,
})
Expand Down

0 comments on commit 70b1240

Please sign in to comment.