intersect method

Rect intersect(
  1. Rect other
)

Calculates the intersection rectangle between this and other.

Implementation

Rect intersect(Rect other) {
  final newLeft = left > other.left ? left : other.left;
  final newTop = top > other.top ? top : other.top;
  final newRight = right < other.right ? right : other.right;
  final newBottom = bottom < other.bottom ? bottom : other.bottom;
  final newWidth = (newRight - newLeft) < 0 ? 0 : newRight - newLeft;
  final newHeight = (newBottom - newTop) < 0 ? 0 : newBottom - newTop;
  return Rect(newLeft, newTop, newWidth, newHeight);
}