#![deny(non_camel_case_types)]
#![deny(unused_parens)]
#![deny(non_upper_case_globals)]
#![deny(unused_qualifications)]
#![deny(unused_results)]
#![warn(missing_docs)]
#![cfg_attr(test, feature(test))]
#![doc(html_root_url = "http://nalgebra.org/doc")]
extern crate rustc_serialize;
extern crate rand;
#[cfg(feature="arbitrary")]
extern crate quickcheck;
#[cfg(test)]
extern crate test;
use std::cmp;
use std::ops::{Neg, Mul};
pub use traits::{
Absolute,
AbsoluteRotate,
ApproxEq,
Axpy,
Basis,
BaseFloat,
BaseNum,
Bounded,
Cast,
Col,
ColSlice, RowSlice,
Cov,
Cross,
CrossMatrix,
Det,
Diag,
Dim,
Dot,
EigenQR,
Eye,
FloatPnt,
FloatVec,
FromHomogeneous,
Indexable,
Inv,
Iterable,
IterableMut,
LMul,
Mat,
Mean,
Norm,
NumPnt,
NumVec,
One,
Orig,
Outer,
POrd,
POrdering,
PntAsVec,
RMul,
Rotate, Rotation, RotationMatrix, RotationWithTranslation,
Row,
ScalarAdd, ScalarSub,
ScalarMul, ScalarDiv,
Shape,
SquareMat,
ToHomogeneous,
Transform, Transformation,
Translate, Translation,
Transpose,
UniformSphereSample,
VecAsPnt,
Zero
};
pub use structs::{
Identity,
DMat,
DVec, DVec1, DVec2, DVec3, DVec4, DVec5, DVec6,
Iso2, Iso3, Iso4,
Mat1, Mat2, Mat3, Mat4,
Mat5, Mat6,
Rot2, Rot3, Rot4,
Vec0, Vec1, Vec2, Vec3, Vec4, Vec5, Vec6,
Pnt0, Pnt1, Pnt2, Pnt3, Pnt4, Pnt5, Pnt6,
Persp3, PerspMat3,
Ortho3, OrthoMat3,
Quat, UnitQuat
};
pub use linalg::{
qr,
householder_matrix
};
mod structs;
mod traits;
mod linalg;
mod macros;
#[inline(always)]
pub fn clamp<T: PartialOrd>(val: T, min: T, max: T) -> T {
if val > min {
if val < max {
val
}
else {
max
}
}
else {
min
}
}
#[inline(always)]
pub fn max<T: Ord>(a: T, b: T) -> T {
cmp::max(a, b)
}
#[inline(always)]
pub fn min<T: Ord>(a: T, b: T) -> T {
cmp::min(a, b)
}
#[inline(always)]
pub fn inf<T: POrd>(a: &T, b: &T) -> T {
POrd::inf(a, b)
}
#[inline(always)]
pub fn sup<T: POrd>(a: &T, b: &T) -> T {
POrd::sup(a, b)
}
#[inline(always)]
pub fn partial_cmp<T: POrd>(a: &T, b: &T) -> POrdering {
POrd::partial_cmp(a, b)
}
#[inline(always)]
pub fn partial_lt<T: POrd>(a: &T, b: &T) -> bool {
POrd::partial_lt(a, b)
}
#[inline(always)]
pub fn partial_le<T: POrd>(a: &T, b: &T) -> bool {
POrd::partial_le(a, b)
}
#[inline(always)]
pub fn partial_gt<T: POrd>(a: &T, b: &T) -> bool {
POrd::partial_gt(a, b)
}
#[inline(always)]
pub fn partial_ge<T: POrd>(a: &T, b: &T) -> bool {
POrd::partial_ge(a, b)
}
#[inline(always)]
pub fn partial_min<'a, T: POrd>(a: &'a T, b: &'a T) -> Option<&'a T> {
POrd::partial_min(a, b)
}
#[inline(always)]
pub fn partial_max<'a, T: POrd>(a: &'a T, b: &'a T) -> Option<&'a T> {
POrd::partial_max(a, b)
}
#[inline(always)]
pub fn partial_clamp<'a, T: POrd>(value: &'a T, min: &'a T, max: &'a T) -> Option<&'a T> {
POrd::partial_clamp(value, min, max)
}
#[inline(always)]
pub fn identity() -> Identity {
Identity::new()
}
#[inline(always)]
pub fn zero<T: Zero>() -> T {
Zero::zero()
}
#[inline(always)]
pub fn is_zero<T: Zero>(val: &T) -> bool {
val.is_zero()
}
#[inline(always)]
pub fn one<T: One>() -> T {
One::one()
}
#[inline(always)]
pub fn orig<P: Orig>() -> P {
Orig::orig()
}
#[inline]
pub fn center<N: BaseFloat, P: FloatPnt<N, V>, V: Copy>(a: &P, b: &P) -> P {
let _2 = one::<N>() + one();
(*a + *b.as_vec()) / _2
}
#[inline(always)]
pub fn dist<N: BaseFloat, P: FloatPnt<N, V>, V: Norm<N>>(a: &P, b: &P) -> N {
a.dist(b)
}
#[inline(always)]
pub fn sqdist<N: BaseFloat, P: FloatPnt<N, V>, V: Norm<N>>(a: &P, b: &P) -> N {
a.sqdist(b)
}
#[deprecated = "Use `Persp3::new(width / height, fov, znear, zfar).as_mat()` instead"]
pub fn perspective3d<N: BaseFloat + Cast<f64> + Zero + One>(width: N, height: N, fov: N, znear: N, zfar: N) -> Mat4<N> {
let aspect = width / height;
let _1: N = one();
let sy = _1 / (fov * cast(0.5)).tan();
let sx = -sy / aspect;
let sz = -(zfar + znear) / (znear - zfar);
let tz = zfar * znear * cast(2.0) / (znear - zfar);
Mat4::new(
sx, zero(), zero(), zero(),
zero(), sy, zero(), zero(),
zero(), zero(), sz, tz,
zero(), zero(), one(), zero())
}
#[inline(always)]
pub fn translation<V, M: Translation<V>>(m: &M) -> V {
m.translation()
}
#[inline(always)]
pub fn inv_translation<V, M: Translation<V>>(m: &M) -> V {
m.inv_translation()
}
#[inline(always)]
pub fn append_translation<V, M: Translation<V>>(m: &M, v: &V) -> M {
Translation::append_translation(m, v)
}
#[inline(always)]
pub fn translate<P, M: Translate<P>>(m: &M, p: &P) -> P {
m.translate(p)
}
#[inline(always)]
pub fn inv_translate<P, M: Translate<P>>(m: &M, p: &P) -> P {
m.inv_translate(p)
}
#[inline(always)]
pub fn rotation<V, M: Rotation<V>>(m: &M) -> V {
m.rotation()
}
#[inline(always)]
pub fn inv_rotation<V, M: Rotation<V>>(m: &M) -> V {
m.inv_rotation()
}
#[inline(always)]
pub fn append_rotation<V, M: Rotation<V>>(m: &M, v: &V) -> M {
Rotation::append_rotation(m, v)
}
#[inline(always)]
pub fn prepend_rotation<V, M: Rotation<V>>(m: &M, v: &V) -> M {
Rotation::prepend_rotation(m, v)
}
#[inline(always)]
pub fn rotate<V, M: Rotate<V>>(m: &M, v: &V) -> V {
m.rotate(v)
}
#[inline(always)]
pub fn inv_rotate<V, M: Rotate<V>>(m: &M, v: &V) -> V {
m.inv_rotate(v)
}
#[inline(always)]
pub fn append_rotation_wrt_point<LV: Neg<Output = LV> + Copy,
AV,
M: RotationWithTranslation<LV, AV>>(
m: &M,
amount: &AV,
center: &LV) -> M {
RotationWithTranslation::append_rotation_wrt_point(m, amount, center)
}
#[inline(always)]
pub fn append_rotation_wrt_center<LV: Neg<Output = LV> + Copy,
AV,
M: RotationWithTranslation<LV, AV>>(
m: &M,
amount: &AV) -> M {
RotationWithTranslation::append_rotation_wrt_center(m, amount)
}
#[inline(always)]
pub fn to_rot_mat<N, LV, AV, R, M>(r: &R) -> M
where R: RotationMatrix<N, LV, AV, Output=M>,
M: Mat<N, LV, AV> + Rotation<AV> + Col<LV> + Copy,
LV: Mul<M, Output=LV> + Copy,
{
r.to_rot_mat()
}
#[inline(always)]
pub fn absolute_rotate<V, M: AbsoluteRotate<V>>(m: &M, v: &V) -> V {
m.absolute_rotate(v)
}
#[inline(always)]
pub fn transformation<T, M: Transformation<T>>(m: &M) -> T {
m.transformation()
}
#[inline(always)]
pub fn inv_transformation<T, M: Transformation<T>>(m: &M) -> T {
m.inv_transformation()
}
#[inline(always)]
pub fn append_transformation<T, M: Transformation<T>>(m: &M, t: &T) -> M {
Transformation::append_transformation(m, t)
}
#[inline(always)]
pub fn transform<V, M: Transform<V>>(m: &M, v: &V) -> V {
m.transform(v)
}
#[inline(always)]
pub fn inv_transform<V, M: Transform<V>>(m: &M, v: &V) -> V {
m.inv_transform(v)
}
#[inline(always)]
pub fn dot<V: Dot<N>, N>(a: &V, b: &V) -> N {
Dot::dot(a, b)
}
#[inline(always)]
pub fn norm<V: Norm<N>, N: BaseFloat>(v: &V) -> N {
Norm::norm(v)
}
#[inline(always)]
pub fn sqnorm<V: Norm<N>, N: BaseFloat>(v: &V) -> N {
Norm::sqnorm(v)
}
#[inline(always)]
pub fn normalize<V: Norm<N>, N: BaseFloat>(v: &V) -> V {
Norm::normalize(v)
}
#[inline(always)]
pub fn det<M: Det<N>, N>(m: &M) -> N {
Det::det(m)
}
#[inline(always)]
pub fn cross<LV: Cross>(a: &LV, b: &LV) -> LV::Output {
Cross::cross(a, b)
}
#[inline(always)]
pub fn cross_matrix<V: CrossMatrix<M>, M>(v: &V) -> M {
CrossMatrix::cross_matrix(v)
}
#[inline(always)]
pub fn to_homogeneous<M: ToHomogeneous<Res>, Res>(m: &M) -> Res {
ToHomogeneous::to_homogeneous(m)
}
#[inline(always)]
pub fn from_homogeneous<M, Res: FromHomogeneous<M>>(m: &M) -> Res {
FromHomogeneous::from(m)
}
#[inline(always)]
pub fn sample_sphere<V: UniformSphereSample, F: FnMut(V)>(f: F) {
UniformSphereSample::sample(f)
}
#[inline(always)]
pub fn approx_eq<T: ApproxEq<N>, N>(a: &T, b: &T) -> bool {
ApproxEq::approx_eq(a, b)
}
#[inline(always)]
pub fn approx_eq_eps<T: ApproxEq<N>, N>(a: &T, b: &T, eps: &N) -> bool {
ApproxEq::approx_eq_eps(a, b, eps)
}
#[inline(always)]
pub fn abs<M: Absolute<Res>, Res>(m: &M) -> Res {
Absolute::abs(m)
}
#[inline(always)]
pub fn inv<M: Inv>(m: &M) -> Option<M> {
Inv::inv(m)
}
#[inline(always)]
pub fn transpose<M: Transpose>(m: &M) -> M {
Transpose::transpose(m)
}
#[inline(always)]
pub fn outer<V: Outer<M>, M>(a: &V, b: &V) -> M {
Outer::outer(a, b)
}
#[inline(always)]
pub fn cov<M: Cov<Res>, Res>(observations: &M) -> Res {
Cov::cov(observations)
}
#[inline(always)]
pub fn mean<N, M: Mean<N>>(observations: &M) -> N {
Mean::mean(observations)
}
#[inline(always)]
pub fn eigen_qr<N, V, M: EigenQR<N, V>>(m: &M, eps: &N, niter: usize) -> (M, V) {
EigenQR::eigen_qr(m, eps, niter)
}
#[inline(always)]
pub fn new_identity<M: Eye>(dim: usize) -> M {
Eye::new_identity(dim)
}
#[inline(always)]
pub fn canonical_basis<V: Basis, F: FnMut(V) -> bool>(f: F) {
Basis::canonical_basis(f)
}
#[inline(always)]
pub fn orthonormal_subspace_basis<V: Basis, F: FnMut(V) -> bool>(v: &V, f: F) {
Basis::orthonormal_subspace_basis(v, f)
}
#[inline]
pub fn canonical_basis_element<V: Basis>(i: usize) -> Option<V> {
Basis::canonical_basis_element(i)
}
#[inline(always)]
pub fn diag<M: Diag<V>, V>(m: &M) -> V {
m.diag()
}
#[inline(always)]
pub fn dim<V: Dim>() -> usize {
Dim::dim(None::<V>)
}
#[inline(always)]
pub fn shape<V: Shape<I>, I>(v: &V) -> I {
v.shape()
}
#[inline(always)]
pub fn cast<T, U: Cast<T>>(t: T) -> U {
Cast::from(t)
}