Move all the rotation-related free functions to a `RotationWithTranslation` trait.
This is not a very good name though.
This commit is contained in:
parent
70cee0ea3d
commit
539e34c2bf
|
@ -15,16 +15,13 @@ pub use traits::mat_cast::MatCast;
|
||||||
pub use traits::column::Column;
|
pub use traits::column::Column;
|
||||||
pub use traits::inv::Inv;
|
pub use traits::inv::Inv;
|
||||||
pub use traits::rlmul::{RMul, LMul};
|
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::transformation::{Transformation, Transform};
|
||||||
pub use traits::translation::{Translation, Translate};
|
pub use traits::translation::{Translation, Translate};
|
||||||
pub use traits::transpose::{Transpose};
|
pub use traits::transpose::{Transpose};
|
||||||
pub use traits::homogeneous::{ToHomogeneous, FromHomogeneous};
|
pub use traits::homogeneous::{ToHomogeneous, FromHomogeneous};
|
||||||
pub use traits::row::Row;
|
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;
|
mod mat_macros;
|
||||||
|
|
||||||
/// Special identity matrix. All its operation are no-ops.
|
/// Special identity matrix. All its operation are no-ops.
|
||||||
|
|
|
@ -26,78 +26,64 @@ pub trait Rotate<V> {
|
||||||
fn inv_rotate(&self, &V) -> V;
|
fn inv_rotate(&self, &V) -> V;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// Utilities to make rotations with regard to a point different than the origin.
|
||||||
* Applies a rotation centered on a specific point.
|
// 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).
|
||||||
* - `m`: the object to be rotated.
|
pub trait RotationWithTranslation<LV: Neg<LV>, AV>: Rotation<AV> + Translation<LV> {
|
||||||
* - `ammount`: the rotation to apply.
|
/**
|
||||||
* - `point`: the center of rotation.
|
* Applies a rotation centered on a specific point.
|
||||||
*/
|
*
|
||||||
#[inline]
|
* - `m`: the object to be rotated.
|
||||||
pub fn rotated_wrt_point<M: Translation<LV> + Rotation<AV>,
|
* - `ammount`: the rotation to apply.
|
||||||
LV: Neg<LV>,
|
* - `point`: the center of rotation.
|
||||||
AV>(
|
*/
|
||||||
m: &M,
|
#[inline]
|
||||||
ammount: &AV,
|
fn rotated_wrt_point(&self, ammount: &AV, center: &LV) -> Self {
|
||||||
center: &LV)
|
let mut res = self.translated(&-center);
|
||||||
-> M {
|
|
||||||
let mut res = m.translated(&-center);
|
|
||||||
|
|
||||||
res.rotate_by(ammount);
|
res.rotate_by(ammount);
|
||||||
res.translate_by(center);
|
res.translate_by(center);
|
||||||
|
|
||||||
res
|
res
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Rotates an object using a specific center of rotation.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * `m` - the object to be rotated
|
||||||
|
/// * `ammount` - the rotation to be applied
|
||||||
|
/// * `center` - the new center of rotation
|
||||||
|
#[inline]
|
||||||
|
fn rotate_wrt_point(&mut self, ammount: &AV, center: &LV) {
|
||||||
|
self.translate_by(&-center);
|
||||||
|
self.rotate_by(ammount);
|
||||||
|
self.translate_by(center);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a rotation centered on the input translation.
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
* * `m` - the object to be rotated.
|
||||||
|
* * `ammount` - the rotation to apply.
|
||||||
|
*/
|
||||||
|
#[inline]
|
||||||
|
fn rotated_wrt_center(&self, ammount: &AV) -> Self {
|
||||||
|
self.rotated_wrt_point(ammount, &self.translation())
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a rotation centered on the input translation.
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
* * `m` - the object to be rotated.
|
||||||
|
* * `ammount` - the rotation to apply.
|
||||||
|
*/
|
||||||
|
#[inline]
|
||||||
|
fn rotate_wrt_center(&mut self, ammount: &AV) {
|
||||||
|
let center = self.translation();
|
||||||
|
self.rotate_wrt_point(ammount, ¢er)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rotates an object using a specific center of rotation.
|
impl<LV: Neg<LV>, AV, M: Rotation<AV> + Translation<LV>> RotationWithTranslation<LV, AV> for M;
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
/// * `m` - the object to be rotated
|
|
||||||
/// * `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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies a rotation centered on the input translation.
|
|
||||||
*
|
|
||||||
* # Arguments
|
|
||||||
* * `m` - the object to be rotated.
|
|
||||||
* * `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())
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies a rotation centered on the input translation.
|
|
||||||
*
|
|
||||||
* # Arguments
|
|
||||||
* * `m` - the object to be rotated.
|
|
||||||
* * `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)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue