Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mm conversion in generateFootprintTsx function #13

Merged
merged 2 commits into from
Jul 9, 2024
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
15 changes: 8 additions & 7 deletions lib/generate-footprint-tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { z } from "zod"
import type { EasyEdaJson } from "./schemas/easy-eda-json-schema"
import { PadSchema } from "./schemas/package-detail-shape-schema"
import { computeCenterOffset } from "./compute-center-offset"
import { mm } from "@tscircuit/mm"

export const generateFootprintTsx = (easyEdaJson: EasyEdaJson): string => {
const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
Expand All @@ -14,28 +15,28 @@ export const generateFootprintTsx = (easyEdaJson: EasyEdaJson): string => {

const footprintElements = pads.map((pad) => {
const { center, width, height, holeRadius, number } = pad
const isPlatedHole = holeRadius !== undefined && holeRadius > 0
const isPlatedHole = holeRadius !== undefined && mm(holeRadius) > 0

// Normalize the position by subtracting the center point
const normalizedX = center.x - centerX
const normalizedY = center.y - centerY
const normalizedX = mm(center.x) - centerX
const normalizedY = mm(center.y) - centerY

if (isPlatedHole) {
return `
<platedhole
pcbX="${normalizedX.toFixed(2)}mm"
pcbY="${normalizedY.toFixed(2)}mm"
hole_diameter="${holeRadius * 2}mm"
outer_diameter="${width}mm"
hole_diameter="${mm(holeRadius) * 2}mm"
outer_diameter="${mm(width)}mm"
portHints={["${number}"]}
/>`.replace(/\n/, "")
} else {
return `
<smtpad
pcbX="${normalizedX.toFixed(2)}mm"
pcbY="${normalizedY.toFixed(2)}mm"
width="${width}mm"
height="${height}mm"
width="${mm(width)}mm"
height="${mm(height)}mm"
shape="rect"
portHints={["${number}"]}
/>`.replace(/\n/, "")
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"name": "easyeda",
"type": "module",
"version": "0.0.9",
"files": [
"dist"
],
"files": ["dist"],
"repository": {
"type": "git",
"url": "https://github.com/tscircuit/easyeda-converter"
Expand Down
4 changes: 4 additions & 0 deletions tests/convert-to-ts/C88224-to-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ it("should convert c88224 into typescript file", async () => {
easyeda,
soup,
})

console.log(result)

expect(result).not.toContain("milmm")
expect(result).not.toContain("NaNmm")
})
Loading