intersection method

  1. @override
Rectangle<T> intersection(
  1. Rectangle<T> rect
)

Computes the intersection of this and other.

The intersection of two axis-aligned rectangles, if any, is always another axis-aligned rectangle.

Returns the intersection of this and other, or null if they don't intersect.

Implementation

@override
Rectangle<T> intersection(math.Rectangle<T> rect) {
  final rLeft = max(left, rect.left);
  final rTop = max(top, rect.top);
  final rRight = min(right, rect.right);
  final rBottom = min(bottom, rect.bottom);
  return Rectangle<T>(rLeft, rTop, rRight - rLeft as T, rBottom - rTop as T);
}