Permalink
Browse files

Added a nodes generator function to the Layout

  • Loading branch information...
1 parent 0b79a98 commit 560e2312e4f4a480fc1625abff198e85b595be54 @industria committed Oct 23, 2011
Showing with 19 additions and 0 deletions.
  1. +13 −0 rectanglelayout.py
  2. +6 −0 testrectanglelayout.py
View
@@ -77,6 +77,7 @@ def __init__(self, width, height):
self._root = Node(0, 0, width, height)
self._partitioning = self.__selectPartitioning(width, height)
self._free_node = None
+ self._allocated = []
def __selectPartitioning(self, width, height):
"""
@@ -168,6 +169,8 @@ def insert(self, width, height, item):
node.item = item
node.width = width
node.height = height
+ # Add the allocated node to the allocated list
+ self._allocated.append(node)
print "After allocation", node
# Place the smallest free space area to the left in the tree
if(node_below.area < node_beside.area):
@@ -226,3 +229,13 @@ def bounding(self):
"""
(width, height) = self.__bounding_traverse(self._root, 0, 0)
return (width, height)
+
+
+ def nodes(self):
+ """
+ Generator function for nodes in the layout.
+ """
+ for node in self._allocated:
+ yield node
+
+
View
@@ -38,6 +38,12 @@ def test_layout_locked_width(self):
(width, height) = layout.bounding()
self.assertEqual(12, width)
self.assertEqual(22, height)
+
+ node_count = 0
+ for node in layout.nodes():
+ node_count = node_count + 1
+ self.assertEqual(14, node_count)
+
if __name__ == '__main__':
unittest.main()

0 comments on commit 560e231

Please sign in to comment.