Thanks a lot for the hint. I googled a bit and came up with this code:
def arrange():
global index
if(index == len(rList)):
return 0
rect = rList[index]
for i in range(0,len(freeNodesList)):
node = freeNodesList[i]
if(node.width >= rect.width and node.height >= rect.height): #rectangle fits inside the node
freeNodesList.pop(i) #remove current node because it's going to be filled
rect.sX = node.sX
rect.sY = node.sY
node.rectangle = rect
node.width = rect.width
node.height = rect.height
child1 = Node(wW-(node.sX+node.width),node.height,node.sX+node.width,node.sY)
freeNodesList.append(child1)
if(wH-(node.sY+node.height) > 0): #there is still space left to the top
child2 = Node(wW,wH-(node.sY+node.height),0,node.sY+node.height)
freeNodesList.append(child2)
index += 1
break;
else: #current node doesn't fit
continue
But it is not working as expected. The problem is, that i generate two new nodes after every rectangle and that those nodes don't consider the already placed rectangles. I made a short gif which should show that problem:
So basically i have to check for every node if there is already a rectangle which shrinks the originally intended space. The next problem would be to combine two free nodes if there is a rectangle which can only be placed if those two nodes are combined.
I would really appreciate it if someone could explain to me how i can solve those problems.
Best regards