Struct egui::util::History [−][src]
pub struct History<T> { /* fields omitted */ }
Expand description
This struct tracks recent values of some time series.
It can be used as a smoothing filter for e.g. latency, fps etc, or to show a log or graph of recent events.
It has a minimum and maximum length, as well as a maximum storage time.
- The minimum length is to ensure you have enough data for an estimate.
- The maximum length is to make sure the history doesn’t take up too much space.
- The maximum age is to make sure the estimate isn’t outdated.
Time difference between values can be zero, but never negative.
This can be used for things like smoothed averages (for e.g. FPS) or for smoothed velocity (e.g. mouse pointer speed). All times are in seconds.
Implementations
Example:
// Drop events that are older than one second,
// as long we keep at least two events. Never keep more than a hundred events.
let mut history = History::new(2..100, 1.0);
assert_eq!(history.average(), None);
history.add(now(), 40.0_f32);
history.add(now(), 44.0_f32);
assert_eq!(history.average(), Some(42.0));
Total number of values seen.
Includes those that have been discarded due to max_len
or max_age
.
(time, value)
pairs
Time difference between values can be zero, but never negative.
Values must be added with a monotonically increasing time, or at least not decreasing.
Mean time difference between values in this History
.
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for History<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for History<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more