Skip to main content

ContactCache

Struct ContactCache 

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

Per-step contact impulses, keyed by feature, for warm starting.

Usage is two calls per step around the solve: ContactCache::warm_start before it to build the seed vector, ContactCache::store after it to record the result. store replaces the whole table rather than merging, so contacts that ended are dropped and the cache cannot grow without bound.

Implementations§

Source§

impl ContactCache

Source

pub const DEFAULT_CELL: f64 = 2e-3

Default quantization cell, in metres.

Coarse enough to absorb the sub-millimetre wander of a narrow-phase contact point on a resting face, fine enough to keep the corners of a centimetre-scale box distinct.

Source

pub fn new(cell: f64) -> Self

Create a cache with a given quantization cell size, in metres.

Source

pub fn key(&self, state: &State, c: &Collision) -> ContactKey

The feature key for one contact at the current state.

Source

pub fn warm_start(&mut self, state: &State, contacts: &[Collision]) -> Vec<Vec3> ⓘ

Seed impulses for contacts, in the same order, from the previous step.

Contacts with no cached match seed at zero, which is exactly the cold start. The returned vector is what crate::solve_contacts_warm takes.

Source

pub fn store( &mut self, state: &State, contacts: &[Collision], impulses: &[Vec3], )

Record the solved impulses for the next step’s warm start.

Source

pub fn clear(&mut self)

Forget every cached contact. Call after teleporting or resetting a state, where last step’s impulses are not a guess about this step.

Source

pub fn stats(&self) -> (usize, usize)

(hits, misses) since construction or the last Self::clear.

A persistently low hit rate on a body that is visibly resting means the key is not identifying the feature — the cell size is likely wrong for the scale of the model.

Source

pub fn len(&self) -> usize

Number of contacts currently remembered.

Source

pub fn is_empty(&self) -> bool

Whether anything is remembered.

Trait Implementations§

Source§

impl Clone for ContactCache

Source§

fn clone(&self) -> ContactCache

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContactCache

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ContactCache

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.