pub struct SpatialHitIndex { /* private fields */ }Expand description
Spatial index for efficient hit-testing with z-order support.
Provides O(1) average-case queries by bucketing widgets into a uniform grid. Supports dirty-rect caching to avoid recomputation of unchanged regions.
Implementations§
Source§impl SpatialHitIndex
impl SpatialHitIndex
Sourcepub fn new(width: u16, height: u16, config: SpatialHitConfig) -> Self
pub fn new(width: u16, height: u16, config: SpatialHitConfig) -> Self
Create a new spatial hit index for the given screen dimensions.
Sourcepub fn with_defaults(width: u16, height: u16) -> Self
pub fn with_defaults(width: u16, height: u16) -> Self
Create with default configuration.
Sourcepub fn register(
&mut self,
id: HitId,
rect: Rect,
region: HitRegion,
data: HitData,
z_order: u16,
)
pub fn register( &mut self, id: HitId, rect: Rect, region: HitRegion, data: HitData, z_order: u16, )
Register a widget hitbox.
§Arguments
id: Unique widget identifierrect: Bounding rectangleregion: Hit region typedata: User dataz_order: Z-order layer (higher = on top)
Sourcepub fn register_simple(
&mut self,
id: HitId,
rect: Rect,
region: HitRegion,
data: HitData,
)
pub fn register_simple( &mut self, id: HitId, rect: Rect, region: HitRegion, data: HitData, )
Register with default z-order (0).
Sourcepub fn update(&mut self, id: HitId, new_rect: Rect) -> bool
pub fn update(&mut self, id: HitId, new_rect: Rect) -> bool
Update an existing widget’s hitbox.
Returns true if widget was found and updated.
Sourcepub fn remove(&mut self, id: HitId) -> bool
pub fn remove(&mut self, id: HitId) -> bool
Remove a widget from the index.
Returns true if widget was found and removed.
Sourcepub fn hit_test(
&mut self,
x: u16,
y: u16,
) -> Option<(HitId, HitRegion, HitData)>
pub fn hit_test( &mut self, x: u16, y: u16, ) -> Option<(HitId, HitRegion, HitData)>
Hit test at the given position.
Returns the topmost (highest z-order) widget at (x, y), if any.
§Performance
- O(1) average case with cache hit
- O(k) where k = widgets overlapping the bucket cell
Sourcepub fn hit_test_readonly(
&self,
x: u16,
y: u16,
) -> Option<(HitId, HitRegion, HitData)>
pub fn hit_test_readonly( &self, x: u16, y: u16, ) -> Option<(HitId, HitRegion, HitData)>
Hit test without modifying cache (for read-only queries).
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get diagnostic statistics.
Sourcepub fn reset_stats(&mut self)
pub fn reset_stats(&mut self)
Reset diagnostic statistics.
Sourcepub fn invalidate_region(&mut self, rect: Rect)
pub fn invalidate_region(&mut self, rect: Rect)
Invalidate cache for a specific region.
Sourcepub fn invalidate_all(&mut self)
pub fn invalidate_all(&mut self)
Force full cache invalidation.