code: public static void shiftToContain (Rectangle tainer, Rectangle tained)
      {
          if (tained.x < tainer.x) {
              tainer.x = tained.x;
          }
          if (tained.y < tainer.y) {
              tainer.y = tained.y;
          }
          if (tained.x + tained.width > tainer.x + tainer.width) {
              tainer.x = tained.x - (tainer.width - tained.width);
          }
          if (tained.y + tained.height > tainer.y + tainer.height) {
              tainer.y = tained.y - (tainer.height - tained.height);
          }
      }
docs: Shifts the position of the <code>tainer</code> rectangle to ensure that it contains the
  <code>tained</code> rectangle. The <code>tainer</code> rectangle must be larger than or
  equal to the size of the <code>tained</code> rectangle.