fitInto method

void fitInto(
  1. Rect rect
)

Fit this rectangle into the other rectangle by resizing it

Implementation

void fitInto(Rect rect)
{
  // left constriant
  if (left < rect.left) {
    width -= rect.left - left;
    left = rect.left;
  }
  // top constriant
  if (top < rect.top) {
    height -= rect.top - top;
    top = rect.top;
  }
  // width constraint
  width = Math.min(width + left, rect.width + rect.left) - left;
  // height constraint
  height = Math.min(height + top, rect.height + rect.top) - top;
}