diff options
-rw-r--r-- | libs/canvas/canvas/types.h | 1 | ||||
-rw-r--r-- | libs/canvas/types.cc | 18 |
2 files changed, 19 insertions, 0 deletions
diff --git a/libs/canvas/canvas/types.h b/libs/canvas/canvas/types.h index 6d952794c9..ff9388f7ba 100644 --- a/libs/canvas/canvas/types.h +++ b/libs/canvas/canvas/types.h @@ -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); } diff --git a/libs/canvas/types.cc b/libs/canvas/types.cc index 4fd064d746..4c8cd854f2 100644 --- a/libs/canvas/types.cc +++ b/libs/canvas/types.cc @@ -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 { |