pub fn rectangle_union(a: &Rect, b: &Rect) -> RectExpand description
Rectangle union (bounding box) calculation.
Computes the smallest rectangle that contains both input rectangles. This is used in region merging to create the combined dirty area.
§Algorithm
- Find minimum X and Y coordinates (top-left corner)
- Find maximum X+width and Y+height coordinates (bottom-right corner)
- Compute width and height from corners
§Complexity
- Time: O(1) - arithmetic operations only
- Space: O(1) - no additional memory allocation
§Overflow Handling
Uses saturating arithmetic to handle coordinate overflow gracefully. Large coordinates are clamped to u16::MAX rather than wrapping.
§Examples
use hojicha_rendering::algorithms::rectangle_union;
use ratatui::layout::Rect;
let a = Rect::new(0, 0, 10, 10);
let b = Rect::new(5, 5, 10, 10);
let union = rectangle_union(&a, &b);
assert_eq!(union, Rect::new(0, 0, 15, 15));