-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenums.go
More file actions
234 lines (215 loc) · 4.67 KB
/
Copy pathenums.go
File metadata and controls
234 lines (215 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package resistor
import (
"fmt"
"strings"
)
///////////////////////////////////////////////////////////////////////////////
// ESeries
///////////////////////////////////////////////////////////////////////////////
// String returns the canonical string representation of an E-series.
func (e ESeries) String() string {
switch e {
case E3:
return "E3"
case E6:
return "E6"
case E12:
return "E12"
case E24:
return "E24"
case E48:
return "E48"
case E96:
return "E96"
case E192:
return "E192"
default:
return "Unknown"
}
}
// ParseESeries converts a string into an ESeries value.
func ParseESeries(input string) (ESeries, error) {
switch strings.ToUpper(strings.TrimSpace(input)) {
case "E3":
return E3, nil
case "E6":
return E6, nil
case "E12":
return E12, nil
case "E24":
return E24, nil
case "E48":
return E48, nil
case "E96":
return E96, nil
case "E192":
return E192, nil
default:
return 0, fmt.Errorf("invalid E-series: %s", input)
}
}
// AllESeries returns the supported E-series values.
func AllESeries() []ESeries {
return []ESeries{E3, E6, E12, E24, E48, E96, E192}
}
///////////////////////////////////////////////////////////////////////////////
// RoundingMode
///////////////////////////////////////////////////////////////////////////////
// String returns the canonical string representation of a rounding mode.
func (r RoundingMode) String() string {
switch r {
case RoundNearest:
return "Nearest"
case RoundUp:
return "Up"
case RoundDown:
return "Down"
default:
return "Unknown"
}
}
// ParseRoundingMode converts a string into a RoundingMode.
func ParseRoundingMode(input string) (RoundingMode, error) {
switch strings.ToLower(strings.TrimSpace(input)) {
case "", "nearest":
return RoundNearest, nil
case "up":
return RoundUp, nil
case "down":
return RoundDown, nil
default:
return 0, fmt.Errorf("invalid rounding mode: %s", input)
}
}
// AllRoundingModes returns all supported rounding modes.
func AllRoundingModes() []RoundingMode {
return []RoundingMode{RoundNearest, RoundUp, RoundDown}
}
///////////////////////////////////////////////////////////////////////////////
// PackageType
///////////////////////////////////////////////////////////////////////////////
// String returns the canonical string representation of a package type.
func (p PackageType) String() string {
switch p {
case ThroughHole:
return "through_hole"
case SMD:
return "smd"
case SMD0402:
return "0402"
case SMD0603:
return "0603"
case SMD0805:
return "0805"
case SMD1206:
return "1206"
case Axial:
return "axial"
case Radial:
return "radial"
default:
return "unknown"
}
}
// ParsePackageType converts a string into a PackageType.
func ParsePackageType(input string) (PackageType, error) {
switch strings.ToLower(strings.TrimSpace(input)) {
case "":
return "", nil
case "through_hole":
return ThroughHole, nil
case "smd":
return SMD, nil
case "0402":
return SMD0402, nil
case "0603":
return SMD0603, nil
case "0805":
return SMD0805, nil
case "1206":
return SMD1206, nil
case "axial":
return Axial, nil
case "radial":
return Radial, nil
default:
return "", fmt.Errorf("invalid package type: %s", input)
}
}
// AllPackageTypes returns the commonly selectable package types.
// UnknownPKG is excluded; it is used internally when a type cannot be determined.
func AllPackageTypes() []PackageType {
return []PackageType{
ThroughHole,
SMD0402,
SMD0603,
SMD0805,
SMD1206,
Axial,
Radial,
}
}
///////////////////////////////////////////////////////////////////////////////
// Color Enumerations
///////////////////////////////////////////////////////////////////////////////
// The following functions expose canonical color lists for UI layers.
// These are intentionally ordered for deterministic presentation.
// UI layers (CLI, TUI, WASM) should rely on these functions rather
// than hardcoding color lists.
// DigitColors returns colors valid for significant digit bands (0–9).
func DigitColors() []Color {
return []Color{
Black,
Brown,
Red,
Orange,
Yellow,
Green,
Blue,
Violet,
Grey,
White,
}
}
// MultiplierColors returns valid multiplier band colors.
func MultiplierColors() []Color {
return []Color{
Black,
Brown,
Red,
Orange,
Yellow,
Green,
Blue,
Violet,
Grey,
White,
Gold,
Silver,
}
}
// ToleranceColors returns valid tolerance band colors.
func ToleranceColors() []Color {
return []Color{
Brown,
Red,
Green,
Blue,
Violet,
Grey,
Gold,
Silver,
None,
}
}
// TempCoeffColors returns valid 6th band temperature coefficient colors.
func TempCoeffColors() []Color {
return []Color{
Brown,
Red,
Orange,
Yellow,
Blue,
Violet,
}
}