old_contents: import ui
  import objc_util
  
  
  def get_path_image(path):
      """ Get an image of a path """
      bounds = path.bounds
      with ui.ImageContext(bounds.max_x, bounds.max_y) as ctx:
          path.fill()
          return ctx.get_image()
  
  
  def copy_path(path):
      """ Make a copy of a ui.Path and return it. Preserves all data. """
      new = ui.Path()
      new.append_path(path)
      # Copy over the attributes
      new.line_cap_style = path.line_cap_style
      new.line_join_style = path.line_join_style
      new.line_width = path.line_width
  
      return new
  
  
  def scale_path(path, scale):
      """ Stretch or scale a path. Pass either a scale or a tuple of scales """
      if not hasattr(scale, "__iter__"):
          scale = (scale, scale)
      sx, sy = scale
  
      newpath = copy_path(path)
      # Construct an affine transformation matrix
      transform = objc_util.CGAffineTransform(sx, 0, 0, sy, 0, 0)
      # Apply it to the path
      objcpath = objc_util.ObjCInstance(newpath)
      objcpath.applyTransform_(transform)
      return newpath
  
new_contents: import ui
  import objc_util
  
  
  def get_path_image(path):
      """ Get an image of a path """
      bounds = path.bounds
      with ui.ImageContext(bounds.max_x, bounds.max_y) as ctx:
          path.fill()
          return ctx.get_image()
  
  
  def copy_path(path):
      """ Make a copy of a ui.Path and return it. Preserves all data. """
      new = ui.Path()
      new.append_path(path)
      # Copy over the attributes
      new.line_cap_style = path.line_cap_style
      new.line_join_style = path.line_join_style
      new.line_width = path.line_width
  
      return new
  
  
  def scale_path(path, scale):
      """ Stretch or scale a path. Pass either a scale or a tuple of scales """
      if not hasattr(scale, "__iter__"):
          scale = (scale, scale)
      sx, sy = scale
  
      newpath = copy_path(path)
      # Construct an affine transformation matrix
      transform = objc_util.CGAffineTransform(sx, 0, 0, sy, 0, 0)
      # Apply it to the path
      objcpath = objc_util.ObjCInstance(newpath)
      objcpath.applyTransform_(transform)
      return newpath
  
  
  if __name__ == "__main__":
      a = ui.Path()
      a.line_to(100, 0)
      a.line_to(100, 100)
      a.close()
  
      b = scale_path(a, 0.25)
  
      get_path_image(a).show()  # Note that the original is not mutated
      get_path_image(b).show()
  
subject: Add tests for path_helpers