Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1.     def update_rectangles(self, rect: Tuple[int, int, int, int]) -> None:
  2.         """Update the rectangles in this tree and its descendents using the
  3.        treemap algorithm to fill the area defined by pygame rectangle <rect>.
  4.        """
  5.         # TODO: (Task 2) Complete the body of this method.
  6.         # Read the handout carefully to help get started identifying base cases,
  7.         # then write the outline of a recursive step.
  8.         #
  9.         # Programming tip: use "tuple unpacking assignment" to easily extract
  10.         # elements of a rectangle, as follows.
  11.  
  12.         x, y, width, height = rect
  13.         big_width, big_height = width, height
  14.         if self.is_empty():
  15.             return []
  16.  
  17.         if self.get_suffix() == '(file)':
  18.             self.rect = rect
  19.  
  20.  
  21.         if self.get_suffix() == '(folder)':
  22.  
  23.             if self._subtrees == []:
  24.                 self.rect = rect
  25.             for subtree in self._subtrees:
  26.  
  27.                 scale = math.trunc(subtree.data_size / self.data_size)
  28.                 if width >= height:
  29.                     small_width = math.trunc(scale * big_width)
  30.                     self.update_rectangles((x,y,small_width,height))
  31.                     x += small_width
  32.                     width -= small_width
  33.                 if width < height:
  34.                     small_height = math.trunc(scale * big_height)
  35.                     self.update_rectangles((x,y,width,small_height))
  36.                     y += small_height
  37.                     height -= small_height
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement