From 30c831a3bee41dd7ab0a5908e1ba6940f1a15da7 Mon Sep 17 00:00:00 2001 From: Dmitrii Ubskii Date: Fri, 11 Jun 2021 15:11:07 +0300 Subject: [PATCH] LibGfx: Add Rect::centered_on() This is a helper function for creating Rects of a given Size centered on a Point. --- Userland/Libraries/LibGfx/Rect.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Userland/Libraries/LibGfx/Rect.h b/Userland/Libraries/LibGfx/Rect.h index 9b4138d12a..77e58a827d 100644 --- a/Userland/Libraries/LibGfx/Rect.h +++ b/Userland/Libraries/LibGfx/Rect.h @@ -422,6 +422,11 @@ public: void intersect(const Rect&); + static Rect centered_on(const Point& center, const Size& size) + { + return { { center.x() - size.width() / 2, center.y() - size.height() / 2 }, size }; + } + static Rect from_two_points(const Point& a, const Point& b) { return { min(a.x(), b.x()), min(a.y(), b.y()), abst(a.x() - b.x()), abst(a.y() - b.y()) };