From fcf5b1ff5bbcb2ad407265d8910167d1d5d24e41 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 16 Sep 2019 20:56:23 +0200 Subject: [PATCH] Rect: Add set_right_without_resize() and set_bottom_without_resize() Sometimes you want to move the Rect by its right or bottom edge without resizing the rect in the process. There are probably better names for this but nothing comes to mind at the moment. --- Libraries/LibDraw/Rect.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Libraries/LibDraw/Rect.h b/Libraries/LibDraw/Rect.h index a756bd8e55..25cf87d7a9 100644 --- a/Libraries/LibDraw/Rect.h +++ b/Libraries/LibDraw/Rect.h @@ -192,6 +192,18 @@ public: set_height(bottom - y() + 1); } + void set_right_without_resize(int new_right) + { + int delta = new_right - right(); + move_by(delta, 0); + } + + void set_bottom_without_resize(int new_bottom) + { + int delta = new_bottom - bottom(); + move_by(0, delta); + } + bool intersects(const Rect& other) const { return left() <= other.right()