2020-03-21 19:16:46 +08:00
|
|
|
use crate::allocator::Allocator;
|
|
|
|
use crate::geometry::{Rotation, UnitComplex, UnitQuaternion};
|
2020-03-22 06:22:55 +08:00
|
|
|
use crate::{DefaultAllocator, DimName, Point, Scalar, SimdRealField, VectorN, U2, U3};
|
2020-03-21 19:16:46 +08:00
|
|
|
|
|
|
|
use simba::scalar::ClosedMul;
|
|
|
|
|
|
|
|
pub trait AbstractRotation<N: Scalar, D: DimName>: PartialEq + ClosedMul + Clone {
|
|
|
|
fn identity() -> Self;
|
|
|
|
fn inverse(&self) -> Self;
|
|
|
|
fn inverse_mut(&mut self);
|
|
|
|
fn transform_vector(&self, v: &VectorN<N, D>) -> VectorN<N, D>
|
|
|
|
where DefaultAllocator: Allocator<N, D>;
|
|
|
|
fn transform_point(&self, p: &Point<N, D>) -> Point<N, D>
|
|
|
|
where DefaultAllocator: Allocator<N, D>;
|
|
|
|
fn inverse_transform_vector(&self, v: &VectorN<N, D>) -> VectorN<N, D>
|
|
|
|
where DefaultAllocator: Allocator<N, D>;
|
|
|
|
fn inverse_transform_point(&self, p: &Point<N, D>) -> Point<N, D>
|
|
|
|
where DefaultAllocator: Allocator<N, D>;
|
|
|
|
}
|
|
|
|
|
2020-03-22 06:22:55 +08:00
|
|
|
impl<N: SimdRealField, D: DimName> AbstractRotation<N, D> for Rotation<N, D>
|
|
|
|
where
|
|
|
|
N::Element: SimdRealField,
|
|
|
|
DefaultAllocator: Allocator<N, D, D>,
|
2020-03-21 19:16:46 +08:00
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn identity() -> Self {
|
|
|
|
Self::identity()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inverse(&self) -> Self {
|
|
|
|
self.inverse()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inverse_mut(&mut self) {
|
|
|
|
self.inverse_mut()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn transform_vector(&self, v: &VectorN<N, D>) -> VectorN<N, D>
|
|
|
|
where DefaultAllocator: Allocator<N, D> {
|
|
|
|
self * v
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn transform_point(&self, p: &Point<N, D>) -> Point<N, D>
|
|
|
|
where DefaultAllocator: Allocator<N, D> {
|
|
|
|
self * p
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inverse_transform_vector(&self, v: &VectorN<N, D>) -> VectorN<N, D>
|
|
|
|
where DefaultAllocator: Allocator<N, D> {
|
|
|
|
self.inverse_transform_vector(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inverse_transform_point(&self, p: &Point<N, D>) -> Point<N, D>
|
|
|
|
where DefaultAllocator: Allocator<N, D> {
|
|
|
|
self.inverse_transform_point(p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 06:22:55 +08:00
|
|
|
impl<N: SimdRealField> AbstractRotation<N, U3> for UnitQuaternion<N>
|
|
|
|
where N::Element: SimdRealField
|
|
|
|
{
|
2020-03-21 19:16:46 +08:00
|
|
|
#[inline]
|
|
|
|
fn identity() -> Self {
|
|
|
|
Self::identity()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inverse(&self) -> Self {
|
|
|
|
self.inverse()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inverse_mut(&mut self) {
|
|
|
|
self.inverse_mut()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn transform_vector(&self, v: &VectorN<N, U3>) -> VectorN<N, U3> {
|
|
|
|
self * v
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn transform_point(&self, p: &Point<N, U3>) -> Point<N, U3> {
|
|
|
|
self * p
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inverse_transform_vector(&self, v: &VectorN<N, U3>) -> VectorN<N, U3> {
|
|
|
|
self.inverse_transform_vector(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inverse_transform_point(&self, p: &Point<N, U3>) -> Point<N, U3> {
|
|
|
|
self.inverse_transform_point(p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 06:22:55 +08:00
|
|
|
impl<N: SimdRealField> AbstractRotation<N, U2> for UnitComplex<N>
|
|
|
|
where N::Element: SimdRealField
|
|
|
|
{
|
2020-03-21 19:16:46 +08:00
|
|
|
#[inline]
|
|
|
|
fn identity() -> Self {
|
|
|
|
Self::identity()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inverse(&self) -> Self {
|
|
|
|
self.inverse()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inverse_mut(&mut self) {
|
|
|
|
self.inverse_mut()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn transform_vector(&self, v: &VectorN<N, U2>) -> VectorN<N, U2> {
|
|
|
|
self * v
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn transform_point(&self, p: &Point<N, U2>) -> Point<N, U2> {
|
|
|
|
self * p
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inverse_transform_vector(&self, v: &VectorN<N, U2>) -> VectorN<N, U2> {
|
|
|
|
self.inverse_transform_vector(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inverse_transform_point(&self, p: &Point<N, U2>) -> Point<N, U2> {
|
|
|
|
self.inverse_transform_point(p)
|
|
|
|
}
|
|
|
|
}
|