@tscircuit/ngspice-spice-engine 0.0.4 → 0.0.6

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 (2) hide show
  1. package/dist/index.js +45 -0
  2. package/package.json +3 -1
package/dist/index.js CHANGED
@@ -1,3 +1,28 @@
1
+ // lib/linear-interpolate.ts
2
+ var linearInterpolate = (targetX, xPoints, yPoints) => {
3
+ if (xPoints.length === 0) {
4
+ return 0;
5
+ }
6
+ if (targetX <= xPoints[0]) {
7
+ return yPoints[0];
8
+ }
9
+ if (targetX >= xPoints[xPoints.length - 1]) {
10
+ return yPoints[yPoints.length - 1];
11
+ }
12
+ let i = 1;
13
+ while (i < xPoints.length && xPoints[i] < targetX) {
14
+ i++;
15
+ }
16
+ const x1 = xPoints[i - 1];
17
+ const y1 = yPoints[i - 1];
18
+ const x2 = xPoints[i];
19
+ const y2 = yPoints[i];
20
+ if (x2 === x1) {
21
+ return y1;
22
+ }
23
+ return y1 + (y2 - y1) * (targetX - x1) / (x2 - x1);
24
+ };
25
+
1
26
  // lib/parse-tran-params.ts
2
27
  var SUFFIX_MULTIPLIERS = {
3
28
  t: 1e12,
@@ -179,6 +204,26 @@ var eecircuitResultToVGraphs = (result, spiceString) => {
179
204
  });
180
205
  }
181
206
  }
207
+ const tranParams = parseTranParams(spiceString);
208
+ if (tranParams?.tstep && tranParams.tstep > 0 && tranParams.tstop && graphs.length > 0) {
209
+ const { tstep, tstop } = tranParams;
210
+ const tstart = tranParams.tstart ?? 0;
211
+ const numSteps = Math.floor((tstop - tstart) / tstep);
212
+ if (numSteps > 0) {
213
+ const newTimeValues = Array.from(
214
+ { length: numSteps + 1 },
215
+ (_, i) => tstart + i * tstep
216
+ );
217
+ const oldTimeValues = graphs[0].time;
218
+ return graphs.map((graph) => ({
219
+ ...graph,
220
+ time: newTimeValues,
221
+ voltage: newTimeValues.map(
222
+ (t) => linearInterpolate(t, oldTimeValues, graph.voltage)
223
+ )
224
+ }));
225
+ }
226
+ }
182
227
  return graphs;
183
228
  };
184
229
  var voltageGraphsToCircuitJson = (graphs, spiceString) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/ngspice-spice-engine",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "A tscircuit-compatible SPICE engine using ngspice.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,7 +21,9 @@
21
21
  },
22
22
  "devDependencies": {
23
23
  "@tscircuit/props": "^0.0.374",
24
+ "bun-match-svg": "^0.0.14",
24
25
  "circuit-json": "^0.0.290",
26
+ "circuit-to-svg": "^0.0.217",
25
27
  "@biomejs/biome": "^2.2.7",
26
28
  "@types/bun": "latest",
27
29
  "tscircuit": "^0.0.805",