pub trait ProgressResolution {
// Required methods
fn absolute(&self) -> Self;
fn reverse(&mut self);
fn restart(&mut self);
fn is_reverse(&self) -> bool;
fn start_signal(&self) -> bool;
fn to_f32(&self) -> f32;
fn from_f32(value: f32) -> Self;
fn zero() -> Self;
fn max() -> Self;
}Expand description
Using f32 for progress (0.0 to 1.0) is inefficient for large-scale systems. While switching to integers like i8 (using its range, e.g., 127 steps) saves memory, it introduces significant quantization errors. For example, a 1.5-second animation at 60FPS requires a per-frame progress step of 127 steps / (1.5s * 60fps) \approx 1.41. Since i8 can only store integers, rounding this to 1 discards 0.41, causing a 41% error (0.41 / 1.0) on that frame’s increment, which accumulates and leads to jerky or inaccurate animations. Maximum animation error = (0.5/integer) * 100 %
§Example for i16:
- each frame takes 564 resolution steps.
- animation error = (0.0777778/564) * 100% = 0.0213675 %
- maximum animation error = (0.5/564) * 100% = 0.1373626 %
§Example for i32:
- each frame takes 23860929.41 resolution steps.
- animation error = (0.41/23860929) * 100% = 0.0000017 %
- maximum animation error = (0.5/23860929) * 100% = 0.0000021 %
Reversing progress is simple just negative the progress value. but progress value is still absolute for animation. negative value is used for reverse animation. if the progress value is maximum example 128 for i8. It means animation restart to Zero.
Required Methods§
fn absolute(&self) -> Self
fn reverse(&mut self)
Sourcefn restart(&mut self)
fn restart(&mut self)
restart means set progress at specific value that represents the start signal. AKA forward/start function. If restart is not called then it’s value stay in 0 or MIN-1 after animation and wait for restart signal. progress will goes MIN-1 (replace to zero for animation) to MAX.
Sourcefn is_reverse(&self) -> bool
fn is_reverse(&self) -> bool
true for forward animation. false for reverse animation.
fn start_signal(&self) -> bool
fn to_f32(&self) -> f32
fn from_f32(value: f32) -> Self
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.