calculate-packing 0.0.21 → 0.0.23
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 +2 -1
- package/dist/index.js +69 -49
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -408,7 +408,7 @@ declare class SingleComponentPackSolver extends BaseSolver {
|
|
|
408
408
|
packedComponents: PackedComponent[];
|
|
409
409
|
packPlacementStrategy: PackPlacementStrategy;
|
|
410
410
|
minGap: number;
|
|
411
|
-
}
|
|
411
|
+
};
|
|
412
412
|
}
|
|
413
413
|
|
|
414
414
|
declare class PackSolver2 extends BaseSolver {
|
|
@@ -418,6 +418,7 @@ declare class PackSolver2 extends BaseSolver {
|
|
|
418
418
|
packedComponents: PackedComponent[];
|
|
419
419
|
componentToPack?: InputComponent | null | undefined;
|
|
420
420
|
constructor(packInput: PackInput);
|
|
421
|
+
getConstructorParams(): PackInput;
|
|
421
422
|
_setup(): void;
|
|
422
423
|
private packFirstComponent;
|
|
423
424
|
_step(): void;
|
package/dist/index.js
CHANGED
|
@@ -195,6 +195,53 @@ function simplifyCollinearSegments(outline, tolerance = 1e-10) {
|
|
|
195
195
|
return simplified;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
// lib/geometry/getComponentBounds.ts
|
|
199
|
+
var getComponentBounds = (component, minGap = 0) => {
|
|
200
|
+
const bounds = {
|
|
201
|
+
minX: Infinity,
|
|
202
|
+
maxX: -Infinity,
|
|
203
|
+
minY: Infinity,
|
|
204
|
+
maxY: -Infinity
|
|
205
|
+
};
|
|
206
|
+
component.pads.forEach((pad) => {
|
|
207
|
+
const hw = pad.size.x / 2;
|
|
208
|
+
const hh = pad.size.y / 2;
|
|
209
|
+
const localCorners = [
|
|
210
|
+
{ x: pad.offset.x - hw, y: pad.offset.y - hh },
|
|
211
|
+
{ x: pad.offset.x + hw, y: pad.offset.y - hh },
|
|
212
|
+
{ x: pad.offset.x + hw, y: pad.offset.y + hh },
|
|
213
|
+
{ x: pad.offset.x - hw, y: pad.offset.y + hh }
|
|
214
|
+
];
|
|
215
|
+
localCorners.forEach((corner) => {
|
|
216
|
+
const world = rotatePoint(
|
|
217
|
+
corner,
|
|
218
|
+
component.ccwRotationOffset * Math.PI / 180
|
|
219
|
+
);
|
|
220
|
+
const x = world.x + component.center.x;
|
|
221
|
+
const y = world.y + component.center.y;
|
|
222
|
+
bounds.minX = Math.min(bounds.minX, x);
|
|
223
|
+
bounds.maxX = Math.max(bounds.maxX, x);
|
|
224
|
+
bounds.minY = Math.min(bounds.minY, y);
|
|
225
|
+
bounds.maxY = Math.max(bounds.maxY, y);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
return {
|
|
229
|
+
minX: bounds.minX - minGap,
|
|
230
|
+
maxX: bounds.maxX + minGap,
|
|
231
|
+
minY: bounds.minY - minGap,
|
|
232
|
+
maxY: bounds.maxY + minGap
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// lib/geometry/combineBounds.ts
|
|
237
|
+
var combineBounds = (bounds) => {
|
|
238
|
+
const minX = Math.min(...bounds.map((b) => b.minX));
|
|
239
|
+
const minY = Math.min(...bounds.map((b) => b.minY));
|
|
240
|
+
const maxX = Math.max(...bounds.map((b) => b.maxX));
|
|
241
|
+
const maxY = Math.max(...bounds.map((b) => b.maxY));
|
|
242
|
+
return { minX, minY, maxX, maxY };
|
|
243
|
+
};
|
|
244
|
+
|
|
198
245
|
// lib/constructOutlinesFromPackedComponents.ts
|
|
199
246
|
var createPadPolygons = (component, minGap) => {
|
|
200
247
|
return component.pads.map((pad) => {
|
|
@@ -222,16 +269,26 @@ var createPadPolygons = (component, minGap) => {
|
|
|
222
269
|
var constructOutlinesFromPackedComponents = (components, opts = {}) => {
|
|
223
270
|
const { minGap = 0 } = opts;
|
|
224
271
|
if (components.length === 0) return [];
|
|
272
|
+
const bounds = combineBounds(
|
|
273
|
+
components.map((c) => getComponentBounds(c, minGap))
|
|
274
|
+
);
|
|
225
275
|
const allPadPolys = [];
|
|
226
276
|
for (const component of components) {
|
|
227
277
|
const padPolys = createPadPolygons(component, minGap);
|
|
228
278
|
allPadPolys.push(...padPolys);
|
|
229
279
|
}
|
|
230
280
|
if (allPadPolys.length === 0) return [];
|
|
231
|
-
let
|
|
232
|
-
|
|
233
|
-
|
|
281
|
+
let A = new Flatten.Polygon(
|
|
282
|
+
new Flatten.Box(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY)
|
|
283
|
+
);
|
|
284
|
+
let B = A.clone();
|
|
285
|
+
for (let i = 0; i < allPadPolys.length; i++) {
|
|
286
|
+
try {
|
|
287
|
+
A = Flatten.BooleanOperations.subtract(A, allPadPolys[i]);
|
|
288
|
+
} catch (e) {
|
|
289
|
+
}
|
|
234
290
|
}
|
|
291
|
+
const union = Flatten.BooleanOperations.subtract(B, A);
|
|
235
292
|
const outlines = [];
|
|
236
293
|
for (const face of union.faces) {
|
|
237
294
|
if (face.isHole) continue;
|
|
@@ -351,44 +408,6 @@ function findOptimalPointOnSegment({
|
|
|
351
408
|
};
|
|
352
409
|
}
|
|
353
410
|
|
|
354
|
-
// lib/geometry/getComponentBounds.ts
|
|
355
|
-
var getComponentBounds = (component, minGap = 0) => {
|
|
356
|
-
const bounds = {
|
|
357
|
-
minX: Infinity,
|
|
358
|
-
maxX: -Infinity,
|
|
359
|
-
minY: Infinity,
|
|
360
|
-
maxY: -Infinity
|
|
361
|
-
};
|
|
362
|
-
component.pads.forEach((pad) => {
|
|
363
|
-
const hw = pad.size.x / 2;
|
|
364
|
-
const hh = pad.size.y / 2;
|
|
365
|
-
const localCorners = [
|
|
366
|
-
{ x: pad.offset.x - hw, y: pad.offset.y - hh },
|
|
367
|
-
{ x: pad.offset.x + hw, y: pad.offset.y - hh },
|
|
368
|
-
{ x: pad.offset.x + hw, y: pad.offset.y + hh },
|
|
369
|
-
{ x: pad.offset.x - hw, y: pad.offset.y + hh }
|
|
370
|
-
];
|
|
371
|
-
localCorners.forEach((corner) => {
|
|
372
|
-
const world = rotatePoint(
|
|
373
|
-
corner,
|
|
374
|
-
component.ccwRotationOffset * Math.PI / 180
|
|
375
|
-
);
|
|
376
|
-
const x = world.x + component.center.x;
|
|
377
|
-
const y = world.y + component.center.y;
|
|
378
|
-
bounds.minX = Math.min(bounds.minX, x);
|
|
379
|
-
bounds.maxX = Math.max(bounds.maxX, x);
|
|
380
|
-
bounds.minY = Math.min(bounds.minY, y);
|
|
381
|
-
bounds.maxY = Math.max(bounds.maxY, y);
|
|
382
|
-
});
|
|
383
|
-
});
|
|
384
|
-
return {
|
|
385
|
-
minX: bounds.minX - minGap,
|
|
386
|
-
maxX: bounds.maxX + minGap,
|
|
387
|
-
minY: bounds.minY - minGap,
|
|
388
|
-
maxY: bounds.maxY + minGap
|
|
389
|
-
};
|
|
390
|
-
};
|
|
391
|
-
|
|
392
411
|
// lib/testing/createColorMapFromStrings.ts
|
|
393
412
|
var createColorMapFromStrings = (strings) => {
|
|
394
413
|
const colorMap = {};
|
|
@@ -2904,14 +2923,12 @@ var SingleComponentPackSolver = class extends BaseSolver {
|
|
|
2904
2923
|
return this.outputPackedComponent;
|
|
2905
2924
|
}
|
|
2906
2925
|
getConstructorParams() {
|
|
2907
|
-
return
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
}
|
|
2914
|
-
];
|
|
2926
|
+
return {
|
|
2927
|
+
componentToPack: this.componentToPack,
|
|
2928
|
+
packedComponents: this.packedComponents,
|
|
2929
|
+
packPlacementStrategy: this.packPlacementStrategy,
|
|
2930
|
+
minGap: this.minGap
|
|
2931
|
+
};
|
|
2915
2932
|
}
|
|
2916
2933
|
};
|
|
2917
2934
|
|
|
@@ -2925,6 +2942,9 @@ var PackSolver2 = class extends BaseSolver {
|
|
|
2925
2942
|
super();
|
|
2926
2943
|
this.packInput = packInput;
|
|
2927
2944
|
}
|
|
2945
|
+
getConstructorParams() {
|
|
2946
|
+
return this.packInput;
|
|
2947
|
+
}
|
|
2928
2948
|
_setup() {
|
|
2929
2949
|
const { components, packOrderStrategy, packFirst = [] } = this.packInput;
|
|
2930
2950
|
this.unpackedComponentQueue = sortComponentQueue({
|
package/package.json
CHANGED