@tscircuit/footprinter 0.0.18 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/footprinter",
3
3
  "type": "module",
4
- "version": "0.0.18",
4
+ "version": "0.0.20",
5
5
  "description": "",
6
6
  "main": "dist/index.cjs",
7
7
  "scripts": {
package/src/fn/quad.ts CHANGED
@@ -11,7 +11,12 @@ const base_quad_def = z.object({
11
11
  quad: z.literal(true),
12
12
  cc: z.literal(true).optional(),
13
13
  ccw: z.literal(true).optional(),
14
- startingpin: z.array(pin_order_specifier).optional(),
14
+ startingpin: z
15
+ .string()
16
+ .or(z.array(pin_order_specifier))
17
+ .transform((a) => (typeof a === "string" ? a.slice(1, -1).split(",") : a))
18
+ .pipe(z.array(pin_order_specifier))
19
+ .optional(),
15
20
  num_pins: z.number(),
16
21
  w: length.optional(),
17
22
  h: length.optional(),
@@ -92,6 +97,8 @@ export const quad = (
92
97
  const params = quad_def.parse(raw_params)
93
98
  const pads: AnySoupElement[] = []
94
99
  const pin_map = getQuadPinMap(params)
100
+ /** Side pin count */
101
+ const spc = params.num_pins / 4
95
102
  for (let i = 0; i < params.num_pins; i++) {
96
103
  const {
97
104
  x,
@@ -131,31 +138,119 @@ export const quad = (
131
138
 
132
139
  // Silkscreen corners
133
140
  const silkscreen_corners: PcbSilkscreenPath[] = []
134
- for (let corner_index = 0; corner_index < 4; corner_index++) {
135
- const dx = Math.floor(corner_index / 2) * 2 - 1
136
- const dy = (corner_index % 2) * 2 - 1
137
- const corner_x = (params.w / 2) * dx
138
- const corner_y = (params.h / 2) * dy
139
- silkscreen_corners.push({
140
- layer: "top",
141
- pcb_component_id: "",
142
- pcb_silkscreen_path_id: `pcb_silkscreen_path_${corner_index}`,
143
- route: [
141
+ for (const [corner, dx, dy] of [
142
+ ["top-left", -1, 1],
143
+ ["bottom-left", -1, -1],
144
+ ["bottom-right", 1, -1],
145
+ ["top-right", 1, 1],
146
+ ] as const) {
147
+ // const dx = Math.floor(corner_index / 2) * 2 - 1
148
+ // const dy = 1 - (corner_index % 2) * 2
149
+ const corner_x = (params.w / 2 - params.pl / 2) * dx
150
+ const corner_y = (params.h / 2 - params.pl / 2) * dy
151
+ let arrow: "none" | "in1" | "in2" = "none"
152
+ /** corner size */
153
+ const csz = params.pw * 2
154
+
155
+ if (pin_map[1] === 1 && corner === "top-left") {
156
+ arrow = "in1"
157
+ } else if (pin_map[spc * 4] === 1 && corner === "top-left") {
158
+ arrow = "in2"
159
+ } else if (pin_map[spc * 3 + 1] === 1 && corner === "top-right") {
160
+ arrow = "in2"
161
+ } else if (pin_map[spc * 3] === 1 && corner === "top-right") {
162
+ arrow = "in1"
163
+ } else if (pin_map[spc] === 1 && corner === "bottom-left") {
164
+ arrow = "in1"
165
+ } else if (pin_map[spc + 1] === 1 && corner === "bottom-left") {
166
+ arrow = "in2"
167
+ } else if (pin_map[spc * 2] === 1 && corner === "bottom-right") {
168
+ arrow = "in1"
169
+ } else if (pin_map[spc * 2 + 1] === 1 && corner === "bottom-right") {
170
+ arrow = "in2"
171
+ }
172
+ if (arrow === "none") {
173
+ silkscreen_corners.push({
174
+ layer: "top",
175
+ pcb_component_id: "",
176
+ pcb_silkscreen_path_id: `pcb_silkscreen_path_${corner}`,
177
+ route: [
178
+ {
179
+ x: corner_x - csz * dx,
180
+ y: corner_y,
181
+ },
182
+ {
183
+ x: corner_x,
184
+ y: corner_y,
185
+ },
186
+ {
187
+ x: corner_x,
188
+ y: corner_y - csz * dy,
189
+ },
190
+ ],
191
+ type: "pcb_silkscreen_path",
192
+ })
193
+ } else {
194
+ const rotate_arrow = arrow === "in1" ? 1 : -1
195
+ silkscreen_corners.push(
144
196
  {
145
- x: corner_x - params.pw * dx,
146
- y: corner_y,
197
+ layer: "top",
198
+ pcb_component_id: "",
199
+ pcb_silkscreen_path_id: `pcb_silkscreen_path_${corner}_1`,
200
+ route: [
201
+ {
202
+ x: corner_x - csz * dx,
203
+ y: corner_y,
204
+ },
205
+ {
206
+ x: corner_x - (csz * dx) / 2,
207
+ y: corner_y,
208
+ },
209
+ ],
210
+ type: "pcb_silkscreen_path",
147
211
  },
148
212
  {
149
- x: corner_x,
150
- y: corner_y,
213
+ layer: "top",
214
+ pcb_component_id: "",
215
+ pcb_silkscreen_path_id: `pcb_silkscreen_path_${corner}_2`,
216
+ route: [
217
+ {
218
+ x: corner_x,
219
+ y: corner_y - (csz * dy) / 2,
220
+ },
221
+ {
222
+ x: corner_x,
223
+ y: corner_y - csz * dy,
224
+ },
225
+ ],
226
+ type: "pcb_silkscreen_path",
151
227
  },
152
228
  {
153
- x: corner_x,
154
- y: corner_y - params.pw * dy,
155
- },
156
- ],
157
- type: "pcb_silkscreen_path",
158
- })
229
+ layer: "top",
230
+ pcb_component_id: "",
231
+ pcb_silkscreen_path_id: `pcb_silkscreen_path_${corner}_3`,
232
+ route: [
233
+ {
234
+ x: corner_x - 0.2 * -dx,
235
+ y: corner_y + 0.2 * rotate_arrow,
236
+ },
237
+ {
238
+ x: corner_x,
239
+ y: corner_y,
240
+ },
241
+ {
242
+ x: corner_x + 0.2 * rotate_arrow * -dx,
243
+ y: corner_y + 0.2,
244
+ },
245
+ {
246
+ x: corner_x - 0.2 * -dx,
247
+ y: corner_y + 0.2 * rotate_arrow,
248
+ },
249
+ ],
250
+ type: "pcb_silkscreen_path",
251
+ }
252
+ )
253
+ }
159
254
  }
160
255
 
161
256
  return [...pads, ...silkscreen_corners]
@@ -22,7 +22,7 @@ import type { PinOrderSpecifier } from "./zod/pin-order-specifier"
22
22
  * 8 -> 2
23
23
  *
24
24
  * Which allows us to create the CW version of the package using...
25
- * new_pin = pin_map[old_pin]
25
+ * new_pin = pin_map[normal_ccw_pin]
26
26
  *
27
27
  * 2 3
28
28
  * 1 4
@@ -88,7 +88,7 @@ export const getQuadPinMap = ({
88
88
  // going CCW this means incrementing, if we're going CW this means
89
89
  // decrementing
90
90
  for (let i = 0; i < num_pins; i++) {
91
- pin_map.push(current_position_ccw_normal)
91
+ pin_map[current_position_ccw_normal] = i + 1
92
92
  if (ccw || !cw) {
93
93
  current_position_ccw_normal++
94
94
  if (current_position_ccw_normal > num_pins) {
@@ -11,35 +11,14 @@ test("quad16_w4_l4_p0.4_pw0.25_pl0.4", async (t) => {
11
11
  t.pass()
12
12
  })
13
13
 
14
- test("quad16_w4_l4_p0.4_pw0.25_pl0.4_thermalpad", async (t) => {
14
+ test("quad16_w4_l4_p0.4_pw0.25_pl0.4_thermalpad_startingpin(bottomside,leftpin)", async (t) => {
15
15
  const { fp, logSoup } = await getTestFixture(t)
16
- const soup = fp.string("quad16_w4_l4_p0.4_pw0.25_pl0.4_thermalpad").soup()
16
+ const soup = fp
17
+ .string(
18
+ "quad16_w4_l4_p0.4_pw0.25_pl0.4_thermalpad_startingpin(bottomside,leftpin)"
19
+ )
20
+ .soup()
17
21
 
18
22
  await logSoup(soup)
19
23
  t.pass()
20
24
  })
21
-
22
- // const ps = toPinPositionString(soup)
23
-
24
- // t.is(
25
- // ps,
26
- // `
27
- // 1 : -1.75 -2.00
28
- // 2 : -1.25 -2.00
29
- // 3 : -0.75 -2.00
30
- // 4 : -0.25 -2.00
31
- // 5 : 0.25 -2.00
32
- // 6 : 0.75 -2.00
33
- // 7 : 1.25 -2.00
34
- // 8 : 1.75 -2.00
35
- // 9 : 2.00 -1.75
36
- // 10: 2.00 -1.25
37
- // 11: 2.00 -0.75
38
- // 12: 2.00 -0.25
39
- // 13: 2.00 0.25
40
- // 14: 2.00 0.75
41
- // 15: 2.00 1.25
42
- // 16: 2.00 1.75
43
- // `.trim()
44
- // )
45
- // })