From 483e0a55262326846a1f3181ab2642449caf8be7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 3 Mar 2019 13:34:50 +0100 Subject: [PATCH] SharedGraphics: Add Rect::center_within(Rect). --- SharedGraphics/Rect.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SharedGraphics/Rect.h b/SharedGraphics/Rect.h index dc095166f4..86fc790a9e 100644 --- a/SharedGraphics/Rect.h +++ b/SharedGraphics/Rect.h @@ -196,6 +196,12 @@ public: Point bottom_left() const { return { left(), bottom() }; } Point bottom_right() const { return { right(), bottom() }; } + void center_within(const Rect& other) + { + set_x(other.center().x() - width() / 2); + set_y(other.center().y() - height() / 2); + } + String to_string() const { return String::format("[%d,%d %dx%d]", x(), y(), width(), height()); } private: