From ba18f5aa702846c7fd79d80b9eefc0372d7a00dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 28 Sep 2014 19:20:22 +0200 Subject: [PATCH] Deprecate `na::`, move all reexport to the root crate. This also moves the tests and benches to cargo-complient folders. Fix #21. --- Makefile | 3 +- {src/bench => benches}/mat.rs | 6 + {src/bench => benches}/vec.rs | 7 +- src/lib.rs | 828 +++++++++++++++++++++++++++++++++- src/na.rs | 349 +++++--------- {src/tests => tests}/mat.rs | 8 +- {src/tests => tests}/vec.rs | 9 +- 7 files changed, 962 insertions(+), 248 deletions(-) rename {src/bench => benches}/mat.rs (97%) rename {src/bench => benches}/vec.rs (89%) rename {src/tests => tests}/mat.rs (98%) rename {src/tests => tests}/vec.rs (97%) diff --git a/Makefile b/Makefile index 0a74666a..4358345e 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,7 @@ test: cargo test bench: - rustc --test src/lib.rs --opt-level 3 -o bench~ && ./bench~ --bench - rm bench~ + cargo bench doc: cargo doc diff --git a/src/bench/mat.rs b/benches/mat.rs similarity index 97% rename from src/bench/mat.rs rename to benches/mat.rs index 613afb41..7d4d66ba 100644 --- a/src/bench/mat.rs +++ b/benches/mat.rs @@ -1,3 +1,9 @@ +#![feature(macro_rules)] + +extern crate debug; +extern crate test; +extern crate "nalgebra" as na; + use std::rand::random; use test::Bencher; use na::{Vec2, Vec3, Vec4, Vec5, Vec6, DVec, Mat2, Mat3, Mat4, Mat5, Mat6, DMat}; diff --git a/src/bench/vec.rs b/benches/vec.rs similarity index 89% rename from src/bench/vec.rs rename to benches/vec.rs index 6ea055d6..16aaabe0 100644 --- a/src/bench/vec.rs +++ b/benches/vec.rs @@ -1,7 +1,12 @@ +#![feature(macro_rules)] + +extern crate debug; +extern crate test; +extern crate "nalgebra" as na; + use std::rand::random; use test::Bencher; use na::{Vec2, Vec3, Vec4, Vec5, Vec6}; -use na; macro_rules! bench_dot_vec( ($bh: expr, $t: ty) => { diff --git a/src/lib.rs b/src/lib.rs index d0374b66..9d618f31 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,23 +10,22 @@ An on-line version of this documentation is available [here](http://nalgebra.org). ## Using **nalgebra** -All the functionalities of **nalgebra** are grouped in one place: the `na` module. +All the functionalities of **nalgebra** are grouped in one place: the root `nalgebra::` module. This module re-exports everything and includes free functions for all traits methods doing out-of-place modifications. * You can import the whole prelude using: ```.ignore -use nalgebra::na::*; +use nalgebra::*; ``` The preferred way to use **nalgebra** is to import types and traits explicitly, and call free-functions using the `na::` prefix: ```.rust -extern crate nalgebra; -use nalgebra::na::{Vec3, Rot3, Rotation}; -use nalgebra::na; +extern crate "nalgebra" as na; +use na::{Vec3, Rot3, Rotation}; fn main() { let a = Vec3::new(1.0f64, 1.0, 1.0); @@ -55,9 +54,8 @@ and keeps an optimized set of tools for computational graphics and physics. Thos For example, the following works: ```rust -extern crate nalgebra; -use nalgebra::na::{Vec3, Mat3}; -use nalgebra::na; +extern crate "nalgebra" as na; +use na::{Vec3, Mat3}; fn main() { let v: Vec3 = na::zero(); @@ -99,6 +97,7 @@ Feel free to add your project to this list if you happen to use **nalgebra**! #![deny(unused_result)] #![warn(missing_doc)] #![feature(macro_rules)] +#![feature(globs)] #![doc(html_root_url = "http://nalgebra.org/doc")] extern crate rand; @@ -109,6 +108,71 @@ extern crate test; #[cfg(test)] extern crate debug; +use std::num::{Zero, One, FloatMath}; +use std::cmp; +pub use traits::{PartialLess, PartialEqual, PartialGreater, NotComparable}; +pub use traits::{ + Absolute, + AbsoluteRotate, + AnyVec, + ApproxEq, + Basis, + Cast, + Col, + ColSlice, RowSlice, + Cov, + Cross, + CrossMatrix, + Det, + Diag, + Dim, + Dot, + Eye, + FloatVec, + FloatVecExt, + FromHomogeneous, + Indexable, + Inv, + Iterable, + IterableMut, + LMul, + Mat, + Mean, + Norm, + Outer, + PartialOrd, + PartialOrdering, + RMul, + Rotate, Rotation, RotationMatrix, RotationWithTranslation, + Row, + ScalarAdd, ScalarSub, + ScalarMul, ScalarDiv, + ToHomogeneous, + Transform, Transformation, + Translate, Translation, + Transpose, + UniformSphereSample, + VecExt +}; + +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 +}; + +pub use linalg::{ + qr, + eigen_qr, + householder_matrix +}; + +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub mod na; mod structs; mod traits; @@ -117,14 +181,746 @@ mod linalg; // mod lower_triangular; // mod chol; -#[cfg(test)] -mod tests { - mod vec; - mod mat; +/* + * Reexport everything. + */ +/// Traits to work around the language limitations related to operator overloading. +/// +/// The trait names are formed by: +/// +/// * a type name (eg. Vec1, Vec2, Mat3, Mat4, etc.). +/// * the name of a binary operation (eg. Mul, Div, Add, Sub, etc.). +/// * the word `Rhs`. +/// +/// When implemented by the type `T`, the trait makes it possible to overload the binary operator +/// between `T` and the type name given by the trait. +/// +/// # Examples: +/// +/// * `Vec3MulRhs` will allow the overload of the `*` operator between the implementor type and +/// `Vec3`. The `Vec3` being the first argument of the multiplication. +/// * `Mat4DivRhs` will allow the overload of the `/` operator between the implementor type and +/// `Mat4`. The `Mat4` being the first argument of the division. +pub mod overload { + pub use structs::{Vec1MulRhs, Vec2MulRhs, Vec3MulRhs, Vec4MulRhs, Vec5MulRhs, Vec6MulRhs, + Vec1DivRhs, Vec2DivRhs, Vec3DivRhs, Vec4DivRhs, Vec5DivRhs, Vec6DivRhs, + Vec1AddRhs, Vec2AddRhs, Vec3AddRhs, Vec4AddRhs, Vec5AddRhs, Vec6AddRhs, + Vec1SubRhs, Vec2SubRhs, Vec3SubRhs, Vec4SubRhs, Vec5SubRhs, Vec6SubRhs, + Mat1MulRhs, Mat2MulRhs, Mat3MulRhs, Mat4MulRhs, Mat5MulRhs, Mat6MulRhs, + Mat1DivRhs, Mat2DivRhs, Mat3DivRhs, Mat4DivRhs, Mat5DivRhs, Mat6DivRhs, + Mat1AddRhs, Mat2AddRhs, Mat3AddRhs, Mat4AddRhs, Mat5AddRhs, Mat6AddRhs, + Mat1SubRhs, Mat2SubRhs, Mat3SubRhs, Mat4SubRhs, Mat5SubRhs, Mat6SubRhs}; } -#[cfg(test)] -mod bench { - mod vec; - mod mat; +/// Change the input value to ensure it is on the range `[min, max]`. +#[inline(always)] +pub fn clamp(val: T, min: T, max: T) -> T { + if val > min { + if val < max { + val + } + else { + max + } + } + else { + min + } } + +/// Same as `cmp::max`. +#[inline(always)] +pub fn max(a: T, b: T) -> T { + cmp::max(a, b) +} + +/// Same as `cmp::min`. +#[inline(always)] +pub fn min(a: T, b: T) -> T { + cmp::min(a, b) +} + +/// Returns the infimum of `a` and `b`. +#[inline(always)] +pub fn inf(a: &T, b: &T) -> T { + PartialOrd::inf(a, b) +} + +/// Returns the supremum of `a` and `b`. +#[inline(always)] +pub fn sup(a: &T, b: &T) -> T { + PartialOrd::sup(a, b) +} + +/// Compare `a` and `b` using a partial ordering relation. +#[inline(always)] +pub fn partial_cmp(a: &T, b: &T) -> PartialOrdering { + PartialOrd::partial_cmp(a, b) +} + +/// Returns `true` iff `a` and `b` are comparable and `a < b`. +#[inline(always)] +pub fn partial_lt(a: &T, b: &T) -> bool { + PartialOrd::partial_lt(a, b) +} + +/// Returns `true` iff `a` and `b` are comparable and `a <= b`. +#[inline(always)] +pub fn partial_le(a: &T, b: &T) -> bool { + PartialOrd::partial_le(a, b) +} + +/// Returns `true` iff `a` and `b` are comparable and `a > b`. +#[inline(always)] +pub fn partial_gt(a: &T, b: &T) -> bool { + PartialOrd::partial_gt(a, b) +} + +/// Returns `true` iff `a` and `b` are comparable and `a >= b`. +#[inline(always)] +pub fn partial_ge(a: &T, b: &T) -> bool { + PartialOrd::partial_ge(a, b) +} + +/// Return the minimum of `a` and `b` if they are comparable. +#[inline(always)] +pub fn partial_min<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<&'a T> { + PartialOrd::partial_min(a, b) +} + +/// Return the maximum of `a` and `b` if they are comparable. +#[inline(always)] +pub fn partial_max<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<&'a T> { + PartialOrd::partial_max(a, b) +} + +/// Clamp `value` between `min` and `max`. Returns `None` if `value` is not comparable to +/// `min` or `max`. +#[inline(always)] +pub fn partial_clamp<'a, T: PartialOrd>(value: &'a T, min: &'a T, max: &'a T) -> Option<&'a T> { + PartialOrd::partial_clamp(value, min, max) +} + +// +// +// 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()`. +#[inline(always)] +pub fn zero() -> T { + Zero::zero() +} + +/// Create a one-valued value. +/// +/// This is the same as `std::num::one()`. +#[inline(always)] +pub fn one() -> T { + One::one() +} + +// +// +// Geometry +// +// + +/* + * Perspective + */ +/// Computes a projection matrix given the frustrum near plane width, height, the field of +/// view, and the distance to the clipping planes (`znear` and `zfar`). +pub fn perspective3d + Zero + One>(width: N, height: N, fov: N, znear: N, zfar: N) -> Mat4 { + 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()) +} + +/* + * Translation + */ + +/// Gets the translation applicable by `m`. +/// +/// ```rust +/// extern crate "nalgebra" as na; +/// use na::{Vec3, Iso3}; +/// +/// fn main() { +/// let t = Iso3::new(Vec3::new(1.0f64, 1.0, 1.0), na::zero()); +/// 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 `m`. +/// +/// ```rust +/// extern crate "nalgebra" as na; +/// use na::{Vec3, Iso3}; +/// +/// fn main() { +/// let t = Iso3::new(Vec3::new(1.0f64, 1.0, 1.0), na::zero()); +/// 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() +} + +/// Applies the translation `v` to a copy of `m`. +#[inline(always)] +pub fn append_translation>(m: &M, v: &V) -> M { + Translation::append_translation_cpy(m, v) +} + +/* + * Translate + */ + +/// Applies a translation to a vector. +/// +/// ```rust +/// extern crate "nalgebra" as na; +/// use na::{Vec3, Iso3}; +/// +/// fn main() { +/// let t = Iso3::new(Vec3::new(1.0f64, 1.0, 1.0), na::zero()); +/// let v = Vec3::new(2.0, 2.0, 2.0); +/// +/// let tv = na::translate(&t, &v); +/// +/// assert!(tv == Vec3::new(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 crate "nalgebra" as na; +/// use na::{Vec3, Iso3}; +/// +/// fn main() { +/// let t = Iso3::new(Vec3::new(1.0f64, 1.0, 1.0), na::zero()); +/// let v = Vec3::new(2.0, 2.0, 2.0); +/// +/// let tv = na::inv_translate(&t, &v); +/// +/// assert!(na::approx_eq(&tv, &Vec3::new(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 `m`. +/// +/// ```rust +/// extern crate "nalgebra" as na; +/// use na::{Vec3, Rot3}; +/// +/// fn main() { +/// let t = Rot3::new(Vec3::new(1.0f64, 1.0, 1.0)); +/// +/// assert!(na::approx_eq(&na::rotation(&t), &Vec3::new(1.0, 1.0, 1.0))); +/// } +/// ``` +#[inline(always)] +pub fn rotation>(m: &M) -> V { + m.rotation() +} + + +/// Gets the inverse rotation applicable by `m`. +/// +/// ```rust +/// extern crate "nalgebra" as na; +/// use na::{Vec3, Rot3}; +/// +/// fn main() { +/// let t = Rot3::new(Vec3::new(1.0f64, 1.0, 1.0)); +/// +/// assert!(na::approx_eq(&na::inv_rotation(&t), &Vec3::new(-1.0, -1.0, -1.0))); +/// } +/// ``` +#[inline(always)] +pub fn inv_rotation>(m: &M) -> V { + m.inv_rotation() +} + +// FIXME: this example is a bit shity +/// Applies the rotation `v` to a copy of `m`. +/// +/// ```rust +/// extern crate "nalgebra" as na; +/// use na::{Vec3, Rot3}; +/// +/// fn main() { +/// let t = Rot3::new(Vec3::new(0.0f64, 0.0, 0.0)); +/// let v = Vec3::new(1.0, 1.0, 1.0); +/// let rt = na::append_rotation(&t, &v); +/// +/// assert!(na::approx_eq(&na::rotation(&rt), &Vec3::new(1.0, 1.0, 1.0))) +/// } +/// ``` +#[inline(always)] +pub fn append_rotation>(m: &M, v: &V) -> M { + Rotation::append_rotation_cpy(m, v) +} + +// FIXME: this example is a bit shity +/// Pre-applies the rotation `v` to a copy of `m`. +/// +/// ```rust +/// extern crate "nalgebra" as na; +/// use na::{Vec3, Rot3}; +/// +/// fn main() { +/// let t = Rot3::new(Vec3::new(0.0f64, 0.0, 0.0)); +/// let v = Vec3::new(1.0, 1.0, 1.0); +/// let rt = na::prepend_rotation(&t, &v); +/// +/// assert!(na::approx_eq(&na::rotation(&rt), &Vec3::new(1.0, 1.0, 1.0))) +/// } +/// ``` +#[inline(always)] +pub fn prepend_rotation>(m: &M, v: &V) -> M { + Rotation::prepend_rotation_cpy(m, v) +} + +/* + * Rotate + */ + +/// Applies a rotation to a vector. +/// +/// ```rust +/// extern crate "nalgebra" as na; +/// use std::num::Float; +/// use na::{Rot3, Vec3}; +/// +/// fn main() { +/// let t = Rot3::new(Vec3::new(0.0f64, 0.0, 0.5 * Float::pi())); +/// let v = Vec3::new(1.0, 0.0, 0.0); +/// +/// let tv = na::rotate(&t, &v); +/// +/// assert!(na::approx_eq(&tv, &Vec3::new(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 crate "nalgebra" as na; +/// use std::num::Float; +/// use na::{Rot3, Vec3}; +/// +/// fn main() { +/// let t = Rot3::new(Vec3::new(0.0f64, 0.0, 0.5 * Float::pi())); +/// let v = Vec3::new(1.0, 0.0, 0.0); +/// +/// let tv = na::inv_rotate(&t, &v); +/// +/// assert!(na::approx_eq(&tv, &Vec3::new(0.0, -1.0, 0.0))) +/// } +/// ``` +#[inline(always)] +pub fn inv_rotate>(m: &M, v: &V) -> V { + m.inv_rotate(v) +} + +/* + * RotationWithTranslation + */ + +/// Rotates a copy of `m` by `amount` using `center` as the pivot point. +#[inline(always)] +pub fn append_rotation_wrt_point, + AV, + M: RotationWithTranslation>( + m: &M, + amount: &AV, + center: &LV) -> M { + RotationWithTranslation::append_rotation_wrt_point_cpy(m, amount, center) +} + +/// Rotates a copy of `m` by `amount` using `m.translation()` as the pivot point. +#[inline(always)] +pub fn append_rotation_wrt_center, + AV, + M: RotationWithTranslation>( + m: &M, + amount: &AV) -> M { + RotationWithTranslation::append_rotation_wrt_center_cpy(m, amount) +} + +/* + * RotationMatrix + */ + +/// Builds a rotation matrix from `r`. +#[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 `m`. +#[inline(always)] +pub fn transformation>(m: &M) -> T { + m.transformation() +} + +/// Gets the inverse transformation applicable by `m`. +#[inline(always)] +pub fn inv_transformation>(m: &M) -> T { + m.inv_transformation() +} + +/// Gets a transformed copy of `m`. +#[inline(always)] +pub fn append_transformation>(m: &M, t: &T) -> M { + Transformation::append_transformation_cpy(m, 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 { + Dot::dot(a, b) +} + +/// Computes a subtraction followed by a dot product. +#[inline(always)] +pub fn sub_dot, N>(a: &V, b: &V, c: &V) -> N { + Dot::sub_dot(a, b, c) +} + +/* + * Norm + */ + +/// Computes the L2 norm of a vector. +#[inline(always)] +pub fn norm, N: Float>(v: &V) -> N { + Norm::norm(v) +} + +/// Computes the squared L2 norm of a vector. +#[inline(always)] +pub fn sqnorm, N: Float>(v: &V) -> N { + Norm::sqnorm(v) +} + +/// Gets the normalized version of a vector. +#[inline(always)] +pub fn normalize, N: Float>(v: &V) -> V { + Norm::normalize_cpy(v) +} + +/* + * Det + */ +/// Computes the determinant of a square matrix. +#[inline(always)] +pub fn det, N>(m: &M) -> N { + Det::det(m) +} + +/* + * Cross + */ + +/// Computes the cross product of two vectors. +#[inline(always)] +pub fn cross, AV>(a: &LV, b: &LV) -> AV { + Cross::cross(a, 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 { + CrossMatrix::cross_matrix(v) +} + +/* + * ToHomogeneous + */ + +/// Converts a matrix or vector to homogeneous coordinates. +#[inline(always)] +pub fn to_homogeneous, Res>(m: &M) -> Res { + ToHomogeneous::to_homogeneous(m) +} + +/* + * FromHomogeneous + */ + +/// Converts a matrix or vector from homogeneous 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: |V| -> ()) { + UniformSphereSample::sample(f) +} + +// +// +// Operations +// +// + +/* + * AproxEq + */ +/// Tests approximate equality. +#[inline(always)] +pub fn approx_eq, N>(a: &T, b: &T) -> bool { + ApproxEq::approx_eq(a, b) +} + +/// Tests approximate equality using a custom epsilon. +#[inline(always)] +pub fn approx_eq_eps, N>(a: &T, b: &T, eps: &N) -> bool { + ApproxEq::approx_eq_eps(a, b, eps) +} + + +/* + * Absolute + */ + +/// Computes a component-wise absolute value. +#[inline(always)] +pub fn abs, Res>(m: &M) -> Res { + Absolute::abs(m) +} + +/* + * Inv + */ + +/// Gets an inverted copy of a matrix. +#[inline(always)] +pub fn inv(m: &M) -> Option { + Inv::inv_cpy(m) +} + +/* + * Transpose + */ + +/// Gets a transposed copy of a matrix. +#[inline(always)] +pub fn transpose(m: &M) -> M { + Transpose::transpose_cpy(m) +} + +/* + * Outer + */ + +/// Computes the outer product of two vectors. +#[inline(always)] +pub fn outer, M>(a: &V, b: &V) -> M { + Outer::outer(a, b) +} + +/* + * Cov + */ + +/// Computes the covariance of a set of observations. +#[inline(always)] +pub fn cov, Res>(observations: &M) -> Res { + Cov::cov(observations) +} + +/* + * Mean + */ + +/// Computes the mean of a set of observations. +#[inline(always)] +pub fn mean>(observations: &M) -> N { + Mean::mean(observations) +} + +// +// +// Structure +// +// + +/* + * Eye + */ +/// Construct the identity matrix for a given dimension +#[inline(always)] +pub fn new_identity(dim: uint) -> M { + Eye::new_identity(dim) +} + +/* + * Basis + */ + +/// Computes the canonical basis for a given dimension. +#[inline(always)] +pub fn canonical_basis(f: |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: |V| -> bool) { + Basis::orthonormal_subspace_basis(v, f) +} + +/* + * Row + */ + +/* + * Col + */ + +/* + * Diag + */ +/// Gets the diagonal of a square matrix. +#[inline(always)] +pub fn diag, V>(m: &M) -> V { + m.diag() +} + +/* + * Dim + */ +/// Gets the dimension an object lives in. +/// +/// Same as `Dim::dim::(None::)`. +#[inline(always)] +pub fn dim() -> uint { + Dim::dim(None::) +} + +/* + * Cast + */ +/// Converts an object from one type to another. +/// +/// For primitive types, this is the same as the `as` keywords. +/// The following properties are preserved by a cast: +/// +/// * Type-level geometric invariants cannot be broken (eg. a cast from Rot3 to Rot3 is +/// not possible) +/// * A cast to a type with more type-level invariants cannot be done (eg. a cast from Mat to +/// Rot3 is not possible) +/// * For primitive types an unbounded cast is done using the `as` keyword (this is different from +/// the standard library which makes bound-checking to ensure eg. that a i64 is not out of the +/// range of an i32 when a cast from i64 to i32 is done). +/// * A cast does not affect the dimension of an algebraic object. Note that this prevents an +/// isometric transform to be cast to a raw matrix. Use `to_homogeneous` for that special purpose. +#[inline(always)] +pub fn cast>(t: T) -> U { + Cast::from(t) +} + +/* + * Indexable + */ diff --git a/src/na.rs b/src/na.rs index ec4da3bc..c5298494 100644 --- a/src/na.rs +++ b/src/na.rs @@ -1,4 +1,4 @@ -//! **nalgebra** prelude. +//! [DEPRECATED] **nalgebra** prelude. use std::num::{Zero, One, FloatMath}; use std::cmp; @@ -94,91 +94,94 @@ pub mod overload { /// Change the input value to ensure it is on the range `[min, max]`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn clamp(val: T, min: T, max: T) -> T { - if val > min { - if val < max { - val - } - else { - max - } - } - else { - min - } + super::clamp(val, min, max) } /// Same as `cmp::max`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn max(a: T, b: T) -> T { - cmp::max(a, b) + super::max(a, b) } /// Same as `cmp::min`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn min(a: T, b: T) -> T { - cmp::min(a, b) + super::min(a, b) } /// Returns the infimum of `a` and `b`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn inf(a: &T, b: &T) -> T { - PartialOrd::inf(a, b) + super::inf(a, b) } /// Returns the supremum of `a` and `b`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn sup(a: &T, b: &T) -> T { - PartialOrd::sup(a, b) + super::sup(a, b) } /// Compare `a` and `b` using a partial ordering relation. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn partial_cmp(a: &T, b: &T) -> PartialOrdering { - PartialOrd::partial_cmp(a, b) + super::partial_cmp(a, b) } /// Returns `true` iff `a` and `b` are comparable and `a < b`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn partial_lt(a: &T, b: &T) -> bool { - PartialOrd::partial_lt(a, b) + super::partial_lt(a, b) } /// Returns `true` iff `a` and `b` are comparable and `a <= b`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn partial_le(a: &T, b: &T) -> bool { - PartialOrd::partial_le(a, b) + super::partial_le(a, b) } /// Returns `true` iff `a` and `b` are comparable and `a > b`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn partial_gt(a: &T, b: &T) -> bool { - PartialOrd::partial_gt(a, b) + super::partial_gt(a, b) } /// Returns `true` iff `a` and `b` are comparable and `a >= b`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn partial_ge(a: &T, b: &T) -> bool { - PartialOrd::partial_ge(a, b) + super::partial_ge(a, b) } /// Return the minimum of `a` and `b` if they are comparable. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn partial_min<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<&'a T> { - PartialOrd::partial_min(a, b) + super::partial_min(a, b) } /// Return the maximum of `a` and `b` if they are comparable. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn partial_max<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<&'a T> { - PartialOrd::partial_max(a, b) + super::partial_max(a, b) } /// Clamp `value` between `min` and `max`. Returns `None` if `value` is not comparable to /// `min` or `max`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn partial_clamp<'a, T: PartialOrd>(value: &'a T, min: &'a T, max: &'a T) -> Option<&'a T> { - PartialOrd::partial_clamp(value, min, max) + super::partial_clamp(value, min, max) } // @@ -191,24 +194,27 @@ pub fn partial_clamp<'a, T: PartialOrd>(value: &'a T, min: &'a T, max: &'a T) -> /// /// Same as `Identity::new()`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn identity() -> Identity { - Identity::new() + super::identity() } /// Create a zero-valued value. /// /// This is the same as `std::num::zero()`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn zero() -> T { - Zero::zero() + super::zero() } /// Create a one-valued value. /// /// This is the same as `std::num::one()`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn one() -> T { - One::one() + super::one() } // @@ -223,19 +229,7 @@ pub fn one() -> T { /// Computes a projection matrix given the frustrum near plane width, height, the field of /// view, and the distance to the clipping planes (`znear` and `zfar`). pub fn perspective3d + Zero + One>(width: N, height: N, fov: N, znear: N, zfar: N) -> Mat4 { - 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()) + super::perspective3d(width, height, fov, znear, zfar) } /* @@ -243,47 +237,24 @@ pub fn perspective3d + Zero + One>(width: N, height: N, */ /// Gets the translation applicable by `m`. -/// -/// ```rust -/// extern crate nalgebra; -/// use nalgebra::na::{Vec3, Iso3}; -/// use nalgebra::na; -/// -/// fn main() { -/// let t = Iso3::new(Vec3::new(1.0f64, 1.0, 1.0), na::zero()); -/// let trans = na::translation(&t); -/// -/// assert!(trans == Vec3::new(1.0, 1.0, 1.0)); -/// } -/// ``` #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn translation>(m: &M) -> V { - m.translation() + super::translation(m) } /// Gets the inverse translation applicable by `m`. -/// -/// ```rust -/// extern crate nalgebra; -/// use nalgebra::na::{Vec3, Iso3}; -/// use nalgebra::na; -/// -/// fn main() { -/// let t = Iso3::new(Vec3::new(1.0f64, 1.0, 1.0), na::zero()); -/// let itrans = na::inv_translation(&t); -/// -/// assert!(itrans == Vec3::new(-1.0, -1.0, -1.0)); -/// } -/// ``` #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn inv_translation>(m: &M) -> V { - m.inv_translation() + super::inv_translation(m) } /// Applies the translation `v` to a copy of `m`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn append_translation>(m: &M, v: &V) -> M { - Translation::append_translation_cpy(m, v) + super::append_translation(m, v) } /* @@ -291,44 +262,17 @@ pub fn append_translation>(m: &M, v: &V) -> M { */ /// Applies a translation to a vector. -/// -/// ```rust -/// extern crate nalgebra; -/// use nalgebra::na::{Vec3, Iso3}; -/// use nalgebra::na; -/// -/// fn main() { -/// let t = Iso3::new(Vec3::new(1.0f64, 1.0, 1.0), na::zero()); -/// let v = Vec3::new(2.0, 2.0, 2.0); -/// -/// let tv = na::translate(&t, &v); -/// -/// assert!(tv == Vec3::new(3.0, 3.0, 3.0)) -/// } -/// ``` #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn translate>(m: &M, v: &V) -> V { - m.translate(v) + super::translate(m, v) } /// Applies an inverse translation to a vector. -/// -/// ```rust -/// extern crate nalgebra; -/// use nalgebra::na::{Vec3, Iso3}; -/// use nalgebra::na; -/// -/// fn main() { -/// let t = Iso3::new(Vec3::new(1.0f64, 1.0, 1.0), na::zero()); -/// let v = Vec3::new(2.0, 2.0, 2.0); -/// -/// let tv = na::inv_translate(&t, &v); -/// -/// assert!(na::approx_eq(&tv, &Vec3::new(1.0, 1.0, 1.0))) -/// } #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn inv_translate>(m: &M, v: &V) -> V { - m.inv_translate(v) + super::inv_translate(m, v) } /* @@ -336,82 +280,34 @@ pub fn inv_translate>(m: &M, v: &V) -> V { */ /// Gets the rotation applicable by `m`. -/// -/// ```rust -/// extern crate nalgebra; -/// use nalgebra::na::{Vec3, Rot3}; -/// use nalgebra::na; -/// -/// fn main() { -/// let t = Rot3::new(Vec3::new(1.0f64, 1.0, 1.0)); -/// -/// assert!(na::approx_eq(&na::rotation(&t), &Vec3::new(1.0, 1.0, 1.0))); -/// } -/// ``` #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn rotation>(m: &M) -> V { - m.rotation() + super::rotation(m) } /// Gets the inverse rotation applicable by `m`. -/// -/// ```rust -/// extern crate nalgebra; -/// use nalgebra::na::{Vec3, Rot3}; -/// use nalgebra::na; -/// -/// fn main() { -/// let t = Rot3::new(Vec3::new(1.0f64, 1.0, 1.0)); -/// -/// assert!(na::approx_eq(&na::inv_rotation(&t), &Vec3::new(-1.0, -1.0, -1.0))); -/// } -/// ``` #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn inv_rotation>(m: &M) -> V { - m.inv_rotation() + super::inv_rotation(m) } // FIXME: this example is a bit shity /// Applies the rotation `v` to a copy of `m`. -/// -/// ```rust -/// extern crate nalgebra; -/// use nalgebra::na::{Vec3, Rot3}; -/// use nalgebra::na; -/// -/// fn main() { -/// let t = Rot3::new(Vec3::new(0.0f64, 0.0, 0.0)); -/// let v = Vec3::new(1.0, 1.0, 1.0); -/// let rt = na::append_rotation(&t, &v); -/// -/// assert!(na::approx_eq(&na::rotation(&rt), &Vec3::new(1.0, 1.0, 1.0))) -/// } -/// ``` #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn append_rotation>(m: &M, v: &V) -> M { - Rotation::append_rotation_cpy(m, v) + super::append_rotation(m, v) } // FIXME: this example is a bit shity /// Pre-applies the rotation `v` to a copy of `m`. -/// -/// ```rust -/// extern crate nalgebra; -/// use nalgebra::na::{Vec3, Rot3}; -/// use nalgebra::na; -/// -/// fn main() { -/// let t = Rot3::new(Vec3::new(0.0f64, 0.0, 0.0)); -/// let v = Vec3::new(1.0, 1.0, 1.0); -/// let rt = na::prepend_rotation(&t, &v); -/// -/// assert!(na::approx_eq(&na::rotation(&rt), &Vec3::new(1.0, 1.0, 1.0))) -/// } -/// ``` #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn prepend_rotation>(m: &M, v: &V) -> M { - Rotation::prepend_rotation_cpy(m, v) + super::prepend_rotation(m, v) } /* @@ -419,48 +315,18 @@ pub fn prepend_rotation>(m: &M, v: &V) -> M { */ /// Applies a rotation to a vector. -/// -/// ```rust -/// extern crate nalgebra; -/// use std::num::Float; -/// use nalgebra::na::{Rot3, Vec3}; -/// use nalgebra::na; -/// -/// fn main() { -/// let t = Rot3::new(Vec3::new(0.0f64, 0.0, 0.5 * Float::pi())); -/// let v = Vec3::new(1.0, 0.0, 0.0); -/// -/// let tv = na::rotate(&t, &v); -/// -/// assert!(na::approx_eq(&tv, &Vec3::new(0.0, 1.0, 0.0))) -/// } -/// ``` #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn rotate>(m: &M, v: &V) -> V { - m.rotate(v) + super::rotate(m, v) } /// Applies an inverse rotation to a vector. -/// -/// ```rust -/// extern crate nalgebra; -/// use std::num::Float; -/// use nalgebra::na::{Rot3, Vec3}; -/// use nalgebra::na; -/// -/// fn main() { -/// let t = Rot3::new(Vec3::new(0.0f64, 0.0, 0.5 * Float::pi())); -/// let v = Vec3::new(1.0, 0.0, 0.0); -/// -/// let tv = na::inv_rotate(&t, &v); -/// -/// assert!(na::approx_eq(&tv, &Vec3::new(0.0, -1.0, 0.0))) -/// } -/// ``` #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn inv_rotate>(m: &M, v: &V) -> V { - m.inv_rotate(v) + super::inv_rotate(m, v) } /* @@ -469,23 +335,25 @@ pub fn inv_rotate>(m: &M, v: &V) -> V { /// Rotates a copy of `m` by `amount` using `center` as the pivot point. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn append_rotation_wrt_point, AV, M: RotationWithTranslation>( m: &M, amount: &AV, center: &LV) -> M { - RotationWithTranslation::append_rotation_wrt_point_cpy(m, amount, center) + super::append_rotation_wrt_point(m, amount, center) } /// Rotates a copy of `m` by `amount` using `m.translation()` as the pivot point. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn append_rotation_wrt_center, AV, M: RotationWithTranslation>( m: &M, amount: &AV) -> M { - RotationWithTranslation::append_rotation_wrt_center_cpy(m, amount) + super::append_rotation_wrt_center(m, amount) } /* @@ -494,8 +362,9 @@ pub fn append_rotation_wrt_center, /// Builds a rotation matrix from `r`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn to_rot_mat + Rotation, R: RotationMatrix>(r: &R) -> M { - r.to_rot_mat() + super::to_rot_mat(r) } /* @@ -504,8 +373,9 @@ pub fn to_rot_mat + Rotation, R: RotationMatrix>(m: &M, v: &V) -> V { - m.absolute_rotate(v) + super::absolute_rotate(m, v) } /* @@ -514,20 +384,22 @@ pub fn absolute_rotate>(m: &M, v: &V) -> V { /// Gets the transformation applicable by `m`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn transformation>(m: &M) -> T { - m.transformation() + super::transformation(m) } /// Gets the inverse transformation applicable by `m`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn inv_transformation>(m: &M) -> T { - m.inv_transformation() + super::inv_transformation(m) } /// Gets a transformed copy of `m`. #[inline(always)] pub fn append_transformation>(m: &M, t: &T) -> M { - Transformation::append_transformation_cpy(m, t) + super::append_transformation(m, t) } /* @@ -536,14 +408,16 @@ pub fn append_transformation>(m: &M, t: &T) -> M { /// Applies a transformation to a vector. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn transform>(m: &M, v: &V) -> V { - m.transform(v) + super::transform(m, v) } /// Applies an inverse transformation to a vector. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn inv_transform>(m: &M, v: &V) -> V { - m.inv_transform(v) + super::inv_transform(m, v) } /* @@ -552,14 +426,16 @@ pub fn inv_transform>(m: &M, v: &V) -> V { /// Computes the dot product of two vectors. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn dot, N>(a: &V, b: &V) -> N { - Dot::dot(a, b) + super::dot(a, b) } /// Computes a subtraction followed by a dot product. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn sub_dot, N>(a: &V, b: &V, c: &V) -> N { - Dot::sub_dot(a, b, c) + super::sub_dot(a, b, c) } /* @@ -568,20 +444,23 @@ pub fn sub_dot, N>(a: &V, b: &V, c: &V) -> N { /// Computes the L2 norm of a vector. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn norm, N: Float>(v: &V) -> N { - Norm::norm(v) + super::norm(v) } /// Computes the squared L2 norm of a vector. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn sqnorm, N: Float>(v: &V) -> N { - Norm::sqnorm(v) + super::sqnorm(v) } /// Gets the normalized version of a vector. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn normalize, N: Float>(v: &V) -> V { - Norm::normalize_cpy(v) + super::normalize(v) } /* @@ -589,8 +468,9 @@ pub fn normalize, N: Float>(v: &V) -> V { */ /// Computes the determinant of a square matrix. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn det, N>(m: &M) -> N { - Det::det(m) + super::det(m) } /* @@ -599,8 +479,9 @@ pub fn det, N>(m: &M) -> N { /// Computes the cross product of two vectors. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn cross, AV>(a: &LV, b: &LV) -> AV { - Cross::cross(a, b) + super::cross(a, b) } /* @@ -610,8 +491,9 @@ pub fn cross, AV>(a: &LV, b: &LV) -> AV { /// Given a vector, computes the matrix which, when multiplied by another vector, computes a cross /// product. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn cross_matrix, M>(v: &V) -> M { - CrossMatrix::cross_matrix(v) + super::cross_matrix(v) } /* @@ -620,8 +502,9 @@ pub fn cross_matrix, M>(v: &V) -> M { /// Converts a matrix or vector to homogeneous coordinates. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn to_homogeneous, Res>(m: &M) -> Res { - ToHomogeneous::to_homogeneous(m) + super::to_homogeneous(m) } /* @@ -632,8 +515,9 @@ pub fn to_homogeneous, Res>(m: &M) -> Res { /// /// w-normalization is appied. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn from_homogeneous>(m: &M) -> Res { - FromHomogeneous::from(m) + super::from_homogeneous(m) } /* @@ -644,8 +528,9 @@ pub fn from_homogeneous>(m: &M) -> Res { /// /// The number of sampling point is implementation-specific. It is always uniform. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn sample_sphere(f: |V| -> ()) { - UniformSphereSample::sample(f) + super::sample_sphere(f) } // @@ -659,14 +544,16 @@ pub fn sample_sphere(f: |V| -> ()) { */ /// Tests approximate equality. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn approx_eq, N>(a: &T, b: &T) -> bool { - ApproxEq::approx_eq(a, b) + super::approx_eq(a, b) } /// Tests approximate equality using a custom epsilon. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn approx_eq_eps, N>(a: &T, b: &T, eps: &N) -> bool { - ApproxEq::approx_eq_eps(a, b, eps) + super::approx_eq_eps(a, b, eps) } @@ -676,8 +563,9 @@ pub fn approx_eq_eps, N>(a: &T, b: &T, eps: &N) -> bool { /// Computes a component-wise absolute value. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn abs, Res>(m: &M) -> Res { - Absolute::abs(m) + super::abs(m) } /* @@ -686,8 +574,9 @@ pub fn abs, Res>(m: &M) -> Res { /// Gets an inverted copy of a matrix. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn inv(m: &M) -> Option { - Inv::inv_cpy(m) + super::inv(m) } /* @@ -696,8 +585,9 @@ pub fn inv(m: &M) -> Option { /// Gets a transposed copy of a matrix. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn transpose(m: &M) -> M { - Transpose::transpose_cpy(m) + super::transpose(m) } /* @@ -706,8 +596,9 @@ pub fn transpose(m: &M) -> M { /// Computes the outer product of two vectors. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn outer, M>(a: &V, b: &V) -> M { - Outer::outer(a, b) + super::outer(a, b) } /* @@ -716,8 +607,9 @@ pub fn outer, M>(a: &V, b: &V) -> M { /// Computes the covariance of a set of observations. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn cov, Res>(observations: &M) -> Res { - Cov::cov(observations) + super::cov(observations) } /* @@ -726,8 +618,9 @@ pub fn cov, Res>(observations: &M) -> Res { /// Computes the mean of a set of observations. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn mean>(observations: &M) -> N { - Mean::mean(observations) + super::mean(observations) } // @@ -741,7 +634,10 @@ pub fn mean>(observations: &M) -> N { */ /// Construct the identity matrix for a given dimension #[inline(always)] -pub fn new_identity(dim: uint) -> M { Eye::new_identity(dim) } +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] +pub fn new_identity(dim: uint) -> M { + super::new_identity(dim) +} /* * Basis @@ -749,14 +645,16 @@ pub fn new_identity(dim: uint) -> M { Eye::new_identity(dim) } /// Computes the canonical basis for a given dimension. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn canonical_basis(f: |V| -> bool) { - Basis::canonical_basis(f) + super::canonical_basis(f) } /// Computes the basis of the orthonormal subspace of a given vector. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn orthonormal_subspace_basis(v: &V, f: |V| -> bool) { - Basis::orthonormal_subspace_basis(v, f) + super::orthonormal_subspace_basis(v, f) } /* @@ -772,8 +670,9 @@ pub fn orthonormal_subspace_basis(v: &V, f: |V| -> bool) { */ /// Gets the diagonal of a square matrix. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn diag, V>(m: &M) -> V { - m.diag() + super::diag(m) } /* @@ -783,8 +682,9 @@ pub fn diag, V>(m: &M) -> V { /// /// Same as `Dim::dim::(None::)`. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn dim() -> uint { - Dim::dim(None::) + super::dim::() } /* @@ -805,8 +705,9 @@ pub fn dim() -> uint { /// * A cast does not affect the dimension of an algebraic object. Note that this prevents an /// isometric transform to be cast to a raw matrix. Use `to_homogeneous` for that special purpose. #[inline(always)] +#[deprecated = "use the root module `nalgebra::` directly instead of the `nalgebra::na::` module (you may create an alias `extern crate \"nalgebra\" as na;` when importing the crate)"] pub fn cast>(t: T) -> U { - Cast::from(t) + super::cast::(t) } /* diff --git a/src/tests/mat.rs b/tests/mat.rs similarity index 98% rename from src/tests/mat.rs rename to tests/mat.rs index b5388bb3..8526510c 100644 --- a/src/tests/mat.rs +++ b/tests/mat.rs @@ -1,8 +1,12 @@ +#![feature(macro_rules)] + +extern crate debug; +extern crate "nalgebra" as na; + use std::num::{Float, abs}; use std::rand::random; -use na::{Vec1, Vec3, Mat1, Mat2, Mat3, Mat4, Mat5, Mat6, Rot3, DMat, DVec, Indexable, Row, Col}; -use na; use std::cmp::{min, max}; +use na::{Vec1, Vec3, Mat1, Mat2, Mat3, Mat4, Mat5, Mat6, Rot3, DMat, DVec, Indexable, Row, Col}; macro_rules! test_inv_mat_impl( ($t: ty) => ( diff --git a/src/tests/vec.rs b/tests/vec.rs similarity index 97% rename from src/tests/vec.rs rename to tests/vec.rs index 97bb94e0..51524a91 100644 --- a/src/tests/vec.rs +++ b/tests/vec.rs @@ -1,7 +1,10 @@ +#![feature(macro_rules)] + +extern crate debug; +extern crate "nalgebra" as na; + use std::rand::random; -use na::{Vec0, Vec1, Vec2, Vec3, Vec4, Vec5, Vec6}; -use na::{Mat3, Iterable, IterableMut}; // FIXME: get rid of that -use na; +use na::{Vec0, Vec1, Vec2, Vec3, Vec4, Vec5, Vec6, Mat3, Iterable, IterableMut}; macro_rules! test_iterator_impl( ($t: ty, $n: ty) => (