pub struct DiscontinuousTransitioner {
state_buffer: Vec<Arc<IterationState>>,
time_per_flomap: f64,
current_index: usize,
}Expand description
A transitioner that handles discontinuous transitions between flow-map states.
Each IterationState in state_buffer represents a flow-map state, and
consecutive states are separated by a fixed duration time_per_flomap.
§Behavior
- The transitioner does not maintain an internal time counter;
calling
advanceoradvance_arcwith the samecurrent_timemultiple times are idempotent and always returns the correct state corresponding tocurrent_time. - Delta time argument is therefore not used
- Transitions are discontinuous: as
current_timecrosses multiples oftime_per_flomap,current_indexjumps directly to the correct state instate_buffer. - Iteration is cyclic: when the
current_indexreaches the last state, it wraps around to index 0. For example, with 15 states, iteration goes:14 -> 0 -> 1 -> .... current_indexalways points to the active flow-map state based oncurrent_time.
§Fields
state_buffer— AVec<Arc<IterationState>>containing all flow-map states.time_per_flomap— Duration of each flow-map in seconds (or any consistent time unit).current_index— The index of the currently active flow-map state instate_buffer.
§Example
ⓘ
let transitioner = DiscontinuousTransitioner {
state_buffer: vec![Arc::new(state1), Arc::new(state2), Arc::new(state3)],
time_per_flomap: 0.5,
current_index: 0,
};
// current_time = 1.3 -> index = 2 (3rd state)
let state = transitioner.advance(1.3, 0.1);
// current_time = 1.6 -> cycles back to index 0 (if 3 states)
let state = transitioner.advance(1.6, 0.1);Fields§
§state_buffer: Vec<Arc<IterationState>>§time_per_flomap: f64§current_index: usizeImplementations§
Source§impl DiscontinuousTransitioner
impl DiscontinuousTransitioner
fn index_for_time(&self, t: f64) -> usize
fn get_index_and_state( &mut self, current_time: f64, ) -> (usize, &Arc<IterationState>)
fn get_state(&mut self, current_time: f64) -> &Arc<IterationState>
pub fn advance_mut( &mut self, state: &mut Arc<IterationState>, current_time: f64, _time_step: f64, ) -> bool
Trait Implementations§
Source§impl FlowMapTransitioner for DiscontinuousTransitioner
impl FlowMapTransitioner for DiscontinuousTransitioner
Source§fn advance(&mut self, current_time: f64, _time_step: f64) -> &IterationState
fn advance(&mut self, current_time: f64, _time_step: f64) -> &IterationState
Advances the internal state according to
current_time and
time_step, and returns a borrowed reference to the active
IterationState. Read moreSource§fn advance_arc(
&mut self,
current_time: f64,
_time_step: f64,
) -> Arc<IterationState>
fn advance_arc( &mut self, current_time: f64, _time_step: f64, ) -> Arc<IterationState>
Source§fn need_advance(&self, current_time: f64, _time_step: f64) -> bool
fn need_advance(&self, current_time: f64, _time_step: f64) -> bool
Returns
true if the flow-map index should advance when evaluating
the given current_time and time_step. Read moreSource§fn get_current_arc(&self) -> Arc<IterationState>
fn get_current_arc(&self) -> Arc<IterationState>
Returns the current state as an owned
Arc<IterationState>.Source§fn get_current(&self) -> &IterationState
fn get_current(&self) -> &IterationState
Returns the current state as a borrowed reference.
Source§fn get_at(&self, idx: usize) -> Option<Arc<IterationState>>
fn get_at(&self, idx: usize) -> Option<Arc<IterationState>>
Retrieves the state at the given buffer index as an owned
Arc. Read moreSource§fn new(time_per_flomap: f64, buffer: FlowMapBuffer) -> Self
fn new(time_per_flomap: f64, buffer: FlowMapBuffer) -> Self
Constructs a new transitioner from the duration of each flow-map (
time_per_flomap)
and a validated FlowMapBuffer. Read moreAuto Trait Implementations§
impl Freeze for DiscontinuousTransitioner
impl RefUnwindSafe for DiscontinuousTransitioner
impl Send for DiscontinuousTransitioner
impl Sync for DiscontinuousTransitioner
impl Unpin for DiscontinuousTransitioner
impl UnsafeUnpin for DiscontinuousTransitioner
impl UnwindSafe for DiscontinuousTransitioner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.