Move all the rotation-related free functions to a `RotationWithTranslation` trait.

This is not a very good name though.
This commit is contained in:
Sébastien Crozet 2013-09-04 17:00:56 +02:00
parent 70cee0ea3d
commit 539e34c2bf
2 changed files with 58 additions and 75 deletions

View File

@ -15,16 +15,13 @@ pub use traits::mat_cast::MatCast;
pub use traits::column::Column;
pub use traits::inv::Inv;
pub use traits::rlmul::{RMul, LMul};
pub use traits::rotation::{Rotation, Rotate};
pub use traits::rotation::{Rotation, Rotate, RotationWithTranslation};
pub use traits::transformation::{Transformation, Transform};
pub use traits::translation::{Translation, Translate};
pub use traits::transpose::{Transpose};
pub use traits::homogeneous::{ToHomogeneous, FromHomogeneous};
pub use traits::row::Row;
// functions
pub use traits::rotation::{rotated_wrt_point, rotate_wrt_point, rotated_wrt_center, rotate_wrt_center};
mod mat_macros;
/// Special identity matrix. All its operation are no-ops.

View File

@ -26,6 +26,10 @@ pub trait Rotate<V> {
fn inv_rotate(&self, &V) -> V;
}
/// Utilities to make rotations with regard to a point different than the origin.
// NOTE: we cannot call this an Isometry since an isometry really does not need to have a rotation
// nor a translation (this can be a reflexion).
pub trait RotationWithTranslation<LV: Neg<LV>, AV>: Rotation<AV> + Translation<LV> {
/**
* Applies a rotation centered on a specific point.
*
@ -34,14 +38,8 @@ pub trait Rotate<V> {
* - `point`: the center of rotation.
*/
#[inline]
pub fn rotated_wrt_point<M: Translation<LV> + Rotation<AV>,
LV: Neg<LV>,
AV>(
m: &M,
ammount: &AV,
center: &LV)
-> M {
let mut res = m.translated(&-center);
fn rotated_wrt_point(&self, ammount: &AV, center: &LV) -> Self {
let mut res = self.translated(&-center);
res.rotate_by(ammount);
res.translate_by(center);
@ -56,15 +54,10 @@ pub fn rotated_wrt_point<M: Translation<LV> + Rotation<AV>,
/// * `ammount` - the rotation to be applied
/// * `center` - the new center of rotation
#[inline]
pub fn rotate_wrt_point<M: Rotation<AV> + Translation<LV>,
LV: Neg<LV>,
AV>(
m: &mut M,
ammount: &AV,
center: &LV) {
m.translate_by(&-center);
m.rotate_by(ammount);
m.translate_by(center);
fn rotate_wrt_point(&mut self, ammount: &AV, center: &LV) {
self.translate_by(&-center);
self.rotate_by(ammount);
self.translate_by(center);
}
/**
@ -75,13 +68,8 @@ pub fn rotate_wrt_point<M: Rotation<AV> + Translation<LV>,
* * `ammount` - the rotation to apply.
*/
#[inline]
pub fn rotated_wrt_center<M: Rotation<AV> + Translation<LV>,
LV: Neg<LV>,
AV>(
m: &M,
ammount: &AV)
-> M {
rotated_wrt_point(m, ammount, &m.translation())
fn rotated_wrt_center(&self, ammount: &AV) -> Self {
self.rotated_wrt_point(ammount, &self.translation())
}
/**
@ -92,12 +80,10 @@ pub fn rotated_wrt_center<M: Rotation<AV> + Translation<LV>,
* * `ammount` - the rotation to apply.
*/
#[inline]
pub fn rotate_wrt_center<M: Translation<LV> + Rotation<AV>,
LV: Neg<LV>,
AV>(
m: &mut M,
ammount: &AV) {
let t = m.translation();
rotate_wrt_point(m, ammount, &t)
fn rotate_wrt_center(&mut self, ammount: &AV) {
let center = self.translation();
self.rotate_wrt_point(ammount, &center)
}
}
impl<LV: Neg<LV>, AV, M: Rotation<AV> + Translation<LV>> RotationWithTranslation<LV, AV> for M;