Skip to content

Commit 4a9ea0e

Browse files
refactor
1 parent c9413ba commit 4a9ea0e

30 files changed

Lines changed: 82 additions & 91 deletions

bun.lockb

386 Bytes
Binary file not shown.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
"@types/bun": "^1.2.2",
2525
"@types/node": "^20.12.13",
2626
"bun-match-svg": "^0.0.10",
27-
"circuit-json": "^0.0.148",
27+
"circuit-json": "^0.0.190",
2828
"circuit-json-to-connectivity-map": "^0.0.18",
29-
"circuit-to-svg": "^0.0.129",
29+
"circuit-to-svg": "^0.0.131",
3030
"esbuild": "^0.21.4",
3131
"esbuild-register": "^3.5.0",
3232
"react": "^19.0.0",

src/fn/pinrow.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,34 @@ export const pinrow_def = z
2121
od: length.default("1.5mm").describe("outer diameter"),
2222
male: z.boolean().optional().describe("for male pin headers"),
2323
female: z.boolean().optional().describe("for female pin headers"),
24-
pinlabelpositionup: z.boolean().optional().default(false),
25-
pinlabelpositiondown: z.boolean().optional().default(false),
26-
pinlabelpositionleft: z.boolean().optional().default(false),
27-
pinlabelpositionright: z.boolean().optional().default(false),
24+
pinlabeltop: z.boolean().optional().default(false),
25+
pinlabelbottom: z.boolean().optional().default(false),
26+
pinlabelleft: z.boolean().optional().default(false),
27+
pinlabelright: z.boolean().optional().default(false),
2828
pinlabelparallel: z.boolean().optional().default(false),
29-
pinlabelinverted: z.boolean().optional().default(false),
29+
pinlabelorthogonal: z.boolean().optional().default(false),
3030
nosquareplating: z
3131
.boolean()
3232
.optional()
3333
.default(false)
3434
.describe("do not use rectangular pad for pin 1"),
3535
})
3636
.transform((data) => {
37-
let resolvedPinLabelPosition: "up" | "down" | "left" | "right"
38-
const {
39-
pinlabelpositionup,
40-
pinlabelpositiondown,
41-
pinlabelpositionleft,
42-
pinlabelpositionright,
43-
} = data
37+
let resolvedPinLabelPosition: "top" | "bottom" | "left" | "right"
38+
const { pinlabeltop, pinlabelbottom, pinlabelleft, pinlabelright } = data
4439

45-
const truePositionFlags: ("up" | "down" | "left" | "right")[] = []
46-
if (pinlabelpositionup) truePositionFlags.push("up")
47-
if (pinlabelpositiondown) truePositionFlags.push("down")
48-
if (pinlabelpositionleft) truePositionFlags.push("left")
49-
if (pinlabelpositionright) truePositionFlags.push("right")
40+
const truePositionFlags: ("top" | "bottom" | "left" | "right")[] = []
41+
if (pinlabeltop) truePositionFlags.push("top")
42+
if (pinlabelbottom) truePositionFlags.push("bottom")
43+
if (pinlabelleft) truePositionFlags.push("left")
44+
if (pinlabelright) truePositionFlags.push("right")
5045

51-
if (truePositionFlags.includes("up")) {
52-
resolvedPinLabelPosition = "up"
46+
if (truePositionFlags.includes("top")) {
47+
resolvedPinLabelPosition = "top"
5348
} else if (truePositionFlags.length === 1) {
5449
resolvedPinLabelPosition = truePositionFlags[0]!
5550
} else {
56-
resolvedPinLabelPosition = "up"
51+
resolvedPinLabelPosition = "top"
5752
}
5853

5954
return {
@@ -86,7 +81,7 @@ export const pinrow = (
8681
num_pins,
8782
resolvedPinLabelPosition,
8883
pinlabelparallel,
89-
pinlabelinverted,
84+
pinlabelorthogonal,
9085
} = parameters
9186

9287
const holes: AnySoupElement[] = []
@@ -97,7 +92,7 @@ export const pinrow = (
9792
xoff: number,
9893
yoff: number,
9994
od: number,
100-
resolvedPinLabelPosition: "up" | "down" | "left" | "right",
95+
resolvedPinLabelPosition: "top" | "bottom" | "left" | "right",
10196
): { anchor_x: number; anchor_y: number } => {
10297
let dx = 0,
10398
dy = 0
@@ -107,11 +102,11 @@ export const pinrow = (
107102
dx = offset
108103
dy = 0
109104
break
110-
case "up":
105+
case "top":
111106
dx = 0
112107
dy = offset
113108
break
114-
case "down":
109+
case "bottom":
115110
dx = 0
116111
dy = -offset
117112
break
@@ -149,7 +144,7 @@ export const pinrow = (
149144
anchor_y,
150145
pinlabelposition: resolvedPinLabelPosition,
151146
pinlabelparallel: pinlabelparallel,
152-
pinlabelinverted: pinlabelinverted,
147+
pinlabelorthogonal: pinlabelorthogonal,
153148
}),
154149
)
155150
}

src/footprinter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ export type Footprinter = {
7171
| "male"
7272
| "female"
7373
| "rows"
74-
| "pinlabelpositionup"
75-
| "pinlabelpositiondown"
76-
| "pinlabelpositionleft"
77-
| "pinlabelpositionright"
74+
| "pinlabeltop"
75+
| "pinlabelbottom"
76+
| "pinlabelleft"
77+
| "pinlabelright"
7878
| "pinlabelparallel"
79-
| "pinlabelinverted"
79+
| "pinlabelorthogonal"
8080
| "nosquareplating"
8181
>
8282
axial: () => FootprinterParamsBuilder<"p" | "id" | "od">

src/helpers/silkscreenPin.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import type { PcbSilkscreenText } from "circuit-json"
22

3-
type PinLabelPositionType = "up" | "down" | "left" | "right"
3+
type PinLabelPositionType = "top" | "bottom" | "left" | "right"
44
type RotationType = 0 | 90 | 180 | 270
55
type AnchorAlignmentType = PcbSilkscreenText["anchor_alignment"]
66

77
const fullyExplicitAlignmentMap: Record<
88
PinLabelPositionType,
99
Record<RotationType, AnchorAlignmentType>
1010
> = {
11-
up: { 0: "center", 90: "bottom_right", 180: "center", 270: "bottom_left" },
12-
down: { 0: "center", 90: "bottom_left", 180: "center", 270: "bottom_right" },
13-
left: { 0: "bottom_right", 90: "center", 180: "bottom_left", 270: "center" },
14-
right: { 0: "bottom_left", 90: "center", 180: "top_right", 270: "center" },
11+
top: { 0: "center", 90: "center_right", 180: "center", 270: "center_left" },
12+
bottom: {
13+
0: "center",
14+
90: "center_left",
15+
180: "center",
16+
270: "center_right",
17+
},
18+
left: { 0: "center_right", 90: "center", 180: "center_left", 270: "center" },
19+
right: { 0: "center_left", 90: "center", 180: "center_right", 270: "center" },
1520
}
1621

1722
// fs is font size // pn is pin number
@@ -20,26 +25,26 @@ export const silkscreenPin = ({
2025
pn,
2126
anchor_x,
2227
anchor_y,
23-
pinlabelposition = "up",
28+
pinlabelposition = "top",
2429
pinlabelparallel = false,
25-
pinlabelinverted = false,
30+
pinlabelorthogonal = false,
2631
}: {
2732
fs: number
2833
pn: number
2934
anchor_x: number
3035
anchor_y: number
3136
pinlabelposition?: PinLabelPositionType
3237
pinlabelparallel?: boolean
33-
pinlabelinverted?: boolean
38+
pinlabelorthogonal?: boolean
3439
}): PcbSilkscreenText => {
3540
let ccw_rotation: RotationType = 0
36-
if (!pinlabelparallel && !pinlabelinverted) {
41+
if (!pinlabelparallel && !pinlabelorthogonal) {
3742
ccw_rotation = 0
38-
} else if (pinlabelparallel && !pinlabelinverted) {
43+
} else if (pinlabelparallel && !pinlabelorthogonal) {
3944
ccw_rotation = 90
40-
} else if (!pinlabelparallel && pinlabelinverted) {
45+
} else if (!pinlabelparallel && pinlabelorthogonal) {
4146
ccw_rotation = 180
42-
} else if (pinlabelparallel && pinlabelinverted) {
47+
} else if (pinlabelparallel && pinlabelorthogonal) {
4348
ccw_rotation = 270
4449
}
4550

@@ -51,7 +56,6 @@ export const silkscreenPin = ({
5156
pcb_silkscreen_text_id: "silkscreen_text_1",
5257
font: "tscircuit2024",
5358
font_size: fs,
54-
stroke_width: fs / 100,
5559
pcb_component_id: "pcb_component_1",
5660
text: `{PIN${pn}}`,
5761
layer: "top",

tests/__snapshots__/pinrow5_labelpositionUp_labelrotation0.snap.svg renamed to tests/__snapshots__/pinrow5.snap.svg

File renamed without changes.

tests/__snapshots__/pinrow5_labelpositionDown_labelrotation270.snap.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/__snapshots__/pinrow5_labelpositionDown_labelrotation90.snap.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/__snapshots__/pinrow5_labelpositionLeft_labelrotation0.snap.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)