calculate-packing 0.0.4 → 0.0.5

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
@@ -122,6 +122,7 @@ declare class PackSolver extends BaseSolver {
122
122
  })[];
123
123
  distance: number;
124
124
  };
125
+ lastEvaluatedPositionShadows?: Array<PackedComponent>;
125
126
  constructor(input: PackInput);
126
127
  _setup(): void;
127
128
  _step(): void;
package/dist/index.js CHANGED
@@ -353,11 +353,13 @@ function computeNearestPointOnSegmentForSegmentSet(segmentA, segmentSet) {
353
353
  }
354
354
 
355
355
  // lib/PackSolver/PackSolver.ts
356
+ import { computeDistanceBetweenBoxes } from "@tscircuit/math-utils";
356
357
  var PackSolver = class extends BaseSolver {
357
358
  packInput;
358
359
  unpackedComponentQueue;
359
360
  packedComponents;
360
361
  lastBestPointsResult;
362
+ lastEvaluatedPositionShadows;
361
363
  constructor(input) {
362
364
  super();
363
365
  this.packInput = input;
@@ -471,6 +473,7 @@ var PackSolver = class extends BaseSolver {
471
473
  bestPoints,
472
474
  distance: smallestDistance
473
475
  };
476
+ this.lastEvaluatedPositionShadows = [];
474
477
  for (const bestPoint of bestPoints) {
475
478
  const networkId = bestPoint.networkId;
476
479
  const newPadsConnectedToNetworkId = newPackedComponent.pads.filter(
@@ -500,13 +503,36 @@ var PackSolver = class extends BaseSolver {
500
503
  const tempComponent = {
501
504
  ...newPackedComponent,
502
505
  center: candidateCenter,
503
- ccwRotationOffset: angle
506
+ ccwRotationOffset: angle,
507
+ pads: transformedPads
504
508
  };
509
+ this.lastEvaluatedPositionShadows?.push(tempComponent);
505
510
  const candBounds = getComponentBounds(tempComponent, 0);
506
- const overlapsWithPackedComponent = this.packedComponents.some((pc) => {
507
- const pcBounds = getComponentBounds(pc, 0);
508
- return candBounds.minX < pcBounds.maxX && candBounds.maxX > pcBounds.minX && candBounds.minY < pcBounds.maxY && candBounds.maxY > pcBounds.minY;
509
- });
511
+ const candBox = {
512
+ center: {
513
+ x: (candBounds.minX + candBounds.maxX) / 2,
514
+ y: (candBounds.minY + candBounds.maxY) / 2
515
+ },
516
+ width: candBounds.maxX - candBounds.minX,
517
+ height: candBounds.maxY - candBounds.minY
518
+ };
519
+ let overlapsWithPackedComponent = false;
520
+ for (const pc of this.packedComponents) {
521
+ for (const pcPad of pc.pads) {
522
+ const distToPad = computeDistanceBetweenBoxes(
523
+ {
524
+ center: pcPad.absoluteCenter,
525
+ width: pcPad.size.x,
526
+ height: pcPad.size.y
527
+ },
528
+ candBox
529
+ ).distance;
530
+ if (distToPad < this.packInput.minGap) {
531
+ overlapsWithPackedComponent = true;
532
+ break;
533
+ }
534
+ }
535
+ }
510
536
  if (overlapsWithPackedComponent) continue;
511
537
  let cost = 0;
512
538
  for (const tp of transformedPads) {
@@ -575,15 +601,35 @@ var PackSolver = class extends BaseSolver {
575
601
  )
576
602
  )
577
603
  );
578
- if (this.lastBestPointsResult) {
579
- for (const bestPoint of this.lastBestPointsResult.bestPoints) {
580
- graphics.points.push({
581
- x: bestPoint.x,
582
- y: bestPoint.y,
583
- label: `bestPoint
604
+ if (!this.solved) {
605
+ for (const shadow of this.lastEvaluatedPositionShadows ?? []) {
606
+ const bounds = getComponentBounds(shadow, 0);
607
+ graphics.rects.push({
608
+ center: shadow.center,
609
+ width: bounds.maxX - bounds.minX,
610
+ height: bounds.maxY - bounds.minY,
611
+ fill: "rgba(0,255,255,0.2)",
612
+ label: (shadow.ccwRotationOffset / Math.PI * 180).toFixed(1)
613
+ });
614
+ for (const shadowPad of shadow.pads) {
615
+ graphics.rects.push({
616
+ center: shadowPad.absoluteCenter,
617
+ width: shadowPad.size.x,
618
+ height: shadowPad.size.y,
619
+ fill: "rgba(0,0,255,0.5)"
620
+ });
621
+ }
622
+ }
623
+ if (this.lastBestPointsResult) {
624
+ for (const bestPoint of this.lastBestPointsResult.bestPoints) {
625
+ graphics.points.push({
626
+ x: bestPoint.x,
627
+ y: bestPoint.y,
628
+ label: `bestPoint
584
629
  networkId: ${bestPoint.networkId}
585
630
  d=${this.lastBestPointsResult.distance}`
586
- });
631
+ });
632
+ }
587
633
  }
588
634
  }
589
635
  return graphics;
package/package.json CHANGED
@@ -2,11 +2,12 @@
2
2
  "name": "calculate-packing",
3
3
  "main": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.0.4",
5
+ "version": "0.0.5",
6
6
  "description": "Calculate a packing layout with support for different strategy configurations",
7
7
  "scripts": {
8
8
  "start": "cosmos",
9
9
  "format": "biome format --write .",
10
+ "format:check": "biome format .",
10
11
  "build": "tsup-node lib/index.ts --format esm --dts --outDir dist",
11
12
  "build:site": "cosmos-export"
12
13
  },