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
impl Frames
Sourcepub fn new(mu: f64) -> Self
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.
Sourcepub fn is_empty(&self) -> bool
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.
Sourcepub fn add(
&mut self,
parent: FrameId,
mu: f64,
soi_radius: f64,
origin: WorldPos,
velocity: DVec3,
) -> FrameId
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.
Sourcepub fn parent(&self, id: FrameId) -> Option<FrameId>
pub fn parent(&self, id: FrameId) -> Option<FrameId>
This frame’s parent, or None for the root.
Sourcepub fn soi_radius(&self, id: FrameId) -> f64
pub fn soi_radius(&self, id: FrameId) -> f64
The radius of this frame’s sphere of influence, in metres. Infinite for the root.
Sourcepub fn state_in_parent(&self, id: FrameId) -> State
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.
Sourcepub fn set_state(&mut self, id: FrameId, state: State)
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.
Sourcepub fn common_ancestor(&self, a: FrameId, b: FrameId) -> FrameId
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.
Sourcepub fn convert(&self, state: State, from: FrameId, to: FrameId) -> State
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.
Sourcepub fn transition(&self, state: State, frame: FrameId) -> Option<FrameId>
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.