author | Wolfgang Steffens <WolfgangSteff@gmail.com> |
Mon, 25 Jun 2012 16:22:03 +0200 | |
changeset 7301 | bea42438a2ec |
parent 7292 | 18430abfbcd2 |
permissions | -rw-r--r-- |
7292
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
1 |
unit uBinPacker; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
2 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
3 |
interface |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
4 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
5 |
// implements a maxrects packer with best short side fit heuristic |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
6 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
7 |
type Rectangle = record |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
8 |
x, y, width, height: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
9 |
UserData: Pointer; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
10 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
11 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
12 |
type Size = record |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
13 |
width, height: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
14 |
UserData: Pointer; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
15 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
16 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
17 |
type PRectangle = ^Rectangle; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
18 |
type PSize = ^Size; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
19 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
20 |
type RectangleList = record |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
21 |
data: PRectangle; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
22 |
count: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
23 |
size: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
24 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
25 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
26 |
type SizeList = record |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
27 |
data: PSize; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
28 |
count: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
29 |
size: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
30 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
31 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
32 |
type Atlas = record |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
33 |
width, height: Longint; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
34 |
freeRectangles: RectangleList; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
35 |
usedRectangles: RectangleList; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
36 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
37 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
38 |
function atlasInsertAdaptive(var a: Atlas; sz: Size; var output: Rectangle): boolean; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
39 |
function atlasInsertSet(var a: Atlas; var input: SizeList; var outputs: RectangleList): boolean; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
40 |
function atlasNew(width, height: LongInt): Atlas; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
41 |
procedure atlasDelete(var a: Atlas); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
42 |
procedure atlasReset(var a: Atlas); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
43 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
44 |
procedure rectangleListInit(var list: RectangleList); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
45 |
procedure rectangleListRemoveAt(var list: RectangleList; index: LongInt); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
46 |
procedure rectangleListAdd(var list: RectangleList; r: Rectangle); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
47 |
procedure rectangleListClear(var list: RectangleList); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
48 |
procedure sizeListInit(var list: SizeList); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
49 |
procedure sizeListRemoveAt(var list: SizeList; index: LongInt); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
50 |
procedure sizeListAdd(var list: SizeList; s: Size); overload; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
51 |
procedure sizeListAdd(var list: SizeList; width, height: LongInt; UserData: Pointer); overload; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
52 |
procedure sizeListClear(var list: SizeList); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
53 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
54 |
implementation |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
55 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
56 |
uses Math; // for min/max |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
57 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
58 |
procedure rectangleListRemoveAt(var list: RectangleList; index: LongInt); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
59 |
var |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
60 |
i: Integer; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
61 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
62 |
i:=index; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
63 |
while (i + 1 < list.count) do |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
64 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
65 |
list.data[i]:=list.data[i + 1]; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
66 |
inc(i); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
67 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
68 |
dec(list.count); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
69 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
70 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
71 |
procedure rectangleListAdd(var list: RectangleList; r: Rectangle); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
72 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
73 |
if list.count >= list.size then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
74 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
75 |
inc(list.size, 512); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
76 |
ReAllocMem(list.data, sizeof(Rectangle) * list.size); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
77 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
78 |
list.data[list.count]:=r; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
79 |
inc(list.count); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
80 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
81 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
82 |
procedure rectangleListInit(var list: RectangleList); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
83 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
84 |
list.data:= nil; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
85 |
list.count:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
86 |
list.size:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
87 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
88 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
89 |
procedure rectangleListClear(var list: RectangleList); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
90 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
91 |
FreeMem(list.data); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
92 |
list.count:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
93 |
list.size:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
94 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
95 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
96 |
procedure sizeListRemoveAt(var list: SizeList; index: LongInt); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
97 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
98 |
list.data[index]:= list.data[list.count - 1]; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
99 |
dec(list.count); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
100 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
101 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
102 |
procedure sizeListAdd(var list: SizeList; s: Size); overload; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
103 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
104 |
if list.count >= list.size then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
105 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
106 |
inc(list.size, 512); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
107 |
ReAllocMem(list.data, sizeof(Size) * list.size); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
108 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
109 |
list.data[list.count]:=s; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
110 |
inc(list.count); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
111 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
112 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
113 |
procedure sizeListAdd(var list: SizeList; width, height: LongInt; UserData: Pointer); overload; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
114 |
var |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
115 |
sz: Size; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
116 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
117 |
sz.width:= width; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
118 |
sz.height:= height; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
119 |
sz.UserData:= UserData; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
120 |
sizeListAdd(list, sz); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
121 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
122 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
123 |
procedure sizeListInit(var list: SizeList); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
124 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
125 |
list.data:= nil; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
126 |
list.count:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
127 |
list.size:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
128 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
129 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
130 |
procedure sizeListClear(var list: SizeList); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
131 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
132 |
FreeMem(list.data); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
133 |
list.count:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
134 |
list.size:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
135 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
136 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
137 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
138 |
function isContainedIn(a, b: Rectangle): boolean; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
139 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
140 |
isContainedIn:= (a.x >= b.x) and (a.y >= b.y) |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
141 |
and (a.x + a.width <= b.x + b.width) |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
142 |
and (a.y + a.height <= b.y + b.height); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
143 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
144 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
145 |
function findPositionForNewNodeBestShortSideFit(var list: RectangleList; width, height: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
146 |
var bestShortSideFit, bestLongSideFit: LongInt): Rectangle; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
147 |
var |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
148 |
bestNode: Rectangle; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
149 |
i: Integer; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
150 |
ri: Rectangle; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
151 |
leftoverHoriz, leftoverVert, shortSideFit, longSideFit: Longint; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
152 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
153 |
bestNode.x:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
154 |
bestNode.y:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
155 |
bestNode.width:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
156 |
bestNode.height:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
157 |
bestShortSideFit:= $7FFFFFFF; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
158 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
159 |
for i:=0 to pred(list.count) do |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
160 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
161 |
ri:= list.data[i]; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
162 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
163 |
// Try to place the rectangle in upright (non-flipped) orientation. |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
164 |
if (ri.width >= width) and (ri.height >= height) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
165 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
166 |
leftoverHoriz:= Abs(ri.width - width); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
167 |
leftoverVert:= Abs(ri.height - height); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
168 |
shortSideFit:= Min(leftoverHoriz, leftoverVert); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
169 |
longSideFit:= Max(leftoverHoriz, leftoverVert); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
170 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
171 |
if (shortSideFit < bestShortSideFit) or |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
172 |
((shortSideFit = bestShortSideFit) and (longSideFit < bestLongSideFit)) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
173 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
174 |
bestNode.x:= ri.x; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
175 |
bestNode.y:= ri.y; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
176 |
bestNode.width:= width; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
177 |
bestNode.height:= height; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
178 |
bestShortSideFit:= shortSideFit; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
179 |
bestLongSideFit:= longSideFit; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
180 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
181 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
182 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
183 |
if (ri.width >= height) and (ri.height >= width) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
184 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
185 |
leftoverHoriz:= Abs(ri.width - height); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
186 |
leftoverVert:= Abs(ri.height - width); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
187 |
shortSideFit:= Min(leftoverHoriz, leftoverVert); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
188 |
longSideFit:= Max(leftoverHoriz, leftoverVert); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
189 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
190 |
if (shortSideFit < bestShortSideFit) or |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
191 |
((shortSideFit = bestShortSideFit) and (longSideFit < bestLongSideFit)) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
192 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
193 |
bestNode.x:= ri.x; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
194 |
bestNode.y:= ri.y; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
195 |
bestNode.width:= height; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
196 |
bestNode.height:= width; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
197 |
bestShortSideFit:= shortSideFit; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
198 |
bestLongSideFit:= longSideFit; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
199 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
200 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
201 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
202 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
203 |
findPositionForNewNodeBestShortSideFit:= bestNode; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
204 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
205 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
206 |
function scoreRect(var list: RectangleList; width, height: LongInt; var score1, score2: LongInt): Rectangle; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
207 |
var |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
208 |
newNode: Rectangle; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
209 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
210 |
newNode:= findPositionForNewNodeBestShortSideFit(list, width, height, score1, score2); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
211 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
212 |
// Cannot fit the current rectangle. |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
213 |
if newNode.height = 0 then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
214 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
215 |
score1:= $7FFFFFFF; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
216 |
score2:= $7FFFFFFF; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
217 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
218 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
219 |
scoreRect:= newNode; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
220 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
221 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
222 |
function splitFreeNode(var freeRectangles: RectangleList; freeNode, usedNode: Rectangle): boolean; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
223 |
var |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
224 |
newNode: Rectangle; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
225 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
226 |
// Test with SAT if the rectangles even intersect. |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
227 |
if (usedNode.x >= freeNode.x + freeNode.width) or (usedNode.x + usedNode.width <= freeNode.x) or |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
228 |
(usedNode.y >= freeNode.y + freeNode.height) or (usedNode.y + usedNode.height <= freeNode.y) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
229 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
230 |
splitFreeNode:=false; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
231 |
exit; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
232 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
233 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
234 |
if (usedNode.x < freeNode.x + freeNode.width) and (usedNode.x + usedNode.width > freeNode.x) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
235 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
236 |
// New node at the top side of the used node. |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
237 |
if (usedNode.y > freeNode.y) and (usedNode.y < freeNode.y + freeNode.height) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
238 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
239 |
newNode:= freeNode; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
240 |
newNode.height:= usedNode.y - newNode.y; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
241 |
rectangleListAdd(freeRectangles, newNode); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
242 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
243 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
244 |
// New node at the bottom side of the used node. |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
245 |
if (usedNode.y + usedNode.height < freeNode.y + freeNode.height) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
246 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
247 |
newNode:= freeNode; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
248 |
newNode.y:= usedNode.y + usedNode.height; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
249 |
newNode.height:= freeNode.y + freeNode.height - (usedNode.y + usedNode.height); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
250 |
rectangleListAdd(freeRectangles, newNode); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
251 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
252 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
253 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
254 |
if (usedNode.y < freeNode.y + freeNode.height) and (usedNode.y + usedNode.height > freeNode.y) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
255 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
256 |
// New node at the left side of the used node. |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
257 |
if (usedNode.x > freeNode.x) and (usedNode.y < freeNode.y + freeNode.width) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
258 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
259 |
newNode:= freeNode; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
260 |
newNode.width:= usedNode.x - newNode.x; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
261 |
rectangleListAdd(freeRectangles, newNode); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
262 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
263 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
264 |
// New node at the right side of the used node. |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
265 |
if (usedNode.x + usedNode.width < freeNode.x + freeNode.width) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
266 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
267 |
newNode:= freeNode; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
268 |
newNode.x:= usedNode.x + usedNode.width; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
269 |
newNode.width:= freeNode.x + freeNode.width - (usedNode.x + usedNode.width); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
270 |
rectangleListAdd(freeRectangles, newNode); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
271 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
272 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
273 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
274 |
splitFreeNode:= true; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
275 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
276 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
277 |
procedure pruneFreeList(var freeRectangles: RectangleList); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
278 |
var |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
279 |
i, j: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
280 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
281 |
// Go through each pair and remove any rectangle that is redundant. |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
282 |
i:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
283 |
while i < freeRectangles.count do |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
284 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
285 |
j:= i + 1; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
286 |
while j < freeRectangles.count do |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
287 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
288 |
if (isContainedIn(freeRectangles.data[i], freeRectangles.data[j])) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
289 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
290 |
rectangleListRemoveAt(freeRectangles, i); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
291 |
dec(i); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
292 |
break; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
293 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
294 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
295 |
if (isContainedIn(freeRectangles.data[j], freeRectangles.data[i])) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
296 |
rectangleListRemoveAt(freeRectangles, j) |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
297 |
else |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
298 |
inc(j); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
299 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
300 |
inc(i); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
301 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
302 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
303 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
304 |
function atlasInsertAdaptive(var a: Atlas; sz: Size; var output: Rectangle): boolean; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
305 |
var |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
306 |
newNode: Rectangle; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
307 |
score1, score2: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
308 |
numRectanglesToProcess: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
309 |
i: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
310 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
311 |
newNode:= findPositionForNewNodeBestShortSideFit(a.freeRectangles, sz.width, sz.height, score1, score2); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
312 |
if newNode.height = 0 then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
313 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
314 |
output:= newNode; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
315 |
output.UserData:= nil; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
316 |
atlasInsertAdaptive:= false; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
317 |
exit; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
318 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
319 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
320 |
numRectanglesToProcess:= a.freeRectangles.count; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
321 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
322 |
i:=0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
323 |
while i < numRectanglesToProcess do |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
324 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
325 |
if splitFreeNode(a.freeRectangles, a.freeRectangles.data[i], newNode) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
326 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
327 |
rectangleListRemoveAt(a.freeRectangles, i); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
328 |
dec(numRectanglesToProcess); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
329 |
end |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
330 |
else |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
331 |
inc(i); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
332 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
333 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
334 |
pruneFreeList(a.freeRectangles); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
335 |
newNode.UserData:= sz.UserData; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
336 |
rectangleListAdd(a.usedRectangles, newNode); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
337 |
output:= newNode; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
338 |
atlasInsertAdaptive:= true; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
339 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
340 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
341 |
procedure placeRect(var a: Atlas; node: Rectangle); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
342 |
var |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
343 |
numRectanglesToProcess: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
344 |
i: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
345 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
346 |
numRectanglesToProcess:= a.freeRectangles.Count; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
347 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
348 |
i:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
349 |
while i < numRectanglesToProcess do |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
350 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
351 |
if not splitFreeNode(a.freeRectangles, a.freeRectangles.data[i], node) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
352 |
inc(i) |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
353 |
else |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
354 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
355 |
rectangleListRemoveAt(a.freeRectangles, i); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
356 |
dec(numRectanglesToProcess); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
357 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
358 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
359 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
360 |
pruneFreeList(a.freeRectangles); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
361 |
rectangleListAdd(a.usedRectangles, node); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
362 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
363 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
364 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
365 |
function atlasInsertSet(var a: Atlas; var input: SizeList; var outputs: RectangleList): boolean; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
366 |
var |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
367 |
bestScore1, bestScore2, bestRectIndex: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
368 |
score1, score2: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
369 |
bestNode, newNode: Rectangle; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
370 |
i: LongInt; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
371 |
sz: Size; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
372 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
373 |
atlasInsertSet:= false; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
374 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
375 |
while input.count > 0 do |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
376 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
377 |
bestScore1:= $7FFFFFFF; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
378 |
bestScore2:= $7FFFFFFF; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
379 |
bestRectIndex:= -1; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
380 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
381 |
for i:=0 to pred(input.count) do |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
382 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
383 |
sz:= input.data[i]; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
384 |
newNode:= scoreRect(a.freeRectangles, sz.width, sz.height, score1, score2); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
385 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
386 |
if (score1 >= bestScore1) and ((score1 <> bestScore1) or (score2 >= bestScore2)) then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
387 |
continue; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
388 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
389 |
bestScore1:= score1; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
390 |
bestScore2:= score2; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
391 |
bestNode:= newNode; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
392 |
bestRectIndex:= i; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
393 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
394 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
395 |
if bestRectIndex = -1 then |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
396 |
exit; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
397 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
398 |
bestNode.UserData:= input.data[bestRectIndex].UserData; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
399 |
placeRect(a, bestNode); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
400 |
rectangleListAdd(outputs, bestNode); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
401 |
sizeListRemoveAt(input, bestRectIndex); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
402 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
403 |
atlasInsertSet:= true; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
404 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
405 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
406 |
function atlasNew(width, height: LongInt): Atlas; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
407 |
var |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
408 |
a: Atlas; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
409 |
r: Rectangle; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
410 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
411 |
rectangleListInit(a.freeRectangles); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
412 |
rectangleListInit(a.usedRectangles); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
413 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
414 |
a.width:= width; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
415 |
a.height:= height; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
416 |
r.x:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
417 |
r.y:= 0; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
418 |
r.width:= width; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
419 |
r.height:= height; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
420 |
rectangleListAdd(a.freeRectangles, r); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
421 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
422 |
atlasNew:=a; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
423 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
424 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
425 |
procedure atlasDelete(var a: atlas); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
426 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
427 |
rectangleListClear(a.freeRectangles); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
428 |
rectangleListClear(a.usedRectangles); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
429 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
430 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
431 |
procedure atlasReset(var a: atlas); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
432 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
433 |
atlasDelete(a); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
434 |
a:=atlasNew(a.width, a.height); |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
435 |
end; |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
436 |
|
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
437 |
begin |
18430abfbcd2
added missing uBinPacker.pas and uAtlas.pas
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
diff
changeset
|
438 |
end. |