calculate-packing 0.0.34 → 0.0.36

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 (3) hide show
  1. package/dist/index.d.ts +53 -94
  2. package/dist/index.js +1209 -2120
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { GraphicsObject, Point as Point$2 } from 'graphics-debug';
2
1
  import { CircuitJson } from 'circuit-json';
3
- import { Bounds, Point as Point$3 } from '@tscircuit/math-utils';
2
+ import { GraphicsObject, Point as Point$3 } from 'graphics-debug';
3
+ import { Bounds, Point as Point$2 } from '@tscircuit/math-utils';
4
4
 
5
5
  type ComponentId = string;
6
6
  type PadId = string;
@@ -43,9 +43,19 @@ interface PackedComponent extends InputComponent {
43
43
  ccwRotationDegrees?: number;
44
44
  pads: OutputPad[];
45
45
  }
46
+ interface InputObstacle {
47
+ obstacleId: string;
48
+ absoluteCenter: {
49
+ x: number;
50
+ y: number;
51
+ };
52
+ width: number;
53
+ height: number;
54
+ }
46
55
  type PackPlacementStrategy = "shortest_connection_along_outline" | "minimum_sum_distance_to_network" | "minimum_sum_squared_distance_to_network" | "minimum_closest_sum_squared_distance";
47
56
  interface PackInput {
48
57
  components: InputComponent[];
58
+ obstacles?: InputObstacle[];
49
59
  minGap: number;
50
60
  packOrderStrategy: "largest_to_smallest";
51
61
  packPlacementStrategy: PackPlacementStrategy;
@@ -73,6 +83,34 @@ interface PackOutput extends PackInput {
73
83
  */
74
84
  declare const pack: (input: PackInput) => PackOutput;
75
85
 
86
+ declare const convertCircuitJsonToPackOutput: (circuitJson: CircuitJson, opts?: {
87
+ source_group_id?: string;
88
+ shouldAddInnerObstacles?: boolean;
89
+ chipMarginsMap?: Record<string, {
90
+ left: number;
91
+ right: number;
92
+ top: number;
93
+ bottom: number;
94
+ }>;
95
+ }) => PackOutput;
96
+
97
+ declare const getGraphicsFromPackOutput: (packOutput: PackOutput) => GraphicsObject;
98
+
99
+ /**
100
+ * Strip all “output only” properties (those added by the pack() solver)
101
+ * so the result can be fed back into pack() again or compared against an
102
+ * original PackInput. Everything else must be preserved verbatim.
103
+ *
104
+ * NOTE:
105
+ * – PackInput.components is an array of **InputComponent**,
106
+ * while PackOutput.components is an array of **PackedComponent**.
107
+ * We therefore have to:
108
+ * • copy componentId
109
+ * • copy each pad but drop `absoluteCenter`
110
+ * • drop `center` and `ccwRotationOffset`
111
+ */
112
+ declare const convertPackOutputToPackInput: (packed: PackOutput) => PackInput;
113
+
76
114
  declare class BaseSolver {
77
115
  MAX_ITERATIONS: number;
78
116
  solved: boolean;
@@ -113,90 +151,6 @@ type Point$1 = {
113
151
  };
114
152
  type Segment = [Point$1, Point$1];
115
153
 
116
- type PackingPhase = "idle" | "show_candidate_points" | "show_rotations" | "show_final_placement";
117
- interface RotationTrial extends PackedComponent {
118
- cost: number;
119
- anchorType: "pad" | "center";
120
- anchorPadId?: string;
121
- hasOverlap: boolean;
122
- }
123
- declare class PhasedPackSolver extends BaseSolver {
124
- packInput: PackInput;
125
- unpackedComponentQueue: InputComponent[];
126
- packedComponents: PackedComponent[];
127
- currentPhase: PackingPhase;
128
- currentComponent?: InputComponent;
129
- phaseData: {
130
- candidatePoints?: Array<Point$2 & {
131
- networkId: NetworkId;
132
- distance: number;
133
- }>;
134
- goodCandidates?: Array<Point$2 & {
135
- networkId: NetworkId;
136
- }>;
137
- bestDistance?: number;
138
- rotationTrials?: Array<RotationTrial>;
139
- selectedRotation?: PackedComponent;
140
- outlines?: Segment[][];
141
- };
142
- lastBestPointsResult?: {
143
- goodCandidates: (Point$2 & {
144
- networkId: NetworkId;
145
- })[];
146
- distance: number;
147
- };
148
- lastEvaluatedPositionShadows?: Array<PackedComponent>;
149
- lastCandidatePoints?: Array<Point$2 & {
150
- networkId: NetworkId;
151
- distance: number;
152
- }>;
153
- constructor(input: PackInput);
154
- _setup(): void;
155
- _step(): void;
156
- private placeFirstComponent;
157
- private computeCandidatePoints;
158
- private computeRotationTrials;
159
- private selectBestRotation;
160
- private finalizeComponentPlacement;
161
- /** Visualize the current packing state based on the current phase */
162
- visualize(): GraphicsObject;
163
- private visualizeCandidatePoints;
164
- private visualizeRotationTrials;
165
- private visualizeFinalPlacement;
166
- getConstructorParams(): PackInput[];
167
- getResult(): PackedComponent[];
168
- private getCandidateAngles;
169
- private checkOverlapWithPackedComponents;
170
- }
171
-
172
- declare const convertCircuitJsonToPackOutput: (circuitJson: CircuitJson, opts?: {
173
- source_group_id?: string;
174
- shouldAddInnerObstacles?: boolean;
175
- chipMarginsMap?: Record<string, {
176
- left: number;
177
- right: number;
178
- top: number;
179
- bottom: number;
180
- }>;
181
- }) => PackOutput;
182
-
183
- declare const getGraphicsFromPackOutput: (packOutput: PackOutput) => GraphicsObject;
184
-
185
- /**
186
- * Strip all “output only” properties (those added by the pack() solver)
187
- * so the result can be fed back into pack() again or compared against an
188
- * original PackInput. Everything else must be preserved verbatim.
189
- *
190
- * NOTE:
191
- * – PackInput.components is an array of **InputComponent**,
192
- * while PackOutput.components is an array of **PackedComponent**.
193
- * We therefore have to:
194
- * • copy componentId
195
- * • copy each pad but drop `absoluteCenter`
196
- * • drop `center` and `ccwRotationOffset`
197
- */
198
- declare const convertPackOutputToPackInput: (packed: PackOutput) => PackInput;
199
-
200
154
  type Rect = {
201
155
  x: number;
202
156
  y: number;
@@ -387,26 +341,28 @@ declare class TwoPhaseIrlsSolver extends BaseSolver {
387
341
  * an interactive visualization of how it works.
388
342
  */
389
343
  declare class OutlineSegmentCandidatePointSolver extends BaseSolver {
390
- outlineSegment: [Point$3, Point$3];
391
- viableOutlineSegment: [Point$3, Point$3] | null;
392
- fullOutline: [Point$3, Point$3][];
344
+ outlineSegment: [Point$2, Point$2];
345
+ viableOutlineSegment: [Point$2, Point$2] | null;
346
+ fullOutline: [Point$2, Point$2][];
393
347
  componentRotationDegrees: number;
394
348
  packStrategy: PackPlacementStrategy;
395
349
  minGap: number;
350
+ obstacles: InputObstacle[];
396
351
  packedComponents: PackedComponent[];
397
352
  componentToPack: InputComponent;
398
353
  viableBounds?: Bounds;
399
- optimalPosition?: Point$3;
354
+ optimalPosition?: Point$2;
400
355
  irlsSolver?: MultiOffsetIrlsSolver;
401
356
  twoPhaseIrlsSolver?: TwoPhaseIrlsSolver;
402
357
  constructor(params: {
403
- outlineSegment: [Point$3, Point$3];
404
- fullOutline: [Point$3, Point$3][];
358
+ outlineSegment: [Point$2, Point$2];
359
+ fullOutline: [Point$2, Point$2][];
405
360
  componentRotationDegrees: number;
406
361
  packStrategy: PackPlacementStrategy;
407
362
  minGap: number;
408
363
  packedComponents: PackedComponent[];
409
364
  componentToPack: InputComponent;
365
+ obstacles?: InputObstacle[];
410
366
  });
411
367
  getConstructorParams(): ConstructorParameters<typeof OutlineSegmentCandidatePointSolver>[0];
412
368
  _getOutlineBoundsWithMargin(params?: {
@@ -452,7 +408,7 @@ interface QueuedOutlineSegment {
452
408
  interface CandidateResult {
453
409
  segment: Segment;
454
410
  rotation: number;
455
- optimalPosition?: Point$2;
411
+ optimalPosition?: Point$3;
456
412
  distance: number;
457
413
  segmentIndex: number;
458
414
  rotationIndex: number;
@@ -475,6 +431,7 @@ declare class SingleComponentPackSolver extends BaseSolver {
475
431
  packedComponents: PackedComponent[];
476
432
  packPlacementStrategy: PackPlacementStrategy;
477
433
  minGap: number;
434
+ obstacles: InputObstacle[];
478
435
  currentPhase: Phase;
479
436
  outlines: Segment[][];
480
437
  queuedOutlineSegments: QueuedOutlineSegment[];
@@ -492,6 +449,7 @@ declare class SingleComponentPackSolver extends BaseSolver {
492
449
  packedComponents: PackedComponent[];
493
450
  packPlacementStrategy: PackPlacementStrategy;
494
451
  minGap?: number;
452
+ obstacles?: InputObstacle[];
495
453
  });
496
454
  _setup(): void;
497
455
  _step(): void;
@@ -510,6 +468,7 @@ declare class SingleComponentPackSolver extends BaseSolver {
510
468
  packedComponents: PackedComponent[];
511
469
  packPlacementStrategy: PackPlacementStrategy;
512
470
  minGap: number;
471
+ obstacles: InputObstacle[];
513
472
  };
514
473
  }
515
474
 
@@ -527,4 +486,4 @@ declare class PackSolver2 extends BaseSolver {
527
486
  visualize(): GraphicsObject;
528
487
  }
529
488
 
530
- export { type ComponentId, type GlobalBounds, type InputComponent, type InputPad, LargestRectOutsideOutlineFromPointSolver, type NetworkId, type OutputPad, type PackInput, type PackOutput, type PackPlacementStrategy, PackSolver2, type PackedComponent, type PadId, PhasedPackSolver, type Point$1 as Point, type Rect, convertCircuitJsonToPackOutput, convertPackOutputToPackInput, getGraphicsFromPackOutput, pack };
489
+ 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 };