calculate-packing 0.0.42 → 0.0.44

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
@@ -62,6 +62,10 @@ interface PackInput {
62
62
  maxX: number;
63
63
  maxY: number;
64
64
  };
65
+ boundaryOutline?: Array<{
66
+ x: number;
67
+ y: number;
68
+ }>;
65
69
  minGap: number;
66
70
  packOrderStrategy: "largest_to_smallest";
67
71
  packPlacementStrategy: PackPlacementStrategy;
@@ -359,6 +363,10 @@ declare class OutlineSegmentCandidatePointSolver extends BaseSolver {
359
363
  componentToPack: InputComponent;
360
364
  viableBounds?: Bounds;
361
365
  globalBounds?: Bounds;
366
+ boundaryOutline?: Array<{
367
+ x: number;
368
+ y: number;
369
+ }>;
362
370
  optimalPosition?: Point$2;
363
371
  irlsSolver?: MultiOffsetIrlsSolver;
364
372
  twoPhaseIrlsSolver?: TwoPhaseIrlsSolver;
@@ -372,6 +380,10 @@ declare class OutlineSegmentCandidatePointSolver extends BaseSolver {
372
380
  componentToPack: InputComponent;
373
381
  obstacles?: InputObstacle[];
374
382
  globalBounds?: Bounds;
383
+ boundaryOutline?: Array<{
384
+ x: number;
385
+ y: number;
386
+ }>;
375
387
  });
376
388
  getConstructorParams(): ConstructorParameters<typeof OutlineSegmentCandidatePointSolver>[0];
