This matrix shows what happens in each case:
in all cases: sX = 0; sY = 0; sW = width; sH = height;
north: tX = 0; tY = 0; tW = sW; tH = sizeH; wX = 0; wY = tH; wW = sW; wH = sH - sizeH; sizeW=0, sizeH=size
south: tX = 0; tY = sH - sizeH; tW = sW; tH = sizeH; wX = 0; wY = 0; wW = sW; wH = sH - sizeH; sizeW=0, sizeH=size
east : tX = 0; tY = 0; tW = sizeW; tH = sH; wX = sizeW; wY = 0; wW = sW - sizeW; wH = sH ; sizeW=size, sizeH=0
west : tX = sW - sizeW; tY = 0; tW = sizeW; tH = sH; wX = 0; wY = 0; wW = sW - sizeW; wH = sH ; sizeW=size, sizeH=0
which we can generalize into:
in all cases: sX = 0; sY = 0; sW = width; sH = height;
north: tX = 0; tY = 0; tW = sW; tH = sizeH; wX = 0; wY = tH; wW = sW - sizeW; wH = sH - sizeH; sizeW=0, sizeH=value
south: tX = 0; tY = sH - sizeH; tW = sW; tH = sizeH; wX = 0; wY = 0; wW = sW - sizeW; wH = sH - sizeH; sizeW=0, sizeH=value
east : tX = 0; tY = 0; tW = sizeW; tH = sH; wX = tW; wY = 0; wW = sW - sizeW; wH = sH - sizeH; sizeW=value, sizeH=0
west : tX = sW - sizeW; tY = 0; tW = sizeW; tH = sH; wX = 0; wY = 0; wW = sW - sizeW; wH = sH - sizeH; sizeW=value, sizeH=0
the matrix revealed this algorithm:
if (east/west) sizeW = tW; else sizeW = 0;
if (north/south) sizeH = tH; else sizeH = 0;
wX = 0; wY = 0; wW = sW - sizeW; wH = sH - sizeH;
if (east) wX = sizeW;
if (north) wY = sizeH;
which in C/C++/Java and other similar languages can be written as:
sizeW = (tH == sH) ? tW : 0;
sizeH = (tW == sW) ? tH : 0;
wX = (sizeH == 0 && tX == 0) ? sizeW : 0;
wY = (sizeW == 0 && tY == 0) ? sizeH : 0;
wW = sW - sizeW;
wH = sH - sizeH;
This seems to be correct for the case you've given. I haven't re-checked for the other cases though, so I may have made a mistake.
EDIT:
after a bit more thinking, I think I found the optimum selection:
wW = sW - ((tH == sH) ? tW : 0);
wH = sH - ((tW == sW) ? tH : 0);
wX = (wH == sH && tX == 0) ? tW : 0;
wY = (wW == sW && tY == 0) ? tH : 0;