1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 09:58:14 +00:00

LibGfx: Add Rect::centered_on()

This is a helper function for creating Rects of a given Size centered
on a Point.
This commit is contained in:
Dmitrii Ubskii 2021-06-11 15:11:07 +03:00 committed by Andreas Kling
parent 11158c2400
commit 30c831a3be

View file

@ -422,6 +422,11 @@ public:
void intersect(const Rect<T>&);
static Rect<T> centered_on(const Point<T>& center, const Size<T>& size)
{
return { { center.x() - size.width() / 2, center.y() - size.height() / 2 }, size };
}
static Rect<T> from_two_points(const Point<T>& a, const Point<T>& b)
{
return { min(a.x(), b.x()), min(a.y(), b.y()), abst(a.x() - b.x()), abst(a.y() - b.y()) };