forked from M-Labs/nalgebra
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:
parent
15d1fa0b8b
commit
39b9d20717
17
src/lib.rs
17
src/lib.rs
@ -108,7 +108,7 @@ extern crate serialize;
|
||||
#[cfg(test)]
|
||||
extern crate test;
|
||||
|
||||
use std::num::{Zero, One, FloatMath};
|
||||
use std::num::{Zero, One};
|
||||
use std::cmp;
|
||||
pub use traits::{PartialLess, PartialEqual, PartialGreater, NotComparable};
|
||||
pub use traits::{
|
||||
@ -119,6 +119,7 @@ pub use traits::{
|
||||
ApproxEq,
|
||||
Axpy,
|
||||
Basis,
|
||||
BaseFloat,
|
||||
Cast,
|
||||
Col,
|
||||
ColSlice, RowSlice,
|
||||
@ -357,7 +358,7 @@ pub fn orig<P: Orig>() -> P {
|
||||
|
||||
/// Returns the center of two points.
|
||||
#[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();
|
||||
(*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.
|
||||
#[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)
|
||||
}
|
||||
|
||||
/// Returns the squared distance between two points.
|
||||
#[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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
/// view, and the distance to the clipping planes (`znear` and `zfar`).
|
||||
#[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 _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.
|
||||
#[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)
|
||||
}
|
||||
|
||||
/// Computes the squared L2 norm of a vector.
|
||||
#[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)
|
||||
}
|
||||
|
||||
/// Gets the normalized version of a vector.
|
||||
#[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)
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::num::{Zero, Float};
|
||||
use std::num::Zero;
|
||||
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 std::cmp::min;
|
||||
|
||||
@ -12,7 +12,7 @@ use std::cmp::min;
|
||||
/// * `start` - the starting dimension of the subspace of the reflexion
|
||||
/// * `vec` - the vector defining the reflection.
|
||||
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>,
|
||||
V: Indexable<uint, N> {
|
||||
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
|
||||
/// * `m` - matrix to decompose
|
||||
pub fn qr<N, V, M>(m: &M) -> (M, M)
|
||||
where N: Float,
|
||||
where N: BaseFloat,
|
||||
V: Indexable<uint, N> + Norm<N>,
|
||||
M: Clone + Eye + ColSlice<V> + Transpose + Indexable<(uint, uint), N> + Mul<M, M> {
|
||||
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.
|
||||
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>,
|
||||
M: Indexable<(uint, uint), N> + SquareMat<N, V> + Add<M, M> + Sub<M, M> + ColSlice<VS> +
|
||||
ApproxEq<N> + Clone {
|
||||
|
@ -5,7 +5,7 @@
|
||||
use std::cmp;
|
||||
use std::rand::Rand;
|
||||
use std::rand;
|
||||
use std::num::{One, Zero};
|
||||
use std::num::{One, Zero, Num};
|
||||
use traits::operations::ApproxEq;
|
||||
use std::mem;
|
||||
use structs::dvec::{DVec, DVecMulRhs};
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
#![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;
|
||||
use std::slice::{Items, MutItems};
|
||||
use traits::operations::ApproxEq;
|
||||
use std::iter::FromIterator;
|
||||
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.
|
||||
#[deriving(Eq, PartialEq, Show, Clone)]
|
||||
|
@ -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
|
||||
/// vectors, mutually orthogonal, with all its component equal to 0.0 except one which is equal
|
||||
/// 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]
|
||||
fn sqnorm(v: &$dvec<N>) -> N {
|
||||
Dot::dot(v, v)
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use std::num::{Zero, One};
|
||||
use std::num::{Zero, One, Num};
|
||||
use std::rand::{Rand, Rng};
|
||||
use structs::mat::{Mat3, Mat4, Mat5};
|
||||
use traits::structure::{Cast, Dim, Col};
|
||||
use traits::operations::{Inv, ApproxEq};
|
||||
use traits::structure::{Cast, Dim, Col, BaseFloat};
|
||||
use traits::operations::{Inv, ApproxEq, Absolute};
|
||||
use traits::geometry::{RotationMatrix, Rotation, Rotate, AbsoluteRotate, Transform, Transformation,
|
||||
Translate, Translation, ToHomogeneous};
|
||||
|
||||
@ -50,7 +50,7 @@ pub struct Iso4<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
|
||||
/// direction. Note that the usually known `look_at` function does the same thing but with the
|
||||
/// `z` axis. See `look_at_z` for that.
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
macro_rules! iso_impl(
|
||||
($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.
|
||||
#[inline]
|
||||
pub fn new(translation: $subvec<N>, rotation: $subrotvec<N>) -> $t<N> {
|
||||
@ -26,7 +26,7 @@ macro_rules! iso_impl(
|
||||
|
||||
macro_rules! rotation_matrix_impl(
|
||||
($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> {
|
||||
#[inline]
|
||||
fn to_rot_mat(&self) -> $trot<N> {
|
||||
@ -50,7 +50,7 @@ macro_rules! dim_impl(
|
||||
|
||||
macro_rules! one_impl(
|
||||
($t: ident) => (
|
||||
impl<N: FloatMath + Clone> One for $t<N> {
|
||||
impl<N: BaseFloat + Clone> One for $t<N> {
|
||||
#[inline]
|
||||
fn one() -> $t<N> {
|
||||
$t::new_with_rotmat(Zero::zero(), One::one())
|
||||
@ -61,7 +61,7 @@ macro_rules! one_impl(
|
||||
|
||||
macro_rules! iso_mul_iso_impl(
|
||||
($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]
|
||||
fn binop(left: &$t<N>, right: &$t<N>) -> $t<N> {
|
||||
$t::new_with_rotmat(
|
||||
@ -96,7 +96,7 @@ macro_rules! pnt_mul_iso_impl(
|
||||
|
||||
macro_rules! translation_impl(
|
||||
($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]
|
||||
fn translation(&self) -> $tv<N> {
|
||||
self.translation.clone()
|
||||
@ -153,7 +153,7 @@ macro_rules! translate_impl(
|
||||
|
||||
macro_rules! rotation_impl(
|
||||
($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]
|
||||
fn rotation(&self) -> $tav<N> {
|
||||
self.rotation.rotation()
|
||||
@ -220,7 +220,7 @@ macro_rules! rotate_impl(
|
||||
|
||||
macro_rules! transformation_impl(
|
||||
($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> {
|
||||
self.clone()
|
||||
}
|
||||
@ -357,7 +357,7 @@ macro_rules! approx_eq_impl(
|
||||
|
||||
macro_rules! rand_impl(
|
||||
($t: ident) => (
|
||||
impl<N: Rand + Clone + FloatMath> Rand for $t<N> {
|
||||
impl<N: Rand + Clone + BaseFloat> Rand for $t<N> {
|
||||
#[inline]
|
||||
fn rand<R: Rng>(rng: &mut R) -> $t<N> {
|
||||
$t::new(rng.gen(), rng.gen())
|
||||
@ -368,7 +368,7 @@ macro_rules! rand_impl(
|
||||
|
||||
macro_rules! absolute_rotate_impl(
|
||||
($t: ident, $tv: ident) => (
|
||||
impl<N: Signed> AbsoluteRotate<$tv<N>> for $t<N> {
|
||||
impl<N: BaseFloat> AbsoluteRotate<$tv<N>> for $t<N> {
|
||||
#[inline]
|
||||
fn absolute_rotate(&self, v: &$tv<N>) -> $tv<N> {
|
||||
self.rotation.absolute_rotate(v)
|
||||
|
@ -3,7 +3,7 @@
|
||||
#![allow(missing_docs)] // we allow missing to avoid having to document the mij components.
|
||||
|
||||
use std::mem;
|
||||
use std::num::{One, Zero};
|
||||
use std::num::{One, Zero, Num};
|
||||
use traits::operations::ApproxEq;
|
||||
use std::slice::{Items, MutItems};
|
||||
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 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::geometry::{ToHomogeneous, FromHomogeneous, Orig};
|
||||
use linalg;
|
||||
|
@ -125,10 +125,10 @@ macro_rules! mat_sub_scalar_impl(
|
||||
|
||||
macro_rules! absolute_impl(
|
||||
($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]
|
||||
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(
|
||||
($t: ident, $v: ident) => (
|
||||
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>) {
|
||||
linalg::eigen_qr(m, eps, niter)
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::num::{Zero, One};
|
||||
use std::num::{Zero, One };
|
||||
use std::num;
|
||||
use traits::structure::BaseFloat;
|
||||
use structs::{Pnt3, Vec3, Mat4};
|
||||
|
||||
/// A 3D orthographic projection stored without any matrix.
|
||||
@ -21,7 +22,7 @@ pub struct OrthoMat3<N> {
|
||||
mat: Mat4<N>
|
||||
}
|
||||
|
||||
impl<N: FloatMath> Ortho3<N> {
|
||||
impl<N: BaseFloat> Ortho3<N> {
|
||||
/// Creates a new 3D orthographic projection.
|
||||
pub fn new(width: N, height: N, znear: N, zfar: N) -> Ortho3<N> {
|
||||
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.
|
||||
#[inline]
|
||||
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.
|
||||
pub fn new(width: N, height: N, znear: N, zfar: N) -> OrthoMat3<N> {
|
||||
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.
|
||||
#[inline]
|
||||
pub fn to_mat<'a>(&'a self) -> Mat4<N> {
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::num::{Zero, One};
|
||||
use traits::structure::BaseFloat;
|
||||
use structs::{Pnt3, Vec3, Mat4};
|
||||
|
||||
/// A 3D perspective projection stored without any matrix.
|
||||
@ -20,7 +21,7 @@ pub struct PerspMat3<N> {
|
||||
mat: Mat4<N>
|
||||
}
|
||||
|
||||
impl<N: FloatMath> Persp3<N> {
|
||||
impl<N: BaseFloat> Persp3<N> {
|
||||
/// Creates a new 3D perspective projection.
|
||||
pub fn new(aspect: N, fov: N, znear: N, zfar: N) -> Persp3<N> {
|
||||
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.
|
||||
#[inline]
|
||||
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.
|
||||
pub fn new(aspect: N, fov: N, znear: N, zfar: N) -> PerspMat3<N> {
|
||||
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.
|
||||
#[inline]
|
||||
pub fn to_mat<'a>(&'a self) -> Mat4<N> {
|
||||
|
@ -3,14 +3,14 @@
|
||||
#![allow(missing_docs)] // we allow missing to avoid having to document the point components.
|
||||
|
||||
use std::mem;
|
||||
use std::num::{Zero, One, Bounded};
|
||||
use std::num::{Zero, One, Bounded, Num};
|
||||
use std::slice::{Items, MutItems};
|
||||
use std::iter::{Iterator, FromIterator};
|
||||
use traits::operations::{ApproxEq, POrd, POrdering, PartialLess, PartialEqual,
|
||||
PartialGreater, NotComparable, Axpy, ScalarAdd, ScalarSub, ScalarMul,
|
||||
ScalarDiv};
|
||||
use traits::structure::{Cast, Dim, Indexable, Iterable, IterableMut, PntAsVec, Shape,
|
||||
NumPnt, FloatPnt};
|
||||
NumPnt, FloatPnt, BaseFloat};
|
||||
use traits::geometry::{Orig, FromHomogeneous, ToHomogeneous};
|
||||
use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6};
|
||||
|
||||
|
@ -136,7 +136,7 @@ macro_rules! num_float_pnt_impl(
|
||||
}
|
||||
|
||||
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>>)* {
|
||||
}
|
||||
)
|
||||
)
|
||||
|
@ -3,7 +3,7 @@
|
||||
#![allow(missing_docs)] // we allow missing to avoid having to document the dispatch trait.
|
||||
|
||||
use std::mem;
|
||||
use std::num::{Zero, One, Bounded};
|
||||
use std::num::{Zero, One, Bounded, Num};
|
||||
use std::num;
|
||||
use std::rand::{Rand, Rng};
|
||||
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,
|
||||
PartialGreater, PartialEqual, Axpy, ScalarAdd, ScalarSub, ScalarMul,
|
||||
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};
|
||||
|
||||
/// 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]
|
||||
fn inv_cpy(m: &Quat<N>) -> Option<Quat<N>> {
|
||||
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]
|
||||
fn sqnorm(q: &Quat<N>) -> N {
|
||||
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]
|
||||
fn binop(left: &Quat<N>, right: &Quat<N>) -> Quat<N> {
|
||||
*left * Inv::inv_cpy(right).expect("Unable to invert the denominator.")
|
||||
@ -146,7 +146,7 @@ pub struct UnitQuat<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.
|
||||
#[inline]
|
||||
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]
|
||||
fn rand<R: Rng>(rng: &mut R) -> UnitQuat<N> {
|
||||
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]
|
||||
fn div(&self, other: &UnitQuat<N>) -> UnitQuat<N> {
|
||||
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]
|
||||
fn rotation(&self) -> Vec3<N> {
|
||||
let _2 = num::one::<N>() + num::one();
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use std::num::{Zero, One};
|
||||
use std::num::{Zero, One, Num};
|
||||
use std::rand::{Rand, Rng};
|
||||
use traits::geometry::{Rotate, Rotation, AbsoluteRotate, RotationMatrix, Transform, ToHomogeneous,
|
||||
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 structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec2MulRhs, Vec3MulRhs, Vec4MulRhs};
|
||||
use structs::pnt::{Pnt2, Pnt3, Pnt4, Pnt2MulRhs, Pnt3MulRhs, Pnt4MulRhs};
|
||||
@ -19,7 +19,7 @@ pub struct Rot2<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.
|
||||
pub fn new(angle: Vec1<N>) -> Rot2<N> {
|
||||
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]
|
||||
fn rotation(&self) -> Vec1<N> {
|
||||
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]
|
||||
fn rand<R: Rng>(rng: &mut R) -> Rot2<N> {
|
||||
Rot2::new(rng.gen())
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Signed> AbsoluteRotate<Vec2<N>> for Rot2<N> {
|
||||
impl<N: BaseFloat> AbsoluteRotate<Vec2<N>> for Rot2<N> {
|
||||
#[inline]
|
||||
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
|
||||
// component.
|
||||
let m11 = self.submat.m11.abs();
|
||||
let m12 = self.submat.m12.abs();
|
||||
let m22 = self.submat.m22.abs();
|
||||
let m11 = ::abs(&self.submat.m11);
|
||||
let m12 = ::abs(&self.submat.m12);
|
||||
let m22 = ::abs(&self.submat.m22);
|
||||
|
||||
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.
|
||||
///
|
||||
/// # 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
|
||||
/// usually known `look_at` function does the same thing but with the `z` axis. See `look_at_z`
|
||||
/// 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> {
|
||||
#[inline]
|
||||
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> {
|
||||
#[inline]
|
||||
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]
|
||||
fn absolute_rotate(&self, v: &Vec3<N>) -> Vec3<N> {
|
||||
Vec3::new(
|
||||
self.submat.m11.abs() * v.x + self.submat.m12.abs() * v.y + self.submat.m13.abs() * v.z,
|
||||
self.submat.m21.abs() * v.x + self.submat.m22.abs() * v.y + self.submat.m23.abs() * v.z,
|
||||
self.submat.m31.abs() * v.x + self.submat.m32.abs() * v.y + self.submat.m33.abs() * v.z)
|
||||
::abs(&self.submat.m11) * v.x + ::abs(&self.submat.m12) * v.y + ::abs(&self.submat.m13) * v.z,
|
||||
::abs(&self.submat.m21) * v.x + ::abs(&self.submat.m22) * v.y + ::abs(&self.submat.m23) * 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]
|
||||
fn absolute_rotate(&self, v: &Vec4<N>) -> Vec4<N> {
|
||||
Vec4::new(
|
||||
self.submat.m11.abs() * v.x + self.submat.m12.abs() * v.y +
|
||||
self.submat.m13.abs() * v.z + self.submat.m14.abs() * v.w,
|
||||
::abs(&self.submat.m11) * v.x + ::abs(&self.submat.m12) * v.y +
|
||||
::abs(&self.submat.m13) * v.z + ::abs(&self.submat.m14) * v.w,
|
||||
|
||||
self.submat.m21.abs() * v.x + self.submat.m22.abs() * v.y +
|
||||
self.submat.m23.abs() * v.z + self.submat.m24.abs() * v.w,
|
||||
::abs(&self.submat.m21) * v.x + ::abs(&self.submat.m22) * v.y +
|
||||
::abs(&self.submat.m23) * v.z + ::abs(&self.submat.m24) * v.w,
|
||||
|
||||
self.submat.m31.abs() * v.x + self.submat.m32.abs() * v.y +
|
||||
self.submat.m33.abs() * v.z + self.submat.m34.abs() * v.w,
|
||||
::abs(&self.submat.m31) * v.x + ::abs(&self.submat.m32) * v.y +
|
||||
::abs(&self.submat.m33) * v.z + ::abs(&self.submat.m34) * v.w,
|
||||
|
||||
self.submat.m41.abs() * v.x + self.submat.m42.abs() * v.y +
|
||||
self.submat.m43.abs() * v.z + self.submat.m44.abs() * v.w)
|
||||
::abs(&self.submat.m41) * v.x + ::abs(&self.submat.m42) * v.y +
|
||||
::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> {
|
||||
#[inline]
|
||||
fn rotation(&self) -> Vec4<N> {
|
||||
|
@ -122,7 +122,7 @@ macro_rules! dim_impl(
|
||||
|
||||
macro_rules! rotation_matrix_impl(
|
||||
($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]
|
||||
fn to_rot_mat(&self) -> $t<N> {
|
||||
self.clone()
|
||||
@ -313,7 +313,7 @@ macro_rules! approx_eq_impl(
|
||||
|
||||
macro_rules! absolute_impl(
|
||||
($t: ident, $tm: ident) => (
|
||||
impl<N: Signed> Absolute<$tm<N>> for $t<N> {
|
||||
impl<N: Absolute<N>> Absolute<$tm<N>> for $t<N> {
|
||||
#[inline]
|
||||
fn abs(m: &$t<N>) -> $tm<N> {
|
||||
Absolute::abs(&m.submat)
|
||||
|
@ -1,9 +1,9 @@
|
||||
use std::num::{Zero, One};
|
||||
use std::num::{Zero, One, Num};
|
||||
use structs::vec::{Vec2, Vec3, Vec2MulRhs, Vec3MulRhs};
|
||||
use structs::pnt::{Pnt2, Pnt3, Pnt2MulRhs, Pnt3MulRhs};
|
||||
use structs::mat::{Mat1, Mat2, Mat3, Mat3MulRhs, Mat2MulRhs};
|
||||
use traits::operations::{Inv, Det, ApproxEq};
|
||||
use traits::structure::{Row, Col};
|
||||
use traits::structure::{Row, Col, BaseFloat};
|
||||
|
||||
// some specializations:
|
||||
impl<N: Num + ApproxEq<N> + Clone> Inv for Mat1<N> {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::num::{Zero, One};
|
||||
use traits::structure::{Cast, Row, Basis};
|
||||
use std::num::{Zero, One, Num};
|
||||
use traits::structure::{Cast, Row, Basis, BaseFloat};
|
||||
use traits::geometry::{Norm, Cross, CrossMatrix, UniformSphereSample};
|
||||
use structs::vec::{Vec1, Vec2, Vec3, Vec4};
|
||||
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)]
|
||||
fn canonical_basis(f: |Vec3<N>| -> bool) {
|
||||
if !f(Vec3::new(One::one(), Zero::zero(), Zero::zero())) { return };
|
||||
|
@ -1,9 +1,9 @@
|
||||
use std::mem;
|
||||
use std::num::{Zero, One, Float, Bounded};
|
||||
use std::num::{Zero, One, Bounded, Num};
|
||||
use std::slice::{Items, MutItems};
|
||||
use std::iter::{Iterator, FromIterator};
|
||||
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 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]
|
||||
fn sqnorm(_: &vec::Vec0<N>) -> N {
|
||||
Zero::zero()
|
||||
|
@ -3,7 +3,7 @@
|
||||
#![allow(missing_docs)] // we allow missing to avoid having to document the dispatch traits.
|
||||
|
||||
use std::mem;
|
||||
use std::num::{Zero, One, Float, Bounded};
|
||||
use std::num::{Zero, One, Bounded, Num};
|
||||
use std::slice::{Items, MutItems};
|
||||
use std::iter::{Iterator, FromIterator};
|
||||
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,
|
||||
Translation, Translate};
|
||||
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};
|
||||
|
||||
|
||||
|
@ -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…
|
||||
macro_rules! ord_impl(
|
||||
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||
impl<N: FloatMath + Clone> POrd for $t<N> {
|
||||
impl<N: BaseFloat + Clone> POrd for $t<N> {
|
||||
#[inline]
|
||||
fn inf(a: &$t<N>, b: &$t<N>) -> $t<N> {
|
||||
$t::new(a.$comp0.min(b.$comp0.clone())
|
||||
@ -293,7 +293,7 @@ macro_rules! container_impl(
|
||||
|
||||
macro_rules! basis_impl(
|
||||
($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]
|
||||
fn canonical_basis(f: |$t<N>| -> bool) {
|
||||
for i in range(0u, $dim) {
|
||||
@ -552,7 +552,7 @@ macro_rules! translation_impl(
|
||||
|
||||
macro_rules! norm_impl(
|
||||
($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]
|
||||
fn sqnorm(v: &$t<N>) -> N {
|
||||
Dot::dot(v, v)
|
||||
@ -769,17 +769,17 @@ macro_rules! num_float_vec_impl(
|
||||
}
|
||||
|
||||
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(
|
||||
($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]
|
||||
fn abs(m: &$t<N>) -> $t<N> {
|
||||
$t::new(m.$comp0.abs() $(, m.$compN.abs() )*)
|
||||
$t::new(::abs(&m.$comp0) $(, ::abs(&m.$compN) )*)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! 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
|
||||
/// can be appended.
|
||||
@ -205,7 +205,7 @@ pub trait Dot<N> {
|
||||
}
|
||||
|
||||
/// Traits of objects having an euclidian norm.
|
||||
pub trait Norm<N: Float> {
|
||||
pub trait Norm<N: BaseFloat> {
|
||||
/// Computes the norm of `self`.
|
||||
#[inline]
|
||||
fn norm(v: &Self) -> N {
|
||||
|
@ -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,
|
||||
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,
|
||||
RMul, ScalarAdd, ScalarSub, ScalarMul, ScalarDiv, Transpose, EigenQR};
|
||||
|
@ -1,5 +1,6 @@
|
||||
//! Low level operations on vectors and matrices.
|
||||
|
||||
use std::num::{Float, SignedInt};
|
||||
use traits::structure::SquareMat;
|
||||
|
||||
/// Result of a partial ordering.
|
||||
@ -170,7 +171,7 @@ impl ApproxEq<f32> for f32 {
|
||||
|
||||
#[inline]
|
||||
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]
|
||||
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`.
|
||||
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)
|
||||
|
@ -1,10 +1,16 @@
|
||||
//! 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 traits::operations::{RMul, LMul, Axpy, Transpose, Inv};
|
||||
use traits::operations::{RMul, LMul, Axpy, Transpose, Inv, Absolute};
|
||||
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`.
|
||||
pub trait Cast<T> {
|
||||
/// 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> {
|
||||
}
|
||||
|
||||
/// Trait of vector with components implementing the `Float` trait.
|
||||
pub trait FloatVec<N: Float>: NumVec<N> + Norm<N> + Basis {
|
||||
/// Trait of vector with components implementing the `BaseFloat` trait.
|
||||
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>
|
||||
}
|
||||
|
||||
/// Trait of points with components implementing the `Float` trait.
|
||||
pub trait FloatPnt<N: Float, V: Norm<N>>: NumPnt<N, V> {
|
||||
/// Trait of points with components implementing the `BaseFloat` trait.
|
||||
pub trait FloatPnt<N: BaseFloat, V: Norm<N>>: NumPnt<N, V> {
|
||||
/// Computes the square distance between two points.
|
||||
#[inline]
|
||||
fn sqdist(a: &Self, b: &Self) -> N {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
extern crate "nalgebra" as na;
|
||||
|
||||
use std::num::{Float, abs};
|
||||
use std::num::Float;
|
||||
use std::rand::random;
|
||||
use std::cmp::{min, max};
|
||||
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() {
|
||||
for _ in range(0u, 10000) {
|
||||
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));
|
||||
}
|
||||
@ -149,7 +149,7 @@ fn test_inv_rotation3() {
|
||||
for _ in range(0u, 10000) {
|
||||
let randmat: Rot3<f64> = na::one();
|
||||
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);
|
||||
|
||||
assert!(na::approx_eq(&(na::transpose(&rot) * rot), &na::one()));
|
||||
|
Loading…
Reference in New Issue
Block a user