From a77013e4c79abd4fbf866fb823a0dc3a99498196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sat, 25 May 2013 18:30:03 +0000 Subject: [PATCH] Use automatic ToStr deriving for everything. --- src/adaptors/rotmat.rs | 8 +------- src/adaptors/transform.rs | 10 +--------- src/dim1/mat1.rs | 12 +----------- src/dim1/vec1.rs | 8 +------- src/dim2/mat2.rs | 16 +--------------- src/dim2/vec2.rs | 8 +------- src/dim3/mat3.rs | 22 +--------------------- src/dim3/vec3.rs | 14 +------------- src/ndim/nmat.rs | 8 +------- src/ndim/nvec.rs | 8 +------- src/traits/dim.rs | 16 ++++++++-------- 11 files changed, 18 insertions(+), 112 deletions(-) diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index f790b764..d79d634e 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -12,7 +12,7 @@ use dim2::mat2::{Mat2, mat2}; use dim3::mat3::{Mat3, mat3}; use dim3::vec3::{Vec3}; -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct Rotmat { priv submat: M @@ -171,9 +171,3 @@ impl, M: ApproxEq> ApproxEq for Rotmat fn approx_eq_eps(&self, other: &Rotmat, epsilon: &T) -> bool { self.submat.approx_eq_eps(&other.submat, epsilon) } } - -impl ToStr for Rotmat -{ - fn to_str(&self) -> ~str - { ~"Rotmat {" + " submat: " + self.submat.to_str() + " }" } -} diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index 0bb26ea6..cb31216a 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -9,6 +9,7 @@ use traits::transpose::Transpose; use traits::delta_transform::DeltaTransform; use traits::workarounds::rlmul::{RMul, LMul}; +#[deriving(Eq, ToStr)] pub struct Transform { priv submat : M, @@ -146,12 +147,3 @@ impl Rand for Transform fn rand(rng: &mut R) -> Transform { transform(&rng.gen(), &rng.gen()) } } - -impl ToStr for Transform -{ - fn to_str(&self) -> ~str - { - ~"Transform {" + " submat: " + self.submat.to_str() + - " subtrans: " + self.subtrans.to_str() + " }" - } -} diff --git a/src/dim1/mat1.rs b/src/dim1/mat1.rs index 9a2d4c2e..12780120 100644 --- a/src/dim1/mat1.rs +++ b/src/dim1/mat1.rs @@ -7,7 +7,7 @@ use traits::transpose::Transpose; use traits::workarounds::rlmul::{RMul, LMul}; use dim1::vec1::{Vec1, vec1}; -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct Mat1 { m11: T } @@ -102,13 +102,3 @@ impl Rand for Mat1 fn rand(rng: &mut R) -> Mat1 { mat1(rng.gen()) } } - -impl ToStr for Mat1 -{ - fn to_str(&self) -> ~str - { - ~"Mat1 {" - + " m11: " + self.m11.to_str() - + " }" - } -} diff --git a/src/dim1/vec1.rs b/src/dim1/vec1.rs index fbb26af0..3b33d0fc 100644 --- a/src/dim1/vec1.rs +++ b/src/dim1/vec1.rs @@ -9,7 +9,7 @@ use traits::translation::Translation; use traits::sub_dot::SubDot; use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct Vec1 { x : T } @@ -165,9 +165,3 @@ impl Rand for Vec1 fn rand(rng: &mut R) -> Vec1 { vec1(rng.gen()) } } - -impl ToStr for Vec1 -{ - fn to_str(&self) -> ~str - { ~"Vec1 { x : " + self.x.to_str() + " }" } -} diff --git a/src/dim2/mat2.rs b/src/dim2/mat2.rs index 81a41fb4..505700d0 100644 --- a/src/dim2/mat2.rs +++ b/src/dim2/mat2.rs @@ -8,7 +8,7 @@ use traits::transpose::Transpose; use traits::workarounds::rlmul::{RMul, LMul}; use dim2::vec2::{Vec2, vec2}; -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct Mat2 { m11: T, m12: T, @@ -154,17 +154,3 @@ impl Rand for Mat2 fn rand(rng: &mut R) -> Mat2 { mat2(rng.gen(), rng.gen(), rng.gen(), rng.gen()) } } - -impl ToStr for Mat2 -{ - fn to_str(&self) -> ~str - { - ~"Mat2 {" - + " m11: " + self.m11.to_str() - + " m12: " + self.m12.to_str() - - + " m21: " + self.m21.to_str() - + " m22: " + self.m22.to_str() - + " }" - } -} diff --git a/src/dim2/vec2.rs b/src/dim2/vec2.rs index aaf01032..0da1f880 100644 --- a/src/dim2/vec2.rs +++ b/src/dim2/vec2.rs @@ -11,7 +11,7 @@ use traits::norm::Norm; use traits::translation::Translation; use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct Vec2 { x : T, @@ -200,9 +200,3 @@ impl Rand for Vec2 fn rand(rng: &mut R) -> Vec2 { vec2(rng.gen(), rng.gen()) } } - -impl ToStr for Vec2 -{ - fn to_str(&self) -> ~str - { ~"Vec2 { x : " + self.x.to_str() + ", y : " + self.y.to_str() + " }" } -} diff --git a/src/dim3/mat3.rs b/src/dim3/mat3.rs index df495fef..9e8f56bc 100644 --- a/src/dim3/mat3.rs +++ b/src/dim3/mat3.rs @@ -8,7 +8,7 @@ use traits::transpose::Transpose; use traits::workarounds::rlmul::{RMul, LMul}; use dim3::vec3::{Vec3, vec3}; -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct Mat3 { m11: T, m12: T, m13: T, @@ -209,23 +209,3 @@ impl Rand for Mat3 rng.gen(), rng.gen(), rng.gen()) } } - -impl ToStr for Mat3 -{ - fn to_str(&self) -> ~str - { - ~"Mat3 {" - + " m11: " + self.m11.to_str() - + " m12: " + self.m12.to_str() - + " m13: " + self.m13.to_str() - - + " m21: " + self.m21.to_str() - + " m22: " + self.m22.to_str() - + " m23: " + self.m23.to_str() - - + " m31: " + self.m31.to_str() - + " m32: " + self.m32.to_str() - + " m33: " + self.m33.to_str() - + " }" - } -} diff --git a/src/dim3/vec3.rs b/src/dim3/vec3.rs index 96dc17a0..8cf59713 100644 --- a/src/dim3/vec3.rs +++ b/src/dim3/vec3.rs @@ -10,7 +10,7 @@ use traits::norm::Norm; use traits::translation::Translation; use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct Vec3 { x : T, @@ -229,15 +229,3 @@ impl Rand for Vec3 fn rand(rng: &mut R) -> Vec3 { vec3(rng.gen(), rng.gen(), rng.gen()) } } - -impl ToStr for Vec3 -{ - fn to_str(&self) -> ~str - { - ~"Vec3 " - + "{ x : " + self.x.to_str() - + ", y : " + self.y.to_str() - + ", z : " + self.z.to_str() - + " }" - } -} diff --git a/src/ndim/nmat.rs b/src/ndim/nmat.rs index e9c9452b..f83d4a38 100644 --- a/src/ndim/nmat.rs +++ b/src/ndim/nmat.rs @@ -12,7 +12,7 @@ use ndim::nvec::NVec; // 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 and d4 tokens are prefered. -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct NMat { mij: ~[T] @@ -278,9 +278,3 @@ impl Rand for NMat res } } - -impl ToStr for NMat -{ - fn to_str(&self) -> ~str - { ~"Mat" + Dim::dim::().to_str() + " {" + self.mij.to_str() + " }" } -} diff --git a/src/ndim/nvec.rs b/src/ndim/nvec.rs index ae9467ab..cb04ceb1 100644 --- a/src/ndim/nvec.rs +++ b/src/ndim/nvec.rs @@ -18,7 +18,7 @@ use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub} // using d0, d1, d2, d3 and d4 tokens are prefered. // FIXME: it might be possible to implement type-level integers and use them // here? -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct NVec { at: ~[T] @@ -278,9 +278,3 @@ impl Rand for NVec res } } - -impl ToStr for NVec -{ - fn to_str(&self) -> ~str - { ~"Vec" + Dim::dim::().to_str() + self.at.to_str() } -} diff --git a/src/traits/dim.rs b/src/traits/dim.rs index 6cc56c66..489b57d2 100644 --- a/src/traits/dim.rs +++ b/src/traits/dim.rs @@ -11,42 +11,42 @@ pub trait Dim { /// Dimensional token for 0-dimensions. Dimensional tokens are the preferred /// way to specify at the type level the dimension of n-dimensional objects. -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct d0; /// Dimensional token for 1-dimension. Dimensional tokens are the preferred /// way to specify at the type level the dimension of n-dimensional objects. -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct d1; /// Dimensional token for 2-dimensions. Dimensional tokens are the preferred /// way to specify at the type level the dimension of n-dimensional objects. -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct d2; /// Dimensional token for 3-dimensions. Dimensional tokens are the preferred /// way to specify at the type level the dimension of n-dimensional objects. -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct d3; /// Dimensional token for 4-dimensions. Dimensional tokens are the preferred /// way to specify at the type level the dimension of n-dimensional objects. -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct d4; /// Dimensional token for 5-dimensions. Dimensional tokens are the preferred /// way to specify at the type level the dimension of n-dimensional objects. -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct d5; /// Dimensional token for 6-dimensions. Dimensional tokens are the preferred /// way to specify at the type level the dimension of n-dimensional objects. -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct d6; /// Dimensional token for 7-dimensions. Dimensional tokens are the preferred /// way to specify at the type level the dimension of n-dimensional objects. -#[deriving(Eq)] +#[deriving(Eq, ToStr)] pub struct d7; impl Dim for d0