377
389
  _getOutlineBoundsWithMargin(params?: {
@@ -436,6 +448,10 @@ declare class SingleComponentPackSolver extends BaseSolver {
436
448
  packPlacementStrategy: PackPlacementStrategy;
437
449
  minGap: number;
438
450
  obstacles: InputObstacle[];
451
+ boundaryOutline?: Array<{
452
+ x: number;
453
+ y: number;
454
+ }>;
439
455
  currentPhase: Phase;
440
456
  outlines: Segment[][];
441
457
  queuedOutlineSegments: QueuedOutlineSegment[];
@@ -456,6 +472,10 @@ declare class SingleComponentPackSolver extends BaseSolver {
456
472
  minGap?: number;
457
473
  obstacles?: InputObstacle[];
458
474
  bounds?: Bounds;
475
+ boundaryOutline?: Array<{
476
+ x: number;
477
+ y: number;
478
+ }>;
459
479
  });
460
480
  _setup(): void;
461
481
  _step(): void;
@@ -476,6 +496,10 @@ declare class SingleComponentPackSolver extends BaseSolver {
476
496
  minGap: number;
477
497
  obstacles: InputObstacle[];
478
498
  bounds: Bounds | undefined;
499
+ boundaryOutline: {
500
+ x: number;
501
+ y: number;
502
+ }[] | undefined;
479
503
  };
480
504
  }
481
505
 
package/dist/index.js CHANGED
@@ -1417,6 +1417,7 @@ var OutlineSegmentCandidatePointSolver = class extends BaseSolver {
1417
1417
  componentToPack;
1418
1418
  viableBounds;
1419
1419
  globalBounds;
1420
+ boundaryOutline;
1420
1421
  optimalPosition;
1421
1422
  irlsSolver;
1422
1423
  twoPhaseIrlsSolver;
@@ -1431,6 +1432,7 @@ var OutlineSegmentCandidatePointSolver = class extends BaseSolver {
1431
1432
  this.componentToPack = params.componentToPack;
1432
1433
  this.obstacles = params.obstacles ?? [];
1433
1434
  this.globalBounds = params.globalBounds;
1435
+ this.boundaryOutline = params.boundaryOutline;
1434
1436
  }
1435
1437
  getConstructorParams() {
1436
1438
  return {
@@ -1442,7 +1444,8 @@ var OutlineSegmentCandidatePointSolver = class extends BaseSolver {
1442
1444
  packedComponents: this.packedComponents,
1443
1445
  componentToPack: this.componentToPack,
1444
1446
  obstacles: this.obstacles,
1445
- globalBounds: this.globalBounds
1447
+ globalBounds: this.globalBounds,
1448
+ boundaryOutline: this.boundaryOutline
1446
1449
  };
1447
1450
  }
1448
1451
  _getOutlineBoundsWithMargin(params = {}) {
@@ -1747,6 +1750,17 @@ var OutlineSegmentCandidatePointSolver = class extends BaseSolver {
1747
1750
  strokeDash: "2 2"
1748
1751
  });
1749
1752
  }
1753
+ if (this.boundaryOutline && this.boundaryOutline.length) {
1754
+ const outlinePoints = [...this.boundaryOutline];
1755
+ if (outlinePoints.length > 0 && (outlinePoints[0].x !== outlinePoints[outlinePoints.length - 1].x || outlinePoints[0].y !== outlinePoints[outlinePoints.length - 1].y)) {
1756
+ outlinePoints.push({ ...outlinePoints[0] });
1757
+ }
1758
+ graphics.lines.push({
1759
+ points: outlinePoints,
1760
+ strokeColor: "rgba(0, 0, 255, 0.5)",
1761
+ strokeDash: "4 2"
1762
+ });
1763
+ }
1750
1764
  if (this.viableBounds) {
1751
1765
  graphics.rects.push({
1752
1766
  center: {
@@ -1856,6 +1870,17 @@ var OutlineSegmentCandidatePointSolver = class extends BaseSolver {
1856
1870
  var getGraphicsFromPackOutput = (packOutput) => {
1857
1871
  const rects = [];
1858
1872
  const lines = [];
1873
+ if (packOutput.boundaryOutline && packOutput.boundaryOutline.length) {
1874
+ const outlinePoints = [...packOutput.boundaryOutline];
1875
+ if (outlinePoints.length > 0 && (outlinePoints[0].x !== outlinePoints[outlinePoints.length - 1].x || outlinePoints[0].y !== outlinePoints[outlinePoints.length - 1].y)) {
1876
+ outlinePoints.push({ ...outlinePoints[0] });
1877
+ }
1878
+ lines.push({
1879
+ points: outlinePoints,
1880
+ strokeColor: "rgba(0, 0, 255, 0.5)",
1881
+ strokeDash: "4 2"
1882
+ });
1883
+ }
1859
1884
  const allNetworkIds = Array.from(
1860
1885
  new Set(
1861
1886
  packOutput.components.flatMap((c) => c.pads.map((p) => p.networkId))
@@ -1967,6 +1992,7 @@ var SingleComponentPackSolver = class extends BaseSolver {
1967
1992
  packPlacementStrategy;
1968
1993
  minGap;
1969
1994
  obstacles;
1995
+ boundaryOutline;
1970
1996
  // Phase management
1971
1997
  currentPhase = "outline";
1972
1998
  outlines = [];
@@ -1987,6 +2013,7 @@ var SingleComponentPackSolver = class extends BaseSolver {
1987
2013
  this.minGap = params.minGap ?? 0;
1988
2014
  this.obstacles = params.obstacles ?? [];
1989
2015
  this.bounds = params.bounds;
2016
+ this.boundaryOutline = params.boundaryOutline;
1990
2017
  }
1991
2018
  _setup() {
1992
2019
  super._setup();
@@ -2157,7 +2184,8 @@ var SingleComponentPackSolver = class extends BaseSolver {
2157
2184
  packedComponents: this.packedComponents,
2158
2185
  componentToPack: this.componentToPack,
2159
2186
  obstacles: this.obstacles,
2160
- globalBounds: this.bounds
2187
+ globalBounds: this.bounds,
2188
+ boundaryOutline: this.boundaryOutline
2161
2189
  });
2162
2190
  this.activeSubSolver.setup();
2163
2191
  break;
@@ -2256,6 +2284,17 @@ var SingleComponentPackSolver = class extends BaseSolver {
2256
2284
  strokeDash: "2 2"
2257
2285
  });
2258
2286
  }
2287
+ if (this.boundaryOutline && this.boundaryOutline.length) {
2288
+ const outlinePoints = [...this.boundaryOutline];
2289
+ if (outlinePoints.length > 0 && (outlinePoints[0].x !== outlinePoints[outlinePoints.length - 1].x || outlinePoints[0].y !== outlinePoints[outlinePoints.length - 1].y)) {
2290
+ outlinePoints.push({ ...outlinePoints[0] });
2291
+ }
2292
+ graphics.lines.push({
2293
+ points: outlinePoints,
2294
+ strokeColor: "rgba(0, 0, 255, 0.5)",
2295
+ strokeDash: "4 2"
2296
+ });
2297
+ }
2259
2298
  switch (this.currentPhase) {
2260
2299
  case "outline":
2261
2300
  this.visualizeOutlinePhase(graphics);
@@ -2363,7 +2402,8 @@ gap_distance=${candidate.gapDistance}`,
2363
2402
  packPlacementStrategy: this.packPlacementStrategy,
2364
2403
  minGap: this.minGap,
2365
2404
  obstacles: this.obstacles,
2366
- bounds: this.bounds
2405
+ bounds: this.bounds,
2406
+ boundaryOutline: this.boundaryOutline
2367
2407
  };
2368
2408
  }
2369
2409
  };
@@ -2430,7 +2470,8 @@ var PackSolver2 = class extends BaseSolver {
2430
2470
  packPlacementStrategy: this.packInput.packPlacementStrategy,
2431
2471
  minGap: this.packInput.minGap,
2432
2472
  obstacles,
2433
- bounds: this.packInput.bounds
2473
+ bounds: this.packInput.bounds,
2474
+ boundaryOutline: this.packInput.boundaryOutline
2434
2475
  });
2435
2476
  fallbackSolver.solve();
2436
2477
  const result = fallbackSolver.getResult();
@@ -2466,7 +2507,8 @@ var PackSolver2 = class extends BaseSolver {
2466
2507
  packPlacementStrategy: this.packInput.packPlacementStrategy,
2467
2508
  minGap: this.packInput.minGap,
2468
2509
  obstacles: this.packInput.obstacles ?? [],
2469
- bounds: this.packInput.bounds
2510
+ bounds: this.packInput.bounds,
2511
+ boundaryOutline: this.packInput.boundaryOutline
2470
2512
  });
2471
2513
  this.activeSubSolver.setup();
2472
2514
  }
@@ -2534,6 +2576,17 @@ var PackSolver2 = class extends BaseSolver {
2534
2576
  strokeDash: "2 2"
2535
2577
  });
2536
2578
  }
2579
+ if (this.packInput.boundaryOutline && this.packInput.boundaryOutline.length) {
2580
+ const points = [...this.packInput.boundaryOutline];
2581
+ if (points.length > 0 && (points[0].x !== points[points.length - 1].x || points[0].y !== points[points.length - 1].y)) {
2582
+ points.push({ ...points[0] });
2583
+ }
2584
+ graphics.lines.push({
2585
+ points,
2586
+ strokeColor: "rgba(0, 0, 255, 0.5)",
2587
+ strokeDash: "4 2"
2588
+ });
2589
+ }
2537
2590
  if (this.packedComponents.length === 0) {
2538
2591
  for (const component of this.unpackedComponentQueue) {
2539
2592
  for (const pad of component.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.42",
5
+ "version": "0.0.44",
6
6
  "description": "Calculate a packing layout with support for different strategy configurations",
7
7
  "scripts": {
8
8
  "start": "cosmos",