calculate-packing 0.0.65 → 0.0.66

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
@@ -18,6 +18,10 @@ interface InputPad {
18
18
  x: number;
19
19
  y: number;
20
20
  };
21
+ absoluteCenter?: {
22
+ x: number;
23
+ y: number;
24
+ };
21
25
  }
22
26
  interface OutputPad extends InputPad {
23
27
  absoluteCenter: {
@@ -27,10 +31,19 @@ interface OutputPad extends InputPad {
27
31
  }
28
32
  interface InputComponent {
29
33
  componentId: string;
34
+ /** Components marked as static are not moved by the packer */
35
+ isStatic?: boolean;
30
36
  /**
31
37
  * If not provided, the component can be rotated by 0, 90, 180, or 270 degrees.
32
38
  */
33
39
  availableRotationDegrees?: number[];
40
+ /** Preconfigured center for static components */
41
+ center?: {
42
+ x: number;
43
+ y: number;
44
+ };
45
+ /** Preconfigured rotation (degrees CCW) for static components */
46
+ ccwRotationOffset?: number;
34
47
  pads: InputPad[];
35
48
  }
36
49
  interface PackedComponent extends InputComponent {
@@ -109,6 +122,7 @@ declare const convertCircuitJsonToPackOutput: (circuitJson: CircuitJson, opts?:
109
122
  bottom: number;
110
123
  }>;
111
124
  obstacles?: InputObstacle[];
125
+ staticPcbComponentIds?: string[];
112
126
  }) => PackOutput;
113
127
 
114
128
  declare const getGraphicsFromPackOutput: (packOutput: PackOutput) => GraphicsObject;
package/dist/index.js CHANGED
@@ -2041,11 +2041,15 @@ var getGraphicsFromPackOutput = (packOutput) => {
2041
2041
  const bounds = getComponentBounds(component);
2042
2042
  const width = bounds.maxX - bounds.minX;
2043
2043
  const height = bounds.maxY - bounds.minY;
2044
+ const isStatic = Boolean(component.isStatic);
2045
+ const staticFill = "rgba(33, 150, 243, 0.25)";
2046
+ const staticStroke = "rgba(33, 150, 243, 0.6)";
2044
2047
  const rect = {
2045
2048
  center: { x: component.center.x, y: component.center.y },
2046
2049
  width,
2047
2050
  height,
2048
- fill: "rgba(0,0,0,0.25)",
2051
+ fill: isStatic ? staticFill : "rgba(0,0,0,0.25)",
2052
+ stroke: isStatic ? staticStroke : void 0,
2049
2053
  label: [
2050
2054
  component.componentId,
2051
2055
  `ccwRotationOffset: ${component.ccwRotationOffset.toFixed(1)}\xB0`
@@ -2728,12 +2732,30 @@ var PackSolver2 = class extends BaseSolver5 {
2728
2732
  (pad) => Number.isFinite(pad.size.x) && Number.isFinite(pad.size.y) && pad.size.x > 0 && pad.size.y > 0
2729
2733
  );
2730
2734
  });
2735
+ const staticComponents = validComponents.filter(
2736
+ (component) => component.isStatic
2737
+ );
2738
+ const dynamicComponents = validComponents.filter(
2739
+ (component) => !component.isStatic
2740
+ );
2741
+ this.packedComponents = staticComponents.map((component) => {
2742
+ const packedComponent = {
2743
+ ...component,
2744
+ center: component.center ?? { x: 0, y: 0 },
2745
+ ccwRotationOffset: component.ccwRotationOffset ?? 0,
2746
+ pads: component.pads.map((pad) => ({
2747
+ ...pad,
2748
+ absoluteCenter: pad.absoluteCenter ?? { x: 0, y: 0 }
2749
+ }))
2750
+ };
2751
+ setPackedComponentPadCenters(packedComponent);
2752
+ return packedComponent;
2753
+ });
2731
2754
  this.unpackedComponentQueue = sortComponentQueue({
2732
- components: validComponents,
2755
+ components: dynamicComponents,
2733
2756
  packOrderStrategy,
2734
2757
  packFirst
2735
2758
  });
2736
- this.packedComponents = [];
2737
2759
  }
2738
2760
  packFirstComponent() {
2739
2761
  const firstComponentToPack = this.unpackedComponentQueue.shift();
@@ -3151,7 +3173,7 @@ var getElementOutsideTree = (db, tree) => {
3151
3173
  };
3152
3174
 
3153
3175
  // lib/plumbing/convertCircuitJsonToPackOutput.ts
3154
- var buildPackedComponent = (pcbComponents, componentId, db, getNetworkId, shouldAddInnerObstacles, sourcePortToPadIds = /* @__PURE__ */ new Map(), chipMarginsMap = {}) => {
3176
+ var buildPackedComponent = (pcbComponents, componentId, db, getNetworkId, shouldAddInnerObstacles, sourcePortToPadIds = /* @__PURE__ */ new Map(), chipMarginsMap = {}, isStatic = false) => {
3155
3177
  const padInfos = pcbComponents.flatMap((pc) => {
3156
3178
  const pads2 = extractPadInfos(pc, db, getNetworkId);
3157
3179
  const margins = chipMarginsMap[pc.pcb_component_id];
@@ -3211,6 +3233,7 @@ var buildPackedComponent = (pcbComponents, componentId, db, getNetworkId, should
3211
3233
  }
3212
3234
  return {
3213
3235
  componentId,
3236
+ isStatic,
3214
3237
  center,
3215
3238
  ccwRotationOffset: 0,
3216
3239
  pads
@@ -3272,6 +3295,7 @@ var convertCircuitJsonToPackOutput = (circuitJson, opts = {}) => {
3272
3295
  }
3273
3296
  return relativeComponents2;
3274
3297
  };
3298
+ const staticComponentIds = new Set(opts.staticPcbComponentIds ?? []);
3275
3299
  for (const node of topLevelNodes) {
3276
3300
  if (node.nodeType === "component") {
3277
3301
  const pcbComponent = node.otherChildElements.find(
@@ -3293,7 +3317,8 @@ var convertCircuitJsonToPackOutput = (circuitJson, opts = {}) => {
3293
3317
  getNetworkId,
3294
3318
  shouldAddInnerObstaclesForComp,
3295
3319
  sourcePortToPadIds,
3296
- opts.chipMarginsMap
3320
+ opts.chipMarginsMap,
3321
+ staticComponentIds.has(pcbComponent.pcb_component_id)
3297
3322
  )
3298
3323
  );
3299
3324
  } else if (node.nodeType === "group") {
@@ -3308,7 +3333,8 @@ var convertCircuitJsonToPackOutput = (circuitJson, opts = {}) => {
3308
3333
  getNetworkId,
3309
3334
  void 0,
3310
3335
  sourcePortToPadIds,
3311
- opts.chipMarginsMap
3336
+ opts.chipMarginsMap,
3337
+ staticComponentIds.has(compId)
3312
3338
  )
3313
3339
  );
3314
3340
  }
@@ -3383,10 +3409,15 @@ var convertCircuitJsonToPackOutput = (circuitJson, opts = {}) => {
3383
3409
  // lib/plumbing/convertPackOutputToPackInput.ts
3384
3410
  var convertPackOutputToPackInput = (packed) => {
3385
3411
  const strippedComponents = packed.components.map((pc) => ({
3386
- componentId: pc.componentId,
3387
- availableRotationDegrees: pc.availableRotationDegrees,
3388
- // Preserve rotation constraints
3389
- pads: pc.pads.map(({ absoluteCenter: _ac, ...rest }) => rest)
3412
+ ...pc.isStatic ? {
3413
+ ...pc,
3414
+ pads: pc.pads.map((pad) => ({ ...pad }))
3415
+ } : {
3416
+ componentId: pc.componentId,
3417
+ availableRotationDegrees: pc.availableRotationDegrees,
3418
+ // Preserve rotation constraints
3419
+ pads: pc.pads.map(({ absoluteCenter: _ac, ...rest }) => rest)
3420
+ }
3390
3421
  }));
3391
3422
  return {
3392
3423
  ...packed,
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.65",
5
+ "version": "0.0.66",
6
6
  "description": "Calculate a packing layout with support for different strategy configurations",
7
7
  "scripts": {
8
8
  "start": "cosmos",