@tscircuit/footprinter 0.0.13 → 0.0.15

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.13",
4
+ "version": "0.0.15",
5
5
  "description": "",
6
6
  "main": "dist/index.cjs",
7
7
  "scripts": {
package/src/fn/quad.ts CHANGED
@@ -3,17 +3,8 @@ import { z } from "zod"
3
3
  import { length } from "@tscircuit/soup"
4
4
  import type { NowDefined } from "../helpers/zod/now-defined"
5
5
  import { rectpad } from "../helpers/rectpad"
6
-
7
- const pin_order_specifier = z.enum([
8
- "leftside",
9
- "topside",
10
- "rightside",
11
- "bottomside",
12
- "toppin",
13
- "bottompin",
14
- "leftpin",
15
- "rightpin",
16
- ])
6
+ import { pin_order_specifier } from "src/helpers/zod/pin-order-specifier"
7
+ import { getQuadPinMap } from "src/helpers/get-quad-pin-map"
17
8
 
18
9
  const base_quad_def = z.object({
19
10
  quad: z.literal(true),
@@ -106,6 +97,7 @@ export const quad = (raw_params: {
106
97
  }): AnySoupElement[] => {
107
98
  const params = quad_def.parse(raw_params)
108
99
  const pads: AnySoupElement[] = []
100
+ const pin_map = getQuadPinMap(params)
109
101
  for (let i = 0; i < params.num_pins; i++) {
110
102
  const {
111
103
  x,
@@ -125,7 +117,8 @@ export const quad = (raw_params: {
125
117
  ;[pw, pl] = [pl, pw]
126
118
  }
127
119
 
128
- pads.push(rectpad(i + 1, x, y, pw, pl))
120
+ const pn = getQuadPinMap(params)[i + 1]
121
+ pads.push(rectpad(pn!, x, y, pw, pl))
129
122
  }
130
123
  return pads
131
124
  }
@@ -0,0 +1,106 @@
1
+ import type { PinOrderSpecifier } from "./zod/pin-order-specifier"
2
+
3
+ /**
4
+ * A counter-clockwise pin map is [1,2,3,4,5,6,7,8] for an 8-pin package
5
+ *
6
+ * 8 7
7
+ * 1 6
8
+ * 2 5
9
+ * 3 4
10
+ *
11
+ * Given some parameters, we're returning how to map the pins in a quad package
12
+ * with a different order. For example, if we pass in cw=true, we'll get the
13
+ * following mapping
14
+ *
15
+ * 1 -> 1
16
+ * 2 -> 8
17
+ * 3 -> 7
18
+ * 4 -> 6
19
+ * 5 -> 5
20
+ * 6 -> 4
21
+ * 7 -> 3
22
+ * 8 -> 2
23
+ *
24
+ * Which allows us to create the CW version of the package using...
25
+ * new_pin = pin_map[old_pin]
26
+ *
27
+ * 2 3
28
+ * 1 4
29
+ * 8 5
30
+ * 7 6
31
+ */
32
+ export const getQuadPinMap = ({
33
+ num_pins,
34
+ cw,
35
+ ccw,
36
+ startingpin,
37
+ }: {
38
+ num_pins: number
39
+ cw?: boolean
40
+ ccw?: boolean
41
+ startingpin?: PinOrderSpecifier[]
42
+ }): number[] => {
43
+ const pin_map: number[] = []
44
+ const pins_per_side = num_pins / 4
45
+ let current_position_ccw_normal = 1
46
+
47
+ /** Starting Flag Pins */
48
+ const sfp: Record<PinOrderSpecifier, boolean> = {} as any
49
+ for (const specifier of startingpin ?? []) {
50
+ sfp[specifier] = true
51
+ }
52
+ if (!sfp.leftside && !sfp.topside && !sfp.rightside && !sfp.bottomside) {
53
+ sfp.leftside = true
54
+ }
55
+ if (!sfp.bottompin && !sfp.leftpin && !sfp.rightpin && !sfp.toppin) {
56
+ if (sfp.leftside) {
57
+ sfp.toppin = true
58
+ } else if (sfp.topside) {
59
+ sfp.rightpin = true
60
+ } else if (sfp.rightside) {
61
+ sfp.bottompin = true
62
+ } else if (sfp.bottomside) {
63
+ sfp.leftpin = true
64
+ }
65
+ }
66
+
67
+ if (sfp.leftside && sfp.toppin) {
68
+ current_position_ccw_normal = 1
69
+ } else if (sfp.leftside && sfp.bottompin) {
70
+ current_position_ccw_normal = pins_per_side
71
+ } else if (sfp.bottomside && sfp.leftpin) {
72
+ current_position_ccw_normal = pins_per_side + 1
73
+ } else if (sfp.bottomside && sfp.rightpin) {
74
+ current_position_ccw_normal = pins_per_side * 2
75
+ } else if (sfp.rightside && sfp.bottompin) {
76
+ current_position_ccw_normal = pins_per_side * 2 + 1
77
+ } else if (sfp.rightside && sfp.toppin) {
78
+ current_position_ccw_normal = pins_per_side * 3
79
+ } else if (sfp.topside && sfp.rightpin) {
80
+ current_position_ccw_normal = pins_per_side * 3 + 1
81
+ } else if (sfp.topside && sfp.leftpin) {
82
+ current_position_ccw_normal = pins_per_side * 4
83
+ }
84
+
85
+ pin_map.push(-1) // the first index is meaningless
86
+
87
+ // Each iteration we move the current position to the next pin, if we're
88
+ // going CCW this means incrementing, if we're going CW this means
89
+ // decrementing
90
+ for (let i = 0; i < num_pins; i++) {
91
+ pin_map.push(current_position_ccw_normal)
92
+ if (ccw) {
93
+ current_position_ccw_normal++
94
+ if (current_position_ccw_normal > num_pins) {
95
+ current_position_ccw_normal = 1
96
+ }
97
+ } else {
98
+ current_position_ccw_normal--
99
+ if (current_position_ccw_normal < 1) {
100
+ current_position_ccw_normal = num_pins
101
+ }
102
+ }
103
+ }
104
+
105
+ return pin_map
106
+ }
@@ -0,0 +1,13 @@
1
+ import { z } from "zod"
2
+ export const pin_order_specifier = z.enum([
3
+ "leftside",
4
+ "topside",
5
+ "rightside",
6
+ "bottomside",
7
+ "toppin",
8
+ "bottompin",
9
+ "leftpin",
10
+ "rightpin",
11
+ ])
12
+
13
+ export type PinOrderSpecifier = z.infer<typeof pin_order_specifier>