-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo.js
40 lines (28 loc) · 941 Bytes
/
go.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function go(blocks)
{
var unfitblocks = [];
blocks.sort(function(a,b){return Math.max(b.w, b.h) - Math.max(a.w, a.h)});
//blocks.sort(function(a,b){return b.w - a.w});
//blocks.sort(function(a,b){return b.h - a.h});
//blocks.sort(function(a,b){return (b.w * b.h) - (a.w * a.h)});
var rootDD = calcTotalAreaSquareDimension(blocks, 5);
console.log(rootDD + " root");
var packer = new Packer(rootDD, rootDD);
packer.fit(blocks);
drawBlocks(blocks, 0, 0);
//get blocks that did not fit
for(var n = 0 ; n < blocks.length ; n++)
{
var block = blocks[n];
if (!block.fit)
{
unfitblocks.push(block);
}
}
if (unfitblocks.length == 0)
return;
var maxwidth = maxWidth(unfitblocks);
var packer2 = new Packer(maxwidth, rootDD);
packer2.fit(unfitblocks);
drawBlocks(unfitblocks, rootDD, 0);
}