Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def update_rectangles(self, rect: Tuple[int, int, int, int]) -> None:
- """Update the rectangles in this tree and its descendents using the
- treemap algorithm to fill the area defined by pygame rectangle <rect>.
- """
- # TODO: (Task 2) Complete the body of this method.
- # Read the handout carefully to help get started identifying base cases,
- # then write the outline of a recursive step.
- #
- # Programming tip: use "tuple unpacking assignment" to easily extract
- # elements of a rectangle, as follows.
- x, y, width, height = rect
- big_width, big_height = width, height
- if self.is_empty():
- return []
- if self.get_suffix() == '(file)':
- self.rect = rect
- if self.get_suffix() == '(folder)':
- if self._subtrees == []:
- self.rect = rect
- for subtree in self._subtrees:
- scale = math.trunc(subtree.data_size / self.data_size)
- if width >= height:
- small_width = math.trunc(scale * big_width)
- self.update_rectangles((x,y,small_width,height))
- x += small_width
- width -= small_width
- if width < height:
- small_height = math.trunc(scale * big_height)
- self.update_rectangles((x,y,width,small_height))
- y += small_height
- height -= small_height
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement