Skip to content

Commit

Permalink
Fix stroke width calculation (#84)
Browse files Browse the repository at this point in the history
* Fix stroke width calculation

* Update easyeda ref link, format

* REmove console log

* Rename easyEdaUnitToMm to mil10ToMm
  • Loading branch information
andrii-balitskyi authored Oct 24, 2024
1 parent 5e792c2 commit 539ba2d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
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 { mil10ToMm } 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: mil10ToMm(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: mil10ToMm(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 { mil10ToMm } 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: mil10ToMm(Number(strokeWidth)),
strokeColor,
id,
}
Expand Down
9 changes: 9 additions & 0 deletions lib/utils/easyeda-unit-to-mm.ts
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/#unit
*
* 1 mil = 0.001 inch
* 1 inch = 25.4 mm
* 1 mil = 25.4/1000 = 0.0254 mm
*/
export const mil10ToMm = (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.
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.

0 comments on commit 539ba2d

Please sign in to comment.