aurum_numeric/
interpolate.rs

1// Copyright (c) 2016-2017 <daggerbot@gmail.com>
2// This software is available under the terms of the zlib license.
3// See COPYING.md for more information.
4
5use std::ops::{Add, Sub};
6
7use raw::RawFrom;
8
9/// Trait for linear interpolation.
10pub trait Lerp<T> {
11    fn lerp (a: Self, b: Self, t: T) -> Self;
12}
13
14impl<N> Lerp<f32> for N
15    where N: Copy + Add<Output = N> + Sub<Output = N> + RawFrom<f32>,
16          f32: RawFrom<N>
17{
18    fn lerp (a: N, b: N, t: f32) -> N { a + N::raw_from(f32::raw_from(b - a) * t) }
19}
20
21impl<N> Lerp<f64> for N
22    where N: Copy + Add<Output = N> + Sub<Output = N> + RawFrom<f64>,
23          f64: RawFrom<N>
24{
25    fn lerp (a: N, b: N, t: f64) -> N { a + N::raw_from(f64::raw_from(b - a) * t) }
26}