13
0

add Rect::shrink(Distance) even though it arguably should be handled by Rect::expand()

This commit is contained in:
Paul Davis 2014-11-05 16:56:45 -05:00
parent f3d349bc9a
commit 857719f2e1
2 changed files with 19 additions and 0 deletions

View File

@ -94,6 +94,7 @@ struct LIBCANVAS_API Rect
Rect extend (Rect const &) const;
Rect translate (Duple) const;
Rect expand (Distance) const;
Rect shrink (Distance) const;
bool contains (Duple) const;
Rect fix () const;
bool empty() const { return (x0 == x1 && y0 == y1); }

View File

@ -102,6 +102,24 @@ Rect::expand (Distance amount) const
return r;
}
Rect
Rect::shrink (Distance amount) const
{
/* This isn't the equivalent of expand (-distance) because
of the peculiarities of safe_add() with negative values.
Maybe.
*/
Rect r;
r.x0 = safe_add (x0, amount);
r.y0 = safe_add (y0, amount);
r.x1 = x1 - amount;
r.y1 = y1 - amount;
return r;
}
bool
Rect::contains (Duple point) const
{