code: def padRect(rect, padTop, padBottom, padLeft, padRight, bounds, clipExcess = True):
  	
  	
  	# Unpack the rectangle
  	x, y, w, h = rect
  	
  	# Pad by the specified value
  	x -= padLeft
  	y -= padTop
  	w += (padLeft + padRight)
  	h += (padTop + padBottom)
  	
  	# Determine if we are clipping overflows/underflows or
  	# shifting the centre of the rectangle to compensate
  	if clipExcess == True:
  		
  		# Clip any underflows
  		x = max(0, x)
  		y = max(0, y)
  		
  		# Clip any overflows
  		overflowY = max(0, (y + h) - bounds[0])
  		overflowX = max(0, (x + w) - bounds[1])
  		h -= overflowY
  		w -= overflowX
  		
  	else:
  		
  		# Compensate for any underflows
  		underflowX = max(0, 0 - x)
  		underflowY = max(0, 0 - y)
  		x += underflowX
  		y += underflowY
  		
  		# Compensate for any overflows
  		overflowY = max(0, (y + h) - bounds[0])
  		overflowX = max(0, (x + w) - bounds[1])
  		x -= overflowX
  		w += overflowX
  		y -= overflowY
  		h += overflowY
  		
  		# If there are still overflows or underflows after our
  		# modifications, we have no choice but to clip them
  		x, y, w, h = padRect((x,y,w,h), 0, 0, 0, 0, bounds, True)
  	
  	# Re-pack the padded rect
  	return (x,y,w,h)
docs: Pads a rectangle by the specified values on each individual side,
  	ensuring the padded rectangle falls within the specified bounds.
  	
  	The input rectangle, bounds, and return value are all a tuple of (x,y,w,h).