pub use {
angle::{
Angle, PolarVec, SphericalVec, degs, polar, rads, spherical, turns,
},
approx::ApproxEq,
color::{Color, Color3, Color3f, Color4, Color4f, rgb, rgba},
mat::{
Apply, Mat2x2, Mat3x3, Mat4x4, Matrix, orthographic, perspective,
scale, scale3, translate, translate3, viewport,
},
param::Parametric,
point::{Point, Point2, Point2u, Point3, pt2, pt3},
space::{Affine, Linear},
spline::{BezierSpline, CubicBezier, smootherstep, smoothstep},
vary::Vary,
vec::{Vec2, Vec2i, Vec3, Vec3i, Vector, splat, vec2, vec3},
};
#[cfg(feature = "fp")]
pub use {
angle::{acos, asin, atan2},
mat::{orient_y, orient_z, rotate, rotate_x, rotate_y, rotate_z, rotate2},
};
macro_rules! impl_op {
($trait:ident :: $method:ident, $self:ident, $rhs:ty, $op:tt) => {
impl_op!($trait::$method, $self, $rhs, $op, bound=Linear);
};
($trait:ident :: $method:ident, $self:ident, $rhs:ty, $op:tt, bound=$bnd:path) => {
impl<R, Sp> $trait<$rhs> for $self<R, Sp>
where
Self: $bnd,
{
type Output = Self;
#[inline]
fn $method(mut self, rhs: $rhs) -> Self {
self $op rhs; self
}
}
};
}
pub mod angle;
pub mod approx;
pub mod color;
pub mod float;
pub mod mat;
pub mod param;
pub mod point;
pub mod rand;
pub mod space;
pub mod spline;
pub mod vary;
pub mod vec;
pub trait Lerp: Sized {
fn lerp(&self, other: &Self, t: f32) -> Self;
fn midpoint(&self, other: &Self) -> Self {
self.lerp(other, 0.5)
}
}
#[inline]
pub fn lerp<T: Lerp>(t: f32, from: T, to: T) -> T {
from.lerp(&to, t)
}
#[inline]
pub fn inv_lerp(t: f32, min: f32, max: f32) -> f32 {
(t - min) / (max - min)
}
impl<T> Lerp for T
where
T: Affine<Diff: Linear<Scalar = f32>>,
{
fn lerp(&self, other: &Self, t: f32) -> Self {
self.add(&other.sub(self).mul(t))
}
}
impl Lerp for () {
fn lerp(&self, _: &Self, _: f32) {}
}
impl<U: Lerp, V: Lerp> Lerp for (U, V) {
fn lerp(&self, (u, v): &Self, t: f32) -> Self {
(self.0.lerp(u, t), self.1.lerp(v, t))
}
}