1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
// Copyright 2016-2018 Mateusz Sieczko and other GilRs Developers
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
pub use gilrs_core::utils::*;
/// Like `(a: f32 / b).ceil()` but for integers.
pub fn ceil_div(a: u32, b: u32) -> u32 {
if a == 0 {
0
} else {
1 + ((a - 1) / b)
}
}
pub fn clamp(x: f32, min: f32, max: f32) -> f32 {
x.clamp(min, max)
}
#[cfg(path_separator = "backslash")]
macro_rules! PATH_SEPARATOR {
() => {
r"\"
};
}
#[cfg(path_separator = "slash")]
macro_rules! PATH_SEPARATOR {
() => {
r"/"
};
}
pub(crate) use PATH_SEPARATOR;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn t_clamp() {
assert_eq!(clamp(-1.0, 0.0, 1.0), 0.0);
assert_eq!(clamp(0.5, 0.0, 1.0), 0.5);
assert_eq!(clamp(2.0, 0.0, 1.0), 1.0);
}
}