Skip to main content

SimState

Struct SimState 

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

Simulation state.

Contains all state variables needed to reproduce the simulation.

Implementations§

Source§

impl SimState

Source

pub fn new() -> Self

Create a new empty state.

Source

pub fn num_bodies(&self) -> usize

Get number of bodies.

Source

pub fn add_body(&mut self, mass: f64, position: Vec3, velocity: Vec3)

Add a body to the simulation.

Source

pub fn masses(&self) -> &[f64]

Get body masses.

Source

pub fn positions(&self) -> &[Vec3]

Get body positions.

Source

pub fn positions_mut(&mut self) -> &mut [Vec3]

Get mutable body positions.

Source

pub fn velocities(&self) -> &[Vec3]

Get body velocities.

Source

pub fn velocities_mut(&mut self) -> &mut [Vec3]

Get mutable body velocities.

Source

pub fn forces(&self) -> &[Vec3]

Get body forces.

Source

pub fn forces_mut(&mut self) -> &mut [Vec3]

Get mutable body forces.

Source

pub fn set_position(&mut self, index: usize, position: Vec3)

Set position for a body.

§Panics

Panics if index is out of bounds.

Source

pub fn set_velocity(&mut self, index: usize, velocity: Vec3)

Set velocity for a body.

§Panics

Panics if index is out of bounds.

Source

pub fn apply_force(&mut self, index: usize, force: Vec3)

Apply force to a body.

§Panics

Panics if index is out of bounds.

Source

pub fn clear_forces(&mut self)

Clear all forces (called at start of each step).

Source

pub fn set_potential_energy(&mut self, energy: f64)

Set potential energy (called by domain engine).

Source

pub fn kinetic_energy(&self) -> f64

Get total kinetic energy.

Source

pub const fn potential_energy(&self) -> f64

Get potential energy.

Source

pub fn total_energy(&self) -> f64

Get total energy (kinetic + potential).

Source

pub fn add_constraint(&mut self, name: impl Into<String>, violation: f64)

Add a constraint violation.

Source

pub fn clear_constraints(&mut self)

Clear all constraints.

Source

pub fn constraint_violations(&self) -> impl Iterator<Item = (String, f64)> + '_

Get constraint violations.

Source

pub fn all_finite(&self) -> bool

Check if all state values are finite.

Source

pub fn apply_event(&mut self, event: &SimEvent) -> SimResult<()>

Apply an event to the state.

§Errors

Returns error if event cannot be applied.

Trait Implementations§

Source§

impl Clone for SimState

Source§

fn clone(&self) -> SimState

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 SimState

Source§

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

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

impl Default for SimState

Source§

fn default() -> SimState

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SimState

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 SimState

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,