calculate-packing 0.0.52 → 0.0.54

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.
Files changed (2) hide show
  1. package/dist/index.js +33 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2843,6 +2843,18 @@ var pack = (input) => {
2843
2843
  import { cju, getCircuitJsonTree } from "@tscircuit/circuit-json-util";
2844
2844
 
2845
2845
  // lib/plumbing/extractPadInfos.ts
2846
+ var getPolygonBoundingBox = (points) => {
2847
+ if (!points || points.length === 0)
2848
+ return { minX: 0, maxX: 0, minY: 0, maxY: 0 };
2849
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
2850
+ for (const point of points) {
2851
+ minX = Math.min(minX, point.x);
2852
+ maxX = Math.max(maxX, point.x);
2853
+ minY = Math.min(minY, point.y);
2854
+ maxY = Math.max(maxY, point.y);
2855
+ }
2856
+ return { minX, maxX, minY, maxY };
2857
+ };
2846
2858
  var extractPadInfos = (pcbComponent, db, getNetworkId) => {
2847
2859
  const out = [];
2848
2860
  const pushPad = ({
@@ -2942,28 +2954,32 @@ var extractPadInfos = (pcbComponent, db, getNetworkId) => {
2942
2954
  pushPad({
2943
2955
  padId: sp.pcb_smtpad_id,
2944
2956
  pcbPortId: sp.pcb_port_id,
2945
- sx: sp.radius ?? 0,
2946
- sy: sp.radius ?? 0,
2957
+ sx: sp.radius * 2,
2958
+ // Convert radius to diameter for width/height
2959
+ sy: sp.radius * 2,
2947
2960
  x: sp.x,
2948
2961
  y: sp.y
2949
2962
  });
2950
2963
  break;
2951
2964
  }
2952
- case "pill": {
2953
- pushPad({
2954
- padId: sp.pcb_smtpad_id,
2955
- pcbPortId: sp.pcb_port_id,
2956
- sx: sp.width ?? 0,
2957
- sy: sp.height ?? 0,
2958
- x: sp.x,
2959
- y: sp.y
2960
- });
2961
- break;
2962
- }
2963
- default: {
2964
- console.warn(
2965
- `smtpad shape ${sp.shape} pads are not supported in pack layout yet`
2966
- );
2965
+ case "polygon": {
2966
+ if (sp.points && sp.points.length > 0) {
2967
+ const { minX, maxX, minY, maxY } = getPolygonBoundingBox(sp.points);
2968
+ const width = maxX - minX;
2969
+ const height = maxY - minY;
2970
+ const centerX = (minX + maxX) / 2;
2971
+ const centerY = (minY + maxY) / 2;
2972
+ pushPad({
2973
+ padId: sp.pcb_smtpad_id,
2974
+ pcbPortId: sp.pcb_port_id,
2975
+ sx: width,
2976
+ sy: height,
2977
+ x: centerX,
2978
+ y: centerY
2979
+ });
2980
+ } else {
2981
+ console.warn(`Polygon pad ${sp.pcb_smtpad_id} has no points`);
2982
+ }
2967
2983
  break;
2968
2984
  }
2969
2985
  }
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.52",
5
+ "version": "0.0.54",
6
6
  "description": "Calculate a packing layout with support for different strategy configurations",
7
7
  "scripts": {
8
8
  "start": "cosmos",