shrink method
Create a new Rect by shrinking all four sides of this rectangle inwards
by the given amount
. Calling with a negative amount
will return an
expanded Rect.
Note that this will not shrink the rectangle beyond size zero.
Implementation
Rect shrink(int amount) {
if (amount == 0) return this;
if (amount < 0) return expand(amount.abs());
int t, b, l, r;
if (size.x < amount * 2) {
l = r = position.x;
} else {
l = left + amount;
r = right - amount;
}
if (size.y < amount * 2) {
t = b = position.y;
} else {
t = top + amount;
b = bottom - amount;
}
return Rect.sides(t, r, b, l);
}