mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:47:34 +00:00
LibGfx: Add convenience helpers for Rect
This commit is contained in:
parent
a43ba348e1
commit
f8903acea2
1 changed files with 39 additions and 1 deletions
|
@ -43,7 +43,7 @@ T abst(T value)
|
|||
template<typename T>
|
||||
class Rect {
|
||||
public:
|
||||
Rect() {}
|
||||
Rect() { }
|
||||
|
||||
Rect(T x, T y, T width, T height)
|
||||
: m_location(x, y)
|
||||
|
@ -191,6 +191,18 @@ public:
|
|||
&& bottom() >= other.bottom();
|
||||
}
|
||||
|
||||
template<typename Container>
|
||||
bool contains(const Container& others) const
|
||||
{
|
||||
bool have_any = false;
|
||||
for (const auto& other : others) {
|
||||
if (!contains(other))
|
||||
return false;
|
||||
have_any = true;
|
||||
}
|
||||
return have_any;
|
||||
}
|
||||
|
||||
int primary_offset_for_orientation(Orientation orientation) const { return m_location.primary_offset_for_orientation(orientation); }
|
||||
void set_primary_offset_for_orientation(Orientation orientation, int value) { m_location.set_primary_offset_for_orientation(orientation, value); }
|
||||
int secondary_offset_for_orientation(Orientation orientation) const { return m_location.secondary_offset_for_orientation(orientation); }
|
||||
|
@ -270,6 +282,32 @@ public:
|
|||
&& other.top() <= bottom();
|
||||
}
|
||||
|
||||
template<typename Container>
|
||||
bool intersects(const Container& others) const
|
||||
{
|
||||
for (const auto& other : others) {
|
||||
if (intersects(other))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename Container, typename Function>
|
||||
IterationDecision for_each_intersected(const Container& others, Function f) const
|
||||
{
|
||||
if (is_empty())
|
||||
return IterationDecision::Continue;
|
||||
for (const auto& other : others) {
|
||||
auto intersected_rect = intersected(other);
|
||||
if (!intersected_rect.is_empty()) {
|
||||
IterationDecision decision = f(intersected_rect);
|
||||
if (decision != IterationDecision::Continue)
|
||||
return decision;
|
||||
}
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
}
|
||||
|
||||
T x() const { return location().x(); }
|
||||
T y() const { return location().y(); }
|
||||
T width() const { return m_size.width(); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue