Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Nov 18, 2024
1 parent 1de0917 commit 0e63047
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
27 changes: 0 additions & 27 deletions lib/dsn-pcb/circuit-json-to-dsn-json/stringify-dsn-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,3 @@ export const stringifyDsnJson = (dsnJson: DsnPcb): string => {

return result
}

function convertSessionToPcb(session: DsnSession): DsnPcb {
const pcb: DsnPcb = {
filename: session.filename,
parser: session.routes.parser,
resolution: session.routes.resolution,
unit: "um",
structure: {
layers: [],
boundary: { path: { layer: "", width: 0, coordinates: [] } },
via: "",
rule: { width: 0, clearances: [] }
},
placement: { components: session.placement.components },
library: { images: [], padstacks: [] },
network: { nets: [], classes: [] },
wiring: {
wires: session.routes.network_out.nets.flatMap(net =>
net.wires.map(wire => ({
...wire,
net: net.name
}))
)
}
}
return pcb
}
6 changes: 3 additions & 3 deletions lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,21 @@ function processPath(nodes: ASTNode[]): Path {
typeof nodes[startIndex + 1].value === "number"
) {
path.layer = nodes[startIndex].value
path.width = nodes[startIndex + 1].value
path.width = nodes[startIndex + 1].value as number

// Process coordinates after layer and width
for (let i = startIndex + 2; i < nodes.length; i++) {
const coordNode = nodes[i]
if (coordNode?.type === "Atom" && typeof coordNode.value === "number") {
path.coordinates.push(coordNode.value)
path.coordinates!.push(coordNode.value)
}
}
} else {
// Process all valid number nodes as coordinates
for (let i = startIndex; i < nodes.length; i++) {
const node = nodes[i]
if (node?.type === "Atom" && typeof node.value === "number") {
path.coordinates.push(node.value)
path.coordinates!.push(node.value)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/dsn-pcb/stringify-dsn-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import testDsnFile from "../assets/testkicadproject/testkicadproject.dsn" with {
import { expect, test } from "bun:test"

test("stringify dsn json", () => {
const dsnJson = parseDsnToDsnJson(testDsnFile)
const dsnJson = parseDsnToDsnJson(testDsnFile) as DsnPcb
const dsnString = stringifyDsnJson(dsnJson)
const reparsedJson = parseDsnToDsnJson(dsnString)
const reparsedJson = parseDsnToDsnJson(dsnString) as DsnPcb

for (const key of Object.keys(reparsedJson) as Array<keyof DsnPcb>) {
expect(reparsedJson[key]).toEqual(dsnJson[key])
expect(reparsedJson[key]).toEqual(dsnJson[key] as any)
}

// Test that we can parse the generated string back to the same structure
Expand Down

0 comments on commit 0e63047

Please sign in to comment.