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
// Copyright (c) 2017, Marty Mills <daggerbot@gmail.com> // This software is available under the terms of the zlib license. // See COPYING.md for more information. /// Interpolates between two values. pub trait Lerp<T> { fn lerp (a: Self, b: Self, t: T) -> Self; } macro_rules! impl_lerp { ($($ty:ty),*) => { $( impl Lerp<f32> for $ty { fn lerp (a: $ty, b: $ty, t: f32) -> $ty { Lerp::lerp(a, b, t as f64) } } impl Lerp<f64> for $ty { fn lerp (a: $ty, b: $ty, t: f64) -> $ty { (a as f64 + (b as f64 - a as f64) * t) as $ty } } )* }; } impl_lerp!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize, f32, f64);