calculate-packing 0.0.50 → 0.0.52

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/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  **calculate-packing** is a small TypeScript library that ships the placement /
4
4
  packing algorithm used by the [tscircuit tool-chain](https://github.com/tscircuit/tscircuit) for automatically laying out PCB components.
5
5
 
6
+ [Paste PackInput and Debug Online](https://calculate-packing.tscircuit.com/?fixture=%7B%22path%22%3A%22site%2Fpack%2Fpack-debugger-from-input.page.tsx%22%7D)
7
+
6
8
  The solver turns a user-supplied `PackInput` (components, pads & strategy
7
9
  settings) into a collision-free `PackOutput` while
8
10
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { CircuitJson } from 'circuit-json';
2
2
  import { GraphicsObject, Point as Point$3 } from 'graphics-debug';
3
+ import { BaseSolver as BaseSolver$1 } from '@tscircuit/solver-utils';
3
4
  import { Bounds, Point as Point$2 } from '@tscircuit/math-utils';
4
5
 
5
6
  type ComponentId = string;
@@ -122,40 +123,6 @@ declare const getGraphicsFromPackOutput: (packOutput: PackOutput) => GraphicsObj
122
123
  */
123
124
  declare const convertPackOutputToPackInput: (packed: PackOutput) => PackInput;
124
125
 
125
- declare class BaseSolver {
126
- MAX_ITERATIONS: number;
127
- solved: boolean;
128
- failed: boolean;
129
- iterations: number;
130
- progress: number;
131
- error: string | null;
132
- activeSubSolver?: BaseSolver | null;
133
- failedSubSolvers?: BaseSolver[];
134
- timeToSolve?: number;
135
- stats: Record<string, any>;
136
- _setupDone: boolean;
137
- setup(): void;
138
- /** DO NOT OVERRIDE! Override _step() instead */
139
- step(): void;
140
- _setup(): void;
141
- _step(): void;
142
- getConstructorParams(): void;
143
- solve(): void;
144
- visualize(): GraphicsObject;
145
- /**
146
- * Called when the solver is about to fail, but we want to see if we have an
147
- * "acceptable" or "passable" solution. Mostly used for optimizers that
148
- * have an aggressive early stopping criterion.
149
- */
150
- tryFinalAcceptance(): void;
151
- /**
152
- * A lightweight version of the visualize method that can be used to stream
153
- * progress
154
- */
155
- preview(): GraphicsObject;
156
- noisySolve(): void;
157
- }
158
-
159
126
  type Point$1 = {
160
127
  x: number;
161
128
  y: number;
@@ -170,7 +137,7 @@ type Rect = {
170
137
  };
171
138
 
172
139
  type GlobalBounds = Bounds;
173
- declare class LargestRectOutsideOutlineFromPointSolver extends BaseSolver {
140
+ declare class LargestRectOutsideOutlineFromPointSolver extends BaseSolver$1 {
174
141
  fullOutline: Point$1[];
175
142
  origin: Point$1;
176
143
  globalBounds: Bounds;
@@ -199,6 +166,47 @@ declare class LargestRectOutsideOutlineFromPointSolver extends BaseSolver {
199
166
  getLargestRect(): Rect | null;
200
167
  getLargestRectBounds(): Bounds;
201
168
  visualize(): GraphicsObject;
169
+ getOutput(): Rect | null;
170
+ }
171
+
172
+ declare class BaseSolver {
173
+ MAX_ITERATIONS: number;
174
+ solved: boolean;
175
+ failed: boolean;
176
+ iterations: number;
177
+ progress: number;
178
+ error: string | null;
179
+ activeSubSolver?: BaseSolver | null;
180
+ failedSubSolvers?: BaseSolver[];
181
+ timeToSolve?: number;
182
+ stats: Record<string, any>;
183
+ _setupDone: boolean;
184
+ setup(): void;
185
+ /** DO NOT OVERRIDE! Override _step() instead */
186
+ step(): void;
187
+ _setup(): void;
188
+ _step(): void;
189
+ getConstructorParams(): void;
190
+ solve(): void;
191
+ visualize(): GraphicsObject;
192
+ /**
193
+ * Called when the solver is about to fail, but we want to see if we have an
194
+ * "acceptable" or "passable" solution. Mostly used for optimizers that
195
+ * have an aggressive early stopping criterion.
196
+ */
197
+ tryFinalAcceptance(): void;
198
+ /**
199
+ * Override this method to return the standardized output of the solver.
200
+ * This method should only be called after the solver has completed successfully.
201
+ * Returns null by default - solvers with outputs should override this method.
202
+ */
203
+ getOutput(): any;
204
+ /**
205
+ * A lightweight version of the visualize method that can be used to stream
206
+ * progress
207
+ */
208
+ preview(): GraphicsObject;
209
+ noisySolve(): void;
202
210
  }
203
211
 
204
212
  interface Point {
@@ -273,6 +281,7 @@ declare class MultiOffsetIrlsSolver extends BaseSolver {
273
281
  getDistanceForPad(padId: string, position?: Point): number;
274
282
  computeProgress(): number;
275
283
  visualize(): GraphicsObject;
284
+ getOutput(): Point;
276
285
  }
277
286
 
278
287
  interface TwoPhaseIrlsSolverParams extends Omit<MultiOffsetIrlsSolverParams, "useSquaredDistance"> {
@@ -339,6 +348,10 @@ declare class TwoPhaseIrlsSolver extends BaseSolver {
339
348
  y: number;
340
349
  }): number;
341
350
  visualize(): GraphicsObject;
351
+ getOutput(): {
352
+ x: number;
353
+ y: number;
354
+ };
342
355
  }
343
356
 
344
357
  /**
@@ -351,7 +364,7 @@ declare class TwoPhaseIrlsSolver extends BaseSolver {
351
364
  * at the site/algorithm-visualizations/irls-weiszfeld-algorithm.page.tsx for
352
365
  * an interactive visualization of how it works.
353
366
  */
354
- declare class OutlineSegmentCandidatePointSolver extends BaseSolver {
367
+ declare class OutlineSegmentCandidatePointSolver extends BaseSolver$1 {
355
368
  outlineSegment: [Point$2, Point$2];
356
369
  viableOutlineSegment: [Point$2, Point$2] | null;
357
370
  fullOutline: [Point$2, Point$2][];
@@ -413,6 +426,7 @@ declare class OutlineSegmentCandidatePointSolver extends BaseSolver {
413
426
  */
414
427
  private adjustPositionForOutlineCollision;
415
428
  visualize(): GraphicsObject;
429
+ getOutput(): Point$2 | null;
416
430
  }
417
431
 
418
432
  type Phase = "outline" | "segment_candidate" | "evaluate";
@@ -443,7 +457,7 @@ interface CandidateResult {
443
457
  * where step=0 is the best point (lowest distance) and step=N is the
444
458
  * worst point.
445
459
  */
446
- declare class SingleComponentPackSolver extends BaseSolver {
460
+ declare class SingleComponentPackSolver extends BaseSolver$1 {
447
461
  componentToPack: InputComponent;
448
462
  packedComponents: PackedComponent[];
449
463
  packPlacementStrategy: PackPlacementStrategy;
@@ -490,6 +504,7 @@ declare class SingleComponentPackSolver extends BaseSolver {
490
504
  private visualizeSegmentCandidatePhase;
491
505
  private visualizeEvaluatePhase;
492
506
  getResult(): PackedComponent | undefined;
507
+ getOutput(): PackedComponent | undefined;
493
508
  getConstructorParams(): {
494
509
  componentToPack: InputComponent;
495
510
  packedComponents: PackedComponent[];
@@ -504,7 +519,7 @@ declare class SingleComponentPackSolver extends BaseSolver {
504
519
  };
505
520
  }
506
521
 
507
- declare class PackSolver2 extends BaseSolver {
522
+ declare class PackSolver2 extends BaseSolver$1 {
508
523
  activeSubSolver: SingleComponentPackSolver | null | undefined;
509
524
  packInput: PackInput;
510
525
  unpackedComponentQueue: InputComponent[];
@@ -516,6 +531,10 @@ declare class PackSolver2 extends BaseSolver {
516
531
  private packFirstComponent;
517
532
  _step(): void;
518
533
  visualize(): GraphicsObject;
534
+ getOutput(): {
535
+ packedComponents: PackedComponent[];
536
+ unpackedComponents: InputComponent[];
537
+ };
519
538
  }
520
539
 
521
540
  export { type ComponentId, type GlobalBounds, type InputComponent, type InputObstacle, type InputPad, LargestRectOutsideOutlineFromPointSolver, type NetworkId, type OutputPad, type PackInput, type PackOutput, type PackPlacementStrategy, PackSolver2, type PackedComponent, type PadId, type Point$1 as Point, type Rect, convertCircuitJsonToPackOutput, convertPackOutputToPackInput, getGraphicsFromPackOutput, pack };
package/dist/index.js CHANGED
@@ -320,6 +320,7 @@ var constructOutlinesFromPackedComponents = (components, opts = {}) => {
320
320
 
321
321
  // lib/OutlineSegmentCandidatePointSolver/OutlineSegmentCandidatePointSolver.ts
322
322
  import { clamp } from "@tscircuit/math-utils";
323
+ import { BaseSolver as BaseSolver3 } from "@tscircuit/solver-utils";
323
324
 
324
325
  // lib/solver-utils/makeNumbersRounded.ts
325
326
  var makeNumbersRounded = (obj) => {
@@ -413,6 +414,14 @@ var BaseSolver = class {
413
414
  */
414
415
  tryFinalAcceptance() {
415
416
  }
417
+ /**
418
+ * Override this method to return the standardized output of the solver.
419
+ * This method should only be called after the solver has completed successfully.
420
+ * Returns null by default - solvers with outputs should override this method.
421
+ */
422
+ getOutput() {
423
+ return null;
424
+ }
416
425
  /**
417
426
  * A lightweight version of the visualize method that can be used to stream
418
427
  * progress
@@ -662,6 +671,9 @@ var MultiOffsetIrlsSolver = class extends BaseSolver {
662
671
  }
663
672
  return graphics;
664
673
  }
674
+ getOutput() {
675
+ return this.optimalPosition ?? this.currentPosition;
676
+ }
665
677
  };
666
678
 
667
679
  // lib/solver-utils/TwoPhaseIrlsSolver.ts
@@ -914,6 +926,9 @@ var TwoPhaseIrlsSolver = class extends BaseSolver {
914
926
  }
915
927
  return graphics;
916
928
  }
929
+ getOutput() {
930
+ return this.optimalPosition ?? this.currentPosition;
931
+ }
917
932
  };
918
933
 
919
934
  // lib/testing/createColorMapFromStrings.ts
@@ -1082,7 +1097,8 @@ function getOutlineBoundsWithMargin(fullOutline, margin = 0) {
1082
1097
  }
1083
1098
 
1084
1099
  // lib/LargestRectOutsideOutlineFromPointSolver.ts
1085
- var LargestRectOutsideOutlineFromPointSolver = class extends BaseSolver {
1100
+ import { BaseSolver as BaseSolver2 } from "@tscircuit/solver-utils";
1101
+ var LargestRectOutsideOutlineFromPointSolver = class extends BaseSolver2 {
1086
1102
  fullOutline;
1087
1103
  origin;
1088
1104
  globalBounds;
@@ -1338,6 +1354,9 @@ var LargestRectOutsideOutlineFromPointSolver = class extends BaseSolver {
1338
1354
  }
1339
1355
  return graphics;
1340
1356
  }
1357
+ getOutput() {
1358
+ return this.largestRect ?? null;
1359
+ }
1341
1360
  };
1342
1361
 
1343
1362
  // lib/geometry/getInputComponentBounds.ts
@@ -1424,7 +1443,7 @@ function isPointInPolygon(point, polygon) {
1424
1443
  }
1425
1444
 
1426
1445
  // lib/OutlineSegmentCandidatePointSolver/OutlineSegmentCandidatePointSolver.ts
1427
- var OutlineSegmentCandidatePointSolver = class extends BaseSolver {
1446
+ var OutlineSegmentCandidatePointSolver = class extends BaseSolver3 {
1428
1447
  outlineSegment;
1429
1448
  viableOutlineSegment = null;
1430
1449
  fullOutline;
@@ -1932,8 +1951,14 @@ var OutlineSegmentCandidatePointSolver = class extends BaseSolver {
1932
1951
  }
1933
1952
  return graphics;
1934
1953
  }
1954
+ getOutput() {
1955
+ return this.optimalPosition ?? null;
1956
+ }
1935
1957
  };
1936
1958
 
1959
+ // lib/SingleComponentPackSolver/SingleComponentPackSolver.ts
1960
+ import { BaseSolver as BaseSolver4 } from "@tscircuit/solver-utils";
1961
+
1937
1962
  // lib/testing/getGraphicsFromPackOutput.ts
1938
1963
  var getGraphicsFromPackOutput = (packOutput) => {
1939
1964
  const rects = [];
@@ -2054,7 +2079,7 @@ function checkOverlapWithPackedComponents({
2054
2079
 
2055
2080
  // lib/SingleComponentPackSolver/SingleComponentPackSolver.ts
2056
2081
  import { computeDistanceBetweenBoxes as computeDistanceBetweenBoxes2 } from "@tscircuit/math-utils";
2057
- var SingleComponentPackSolver = class extends BaseSolver {
2082
+ var SingleComponentPackSolver = class extends BaseSolver4 {
2058
2083
  componentToPack;
2059
2084
  packedComponents;
2060
2085
  packPlacementStrategy;
@@ -2504,6 +2529,9 @@ gap_distance=${candidate.gapDistance}`,
2504
2529
  getResult() {
2505
2530
  return this.outputPackedComponent;
2506
2531
  }
2532
+ getOutput() {
2533
+ return this.getResult();
2534
+ }
2507
2535
  getConstructorParams() {
2508
2536
  return {
2509
2537
  componentToPack: this.componentToPack,
@@ -2518,6 +2546,7 @@ gap_distance=${candidate.gapDistance}`,
2518
2546
  };
2519
2547
 
2520
2548
  // lib/PackSolver2/PackSolver2.ts
2549
+ import { BaseSolver as BaseSolver5 } from "@tscircuit/solver-utils";
2521
2550
  import { computeDistanceBetweenBoxes as computeDistanceBetweenBoxes3 } from "@tscircuit/math-utils";
2522
2551
 
2523
2552
  // lib/math/getPolygonCentroid.ts
@@ -2551,7 +2580,7 @@ function getPolygonCentroid(points) {
2551
2580
  }
2552
2581
 
2553
2582
  // lib/PackSolver2/PackSolver2.ts
2554
- var PackSolver2 = class extends BaseSolver {
2583
+ var PackSolver2 = class extends BaseSolver5 {
2555
2584
  packInput;
2556
2585
  unpackedComponentQueue = [];
2557
2586
  packedComponents = [];
@@ -2792,6 +2821,12 @@ var PackSolver2 = class extends BaseSolver {
2792
2821
  }
2793
2822
  return graphics;
2794
2823
  }
2824
+ getOutput() {
2825
+ return {
2826
+ packedComponents: this.packedComponents,
2827
+ unpackedComponents: this.unpackedComponentQueue
2828
+ };
2829
+ }
2795
2830
  };
2796
2831
 
2797
2832
  // lib/pack.ts
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "calculate-packing",
3
3
  "main": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.0.50",
5
+ "version": "0.0.52",
6
6
  "description": "Calculate a packing layout with support for different strategy configurations",
7
7
  "scripts": {
8
8
  "start": "cosmos",
@@ -22,6 +22,7 @@
22
22
  "@tscircuit/circuit-json-util": "^0.0.66",
23
23
  "@tscircuit/footprinter": "^0.0.203",
24
24
  "@tscircuit/math-utils": "^0.0.25",
25
+ "@tscircuit/solver-utils": "^0.0.3",
25
26
  "@types/bun": "latest",
26
27
  "@types/react": "^19.1.8",
27
28
  "@types/react-dom": "^19.1.6",