Skip to main content

SpatialIndex

Trait SpatialIndex 

Source
pub trait SpatialIndex: Send + Debug {
    // Required methods
    fn insert(&mut self, id: ItemId, bounds: Rect);
    fn remove(&mut self, id: ItemId);
    fn query(&self, scene_rect: Rect) -> Vec<ItemId>;
    fn contains(&self, id: ItemId) -> bool;
    fn len(&self) -> usize;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A spatial index over ItemIds keyed by axis-aligned scene rectangles. Used by Scene for items_in_rect queries and by SceneView for viewport culling.

Required Methods§

Source

fn insert(&mut self, id: ItemId, bounds: Rect)

Insert or update an item’s bounds. Calling insert again with the same id replaces the previous bounds (re-buckets the item). Equivalent to remove(id); insert(id, bounds); on implementations that need an explicit update path.

Source

fn remove(&mut self, id: ItemId)

Remove an item. No-op if id is not present.

Source

fn query(&self, scene_rect: Rect) -> Vec<ItemId>

Items whose bounds intersect scene_rect, in implementation- defined order. The result is deduplicated. May include false positives (items in cells the rect overlaps but whose bounds don’t actually intersect) — callers that need exact intersection narrow with a per-item check.

Source

fn contains(&self, id: ItemId) -> bool

Whether id is currently in the index.

Source

fn len(&self) -> usize

Total number of items in the index.

Provided Methods§

Source

fn is_empty(&self) -> bool

Whether the index is empty.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§