Skip to content

Commit

Permalink
check for crazy dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Oct 13, 2024
1 parent 4e8c9f4 commit 94bd7cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/convert-easyeda-json-to-tscircuit-soup-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ export const convertEasyEdaJsonToCircuitJson = (
}
})

// easyeda uses a flipped Y axis ( tscircuit = y+ is up, easyeda = y- is up )
transformPCBElements(soupElements, scale(1, -1))

// TODO Change pcb_component width & height

// TODO compute pcb center based on all elements and transform elements such
Expand Down Expand Up @@ -262,8 +259,9 @@ export const convertEasyEdaJsonToCircuitJson = (
)
transformPCBElements(
soupElements,
compose(translate(-bounds.center.x, bounds.center.y)),
compose(translate(-bounds.center.x, bounds.center.y), scale(1, -1)),
)
pcb_component.center = { x: 0, y: 0 }
}

return soupElements
Expand Down
18 changes: 18 additions & 0 deletions tests/convert-to-soup-tests/c5184526.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,22 @@ test("C5184526 should have two holes", () => {
expect(convertCircuitJsonToPcbSvg(circuitJson)).toMatchSvgSnapshot(
import.meta.path,
)

const coords = circuitJson
.map((e: any) => ({
type: e.type,
x: e.x ?? e.center?.x,
y: e.y ?? e.center?.y,
}))
.filter((e) => e.x !== undefined && e.y !== undefined)

const maxX = Math.max(...coords.map((e) => e.x))
const minX = Math.min(...coords.map((e) => e.x))
const maxY = Math.max(...coords.map((e) => e.y))
const minY = Math.min(...coords.map((e) => e.y))

expect(maxX).toBeLessThan(10)
expect(minX).toBeGreaterThan(-10)
expect(maxY).toBeLessThan(10)
expect(minY).toBeGreaterThan(-10)
})

0 comments on commit 94bd7cc

Please sign in to comment.