intersect method
Calculates the intersection of this rectangle with another rectangle.
other The other rectangle to intersect with.
Returns a new IntRect representing the intersection area.
If there is no intersection, returns an empty rectangle (width and height of 0).
Implementation
IntRect intersect(final IntRect other) {
final int newLeft = max(left, other.left);
final int newTop = max(top, other.top);
final int newRight = min(right, other.right);
final int newBottom = min(bottom, other.bottom);
// Check if there is a valid intersection
if (newLeft >= newRight || newTop >= newBottom) {
// No intersection, return empty rectangle
return IntRect.zero;
}
return IntRect.fromLTRB(newLeft, newTop, newRight, newBottom);
}