calculate-packing 0.0.27 → 0.0.28

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/dist/index.d.ts CHANGED
@@ -233,6 +233,9 @@ interface Point {
233
233
  x: number;
234
234
  y: number;
235
235
  }
236
+ interface PointWithNetworkId extends Point {
237
+ networkId?: string;
238
+ }
236
239
  interface OffsetPadPoint {
237
240
  id: string;
238
241
  offsetX: number;
@@ -265,7 +268,7 @@ interface MultiOffsetIrlsSolverParams {
265
268
  */
266
269
  declare class MultiOffsetIrlsSolver extends BaseSolver {
267
270
  offsetPadPoints: OffsetPadPoint[];
268
- targetPointMap: Map<string, Point[]>;
271
+ targetPointMap: Map<string, PointWithNetworkId[]>;
269
272
  currentPosition: Point;
270
273
  constraintFn?: (point: Point) => Point;
271
274
  epsilon: number;
@@ -405,6 +408,9 @@ declare class SingleComponentPackSolver extends BaseSolver {
405
408
  currentRotationIndex: number;
406
409
  activeSubSolver?: OutlineSegmentCandidatePointSolver | null;
407
410
  candidateResults: CandidateResult[];
411
+ rejectedCandidates: Array<CandidateResult & {
412
+ gapDistance: number;
413
+ }>;
408
414
  bestCandidate?: CandidateResult;
409
415
  outputPackedComponent?: PackedComponent;
410
416
  constructor(params: {
package/dist/index.js CHANGED
@@ -23,12 +23,17 @@ function checkOverlapWithPackedComponents({
23
23
  newComponentPadBox,
24
24
  packedPadBox
25
25
  );
26
- if (boxDist < minGap) {
27
- return true;
26
+ if (boxDist + 1e-6 < minGap) {
27
+ return {
28
+ hasOverlap: true,
29
+ gapDistance: boxDist
30
+ };
28
31
  }
29
32
  }
30
33
  }
31
- return false;
34
+ return {
35
+ hasOverlap: false
36
+ };
32
37
  }
33
38
 
34
39
  // lib/math/computeNearestPointOnSegmentForSegmentSet.ts
@@ -1408,7 +1413,7 @@ var PhasedPackSolver = class extends BaseSolver {
1408
1413
  component,
1409
1414
  packedComponents: this.packedComponents,
1410
1415
  minGap: this.packInput.minGap ?? 0
1411
- });
1416
+ }).hasOverlap;
1412
1417
  }
1413
1418
  };
1414
1419
 
@@ -2451,7 +2456,10 @@ var OutlineSegmentCandidatePointSolver = class extends BaseSolver {
2451
2456
  for (const packedComponent of this.packedComponents) {
2452
2457
  for (const packedPad of packedComponent.pads) {
2453
2458
  if (packedPad.networkId === pad.networkId) {
2454
- targetPoints.push(packedPad.absoluteCenter);
2459
+ targetPoints.push({
2460
+ ...packedPad.absoluteCenter,
2461
+ networkId: packedPad.networkId
2462
+ });
2455
2463
  }
2456
2464
  }
2457
2465
  }
@@ -2726,6 +2734,7 @@ var SingleComponentPackSolver = class extends BaseSolver {
2726
2734
  currentRotationIndex = 0;
2727
2735
  activeSubSolver = null;
2728
2736
  candidateResults = [];
2737
+ rejectedCandidates = [];
2729
2738
  bestCandidate;
2730
2739
  outputPackedComponent;
2731
2740
  constructor(params) {
@@ -2804,13 +2813,23 @@ var SingleComponentPackSolver = class extends BaseSolver {
2804
2813
  let optimalPosition;
2805
2814
  if (this.activeSubSolver.solved && this.activeSubSolver.optimalPosition) {
2806
2815
  optimalPosition = this.activeSubSolver.optimalPosition;
2807
- const hasOverlap = checkOverlapWithPackedComponents({
2816
+ const { hasOverlap, gapDistance } = checkOverlapWithPackedComponents({
2808
2817
  component: this.createPackedComponent(optimalPosition, rotation),
2809
2818
  packedComponents: this.packedComponents,
2810
2819
  minGap: this.minGap
2811
2820
  });
2812
- if (!hasOverlap) {
2813
- distance = this.calculateDistance(optimalPosition, rotation);
2821
+ distance = this.calculateDistance(optimalPosition, rotation);
2822
+ if (hasOverlap) {
2823
+ this.rejectedCandidates.push({
2824
+ segment: queuedSegment.segment,
2825
+ rotation,
2826
+ optimalPosition,
2827
+ distance,
2828
+ segmentIndex: queuedSegment.segmentIndex,
2829
+ rotationIndex: this.currentRotationIndex,
2830
+ gapDistance
2831
+ });
2832
+ } else {
2814
2833
  this.candidateResults.push({
2815
2834
  segment: queuedSegment.segment,
2816
2835
  rotation,
@@ -2982,16 +3001,26 @@ var SingleComponentPackSolver = class extends BaseSolver {
2982
3001
  this.visualizeOutlinePhase(graphics);
2983
3002
  for (let i = 0; i < this.candidateResults.length; i++) {
2984
3003
  const candidate = this.candidateResults[i];
2985
- if (candidate.optimalPosition) {
2986
- const step = i;
2987
- const isBest = step === 0;
2988
- graphics.points.push({
2989
- x: candidate.optimalPosition.x,
2990
- y: candidate.optimalPosition.y,
2991
- label: `step=${step}, d=${candidate.distance.toFixed(3)}`,
2992
- color: isBest ? "rgba(0,255,0,0.8)" : "rgba(255,165,0,0.6)"
2993
- });
2994
- }
3004
+ if (!candidate.optimalPosition) continue;
3005
+ const step = i;
3006
+ const isBest = step === 0;
3007
+ graphics.points.push({
3008
+ x: candidate.optimalPosition.x,
3009
+ y: candidate.optimalPosition.y,
3010
+ label: `step=${step}, d=${candidate.distance.toFixed(3)}`,
3011
+ color: isBest ? "rgba(0,255,0,0.8)" : "rgba(255,165,0,0.6)"
3012
+ });
3013
+ }
3014
+ for (let i = 0; i < this.rejectedCandidates.length; i++) {
3015
+ const candidate = this.rejectedCandidates[i];
3016
+ if (!candidate.optimalPosition) continue;
3017
+ graphics.points.push({
3018
+ x: candidate.optimalPosition.x,
3019
+ y: candidate.optimalPosition.y,
3020
+ label: `rejected, d=${candidate.distance.toFixed(3)}
3021
+ gap_distance=${candidate.gapDistance}`,
3022
+ color: "rgba(255,0,0,0.8)"
3023
+ });
2995
3024
  }
2996
3025
  if (this.outputPackedComponent) {
2997
3026
  for (const pad of this.outputPackedComponent.pads) {
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.27",
5
+ "version": "0.0.28",
6
6
  "description": "Calculate a packing layout with support for different strategy configurations",
7
7
  "scripts": {
8
8
  "start": "cosmos",