Skip to main content

Frames

Struct Frames 

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

A tree of reference frames: a root, and bodies parented to whatever dominates them.

Build it once with new and add, move frames with set_state as they orbit, read a body’s state in another frame with convert, and ask transition whether a body has left the frame it was being simulated in.

Nothing here integrates or propagates anything. A frame’s motion is set by its caller — today by whatever is stepping the scene, later by the on-rails Kepler propagator, which changes nothing about the conversions.

Implementations§

Source§

impl Frames

Source

pub fn new(mu: f64) -> Self

Builds a hierarchy with a single root frame of gravitational parameter mu (GM, in m³/s²).

The root has no parent and an infinite sphere of influence: nothing is outside it, which is what makes transition terminate.

Source

pub fn root(&self) -> FrameId

The root frame’s id, which is always the first one added.

Source

pub fn len(&self) -> usize

How many frames the hierarchy holds, the root included.

Source

pub fn is_empty(&self) -> bool

Always false — a hierarchy always has its root. Present because clippy asks for it wherever len is, and answering honestly is cheaper than explaining the exception.

Source

pub fn add( &mut self, parent: FrameId, mu: f64, soi_radius: f64, origin: WorldPos, velocity: DVec3, ) -> FrameId

Adds a frame under parent, at origin in the parent’s frame and moving at velocity through it.

mu is the body’s gravitational parameter GM in m³/s², and soi_radius the radius in metres beyond which the parent dominates — sphere_of_influence computes the usual one.

§Panics

If soi_radius is not positive. A frame nothing can be inside cannot be transitioned into and would sit in the tree as a body that silently exerts no influence.

Source

pub fn parent(&self, id: FrameId) -> Option<FrameId>

This frame’s parent, or None for the root.

Source

pub fn children(&self, id: FrameId) -> &[FrameId]

The frames parented directly to id.

Source

pub fn mu(&self, id: FrameId) -> f64

This frame’s gravitational parameter GM, in m³/s².

Source

pub fn soi_radius(&self, id: FrameId) -> f64

The radius of this frame’s sphere of influence, in metres. Infinite for the root.

Source

pub fn state_in_parent(&self, id: FrameId) -> State

Where this frame’s origin sits in its parent’s frame, and how fast it moves through it. Both are zero for the root.

Source

pub fn set_state(&mut self, id: FrameId, state: State)

Moves a frame within its parent.

This is how a moon orbits: whatever is propagating it — an integrator now, the Kepler propagator later — writes the new state here each tick, and every conversion through it follows.

§Panics

If id is the root, whose origin is the definition of the hierarchy’s coordinates and cannot move without moving everything with it.

Source

pub fn common_ancestor(&self, a: FrameId, b: FrameId) -> FrameId

The deepest frame that is an ancestor of both a and b, or one of them if it is an ancestor of the other.

Every pair has one, because every frame descends from the root.

Source

pub fn convert(&self, state: State, from: FrameId, to: FrameId) -> State

Reads a state given in frame from as it stands in frame to.

Exact in position: every step is a sector-and-offset addition, which loses nothing, so converting out and back returns the position bit for bit. Velocity is a plain f64 sum of the frames’ velocities and is as exact as those are.

Source

pub fn transition(&self, state: State, frame: FrameId) -> Option<FrameId>

The frame a body at state in frame should be simulated in next, or None if it is already in the right one.

One step: a body that has fallen through two boundaries in a tick — a tick long enough to cross a whole sphere of influence — needs the answer applied and the question asked again. The caller does that rather than a loop here, because a malformed hierarchy is the one thing that could make such a loop run for ever, and a caller that has counted its steps notices.

Entering a child wins over leaving for the parent. In a well-formed hierarchy the two cannot both be true, because a child’s sphere of influence lies inside its parent’s; where a hand-built one says otherwise, the deeper frame is the better approximation.

Trait Implementations§

Source§

impl Debug for Frames

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Frames

§

impl Freeze for Frames

§

impl Move for Frames

§

impl RefUnwindSafe for Frames

§

impl Send for Frames

§

impl Sync for Frames

§

impl Unpin for Frames

§

impl UnsafeUnpin for Frames

§

impl UnwindSafe for Frames

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