smithkit 0.0.0-stage → 0.1.0

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.
Files changed (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +481 -2
  3. package/dist/lib/Smith.d.ts +103 -0
  4. package/dist/lib/Smith.js +551 -0
  5. package/dist/lib/SmithArcsDefs.d.ts +10 -0
  6. package/dist/lib/SmithArcsDefs.js +10 -0
  7. package/dist/lib/SmithConstantCircle.d.ts +62 -0
  8. package/dist/lib/SmithConstantCircle.js +222 -0
  9. package/dist/lib/arcs/Tick.d.ts +33 -0
  10. package/dist/lib/arcs/Tick.js +40 -0
  11. package/dist/lib/complex/Complex.d.ts +130 -0
  12. package/dist/lib/complex/Complex.js +636 -0
  13. package/dist/lib/components.d.ts +14 -0
  14. package/dist/lib/components.js +26 -0
  15. package/dist/lib/draw/ConstCircles.d.ts +61 -0
  16. package/dist/lib/draw/ConstCircles.js +151 -0
  17. package/dist/lib/draw/ConstConductance.d.ts +4 -0
  18. package/dist/lib/draw/ConstConductance.js +6 -0
  19. package/dist/lib/draw/ConstQCircles.d.ts +29 -0
  20. package/dist/lib/draw/ConstQCircles.js +86 -0
  21. package/dist/lib/draw/ConstReactance.d.ts +4 -0
  22. package/dist/lib/draw/ConstReactance.js +6 -0
  23. package/dist/lib/draw/ConstResistance.d.ts +4 -0
  24. package/dist/lib/draw/ConstResistance.js +6 -0
  25. package/dist/lib/draw/ConstSusceptance.d.ts +4 -0
  26. package/dist/lib/draw/ConstSusceptance.js +6 -0
  27. package/dist/lib/draw/ConstSwrCircles.d.ts +29 -0
  28. package/dist/lib/draw/ConstSwrCircles.js +85 -0
  29. package/dist/lib/draw/MouseGesture.d.ts +6 -0
  30. package/dist/lib/draw/MouseGesture.js +26 -0
  31. package/dist/lib/draw/SmithArc.d.ts +10 -0
  32. package/dist/lib/draw/SmithArc.js +26 -0
  33. package/dist/lib/draw/SmithCircle.d.ts +10 -0
  34. package/dist/lib/draw/SmithCircle.js +24 -0
  35. package/dist/lib/draw/SmithCursor.d.ts +49 -0
  36. package/dist/lib/draw/SmithCursor.js +186 -0
  37. package/dist/lib/draw/SmithData.d.ts +66 -0
  38. package/dist/lib/draw/SmithData.js +366 -0
  39. package/dist/lib/draw/SmithDrawOptions.d.ts +5 -0
  40. package/dist/lib/draw/SmithDrawOptions.js +1 -0
  41. package/dist/lib/draw/SmithGridLayer.d.ts +19 -0
  42. package/dist/lib/draw/SmithGridLayer.js +48 -0
  43. package/dist/lib/draw/SmithGroup.d.ts +11 -0
  44. package/dist/lib/draw/SmithGroup.js +31 -0
  45. package/dist/lib/draw/SmithLine.d.ts +11 -0
  46. package/dist/lib/draw/SmithLine.js +27 -0
  47. package/dist/lib/draw/SmithMarker.d.ts +25 -0
  48. package/dist/lib/draw/SmithMarker.js +122 -0
  49. package/dist/lib/draw/SmithPath.d.ts +8 -0
  50. package/dist/lib/draw/SmithPath.js +20 -0
  51. package/dist/lib/draw/SmithScaler.d.ts +19 -0
  52. package/dist/lib/draw/SmithScaler.js +48 -0
  53. package/dist/lib/draw/SmithShape.d.ts +15 -0
  54. package/dist/lib/draw/SmithShape.js +42 -0
  55. package/dist/lib/draw/SmithSvg.d.ts +9 -0
  56. package/dist/lib/draw/SmithSvg.js +27 -0
  57. package/dist/lib/draw/SmithText.d.ts +22 -0
  58. package/dist/lib/draw/SmithText.js +56 -0
  59. package/dist/lib/formatting.d.ts +7 -0
  60. package/dist/lib/formatting.js +16 -0
  61. package/dist/lib/grid/definitions.d.ts +3 -0
  62. package/dist/lib/grid/definitions.js +123 -0
  63. package/dist/lib/grid/geometry.d.ts +20 -0
  64. package/dist/lib/grid/geometry.js +55 -0
  65. package/dist/lib/grid/labels.d.ts +3 -0
  66. package/dist/lib/grid/labels.js +41 -0
  67. package/dist/lib/grid/types.d.ts +30 -0
  68. package/dist/lib/grid/types.js +6 -0
  69. package/dist/lib/index.d.ts +16 -0
  70. package/dist/lib/index.js +9 -0
  71. package/dist/lib/io/touchstone.d.ts +7 -0
  72. package/dist/lib/io/touchstone.js +72 -0
  73. package/dist/lib/layers.d.ts +48 -0
  74. package/dist/lib/layers.js +73 -0
  75. package/dist/lib/math/complexRatio.d.ts +3 -0
  76. package/dist/lib/math/complexRatio.js +30 -0
  77. package/dist/lib/measurements.d.ts +53 -0
  78. package/dist/lib/measurements.js +19 -0
  79. package/dist/lib/renormalization.d.ts +10 -0
  80. package/dist/lib/renormalization.js +62 -0
  81. package/dist/lib/rf.d.ts +35 -0
  82. package/dist/lib/rf.js +74 -0
  83. package/dist/lib/samples.d.ts +6 -0
  84. package/dist/lib/samples.js +1 -0
  85. package/dist/lib/scales/SmithPeripheralScales.d.ts +10 -0
  86. package/dist/lib/scales/SmithPeripheralScales.js +124 -0
  87. package/dist/lib/scales/SmithScales.d.ts +16 -0
  88. package/dist/lib/scales/SmithScales.js +134 -0
  89. package/dist/lib/scales/peripheralScales.d.ts +12 -0
  90. package/dist/lib/scales/peripheralScales.js +49 -0
  91. package/dist/lib/scales/radialScales.d.ts +12 -0
  92. package/dist/lib/scales/radialScales.js +109 -0
  93. package/dist/lib/shapes/Arc.d.ts +6 -0
  94. package/dist/lib/shapes/Arc.js +1 -0
  95. package/dist/lib/shapes/Circle.d.ts +5 -0
  96. package/dist/lib/shapes/Circle.js +1 -0
  97. package/dist/lib/shapes/Line.d.ts +5 -0
  98. package/dist/lib/shapes/Line.js +1 -0
  99. package/dist/lib/shapes/Point.d.ts +1 -0
  100. package/dist/lib/shapes/Point.js +1 -0
  101. package/package.json +76 -4
@@ -0,0 +1,222 @@
1
+ import { complexRatio } from './math/complexRatio.js';
2
+ import { Complex } from './complex/Complex.js';
3
+ export class SmithConstantCircle {
4
+ Z0;
5
+ constructor(Z0 = 50) {
6
+ this.Z0 = Z0;
7
+ }
8
+ rflCoeffToImpedance(c) {
9
+ return this.transform(c, 1 + c.re, c.im, 1 - c.re, -c.im, 2);
10
+ }
11
+ impedanceToRflCoeff(c) {
12
+ return this.transform(c, c.re - 1, c.im, c.re + 1, c.im, 2);
13
+ }
14
+ rflCoeffToAdmittance(c) {
15
+ return this.transform(c, 1 - c.re, -c.im, 1 + c.re, c.im, -2);
16
+ }
17
+ admittanceToRflCoeff(c) {
18
+ return this.transform(c, 1 - c.re, -c.im, 1 + c.re, c.im, -2);
19
+ }
20
+ transform(value, nr, ni, dr, di, determinant) {
21
+ const quotient = complexRatio(nr, ni, dr, di);
22
+ if (!quotient) {
23
+ return;
24
+ }
25
+ // The analytic imaginary numerator avoids cancellation of nearly equal products.
26
+ const scale = Math.max(Math.abs(dr), Math.abs(di));
27
+ const denominator = (dr / scale) ** 2 + (di / scale) ** 2;
28
+ const im = (determinant * (value.im / scale)) / denominator / scale;
29
+ return Number.isFinite(im) ? Complex.from(quotient.re, im) : undefined;
30
+ }
31
+ resistanceCircle(n) {
32
+ return { p: [n / (n + 1), 0], r: 1 / (n + 1) };
33
+ }
34
+ reactanceCircle(n) {
35
+ return { p: [1, 1 / n], r: Math.abs(1 / n) };
36
+ }
37
+ conductanceCircle(n) {
38
+ return { p: [-n / (n + 1), 0], r: 1 / (n + 1) };
39
+ }
40
+ susceptanceCircle(n) {
41
+ return { p: [-1, -1 / n], r: Math.abs(1 / n) };
42
+ }
43
+ constQCircle(q) {
44
+ // Center is (0, +1/Q) or (0, -1/Q).
45
+ return { p: [0, 1 / q], r: Math.sqrt(1 + 1 / (q * q)) };
46
+ }
47
+ rflCoeffToSwr(rc) {
48
+ const gamma = rc.abs();
49
+ return (1 + gamma) / (1 - gamma);
50
+ }
51
+ rflCoeffToDBS(rc) {
52
+ return this.swrTodBS(this.rflCoeffToSwr(rc));
53
+ }
54
+ swrToRflCoeffEOrI(swr) {
55
+ return (swr - 1) / (swr + 1);
56
+ }
57
+ swrTodBS(swr) {
58
+ return 20 * Math.log10(swr);
59
+ }
60
+ dBSToSwr(dBS) {
61
+ return 10 ** (dBS / 20.0);
62
+ }
63
+ dBSToAbsRflCoeff(dBS) {
64
+ const swr = this.dBSToSwr(dBS);
65
+ return this.swrToRflCoeffEOrI(swr);
66
+ }
67
+ rflCoeffToReturnLoss(rc) {
68
+ return -20.0 * Math.log10(this.rflCoeffEOrI(rc));
69
+ }
70
+ returnLossToRflCoeffEOrI(rl) {
71
+ return 10 ** (-rl / 20.0);
72
+ }
73
+ /** One-way attenuation scale, referenced to a fully reflecting termination. */
74
+ rflCoeffToAttenuation(rc) {
75
+ return this.rflCoeffToReturnLoss(rc) / 2;
76
+ }
77
+ attenuationToRflCoeff(attenuation) {
78
+ return 10 ** (-attenuation / 10);
79
+ }
80
+ rflCoeffToMismatchLoss(rc) {
81
+ // mismatch loss is reflection loss
82
+ const abs = this.rflCoeffEOrI(rc);
83
+ return (-10 / Math.LN10) * Math.log1p(-(abs ** 2));
84
+ }
85
+ mismatchLossToRflCoeffEOrI(ml) {
86
+ return Math.sqrt(1 - 10 ** (-ml / 10));
87
+ }
88
+ rflCoeffEOrI(rc) {
89
+ return Math.sqrt(this.rflCoeffP(rc));
90
+ }
91
+ rflCoeffP(rc) {
92
+ return rc.abs() ** 2;
93
+ }
94
+ rflCoeffPToEOrI(p) {
95
+ return Math.sqrt(p);
96
+ }
97
+ rflCoeffToQ(rc) {
98
+ const impedance = this.rflCoeffToImpedance(rc);
99
+ if (!impedance || (impedance.re === 0 && impedance.im === 0)) {
100
+ return;
101
+ }
102
+ return Math.abs(impedance.im / impedance.re);
103
+ }
104
+ rflCoeffToTransmCoeffP(rc) {
105
+ return 1 - this.rflCoeffEOrI(rc) ** 2;
106
+ }
107
+ transmCoeffPToRflCoeffEOrI(tcp) {
108
+ return Math.sqrt(1.0 - tcp);
109
+ }
110
+ rflCoeffToTransmCoeff(rc) {
111
+ // T = R + 1
112
+ return rc.add(1);
113
+ }
114
+ transmCoeffToRflCoeff(tc) {
115
+ return tc.sub(1);
116
+ }
117
+ rflCoeffToTransmCoeffEOrI(rc) {
118
+ // T = R + 1
119
+ const tc = this.rflCoeffToTransmCoeff(rc);
120
+ return tc.abs();
121
+ }
122
+ /** Current transmission magnitude using the voltage reflection coefficient. */
123
+ rflCoeffToCurrentTransmission(rc) {
124
+ return Math.hypot(1 - rc.re, rc.im);
125
+ }
126
+ // s. w. peak (const. p)
127
+ // MAX. LIMITS = |V|max/|V|max,0 = sqrt(VSWR)
128
+ rflCoeffToSwPeakConstP(rc) {
129
+ return Math.sqrt(this.rflCoeffToSwr(rc));
130
+ }
131
+ swPeakConstPToRflCoeffEOrI(swPeak) {
132
+ return this.swrToRflCoeffEOrI(swPeak ** 2);
133
+ }
134
+ // SW. LOSS COEF. = (Pincident + Preflect) / (Pincident - Preflect)
135
+ // SW. LOSS COEF. = (1+|S|^2) / (1-|S|^2)
136
+ rflCoeffToSwLossCoeff(rc) {
137
+ const abs = this.rflCoeffEOrI(rc);
138
+ return (1 + abs ** 2) / (1 - abs ** 2);
139
+ }
140
+ swLossCoeffToRflCoeffEOrI(swl) {
141
+ return Math.sqrt((swl - 1) / (swl + 1));
142
+ }
143
+ // public transmCoeffToInsertionLoss(tc: Complex): number {
144
+ // return -20 * Math.log10()
145
+ // }
146
+ circleCircleIntersection(c1, c2) {
147
+ const dl = Math.sqrt(Math.pow(c2.p[0] - c1.p[0], 2) + Math.pow(c2.p[1] - c1.p[1], 2));
148
+ const cosA = (dl * dl + c1.r * c1.r - c2.r * c2.r) / (2 * dl * c1.r);
149
+ const sinA = Math.sqrt(1 - Math.pow(cosA, 2));
150
+ const vpx = ((c2.p[0] - c1.p[0]) * c1.r) / dl;
151
+ const vpy = ((c2.p[1] - c1.p[1]) * c1.r) / dl;
152
+ return [
153
+ [vpx * cosA - vpy * sinA + c1.p[0], vpx * sinA + vpy * cosA + c1.p[1]],
154
+ [vpx * cosA + vpy * sinA + c1.p[0], vpy * cosA - vpx * sinA + c1.p[1]],
155
+ ];
156
+ }
157
+ isPointWithinCircle(p, c) {
158
+ return Math.pow(p[0] - c.p[0], 2) + Math.pow(p[1] - c.p[1], 2) <= Math.pow(c.r, 2);
159
+ }
160
+ normalize(c) {
161
+ return c.div(this.Z0);
162
+ }
163
+ denormalize(c) {
164
+ return c.mul(this.Z0);
165
+ }
166
+ waveLengthFromFrequency(frequency) {
167
+ return 299792458 / frequency;
168
+ }
169
+ frequencyFromWaveLength(waveLength) {
170
+ return 299792458 / waveLength;
171
+ }
172
+ magnitude(c) {
173
+ return c.abs();
174
+ }
175
+ dB(value) {
176
+ return 20 * Math.log10(value);
177
+ }
178
+ reactanceToCapacitance(x, f) {
179
+ if (x >= 0) {
180
+ return null;
181
+ }
182
+ return -1 / (2 * Math.PI * f * x);
183
+ }
184
+ capacitanceToReactance(C, f) {
185
+ return Complex.from(0, -1 / (2 * Math.PI * f * C));
186
+ }
187
+ reactanceToInductance(x, f) {
188
+ if (x <= 0) {
189
+ return null;
190
+ }
191
+ return x / (2 * Math.PI * f);
192
+ }
193
+ inductanceToReactance(L, f) {
194
+ return Complex.from(0, 2 * Math.PI * f * L);
195
+ }
196
+ addImpedance(rc, imp) {
197
+ let Z = this.rflCoeffToImpedance(rc);
198
+ if (Z === undefined) {
199
+ return undefined;
200
+ }
201
+ Z = Z.add(imp.div(this.Z0));
202
+ return this.impedanceToRflCoeff(Z);
203
+ }
204
+ addAdmittance(rc, adm) {
205
+ let Y = this.rflCoeffToAdmittance(rc);
206
+ if (Y === undefined) {
207
+ return undefined;
208
+ }
209
+ Y = Y.add(adm.mul(this.Z0));
210
+ return this.admittanceToRflCoeff(Y);
211
+ }
212
+ tangentToCircleAngle(c, p) {
213
+ // tangent to a circle, angle = atag(a)
214
+ return this.rad2deg(Math.atan((c.p[0] - p[0]) / (p[1] - c.p[1])));
215
+ }
216
+ rad2deg(rad) {
217
+ return (rad * 180.0) / Math.PI;
218
+ }
219
+ deg2rad(deg) {
220
+ return (deg * Math.PI) / 180.0;
221
+ }
222
+ }
@@ -0,0 +1,33 @@
1
+ export interface TickDef {
2
+ point: {
3
+ r: number;
4
+ i: number;
5
+ };
6
+ transform?: {
7
+ dx?: number;
8
+ dy?: number;
9
+ rotate?: number;
10
+ };
11
+ dp?: number;
12
+ textAnchor?: string;
13
+ dominantBaseline?: string;
14
+ }
15
+ export interface TickDefRequired {
16
+ point: {
17
+ r: number;
18
+ i: number;
19
+ };
20
+ transform: {
21
+ dx: number;
22
+ dy: number;
23
+ rotate: number;
24
+ };
25
+ dp: number;
26
+ textAnchor: string;
27
+ dominantBaseline: string;
28
+ }
29
+ export declare class Tick {
30
+ private def;
31
+ constructor(def: TickDef);
32
+ get definition(): TickDefRequired;
33
+ }
@@ -0,0 +1,40 @@
1
+ export class Tick {
2
+ def;
3
+ constructor(def) {
4
+ if (def.transform === undefined) {
5
+ def.transform = {};
6
+ }
7
+ if (def.transform.dx === undefined) {
8
+ def.transform.dx = 0;
9
+ }
10
+ if (def.transform.dy === undefined) {
11
+ def.transform.dy = 0;
12
+ }
13
+ if (def.transform.rotate === undefined) {
14
+ def.transform.rotate = 0;
15
+ }
16
+ if (def.dp === undefined) {
17
+ def.dp = 0;
18
+ }
19
+ if (def.textAnchor === undefined) {
20
+ def.textAnchor = 'start';
21
+ }
22
+ if (def.dominantBaseline === undefined) {
23
+ def.dominantBaseline = 'baseline';
24
+ }
25
+ this.def = {
26
+ point: { r: def.point.r, i: def.point.i },
27
+ transform: {
28
+ dx: def.transform.dx,
29
+ dy: def.transform.dy,
30
+ rotate: def.transform.rotate,
31
+ },
32
+ dp: def.dp,
33
+ textAnchor: def.textAnchor,
34
+ dominantBaseline: def.dominantBaseline,
35
+ };
36
+ }
37
+ get definition() {
38
+ return this.def;
39
+ }
40
+ }
@@ -0,0 +1,130 @@
1
+ export declare class Complex {
2
+ private readonly realPart;
3
+ private readonly imaginaryPart;
4
+ private tolerance;
5
+ private constructor();
6
+ static from(re: number, im?: number): Complex;
7
+ static from(rect: {
8
+ re: number;
9
+ im: number;
10
+ }): Complex;
11
+ static from(polar: {
12
+ r: number;
13
+ phi: number;
14
+ }): Complex;
15
+ static from(arr: readonly [number, number]): Complex;
16
+ private static fromPolar;
17
+ static one(): Complex;
18
+ static zero(): Complex;
19
+ static get i(): Complex;
20
+ get re(): number;
21
+ get im(): number;
22
+ get epsilon(): number;
23
+ set epsilon(e: number);
24
+ abs(): number;
25
+ arg(): number;
26
+ sign(): Complex;
27
+ conj(): Complex;
28
+ neg(): Complex;
29
+ inv(): Complex;
30
+ add(v: number | Complex): Complex;
31
+ sub(v: number | Complex): Complex;
32
+ mul(v: number | Complex): Complex;
33
+ div(v: number | Complex): Complex;
34
+ exp(): Complex;
35
+ log(): Complex;
36
+ log2(): Complex;
37
+ log10(): Complex;
38
+ pow(exponent: number): Complex;
39
+ sqrt(): Complex;
40
+ sin(): Complex;
41
+ asin(): Complex;
42
+ sinh(): Complex;
43
+ asinh(): Complex;
44
+ cos(): Complex;
45
+ acos(): Complex;
46
+ cosh(): Complex;
47
+ acosh(): Complex;
48
+ tan(): Complex;
49
+ atan(): Complex;
50
+ tanh(): Complex;
51
+ atanh(): Complex;
52
+ cot(): Complex;
53
+ acot(): Complex;
54
+ coth(): Complex;
55
+ acoth(): Complex;
56
+ sec(): Complex;
57
+ asec(): Complex;
58
+ sech(): Complex;
59
+ asech(): Complex;
60
+ csc(): Complex;
61
+ acsc(): Complex;
62
+ csch(): Complex;
63
+ acsch(): Complex;
64
+ equals(z: Complex): boolean;
65
+ toPolar(): [number, number];
66
+ toVector(): [number, number];
67
+ toString(dp?: number): string;
68
+ static abs(z: Complex): number;
69
+ static arg(z: Complex): number;
70
+ static sign(z: Complex): Complex;
71
+ static conj(z: Complex): Complex;
72
+ static neg(z: Complex): Complex;
73
+ static inv(z: Complex): Complex;
74
+ static add(z: Complex, v: number | Complex): Complex;
75
+ static sub(z: Complex, v: number | Complex): Complex;
76
+ static mul(z: Complex, v: number | Complex): Complex;
77
+ static div(z: Complex, v: number | Complex): Complex;
78
+ static exp(z: Complex): Complex;
79
+ static log(z: Complex): Complex;
80
+ static log2(z: Complex): Complex;
81
+ static log10(z: Complex): Complex;
82
+ static pow(z: Complex, exponent: number): Complex;
83
+ static sqrt(z: Complex): Complex;
84
+ static sin(z: Complex): Complex;
85
+ static asin(z: Complex): Complex;
86
+ static sinh(z: Complex): Complex;
87
+ static asinh(z: Complex): Complex;
88
+ static cos(z: Complex): Complex;
89
+ static acos(z: Complex): Complex;
90
+ static cosh(z: Complex): Complex;
91
+ static acosh(z: Complex): Complex;
92
+ static tan(z: Complex): Complex;
93
+ static atan(z: Complex): Complex;
94
+ static tanh(z: Complex): Complex;
95
+ static atanh(z: Complex): Complex;
96
+ static cot(z: Complex): Complex;
97
+ static acot(z: Complex): Complex;
98
+ static coth(z: Complex): Complex;
99
+ static acoth(z: Complex): Complex;
100
+ static sec(z: Complex): Complex;
101
+ static asec(z: Complex): Complex;
102
+ static sech(z: Complex): Complex;
103
+ static asech(z: Complex): Complex;
104
+ static csc(z: Complex): Complex;
105
+ static acsc(z: Complex): Complex;
106
+ static csch(z: Complex): Complex;
107
+ static acsch(z: Complex): Complex;
108
+ private static isFinite;
109
+ private static nan;
110
+ private static copySign;
111
+ private static logHypot;
112
+ /** Sum two products without premature overflow/underflow. Result is mantissa × 2^exponent. */
113
+ private static productSum;
114
+ private static scalePowerOfTwo;
115
+ /** Cartesian reciprocal, preserving signed zeros on branch cuts. */
116
+ private static reciprocal;
117
+ private static hyperbolicProduct;
118
+ private static hyperbolicReciprocal;
119
+ /**
120
+ * Elliptic coordinates for principal inverse functions (x,y >= 0).
121
+ * With a = (|z+1| + |z-1|)/2, return acosh(a) and sqrt(a²-x²).
122
+ * Rationalized hypot differences retain tiny components near the branch cuts.
123
+ * Principal branches: https://dlmf.nist.gov/4.37
124
+ */
125
+ private static inverseHyperbolicParts;
126
+ static equals(z1: Complex, z2: Complex, epsilon?: number): boolean;
127
+ static toPolar(z: Complex): [number, number];
128
+ static toVector(z: Complex): [number, number];
129
+ static toString(z: Complex, dp?: number): string;
130
+ }