2019-01-09 02:06:04 +01:00
|
|
|
#include "Rect.h"
|
|
|
|
|
#include <AK/StdLibExtras.h>
|
2019-01-12 06:39:34 +01:00
|
|
|
#include "kstdio.h"
|
2019-01-09 02:06:04 +01:00
|
|
|
|
|
|
|
|
void Rect::intersect(const Rect& other)
|
|
|
|
|
{
|
|
|
|
|
int l = max(left(), other.left());
|
|
|
|
|
int r = min(right(), other.right());
|
|
|
|
|
int t = max(top(), other.top());
|
|
|
|
|
int b = min(bottom(), other.bottom());
|
|
|
|
|
|
|
|
|
|
if (l >= r || t >= b) {
|
|
|
|
|
m_location = { };
|
|
|
|
|
m_size = { };
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_location.setX(l);
|
|
|
|
|
m_location.setY(t);
|
2019-01-12 06:39:34 +01:00
|
|
|
m_size.setWidth((r - l) + 1);
|
|
|
|
|
m_size.setHeight((b - t) + 1);
|
2019-01-09 02:06:04 +01:00
|
|
|
}
|
2019-01-13 00:04:23 +01:00
|
|
|
|
|
|
|
|
Rect Rect::united(const Rect& other) const
|
|
|
|
|
{
|
|
|
|
|
Rect rect;
|
|
|
|
|
rect.set_left(min(left(), other.left()));
|
|
|
|
|
rect.set_top(min(top(), other.top()));
|
|
|
|
|
rect.set_right(max(right(), other.right()));
|
|
|
|
|
rect.set_bottom(max(bottom(), other.bottom()));
|
|
|
|
|
return rect;
|
|
|
|
|
}
|