Skip to content

Commit

Permalink
improve hole props
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Sep 5, 2024
1 parent 4c0f12f commit f72d465
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
25 changes: 25 additions & 0 deletions lib/components/hole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { z } from "zod"
import { distance, type Distance } from "lib/common/distance"
import { pcbLayoutProps, type PcbLayoutProps } from "lib/common/layout"
import { expectTypesMatch } from "lib/typecheck"

export interface HoleProps extends Omit<PcbLayoutProps, "pcbRotation"> {
diameter?: Distance
radius?: Distance
}

export const holeProps = pcbLayoutProps
.omit({ pcbRotation: true })
.extend({
diameter: distance.optional(),
radius: distance.optional(),
})
.transform((d) => ({
...d,
diameter: d.diameter ?? 2 * d.radius!,
radius: d.radius ?? d.diameter! / 2,
}))

export type InferredHoleProps = z.input<typeof holeProps>

expectTypesMatch<HoleProps, InferredHoleProps>(true)
6 changes: 1 addition & 5 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export * from "./components/net"
export * from "./components/constrainedlayout"
export * from "./components/constraint"
export * from "./components/smtpad"
export * from "./components/hole"

export const inductorProps = commonComponentProps.extend({
inductance,
Expand Down Expand Up @@ -151,11 +152,6 @@ export const pcbKeepoutProps = z.union([
])
export type PcbKeepoutProps = z.input<typeof pcbKeepoutProps>

export const holeProps = pcbLayoutProps.omit({ pcbRotation: true }).extend({
holeDiameter: distance,
})
export type HoleProps = z.input<typeof holeProps>

export const schematicBoxProps = z.object({
schX: distance,
schY: distance,
Expand Down

0 comments on commit f72d465

Please sign in to comment.