diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index e68bf2d5..31740467 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -1,7 +1,7 @@ use std::num::{One, Zero}; use std::rand::{Rand, Rng, RngUtil}; use std::cmp::ApproxEq; -use traits::workarounds::rlmul::{RMul, LMul}; +use traits::rlmul::{RMul, LMul}; use traits::dim::Dim; use traits::inv::Inv; use traits::transpose::Transpose; diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index d7a3f706..9411c147 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -7,7 +7,7 @@ use traits::rotation::Rotation; use traits::translation::Translation; use traits::transpose::Transpose; use traits::delta_transform::{DeltaTransform, DeltaTransformVector}; -use traits::workarounds::rlmul::{RMul, LMul}; +use traits::rlmul::{RMul, LMul}; #[deriving(Eq, ToStr)] pub struct Transform diff --git a/src/dim1/mat1.rs b/src/dim1/mat1.rs index d2766040..0cb53412 100644 --- a/src/dim1/mat1.rs +++ b/src/dim1/mat1.rs @@ -5,7 +5,7 @@ use traits::dim::Dim; use traits::inv::Inv; use traits::transpose::Transpose; use traits::flatten::Flatten; -use traits::workarounds::rlmul::{RMul, LMul}; +use traits::rlmul::{RMul, LMul}; use dim1::vec1::Vec1; #[deriving(Eq, ToStr)] diff --git a/src/dim1/vec1.rs b/src/dim1/vec1.rs index b9fd8893..e4f8d627 100644 --- a/src/dim1/vec1.rs +++ b/src/dim1/vec1.rs @@ -8,7 +8,7 @@ use traits::norm::Norm; use traits::translation::Translation; use traits::sub_dot::SubDot; use traits::flatten::Flatten; -use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; +use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; #[deriving(Eq, Ord, ToStr)] pub struct Vec1 diff --git a/src/dim2/mat2.rs b/src/dim2/mat2.rs index ccbb36a2..719e4593 100644 --- a/src/dim2/mat2.rs +++ b/src/dim2/mat2.rs @@ -6,7 +6,7 @@ use traits::dim::Dim; use traits::inv::Inv; use traits::transpose::Transpose; use traits::flatten::Flatten; -use traits::workarounds::rlmul::{RMul, LMul}; +use traits::rlmul::{RMul, LMul}; use dim2::vec2::Vec2; #[deriving(Eq, ToStr)] diff --git a/src/dim2/vec2.rs b/src/dim2/vec2.rs index f8d575d7..9265201d 100644 --- a/src/dim2/vec2.rs +++ b/src/dim2/vec2.rs @@ -10,7 +10,7 @@ use traits::sub_dot::SubDot; use traits::norm::Norm; use traits::flatten::Flatten; use traits::translation::Translation; -use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; +use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; #[deriving(Eq, Ord, ToStr)] pub struct Vec2 diff --git a/src/dim3/mat3.rs b/src/dim3/mat3.rs index 82690c71..b65e5a79 100644 --- a/src/dim3/mat3.rs +++ b/src/dim3/mat3.rs @@ -6,7 +6,7 @@ use traits::dim::Dim; use traits::inv::Inv; use traits::transpose::Transpose; use traits::flatten::Flatten; -use traits::workarounds::rlmul::{RMul, LMul}; +use traits::rlmul::{RMul, LMul}; use dim3::vec3::Vec3; #[deriving(Eq, ToStr)] diff --git a/src/dim3/vec3.rs b/src/dim3/vec3.rs index 6d05db27..6ded2d09 100644 --- a/src/dim3/vec3.rs +++ b/src/dim3/vec3.rs @@ -9,7 +9,7 @@ use traits::sub_dot::SubDot; use traits::norm::Norm; use traits::flatten::Flatten; use traits::translation::Translation; -use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; +use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; #[deriving(Eq, Ord, ToStr)] pub struct Vec3 diff --git a/src/nalgebra.rc b/src/nalgebra.rc index d85d9b86..86832a48 100644 --- a/src/nalgebra.rc +++ b/src/nalgebra.rc @@ -70,16 +70,8 @@ pub mod traits pub mod division_ring; pub mod sub_dot; pub mod flatten; - - /// This package contains everything done because the current compiler either - /// crashes or miss features. - /// Therefore, keep in mind anything in there will be inevitably removed some - /// days. So dont rely on them too much. - pub mod workarounds - { - pub mod rlmul; - pub mod scalar_op; - } + pub mod rlmul; + pub mod scalar_op; } #[cfg(test)] diff --git a/src/ndim/dmat.rs b/src/ndim/dmat.rs index 7a17bdc8..9e951b2b 100644 --- a/src/ndim/dmat.rs +++ b/src/ndim/dmat.rs @@ -6,7 +6,7 @@ use std::iterator::IteratorUtil; use traits::inv::Inv; use traits::division_ring::DivisionRing; use traits::transpose::Transpose; -use traits::workarounds::rlmul::{RMul, LMul}; +use traits::rlmul::{RMul, LMul}; use ndim::dvec::{DVec, zero_vec_with_dim}; #[deriving(Eq, ToStr, Clone)] diff --git a/src/ndim/dvec.rs b/src/ndim/dvec.rs index 74b2628f..df439bea 100644 --- a/src/ndim/dvec.rs +++ b/src/ndim/dvec.rs @@ -9,7 +9,7 @@ use traits::dot::Dot; use traits::sub_dot::SubDot; use traits::norm::Norm; use traits::translation::Translation; -use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; +use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; #[deriving(Eq, Ord, ToStr, Clone)] pub struct DVec diff --git a/src/ndim/nmat.rs b/src/ndim/nmat.rs index 9e0c659d..ac13ab80 100644 --- a/src/ndim/nmat.rs +++ b/src/ndim/nmat.rs @@ -7,7 +7,7 @@ use traits::inv::Inv; use traits::division_ring::DivisionRing; use traits::transpose::Transpose; use traits::flatten::Flatten; -use traits::workarounds::rlmul::{RMul, LMul}; +use traits::rlmul::{RMul, LMul}; use ndim::dmat::{DMat, one_mat_with_dim, zero_mat_with_dim, is_zero_mat}; use ndim::nvec::NVec; diff --git a/src/ndim/nvec.rs b/src/ndim/nvec.rs index c9c6216e..6263151d 100644 --- a/src/ndim/nvec.rs +++ b/src/ndim/nvec.rs @@ -13,14 +13,12 @@ use traits::sub_dot::SubDot; use traits::norm::Norm; use traits::translation::Translation; use traits::flatten::Flatten; -use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; +use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; // D is a phantom parameter, used only as a dimensional token. // Its allows use to encode the vector dimension at the type-level. // It can be anything implementing the Dim trait. However, to avoid confusion, // using d0, d1, d2, d3, ..., d7 (or your own dn) are prefered. -// FIXME: it might be possible to implement type-level integers and use them -// here? #[deriving(Eq, Ord, ToStr)] pub struct NVec { at: DVec } diff --git a/src/traits/rlmul.rs b/src/traits/rlmul.rs new file mode 100644 index 00000000..e28c6ac4 --- /dev/null +++ b/src/traits/rlmul.rs @@ -0,0 +1,17 @@ +/** + * Trait of objects having a right multiplication with another element. + */ +pub trait RMul +{ + /// Computes self * v + fn rmul(&self, v : &V) -> V; +} + +/** + * Trait of objects having a left multiplication with another element. + */ +pub trait LMul +{ + /// Computes v * self + fn lmul(&self, &V) -> V; +} diff --git a/src/traits/scalar_op.rs b/src/traits/scalar_op.rs new file mode 100644 index 00000000..bca833fa --- /dev/null +++ b/src/traits/scalar_op.rs @@ -0,0 +1,47 @@ +/** + * Trait of objects having a multiplication with a scalar. + */ +pub trait ScalarMul +{ + /// Gets the result of a multiplication by a scalar. + fn scalar_mul(&self, &N) -> Self; + + /// In-place version of `scalar_mul`. + fn scalar_mul_inplace(&mut self, &N); +} + +/** + * Trait of objects having a division with a scalar. + */ +pub trait ScalarDiv +{ + /// Gets the result of a division by a scalar. + fn scalar_div(&self, &N) -> Self; + + /// In-place version of `scalar_div`. + fn scalar_div_inplace(&mut self, &N); +} + +/** + * Trait of objects having an addition with a scalar. + */ +pub trait ScalarAdd +{ + /// Gets the result of an addition by a scalar. + fn scalar_add(&self, &N) -> Self; + + /// In-place version of `scalar_add`. + fn scalar_add_inplace(&mut self, &N); +} + +/** + * Trait of objects having a subtraction with a scalar. + */ +pub trait ScalarSub +{ + /// Gets the result of a subtraction by a scalar. + fn scalar_sub(&self, &N) -> Self; + + /// In-place version of `scalar_sub`. + fn scalar_sub_inplace(&mut self, &N); +} diff --git a/src/traits/vector_space.rs b/src/traits/vector_space.rs index 7b07d370..0442d12f 100644 --- a/src/traits/vector_space.rs +++ b/src/traits/vector_space.rs @@ -1,6 +1,6 @@ use std::num::Zero; use traits::division_ring::DivisionRing; -use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv}; +use traits::scalar_op::{ScalarMul, ScalarDiv}; /// Trait of elements of a vector space. A vector space is an algebraic /// structure, the elements of which have addition, substraction, negation, diff --git a/src/traits/workarounds/rlmul.rs b/src/traits/workarounds/rlmul.rs deleted file mode 100644 index 4d11c6bf..00000000 --- a/src/traits/workarounds/rlmul.rs +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Trait of objects having a right multiplication with another element. - * This is a workaround of the fact we cannot implement the same trait - * (with different type parameters) twice for the same type. The following - * exemple does not compile (end with an ICE): - * - * ~~~ - * trait Mul for M - * trait Mul for M - * ~~~ - */ -pub trait RMul -{ - /// Computes self * v - fn rmul(&self, v : &V) -> V; -} - -/** - * Trait of objects having a left multiplication with another element. - * This is a workaround of the fact we cannot implement the same trait - * (with different type parameters) twice for the same type. The following - * exemple does not compile (end with an ICE): - * - * ~~~ - * trait Mul for M - * trait Mul for M - * ~~~ - */ -pub trait LMul -{ - /// Computes v * self - fn lmul(&self, &V) -> V; -} diff --git a/src/traits/workarounds/scalar_op.rs b/src/traits/workarounds/scalar_op.rs deleted file mode 100644 index c2556726..00000000 --- a/src/traits/workarounds/scalar_op.rs +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Trait of objects having a multiplication with a scalar. - * This is a workaround of the fact we cannot implement the same trait - * (with different type parameters) twice for the same type. The following - * exemple does not compile (end with an ICE): - * - * ~~~ - * trait Mul for N - * trait Mul for N - * ~~~ - */ -pub trait ScalarMul -{ - /// Gets the result of a multiplication by a scalar. - fn scalar_mul(&self, &N) -> Self; - - /// In-place version of `scalar_mul`. - fn scalar_mul_inplace(&mut self, &N); -} - -/** - * Trait of objects having a division with a scalar. - * This is a workaround of the fact we cannot implement the same trait - * (with different type parameters) twice for the same type. The following - * exemple does not compile (end with an ICE): - * - * ~~~ - * trait Div for N - * trait Div for N - * ~~~ - */ -pub trait ScalarDiv -{ - /// Gets the result of a division by a scalar. - fn scalar_div(&self, &N) -> Self; - - /// In-place version of `scalar_div`. - fn scalar_div_inplace(&mut self, &N); -} - -/** - * Trait of objects having an addition with a scalar. - * This is a workaround of the fact we cannot implement the same trait - * (with different type parameters) twice for the same type. The following - * exemple does not compile (end with an ICE): - * - * ~~~ - * trait Add for N - * trait Add for N - * ~~~ - */ -pub trait ScalarAdd -{ - /// Gets the result of an addition by a scalar. - fn scalar_add(&self, &N) -> Self; - - /// In-place version of `scalar_add`. - fn scalar_add_inplace(&mut self, &N); -} - -/** - * Trait of objects having a subtraction with a scalar. - * This is a workaround of the fact we cannot implement the same trait - * (with different type parameters) twice for the same type. The following - * exemple does not compile (end with an ICE): - * - * ~~~ - * trait Sub for N - * trait Sub for N - * ~~~ - */ -pub trait ScalarSub -{ - /// Gets the result of a subtraction by a scalar. - fn scalar_sub(&self, &N) -> Self; - - /// In-place version of `scalar_sub`. - fn scalar_sub_inplace(&mut self, &N); -}