pub struct EmaF64 { /* private fields */ }Expand description
Exponential moving average over f64 samples, with an
alpha-per-update-call smoothing factor (rather than a
fixed-at-construction one) so a single small primitive can back both
this module’s per-stage profiler (alpha 0.08, the source app’s own
constant) and uzor-desktop::Manager’s own whole-frame fps_ema
(alpha 0.1) without needing two copies of the formula.
Implementations§
Source§impl EmaF64
impl EmaF64
Sourcepub fn new() -> Self
pub fn new() -> Self
A fresh, uninitialized tracker — its very first EmaF64::update
call wins outright (no smoothing against 0.0).
Sourcepub fn seeded(value: f64) -> Self
pub fn seeded(value: f64) -> Self
A tracker pre-seeded with value, marked initialized — the first
real EmaF64::update call blends against value instead of
replacing it outright. Useful when a caller has a sensible
starting guess (e.g. an assumed 60.0 fps before the first frame
has actually been timed) rather than wanting the very first
sample to jump straight to its own raw value.
Sourcepub fn update(&mut self, sample: f64, alpha: f64) -> f64
pub fn update(&mut self, sample: f64, alpha: f64) -> f64
Fold sample into the running average at smoothing factor
alpha (0.0..=1.0; higher = more responsive to new samples,
lower = smoother/slower) and return the new value. The very first
call on an uninitialized (Self::new/Self::default) tracker
always wins outright — matches both source call sites’ own
if initialized { blend } else { sample } cold-start rule,
avoiding a synthetic warm-up period biased toward whatever value
the struct happened to start at.
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Whether at least one EmaF64::update has run, or the tracker
was constructed via EmaF64::seeded.