intersection method

Rect intersection(
  1. Rect other
)

Returns the overlapping area with other.

Implementation

Rect intersection(Rect other) {
  final x1 = x > other.x ? x : other.x;
  final y1 = y > other.y ? y : other.y;
  final x2 = right < other.right ? right : other.right;
  final y2 = bottom < other.bottom ? bottom : other.bottom;
  final w = (x2 - x1).clamp(0, 0xFFFF);
  final h = (y2 - y1).clamp(0, 0xFFFF);
  return Rect(x1, y1, w, h);
}