function getClipRect(clip) {
    var minX = Number.MAX_VALUE;
    var minY = Number.MAX_VALUE;
    var maxX = -Number.MAX_VALUE;
    var maxY = -Number.MAX_VALUE;
    for (var i = 0; i < clip.length; i += 2) {
      var x = clip[i];
      var y = clip[i + 1];
      minX = Math.min(minX, x);
      minY = Math.min(minY, y);
      maxX = Math.max(maxX, x);
      maxY = Math.max(maxY, y);
    }
    if (minX == Number.MAX_VALUE) {
      return null;
    }
    return [minX, minY, maxX - minX, maxY - minY];
  }
Attempts to get the bounding rectangle from clip points.
@param {!Array.<number>} clip Clip points.
@return {Array.<number>} The [x,y,w,h] rect or null invalid.