space: Handle multiple overlapping rects when merging damage
This commit is contained in:
parent
8c126eeb80
commit
a53d64053f
|
@ -557,12 +557,15 @@ impl Space {
|
||||||
damage.retain(|rect| rect.overlaps(output_geo));
|
damage.retain(|rect| rect.overlaps(output_geo));
|
||||||
damage.retain(|rect| rect.size.h > 0 && rect.size.w > 0);
|
damage.retain(|rect| rect.size.h > 0 && rect.size.w > 0);
|
||||||
// merge overlapping rectangles
|
// merge overlapping rectangles
|
||||||
damage = damage.into_iter().fold(Vec::new(), |mut new_damage, rect| {
|
damage = damage.into_iter().fold(Vec::new(), |new_damage, mut rect| {
|
||||||
if let Some(existing) = new_damage.iter_mut().find(|other| rect.overlaps(**other)) {
|
// replace with drain_filter, when that becomes stable to reuse the original Vec's memory
|
||||||
*existing = existing.merge(rect);
|
let (overlapping, mut new_damage): (Vec<_>, Vec<_>) =
|
||||||
} else {
|
new_damage.into_iter().partition(|other| other.overlaps(rect));
|
||||||
new_damage.push(rect);
|
|
||||||
|
for overlap in overlapping {
|
||||||
|
rect = rect.merge(overlap);
|
||||||
}
|
}
|
||||||
|
new_damage.push(rect);
|
||||||
new_damage
|
new_damage
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue