aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
blob: 8f6699a121489eed3842c28ddb38870caf01c480 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/// 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);
    }
}