@tscircuit/matchpack 0.0.19 → 0.0.21

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
@@ -244,6 +244,8 @@ declare class PartitionPackingSolver extends BaseSolver {
244
244
  private organizePackedPartitions;
245
245
  private createPackInput;
246
246
  private applyPackingResult;
247
+ private getCombinedPackedPartitionsProblem;
248
+ private getCombinedPackedPartitionsLayout;
247
249
  visualize(): GraphicsObject;
248
250
  getConstructorParams(): PartitionPackingSolverInput;
249
251
  }
package/dist/index.js CHANGED
@@ -99,6 +99,20 @@ function getChipLabelFontSize(width, height) {
99
99
  const smallerDimension = Math.min(width, height);
100
100
  return Math.min(0.35, Math.max(0.08, smallerDimension * 0.22));
101
101
  }
102
+ function getChipFillColor(chipId, isFixed = false) {
103
+ const chipType = chipId.charAt(0).toUpperCase();
104
+ if (isFixed) {
105
+ if (chipType === "C") return "rgba(30, 64, 175, 0.35)";
106
+ if (chipType === "R") return "rgba(5, 150, 105, 0.35)";
107
+ if (chipType === "L") return "rgba(126, 34, 206, 0.35)";
108
+ if (chipType === "U") return "rgba(180, 83, 9, 0.35)";
109
+ }
110
+ if (chipType === "C") return "rgba(59, 130, 246, 0.18)";
111
+ if (chipType === "R") return "rgba(16, 185, 129, 0.18)";
112
+ if (chipType === "L") return "rgba(168, 85, 247, 0.18)";
113
+ if (chipType === "U") return "rgba(245, 158, 11, 0.18)";
114
+ return "rgba(59, 130, 246, 0.12)";
115
+ }
102
116
  function visualizeInputProblem(inputProblem, basicLayout) {
103
117
  const inputViz = {
104
118
  points: [],
@@ -138,18 +152,19 @@ function visualizeInputProblem(inputProblem, basicLayout) {
138
152
  height,
139
153
  placement.ccwRotationDegrees
140
154
  );
155
+ const chipLabel = chip.fixedPosition ? `${chipId} [fixed]` : chipId;
141
156
  inputViz.rects.push({
142
157
  center: { x: chipCenterX, y: chipCenterY },
143
158
  width: rotatedDims.width,
144
159
  height: rotatedDims.height,
145
- label: chipId,
146
- fill: "rgba(59, 130, 246, 0.12)",
160
+ label: chipLabel,
161
+ fill: getChipFillColor(chipId, Boolean(chip.fixedPosition)),
147
162
  stroke: "none"
148
163
  });
149
164
  inputViz.texts.push({
150
165
  x: chipCenterX,
151
166
  y: chipCenterY,
152
- text: chipId,
167
+ text: chipLabel,
153
168
  fontSize: getChipLabelFontSize(rotatedDims.width, rotatedDims.height)
154
169
  });
155
170
  for (const pin of chipPins) {
@@ -295,9 +310,16 @@ function doBasicInputProblemLayout(inputProblem) {
295
310
  offset: { x: 0, y: 0 },
296
311
  size: { x: chip.size.x, y: chip.size.y }
297
312
  });
313
+ const fixedRotation = chip.availableRotations?.[0] ?? 0;
298
314
  return {
299
315
  componentId: chipId,
300
- pads
316
+ pads,
317
+ availableRotationDegrees: chip.availableRotations ?? [0, 90, 180, 270],
318
+ ...chip.fixedPosition && {
319
+ isStatic: true,
320
+ center: chip.fixedPosition,
321
+ ccwRotationOffset: fixedRotation
322
+ }
301
323
  };
302
324
  }
303
325
  );
@@ -500,7 +522,8 @@ var ChipPartitionsSolver = class extends BaseSolver {
500
522
  }
501
523
  visualize() {
502
524
  if (this.partitions.length === 0) {
503
- return super.visualize();
525
+ const layout = doBasicInputProblemLayout(this.inputProblem);
526
+ return visualizeInputProblem(this.inputProblem, layout);
504
527
  }
505
528
  const partitionVisualizations = this.partitions.map((partition) => {
506
529
  const layout = doBasicInputProblemLayout(partition);
@@ -995,7 +1018,12 @@ var PackInnerPartitionsSolver = class extends BaseSolver {
995
1018
  return this.activeSolver.visualize();
996
1019
  }
997
1020
  if (this.completedSolvers.length === 0) {
998
- return super.visualize();
1021
+ const partitionVisualizations2 = this.partitions.map((partition) => {
1022
+ const layout = doBasicInputProblemLayout(partition);
1023
+ return visualizeInputProblem(partition, layout);
1024
+ });
1025
+ const titles2 = this.partitions.map((_, index) => `partition${index}`);
1026
+ return stackGraphicsHorizontally2(partitionVisualizations2, { titles: titles2 });
999
1027
  }
1000
1028
  const partitionVisualizations = this.completedSolvers.map(
1001
1029
  (solver) => solver.visualize()
@@ -1237,13 +1265,7 @@ var PartitionPackingSolver = class extends BaseSolver {
1237
1265
  groupPlacements: {}
1238
1266
  };
1239
1267
  }
1240
- visualize() {
1241
- if (this.packSolver2 && !this.solved) {
1242
- return this.packSolver2.visualize();
1243
- }
1244
- if (!this.finalLayout) {
1245
- return super.visualize();
1246
- }
1268
+ getCombinedPackedPartitionsProblem() {
1247
1269
  const combinedProblem = {
1248
1270
  chipMap: {},
1249
1271
  chipPinMap: {},
@@ -1272,7 +1294,35 @@ var PartitionPackingSolver = class extends BaseSolver {
1272
1294
  packedPartition.inputProblem.netConnMap
1273
1295
  );
1274
1296
  }
1275
- return visualizeInputProblem(combinedProblem, this.finalLayout);
1297
+ return combinedProblem;
1298
+ }
1299
+ getCombinedPackedPartitionsLayout() {
1300
+ const chipPlacements = {};
1301
+ for (const packedPartition of this.packedPartitions) {
1302
+ Object.assign(chipPlacements, packedPartition.layout.chipPlacements);
1303
+ }
1304
+ return {
1305
+ chipPlacements,
1306
+ groupPlacements: {}
1307
+ };
1308
+ }
1309
+ visualize() {
1310
+ if (this.packSolver2 && !this.solved) {
1311
+ return this.packSolver2.visualize();
1312
+ }
1313
+ if (!this.finalLayout) {
1314
+ if (this.packedPartitions.length === 0) {
1315
+ return super.visualize();
1316
+ }
1317
+ return visualizeInputProblem(
1318
+ this.getCombinedPackedPartitionsProblem(),
1319
+ this.getCombinedPackedPartitionsLayout()
1320
+ );
1321
+ }
1322
+ return visualizeInputProblem(
1323
+ this.getCombinedPackedPartitionsProblem(),
1324
+ this.finalLayout
1325
+ );
1276
1326
  }
1277
1327
  getConstructorParams() {
1278
1328
  return {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tscircuit/matchpack",
3
3
  "main": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.0.19",
5
+ "version": "0.0.21",
6
6
  "files": [
7
7
  "dist"
8
8
  ],