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 50 51 52 53 54 55
mod dimension; mod length_traits; mod surround; pub use self::{dimension::*, length_traits::*, surround::*}; pub type Size<T = f32, Unit = Unknown> = euclid::Size2D<T, Unit>; pub type Point<T = f32, Unit = Unknown> = euclid::Point2D<T, Unit>; pub type Rect<T = f32, Unit = Unknown> = euclid::Rect<T, Unit>; pub type Pixels = euclid::Length<f32, Raw>; pub type Points = euclid::Length<f32, Scaled>; pub type Vector<T = f32, Unit = Unknown> = euclid::Vector2D<T, Unit>; pub use euclid::{Length, Scale}; pub type ScreenScale = Scale<f32, Scaled, Raw>; pub type Angle = euclid::Angle<f32>; #[derive(Clone, Copy, Debug, Default)] pub struct Raw; #[derive(Clone, Copy, Debug, Default)] pub struct Scaled; #[derive(Clone, Copy, Debug, Default)] pub struct Unknown; pub(crate) fn max_f(a: f32, b: f32) -> f32 { if a > b { a } else { b } } pub(crate) fn min_f(a: f32, b: f32) -> f32 { if a < b { a } else { b } } #[cfg(test)] mod tests { use super::*; use approx::assert_relative_eq; #[test] fn min_max_tests() { assert_relative_eq!(min_f(0.0, 1.0), 0.0); assert_relative_eq!(min_f(1.0, 0.0), 0.0); assert_relative_eq!(min_f(0.0, 0.0), 0.0); assert_relative_eq!(max_f(0.0, 1.0), 1.0); assert_relative_eq!(max_f(1.0, 0.0), 1.0); assert_relative_eq!(max_f(0.0, 0.0), 0.0); } }