Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -76,8 +76,34 @@ export class SchematicTraceSingleLineSolver extends BaseSolver {
pin._facingDirection = getPinDirection(pin, chip)
}
}

const [pin1, pin2] = this.pins

// Attempt direct straight-line connection if pins are aligned
const EPS = 1e-6
const isDirectVertical = Math.abs(pin1.x - pin2.x) < EPS
const isDirectHorizontal = Math.abs(pin1.y - pin2.y) < EPS
if (isDirectVertical || isDirectHorizontal) {
const directPath = [
{ x: pin1.x, y: pin1.y },
{ x: pin2.x, y: pin2.y },
]
const excludeChipIds = Array.from(new Set(this.pins.map((p) => p.chipId)))
const intersects =
this.chipObstacleSpatialIndex.doesOrthogonalLineIntersectChip(
directPath,
{ excludeChipIds },
)
if (!intersects) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Direct-line solver ignores collisions with shared chip

The early return for aligned pins drops both pins’ chip IDs before calling doesOrthogonalLineIntersectChip. When the pins are on the same chip this removes the only obstacle that would block the path, so the solver now marks a straight segment across the chip interior as solved without running the later getRestrictedCenterLines and interior-approach checks. Previously these routes were forced to leave the chip and bend around its center; now they can cut directly through the component. This violates the solver’s own chip-intersection rules and will produce invalid traces for any same-chip connection. The shortcut should skip when both pins share a chip or still verify the path against that chip’s bounds.

Useful? React with 👍 / 👎.

this.solvedTracePath = directPath
this.solved = true
this.baseElbow = directPath
this.movableSegments = []
this.allCandidatePaths = [directPath]
this.queuedCandidatePaths = [directPath]
return
}
}

this.baseElbow = calculateElbow(
{
x: pin1.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,27 @@ export class SchematicTraceSingleLineSolver2 extends BaseSolver {
this.obstacles = getObstacleRects(this.inputProblem)
this.rectById = new Map(this.obstacles.map((r) => [r.chipId, r]))

// Build initial elbow path
const [pin1, pin2] = this.pins

// Attempt direct straight-line connection if pins are aligned
const EPS = 1e-6
const isDirectVertical = Math.abs(pin1.x - pin2.x) < EPS
const isDirectHorizontal = Math.abs(pin1.y - pin2.y) < EPS
if (isDirectVertical || isDirectHorizontal) {
const directPath: Point[] = [
{ x: pin1.x, y: pin1.y },
{ x: pin2.x, y: pin2.y },
]
const collision = findFirstCollision(directPath, this.obstacles)
if (!collision) {
this.solvedTracePath = directPath
this.solved = true
this.baseElbow = directPath
this.aabb = aabbFromPoints(directPath[0]!, directPath[1]!)
return
}
}
// Build initial elbow path
this.baseElbow = calculateElbow(
{
x: pin1.x,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { SchematicTraceSingleLineSolver2 } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceSingleLineSolver2/SchematicTraceSingleLineSolver2"
import { test, expect } from "bun:test"

test("SchematicTraceSingleLineSolver2 traces direct horizontal line when possible", () => {
const chipA = {
chipId: "A",
center: { x: 0, y: 0 },
width: 1,
height: 1,
pins: [
{
pinId: "A.1",
x: 0.5,
y: 0,
},
],
}
const chipB = {
chipId: "B",
center: { x: 3, y: 0 },
width: 1,
height: 1,
pins: [
{
pinId: "B.1",
x: 2.5,
y: 0,
},
],
}

const input = {
chipMap: {
A: chipA,
B: chipB,
},
pins: [
{ pinId: "A.1", x: 0.5, y: 0, chipId: "A" },
{ pinId: "B.1", x: 2.5, y: 0, chipId: "B" },
],
inputProblem: {
chips: [chipA, chipB],
},
}

const solver = new SchematicTraceSingleLineSolver2(input as any)
solver.solve()

expect(solver.solved).toBe(true)
expect(solver.solvedTracePath).toEqual([
{ x: 0.5, y: 0 },
{ x: 2.5, y: 0 },
])
})
Loading