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,6 +26,10 @@ 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.
|
||||||
|
// 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.
|
* Applies a rotation centered on a specific point.
|
||||||
*
|
*
|
||||||
|
@ -34,14 +38,8 @@ pub trait Rotate<V> {
|
||||||
* - `point`: the center of rotation.
|
* - `point`: the center of rotation.
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rotated_wrt_point<M: Translation<LV> + Rotation<AV>,
|
fn rotated_wrt_point(&self, ammount: &AV, center: &LV) -> Self {
|
||||||
LV: Neg<LV>,
|
let mut res = self.translated(&-center);
|
||||||
AV>(
|
|
||||||
m: &M,
|
|
||||||
ammount: &AV,
|
|
||||||
center: &LV)
|
|
||||||
-> M {
|
|
||||||
let mut res = m.translated(&-center);
|
|
||||||
|
|
||||||
res.rotate_by(ammount);
|
res.rotate_by(ammount);
|
||||||
res.translate_by(center);
|
res.translate_by(center);
|
||||||
|
@ -56,15 +54,10 @@ pub fn rotated_wrt_point<M: Translation<LV> + Rotation<AV>,
|
||||||
/// * `ammount` - the rotation to be applied
|
/// * `ammount` - the rotation to be applied
|
||||||
/// * `center` - the new center of rotation
|
/// * `center` - the new center of rotation
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rotate_wrt_point<M: Rotation<AV> + Translation<LV>,
|
fn rotate_wrt_point(&mut self, ammount: &AV, center: &LV) {
|
||||||
LV: Neg<LV>,
|
self.translate_by(&-center);
|
||||||
AV>(
|
self.rotate_by(ammount);
|
||||||
m: &mut M,
|
self.translate_by(center);
|
||||||
ammount: &AV,
|
|
||||||
center: &LV) {
|
|
||||||
m.translate_by(&-center);
|
|
||||||
m.rotate_by(ammount);
|
|
||||||
m.translate_by(center);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,13 +68,8 @@ pub fn rotate_wrt_point<M: Rotation<AV> + Translation<LV>,
|
||||||
* * `ammount` - the rotation to apply.
|
* * `ammount` - the rotation to apply.
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rotated_wrt_center<M: Rotation<AV> + Translation<LV>,
|
fn rotated_wrt_center(&self, ammount: &AV) -> Self {
|
||||||
LV: Neg<LV>,
|
self.rotated_wrt_point(ammount, &self.translation())
|
||||||
AV>(
|
|
||||||
m: &M,
|
|
||||||
ammount: &AV)
|
|
||||||
-> M {
|
|
||||||
rotated_wrt_point(m, ammount, &m.translation())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,12 +80,10 @@ pub fn rotated_wrt_center<M: Rotation<AV> + Translation<LV>,
|
||||||
* * `ammount` - the rotation to apply.
|
* * `ammount` - the rotation to apply.
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rotate_wrt_center<M: Translation<LV> + Rotation<AV>,
|
fn rotate_wrt_center(&mut self, ammount: &AV) {
|
||||||
LV: Neg<LV>,
|
let center = self.translation();
|
||||||
AV>(
|
self.rotate_wrt_point(ammount, ¢er)
|
||||||
m: &mut M,
|
|
||||||
ammount: &AV) {
|
|
||||||
let t = m.translation();
|
|
||||||
|
|
||||||
rotate_wrt_point(m, ammount, &t)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<LV: Neg<LV>, AV, M: Rotation<AV> + Translation<LV>> RotationWithTranslation<LV, AV> for M;
|
||||||
|
|
Loading…
Reference in New Issue