/// Converts a percentage (0-100) to pixels based on the dimension #[inline] pub fn percent_to_pixel(percentage: f64, dimension: f64) -> f64 { (percentage * dimension) / 100.0 } #[cfg(test)] mod tests { use super::*; #[test] fn test_percent_to_pixel() { assert_eq!(percent_to_pixel(0.0, 100.0), 0.0); assert_eq!(percent_to_pixel(50.0, 100.0), 50.0); assert_eq!(percent_to_pixel(100.0, 100.0), 100.0); assert_eq!(percent_to_pixel(25.0, 1300.0), 325.0); } }