Skip to main content

ViewportIndex

Struct ViewportIndex 

Source
pub struct ViewportIndex { /* private fields */ }
Expand description

R-tree spatial index with a lazy-rebuild incremental-update policy. Construct with ViewportIndex::new and populate with ViewportIndex::rebuild.

Implementations§

Source§

impl ViewportIndex

Source

pub fn new() -> Self

Source

pub fn len(&self) -> usize

Number of points currently indexed (or pending in the dirty buffer — the state map is the source of truth).

Source

pub fn is_empty(&self) -> bool

Source

pub fn rebuild(&mut self, points: &[IndexPoint])

Bulk-load the index from points. O(n log n) via rstar’s STR packing. Clears any pending updates.

Source

pub fn update_positions(&mut self, changes: &[(u32, Vec2)])

Apply a batch of (id, new_position) updates. Updates are stored in an internal position cache immediately; the R-tree itself is rebuilt only when the dirty count crosses max(1000, n / 20). Amortised O(1) per update.

Source

pub fn query( &self, min: Vec2, max: Vec2, limit: usize, order: ScoreKey, ) -> Vec<u32>

Return the ids whose current position falls inside the axis-aligned box [min, max], optionally truncated and ordered.

The tree may be slightly out-of-date relative to the state map between rebuilds — callers who need point-in-time accuracy should call rebuild before querying. For the viewport use case a handful of frames of drift is fine (the user’s viewport is typically moving faster than the simulation is drifting).

Source

pub fn query_with_scores( &self, min: Vec2, max: Vec2, limit: usize, order: ScoreKey, ) -> Vec<(u32, f32)>

Return the (id, score) pairs inside the axis-aligned box, optionally truncated and ordered.

Added in Phase 223 Wave 3. Same semantics as Self::query but exposes the associated score so the PyO3 surface can return both without a second lookup. The id-only Self::query stays as a convenience for callers (including the WASM crate) that already ignore the score.

Source

pub fn snapshot(&self) -> Vec<IndexPoint>

Snapshot the indexed points — a clone of the internal state map’s values, in unspecified order.

Phase 223 Wave 3: used by the PyO3 surface to hand the point set to bincode for Redis snapshotting. The tree itself isn’t serialised; callers rebuild it in O(n log n) from the returned slice via Self::rebuild.

Trait Implementations§

Source§

impl Default for ViewportIndex

Source§

fn default() -> Self

Returns the “default value” for a type. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V