aurum-numeric 0.2.0

Numeric traits
Documentation
// Copyright (c) 2016-2017 <daggerbot@gmail.com>
// This software is available under the terms of the zlib license.
// See COPYING.md for more information.

use std::ops::{Add, Sub};

use raw::RawFrom;

/// Trait for linear interpolation.
pub trait Lerp<T> {
    fn lerp (a: Self, b: Self, t: T) -> Self;
}

impl<N> Lerp<f32> for N
    where N: Copy + Add<Output = N> + Sub<Output = N> + RawFrom<f32>,
          f32: RawFrom<N>
{
    fn lerp (a: N, b: N, t: f32) -> N { a + N::raw_from(f32::raw_from(b - a) * t) }
}

impl<N> Lerp<f64> for N
    where N: Copy + Add<Output = N> + Sub<Output = N> + RawFrom<f64>,
          f64: RawFrom<N>
{
    fn lerp (a: N, b: N, t: f64) -> N { a + N::raw_from(f64::raw_from(b - a) * t) }
}