Function coalesce_damage
pub fn coalesce_damage(
rects: Vec<FineDamageRect>,
limit: usize,
) -> Vec<FineDamageRect>Expand description
rects without the ones another contains, merged down to at most limit rectangles when
there are more. Each merge joins the pair whose union adds the least area, so a caret blinking
at one place stays one small rectangle however many frames repeated it. Merging only ever
repaints more than the damage, which is correct; it never loses a pixel.
Every rectangle remembers its cheapest partner, so a merge costs one pass to update the others against the merged rectangle instead of a search over every pair: quadratic overall where the search was cubic. A rectangle whose partner was merged away and that finds the merged one dearer keeps its old cost as a lower bound and looks again only when that bound is the cheapest merge left.