use std::ops::Neg;
use traits::structure::{BaseFloat, Mat};
pub trait Translation<V> {
fn translation(&self) -> V;
fn inv_translation(&self) -> V;
fn append_translation_mut(&mut self, &V);
fn append_translation(&self, amount: &V) -> Self;
fn prepend_translation_mut(&mut self, &V);
fn prepend_translation(&self, amount: &V) -> Self;
fn set_translation(&mut self, V);
}
pub trait Translate<V> {
fn translate(&self, &V) -> V;
fn inv_translate(&self, &V) -> V;
}
pub trait Rotation<V> {
fn rotation(&self) -> V;
fn inv_rotation(&self) -> V;
fn append_rotation_mut(&mut self, &V);
fn append_rotation(&self, amount: &V) -> Self;
fn prepend_rotation_mut(&mut self, &V);
fn prepend_rotation(&self, amount: &V) -> Self;
fn set_rotation(&mut self, V);
}
pub trait Rotate<V> {
fn rotate(&self, v: &V) -> V;
fn inv_rotate(&self, v: &V) -> V;
}
pub trait RotationWithTranslation<LV: Neg<Output = LV> + Copy, AV>: Rotation<AV> + Translation<LV> + Sized {
#[inline]
fn append_rotation_wrt_point(&self, amount: &AV, center: &LV) -> Self {
let mut res = Translation::append_translation(self, &-*center);
res.append_rotation_mut(amount);
res.append_translation_mut(center);
res
}
#[inline]
fn append_rotation_wrt_point_mut(&mut self, amount: &AV, center: &LV) {
self.append_translation_mut(&-*center);
self.append_rotation_mut(amount);
self.append_translation_mut(center);
}
#[inline]
fn append_rotation_wrt_center(&self, amount: &AV) -> Self {
RotationWithTranslation::append_rotation_wrt_point(self, amount, &self.translation())
}
#[inline]
fn append_rotation_wrt_center_mut(&mut self, amount: &AV) {
let center = self.translation();
self.append_rotation_wrt_point_mut(amount, ¢er)
}
}
impl<LV: Neg<Output = LV> + Copy, AV, M: Rotation<AV> + Translation<LV>> RotationWithTranslation<LV, AV> for M {
}
pub trait RotationMatrix<N, LV, AV> : Rotation<AV> {
type Output: Mat<N, LV, LV> + Rotation<AV>;
fn to_rot_mat(&self) -> Self::Output;
}
pub trait AbsoluteRotate<V> {
fn absolute_rotate(&self, v: &V) -> V;
}
pub trait Transformation<M> {
fn transformation(&self) -> M;
fn inv_transformation(&self) -> M;
fn append_transformation_mut(&mut self, &M);
fn append_transformation(&self, amount: &M) -> Self;
fn prepend_transformation_mut(&mut self, &M);
fn prepend_transformation(&self, amount: &M) -> Self;
fn set_transformation(&mut self, M);
}
pub trait Transform<V> {
fn transform(&self, &V) -> V;
fn inv_transform(&self, &V) -> V;
}
pub trait Dot<N> {
#[inline]
fn dot(&self, other: &Self) -> N;
}
pub trait Norm<N: BaseFloat> {
#[inline]
fn norm(&self) -> N {
self.sqnorm().sqrt()
}
fn sqnorm(&self) -> N;
fn normalize(&self) -> Self;
fn normalize_mut(&mut self) -> N;
}
pub trait Cross {
type Output;
fn cross(&self, other: &Self) -> Self::Output;
}
pub trait CrossMatrix<M> {
fn cross_matrix(&self) -> M;
}
pub trait ToHomogeneous<U> {
fn to_homogeneous(&self) -> U;
}
pub trait FromHomogeneous<U> {
fn from(&U) -> Self;
}
pub trait UniformSphereSample {
fn sample<F: FnMut(Self)>(F);
}
pub trait Orig {
fn orig() -> Self;
fn is_orig(&self) -> bool;
}