Struct Universe

Source
pub struct Universe {
    pub time: f64,
    pub time_step: f64,
    pub g: f64,
    /* private fields */
}
Expand description

Struct that represents the simulation of the universe.

Fields§

§time: f64

The time elapsed in the universe, in seconds.

§time_step: f64

The time step of the simulation, in seconds.

§g: f64

The gravitational constant, in m^3 kg^-1 s^-2.

Implementations§

Source§

impl Universe

Source

pub fn new(time_step: Option<f64>, g: Option<f64>) -> Universe

Creates an empty universe.

Source

pub fn add_body( &mut self, body: Body, parent_id: Option<u64>, ) -> Result<u64, BodyAddError>

Adds a body to the universe.

body: The body to add into the universe.
parent_id: The index of the body that this body is orbiting.
Returns: The index of the newly-added body.

Source

pub fn remove_body(&mut self, body_index: u64) -> Vec<Body>

Removes a body from the universe.

body_index: The index of the body to remove.

Returns: A Vec of all bodies that were removed, including the one specified.
An empty Vec is returned if the body was not found.

Source

pub fn get_bodies(&self) -> &HashMap<u64, BodyWrapper>

Gets a reference to a HashMap of all bodies in the universe and their relations.

Source

pub fn get_body_mut(&mut self, index: u64) -> Option<&mut Body>

Gets a mutable reference to a body in the universe.

Source

pub fn get_body(&self, index: u64) -> Option<&Body>

Gets an immutable reference to a body in the universe.

Source

pub fn get_body_index_with_name(&self, name: &str) -> Option<u64>

Gets the first index of a body with a given name, if any.

Source

pub fn tick(&mut self)

Advances the simulation by a tick.

Source

pub fn warp(&mut self, ticks: u128)

Advances the universe by multiple ticks.

Source

pub fn get_body_position(&self, index: u64) -> Option<DVec3>

Gets the absolute position of a body in the universe.

Each coordinate is in meters.

index: The index of the body to get the position of.

Returns: The absolute position of the body.
The top ancestor of the body (i.e, the body with no parent) is at the origin (0, 0, 0).

Trait Implementations§

Source§

impl Clone for Universe

Source§

fn clone(&self) -> Universe

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 Universe

Source§

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

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

impl Default for Universe

Source§

fn default() -> Universe

Creates an empty universe with default parameters.

Source§

impl Display for Universe

Source§

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

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

impl PartialEq for Universe

Source§

fn eq(&self, other: &Universe) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Universe

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.