nalgebra/src/geometry/abstract_rotation.rs

165 lines
3.9 KiB
Rust
Raw Normal View History

2020-03-21 19:16:46 +08:00
use crate::allocator::Allocator;
use crate::geometry::{Rotation, UnitComplex, UnitQuaternion};
use crate::{DefaultAllocator, DimName, Point, Scalar, SimdRealField, VectorN, U2, U3};
2020-03-21 19:16:46 +08:00
use simba::scalar::ClosedMul;
2020-04-06 00:02:03 +08:00
/// Trait implemented by rotations that can be used inside of an `Isometry` or `Similarity`.
2020-03-21 19:16:46 +08:00
pub trait AbstractRotation<N: Scalar, D: DimName>: PartialEq + ClosedMul + Clone {
2020-04-06 00:02:03 +08:00
/// The rotation identity.
2020-03-21 19:16:46 +08:00
fn identity() -> Self;
2020-04-06 00:02:03 +08:00
/// The rotation inverse.
2020-03-21 19:16:46 +08:00
fn inverse(&self) -> Self;
2020-04-06 00:02:03 +08:00
/// Change `self` to its inverse.
2020-03-21 19:16:46 +08:00
fn inverse_mut(&mut self);
2020-04-06 00:02:03 +08:00
/// Apply the rotation to the given vector.
2020-03-21 19:16:46 +08:00
fn transform_vector(&self, v: &VectorN<N, D>) -> VectorN<N, D>
2020-04-06 00:02:03 +08:00
where
DefaultAllocator: Allocator<N, D>;
/// Apply the rotation to the given point.
2020-03-21 19:16:46 +08:00
fn transform_point(&self, p: &Point<N, D>) -> Point<N, D>
2020-04-06 00:02:03 +08:00
where
DefaultAllocator: Allocator<N, D>;
/// Apply the inverse rotation to the given vector.
2020-03-21 19:16:46 +08:00
fn inverse_transform_vector(&self, v: &VectorN<N, D>) -> VectorN<N, D>
2020-04-06 00:02:03 +08:00
where
DefaultAllocator: Allocator<N, D>;
/// Apply the inverse rotation to the given point.
2020-03-21 19:16:46 +08:00
fn inverse_transform_point(&self, p: &Point<N, D>) -> Point<N, D>
2020-04-06 00:02:03 +08:00
where
DefaultAllocator: Allocator<N, D>;
2020-03-21 19:16:46 +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>
2020-04-06 00:02:03 +08:00
where
DefaultAllocator: Allocator<N, D>,
{
2020-03-21 19:16:46 +08:00
self * v
}
#[inline]
fn transform_point(&self, p: &Point<N, D>) -> Point<N, D>
2020-04-06 00:02:03 +08:00
where
DefaultAllocator: Allocator<N, D>,
{
2020-03-21 19:16:46 +08:00
self * p
}
#[inline]
fn inverse_transform_vector(&self, v: &VectorN<N, D>) -> VectorN<N, D>
2020-04-06 00:02:03 +08:00
where
DefaultAllocator: Allocator<N, D>,
{
2020-03-21 19:16:46 +08:00
self.inverse_transform_vector(v)
}
#[inline]
fn inverse_transform_point(&self, p: &Point<N, D>) -> Point<N, D>
2020-04-06 00:02:03 +08:00
where
DefaultAllocator: Allocator<N, D>,
{
2020-03-21 19:16:46 +08:00
self.inverse_transform_point(p)
}
}
impl<N: SimdRealField> AbstractRotation<N, U3> for UnitQuaternion<N>
2020-04-06 00:02:03 +08:00
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)
}
}
impl<N: SimdRealField> AbstractRotation<N, U2> for UnitComplex<N>
2020-04-06 00:02:03 +08:00
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)
}
}