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 stroke width calculation #84

Merged
merged 4 commits into from
Oct 24, 2024
Merged
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
5 changes: 3 additions & 2 deletions lib/convert-easyeda-json-to-tscircuit-soup-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { findBoundsAndCenter, transformPCBElements } from "@tscircuit/soup-util"
import { compose, scale, translate } from "transformation-matrix"
import { computeCenterOffset } from "./compute-center-offset"
import { mm } from "@tscircuit/mm"
import {easyEdaUnitToMm} from "./utils/easyeda-unit-to-mm"

const mil2mm = (mil: number | string) => {
if (typeof mil === "number") return mm(`${mil}mil`)
Expand Down Expand Up @@ -58,7 +59,7 @@ const handleSilkscreenPath = (
x: milx10(point.x),
y: milx10(point.y),
})),
stroke_width: track.width,
stroke_width: easyEdaUnitToMm(track.width),
})
}

Expand All @@ -82,7 +83,7 @@ const handleSilkscreenArc = (arc: z.infer<typeof ArcSchema>, index: number) => {
x: milx10(p.x),
y: milx10(p.y),
})),
stroke_width: mm(arc.width),
stroke_width: easyEdaUnitToMm(arc.width),
} as Soup.PcbSilkscreenPathInput)
}

Expand Down
4 changes: 3 additions & 1 deletion lib/schemas/single-letter-shape-schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { z } from "zod"
import { mm } from "@tscircuit/mm"
import { easyEdaUnitToMm } from "lib/utils/easyeda-unit-to-mm"

/**
I'll break down the elements in the `dataStr.head.shape` array and explain what they represent. This array contains instructions for drawing the schematic symbol of the component.
Expand Down Expand Up @@ -272,7 +274,7 @@ const parsePath = (str: string): z.infer<typeof PathShapeOutputSchema> => {
type: "PATH",
pathData,
fillColor,
strokeWidth: Number(strokeWidth),
strokeWidth: easyEdaUnitToMm(Number(strokeWidth)),
strokeColor,
id,
}
Expand Down
9 changes: 9 additions & 0 deletions lib/utils/easyeda-unit-to-mm.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this is correct, should this be used to convert every value defined on a circuit json element in convertEasyEdaJsonToCircuitJson instead of @tscircuit/mm?

Copy link
Contributor

Choose a reason for hiding this comment

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

Its not the only unit used, i already wrote a function called something like mil10tomm, we should just call it mil10. Unfortunately easyeda uses many units

Copy link
Contributor

Choose a reason for hiding this comment

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

We can use the function you wrote here but we should rename it just to be super clear

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* EasyEDA takes 10 mil as a basic factor, when a stroke width is 1, we can take it as 1*10mil = 10mil, is 2, we can take it as 2*10mil = 20mil,
* Ref: https://docs.easyeda.com/en/DocumentFormat/3-EasyEDA-PCB-File-Format/
*
* 1 mil = 0.001 inch
* 1 inch = 25.4 mm
* 1 mil = 25.4/1000 = 0.0254 mm
*/
export const easyEdaUnitToMm = (value: number): number => value * 10 * 0.0254;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/convert-to-soup-tests/__snapshots__/c57759.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/convert-to-ts/C2998002-to-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ it("should convert C2998002 into typescript file", async () => {
test("C57759 should generate Circuit Json without errors", () => {
const betterEasy = EasyEdaJsonSchema.parse(c2998002)
const circuitJson = convertEasyEdaJsonToCircuitJson(betterEasy)
console.log("🚀 ~ circuitJson:", circuitJson)

expect(convertCircuitJsonToPcbSvg(circuitJson)).toMatchSvgSnapshot(
import.meta.path,
Expand Down
2 changes: 1 addition & 1 deletion tests/convert-to-ts/__snapshots__/C2998002-to-ts.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading