Skip to content
Merged
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
19 changes: 18 additions & 1 deletion lib/utils/convertHdRouteToSimplifiedRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { mapZToLayerName } from "./mapZToLayerName"

type Point = { x: number; y: number; z: number }
const DEFAULT_TERMINAL_VIA_ATTACH_TOLERANCE = 0.25
const SAME_POINT_TOLERANCE = 1e-12

export interface ConvertHdRouteToSimplifiedRouteOptions {
connectionPoints?: ReadonlyArray<ConnectionPoint>
Expand All @@ -24,6 +25,15 @@ type HdRouteWithOptionalJumpers = HighDensityIntraNodeRoute & {
jumpers?: Jumper[]
}

const areSameXyPoint = (
a: Pick<Point, "x" | "y"> | undefined,
b: Pick<Point, "x" | "y"> | undefined,
) =>
!!a &&
!!b &&
Math.abs(a.x - b.x) <= SAME_POINT_TOLERANCE &&
Math.abs(a.y - b.y) <= SAME_POINT_TOLERANCE

const findNearestTerminalViaPoint = ({
endpoint,
endpointLayer,
Expand Down Expand Up @@ -238,7 +248,14 @@ export const convertHdRouteToSimplifiedRoute = (
currentZ = point.z
} else {
// Continue on the same layer
currentLayerPoints.push(point)
if (
!areSameXyPoint(
currentLayerPoints[currentLayerPoints.length - 1],
point,
)
) {
currentLayerPoints.push(point)
}
}
}

Expand Down
72 changes: 72 additions & 0 deletions tests/utils/convertHdRouteToSimplifiedRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,78 @@ describe("convertHdRouteToSimplifiedRoute", () => {
`)
})

test("removes consecutive duplicate points on the same layer", () => {
const input: HighDensityIntraNodeRoute = {
connectionName: "duplicate-point-route",
traceThickness: 0.2,
viaDiameter: 0.6,
route: [
{ x: 1, y: 1, z: 0 },
{ x: 1, y: 1, z: 0 },
{ x: 2, y: 1, z: 0 },
],
vias: [],
}

const result = convertHdRouteToSimplifiedRoute(input, 2)
expect(result).toMatchInlineSnapshot(`
[
{
"layer": "top",
"route_type": "wire",
"width": 0.2,
"x": 1,
"y": 1,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.2,
"x": 2,
"y": 1,
},
]
`)
})

test("zero-length segment repro preserves the original duplicate point pair", () => {
const route = [
{
route_type: "wire",
x: -3.9823015744754504,
y: 18.50630157447545,
width: 0.6,
layer: "top",
},
{
route_type: "wire",
x: -3.9823015744754504,
y: 18.50630157447545,
width: 0.6,
layer: "top",
},
]

expect(route).toMatchInlineSnapshot(`
[
{
"layer": "top",
"route_type": "wire",
"width": 0.6,
"x": -3.9823015744754504,
"y": 18.50630157447545,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.6,
"x": -3.9823015744754504,
"y": 18.50630157447545,
},
]
`)
})

test("serializes terminal vias from single-layer connection points", () => {
const input: HighDensityIntraNodeRoute = {
connectionName: "terminal-via-route",
Expand Down
Loading