@mark1russell7/packing 0.2.9 → 0.2.11
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/build/index.d.ts.map +1 -1
- package/build/index.js +102 -26
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/maxrects.ts +67 -17
- package/src/skyline.ts +24 -1
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["Item","Sides","ContractMeasureSpec","Direction","SelectLevel","Portfolio","LayoutContainer","LayoutEdge","LayoutInput","ContainerTest","PackHard"],"sources":["../src/vector.ts","../src/rect.ts","../src/order.ts","../src/contract.ts","../src/space.ts","../src/maxrects.ts","../src/shelf.ts","../src/pack.ts","../src/skyline.ts","../src/free.ts","../src/push.ts","../src/metrics.ts","../src/measures.ts","../src/strategy.ts","../src/adapters.ts","../src/convert.ts","../src/registry.ts","../src/portfolio.ts","../src/layout-input.ts","../src/portfolio-cell.ts","../src/portfolio-sets.ts","../src/portfolio-strategy.ts","../src/check.ts","../src/generators.ts","../src/corpus.ts"],"mappings":";;qBACa;;EAIX,YAAY,YAAO;;MAMf;MACA,EAAE;;MAEF;MACA,EAAE;;EAGN,IAAI,WAAW;;EAMf,MAAM,GAAG;;EAMT,IAAI,OAAO,SAAS;;EAKpB;;EAKA,SAAS;;EAKT,MAAM,KAAK,QAAQ,KAAK,SAAS;;SAQ1B,GAAG,iBAAiB;;SAKpB,IAAI,SAAS,WAAW;;SASxB,IAAI,SAAS,WAAW;;aASpB,YAAY;;;qBCxEZ,KAAK;;;EAKhB,KAAK;;EAEL;;EAEA;;EAEA;;;;;EAKA;;MAGI,YAAY;;MAEZ,QAAQ;;EAGZ;;EAEA;;EAGA,WAAW;;EAOX,YAAY,QAAQ;;EAMpB;;SAGO,OAAO,GAAG,OAAO,KAAK,OAAO,KAAK;;SAKlC,SAAS,GAAG,OAAO,KAAK,OAAO,KAAK;;SAKpC,YAAY,GAAG,OAAO,KAAK;;SAK3B,SAAS,GAAG,OAAO,KAAK;;SAKxB,UAAU,GAAG,OAAO,KAAK;;;;;;KC/DtB;;qBAGC,sBAAsB;;wBAGnB,aAAa,OAAO,aAAa,GAAG,GAAG,KAAK,IAAI,GAAG,KAAK;;wBCiBxD,SAAS,MAAM,KAAKA,oBAAkBC;;;;;;;wBAWtC,SAAS,MAAMD,SAAOA;;UC/BrB;WACN;WACA;;;UAIM;WACN;WACA;WACA;WACA;;;;;;;;;;;UAYM;;WAEN;;WAEA;;;;;WAKA;;EAET,KAAK,YAAY,aAAa;;;;;EAK9B,OAAO,YAAY,YAAY,gBAAgB;;EAE/C,KAAK,MAAM;;EAEX,KAAK,WAAW,WAAW,YAAY;;;;;EAKvC,MAAM,YAAY,YAAY;;;;;;wBAmWhB,UAAU,OAAO,YAAY;;;;;;;;;;qBCzYhC;;KAGD,uBAAuB;;qBAGtB;;UAGI;;EAEf,YAAY;;;;;EAKZ,QAAQ;;EAER,OAAO;;;;;;EAMP;;EAEA,WAAW;;;;;EAKX,SAAS;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["Item","Sides","ContractMeasureSpec","Direction","SelectLevel","Portfolio","LayoutContainer","LayoutEdge","LayoutInput","ContainerTest","PackHard"],"sources":["../src/vector.ts","../src/rect.ts","../src/order.ts","../src/contract.ts","../src/space.ts","../src/maxrects.ts","../src/shelf.ts","../src/pack.ts","../src/skyline.ts","../src/free.ts","../src/push.ts","../src/metrics.ts","../src/measures.ts","../src/strategy.ts","../src/adapters.ts","../src/convert.ts","../src/registry.ts","../src/portfolio.ts","../src/layout-input.ts","../src/portfolio-cell.ts","../src/portfolio-sets.ts","../src/portfolio-strategy.ts","../src/check.ts","../src/generators.ts","../src/corpus.ts"],"mappings":";;qBACa;;EAIX,YAAY,YAAO;;MAMf;MACA,EAAE;;MAEF;MACA,EAAE;;EAGN,IAAI,WAAW;;EAMf,MAAM,GAAG;;EAMT,IAAI,O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;KAgJjD;EAAwB;;;qBAGvB,eAAe,gBAAgB;;KA8QhC;EACV,eAAe;EACf,gBAAgB;EAChB,WAAW;EACX,OAAO;EACP;;;;;;qBAOW,UAAU,gBAAgB;;KA2B3B;EACV,eAAe;EACf;;;qBA0BW,SAAS,gBAAgB;;qBAWzB,WAAW,gBAAgB;;qBAS3B,OAAO,gBAAgB;;qBAUvB,WAAW,gBAAgB;;KAY5B;;KAGA;EAAmB,MAAM;EAAU;;;;;;;;;;;qBAoBlC,WAAW,gBAAgB;;qBAwF3B,qBAAqB;;wBAGlB,UAAU,eAAe;;UChqBxB;;EAEf;;EAEA;;EAEA,SAAS;EACT;;;UAIe;EACf;EACA;EACA,MAAM;;;UAIS;EACf;;EAEA;;EAEA;IAAS;IAAmB;IAAiB,QAAQ;IAAiB;;EACtE,QAAQ;;;UAIO;EACf,UAAU;EACV,QAAQ;;;;;;wBAOM,OAAO,cAAc,gBAAgB,eAAe"}
|
package/build/index.js
CHANGED
|
@@ -868,14 +868,18 @@ function inside(a, b) {
|
|
|
868
868
|
function cut(free, b, minW, minH) {
|
|
869
869
|
const kept = [];
|
|
870
870
|
const parts = [];
|
|
871
|
+
const sides = [];
|
|
871
872
|
let hits = 0;
|
|
872
|
-
const add = (x0, y0, x1, y1) => {
|
|
873
|
-
if (x1 - x0 >= minW && y1 - y0 >= minH)
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
873
|
+
const add = (side, x0, y0, x1, y1) => {
|
|
874
|
+
if (x1 - x0 >= minW && y1 - y0 >= minH) {
|
|
875
|
+
parts.push({
|
|
876
|
+
x0,
|
|
877
|
+
y0,
|
|
878
|
+
x1,
|
|
879
|
+
y1
|
|
880
|
+
});
|
|
881
|
+
sides.push(side);
|
|
882
|
+
}
|
|
879
883
|
};
|
|
880
884
|
for (const f of free) {
|
|
881
885
|
if (b.x0 >= f.x1 || b.x1 <= f.x0 || b.y0 >= f.y1 || b.y1 <= f.y0) {
|
|
@@ -883,21 +887,54 @@ function cut(free, b, minW, minH) {
|
|
|
883
887
|
continue;
|
|
884
888
|
}
|
|
885
889
|
hits++;
|
|
886
|
-
if (b.x0 > f.x0) add(f.x0, f.y0, b.x0, f.y1);
|
|
887
|
-
if (b.x1 < f.x1) add(b.x1, f.y0, f.x1, f.y1);
|
|
888
|
-
if (b.y0 > f.y0) add(f.x0, f.y0, f.x1, b.y0);
|
|
889
|
-
if (b.y1 < f.y1) add(f.x0, b.y1, f.x1, f.y1);
|
|
890
|
+
if (b.x0 > f.x0) add(0, f.x0, f.y0, b.x0, f.y1);
|
|
891
|
+
if (b.x1 < f.x1) add(1, b.x1, f.y0, f.x1, f.y1);
|
|
892
|
+
if (b.y0 > f.y0) add(2, f.x0, f.y0, f.x1, b.y0);
|
|
893
|
+
if (b.y1 < f.y1) add(3, f.x0, b.y1, f.x1, f.y1);
|
|
894
|
+
}
|
|
895
|
+
if (parts.length === 0) return {
|
|
896
|
+
free: kept,
|
|
897
|
+
hits
|
|
898
|
+
};
|
|
899
|
+
const near = [
|
|
900
|
+
[],
|
|
901
|
+
[],
|
|
902
|
+
[],
|
|
903
|
+
[]
|
|
904
|
+
];
|
|
905
|
+
for (const k of kept) {
|
|
906
|
+
if (k.x1 === b.x0) near[0].push(k);
|
|
907
|
+
if (k.x0 === b.x1) near[1].push(k);
|
|
908
|
+
if (k.y1 === b.y0) near[2].push(k);
|
|
909
|
+
if (k.y0 === b.y1) near[3].push(k);
|
|
910
|
+
}
|
|
911
|
+
const order = parts.map((_, i) => i).sort((i, j) => byExtent(parts[i], parts[j]) || i - j);
|
|
912
|
+
const gone = new Uint8Array(parts.length);
|
|
913
|
+
const stay = [
|
|
914
|
+
[],
|
|
915
|
+
[],
|
|
916
|
+
[],
|
|
917
|
+
[]
|
|
918
|
+
];
|
|
919
|
+
for (const i of order) {
|
|
920
|
+
const p = parts[i];
|
|
921
|
+
const own = stay[sides[i]];
|
|
922
|
+
let drop = false;
|
|
923
|
+
for (const q of own) if (inside(p, q)) {
|
|
924
|
+
drop = true;
|
|
925
|
+
break;
|
|
926
|
+
}
|
|
927
|
+
if (drop) gone[i] = 1;
|
|
928
|
+
else own.push(p);
|
|
890
929
|
}
|
|
891
|
-
const count = kept.length;
|
|
892
930
|
for (let i = 0; i < parts.length; i++) {
|
|
931
|
+
if (gone[i] === 1) continue;
|
|
893
932
|
const p = parts[i];
|
|
894
933
|
let drop = false;
|
|
895
|
-
for (
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
if (inside(p, q) && (j < i || !inside(q, p))) drop = true;
|
|
934
|
+
for (const k of near[sides[i]]) if (inside(p, k)) {
|
|
935
|
+
drop = true;
|
|
936
|
+
break;
|
|
899
937
|
}
|
|
900
|
-
for (let k = 0; k < count && !drop; k++) if (inside(p, kept[k])) drop = true;
|
|
901
938
|
if (!drop) kept.push(p);
|
|
902
939
|
}
|
|
903
940
|
return {
|
|
@@ -905,6 +942,17 @@ function cut(free, b, minW, minH) {
|
|
|
905
942
|
hits
|
|
906
943
|
};
|
|
907
944
|
}
|
|
945
|
+
/**
|
|
946
|
+
* This function orders two boxes. The smaller `x0` comes first, then the smaller `y0`, then the larger `x1`, then the
|
|
947
|
+
* larger `y1`. Thus a box comes before each other box in it.
|
|
948
|
+
*/
|
|
949
|
+
function byExtent(a, b) {
|
|
950
|
+
if (a.x0 !== b.x0) return a.x0 < b.x0 ? -1 : 1;
|
|
951
|
+
if (a.y0 !== b.y0) return a.y0 < b.y0 ? -1 : 1;
|
|
952
|
+
if (a.x1 !== b.x1) return a.x1 > b.x1 ? -1 : 1;
|
|
953
|
+
if (a.y1 !== b.y1) return a.y1 > b.y1 ? -1 : 1;
|
|
954
|
+
return 0;
|
|
955
|
+
}
|
|
908
956
|
/** This function adds a range to the edges at a coordinate. */
|
|
909
957
|
function addEdge(edges, at, a, b) {
|
|
910
958
|
const list = edges.get(at);
|
|
@@ -1109,22 +1157,29 @@ function runMaxRects(rects, outer, options = {}) {
|
|
|
1109
1157
|
s1 = -contact(f.x0, f.y0, bw, bh);
|
|
1110
1158
|
s2 = f.y0 + bh;
|
|
1111
1159
|
}
|
|
1112
|
-
const
|
|
1160
|
+
const x = f.x0;
|
|
1161
|
+
const y = f.y0;
|
|
1162
|
+
if (best === void 0 || s1 < best.s1 || s1 === best.s1 && (s2 < best.s2 || s2 === best.s2 && (y < best.y || y === best.y && x < best.x))) best = {
|
|
1113
1163
|
index: i,
|
|
1114
1164
|
turn: t === 1,
|
|
1115
|
-
x
|
|
1116
|
-
y
|
|
1165
|
+
x,
|
|
1166
|
+
y,
|
|
1117
1167
|
w: bw,
|
|
1118
1168
|
h: bh,
|
|
1119
1169
|
s1,
|
|
1120
1170
|
s2
|
|
1121
1171
|
};
|
|
1122
|
-
if (
|
|
1123
|
-
const ly =
|
|
1124
|
-
if (low === void 0 || ly < low.s1 || ly === low.s1 &&
|
|
1125
|
-
|
|
1172
|
+
if (rule === "bl") continue;
|
|
1173
|
+
const ly = y + bh;
|
|
1174
|
+
if (low === void 0 || ly < low.s1 || ly === low.s1 && x < low.s2) low = {
|
|
1175
|
+
index: i,
|
|
1176
|
+
turn: t === 1,
|
|
1177
|
+
x,
|
|
1178
|
+
y,
|
|
1179
|
+
w: bw,
|
|
1180
|
+
h: bh,
|
|
1126
1181
|
s1: ly,
|
|
1127
|
-
s2:
|
|
1182
|
+
s2: x
|
|
1128
1183
|
};
|
|
1129
1184
|
}
|
|
1130
1185
|
}
|
|
@@ -1716,6 +1771,9 @@ function packSkyline(rects, outer, options = {}) {
|
|
|
1716
1771
|
/**
|
|
1717
1772
|
* This function packs rectangles with a skyline in a free space. Each cell has a free range: the skyline is its start,
|
|
1718
1773
|
* and `limit` is its end. A cell with less room than the lowest rectangle left goes to its next free range.
|
|
1774
|
+
*
|
|
1775
|
+
* A rectangle that needs more cells than the outer rectangle has goes at the left edge. Its y is the first y where each
|
|
1776
|
+
* cell is free over its height. Then each cell starts after the rectangle, as in the plain skyline.
|
|
1719
1777
|
*/
|
|
1720
1778
|
function packSkylineInSpace(rects, outer, order, space) {
|
|
1721
1779
|
const width = Math.floor(outer.size.x);
|
|
@@ -1751,9 +1809,27 @@ function packSkylineInSpace(rects, outer, order, space) {
|
|
|
1751
1809
|
x = 0;
|
|
1752
1810
|
y = 0;
|
|
1753
1811
|
for (let i = 0; i < width; i++) if (Number.isFinite(skyline[i]) && skyline[i] > y) y = skyline[i];
|
|
1812
|
+
for (let moved = true; moved;) {
|
|
1813
|
+
moved = false;
|
|
1814
|
+
for (let i = 0; i < width; i++) {
|
|
1815
|
+
if (!Number.isFinite(skyline[i])) continue;
|
|
1816
|
+
const [s, e] = rangeOf(i, y);
|
|
1817
|
+
const next = s > y ? s : e < y + rh ? rangeOf(i, e)[0] : y;
|
|
1818
|
+
if (next > y && Number.isFinite(next)) {
|
|
1819
|
+
y = next;
|
|
1820
|
+
moved = true;
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1754
1824
|
rect.position.set(x + ox, y + oy);
|
|
1755
1825
|
rect.wasPacked = true;
|
|
1756
|
-
|
|
1826
|
+
const top = y + rh;
|
|
1827
|
+
for (let i = 0; i < width; i++) {
|
|
1828
|
+
if (!Number.isFinite(skyline[i])) continue;
|
|
1829
|
+
if (top <= limit[i]) skyline[i] = top;
|
|
1830
|
+
else [skyline[i], limit[i]] = rangeOf(i, top);
|
|
1831
|
+
}
|
|
1832
|
+
outer.size.y = Math.max(outer.size.y, top);
|
|
1757
1833
|
continue;
|
|
1758
1834
|
}
|
|
1759
1835
|
let found = findWindow(skyline, width, rw, limit, rh);
|