1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

LibDraw: Add Rect::from_two_points(Point, Point)

This returns the rectangle between two given Points. Thanks Owlinator
for suggesting this much easier way of doing it :^)
This commit is contained in:
Andreas Kling 2019-11-17 16:36:43 +01:00
parent 32ff660aa5
commit 6685be36a0
2 changed files with 7 additions and 16 deletions

View file

@ -1,7 +1,7 @@
#pragma once
#include <AK/String.h>
#include <AK/LogStream.h>
#include <AK/String.h>
#include <LibDraw/Orientation.h>
#include <LibDraw/Point.h>
#include <LibDraw/Size.h>
@ -237,6 +237,11 @@ public:
void intersect(const Rect&);
static Rect from_two_points(const Point& a, const Point& b)
{
return { min(a.x(), b.x()), min(a.y(), b.y()), abs(a.x() - b.x()), abs(a.y() - b.y()) };
}
static Rect intersection(const Rect& a, const Rect& b)
{
Rect r(a);