intersect method

Rectangle intersect(
  1. Rectangle other
)

Returns a new rectangle that is the intersection of the given rectangle and this rectangle. The two rectangles must overlap for this to be meaningful. If the two rectangles do not overlap, then the resulting Rect will have a negative width or height.

Implementation

Rectangle intersect(Rectangle other) {
  return Rectangle.fromLTRB(
      math.max(left, other.left),
      math.max(top, other.top),
      math.min(right, other.right),
      math.min(bottom, other.bottom));
}