Skip to main content

SimulationSnapshot

Struct SimulationSnapshot 

Source
pub struct SimulationSnapshot {
    pub version: u32,
    pub time: f64,
    pub gravity: [f64; 3],
    pub bodies: Vec<SimBodyState>,
    pub contacts: Vec<PyContactResult>,
    pub sleeping_count: usize,
    pub description: Option<String>,
    pub metadata: HashMap<String, String>,
}
Expand description

A complete snapshot of simulation state at a particular moment.

Fields§

§version: u32

Snapshot format version (currently 1).

§time: f64

Simulation time when the snapshot was taken.

§gravity: [f64; 3]

Gravity vector [gx, gy, gz] at snapshot time.

§bodies: Vec<SimBodyState>

State of every live body at snapshot time.

§contacts: Vec<PyContactResult>

Contacts active at snapshot time (informational).

§sleeping_count: usize

Number of sleeping bodies at snapshot time.

§description: Option<String>

Optional human-readable description.

§metadata: HashMap<String, String>

Arbitrary key-value metadata.

Implementations§

Source§

impl SimulationSnapshot

Source

pub const FORMAT_VERSION: u32 = 1

Current snapshot format version.

Source

pub fn empty() -> Self

Create an empty snapshot at time zero.

Source

pub fn body_count(&self) -> usize

Number of active bodies in this snapshot.

Source

pub fn sleeping_count(&self) -> usize

Number of sleeping bodies in this snapshot.

Source

pub fn find_body(&self, handle: u32) -> Option<&SimBodyState>

Find a body by its handle.

Source

pub fn find_by_tag(&self, tag: &str) -> Option<&SimBodyState>

Find a body by its tag.

Source

pub fn total_kinetic_energy_proxy(&self) -> f64

Total kinetic-energy proxy across all non-sleeping bodies.

Source

pub fn to_pretty_json(&self) -> String

Return the snapshot as a pretty-printed JSON string.

Source

pub fn to_json(&self) -> String

Serialize to compact JSON.

Source

pub fn from_json(json: &str) -> Result<Self, Error>

Deserialize from JSON.

Source

pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Add a metadata key-value pair.

Source

pub fn with_description(self, desc: impl Into<String>) -> Self

Set a human-readable description.

Source

pub fn to_msgpack(&self) -> Vec<u8>

Serialize to MessagePack bytes.

Source

pub fn from_msgpack(data: &[u8]) -> Result<Self, Error>

Deserialize from MessagePack bytes.

Source

pub fn static_body_count(&self) -> usize

Count of static bodies.

Source

pub fn dynamic_body_count(&self) -> usize

Count of dynamic (non-static) bodies.

Source

pub fn handles(&self) -> Vec<u32>

All body handles.

Source

pub fn find_by_tag_prefix(&self, prefix: &str) -> Vec<&SimBodyState>

Filter bodies by tag prefix.

Source§

impl SimulationSnapshot

Source

pub fn diff( &self, other: &SimulationSnapshot, position_threshold: f64, ) -> SnapshotDiff

Compute the diff between self (snapshot A) and other (snapshot B).

A body is considered “moved” if its position changed by more than position_threshold.

Trait Implementations§

Source§

impl Clone for SimulationSnapshot

Source§

fn clone(&self) -> SimulationSnapshot

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SimulationSnapshot

Source§

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

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

impl<'de> Deserialize<'de> for SimulationSnapshot

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SimulationSnapshot

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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 = 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,