//! **nalgebra** prelude. pub use std::num::{Zero, One}; pub use traits::{ Absolute, AbsoluteRotate, AlgebraicVec, AlgebraicVecExt, Basis, Col, Cov, Cross, CrossMatrix, Dim, Dot, FromHomogeneous, Indexable, Inv, Iterable, IterableMut, LMul, Mat, MatCast, Mean, Norm, Outer, RMul, Rotate, Rotation, RotationMatrix, RotationWithTranslation, Row, ScalarAdd, ScalarSub, ToHomogeneous, Transform, Transformation, Translate, Translation, Transpose, UniformSphereSample, Vec, VecCast, VecExt }; pub use structs::{ Identity, DMat, DVec, Iso2, Iso3, Iso4, Mat1, Mat2, Mat3, Mat4, Mat5, Mat6, Rot2, Rot3, Rot4, Vec0, Vec1, Vec2, Vec3, Vec4, Vec5, Vec6 }; // // // Constructors // // /// Create a special identity object. /// /// Same as `Identity::new()`. #[inline(always)] pub fn identity() -> Identity { Identity::new() } /// Create a zero-valued value. /// /// This is the same as `std::num::Zero::zero()`. #[inline(always)] pub fn zero() -> T { Zero::zero() } /// Create a one-valued value. /// /// This is the same as `std::num::One::one()`. #[inline(always)] pub fn one() -> T { One::one() } /// Creates a new 1d vector. /// /// This is the same as `Vec1::new(x)`. #[inline(always)] pub fn vec1(x: N) -> Vec1 { Vec1::new(x) } /// Creates a new 2d vector. /// /// This is the same as `Vec2::new(x, y)`. #[inline(always)] pub fn vec2(x: N, y: N) -> Vec2 { Vec2::new(x, y) } /// Creates a new 3d vector. /// /// This is the same as `Vec3::new(x, y, z)`. #[inline(always)] pub fn vec3(x: N, y: N, z: N) -> Vec3 { Vec3::new(x, y, z) } /// Creates a new 4d vector. /// /// This is the same as `Vec4::new(x, y, z, w)`. #[inline(always)] pub fn vec4(x: N, y: N, z: N, w: N) -> Vec4 { Vec4::new(x, y, z, w) } /// Creates a new 1d matrix. /// /// This is the same as `Mat1::new(...)`. #[inline(always)] pub fn mat1(m11: N) -> Mat1 { Mat1::new(m11) } /// Creates a new 2d matrix. /// /// This is the same as `Mat2::new(...)`. #[inline(always)] pub fn mat2(m11: N, m12: N, m21: N, m22: N) -> Mat2 { Mat2::new( m11, m12, m21, m22) } /// Creates a new 3d matrix. /// /// This is the same as `Mat3::new(...)`. #[inline(always)] pub fn mat3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> Mat3 { Mat3::new( m11, m12, m13, m21, m22, m23, m31, m32, m33) } /// Creates a new 4d matrix. /// /// This is the same as `Mat4::new(...)`. #[inline(always)] pub fn mat4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N, m31: N, m32: N, m33: N, m34: N, m41: N, m42: N, m43: N, m44: N) -> Mat4 { Mat4::new( m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) } // // // Geometry // // /* * Translation */ /// Gets the translation applicable by the given object. /// /// ```rust /// extern mod nalgebra; /// use nalgebra::types::{Vec3, Affmat}; /// use nalgebra::na; /// /// pub main() { /// let t = Affmat::new_translation3d(1.0, 1.0, 1.0); /// let trans = na::translation(t); /// /// assert!(trans == Vec3::new(1.0, 1.0, 1.0)); /// } /// ``` #[inline(always)] pub fn translation>(m: &M) -> V { m.translation() } /// Gets the inverse translation applicable by the given object. /// /// ```rust /// extern mod nalgebra; /// use nalgebra::types::{Vec3, Affmat}; /// use nalgebra::na; /// /// pub main() { /// let t = Affmat::new_translation3d(1.0, 1.0, 1.0); /// let itrans = na::inv_translation(t); /// /// assert!(itrans == Vec3::new(-1.0, -1.0, -1.0)); /// } /// ``` #[inline(always)] pub fn inv_translation>(m: &M) -> V { m.inv_translation() } /// In-place version of `translated`. #[inline(always)] pub fn translate_by>(m: &mut M, v: &V) { m.translate_by(v) } /// Gets a translated copy of the given object. #[inline(always)] pub fn translated>(m: &M, v: &V) -> M { m.translated(v) } /// Sets the translation of the given object. #[inline(always)] pub fn set_translation>(m: &mut M, v: V) { m.set_translation(v) } /* * Translate */ /// Applies a translation to a vector. /// /// ```rust /// extern mod nalgebra; /// use nalgebra::na; /// /// pub main() { /// let t = na::translation3d(1.0, 1.0, 1.0); /// let v = na::vec3(2.0, 2.0, 2.0); /// /// let tv = na::translate(&t, &v); /// /// assert!(tv == na::vec3(3.0, 3.0, 3.0)) /// } /// ``` #[inline(always)] pub fn translate>(m: &M, v: &V) -> V { m.translate(v) } /// Applies an inverse translation to a vector. /// /// ```rust /// extern mod nalgebra; /// use nalgebra::na; /// /// pub main() { /// let t = na::translation3d(1.0, 1.0, 1.0); /// let v = na::vec3(2.0, 2.0, 2.0); /// /// let tv = na::translate(&t, &v); /// /// assert!(tv == na::vec3(1.0, 1.0, 1.0)) /// } #[inline(always)] pub fn inv_translate>(m: &M, v: &V) -> V { m.inv_translate(v) } /* * Rotation */ /// Gets the rotation applicable by the given object. /// /// ```rust /// extern mod nalgebra; /// use nalgebra::na; /// /// pub main() { /// let t = na::rot3(1.0, 1.0, 1.0); /// /// assert!(na::rotation(t) == na::vec3(1.0, 1.0, 1.0)); /// } /// ``` #[inline(always)] pub fn rotation>(m: &M) -> V { m.rotation() } /// Gets the rotation applicable by the given object. /// /// ```rust /// extern mod nalgebra; /// use nalgebra::na; /// /// pub main() { /// let t = na::rot3(1.0, 1.0, 1.0); /// /// assert!(na::inv_rotation(t) == na::vec3(-1.0, -1.0, -1.0)); /// } /// ``` #[inline(always)] pub fn inv_rotation>(m: &M) -> V { m.inv_rotation() } /// Rotates an object in-place. /// /// ```rust /// extern mod nalgebra; /// use nalgebra::na; /// /// pub main() { /// let mut t = na::rot3(0.0, 0.0, 0.0); /// let v = na::vec3(1.0, 1.0, 1.0); /// /// na::rotate_by(&mut t, &v); /// /// assert!(na::rotation(&t) == na::vec3(1.0, 1.0, 1.0)) /// } /// ``` #[inline(always)] pub fn rotate_by>(m: &mut M, v: &V) { m.rotate_by(v) } /// Creates a rotated copy of an object. /// /// ```rust /// extern mod nalgebra; /// use nalgebra::na; /// /// pub main() { /// let t = na::rot3(0.0, 0.0, 0.0); /// let v = na::vec3(1.0, 1.0, 1.0); /// let rt = na::rotated(&mut t, &v); /// /// assert!(na::rotation(&rt) == na::vec3(1.0, 1.0, 1.0)) /// } /// ``` #[inline(always)] pub fn rotated>(m: &M, v: &V) -> M { m.rotated(v) } /// Sets the rotation of an object. /// /// ```rust /// extern mod nalgebra; /// use nalgebra::na; /// /// pub main() { /// let mut t = na::rot3(1.0, 0.5, 0.2); /// let v = na::vec3(1.0, 1.0, 1.0); /// /// na::set_rotation(&mut t, &v); /// /// assert!(na::rotation(&t) == na::vec3(1.0, 1.0, 1.0)) /// } /// ``` #[inline(always)] pub fn set_rotation>(m: &mut M, v: V) { m.set_rotation(v) } /* * Rotate */ /// Applies a rotation to a vector. /// /// ```rust /// extern mod nalgebra; /// use nalgebra::na; /// /// pub main() { /// let t = na::rot3(1.0, 0.0, 0.0); /// let v = na::vec3(0.0, 0.0, na::pi() / 2.0); /// /// let tv = na::rotate(&t, &v); /// /// assert!(tv == na::vec3(0.0, 1.0, 0.0)) /// } /// ``` #[inline(always)] pub fn rotate>(m: &M, v: &V) -> V { m.rotate(v) } /// Applies an inverse rotation to a vector. /// /// ```rust /// extern mod nalgebra; /// use nalgebra::na; /// /// pub main() { /// let t = na::rot3(1.0, 0.0, 0.0); /// let v = na::vec3(0.0, 0.0, na::pi() / 2.0); /// /// let tv = na::rotate(&t, &v); /// /// assert!(tv == na::vec3(0.0, -1.0, 0.0)) /// } /// ``` #[inline(always)] pub fn inv_rotate>(m: &M, v: &V) -> V { m.inv_rotate(v) } /* * RotationWithTranslation */ /// Creates a rotated copy of an object using a specific center of rotation. #[inline(always)] pub fn rotated_wrt_point, AV, M: RotationWithTranslation>( m: &M, amount: &AV, center: &LV) -> M { m.rotated_wrt_point(amount, center) } /// In-place version of `rotated_wrt_point`. #[inline(always)] pub fn rotate_wrt_point, AV, M: RotationWithTranslation>( m: &mut M, amount: &AV, center: &LV) { m.rotate_wrt_point(amount, center) } /// Creates a rotated copy of an object using its own translation as the center of rotation. #[inline(always)] pub fn rotated_wrt_center, AV, M: RotationWithTranslation>( m: &M, amount: &AV) -> M { m.rotated_wrt_center(amount) } /// In-place version of `rotate_wrt_center`. #[inline(always)] pub fn rotate_wrt_center, AV, M: RotationWithTranslation>( m: &mut M, amount: &AV) { m.rotate_wrt_center(amount) } /* * RotationMatrix */ /// Builds a rotation matrix from a rotation-capable object. #[inline(always)] pub fn to_rot_mat + Rotation, R: RotationMatrix>(r: &R) -> M { r.to_rot_mat() } /* * AbsoluteRotate */ /// Applies a rotation using the absolute values of its components. #[inline(always)] pub fn absolute_rotate>(m: &M, v: &V) -> V { m.absolute_rotate(v) } /* * Transformation */ /// Gets the transformation applicable by the given object. #[inline(always)] pub fn transformation>(m: &M) -> T { m.transformation() } /// Gets the inverse transformation applicable by the given object. #[inline(always)] pub fn inv_transformation>(m: &M) -> T { m.inv_transformation() } /// In-place version of `transformed`. #[inline(always)] pub fn transform_by>(m: &mut M, t: &T) { m.transform_by(t) } /// Gets a transformed copy of an object. #[inline(always)] pub fn transformed>(m: &M, t: &T) -> M { m.transformed(t) } /// Sets the transformation of an object. #[inline(always)] pub fn set_transformation>(m: &mut M, t: T) { m.set_transformation(t) } /* * Transform */ /// Applies a transformation to a vector. #[inline(always)] pub fn transform>(m: &M, v: &V) -> V { m.transform(v) } /// Applies an inverse transformation to a vector. #[inline(always)] pub fn inv_transform>(m: &M, v: &V) -> V { m.inv_transform(v) } /* * Dot */ /// Computes the dot product of two vectors. #[inline(always)] pub fn dot, N>(a: &V, b: &V) -> N { a.dot(b) } /// Computes a subtraction followed by a dot product. #[inline(always)] pub fn sub_dot, N>(a: &V, b: &V, c: &V) -> N { a.sub_dot(b, c) } /* * Norm */ /// Computes the L2 norm of a vector. #[inline(always)] pub fn norm, N: Algebraic>(v: &V) -> N { v.norm() } /// Computes the squared L2 norm of a vector. #[inline(always)] pub fn sqnorm, N: Algebraic>(v: &V) -> N { v.sqnorm() } /// Gets the normalized version of a vector. #[inline(always)] pub fn normalized, N: Algebraic>(v: &V) -> V { v.normalized() } /// In-place version of `normalized`. #[inline(always)] pub fn normalize, N: Algebraic>(v: &mut V) -> N { v.normalize() } /* * Cross */ /// Computes the cross product of two vectors. #[inline(always)] pub fn cross, AV>(a: &LV, b: &LV) -> AV { a.cross(b) } /* * CrossMatrix */ /// Given a vector, computes the matrix which, when multiplied by another vector, computes a cross /// product. #[inline(always)] pub fn cross_matrix, M>(v: &V) -> M { v.cross_matrix() } /* * ToHomogeneous */ /// Converts a matrix or vector to homogoneous coordinates. #[inline(always)] pub fn to_homogeneous, Res>(m: &M) -> Res { m.to_homogeneous() } /* * FromHomogeneous */ /// Converts a matrix or vector from homogoneous coordinates. /// /// w-normalization is appied. #[inline(always)] pub fn from_homogeneous>(m: &M) -> Res { FromHomogeneous::from(m) } /* * UniformSphereSample */ /// Samples the unit sphere living on the dimension as the samples types. /// /// The number of sampling point is implementation-specific. It is always uniform. #[inline(always)] pub fn sample_sphere(f: &fn(V)) { UniformSphereSample::sample(f) } // // // Operations // // /* * Absolute */ /// Computes a component-wise absolute value. #[inline(always)] pub fn absolute, Res>(m: &M) -> Res { m.absolute() } /* * Inv */ /// Gets an inverted copy of a matrix. #[inline(always)] pub fn inverted(m: &M) -> Option { m.inverted() } /// In-place version of `inverted`. #[inline(always)] pub fn invert(m: &mut M) -> bool { m.invert() } /* * Transpose */ /// Gets a transposed copy of a matrix. #[inline(always)] pub fn transposed(m: &M) -> M { m.transposed() } /// In-place version of `transposed`. #[inline(always)] pub fn transpose(m: &mut M) { m.transpose() } /* * Outer */ /// Computes the outer product of two vectors. #[inline(always)] pub fn outer, M>(a: &V, b: &V) -> M { a.outer(b) } /* * Cov */ /// Computes the covariance of a set of observations. #[inline(always)] pub fn cov, Res>(observations: &M) -> Res { observations.cov() } /* * Mean */ /// Computes the mean of a set of observations. #[inline(always)] pub fn mean>(observations: &M) -> N { observations.mean() } // // // Structure // // /* * MatCast */ /// Converts a matrix to a matrix with different value type. #[inline(always)] pub fn cast_mat, Res>(m: M) -> Res { MatCast::from(m) } /* * VecCast */ /// Converts a matrix to a matrix with different value type. #[inline(always)] pub fn cast_vec, Res>(v: V) -> Res { VecCast::from(v) } /* * Basis */ /// Computes the canonical basis for a given dimension. #[inline(always)] pub fn canonical_basis(f: &fn(V) -> bool) { Basis::canonical_basis(f) } /// Computes the basis of the orthonormal subspace of a given vector. #[inline(always)] pub fn orthonormal_subspace_basis(v: &V, f: &fn(V) -> bool) { v.orthonormal_subspace_basis(f) } /* * Row */ /* * Col */ /* * Dim */ /// Gets the dimension an object lives in. /// /// Same as `Dim::dim::(None::)`. #[inline(always)] pub fn dim() -> uint { Dim::dim(None::) } /* * Indexable */