Skip to content

Commit 210646e

Browse files
committed
SharedGraphics: Minor tweaks in rect shattering code.
1 parent 57546d8 commit 210646e

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

SharedGraphics/DisjointRectSet.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ void DisjointRectSet::add(const Rect& new_rect)
1515
void DisjointRectSet::shatter()
1616
{
1717
Vector<Rect> output;
18+
output.ensure_capacity(m_rects.size());
1819
bool pass_had_intersections = false;
1920
do {
2021
pass_had_intersections = false;
2122
output.clear_with_capacity();
2223
for (size_t i = 0; i < m_rects.size(); ++i) {
2324
auto& r1 = m_rects[i];
24-
bool r1_had_intersections = false;
2525
for (size_t j = 0; j < m_rects.size(); ++j) {
2626
if (i == j)
2727
continue;
@@ -37,8 +37,7 @@ void DisjointRectSet::shatter()
3737
output.append(m_rects[i]);
3838
goto next_pass;
3939
}
40-
if (!r1_had_intersections)
41-
output.append(r1);
40+
output.append(r1);
4241
}
4342
next_pass:
4443
swap(output, m_rects);

SharedGraphics/Rect.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ Vector<Rect> Rect::shatter(const Rect& hammer) const
3939
Vector<Rect> pieces;
4040
if (!intersects(hammer)) {
4141
pieces.append(*this);
42-
pieces.append(hammer);
4342
return pieces;
4443
}
4544
Rect top_shard {
@@ -63,7 +62,7 @@ Vector<Rect> Rect::shatter(const Rect& hammer) const
6362
Rect right_shard {
6463
hammer.x() + hammer.width(),
6564
max(hammer.y(), y()),
66-
(x() + width() - 1) - (hammer.x() + hammer.width() - 1),
65+
right() - hammer.right(),
6766
min((hammer.y() + hammer.height()), (y() + height())) - max(hammer.y(), y())
6867
};
6968
if (intersects(top_shard))

0 commit comments

Comments
 (0)