def clip_box(box, max_width, max_height):
  """clipping a [x,y,w,h] boxes."""
  x, y, w, h = box

  if x + w > max_width:
    w = max_width - x
    w = 0.0 if w < 0 else w
  if y + h > max_height:
    h = max_height - y
    h = 0.0 if h < 0 else h

  if x > max_width:
    x = max_width
  if y > max_height:
    y = max_height

  return [x, y, w, h]