mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 21:38:11 +00:00
SharedGraphics: Minor tweaks in rect shattering code.
This commit is contained in:
parent
57546d8420
commit
210646edd2
2 changed files with 3 additions and 5 deletions
|
@ -15,13 +15,13 @@ void DisjointRectSet::add(const Rect& new_rect)
|
||||||
void DisjointRectSet::shatter()
|
void DisjointRectSet::shatter()
|
||||||
{
|
{
|
||||||
Vector<Rect> output;
|
Vector<Rect> output;
|
||||||
|
output.ensure_capacity(m_rects.size());
|
||||||
bool pass_had_intersections = false;
|
bool pass_had_intersections = false;
|
||||||
do {
|
do {
|
||||||
pass_had_intersections = false;
|
pass_had_intersections = false;
|
||||||
output.clear_with_capacity();
|
output.clear_with_capacity();
|
||||||
for (size_t i = 0; i < m_rects.size(); ++i) {
|
for (size_t i = 0; i < m_rects.size(); ++i) {
|
||||||
auto& r1 = m_rects[i];
|
auto& r1 = m_rects[i];
|
||||||
bool r1_had_intersections = false;
|
|
||||||
for (size_t j = 0; j < m_rects.size(); ++j) {
|
for (size_t j = 0; j < m_rects.size(); ++j) {
|
||||||
if (i == j)
|
if (i == j)
|
||||||
continue;
|
continue;
|
||||||
|
@ -37,8 +37,7 @@ void DisjointRectSet::shatter()
|
||||||
output.append(m_rects[i]);
|
output.append(m_rects[i]);
|
||||||
goto next_pass;
|
goto next_pass;
|
||||||
}
|
}
|
||||||
if (!r1_had_intersections)
|
output.append(r1);
|
||||||
output.append(r1);
|
|
||||||
}
|
}
|
||||||
next_pass:
|
next_pass:
|
||||||
swap(output, m_rects);
|
swap(output, m_rects);
|
||||||
|
|
|
@ -39,7 +39,6 @@ Vector<Rect> Rect::shatter(const Rect& hammer) const
|
||||||
Vector<Rect> pieces;
|
Vector<Rect> pieces;
|
||||||
if (!intersects(hammer)) {
|
if (!intersects(hammer)) {
|
||||||
pieces.append(*this);
|
pieces.append(*this);
|
||||||
pieces.append(hammer);
|
|
||||||
return pieces;
|
return pieces;
|
||||||
}
|
}
|
||||||
Rect top_shard {
|
Rect top_shard {
|
||||||
|
@ -63,7 +62,7 @@ Vector<Rect> Rect::shatter(const Rect& hammer) const
|
||||||
Rect right_shard {
|
Rect right_shard {
|
||||||
hammer.x() + hammer.width(),
|
hammer.x() + hammer.width(),
|
||||||
max(hammer.y(), y()),
|
max(hammer.y(), y()),
|
||||||
(x() + width() - 1) - (hammer.x() + hammer.width() - 1),
|
right() - hammer.right(),
|
||||||
min((hammer.y() + hammer.height()), (y() + height())) - max(hammer.y(), y())
|
min((hammer.y() + hammer.height()), (y() + height())) - max(hammer.y(), y())
|
||||||
};
|
};
|
||||||
if (intersects(top_shard))
|
if (intersects(top_shard))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue