keplerian_sim

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 new_default() -> Universe

Creates an empty universe with default parameters.

Source

pub fn add_body(&mut self, body: Body, satellite_of: Option<usize>) -> usize

Adds a body to the universe. body: The body to add into the universe. satellite_of: 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: usize) -> Body

Removes a body from the universe. body_index: The index of the body to remove.

Source

pub fn get_bodies(&self) -> &Vec<Body>

Gets a Vec of all bodies in the universe.

Source

pub fn get_body_relations(&self) -> &Vec<BodyRelation>

Gets a Vec of all body relations in the universe.

Source

pub fn get_body_mut(&mut self, index: usize) -> &mut Body

Gets a mutable reference to a body in the universe.

Source

pub fn get_body(&self, index: usize) -> &Body

Gets an immutable reference to a body in the unvierse.

Source

pub fn get_first_body_index_with_name(&self, name: String) -> Option<usize>

Gets the index of the first body with a given name.

Source

pub fn get_last_body_index_with_name(&self, name: String) -> Option<usize>

Gets the index of the last body with a given name.

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: usize) -> (f64, f64, f64)

Gets the absolute position of a body in the universe.

Each coordinate is in meters.

Trait Implementations§

Source§

impl Clone for Universe

Source§

fn clone(&self) -> Universe

Returns a copy 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() -> Self

Returns the “default value” for a type. Read more
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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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§

default 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.