From 0be1132452c6c630123310455a798cd56b3c199e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Fri, 6 Sep 2013 15:17:53 +0200 Subject: [PATCH] Swap the type parameters of `Transform`. --- src/adaptors/transform.rs | 84 +++++++++++++++++++-------------------- src/types.rs | 48 +++++++++++----------- 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index 39b57968..04e22161 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -22,16 +22,16 @@ use mat::Mat3; /// underlying transform is a rotation (see `Rotmat`): this makes inversion much faster than /// inverting the homogeneous matrix itself. #[deriving(Eq, ToStr, Clone)] -pub struct Transform { +pub struct Transform { priv submat : M, priv subtrans : V } // FIXME: this should be Trasform -impl Transform { +impl Transform { /// Builds a new transform from a matrix and a vector. #[inline] - pub fn new(mat: M, trans: V) -> Transform { + pub fn new(trans: V, mat: M) -> Transform { Transform { submat: mat, subtrans: trans @@ -39,7 +39,7 @@ impl Transform { } } -impl Transform { +impl Transform { /// Gets a copy of the internal matrix. #[inline] pub fn submat(&self) -> M { @@ -53,7 +53,7 @@ impl Transform { } } -impl Transform>, Vec3> { +impl Transform, Rotmat>> { /// 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. @@ -84,25 +84,25 @@ impl Transform>, Vec3> { } } -impl Dim for Transform { +impl Dim for Transform { #[inline] - fn dim(_: Option>) -> uint { + fn dim(_: Option>) -> uint { Dim::dim(None::) } } -impl One for Transform { +impl One for Transform { #[inline] - fn one() -> Transform { + fn one() -> Transform { Transform { submat: One::one(), subtrans: Zero::zero() } } } -impl Zero for Transform { +impl Zero for Transform { #[inline] - fn zero() -> Transform { + fn zero() -> Transform { Transform { submat: Zero::zero(), subtrans: Zero::zero() } @@ -115,9 +115,9 @@ impl Zero for Transform { } impl + Mul, V: Add> -Mul, Transform> for Transform { +Mul, Transform> for Transform { #[inline] - fn mul(&self, other: &Transform) -> Transform { + fn mul(&self, other: &Transform) -> Transform { Transform { submat: self.submat * other.submat, subtrans: self.subtrans + self.submat.rmul(&other.subtrans) @@ -125,21 +125,21 @@ Mul, Transform> for Transform { } } -impl, V: Add> RMul for Transform { +impl, V: Add> RMul for Transform { #[inline] fn rmul(&self, other: &V) -> V { self.submat.rmul(other) + self.subtrans } } -impl, V: Add> LMul for Transform { +impl, V: Add> LMul for Transform { #[inline] fn lmul(&self, other: &V) -> V { self.submat.lmul(other) + self.subtrans } } -impl> Translation for Transform { +impl> Translation for Transform { #[inline] fn translation(&self) -> V { self.subtrans.translation() @@ -156,8 +156,8 @@ impl> Translation for Transform { } #[inline] - fn translated(&self, t: &V) -> Transform { - Transform::new(self.submat.clone(), self.subtrans.translated(t)) + fn translated(&self, t: &V) -> Transform { + Transform::new(self.subtrans.translated(t), self.submat.clone()) } #[inline] @@ -166,7 +166,7 @@ impl> Translation for Transform { } } -impl, V, _0> Translate for Transform { +impl, _0> Translate for Transform<_0, M> { #[inline] fn translate(&self, v: &V) -> V { self.submat.translate(v) @@ -179,7 +179,7 @@ impl, V, _0> Translate for Transform { } impl + RMul + One, V, AV> -Rotation for Transform { +Rotation for Transform { #[inline] fn rotation(&self) -> AV { self.submat.rotation() @@ -201,12 +201,12 @@ Rotation for Transform { } #[inline] - fn rotated(&self, rot: &AV) -> Transform { + fn rotated(&self, rot: &AV) -> Transform { // FIXME: this does not seem opitmal let _1: M = One::one(); let delta = _1.rotated(rot); - Transform::new(self.submat.rotated(rot), delta.rmul(&self.subtrans)) + Transform::new(delta.rmul(&self.subtrans), self.submat.rotated(rot)) } #[inline] @@ -216,7 +216,7 @@ Rotation for Transform { } } -impl, V, _0> Rotate for Transform { +impl, _0> Rotate for Transform<_0, M> { #[inline] fn rotate(&self, v: &V) -> V { self.submat.rotate(v) @@ -229,34 +229,34 @@ impl, V, _0> Rotate for Transform { } impl + Mul + Clone, V: Add + Neg + Clone> -Transformation> for Transform { - fn transformation(&self) -> Transform { +Transformation> for Transform { + fn transformation(&self) -> Transform { self.clone() } - fn inv_transformation(&self) -> Transform { - // FIXME: fail or return a Some> ? + fn inv_transformation(&self) -> Transform { + // FIXME: fail or return a Some> ? match self.inverse() { Some(t) => t, None => fail!("This transformation was not inversible.") } } - fn transform_by(&mut self, other: &Transform) { + fn transform_by(&mut self, other: &Transform) { *self = other * *self } - fn transformed(&self, t: &Transform) -> Transform { + fn transformed(&self, t: &Transform) -> Transform { t * *self } - fn set_transformation(&mut self, t: Transform) { + fn set_transformation(&mut self, t: Transform) { *self = t } } impl, V: Add + Sub> -Ts for Transform { +Ts for Transform { #[inline] fn transform(&self, v: &V) -> V { self.submat.transform(v) + self.subtrans @@ -269,7 +269,7 @@ Ts for Transform { } impl + Clone, V: Neg + Clone> -Inv for Transform { +Inv for Transform { #[inline] fn inplace_inverse(&mut self) -> bool { if !self.submat.inplace_inverse() { @@ -282,7 +282,7 @@ Inv for Transform { } #[inline] - fn inverse(&self) -> Option> { + fn inverse(&self) -> Option> { let mut res = self.clone(); if res.inplace_inverse() { @@ -295,7 +295,7 @@ Inv for Transform { } impl, M2: Dim + Column, V: ToHomogeneous + Clone, V2> -ToHomogeneous for Transform { +ToHomogeneous for Transform { fn to_homogeneous(&self) -> M2 { let mut res = self.submat.to_homogeneous(); @@ -309,14 +309,14 @@ ToHomogeneous for Transform { } impl + Dim, M2: FromHomogeneous, V> -FromHomogeneous for Transform { - fn from(m: &M) -> Transform { - Transform::new(FromHomogeneous::from(m), m.column(Dim::dim(None::) - 1)) +FromHomogeneous for Transform { + fn from(m: &M) -> Transform { + Transform::new(m.column(Dim::dim(None::) - 1), FromHomogeneous::from(m)) } } impl, M:ApproxEq, V:ApproxEq> -ApproxEq for Transform { +ApproxEq for Transform { #[inline] fn approx_epsilon() -> N { fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.") @@ -324,21 +324,21 @@ ApproxEq for Transform { } #[inline] - fn approx_eq(&self, other: &Transform) -> bool { + fn approx_eq(&self, other: &Transform) -> bool { self.submat.approx_eq(&other.submat) && self.subtrans.approx_eq(&other.subtrans) } #[inline] - fn approx_eq_eps(&self, other: &Transform, epsilon: &N) -> bool { + fn approx_eq_eps(&self, other: &Transform, epsilon: &N) -> bool { self.submat.approx_eq_eps(&other.submat, epsilon) && self.subtrans.approx_eq_eps(&other.subtrans, epsilon) } } -impl Rand for Transform { +impl Rand for Transform { #[inline] - fn rand(rng: &mut R) -> Transform { + fn rand(rng: &mut R) -> Transform { Transform::new(rng.gen(), rng.gen()) } } diff --git a/src/types.rs b/src/types.rs index 28a0ac47..a05519d6 100644 --- a/src/types.rs +++ b/src/types.rs @@ -33,11 +33,11 @@ pub type Mat1flt = Mat1; // pub type Iso1flt = Transform; /// 1-dimensional `f64`-valued general transform. -pub type Aff1f64 = Transform; +pub type Aff1f64 = Transform; /// 1-dimensional `f32`-valued general transform. -pub type Aff1f32 = Transform; +pub type Aff1f32 = Transform; /// 1-dimensional `float`-valued general transform. -pub type Aff1flt = Transform; +pub type Aff1flt = Transform; // 2D /// 2-dimensional `f64`-valued vector. @@ -62,18 +62,18 @@ pub type Rot2f32 = Rotmat>; pub type Rot2flt = Rotmat>; /// 2-dimensional `f64`-valued isometric transform. -pub type Iso2f64 = Transform; +pub type Iso2f64 = Transform; /// 2-dimensional `f32`-valued isometric transform. -pub type Iso2f32 = Transform; +pub type Iso2f32 = Transform; /// 2-dimensional `float`-valued isometric transform. -pub type Iso2flt = Transform; +pub type Iso2flt = Transform; /// 2-dimensional `f64`-valued general transform. -pub type Aff2f64 = Transform; +pub type Aff2f64 = Transform; /// 2-dimensional `f32`-valued general transform. -pub type Aff2f32 = Transform; +pub type Aff2f32 = Transform; /// 2-dimensional `float`-valued general transform. -pub type Aff2flt = Transform; +pub type Aff2flt = Transform; // 3D /// 3-dimensional `f64`-valued vector. @@ -98,18 +98,18 @@ pub type Rot3f32 = Rotmat>; pub type Rot3flt = Rotmat>; /// 3-dimensional `f64`-valued isometric transform. -pub type Iso3f64 = Transform; +pub type Iso3f64 = Transform; /// 3-dimensional `f32`-valued isometric transform. -pub type Iso3f32 = Transform; +pub type Iso3f32 = Transform; /// 3-dimensional `float`-valued isometric transform. -pub type Iso3flt = Transform; +pub type Iso3flt = Transform; /// 3-dimensional `f64`-valued general transform. -pub type Aff3f64 = Transform; +pub type Aff3f64 = Transform; /// 3-dimensional `f32`-valued general transform. -pub type Aff3f32 = Transform; +pub type Aff3f32 = Transform; /// 3-dimensional `float`-valued general transform. -pub type Aff3flt = Transform; +pub type Aff3flt = Transform; // 4D /// 4-dimensional `f64`-valued vector. @@ -141,11 +141,11 @@ pub type Mat4flt = Mat4; // pub type Iso4flt = Transform; /// 4-dimensional `f64`-valued general transform. -pub type Aff4f64 = Transform; +pub type Aff4f64 = Transform; /// 4-dimensional `f32`-valued general transform. -pub type Aff4f32 = Transform; +pub type Aff4f32 = Transform; /// 4-dimensional `float`-valued general transform. -pub type Aff4flt = Transform; +pub type Aff4flt = Transform; // 5D /// 5-dimensional `f64`-valued vector. @@ -177,11 +177,11 @@ pub type Mat5flt = Mat5; // pub type Iso5flt = Transform; /// 5-dimensional `f64`-valued general transform. -pub type Aff5f64 = Transform; +pub type Aff5f64 = Transform; /// 5-dimensional `f32`-valued general transform. -pub type Aff5f32 = Transform; +pub type Aff5f32 = Transform; /// 5-dimensional `float`-valued general transform. -pub type Aff5flt = Transform; +pub type Aff5flt = Transform; // 6D /// 6-dimensional `f64`-valued vector. @@ -213,8 +213,8 @@ pub type Mat6flt = Mat6; // pub type Iso6flt = Transform; /// 6-dimensional `f64`-valued general transform. -pub type Aff6f64 = Transform; +pub type Aff6f64 = Transform; /// 6-dimensional `f32`-valued general transform. -pub type Aff6f32 = Transform; +pub type Aff6f32 = Transform; /// 6-dimensional `float`-valued general transform. -pub type Aff6flt = Transform; +pub type Aff6flt = Transform;