@flighthq/binpack 0.5.1-next.920.da8f530 → 0.7.0-edge.5213.ead804b
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/README.md +2 -2
- package/dist/contract.d.ts +4 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +2 -2
- package/dist/contract.js.map +1 -1
- package/dist/explainUnpackedRectangles.d.ts +30 -2
- package/dist/explainUnpackedRectangles.d.ts.map +1 -1
- package/dist/explainUnpackedRectangles.js +73 -40
- package/dist/explainUnpackedRectangles.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/packRectangles.d.ts +89 -3
- package/dist/packRectangles.d.ts.map +1 -1
- package/dist/packRectangles.js +308 -212
- package/dist/packRectangles.js.map +1 -1
- package/package.json +5 -4
- package/src/explainUnpackedRectangles.test.ts +275 -98
- package/src/packRectangles.test.ts +510 -239
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/binpack`. The `@flig
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/binpack@0.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/binpack@0.7.0-edge.5213.ead804b](https://github.com/flighthq/flight/tree/ead804bfaef3e691a2e6e43e9711ddd3fd8a84a2/packages/binpack)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/ead804bfaef3e691a2e6e43e9711ddd3fd8a84a2/LICENSE.md)
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { explainUnpackedRectangles, getUnpackedRectangleReasonString, parseUnpackedRectangleReason, } from './explainUnpackedRectangles.ts';
|
|
2
|
+
export type { UnpackedRectangleExplanation, UnpackedRectangleReason } from './explainUnpackedRectangles.ts';
|
|
3
|
+
export { BIN_PACK_DEFAULT_MAX_EXTENT, getBinPackHeuristicString, getPackResultOccupancy, packRectangles, parseBinPackHeuristic, } from './packRectangles.ts';
|
|
4
|
+
export type { BinPackHeuristic, BinPackOptions, PackResult, PackableRectangle, PackedRectangle, RectangleId, } from './packRectangles.ts';
|
|
3
5
|
//# sourceMappingURL=contract.d.ts.map
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EAChC,4BAA4B,GAC7B,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAC5G,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,sBAAsB,EACtB,cAAc,EACd,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,eAAe,EACf,WAAW,GACZ,MAAM,qBAAqB,CAAC"}
|
package/dist/contract.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { explainUnpackedRectangles, getUnpackedRectangleReasonString, parseUnpackedRectangleReason, } from './explainUnpackedRectangles.js';
|
|
2
|
+
export { BIN_PACK_DEFAULT_MAX_EXTENT, getBinPackHeuristicString, getPackResultOccupancy, packRectangles, parseBinPackHeuristic, } from './packRectangles.js';
|
|
3
3
|
//# sourceMappingURL=contract.js.map
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EAChC,4BAA4B,GAC7B,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,sBAAsB,EACtB,cAAc,EACd,qBAAqB,GACtB,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
import type { BinPackOptions, PackableRectangle,
|
|
2
|
-
|
|
1
|
+
import type { BinPackOptions, PackableRectangle, RectangleId } from './packRectangles.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The reason a rectangle could not be placed.
|
|
4
|
+
*/
|
|
5
|
+
export type UnpackedRectangleReason = 'oversized' | 'regionCollapsed' | 'binExhausted';
|
|
6
|
+
/**
|
|
7
|
+
* An explanation of why a single rectangle was not placed.
|
|
8
|
+
*/
|
|
9
|
+
export interface UnpackedRectangleExplanation {
|
|
10
|
+
readonly id: RectangleId;
|
|
11
|
+
readonly reason: UnpackedRectangleReason;
|
|
12
|
+
readonly usableWidth: number;
|
|
13
|
+
readonly usableHeight: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Says WHY each unplaced rectangle did not fit. `packRectangles` reports `unpacked` as bare ids,
|
|
17
|
+
* which is the right shape for the hot path but tells a caller nothing about the remedy -- and the
|
|
18
|
+
* three causes have three different ones: raise the cap, fix the border, or accept that the bin
|
|
19
|
+
* filled.
|
|
20
|
+
*
|
|
21
|
+
* Separately importable so the packer's own bundle pays nothing for it. It re-runs the pack
|
|
22
|
+
* rather than instrumenting it, which costs a second pass but keeps the packing loop free of
|
|
23
|
+
* reporting concerns and guarantees the explanation describes the same options the caller actually
|
|
24
|
+
* used.
|
|
25
|
+
*
|
|
26
|
+
* Returns an entry only for rectangles that failed; an all-placed input yields an empty vector.
|
|
27
|
+
*/
|
|
28
|
+
export declare function explainUnpackedRectangles(out: UnpackedRectangleExplanation[], rectangles: Readonly<PackableRectangle[]>, options?: Readonly<BinPackOptions>): void;
|
|
29
|
+
export declare function getUnpackedRectangleReasonString(value: UnpackedRectangleReason): string;
|
|
30
|
+
export declare function parseUnpackedRectangleReason(value: string): UnpackedRectangleReason | undefined;
|
|
3
31
|
//# sourceMappingURL=explainUnpackedRectangles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explainUnpackedRectangles.d.ts","sourceRoot":"","sources":["../src/explainUnpackedRectangles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"explainUnpackedRectangles.d.ts","sourceRoot":"","sources":["../src/explainUnpackedRectangles.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAG1F;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,WAAW,GAAG,iBAAiB,GAAG,cAAc,CAAC;AAEvF;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,EAAE,EAAE,WAAW,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,4BAA4B,EAAE,EACnC,UAAU,EAAE,QAAQ,CAAC,iBAAiB,EAAE,CAAC,EACzC,OAAO,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,GACjC,IAAI,CAmCN;AA+BD,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,uBAAuB,GAAG,MAAM,CASvF;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS,CAW/F"}
|
|
@@ -1,64 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
// Generated from crates/flight-binpack/src/explain_unpacked_rectangles.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
import { BIN_PACK_DEFAULT_MAX_EXTENT, packRectangles } from './packRectangles.js';
|
|
4
|
+
/**
|
|
5
|
+
* Says WHY each unplaced rectangle did not fit. `packRectangles` reports `unpacked` as bare ids,
|
|
6
|
+
* which is the right shape for the hot path but tells a caller nothing about the remedy -- and the
|
|
7
|
+
* three causes have three different ones: raise the cap, fix the border, or accept that the bin
|
|
8
|
+
* filled.
|
|
9
|
+
*
|
|
10
|
+
* Separately importable so the packer's own bundle pays nothing for it. It re-runs the pack
|
|
11
|
+
* rather than instrumenting it, which costs a second pass but keeps the packing loop free of
|
|
12
|
+
* reporting concerns and guarantees the explanation describes the same options the caller actually
|
|
13
|
+
* used.
|
|
14
|
+
*
|
|
15
|
+
* Returns an entry only for rectangles that failed; an all-placed input yields an empty vector.
|
|
16
|
+
*/
|
|
17
|
+
export function explainUnpackedRectangles(out, rectangles, options) {
|
|
18
|
+
out.length = 0;
|
|
12
19
|
const border = options?.border ?? 0;
|
|
13
20
|
const allowRotation = options?.allowRotation ?? false;
|
|
14
21
|
const usableWidth = (options?.maxWidth ?? BIN_PACK_DEFAULT_MAX_EXTENT) - 2 * border;
|
|
15
22
|
const usableHeight = (options?.maxHeight ?? BIN_PACK_DEFAULT_MAX_EXTENT) - 2 * border;
|
|
16
23
|
const result = packRectangles(rectangles, options);
|
|
17
|
-
if (result.unpacked.length === 0)
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// entry for every rectangle carrying an unpacked id, which is two explanations for one failure when
|
|
22
|
-
// only one of a duplicate pair fits. Consuming a count keeps the entry count equal to the failure
|
|
23
|
-
// count, which is what the contract above promises.
|
|
24
|
-
//
|
|
25
|
-
// WHICH duplicate a given entry describes is input order, and that is the honest limit: the packer
|
|
26
|
-
// sorts by area before placing and reports bare ids, so an id cannot identify a piece the packer
|
|
27
|
-
// treats as distinct. The count is right; the attribution between same-id pieces is positional.
|
|
28
|
-
const outstanding = new Map();
|
|
29
|
-
for (const id of result.unpacked)
|
|
30
|
-
outstanding.set(id, (outstanding.get(id) ?? 0) + 1);
|
|
31
|
-
const explanations = [];
|
|
24
|
+
if (result.unpacked.length === 0) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
let explained = [];
|
|
32
28
|
for (const rectangle of rectangles) {
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
let outstandingCount = 0;
|
|
30
|
+
for (const id of result.unpacked) {
|
|
31
|
+
if (id === rectangle.id) {
|
|
32
|
+
outstandingCount++;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let explainedCount = 0;
|
|
36
|
+
for (const id of explained) {
|
|
37
|
+
if (id === rectangle.id) {
|
|
38
|
+
explainedCount++;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (explainedCount >= outstandingCount) {
|
|
35
42
|
continue;
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
}
|
|
44
|
+
explained.push(rectangle.id);
|
|
45
|
+
out.push({
|
|
38
46
|
id: rectangle.id,
|
|
39
47
|
reason: getUnpackedReason(rectangle, usableWidth, usableHeight, allowRotation),
|
|
40
48
|
usableWidth,
|
|
41
49
|
usableHeight,
|
|
42
50
|
});
|
|
43
51
|
}
|
|
44
|
-
return explanations;
|
|
45
52
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
function fitsWithin(width, height, usableWidth, usableHeight) {
|
|
54
|
+
return width <= usableWidth && height <= usableHeight;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Region collapse is checked before size, because when the usable region is non-positive EVERY
|
|
58
|
+
* rectangle fails for that one reason and reporting each as "oversized" would send the caller
|
|
59
|
+
* after the pieces instead of after the border.
|
|
60
|
+
*/
|
|
49
61
|
function getUnpackedReason(rectangle, usableWidth, usableHeight, allowRotation) {
|
|
50
|
-
if (usableWidth <= 0 || usableHeight <= 0)
|
|
62
|
+
if (usableWidth <= 0 || usableHeight <= 0) {
|
|
51
63
|
return 'regionCollapsed';
|
|
64
|
+
}
|
|
52
65
|
if (!fitsWithin(rectangle.width, rectangle.height, usableWidth, usableHeight)) {
|
|
53
|
-
if (!allowRotation)
|
|
66
|
+
if (!allowRotation) {
|
|
54
67
|
return 'oversized';
|
|
55
|
-
|
|
56
|
-
if (!fitsWithin(rectangle.height, rectangle.width, usableWidth, usableHeight))
|
|
68
|
+
}
|
|
69
|
+
if (!fitsWithin(rectangle.height, rectangle.width, usableWidth, usableHeight)) {
|
|
57
70
|
return 'oversized';
|
|
71
|
+
}
|
|
58
72
|
}
|
|
59
73
|
return 'binExhausted';
|
|
60
74
|
}
|
|
61
|
-
function
|
|
62
|
-
|
|
75
|
+
export function getUnpackedRectangleReasonString(value) {
|
|
76
|
+
switch (value) {
|
|
77
|
+
case 'oversized':
|
|
78
|
+
return 'oversized';
|
|
79
|
+
case 'regionCollapsed':
|
|
80
|
+
return 'regionCollapsed';
|
|
81
|
+
case 'binExhausted':
|
|
82
|
+
return 'binExhausted';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function parseUnpackedRectangleReason(value) {
|
|
86
|
+
switch (value) {
|
|
87
|
+
case 'oversized':
|
|
88
|
+
return 'oversized';
|
|
89
|
+
case 'regionCollapsed':
|
|
90
|
+
return 'regionCollapsed';
|
|
91
|
+
case 'binExhausted':
|
|
92
|
+
return 'binExhausted';
|
|
93
|
+
default:
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
63
96
|
}
|
|
64
97
|
//# sourceMappingURL=explainUnpackedRectangles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explainUnpackedRectangles.js","sourceRoot":"","sources":["../src/explainUnpackedRectangles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"explainUnpackedRectangles.js","sourceRoot":"","sources":["../src/explainUnpackedRectangles.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,mEAAmE;AAGnE,OAAO,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAiBlF;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,yBAAyB,CACvC,GAAmC,EACnC,UAAyC,EACzC,OAAkC;IAElC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;IACf,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC;IACpC,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,IAAI,KAAK,CAAC;IACtD,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,QAAQ,IAAI,2BAA2B,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;IACpF,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,SAAS,IAAI,2BAA2B,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;IACtF,MAAM,MAAM,GAAG,cAAc,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACnD,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO;IACT,CAAC;IACD,IAAI,SAAS,GAAkB,EAAE,CAAC;IAClC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,gBAAgB,GAAG,CAAC,CAAC;QACzB,KAAK,MAAM,EAAE,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACjC,IAAI,EAAE,KAAK,SAAS,CAAC,EAAE,EAAE,CAAC;gBACxB,gBAAgB,EAAE,CAAC;YACrB,C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AAc,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,gCAAgC,CAAC,KAA8B;IAC7E,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,WAAW;YACd,OAAO,WAAW,CAAC;QACrB,KAAK,iBAAiB;YACpB,OAAO,iBAAiB,CAAC;QAC3B,KAAK,cAAc;YACjB,OAAO,cAAc,CAAC;IAC1B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,KAAa;IACxD,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,WAAW;YACd,OAAO,WAAW,CAAC;QACrB,KAAK,iBAAiB;YACpB,OAAO,iBAAiB,CAAC;QAC3B,KAAK,cAAc;YACjB,OAAO,cAAc,CAAC;QACxB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { explainUnpackedRectangles, getPackResultOccupancy, packRectangles } from './contract';
|
|
1
|
+
export { explainUnpackedRectangles, getPackResultOccupancy, packRectangles } from './contract.ts';
|
|
2
|
+
export type { BinPackHeuristic, BinPackOptions, PackResult, PackableRectangle, PackedRectangle, RectangleId, UnpackedRectangleExplanation, UnpackedRectangleReason, } from './contract.ts';
|
|
2
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAElG,YAAY,EACV,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { explainUnpackedRectangles, getPackResultOccupancy, packRectangles } from './contract';
|
|
1
|
+
export { explainUnpackedRectangles, getPackResultOccupancy, packRectangles } from './contract.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/packRectangles.d.ts
CHANGED
|
@@ -1,5 +1,91 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The heuristic used by the MaxRects bin packing algorithm.
|
|
3
|
+
*/
|
|
4
|
+
export type BinPackHeuristic = 'bestShortSideFit' | 'bestAreaFit';
|
|
5
|
+
/**
|
|
6
|
+
* A rectangle identifier: either a numeric index or a textual name.
|
|
7
|
+
* Maps to the TS `RectangleId = number | string` union.
|
|
8
|
+
*/
|
|
9
|
+
export type RectangleId = number | string;
|
|
10
|
+
/**
|
|
11
|
+
* Options controlling the bin packing algorithm.
|
|
12
|
+
* Options for `packRectangles`. Every field mirrors the optional TS field: `undefined` means the
|
|
13
|
+
* documented default applies (padding/border 0, rotation/power-of-two/square false, growable true,
|
|
14
|
+
* max extent `BIN_PACK_DEFAULT_MAX_EXTENT`, heuristic `BestShortSideFit`).
|
|
15
|
+
*/
|
|
16
|
+
export interface BinPackOptions {
|
|
17
|
+
padding?: number;
|
|
18
|
+
border?: number;
|
|
19
|
+
allowRotation?: boolean;
|
|
20
|
+
heuristic?: BinPackHeuristic;
|
|
21
|
+
growable?: boolean;
|
|
22
|
+
powerOfTwo?: boolean;
|
|
23
|
+
square?: boolean;
|
|
24
|
+
maxWidth?: number;
|
|
25
|
+
maxHeight?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The result of a bin packing operation: the placed rectangles, the bin extents, and the ids of
|
|
29
|
+
* rectangles that did not fit.
|
|
30
|
+
*/
|
|
31
|
+
export interface PackResult {
|
|
32
|
+
placements: PackedRectangle[];
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
unpacked: RectangleId[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A rectangle to be packed: its identity and dimensions.
|
|
39
|
+
*/
|
|
40
|
+
export interface PackableRectangle {
|
|
41
|
+
id: RectangleId;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A placed rectangle in the output: position, dimensions (possibly swapped if rotated), and
|
|
47
|
+
* whether it was turned 90 degrees.
|
|
48
|
+
*/
|
|
49
|
+
export interface PackedRectangle {
|
|
50
|
+
id: RectangleId;
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
rotated: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The default width/height cap when `maxWidth`/`maxHeight` are unset -- large enough to be
|
|
59
|
+
* effectively unbounded for typical inputs while keeping growth from running away.
|
|
60
|
+
*/
|
|
61
|
+
export declare const BIN_PACK_DEFAULT_MAX_EXTENT: number;
|
|
62
|
+
export declare function getBinPackHeuristicString(value: BinPackHeuristic): string;
|
|
63
|
+
/**
|
|
64
|
+
* Fraction of the reported bin actually covered by placements, in [0, 1]. Placed area over
|
|
65
|
+
* `width * height`; 0 for an empty or zero-extent result rather than NaN, since "nothing packed"
|
|
66
|
+
* is an expected outcome and not a division error the caller should have to guard.
|
|
67
|
+
*
|
|
68
|
+
* Measures the REPORTED extent, so power-of-two or square rounding shows up as the padding waste
|
|
69
|
+
* it is -- which is usually the number a caller comparing packings wants to see.
|
|
70
|
+
*/
|
|
2
71
|
export declare function getPackResultOccupancy(result: Readonly<PackResult>): number;
|
|
3
|
-
|
|
4
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Places a set of rectangles without overlap into a bin using the MaxRects algorithm with the
|
|
74
|
+
* Best-Short-Side-Fit (BSSF) heuristic, and reports each placement, the used bin extent, and any
|
|
75
|
+
* ids that did not fit.
|
|
76
|
+
*
|
|
77
|
+
* The result is deterministic: the same `rects` (by value) and `options` always produce an
|
|
78
|
+
* identical `PackResult`. Inputs are sorted by descending area, then descending height, then
|
|
79
|
+
* width, then id before placement -- a total order with no reliance on sort stability -- and no
|
|
80
|
+
* random state is consulted.
|
|
81
|
+
*
|
|
82
|
+
* Padding and border are honored geometrically: every pair of placements is at least `padding`
|
|
83
|
+
* apart and every placement is at least `border` from the reported bin edge. When `allowRotation`
|
|
84
|
+
* is set, a rectangle may be turned 90 degrees (reported via `rotated` and swapped
|
|
85
|
+
* `width`/`height`) if that fits better. A `growable` bin starts small and grows toward
|
|
86
|
+
* `maxWidth`/`maxHeight`; a fixed bin overflows into `unpacked`. The reported `width`/`height`
|
|
87
|
+
* is the tight used extent, then adjusted for `square` and `powerOfTwo` when those are set.
|
|
88
|
+
*/
|
|
89
|
+
export declare function packRectangles(rects: Readonly<PackableRectangle[]>, options?: Readonly<BinPackOptions>): PackResult;
|
|
90
|
+
export declare function parseBinPackHeuristic(value: string): BinPackHeuristic | undefined;
|
|
5
91
|
//# sourceMappingURL=packRectangles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packRectangles.d.ts","sourceRoot":"","sources":["../src/packRectangles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"packRectangles.d.ts","sourceRoot":"","sources":["../src/packRectangles.ts"],"names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