Quick update to the last rust-nightly.

This is just a quick-fix so that nalgebra compiles.
This does not fix the deprecation warnings!

Version of rustc: 0.13.0-nightly (d91a015ab 2014-11-14 23:37:27 +0000).
This commit is contained in:
Sébastien Crozet 2014-11-15 15:47:59 +01:00
parent 15d1fa0b8b
commit 39b9d20717
26 changed files with 164 additions and 117 deletions

View File

@ -108,7 +108,7 @@ extern crate serialize;
#[cfg(test)] #[cfg(test)]
extern crate test; extern crate test;
use std::num::{Zero, One, FloatMath}; use std::num::{Zero, One};
use std::cmp; use std::cmp;
pub use traits::{PartialLess, PartialEqual, PartialGreater, NotComparable}; pub use traits::{PartialLess, PartialEqual, PartialGreater, NotComparable};
pub use traits::{ pub use traits::{
@ -119,6 +119,7 @@ pub use traits::{
ApproxEq, ApproxEq,
Axpy, Axpy,
Basis, Basis,
BaseFloat,
Cast, Cast,
Col, Col,
ColSlice, RowSlice, ColSlice, RowSlice,
@ -357,7 +358,7 @@ pub fn orig<P: Orig>() -> P {
/// Returns the center of two points. /// Returns the center of two points.
#[inline] #[inline]
pub fn center<N: Float, P: FloatPnt<N, V>, V>(a: &P, b: &P) -> P { pub fn center<N: BaseFloat, P: FloatPnt<N, V>, V>(a: &P, b: &P) -> P {
let _2 = one::<N>() + one(); let _2 = one::<N>() + one();
(*a + *b.as_vec()) / _2 (*a + *b.as_vec()) / _2
} }
@ -367,13 +368,13 @@ pub fn center<N: Float, P: FloatPnt<N, V>, V>(a: &P, b: &P) -> P {
*/ */
/// Returns the distance between two points. /// Returns the distance between two points.
#[inline(always)] #[inline(always)]
pub fn dist<N: Float, P: FloatPnt<N, V>, V: Norm<N>>(a: &P, b: &P) -> N { pub fn dist<N: BaseFloat, P: FloatPnt<N, V>, V: Norm<N>>(a: &P, b: &P) -> N {
FloatPnt::<N, V>::dist(a, b) FloatPnt::<N, V>::dist(a, b)
} }
/// Returns the squared distance between two points. /// Returns the squared distance between two points.
#[inline(always)] #[inline(always)]
pub fn sqdist<N: Float, P: FloatPnt<N, V>, V: Norm<N>>(a: &P, b: &P) -> N { pub fn sqdist<N: BaseFloat, P: FloatPnt<N, V>, V: Norm<N>>(a: &P, b: &P) -> N {
FloatPnt::<N, V>::sqdist(a, b) FloatPnt::<N, V>::sqdist(a, b)
} }
@ -383,7 +384,7 @@ pub fn sqdist<N: Float, P: FloatPnt<N, V>, V: Norm<N>>(a: &P, b: &P) -> N {
/// Computes a projection matrix given the frustrum near plane width, height, the field of /// 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`). /// view, and the distance to the clipping planes (`znear` and `zfar`).
#[deprecated = "Use `Persp3::new(width / height, fov, znear, zfar).as_mat()` instead"] #[deprecated = "Use `Persp3::new(width / height, fov, znear, zfar).as_mat()` instead"]
pub fn perspective3d<N: FloatMath + Cast<f64> + Zero + One>(width: N, height: N, fov: N, znear: N, zfar: N) -> Mat4<N> { 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 aspect = width / height;
let _1: N = one(); let _1: N = one();
@ -713,19 +714,19 @@ pub fn dot<V: Dot<N>, N>(a: &V, b: &V) -> N {
/// Computes the L2 norm of a vector. /// Computes the L2 norm of a vector.
#[inline(always)] #[inline(always)]
pub fn norm<V: Norm<N>, N: Float>(v: &V) -> N { pub fn norm<V: Norm<N>, N: BaseFloat>(v: &V) -> N {
Norm::norm(v) Norm::norm(v)
} }
/// Computes the squared L2 norm of a vector. /// Computes the squared L2 norm of a vector.
#[inline(always)] #[inline(always)]
pub fn sqnorm<V: Norm<N>, N: Float>(v: &V) -> N { pub fn sqnorm<V: Norm<N>, N: BaseFloat>(v: &V) -> N {
Norm::sqnorm(v) Norm::sqnorm(v)
} }
/// Gets the normalized version of a vector. /// Gets the normalized version of a vector.
#[inline(always)] #[inline(always)]
pub fn normalize<V: Norm<N>, N: Float>(v: &V) -> V { pub fn normalize<V: Norm<N>, N: BaseFloat>(v: &V) -> V {
Norm::normalize_cpy(v) Norm::normalize_cpy(v)
} }

View File

@ -1,6 +1,6 @@
use std::num::{Zero, Float}; use std::num::Zero;
use traits::operations::{Transpose, ApproxEq}; use traits::operations::{Transpose, ApproxEq};
use traits::structure::{ColSlice, Eye, Indexable, Diag, SquareMat}; use traits::structure::{ColSlice, Eye, Indexable, Diag, SquareMat, BaseFloat};
use traits::geometry::Norm; use traits::geometry::Norm;
use std::cmp::min; use std::cmp::min;
@ -12,7 +12,7 @@ use std::cmp::min;
/// * `start` - the starting dimension of the subspace of the reflexion /// * `start` - the starting dimension of the subspace of the reflexion
/// * `vec` - the vector defining the reflection. /// * `vec` - the vector defining the reflection.
pub fn householder_matrix<N, V, M>(dim: uint, start: uint, vec: V) -> M pub fn householder_matrix<N, V, M>(dim: uint, start: uint, vec: V) -> M
where N: Float, where N: BaseFloat,
M: Eye + Indexable<(uint, uint), N>, M: Eye + Indexable<(uint, uint), N>,
V: Indexable<uint, N> { V: Indexable<uint, N> {
let mut qk : M = Eye::new_identity(dim); let mut qk : M = Eye::new_identity(dim);
@ -39,7 +39,7 @@ pub fn householder_matrix<N, V, M>(dim: uint, start: uint, vec: V) -> M
/// # Arguments /// # Arguments
/// * `m` - matrix to decompose /// * `m` - matrix to decompose
pub fn qr<N, V, M>(m: &M) -> (M, M) pub fn qr<N, V, M>(m: &M) -> (M, M)
where N: Float, where N: BaseFloat,
V: Indexable<uint, N> + Norm<N>, V: Indexable<uint, N> + Norm<N>,
M: Clone + Eye + ColSlice<V> + Transpose + Indexable<(uint, uint), N> + Mul<M, M> { M: Clone + Eye + ColSlice<V> + Transpose + Indexable<(uint, uint), N> + Mul<M, M> {
let (rows, cols) = m.shape(); let (rows, cols) = m.shape();
@ -74,7 +74,7 @@ pub fn qr<N, V, M>(m: &M) -> (M, M)
/// Eigendecomposition of a square matrix using the qr algorithm. /// Eigendecomposition of a square matrix using the qr algorithm.
pub fn eigen_qr<N, V, VS, M>(m: &M, eps: &N, niter: uint) -> (M, V) pub fn eigen_qr<N, V, VS, M>(m: &M, eps: &N, niter: uint) -> (M, V)
where N: Float, where N: BaseFloat,
VS: Indexable<uint, N> + Norm<N>, VS: Indexable<uint, N> + Norm<N>,
M: Indexable<(uint, uint), N> + SquareMat<N, V> + Add<M, M> + Sub<M, M> + ColSlice<VS> + M: Indexable<(uint, uint), N> + SquareMat<N, V> + Add<M, M> + Sub<M, M> + ColSlice<VS> +
ApproxEq<N> + Clone { ApproxEq<N> + Clone {

View File

@ -5,7 +5,7 @@
use std::cmp; use std::cmp;
use std::rand::Rand; use std::rand::Rand;
use std::rand; use std::rand;
use std::num::{One, Zero}; use std::num::{One, Zero, Num};
use traits::operations::ApproxEq; use traits::operations::ApproxEq;
use std::mem; use std::mem;
use structs::dvec::{DVec, DVecMulRhs}; use structs::dvec::{DVec, DVecMulRhs};

View File

@ -2,14 +2,14 @@
#![allow(missing_docs)] // we hide doc to not have to document the $trhs double dispatch trait. #![allow(missing_docs)] // we hide doc to not have to document the $trhs double dispatch trait.
use std::num::{Zero, One, Float}; use std::num::{Zero, One, Num};
use std::rand::Rand; use std::rand::Rand;
use std::rand; use std::rand;
use std::slice::{Items, MutItems}; use std::slice::{Items, MutItems};
use traits::operations::ApproxEq; use traits::operations::ApproxEq;
use std::iter::FromIterator; use std::iter::FromIterator;
use traits::geometry::{Dot, Norm}; use traits::geometry::{Dot, Norm};
use traits::structure::{Iterable, IterableMut, Indexable, Shape}; use traits::structure::{Iterable, IterableMut, Indexable, Shape, BaseFloat};
/// Heap allocated, dynamically sized vector. /// Heap allocated, dynamically sized vector.
#[deriving(Eq, PartialEq, Show, Clone)] #[deriving(Eq, PartialEq, Show, Clone)]

View File

@ -132,7 +132,7 @@ macro_rules! dvec_impl(
} }
} }
impl<N: Clone + Float + ApproxEq<N> + $mul<N, $dvec<N>>> $dvec<N> { impl<N: Clone + BaseFloat + ApproxEq<N> + $mul<N, $dvec<N>>> $dvec<N> {
/// Computes the canonical basis for the given dimension. A canonical basis is a set of /// Computes the canonical basis for the given dimension. A canonical basis is a set of
/// vectors, mutually orthogonal, with all its component equal to 0.0 except one which is equal /// vectors, mutually orthogonal, with all its component equal to 0.0 except one which is equal
/// to 1.0. /// to 1.0.
@ -240,7 +240,7 @@ macro_rules! dvec_impl(
} }
} }
impl<N: Float + Clone> Norm<N> for $dvec<N> { impl<N: BaseFloat + Clone> Norm<N> for $dvec<N> {
#[inline] #[inline]
fn sqnorm(v: &$dvec<N>) -> N { fn sqnorm(v: &$dvec<N>) -> N {
Dot::dot(v, v) Dot::dot(v, v)

View File

@ -2,11 +2,11 @@
#![allow(missing_docs)] #![allow(missing_docs)]
use std::num::{Zero, One}; use std::num::{Zero, One, Num};
use std::rand::{Rand, Rng}; use std::rand::{Rand, Rng};
use structs::mat::{Mat3, Mat4, Mat5}; use structs::mat::{Mat3, Mat4, Mat5};
use traits::structure::{Cast, Dim, Col}; use traits::structure::{Cast, Dim, Col, BaseFloat};
use traits::operations::{Inv, ApproxEq}; use traits::operations::{Inv, ApproxEq, Absolute};
use traits::geometry::{RotationMatrix, Rotation, Rotate, AbsoluteRotate, Transform, Transformation, use traits::geometry::{RotationMatrix, Rotation, Rotate, AbsoluteRotate, Transform, Transformation,
Translate, Translation, ToHomogeneous}; Translate, Translation, ToHomogeneous};
@ -50,7 +50,7 @@ pub struct Iso4<N> {
pub translation: Vec4<N> pub translation: Vec4<N>
} }
impl<N: Clone + Float> Iso3<N> { impl<N: Clone + BaseFloat> Iso3<N> {
/// Reorient and translate this transformation such that its local `x` axis points to a given /// Reorient and translate this transformation such that its local `x` axis points to a given
/// direction. Note that the usually known `look_at` function does the same thing but with the /// direction. Note that the usually known `look_at` function does the same thing but with the
/// `z` axis. See `look_at_z` for that. /// `z` axis. See `look_at_z` for that.

View File

@ -2,7 +2,7 @@
macro_rules! iso_impl( macro_rules! iso_impl(
($t: ident, $submat: ident, $subvec: ident, $subrotvec: ident) => ( ($t: ident, $submat: ident, $subvec: ident, $subrotvec: ident) => (
impl<N: Clone + FloatMath + Num> $t<N> { impl<N: Clone + BaseFloat + Num> $t<N> {
/// Creates a new isometry from a rotation matrix and a vector. /// Creates a new isometry from a rotation matrix and a vector.
#[inline] #[inline]
pub fn new(translation: $subvec<N>, rotation: $subrotvec<N>) -> $t<N> { pub fn new(translation: $subvec<N>, rotation: $subrotvec<N>) -> $t<N> {
@ -26,7 +26,7 @@ macro_rules! iso_impl(
macro_rules! rotation_matrix_impl( macro_rules! rotation_matrix_impl(
($t: ident, $trot: ident, $tlv: ident, $tav: ident) => ( ($t: ident, $trot: ident, $tlv: ident, $tav: ident) => (
impl<N: Cast<f64> + FloatMath + Num + Clone> impl<N: Cast<f64> + BaseFloat + Num + Clone>
RotationMatrix<N, $tlv<N>, $tav<N>, $trot<N>> for $t<N> { RotationMatrix<N, $tlv<N>, $tav<N>, $trot<N>> for $t<N> {
#[inline] #[inline]
fn to_rot_mat(&self) -> $trot<N> { fn to_rot_mat(&self) -> $trot<N> {
@ -50,7 +50,7 @@ macro_rules! dim_impl(
macro_rules! one_impl( macro_rules! one_impl(
($t: ident) => ( ($t: ident) => (
impl<N: FloatMath + Clone> One for $t<N> { impl<N: BaseFloat + Clone> One for $t<N> {
#[inline] #[inline]
fn one() -> $t<N> { fn one() -> $t<N> {
$t::new_with_rotmat(Zero::zero(), One::one()) $t::new_with_rotmat(Zero::zero(), One::one())
@ -61,7 +61,7 @@ macro_rules! one_impl(
macro_rules! iso_mul_iso_impl( macro_rules! iso_mul_iso_impl(
($t: ident, $tmul: ident) => ( ($t: ident, $tmul: ident) => (
impl<N: FloatMath + Clone> $tmul<N, $t<N>> for $t<N> { impl<N: BaseFloat + Clone> $tmul<N, $t<N>> for $t<N> {
#[inline] #[inline]
fn binop(left: &$t<N>, right: &$t<N>) -> $t<N> { fn binop(left: &$t<N>, right: &$t<N>) -> $t<N> {
$t::new_with_rotmat( $t::new_with_rotmat(
@ -96,7 +96,7 @@ macro_rules! pnt_mul_iso_impl(
macro_rules! translation_impl( macro_rules! translation_impl(
($t: ident, $tv: ident) => ( ($t: ident, $tv: ident) => (
impl<N: FloatMath + Clone> Translation<$tv<N>> for $t<N> { impl<N: BaseFloat + Clone> Translation<$tv<N>> for $t<N> {
#[inline] #[inline]
fn translation(&self) -> $tv<N> { fn translation(&self) -> $tv<N> {
self.translation.clone() self.translation.clone()
@ -153,7 +153,7 @@ macro_rules! translate_impl(
macro_rules! rotation_impl( macro_rules! rotation_impl(
($t: ident, $trot: ident, $tav: ident) => ( ($t: ident, $trot: ident, $tav: ident) => (
impl<N: Cast<f64> + FloatMath + Clone> Rotation<$tav<N>> for $t<N> { impl<N: Cast<f64> + BaseFloat + Clone> Rotation<$tav<N>> for $t<N> {
#[inline] #[inline]
fn rotation(&self) -> $tav<N> { fn rotation(&self) -> $tav<N> {
self.rotation.rotation() self.rotation.rotation()
@ -220,7 +220,7 @@ macro_rules! rotate_impl(
macro_rules! transformation_impl( macro_rules! transformation_impl(
($t: ident) => ( ($t: ident) => (
impl<N: FloatMath + Clone> Transformation<$t<N>> for $t<N> { impl<N: BaseFloat + Clone> Transformation<$t<N>> for $t<N> {
fn transformation(&self) -> $t<N> { fn transformation(&self) -> $t<N> {
self.clone() self.clone()
} }
@ -357,7 +357,7 @@ macro_rules! approx_eq_impl(
macro_rules! rand_impl( macro_rules! rand_impl(
($t: ident) => ( ($t: ident) => (
impl<N: Rand + Clone + FloatMath> Rand for $t<N> { impl<N: Rand + Clone + BaseFloat> Rand for $t<N> {
#[inline] #[inline]
fn rand<R: Rng>(rng: &mut R) -> $t<N> { fn rand<R: Rng>(rng: &mut R) -> $t<N> {
$t::new(rng.gen(), rng.gen()) $t::new(rng.gen(), rng.gen())
@ -368,7 +368,7 @@ macro_rules! rand_impl(
macro_rules! absolute_rotate_impl( macro_rules! absolute_rotate_impl(
($t: ident, $tv: ident) => ( ($t: ident, $tv: ident) => (
impl<N: Signed> AbsoluteRotate<$tv<N>> for $t<N> { impl<N: BaseFloat> AbsoluteRotate<$tv<N>> for $t<N> {
#[inline] #[inline]
fn absolute_rotate(&self, v: &$tv<N>) -> $tv<N> { fn absolute_rotate(&self, v: &$tv<N>) -> $tv<N> {
self.rotation.absolute_rotate(v) self.rotation.absolute_rotate(v)

View File

@ -3,7 +3,7 @@
#![allow(missing_docs)] // we allow missing to avoid having to document the mij components. #![allow(missing_docs)] // we allow missing to avoid having to document the mij components.
use std::mem; use std::mem;
use std::num::{One, Zero}; use std::num::{One, Zero, Num};
use traits::operations::ApproxEq; use traits::operations::ApproxEq;
use std::slice::{Items, MutItems}; use std::slice::{Items, MutItems};
use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6, use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6,
@ -12,7 +12,7 @@ use structs::pnt::{Pnt1, Pnt4, Pnt5, Pnt6, Pnt1MulRhs, Pnt4MulRhs, Pnt5MulRhs, P
use structs::dvec::{DVec1, DVec2, DVec3, DVec4, DVec5, DVec6}; use structs::dvec::{DVec1, DVec2, DVec3, DVec4, DVec5, DVec6};
use traits::structure::{Cast, Row, Col, Iterable, IterableMut, Dim, Indexable, use traits::structure::{Cast, Row, Col, Iterable, IterableMut, Dim, Indexable,
Eye, ColSlice, RowSlice, Diag, Shape}; Eye, ColSlice, RowSlice, Diag, Shape, BaseFloat};
use traits::operations::{Absolute, Transpose, Inv, Outer, EigenQR}; use traits::operations::{Absolute, Transpose, Inv, Outer, EigenQR};
use traits::geometry::{ToHomogeneous, FromHomogeneous, Orig}; use traits::geometry::{ToHomogeneous, FromHomogeneous, Orig};
use linalg; use linalg;

View File

@ -125,10 +125,10 @@ macro_rules! mat_sub_scalar_impl(
macro_rules! absolute_impl( macro_rules! absolute_impl(
($t: ident, $comp0: ident $(,$compN: ident)*) => ( ($t: ident, $comp0: ident $(,$compN: ident)*) => (
impl<N: Signed> Absolute<$t<N>> for $t<N> { impl<N: Absolute<N>> Absolute<$t<N>> for $t<N> {
#[inline] #[inline]
fn abs(m: &$t<N>) -> $t<N> { fn abs(m: &$t<N>) -> $t<N> {
$t::new(m.$comp0.abs() $(, m.$compN.abs() )*) $t::new(::abs(&m.$comp0) $(, ::abs(&m.$compN) )*)
} }
} }
) )
@ -642,7 +642,7 @@ macro_rules! outer_impl(
macro_rules! eigen_qr_impl( macro_rules! eigen_qr_impl(
($t: ident, $v: ident) => ( ($t: ident, $v: ident) => (
impl<N> EigenQR<N, $v<N>> for $t<N> impl<N> EigenQR<N, $v<N>> for $t<N>
where N: Float + ApproxEq<N> + Clone { where N: Num + One + Zero + BaseFloat + ApproxEq<N> + Clone {
fn eigen_qr(m: &$t<N>, eps: &N, niter: uint) -> ($t<N>, $v<N>) { fn eigen_qr(m: &$t<N>, eps: &N, niter: uint) -> ($t<N>, $v<N>) {
linalg::eigen_qr(m, eps, niter) linalg::eigen_qr(m, eps, niter)
} }

View File

@ -1,5 +1,6 @@
use std::num::{Zero, One}; use std::num::{Zero, One };
use std::num; use std::num;
use traits::structure::BaseFloat;
use structs::{Pnt3, Vec3, Mat4}; use structs::{Pnt3, Vec3, Mat4};
/// A 3D orthographic projection stored without any matrix. /// A 3D orthographic projection stored without any matrix.
@ -21,7 +22,7 @@ pub struct OrthoMat3<N> {
mat: Mat4<N> mat: Mat4<N>
} }
impl<N: FloatMath> Ortho3<N> { impl<N: BaseFloat> Ortho3<N> {
/// Creates a new 3D orthographic projection. /// Creates a new 3D orthographic projection.
pub fn new(width: N, height: N, znear: N, zfar: N) -> Ortho3<N> { pub fn new(width: N, height: N, znear: N, zfar: N) -> Ortho3<N> {
assert!(!(zfar - znear).is_zero()); assert!(!(zfar - znear).is_zero());
@ -47,7 +48,7 @@ impl<N: FloatMath> Ortho3<N> {
} }
} }
impl<N: FloatMath + Clone> Ortho3<N> { impl<N: BaseFloat + Clone> Ortho3<N> {
/// The width of the view cuboid. /// The width of the view cuboid.
#[inline] #[inline]
pub fn width(&self) -> N { pub fn width(&self) -> N {
@ -111,7 +112,7 @@ impl<N: FloatMath + Clone> Ortho3<N> {
} }
} }
impl<N: FloatMath> OrthoMat3<N> { impl<N: BaseFloat> OrthoMat3<N> {
/// Creates a new orthographic projection matrix from the width, heihgt, znear and zfar planes of the view cuboid. /// Creates a new orthographic projection matrix from the width, heihgt, znear and zfar planes of the view cuboid.
pub fn new(width: N, height: N, znear: N, zfar: N) -> OrthoMat3<N> { pub fn new(width: N, height: N, znear: N, zfar: N) -> OrthoMat3<N> {
assert!(!(zfar - znear).is_zero()); assert!(!(zfar - znear).is_zero());
@ -225,7 +226,7 @@ impl<N: FloatMath> OrthoMat3<N> {
} }
} }
impl<N: FloatMath + Clone> OrthoMat3<N> { impl<N: BaseFloat + Clone> OrthoMat3<N> {
/// Returns the 4D matrix (using homogeneous coordinates) of this projection. /// Returns the 4D matrix (using homogeneous coordinates) of this projection.
#[inline] #[inline]
pub fn to_mat<'a>(&'a self) -> Mat4<N> { pub fn to_mat<'a>(&'a self) -> Mat4<N> {

View File

@ -1,4 +1,5 @@
use std::num::{Zero, One}; use std::num::{Zero, One};
use traits::structure::BaseFloat;
use structs::{Pnt3, Vec3, Mat4}; use structs::{Pnt3, Vec3, Mat4};
/// A 3D perspective projection stored without any matrix. /// A 3D perspective projection stored without any matrix.
@ -20,7 +21,7 @@ pub struct PerspMat3<N> {
mat: Mat4<N> mat: Mat4<N>
} }
impl<N: FloatMath> Persp3<N> { impl<N: BaseFloat> Persp3<N> {
/// Creates a new 3D perspective projection. /// Creates a new 3D perspective projection.
pub fn new(aspect: N, fov: N, znear: N, zfar: N) -> Persp3<N> { pub fn new(aspect: N, fov: N, znear: N, zfar: N) -> Persp3<N> {
assert!(!(zfar - znear).is_zero()); assert!(!(zfar - znear).is_zero());
@ -45,7 +46,7 @@ impl<N: FloatMath> Persp3<N> {
} }
} }
impl<N: FloatMath + Clone> Persp3<N> { impl<N: BaseFloat + Clone> Persp3<N> {
/// Gets the `width / height` aspect ratio. /// Gets the `width / height` aspect ratio.
#[inline] #[inline]
pub fn aspect(&self) -> N { pub fn aspect(&self) -> N {
@ -117,7 +118,7 @@ impl<N: FloatMath + Clone> Persp3<N> {
} }
} }
impl<N: FloatMath> PerspMat3<N> { impl<N: BaseFloat> PerspMat3<N> {
/// Creates a new persepctive matrix from the aspect ratio, field of view, and near/far planes. /// Creates a new persepctive matrix from the aspect ratio, field of view, and near/far planes.
pub fn new(aspect: N, fov: N, znear: N, zfar: N) -> PerspMat3<N> { pub fn new(aspect: N, fov: N, znear: N, zfar: N) -> PerspMat3<N> {
assert!(!(znear - zfar).is_zero()); assert!(!(znear - zfar).is_zero());
@ -256,7 +257,7 @@ impl<N: FloatMath> PerspMat3<N> {
} }
} }
impl<N: FloatMath + Clone> PerspMat3<N> { impl<N: BaseFloat + Clone> PerspMat3<N> {
/// Returns the 4D matrix (using homogeneous coordinates) of this projection. /// Returns the 4D matrix (using homogeneous coordinates) of this projection.
#[inline] #[inline]
pub fn to_mat<'a>(&'a self) -> Mat4<N> { pub fn to_mat<'a>(&'a self) -> Mat4<N> {

View File

@ -3,14 +3,14 @@
#![allow(missing_docs)] // we allow missing to avoid having to document the point components. #![allow(missing_docs)] // we allow missing to avoid having to document the point components.
use std::mem; use std::mem;
use std::num::{Zero, One, Bounded}; use std::num::{Zero, One, Bounded, Num};
use std::slice::{Items, MutItems}; use std::slice::{Items, MutItems};
use std::iter::{Iterator, FromIterator}; use std::iter::{Iterator, FromIterator};
use traits::operations::{ApproxEq, POrd, POrdering, PartialLess, PartialEqual, use traits::operations::{ApproxEq, POrd, POrdering, PartialLess, PartialEqual,
PartialGreater, NotComparable, Axpy, ScalarAdd, ScalarSub, ScalarMul, PartialGreater, NotComparable, Axpy, ScalarAdd, ScalarSub, ScalarMul,
ScalarDiv}; ScalarDiv};
use traits::structure::{Cast, Dim, Indexable, Iterable, IterableMut, PntAsVec, Shape, use traits::structure::{Cast, Dim, Indexable, Iterable, IterableMut, PntAsVec, Shape,
NumPnt, FloatPnt}; NumPnt, FloatPnt, BaseFloat};
use traits::geometry::{Orig, FromHomogeneous, ToHomogeneous}; use traits::geometry::{Orig, FromHomogeneous, ToHomogeneous};
use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6}; use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6};

View File

@ -136,7 +136,7 @@ macro_rules! num_float_pnt_impl(
} }
impl<N> FloatPnt<N, $tv<N>> for $t<N> impl<N> FloatPnt<N, $tv<N>> for $t<N>
where N: ApproxEq<N> + Float $(+ $trhs<N, $t<N>>)* { where N: Num + One + Zero + ApproxEq<N> + BaseFloat $(+ $trhs<N, $t<N>>)* {
} }
) )
) )

View File

@ -3,7 +3,7 @@
#![allow(missing_docs)] // we allow missing to avoid having to document the dispatch trait. #![allow(missing_docs)] // we allow missing to avoid having to document the dispatch trait.
use std::mem; use std::mem;
use std::num::{Zero, One, Bounded}; use std::num::{Zero, One, Bounded, Num};
use std::num; use std::num;
use std::rand::{Rand, Rng}; use std::rand::{Rand, Rng};
use std::slice::{Items, MutItems}; use std::slice::{Items, MutItems};
@ -11,7 +11,7 @@ use structs::{Vec3, Pnt3, Rot3, Mat3, Vec3MulRhs, Pnt3MulRhs};
use traits::operations::{ApproxEq, Inv, POrd, POrdering, NotComparable, PartialLess, use traits::operations::{ApproxEq, Inv, POrd, POrdering, NotComparable, PartialLess,
PartialGreater, PartialEqual, Axpy, ScalarAdd, ScalarSub, ScalarMul, PartialGreater, PartialEqual, Axpy, ScalarAdd, ScalarSub, ScalarMul,
ScalarDiv}; ScalarDiv};
use traits::structure::{Cast, Indexable, Iterable, IterableMut, Dim, Shape}; use traits::structure::{Cast, Indexable, Iterable, IterableMut, Dim, Shape, BaseFloat};
use traits::geometry::{Norm, Cross, Rotation, Rotate, Transform}; use traits::geometry::{Norm, Cross, Rotation, Rotate, Transform};
/// A quaternion. /// A quaternion.
@ -65,7 +65,7 @@ impl<N: Neg<N>> Quat<N> {
} }
} }
impl<N: Float + ApproxEq<N> + Clone> Inv for Quat<N> { impl<N: BaseFloat + ApproxEq<N> + Clone> Inv for Quat<N> {
#[inline] #[inline]
fn inv_cpy(m: &Quat<N>) -> Option<Quat<N>> { fn inv_cpy(m: &Quat<N>) -> Option<Quat<N>> {
let mut res = m.clone(); let mut res = m.clone();
@ -97,7 +97,7 @@ impl<N: Float + ApproxEq<N> + Clone> Inv for Quat<N> {
} }
} }
impl<N: Float> Norm<N> for Quat<N> { impl<N: BaseFloat> Norm<N> for Quat<N> {
#[inline] #[inline]
fn sqnorm(q: &Quat<N>) -> N { fn sqnorm(q: &Quat<N>) -> N {
q.w * q.w + q.i * q.i + q.j * q.j + q.k * q.k q.w * q.w + q.i * q.i + q.j * q.j + q.k * q.k
@ -133,7 +133,7 @@ impl<N: Mul<N, N> + Sub<N, N> + Add<N, N>> QuatMulRhs<N, Quat<N>> for Quat<N> {
} }
} }
impl<N: ApproxEq<N> + Float + Clone> QuatDivRhs<N, Quat<N>> for Quat<N> { impl<N: ApproxEq<N> + BaseFloat + Clone> QuatDivRhs<N, Quat<N>> for Quat<N> {
#[inline] #[inline]
fn binop(left: &Quat<N>, right: &Quat<N>) -> Quat<N> { fn binop(left: &Quat<N>, right: &Quat<N>) -> Quat<N> {
*left * Inv::inv_cpy(right).expect("Unable to invert the denominator.") *left * Inv::inv_cpy(right).expect("Unable to invert the denominator.")
@ -146,7 +146,7 @@ pub struct UnitQuat<N> {
q: Quat<N> q: Quat<N>
} }
impl<N: FloatMath> UnitQuat<N> { impl<N: BaseFloat> UnitQuat<N> {
/// Creates a new unit quaternion from the axis-angle representation of a rotation. /// Creates a new unit quaternion from the axis-angle representation of a rotation.
#[inline] #[inline]
pub fn new(axisangle: Vec3<N>) -> UnitQuat<N> { pub fn new(axisangle: Vec3<N>) -> UnitQuat<N> {
@ -277,7 +277,7 @@ impl<N: Clone + Neg<N>> Inv for UnitQuat<N> {
} }
} }
impl<N: Clone + Rand + FloatMath> Rand for UnitQuat<N> { impl<N: Clone + Rand + BaseFloat> Rand for UnitQuat<N> {
#[inline] #[inline]
fn rand<R: Rng>(rng: &mut R) -> UnitQuat<N> { fn rand<R: Rng>(rng: &mut R) -> UnitQuat<N> {
UnitQuat::new(rng.gen()) UnitQuat::new(rng.gen())
@ -301,7 +301,7 @@ impl<N: ApproxEq<N>> ApproxEq<N> for UnitQuat<N> {
} }
} }
impl<N: Float + ApproxEq<N> + Clone> Div<UnitQuat<N>, UnitQuat<N>> for UnitQuat<N> { impl<N: BaseFloat + ApproxEq<N> + Clone> Div<UnitQuat<N>, UnitQuat<N>> for UnitQuat<N> {
#[inline] #[inline]
fn div(&self, other: &UnitQuat<N>) -> UnitQuat<N> { fn div(&self, other: &UnitQuat<N>) -> UnitQuat<N> {
UnitQuat { q: self.q / other.q } UnitQuat { q: self.q / other.q }
@ -354,7 +354,7 @@ impl<N: Num + Clone> Pnt3MulRhs<N, Pnt3<N>> for UnitQuat<N> {
} }
} }
impl<N: FloatMath + Clone> Rotation<Vec3<N>> for UnitQuat<N> { impl<N: BaseFloat + Clone> Rotation<Vec3<N>> for UnitQuat<N> {
#[inline] #[inline]
fn rotation(&self) -> Vec3<N> { fn rotation(&self) -> Vec3<N> {
let _2 = num::one::<N>() + num::one(); let _2 = num::one::<N>() + num::one();

View File

@ -2,11 +2,11 @@
#![allow(missing_docs)] #![allow(missing_docs)]
use std::num::{Zero, One}; use std::num::{Zero, One, Num};
use std::rand::{Rand, Rng}; use std::rand::{Rand, Rng};
use traits::geometry::{Rotate, Rotation, AbsoluteRotate, RotationMatrix, Transform, ToHomogeneous, use traits::geometry::{Rotate, Rotation, AbsoluteRotate, RotationMatrix, Transform, ToHomogeneous,
Norm, Cross}; Norm, Cross};
use traits::structure::{Cast, Dim, Row, Col}; use traits::structure::{Cast, Dim, Row, Col, BaseFloat};
use traits::operations::{Absolute, Inv, Transpose, ApproxEq}; use traits::operations::{Absolute, Inv, Transpose, ApproxEq};
use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec2MulRhs, Vec3MulRhs, Vec4MulRhs}; use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec2MulRhs, Vec3MulRhs, Vec4MulRhs};
use structs::pnt::{Pnt2, Pnt3, Pnt4, Pnt2MulRhs, Pnt3MulRhs, Pnt4MulRhs}; use structs::pnt::{Pnt2, Pnt3, Pnt4, Pnt2MulRhs, Pnt3MulRhs, Pnt4MulRhs};
@ -19,7 +19,7 @@ pub struct Rot2<N> {
submat: Mat2<N> submat: Mat2<N>
} }
impl<N: Clone + FloatMath + Neg<N>> Rot2<N> { impl<N: Clone + BaseFloat + Neg<N>> Rot2<N> {
/// Builds a 2 dimensional rotation matrix from an angle in radian. /// Builds a 2 dimensional rotation matrix from an angle in radian.
pub fn new(angle: Vec1<N>) -> Rot2<N> { pub fn new(angle: Vec1<N>) -> Rot2<N> {
let (sia, coa) = angle.x.sin_cos(); let (sia, coa) = angle.x.sin_cos();
@ -30,7 +30,7 @@ impl<N: Clone + FloatMath + Neg<N>> Rot2<N> {
} }
} }
impl<N: FloatMath + Clone> Rotation<Vec1<N>> for Rot2<N> { impl<N: BaseFloat + Clone> Rotation<Vec1<N>> for Rot2<N> {
#[inline] #[inline]
fn rotation(&self) -> Vec1<N> { fn rotation(&self) -> Vec1<N> {
Vec1::new((-self.submat.m12).atan2(self.submat.m11.clone())) Vec1::new((-self.submat.m12).atan2(self.submat.m11.clone()))
@ -67,21 +67,21 @@ impl<N: FloatMath + Clone> Rotation<Vec1<N>> for Rot2<N> {
} }
} }
impl<N: Clone + Rand + FloatMath + Neg<N>> Rand for Rot2<N> { impl<N: Clone + Rand + BaseFloat + Neg<N>> Rand for Rot2<N> {
#[inline] #[inline]
fn rand<R: Rng>(rng: &mut R) -> Rot2<N> { fn rand<R: Rng>(rng: &mut R) -> Rot2<N> {
Rot2::new(rng.gen()) Rot2::new(rng.gen())
} }
} }
impl<N: Signed> AbsoluteRotate<Vec2<N>> for Rot2<N> { impl<N: BaseFloat> AbsoluteRotate<Vec2<N>> for Rot2<N> {
#[inline] #[inline]
fn absolute_rotate(&self, v: &Vec2<N>) -> Vec2<N> { fn absolute_rotate(&self, v: &Vec2<N>) -> Vec2<N> {
// the matrix is skew-symetric, so we dont need to compute the absolute value of every // the matrix is skew-symetric, so we dont need to compute the absolute value of every
// component. // component.
let m11 = self.submat.m11.abs(); let m11 = ::abs(&self.submat.m11);
let m12 = self.submat.m12.abs(); let m12 = ::abs(&self.submat.m12);
let m22 = self.submat.m22.abs(); let m22 = ::abs(&self.submat.m22);
Vec2::new(m11 * v.x + m12 * v.y, m12 * v.x + m22 * v.y) Vec2::new(m11 * v.x + m12 * v.y, m12 * v.x + m22 * v.y)
} }
@ -97,7 +97,7 @@ pub struct Rot3<N> {
} }
impl<N: Clone + FloatMath> Rot3<N> { impl<N: Clone + BaseFloat> Rot3<N> {
/// Builds a 3 dimensional rotation matrix from an axis and an angle. /// Builds a 3 dimensional rotation matrix from an axis and an angle.
/// ///
/// # Arguments /// # Arguments
@ -166,7 +166,7 @@ impl<N: Clone + FloatMath> Rot3<N> {
} }
} }
impl<N: Clone + Float> Rot3<N> { impl<N: Clone + BaseFloat> Rot3<N> {
/// Reorient this matrix such that its local `x` axis points to a given point. Note that the /// Reorient this matrix such that its local `x` axis points to a given point. Note that the
/// usually known `look_at` function does the same thing but with the `z` axis. See `look_at_z` /// usually known `look_at` function does the same thing but with the `z` axis. See `look_at_z`
/// for that. /// for that.
@ -205,7 +205,7 @@ impl<N: Clone + Float> Rot3<N> {
} }
} }
impl<N: Clone + FloatMath + Cast<f64>> impl<N: Clone + BaseFloat + Cast<f64>>
Rotation<Vec3<N>> for Rot3<N> { Rotation<Vec3<N>> for Rot3<N> {
#[inline] #[inline]
fn rotation(&self) -> Vec3<N> { fn rotation(&self) -> Vec3<N> {
@ -270,7 +270,7 @@ Rotation<Vec3<N>> for Rot3<N> {
} }
} }
impl<N: Clone + Rand + FloatMath> impl<N: Clone + Rand + BaseFloat>
Rand for Rot3<N> { Rand for Rot3<N> {
#[inline] #[inline]
fn rand<R: Rng>(rng: &mut R) -> Rot3<N> { fn rand<R: Rng>(rng: &mut R) -> Rot3<N> {
@ -278,13 +278,13 @@ Rand for Rot3<N> {
} }
} }
impl<N: Signed> AbsoluteRotate<Vec3<N>> for Rot3<N> { impl<N: BaseFloat> AbsoluteRotate<Vec3<N>> for Rot3<N> {
#[inline] #[inline]
fn absolute_rotate(&self, v: &Vec3<N>) -> Vec3<N> { fn absolute_rotate(&self, v: &Vec3<N>) -> Vec3<N> {
Vec3::new( Vec3::new(
self.submat.m11.abs() * v.x + self.submat.m12.abs() * v.y + self.submat.m13.abs() * v.z, ::abs(&self.submat.m11) * v.x + ::abs(&self.submat.m12) * v.y + ::abs(&self.submat.m13) * v.z,
self.submat.m21.abs() * v.x + self.submat.m22.abs() * v.y + self.submat.m23.abs() * v.z, ::abs(&self.submat.m21) * v.x + ::abs(&self.submat.m22) * v.y + ::abs(&self.submat.m23) * v.z,
self.submat.m31.abs() * v.x + self.submat.m32.abs() * v.y + self.submat.m33.abs() * v.z) ::abs(&self.submat.m31) * v.x + ::abs(&self.submat.m32) * v.y + ::abs(&self.submat.m33) * v.z)
} }
} }
@ -316,25 +316,25 @@ pub struct Rot4<N> {
// } // }
// } // }
impl<N: Signed> AbsoluteRotate<Vec4<N>> for Rot4<N> { impl<N: BaseFloat> AbsoluteRotate<Vec4<N>> for Rot4<N> {
#[inline] #[inline]
fn absolute_rotate(&self, v: &Vec4<N>) -> Vec4<N> { fn absolute_rotate(&self, v: &Vec4<N>) -> Vec4<N> {
Vec4::new( Vec4::new(
self.submat.m11.abs() * v.x + self.submat.m12.abs() * v.y + ::abs(&self.submat.m11) * v.x + ::abs(&self.submat.m12) * v.y +
self.submat.m13.abs() * v.z + self.submat.m14.abs() * v.w, ::abs(&self.submat.m13) * v.z + ::abs(&self.submat.m14) * v.w,
self.submat.m21.abs() * v.x + self.submat.m22.abs() * v.y + ::abs(&self.submat.m21) * v.x + ::abs(&self.submat.m22) * v.y +
self.submat.m23.abs() * v.z + self.submat.m24.abs() * v.w, ::abs(&self.submat.m23) * v.z + ::abs(&self.submat.m24) * v.w,
self.submat.m31.abs() * v.x + self.submat.m32.abs() * v.y + ::abs(&self.submat.m31) * v.x + ::abs(&self.submat.m32) * v.y +
self.submat.m33.abs() * v.z + self.submat.m34.abs() * v.w, ::abs(&self.submat.m33) * v.z + ::abs(&self.submat.m34) * v.w,
self.submat.m41.abs() * v.x + self.submat.m42.abs() * v.y + ::abs(&self.submat.m41) * v.x + ::abs(&self.submat.m42) * v.y +
self.submat.m43.abs() * v.z + self.submat.m44.abs() * v.w) ::abs(&self.submat.m43) * v.z + ::abs(&self.submat.m44) * v.w)
} }
} }
impl<N: Float + Clone> impl<N: BaseFloat + Clone>
Rotation<Vec4<N>> for Rot4<N> { Rotation<Vec4<N>> for Rot4<N> {
#[inline] #[inline]
fn rotation(&self) -> Vec4<N> { fn rotation(&self) -> Vec4<N> {

View File

@ -122,7 +122,7 @@ macro_rules! dim_impl(
macro_rules! rotation_matrix_impl( macro_rules! rotation_matrix_impl(
($t: ident, $tlv: ident, $tav: ident) => ( ($t: ident, $tlv: ident, $tav: ident) => (
impl<N: Cast<f64> + FloatMath> RotationMatrix<N, $tlv<N>, $tav<N>, $t<N>> for $t<N> { impl<N: Zero + Num + Cast<f64> + BaseFloat> RotationMatrix<N, $tlv<N>, $tav<N>, $t<N>> for $t<N> {
#[inline] #[inline]
fn to_rot_mat(&self) -> $t<N> { fn to_rot_mat(&self) -> $t<N> {
self.clone() self.clone()
@ -313,7 +313,7 @@ macro_rules! approx_eq_impl(
macro_rules! absolute_impl( macro_rules! absolute_impl(
($t: ident, $tm: ident) => ( ($t: ident, $tm: ident) => (
impl<N: Signed> Absolute<$tm<N>> for $t<N> { impl<N: Absolute<N>> Absolute<$tm<N>> for $t<N> {
#[inline] #[inline]
fn abs(m: &$t<N>) -> $tm<N> { fn abs(m: &$t<N>) -> $tm<N> {
Absolute::abs(&m.submat) Absolute::abs(&m.submat)

View File

@ -1,9 +1,9 @@
use std::num::{Zero, One}; use std::num::{Zero, One, Num};
use structs::vec::{Vec2, Vec3, Vec2MulRhs, Vec3MulRhs}; use structs::vec::{Vec2, Vec3, Vec2MulRhs, Vec3MulRhs};
use structs::pnt::{Pnt2, Pnt3, Pnt2MulRhs, Pnt3MulRhs}; use structs::pnt::{Pnt2, Pnt3, Pnt2MulRhs, Pnt3MulRhs};
use structs::mat::{Mat1, Mat2, Mat3, Mat3MulRhs, Mat2MulRhs}; use structs::mat::{Mat1, Mat2, Mat3, Mat3MulRhs, Mat2MulRhs};
use traits::operations::{Inv, Det, ApproxEq}; use traits::operations::{Inv, Det, ApproxEq};
use traits::structure::{Row, Col}; use traits::structure::{Row, Col, BaseFloat};
// some specializations: // some specializations:
impl<N: Num + ApproxEq<N> + Clone> Inv for Mat1<N> { impl<N: Num + ApproxEq<N> + Clone> Inv for Mat1<N> {

View File

@ -1,5 +1,5 @@
use std::num::{Zero, One}; use std::num::{Zero, One, Num};
use traits::structure::{Cast, Row, Basis}; use traits::structure::{Cast, Row, Basis, BaseFloat};
use traits::geometry::{Norm, Cross, CrossMatrix, UniformSphereSample}; use traits::geometry::{Norm, Cross, CrossMatrix, UniformSphereSample};
use structs::vec::{Vec1, Vec2, Vec3, Vec4}; use structs::vec::{Vec1, Vec2, Vec3, Vec4};
use structs::mat::Mat3; use structs::mat::Mat3;
@ -114,7 +114,7 @@ impl<N: Clone + One + Zero + Neg<N>> Basis for Vec2<N> {
} }
} }
impl<N: Float> Basis for Vec3<N> { impl<N: BaseFloat> Basis for Vec3<N> {
#[inline(always)] #[inline(always)]
fn canonical_basis(f: |Vec3<N>| -> bool) { fn canonical_basis(f: |Vec3<N>| -> bool) {
if !f(Vec3::new(One::one(), Zero::zero(), Zero::zero())) { return }; if !f(Vec3::new(One::one(), Zero::zero(), Zero::zero())) { return };

View File

@ -1,9 +1,9 @@
use std::mem; use std::mem;
use std::num::{Zero, One, Float, Bounded}; use std::num::{Zero, One, Bounded, Num};
use std::slice::{Items, MutItems}; use std::slice::{Items, MutItems};
use std::iter::{Iterator, FromIterator}; use std::iter::{Iterator, FromIterator};
use traits::operations::ApproxEq; use traits::operations::ApproxEq;
use traits::structure::{Iterable, IterableMut, Indexable, Basis, Dim, Shape}; use traits::structure::{Iterable, IterableMut, Indexable, Basis, Dim, Shape, BaseFloat};
use traits::geometry::{Translation, Dot, Norm}; use traits::geometry::{Translation, Dot, Norm};
use structs::vec; use structs::vec;
@ -164,7 +164,7 @@ impl<N: Clone + Add<N, N> + Neg<N>> Translation<vec::Vec0<N>> for vec::Vec0<N> {
} }
} }
impl<N: Float> Norm<N> for vec::Vec0<N> { impl<N: BaseFloat> Norm<N> for vec::Vec0<N> {
#[inline] #[inline]
fn sqnorm(_: &vec::Vec0<N>) -> N { fn sqnorm(_: &vec::Vec0<N>) -> N {
Zero::zero() Zero::zero()

View File

@ -3,7 +3,7 @@
#![allow(missing_docs)] // we allow missing to avoid having to document the dispatch traits. #![allow(missing_docs)] // we allow missing to avoid having to document the dispatch traits.
use std::mem; use std::mem;
use std::num::{Zero, One, Float, Bounded}; use std::num::{Zero, One, Bounded, Num};
use std::slice::{Items, MutItems}; use std::slice::{Items, MutItems};
use std::iter::{Iterator, FromIterator}; use std::iter::{Iterator, FromIterator};
use traits::operations::{ApproxEq, POrd, POrdering, PartialLess, PartialEqual, use traits::operations::{ApproxEq, POrd, POrdering, PartialLess, PartialEqual,
@ -12,7 +12,7 @@ use traits::operations::{ApproxEq, POrd, POrdering, PartialLess, PartialEqual,
use traits::geometry::{Transform, Rotate, FromHomogeneous, ToHomogeneous, Dot, Norm, use traits::geometry::{Transform, Rotate, FromHomogeneous, ToHomogeneous, Dot, Norm,
Translation, Translate}; Translation, Translate};
use traits::structure::{Basis, Cast, Dim, Indexable, Iterable, IterableMut, VecAsPnt, Shape, use traits::structure::{Basis, Cast, Dim, Indexable, Iterable, IterableMut, VecAsPnt, Shape,
NumVec, FloatVec}; NumVec, FloatVec, BaseFloat};
use structs::pnt::{Pnt1, Pnt2, Pnt3, Pnt4, Pnt5, Pnt6}; use structs::pnt::{Pnt1, Pnt2, Pnt3, Pnt4, Pnt5, Pnt6};

View File

@ -54,11 +54,11 @@ macro_rules! at_fast_impl(
) )
) )
// FIXME: N should be bounded by Ord instead of Float… // FIXME: N should be bounded by Ord instead of BaseFloat…
// However, f32/f64 does not implement Ord… // However, f32/f64 does not implement Ord…
macro_rules! ord_impl( macro_rules! ord_impl(
($t: ident, $comp0: ident $(,$compN: ident)*) => ( ($t: ident, $comp0: ident $(,$compN: ident)*) => (
impl<N: FloatMath + Clone> POrd for $t<N> { impl<N: BaseFloat + Clone> POrd for $t<N> {
#[inline] #[inline]
fn inf(a: &$t<N>, b: &$t<N>) -> $t<N> { fn inf(a: &$t<N>, b: &$t<N>) -> $t<N> {
$t::new(a.$comp0.min(b.$comp0.clone()) $t::new(a.$comp0.min(b.$comp0.clone())
@ -293,7 +293,7 @@ macro_rules! container_impl(
macro_rules! basis_impl( macro_rules! basis_impl(
($t: ident, $trhs: ident, $dim: expr) => ( ($t: ident, $trhs: ident, $dim: expr) => (
impl<N: Clone + Float + ApproxEq<N> + $trhs<N, $t<N>>> Basis for $t<N> { impl<N: Clone + BaseFloat + ApproxEq<N> + $trhs<N, $t<N>>> Basis for $t<N> {
#[inline] #[inline]
fn canonical_basis(f: |$t<N>| -> bool) { fn canonical_basis(f: |$t<N>| -> bool) {
for i in range(0u, $dim) { for i in range(0u, $dim) {
@ -552,7 +552,7 @@ macro_rules! translation_impl(
macro_rules! norm_impl( macro_rules! norm_impl(
($t: ident, $comp0: ident $(,$compN: ident)*) => ( ($t: ident, $comp0: ident $(,$compN: ident)*) => (
impl<N: Clone + Float> Norm<N> for $t<N> { impl<N: Clone + BaseFloat> Norm<N> for $t<N> {
#[inline] #[inline]
fn sqnorm(v: &$t<N>) -> N { fn sqnorm(v: &$t<N>) -> N {
Dot::dot(v, v) Dot::dot(v, v)
@ -769,17 +769,17 @@ macro_rules! num_float_vec_impl(
} }
impl<N> FloatVec<N> for $t<N> impl<N> FloatVec<N> for $t<N>
where N: ApproxEq<N> + Float $(+ $trhs<N, $t<N>>)* { where N: Num + Zero + One + ApproxEq<N> + BaseFloat $(+ $trhs<N, $t<N>>)* {
} }
) )
) )
macro_rules! absolute_vec_impl( macro_rules! absolute_vec_impl(
($t: ident, $comp0: ident $(,$compN: ident)*) => ( ($t: ident, $comp0: ident $(,$compN: ident)*) => (
impl<N: Signed> Absolute<$t<N>> for $t<N> { impl<N: Absolute<N>> Absolute<$t<N>> for $t<N> {
#[inline] #[inline]
fn abs(m: &$t<N>) -> $t<N> { fn abs(m: &$t<N>) -> $t<N> {
$t::new(m.$comp0.abs() $(, m.$compN.abs() )*) $t::new(::abs(&m.$comp0) $(, ::abs(&m.$compN) )*)
} }
} }
) )

View File

@ -1,7 +1,7 @@
//! Traits of operations having a well-known or explicit geometric meaning. //! Traits of operations having a well-known or explicit geometric meaning.
use traits::structure::Mat; use traits::structure::{BaseFloat, Mat};
/// Trait of object which represent a translation, and to wich new translation /// Trait of object which represent a translation, and to wich new translation
/// can be appended. /// can be appended.
@ -205,7 +205,7 @@ pub trait Dot<N> {
} }
/// Traits of objects having an euclidian norm. /// Traits of objects having an euclidian norm.
pub trait Norm<N: Float> { pub trait Norm<N: BaseFloat> {
/// Computes the norm of `self`. /// Computes the norm of `self`.
#[inline] #[inline]
fn norm(v: &Self) -> N { fn norm(v: &Self) -> N {

View File

@ -6,7 +6,7 @@ pub use traits::geometry::{AbsoluteRotate, Cross, CrossMatrix, Dot, FromHomogene
pub use traits::structure::{FloatVec, FloatPnt, Basis, Cast, Col, Dim, Indexable, Iterable, pub use traits::structure::{FloatVec, FloatPnt, Basis, Cast, Col, Dim, Indexable, Iterable,
IterableMut, Mat, SquareMat, Row, NumVec, NumPnt, PntAsVec, VecAsPnt, IterableMut, Mat, SquareMat, Row, NumVec, NumPnt, PntAsVec, VecAsPnt,
ColSlice, RowSlice, Diag, Eye, Shape}; ColSlice, RowSlice, Diag, Eye, Shape, BaseFloat};
pub use traits::operations::{Absolute, ApproxEq, Axpy, Cov, Det, Inv, LMul, Mean, Outer, POrd, pub use traits::operations::{Absolute, ApproxEq, Axpy, Cov, Det, Inv, LMul, Mean, Outer, POrd,
RMul, ScalarAdd, ScalarSub, ScalarMul, ScalarDiv, Transpose, EigenQR}; RMul, ScalarAdd, ScalarSub, ScalarMul, ScalarDiv, Transpose, EigenQR};

View File

@ -1,5 +1,6 @@
//! Low level operations on vectors and matrices. //! Low level operations on vectors and matrices.
use std::num::{Float, SignedInt};
use traits::structure::SquareMat; use traits::structure::SquareMat;
/// Result of a partial ordering. /// Result of a partial ordering.
@ -170,7 +171,7 @@ impl ApproxEq<f32> for f32 {
#[inline] #[inline]
fn approx_eq_eps(a: &f32, b: &f32, epsilon: &f32) -> bool { fn approx_eq_eps(a: &f32, b: &f32, epsilon: &f32) -> bool {
(*a - *b).abs() < *epsilon ::abs(&(*a - *b)) < *epsilon
} }
} }
@ -182,7 +183,7 @@ impl ApproxEq<f64> for f64 {
#[inline] #[inline]
fn approx_eq_eps(a: &f64, b: &f64, approx_epsilon: &f64) -> bool { fn approx_eq_eps(a: &f64, b: &f64, approx_epsilon: &f64) -> bool {
(*a - *b).abs() < *approx_epsilon ::abs(&(*a - *b)) < *approx_epsilon
} }
} }
@ -344,3 +345,40 @@ pub trait Axpy<N> {
/// Adds $$a * x$$ to `self`. /// Adds $$a * x$$ to `self`.
fn axpy(&mut self, a: &N, x: &Self); fn axpy(&mut self, a: &N, x: &Self);
} }
/*
* Some implementation for scalar types.
*/
// FIXME: move this to another module ?
macro_rules! impl_absolute(
($n: ty) => {
impl Absolute<$n> for $n {
#[inline]
fn abs(n: &$n) -> $n {
n.abs()
}
}
}
)
macro_rules! impl_absolute_id(
($n: ty) => {
impl Absolute<$n> for $n {
#[inline]
fn abs(n: &$n) -> $n {
*n
}
}
}
)
impl_absolute!(f32)
impl_absolute!(f64)
impl_absolute!(i16)
impl_absolute!(i32)
impl_absolute!(i64)
impl_absolute!(int)
impl_absolute_id!(u8)
impl_absolute_id!(u16)
impl_absolute_id!(u32)
impl_absolute_id!(u64)
impl_absolute_id!(uint)

View File

@ -1,10 +1,16 @@
//! Traits giving structural informations on linear algebra objects or the space they live in. //! Traits giving structural informations on linear algebra objects or the space they live in.
use std::num::{Zero, One}; use std::num::{Zero, One, FloatMath, Num};
use std::slice::{Items, MutItems}; use std::slice::{Items, MutItems};
use traits::operations::{RMul, LMul, Axpy, Transpose, Inv}; use traits::operations::{RMul, LMul, Axpy, Transpose, Inv, Absolute};
use traits::geometry::{Dot, Norm, Orig}; use traits::geometry::{Dot, Norm, Orig};
pub trait BaseFloat: FloatMath + Zero + One + Num + Absolute<Self> {
}
impl BaseFloat for f32 { }
impl BaseFloat for f64 { }
/// Traits of objects which can be created from an object of type `T`. /// Traits of objects which can be created from an object of type `T`.
pub trait Cast<T> { pub trait Cast<T> {
/// Converts an element of type `T` to an element of type `Self`. /// Converts an element of type `T` to an element of type `Self`.
@ -174,8 +180,8 @@ pub trait NumVec<N>: Dim + Sub<Self, Self> + Add<Self, Self> + Neg<Self> + Zero
Mul<N, Self> + Div<N, Self> + Dot<N> + Axpy<N> + Index<uint, N> { Mul<N, Self> + Div<N, Self> + Dot<N> + Axpy<N> + Index<uint, N> {
} }
/// Trait of vector with components implementing the `Float` trait. /// Trait of vector with components implementing the `BaseFloat` trait.
pub trait FloatVec<N: Float>: NumVec<N> + Norm<N> + Basis { pub trait FloatVec<N: BaseFloat>: NumVec<N> + Norm<N> + Basis {
} }
/* /*
@ -203,8 +209,8 @@ pub trait NumPnt<N, V>:
Div<N, Self> + Add<V, Self> + Axpy<N> + Index<uint, N> { // FIXME: + Sub<V, Self> Div<N, Self> + Add<V, Self> + Axpy<N> + Index<uint, N> { // FIXME: + Sub<V, Self>
} }
/// Trait of points with components implementing the `Float` trait. /// Trait of points with components implementing the `BaseFloat` trait.
pub trait FloatPnt<N: Float, V: Norm<N>>: NumPnt<N, V> { pub trait FloatPnt<N: BaseFloat, V: Norm<N>>: NumPnt<N, V> {
/// Computes the square distance between two points. /// Computes the square distance between two points.
#[inline] #[inline]
fn sqdist(a: &Self, b: &Self) -> N { fn sqdist(a: &Self, b: &Self) -> N {

View File

@ -2,7 +2,7 @@
extern crate "nalgebra" as na; extern crate "nalgebra" as na;
use std::num::{Float, abs}; use std::num::Float;
use std::rand::random; use std::rand::random;
use std::cmp::{min, max}; use std::cmp::{min, max};
use na::{Vec1, Vec3, Mat1, Mat2, Mat3, Mat4, Mat5, Mat6, Rot3, Persp3, PerspMat3, Ortho3, OrthoMat3, use na::{Vec1, Vec3, Mat1, Mat2, Mat3, Mat4, Mat5, Mat6, Rot3, Persp3, PerspMat3, Ortho3, OrthoMat3,
@ -131,7 +131,7 @@ fn test_inv_mat6() {
fn test_rotation2() { fn test_rotation2() {
for _ in range(0u, 10000) { for _ in range(0u, 10000) {
let randmat: na::Rot2<f64> = na::one(); let randmat: na::Rot2<f64> = na::one();
let ang = Vec1::new(abs::<f64>(random()) % Float::pi()); let ang = Vec1::new(na::abs(&random::<f64>()) % Float::pi());
assert!(na::approx_eq(&na::rotation(&na::append_rotation(&randmat, &ang)), &ang)); assert!(na::approx_eq(&na::rotation(&na::append_rotation(&randmat, &ang)), &ang));
} }
@ -149,7 +149,7 @@ fn test_inv_rotation3() {
for _ in range(0u, 10000) { for _ in range(0u, 10000) {
let randmat: Rot3<f64> = na::one(); let randmat: Rot3<f64> = na::one();
let dir: Vec3<f64> = random(); let dir: Vec3<f64> = random();
let ang = na::normalize(&dir) * (abs::<f64>(random()) % Float::pi()); let ang = na::normalize(&dir) * (na::abs(&random::<f64>()) % Float::pi());
let rot = na::append_rotation(&randmat, &ang); let rot = na::append_rotation(&randmat, &ang);
assert!(na::approx_eq(&(na::transpose(&rot) * rot), &na::one())); assert!(na::approx_eq(&(na::transpose(&rot) * rot), &na::one()));