function clipRectByRect(targetRect, rect) {
  var x = graphic_mathMax(targetRect.x, rect.x);
  var x2 = graphic_mathMin(targetRect.x + targetRect.width, rect.x + rect.width);
  var y = graphic_mathMax(targetRect.y, rect.y);
  var y2 = graphic_mathMin(targetRect.y + targetRect.height, rect.y + rect.height); // If the total rect is cliped, nothing, including the border,
  // should be painted. So return undefined.

  if (x2 >= x && y2 >= y) {
    return {
      x: x,
      y: y,
      width: x2 - x,
      height: y2 - y
    };
  }
}
Return a new clipped rect. If rect size are negative, return undefined.