diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index 5a5c242b..1819d404 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -6,7 +6,7 @@ use traits::cross::Cross; use traits::dim::Dim; use traits::inv::Inv; use traits::transpose::Transpose; -use traits::rotation::{Rotation, Rotate, Rotatable}; +use traits::rotation::{Rotation, Rotate}; use traits::transformation::{Transform}; // FIXME: implement Transformation and Transformable use traits::homogeneous::ToHomogeneous; use traits::indexable::Indexable; @@ -136,10 +136,7 @@ Rotation> for Rotmat> { fn rotate_by(&mut self, rot: &Vec1) { *self = self.rotated(rot) } -} -impl -Rotatable, Rotmat>> for Rotmat> { #[inline] fn rotated(&self, rot: &Vec1) -> Rotmat> { Rotmat::from_angle(rot.x.clone()) * *self @@ -163,10 +160,7 @@ Rotation> for Rotmat> { fn rotate_by(&mut self, rot: &Vec3) { *self = self.rotated(rot) } -} -impl -Rotatable, Rotmat>> for Rotmat> { #[inline] fn rotated(&self, axisangle: &Vec3) -> Rotmat> { Rotmat::from_axis_angle(axisangle.clone()) * *self diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index afa13ff5..91aa6cc7 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -3,10 +3,10 @@ use std::rand::{Rand, Rng, RngUtil}; use std::cmp::ApproxEq; use traits::dim::Dim; use traits::inv::Inv; -use traits::rotation::{Rotation, Rotate, Rotatable}; -use traits::translation::{Translation, Translate, Translatable}; +use traits::rotation::{Rotation, Rotate}; +use traits::translation::{Translation, Translate}; use Ts = traits::transformation::Transform; -use traits::transformation::{Transformation, Transformable}; +use traits::transformation::{Transformation}; use traits::rlmul::{RMul, LMul}; use traits::homogeneous::{ToHomogeneous, FromHomogeneous}; use traits::column::Column; @@ -138,7 +138,7 @@ impl, V: Add> LMul for Transform { } } -impl> Translation for Transform { +impl> Translation for Transform { #[inline] fn translation(&self) -> V { self.subtrans.translation() @@ -153,6 +153,11 @@ impl> Translation for Transform { fn translate_by(&mut self, t: &V) { self.subtrans.translate_by(t) } + + #[inline] + fn translated(&self, t: &V) -> Transform { + Transform::new(self.submat.clone(), self.subtrans.translated(t)) + } } impl, V, _0> Translate for Transform { @@ -167,14 +172,6 @@ impl, V, _0> Translate for Transform { } } -impl + Translation> -Translatable> for Transform { - #[inline] - fn translated(&self, t: &V) -> Transform { - Transform::new(self.submat.clone(), self.subtrans.translated(t)) - } -} - impl + RMul + One, V, AV> Rotation for Transform { #[inline] @@ -196,6 +193,14 @@ Rotation for Transform { self.submat.rotate_by(rot); self.subtrans = delta.rmul(&self.subtrans); } + + #[inline] + fn rotated(&self, rot: &AV) -> Transform { + // FIXME: this does not seem opitmal + let delta = One::one::().rotated(rot); + + Transform::new(self.submat.rotated(rot), delta.rmul(&self.subtrans)) + } } impl, V, _0> Rotate for Transform { @@ -210,17 +215,6 @@ impl, V, _0> Rotate for Transform { } } -impl + One, Res: Rotation + RMul + One, V, AV> -Rotatable> for Transform { - #[inline] - fn rotated(&self, rot: &AV) -> Transform { - // FIXME: this does not seem opitmal - let delta = One::one::().rotated(rot); - - Transform::new(self.submat.rotated(rot), delta.rmul(&self.subtrans)) - } -} - impl + Mul + Clone, V: Add + Neg + Clone> Transformation> for Transform { fn transformation(&self) -> Transform { @@ -238,6 +232,10 @@ Transformation> for Transform { fn transform_by(&mut self, other: &Transform) { *self = other * *self } + + fn transformed(&self, t: &Transform) -> Transform { + t * *self + } } impl, V: Add + Sub> @@ -253,16 +251,6 @@ Ts for Transform { } } - -// FIXME: constraints are too restrictive. -// Should be: Transformable ... -impl + Mul + Inv + Clone, V: Add + Neg + Clone> -Transformable, Transform> for Transform { - fn transformed(&self, t: &Transform) -> Transform { - t * *self - } -} - impl + Clone, V: Neg + Clone> Inv for Transform { #[inline] diff --git a/src/dvec.rs b/src/dvec.rs index 1b6c49ff..a7a9395e 100644 --- a/src/dvec.rs +++ b/src/dvec.rs @@ -5,7 +5,7 @@ use std::cmp::ApproxEq; use std::iterator::FromIterator; use traits::vector::{Vec, AlgebraicVec}; use traits::iterable::{Iterable, IterableMut}; -use traits::translation::{Translation, Translatable}; +use traits::translation::Translation; use traits::scalar_op::{ScalarAdd, ScalarSub}; /// Vector with a dimension unknown at compile-time. @@ -219,9 +219,7 @@ impl + Neg + Clone> Translation> for DVec { fn translate_by(&mut self, t: &DVec) { *self = *self + *t; } -} -impl + Neg + Clone> Translatable, DVec> for DVec { #[inline] fn translated(&self, t: &DVec) -> DVec { self + *t diff --git a/src/tests/mat.rs b/src/tests/mat.rs index 97317abc..eab83bb2 100644 --- a/src/tests/mat.rs +++ b/src/tests/mat.rs @@ -7,7 +7,7 @@ use std::cmp::ApproxEq; #[test] use traits::inv::Inv; #[test] -use traits::rotation::{Rotation, Rotatable}; +use traits::rotation::Rotation; #[test] use traits::indexable::Indexable; #[test] diff --git a/src/traits/rotation.rs b/src/traits/rotation.rs index a3e8d79c..46822520 100644 --- a/src/traits/rotation.rs +++ b/src/traits/rotation.rs @@ -1,4 +1,4 @@ -use traits::translation::{Translation, Translatable}; +use traits::translation::Translation; /// Trait of object which represent a rotation, and to wich new rotations can /// be appended. A rotation is assumed to be an isomitry without translation @@ -10,17 +10,11 @@ pub trait Rotation { /// Gets the inverse rotation associated with this object. fn inv_rotation(&self) -> V; - /// In-place version of `rotated` (see the `Rotatable` trait). + /// In-place version of `rotated`. fn rotate_by(&mut self, &V); -} -/// Trait of objects which can be put on an alternate form which represent a rotation. This is -/// typically implemented by structures requiring an internal restructuration to be able to -/// represent a rotation. -pub trait Rotatable> { - /// Appends a rotation from an alternative representation. Such - /// representation has the same format as the one returned by `rotation`. - fn rotated(&self, &V) -> Res; + /// Appends a rotation. + fn rotated(&self, &V) -> Self; } /// Trait of objects able to rotate other objects. This is typically implemented by matrices which @@ -40,14 +34,13 @@ pub trait Rotate { * - `point`: the center of rotation. */ #[inline] -pub fn rotated_wrt_point, - M2: Rotation + Translation, +pub fn rotated_wrt_point + Rotation, LV: Neg, AV>( m: &M, ammount: &AV, center: &LV) - -> M2 { + -> M { let mut res = m.translated(&-center); res.rotate_by(ammount); @@ -82,13 +75,12 @@ pub fn rotate_wrt_point + Translation, * * `ammount` - the rotation to apply. */ #[inline] -pub fn rotated_wrt_center + Translation, - M2: Rotation + Translation, +pub fn rotated_wrt_center + Translation, LV: Neg, AV>( m: &M, ammount: &AV) - -> M2 { + -> M { rotated_wrt_point(m, ammount, &m.translation()) } @@ -100,7 +92,7 @@ pub fn rotated_wrt_center + Translation, * * `ammount` - the rotation to apply. */ #[inline] -pub fn rotate_wrt_center + Translation + Rotation, +pub fn rotate_wrt_center + Rotation, LV: Neg, AV>( m: &mut M, diff --git a/src/traits/transformation.rs b/src/traits/transformation.rs index d1de2276..05cea382 100644 --- a/src/traits/transformation.rs +++ b/src/traits/transformation.rs @@ -8,8 +8,11 @@ pub trait Transformation { /// Gets the inverse transformation associated with this object. fn inv_transformation(&self) -> M; - /// In-place version of `transformed` (see the `Transformable` trait). + /// In-place version of `transformed`. fn transform_by(&mut self, &M); + + /// Appends a transformation. + fn transformed(&self, &M) -> Self; } /// Trait of objects able to transform other objects. This is typically implemented by matrices which @@ -20,12 +23,3 @@ pub trait Transform { /// Apply an inverse transformation to an object. fn inv_transform(&self, &V) -> V; } - -/// Trait of objects which can be put on an alternate form which represent a transformation. This is -/// typically implemented by structures requiring an internal restructuration to be able to -/// represent a transformation. -pub trait Transformable> { - /// Appends a transformation from an alternative representation. Such - /// representation has the same format as the one returned by `transformation`. - fn transformed(&self, &M) -> Res; -} diff --git a/src/traits/translation.rs b/src/traits/translation.rs index 450daa2b..88c13513 100644 --- a/src/traits/translation.rs +++ b/src/traits/translation.rs @@ -8,8 +8,11 @@ pub trait Translation { /// Gets the inverse translation associated with this object. fn inv_translation(&self) -> V; - /// In-place version of `translated` (see the `Translatable` trait). + /// In-place version of `translated`. fn translate_by(&mut self, &V); + + /// Appends a translation. + fn translated(&self, &V) -> Self; } /// Trait of objects able to rotate other objects. This is typically implemented by matrices which @@ -20,12 +23,3 @@ pub trait Translate { /// Apply an inverse translation to an object. fn inv_translate(&self, &V) -> V; } - -/// Trait of objects which can be put on an alternate form which represent a translation. This is -/// typically implemented by structures requiring an internal restructuration to be able to -/// represent a translation. -pub trait Translatable> { - /// Appends a translation from an alternative representation. Such - /// representation has the same format as the one returned by `translation`. - fn translated(&self, &V) -> Res; -} diff --git a/src/vec.rs b/src/vec.rs index c6e556fe..ce9e8102 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -6,7 +6,7 @@ use std::iterator::{Iterator, FromIterator}; use std::cmp::ApproxEq; use traits::basis::Basis; use traits::dim::Dim; -use traits::translation::{Translation, Translatable}; +use traits::translation::Translation; use traits::homogeneous::{FromHomogeneous, ToHomogeneous}; use traits::indexable::Indexable; use traits::scalar_op::{ScalarAdd, ScalarSub}; @@ -45,7 +45,6 @@ scalar_div_impl!(Vec1, x) scalar_add_impl!(Vec1, x) scalar_sub_impl!(Vec1, x) translation_impl!(Vec1) -translatable_impl!(Vec1) norm_impl!(Vec1) approx_eq_impl!(Vec1, x) round_impl!(Vec1, x) @@ -84,7 +83,6 @@ scalar_div_impl!(Vec2, x, y) scalar_add_impl!(Vec2, x, y) scalar_sub_impl!(Vec2, x, y) translation_impl!(Vec2) -translatable_impl!(Vec2) norm_impl!(Vec2) approx_eq_impl!(Vec2, x, y) round_impl!(Vec2, x, y) @@ -125,7 +123,6 @@ scalar_div_impl!(Vec3, x, y, z) scalar_add_impl!(Vec3, x, y, z) scalar_sub_impl!(Vec3, x, y, z) translation_impl!(Vec3) -translatable_impl!(Vec3) norm_impl!(Vec3) approx_eq_impl!(Vec3, x, y, z) round_impl!(Vec3, x, y, z) @@ -168,7 +165,6 @@ scalar_div_impl!(Vec4, x, y, z, w) scalar_add_impl!(Vec4, x, y, z, w) scalar_sub_impl!(Vec4, x, y, z, w) translation_impl!(Vec4) -translatable_impl!(Vec4) norm_impl!(Vec4) approx_eq_impl!(Vec4, x, y, z, w) round_impl!(Vec4, x, y, z, w) @@ -213,7 +209,6 @@ scalar_div_impl!(Vec5, x, y, z, w, a) scalar_add_impl!(Vec5, x, y, z, w, a) scalar_sub_impl!(Vec5, x, y, z, w, a) translation_impl!(Vec5) -translatable_impl!(Vec5) norm_impl!(Vec5) approx_eq_impl!(Vec5, x, y, z, w, a) round_impl!(Vec5, x, y, z, w, a) @@ -260,7 +255,6 @@ scalar_div_impl!(Vec6, x, y, z, w, a, b) scalar_add_impl!(Vec6, x, y, z, w, a, b) scalar_sub_impl!(Vec6, x, y, z, w, a, b) translation_impl!(Vec6) -translatable_impl!(Vec6) norm_impl!(Vec6) approx_eq_impl!(Vec6, x, y, z, w, a, b) round_impl!(Vec6, x, y, z, w, a, b) diff --git a/src/vec0_spec.rs b/src/vec0_spec.rs index 72c564a3..83aedb57 100644 --- a/src/vec0_spec.rs +++ b/src/vec0_spec.rs @@ -6,7 +6,7 @@ use std::cmp::ApproxEq; use traits::iterable::{Iterable, IterableMut}; use traits::basis::Basis; use traits::dim::Dim; -use traits::translation::{Translation, Translatable}; +use traits::translation::Translation; use traits::scalar_op::{ScalarAdd, ScalarSub}; use traits::indexable::Indexable; use traits::vector::{Vec, AlgebraicVec}; @@ -156,9 +156,7 @@ impl + Neg> Translation> for vec::Vec0 { fn translate_by(&mut self, t: &vec::Vec0) { *self = *self + *t; } -} -impl + Neg + Clone> Translatable, vec::Vec0> for vec::Vec0 { #[inline] fn translated(&self, t: &vec::Vec0) -> vec::Vec0 { self + *t diff --git a/src/vec_macros.rs b/src/vec_macros.rs index 668d8b47..51e7c2b5 100644 --- a/src/vec_macros.rs +++ b/src/vec_macros.rs @@ -353,13 +353,7 @@ macro_rules! translation_impl( fn translate_by(&mut self, t: &$t) { *self = *self + *t; } - } - ) -) -macro_rules! translatable_impl( - ($t: ident) => ( - impl + Neg + Clone> Translatable<$t, $t> for $t { #[inline] fn translated(&self, t: &$t) -> $t { self + *t