Skip to main content

SpatialHitIndex

Struct SpatialHitIndex 

Source
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

Source

pub fn new(width: u16, height: u16, config: SpatialHitConfig) -> Self

Create a new spatial hit index for the given screen dimensions.

Source

pub fn with_defaults(width: u16, height: u16) -> Self

Create with default configuration.

Source

pub fn register( &mut self, id: HitId, rect: Rect, region: HitRegion, data: HitData, z_order: u16, )

Register a widget hitbox.

§Arguments
  • id: Unique widget identifier
  • rect: Bounding rectangle
  • region: Hit region type
  • data: User data
  • z_order: Z-order layer (higher = on top)
Source

pub fn register_simple( &mut self, id: HitId, rect: Rect, region: HitRegion, data: HitData, )

Register with default z-order (0).

Source

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.

Source

pub fn remove(&mut self, id: HitId) -> bool

Remove a widget from the index.

Returns true if widget was found and removed.

Source

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
Source

pub fn hit_test_readonly( &self, x: u16, y: u16, ) -> Option<(HitId, HitRegion, HitData)>

Hit test without modifying cache (for read-only queries).

Source

pub fn clear(&mut self)

Clear all entries and reset the index.

Source

pub fn stats(&self) -> CacheStats

Get diagnostic statistics.

Source

pub fn reset_stats(&mut self)

Reset diagnostic statistics.

Source

pub fn len(&self) -> usize

Number of registered widgets.

Source

pub fn is_empty(&self) -> bool

Check if empty.

Source

pub fn invalidate_region(&mut self, rect: Rect)

Invalidate cache for a specific region.

Source

pub fn invalidate_all(&mut self)

Force full cache invalidation.

Trait Implementations§

Source§

impl Debug for SpatialHitIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.