Use automatic ToStr deriving for everything.

This commit is contained in:
Sébastien Crozet 2013-05-25 18:30:03 +00:00
parent 898a87b46c
commit a77013e4c7
11 changed files with 18 additions and 112 deletions

View File

@ -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<M>
{
priv submat: M
@ -171,9 +171,3 @@ impl<T: ApproxEq<T>, M: ApproxEq<T>> ApproxEq<T> for Rotmat<M>
fn approx_eq_eps(&self, other: &Rotmat<M>, epsilon: &T) -> bool
{ self.submat.approx_eq_eps(&other.submat, epsilon) }
}
impl<M: ToStr> ToStr for Rotmat<M>
{
fn to_str(&self) -> ~str
{ ~"Rotmat {" + " submat: " + self.submat.to_str() + " }" }
}

View File

@ -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<M, V>
{
priv submat : M,
@ -146,12 +147,3 @@ impl<M: Rand + Copy, V: Rand + Copy> Rand for Transform<M, V>
fn rand<R: Rng>(rng: &mut R) -> Transform<M, V>
{ transform(&rng.gen(), &rng.gen()) }
}
impl<M:ToStr, V:ToStr> ToStr for Transform<M, V>
{
fn to_str(&self) -> ~str
{
~"Transform {" + " submat: " + self.submat.to_str() +
" subtrans: " + self.subtrans.to_str() + " }"
}
}

View File

@ -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<T>
{ m11: T }
@ -102,13 +102,3 @@ impl<T:Rand + Copy> Rand for Mat1<T>
fn rand<R: Rng>(rng: &mut R) -> Mat1<T>
{ mat1(rng.gen()) }
}
impl<T:ToStr> ToStr for Mat1<T>
{
fn to_str(&self) -> ~str
{
~"Mat1 {"
+ " m11: " + self.m11.to_str()
+ " }"
}
}

View File

@ -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<T>
{ x : T }
@ -165,9 +165,3 @@ impl<T:Rand + Copy> Rand for Vec1<T>
fn rand<R: Rng>(rng: &mut R) -> Vec1<T>
{ vec1(rng.gen()) }
}
impl<T:ToStr> ToStr for Vec1<T>
{
fn to_str(&self) -> ~str
{ ~"Vec1 { x : " + self.x.to_str() + " }" }
}

View File

@ -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<T>
{
m11: T, m12: T,
@ -154,17 +154,3 @@ impl<T:Rand + Copy> Rand for Mat2<T>
fn rand<R: Rng>(rng: &mut R) -> Mat2<T>
{ mat2(rng.gen(), rng.gen(), rng.gen(), rng.gen()) }
}
impl<T:ToStr> ToStr for Mat2<T>
{
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()
+ " }"
}
}

View File

@ -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<T>
{
x : T,
@ -200,9 +200,3 @@ impl<T:Rand + Copy> Rand for Vec2<T>
fn rand<R: Rng>(rng: &mut R) -> Vec2<T>
{ vec2(rng.gen(), rng.gen()) }
}
impl<T:ToStr> ToStr for Vec2<T>
{
fn to_str(&self) -> ~str
{ ~"Vec2 { x : " + self.x.to_str() + ", y : " + self.y.to_str() + " }" }
}

View File

@ -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<T>
{
m11: T, m12: T, m13: T,
@ -209,23 +209,3 @@ impl<T:Rand + Copy> Rand for Mat3<T>
rng.gen(), rng.gen(), rng.gen())
}
}
impl<T:ToStr> ToStr for Mat3<T>
{
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()
+ " }"
}
}

View File

@ -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<T>
{
x : T,
@ -229,15 +229,3 @@ impl<T:Copy + Rand> Rand for Vec3<T>
fn rand<R: Rng>(rng: &mut R) -> Vec3<T>
{ vec3(rng.gen(), rng.gen(), rng.gen()) }
}
impl<T:ToStr> ToStr for Vec3<T>
{
fn to_str(&self) -> ~str
{
~"Vec3 "
+ "{ x : " + self.x.to_str()
+ ", y : " + self.y.to_str()
+ ", z : " + self.z.to_str()
+ " }"
}
}

View File

@ -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<D, T>
{
mij: ~[T]
@ -278,9 +278,3 @@ impl<D: Dim, T: Rand + Zero + Copy> Rand for NMat<D, T>
res
}
}
impl<D: Dim, T: ToStr> ToStr for NMat<D, T>
{
fn to_str(&self) -> ~str
{ ~"Mat" + Dim::dim::<D>().to_str() + " {" + self.mij.to_str() + " }" }
}

View File

@ -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<D, T>
{
at: ~[T]
@ -278,9 +278,3 @@ impl<D: Dim, T: Rand + Zero + Copy> Rand for NVec<D, T>
res
}
}
impl<D: Dim, T: ToStr> ToStr for NVec<D, T>
{
fn to_str(&self) -> ~str
{ ~"Vec" + Dim::dim::<D>().to_str() + self.at.to_str() }
}

View File

@ -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