Skip to main content

iris/utils/
mod.rs

1/// Common utility functions for the Iris library.
2pub struct Utils;
3
4impl Utils {
5    /// Formats a time duration in milliseconds.
6    #[must_use]
7    pub fn format_duration_ms(ms: f64) -> String {
8        format!("{ms:.2} ms")
9    }
10
11    /// Linear interpolation between two float values.
12    #[must_use]
13    pub fn lerp(a: f32, b: f32, t: f32) -> f32 {
14        a + (b - a) * t.clamp(0.0, 1.0)
15    }
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn test_utils() {
24        assert_eq!(Utils::format_duration_ms(12.345), "12.35 ms");
25        assert_eq!(Utils::lerp(0.0, 10.0, 0.5), 5.0);
26    }
27}