pub struct DirtyRegion {
pub rect: Rect,
pub timestamp: Instant,
pub priority: u8,
pub component_id: Option<String>,
}Expand description
Represents a dirty region that needs re-rendering.
Dirty regions are rectangular areas marked for update due to content changes. The system automatically merges overlapping or adjacent regions to optimize rendering performance and reduce the number of draw calls.
§Invariants
rect.width > 0 && rect.height > 0- region must have positive areapriority <= 255- priority is bounded by u8timestampreflects when the region was created
§Memory Layout
Designed to be memory-efficient with total size of ~40 bytes including optional component ID string.
Fields§
§rect: RectThe rectangular area that needs updating
timestamp: InstantWhen this region was marked dirty
priority: u8Priority of this update (higher = more urgent)
component_id: Option<String>Optional component ID that owns this region
Implementations§
Source§impl DirtyRegion
impl DirtyRegion
Sourcepub fn with_priority(rect: Rect, priority: u8) -> Self
pub fn with_priority(rect: Rect, priority: u8) -> Self
Create a dirty region with priority
Sourcepub fn with_component(rect: Rect, component_id: String) -> Self
pub fn with_component(rect: Rect, component_id: String) -> Self
Create a dirty region with component ID
Sourcepub fn intersects(&self, other: &Rect) -> bool
pub fn intersects(&self, other: &Rect) -> bool
Check if this region intersects with another rectangle.
Uses the separating axis theorem: two rectangles intersect if and only if they overlap on both the X and Y axes.
§Algorithm
Two rectangles DON’T intersect if:
- Rectangle A is completely to the left of B, OR
- Rectangle A is completely to the right of B, OR
- Rectangle A is completely above B, OR
- Rectangle A is completely below B
§Time Complexity
O(1) - constant time with 4 comparisons
§Example
use hojicha_rendering::differential::DirtyRegion;
use ratatui::layout::Rect;
let region = DirtyRegion::new(Rect::new(0, 0, 10, 10));
assert!(region.intersects(&Rect::new(5, 5, 10, 10))); // overlapping
assert!(!region.intersects(&Rect::new(20, 20, 10, 10))); // separateSourcepub fn try_merge(&mut self, other: &DirtyRegion) -> bool
pub fn try_merge(&mut self, other: &DirtyRegion) -> bool
Merge with another dirty region if they overlap or are adjacent.
This implements the core region coalescing algorithm that reduces the number of separate render operations by combining nearby regions.
§Algorithm
- Check if regions intersect or are adjacent
- If mergeable, compute bounding rectangle
- Update metadata (priority, timestamp, component_id)
- Validate the resulting region
§Merge Policy
- Priority: Takes the maximum of both priorities
- Timestamp: Takes the more recent timestamp
- Component ID: Clears if components differ (becomes generic region)
§Returns
true if merge occurred, false if regions are not mergeable.
§Time Complexity
O(1) - constant time arithmetic operations
§Panics
In debug builds, panics if the resulting region would have zero area or if coordinate arithmetic would overflow.
Trait Implementations§
Source§impl Clone for DirtyRegion
impl Clone for DirtyRegion
Source§fn clone(&self) -> DirtyRegion
fn clone(&self) -> DirtyRegion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DirtyRegion
impl Debug for DirtyRegion
Source§impl PartialEq for DirtyRegion
impl PartialEq for DirtyRegion
impl Eq for DirtyRegion
impl StructuralPartialEq for DirtyRegion
Auto Trait Implementations§
impl Freeze for DirtyRegion
impl RefUnwindSafe for DirtyRegion
impl Send for DirtyRegion
impl Sync for DirtyRegion
impl Unpin for DirtyRegion
impl UnsafeUnpin for DirtyRegion
impl UnwindSafe for DirtyRegion
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more