Implemented RendertileSet's posttraversal() routine
May not be the most efficient implementation.
This commit is contained in:
@@ -626,8 +626,36 @@ class RendertileSet(object):
|
|||||||
yielded after their dependencies.
|
yielded after their dependencies.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# XXX Implement Me!
|
return (tuple(reversed(rpath)) for rpath in self._posttraversal_helper())
|
||||||
raise NotImplementedError()
|
|
||||||
|
def _posttraversal_helper(self):
|
||||||
|
"""Each node returns an iterator over lists of reversed paths"""
|
||||||
|
if self.depth == 1:
|
||||||
|
# Base case
|
||||||
|
if self.children[0]: yield [0]
|
||||||
|
if self.children[1]: yield [1]
|
||||||
|
if self.children[2]: yield [2]
|
||||||
|
if self.children[3]: yield [3]
|
||||||
|
else:
|
||||||
|
for childnum, child in enumerate(self.children):
|
||||||
|
if child == True:
|
||||||
|
for path in post_traversal_complete_subtree_recursion_helper(self.depth-1):
|
||||||
|
path.append(childnum)
|
||||||
|
yield path
|
||||||
|
|
||||||
|
elif child == False:
|
||||||
|
pass # do nothing
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Recurse
|
||||||
|
for path in child._posttraversal_helper():
|
||||||
|
path.append(childnum)
|
||||||
|
yield path
|
||||||
|
|
||||||
|
# Now do this node itself
|
||||||
|
if bool(self):
|
||||||
|
yield []
|
||||||
|
|
||||||
|
|
||||||
def add(self, path):
|
def add(self, path):
|
||||||
"""Marks the requested leaf node as in this set
|
"""Marks the requested leaf node as in this set
|
||||||
@@ -769,10 +797,11 @@ class RendertileSet(object):
|
|||||||
"""
|
"""
|
||||||
# Any chilren that are True or are a RendertileSet that evaluate to
|
# Any chilren that are True or are a RendertileSet that evaluate to
|
||||||
# True
|
# True
|
||||||
# IDEA: look at all children for True before recursing Better idea:
|
# IDEA: look at all children for True before recursing
|
||||||
# every node except the root /must/ have a descendent in the set or it
|
# Better idea: every node except the root /must/ have a descendent in
|
||||||
# wouldn't exist. This assumption is only valid as long as there is no
|
# the set or it wouldn't exist. This assumption is only valid as long
|
||||||
# method to remove a tile from the set.
|
# as there is no method to remove a tile from the set. So this should
|
||||||
|
# check to see if any children are not False.
|
||||||
return any(self.children)
|
return any(self.children)
|
||||||
|
|
||||||
def count(self):
|
def count(self):
|
||||||
@@ -786,6 +815,25 @@ class RendertileSet(object):
|
|||||||
c += 1
|
c += 1
|
||||||
return c
|
return c
|
||||||
|
|
||||||
|
def post_traversal_complete_subtree_recursion_helper(depth):
|
||||||
|
"""Fakes the recursive calls for RendertileSet.posttraversal() for the case
|
||||||
|
that a subtree is collapsed.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if depth == 1:
|
||||||
|
# Base case
|
||||||
|
yield [0]
|
||||||
|
yield [1]
|
||||||
|
yield [2]
|
||||||
|
yield [3]
|
||||||
|
else:
|
||||||
|
for childnum in xrange(4):
|
||||||
|
for item in post_traversal_complete_subtree_recursion_helper(depth-1):
|
||||||
|
item.append(childnum)
|
||||||
|
yield item
|
||||||
|
|
||||||
|
yield []
|
||||||
|
|
||||||
class RenderTile(object):
|
class RenderTile(object):
|
||||||
"""A simple container class that represents a single render-tile.
|
"""A simple container class that represents a single render-tile.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user