calculate-packing 0.0.17 → 0.0.19

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
@@ -36,8 +36,10 @@ interface PackedComponent extends InputComponent {
36
36
  x: number;
37
37
  y: number;
38
38
  };
39
- /** Rotation in degrees (counterclockwise) */
39
+ /** @deprecated Rotation in degrees (counterclockwise) */
40
40
  ccwRotationOffset: number;
41
+ /** Rotation in degrees (counterclockwise) - output field */
42
+ ccwRotationDegrees?: number;
41
43
  pads: OutputPad[];
42
44
  }
43
45
  interface PackInput {
package/dist/index.js CHANGED
@@ -132,6 +132,69 @@ var rotatePoint = (point, angle, origin = { x: 0, y: 0 }) => {
132
132
  };
133
133
  };
134
134
 
135
+ // lib/math/cross.ts
136
+ var cross = (O, A, B) => (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
137
+
138
+ // lib/geometry/simplify-collinear-segments.ts
139
+ function simplifyCollinearSegments(outline, tolerance = 1e-10) {
140
+ if (outline.length <= 1) {
141
+ return outline;
142
+ }
143
+ const simplified = [];
144
+ let currentSegmentStart = outline[0][0];
145
+ let currentSegmentEnd = outline[0][1];
146
+ for (let i = 1; i < outline.length; i++) {
147
+ const nextSegment = outline[i];
148
+ const [nextStart, nextEnd] = nextSegment;
149
+ const connectionTolerance = 1e-10;
150
+ const isConnected = Math.abs(currentSegmentEnd.x - nextStart.x) < connectionTolerance && Math.abs(currentSegmentEnd.y - nextStart.y) < connectionTolerance;
151
+ if (!isConnected) {
152
+ simplified.push([currentSegmentStart, currentSegmentEnd]);
153
+ currentSegmentStart = nextStart;
154
+ currentSegmentEnd = nextEnd;
155
+ continue;
156
+ }
157
+ const crossProduct = cross(currentSegmentStart, currentSegmentEnd, nextEnd);
158
+ if (Math.abs(crossProduct) < tolerance) {
159
+ currentSegmentEnd = nextEnd;
160
+ } else {
161
+ simplified.push([currentSegmentStart, currentSegmentEnd]);
162
+ currentSegmentStart = nextStart;
163
+ currentSegmentEnd = nextEnd;
164
+ }
165
+ }
166
+ if (outline.length > 2) {
167
+ const firstSegment = simplified[0];
168
+ const lastSegmentCandidate = [
169
+ currentSegmentStart,
170
+ currentSegmentEnd
171
+ ];
172
+ if (firstSegment && simplified.length > 0) {
173
+ const connectionTolerance = 1e-10;
174
+ const isLastConnectedToFirst = Math.abs(currentSegmentEnd.x - firstSegment[0].x) < connectionTolerance && Math.abs(currentSegmentEnd.y - firstSegment[0].y) < connectionTolerance;
175
+ if (isLastConnectedToFirst) {
176
+ const crossProduct = cross(
177
+ currentSegmentStart,
178
+ currentSegmentEnd,
179
+ firstSegment[1]
180
+ );
181
+ if (Math.abs(crossProduct) < tolerance) {
182
+ simplified[0] = [currentSegmentStart, firstSegment[1]];
183
+ } else {
184
+ simplified.push(lastSegmentCandidate);
185
+ }
186
+ } else {
187
+ simplified.push(lastSegmentCandidate);
188
+ }
189
+ } else {
190
+ simplified.push(lastSegmentCandidate);
191
+ }
192
+ } else {
193
+ simplified.push([currentSegmentStart, currentSegmentEnd]);
194
+ }
195
+ return simplified;
196
+ }
197
+
135
198
  // lib/constructOutlinesFromPackedComponents.ts
136
199
  var createPadPolygons = (component, minGap) => {
137
200
  return component.pads.map((pad) => {
@@ -185,7 +248,8 @@ var constructOutlinesFromPackedComponents = (components, opts = {}) => {
185
248
  ]);
186
249
  edge = edge.next;
187
250
  } while (edge !== face.first);
188
- outlines.push(outline);
251
+ const simplifiedOutline = simplifyCollinearSegments(outline);
252
+ outlines.push(simplifiedOutline);
189
253
  }
190
254
  return outlines;
191
255
  };
@@ -1318,7 +1382,10 @@ var PhasedPackSolver = class extends BaseSolver {
1318
1382
  return [this.packInput];
1319
1383
  }
1320
1384
  getResult() {
1321
- return this.packedComponents;
1385
+ return this.packedComponents.map((component) => ({
1386
+ ...component,
1387
+ ccwRotationDegrees: component.ccwRotationOffset
1388
+ }));
1322
1389
  }
1323
1390
  /* ---------- small helpers ------------------------------------------------ */
1324
1391
  getCandidateAngles(c) {
@@ -1339,7 +1406,7 @@ var pack = (input) => {
1339
1406
  solver.solve();
1340
1407
  return {
1341
1408
  ...input,
1342
- components: solver.packedComponents
1409
+ components: solver.getResult()
1343
1410
  };
1344
1411
  };
1345
1412
 
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.17",
5
+ "version": "0.0.19",
6
6
  "description": "Calculate a packing layout with support for different strategy configurations",
7
7
  "scripts": {
8
8
  "start": "cosmos",
@@ -34,7 +34,7 @@
34
34
  "react-dom": "^19.1.0",
35
35
  "tscircuit": "^0.0.562",
36
36
  "tsup": "^8.5.0",
37
- "vite": "^7.0.5"
37
+ "vite": "^7.1.2"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "typescript": "^5",