nalgebra/src/geometry/abstract_rotation.rs

178 lines
4.4 KiB
Rust
Raw Normal View History

2020-03-21 19:16:46 +08:00
use crate::geometry::{Rotation, UnitComplex, UnitQuaternion};
use crate::{CVectorN, Const, Point, Scalar, SimdRealField, Unit, VectorN};
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`.
pub trait AbstractRotation<N: Scalar, const D: usize>: 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.
fn transform_vector(&self, v: &CVectorN<N, D>) -> CVectorN<N, D>;
// where
// DefaultAllocator: Allocator<N, D>;
2020-04-06 00:02:03 +08:00
/// Apply the rotation to the given point.
fn transform_point(&self, p: &Point<N, D>) -> Point<N, D>;
// where
// DefaultAllocator: Allocator<N, D>;
2020-04-06 00:02:03 +08:00
/// Apply the inverse rotation to the given vector.
fn inverse_transform_vector(&self, v: &VectorN<N, Const<D>>) -> VectorN<N, Const<D>>;
// where
// DefaultAllocator: Allocator<N, D>;
/// Apply the inverse rotation to the given unit vector.
fn inverse_transform_unit_vector(&self, v: &Unit<CVectorN<N, D>>) -> Unit<CVectorN<N, D>>
// where
// DefaultAllocator: Allocator<N, D>,
{
Unit::new_unchecked(self.inverse_transform_vector(&**v))
}
2020-04-06 00:02:03 +08:00
/// Apply the inverse rotation to the given point.
fn inverse_transform_point(&self, p: &Point<N, D>) -> Point<N, D>;
// where
// DefaultAllocator: Allocator<N, D>;
2020-03-21 19:16:46 +08:00
}
impl<N: SimdRealField, const D: usize> AbstractRotation<N, D> for Rotation<N, D>
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: &CVectorN<N, D>) -> CVectorN<N, D>
// where
// DefaultAllocator: Allocator<N, D>,
2020-04-06 00:02:03 +08:00
{
2020-03-21 19:16:46 +08:00
self * v
}
#[inline]
fn transform_point(&self, p: &Point<N, D>) -> Point<N, D>
// where
// DefaultAllocator: Allocator<N, D>,
2020-04-06 00:02:03 +08:00
{
2020-03-21 19:16:46 +08:00
self * p
}
#[inline]
fn inverse_transform_vector(&self, v: &CVectorN<N, D>) -> CVectorN<N, D>
// where
// DefaultAllocator: Allocator<N, D>,
2020-04-06 00:02:03 +08:00
{
2020-03-21 19:16:46 +08:00
self.inverse_transform_vector(v)
}
#[inline]
fn inverse_transform_unit_vector(&self, v: &Unit<CVectorN<N, D>>) -> Unit<CVectorN<N, D>>
// where
// DefaultAllocator: Allocator<N, D>,
{
self.inverse_transform_unit_vector(v)
}
2020-03-21 19:16:46 +08:00
#[inline]
fn inverse_transform_point(&self, p: &Point<N, D>) -> Point<N, D>
// where
// DefaultAllocator: Allocator<N, D>,
2020-04-06 00:02:03 +08:00
{
2020-03-21 19:16:46 +08:00
self.inverse_transform_point(p)
}
}
impl<N: SimdRealField> AbstractRotation<N, 3> 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: &CVectorN<N, 3>) -> CVectorN<N, 3> {
2020-03-21 19:16:46 +08:00
self * v
}
#[inline]
fn transform_point(&self, p: &Point<N, 3>) -> Point<N, 3> {
2020-03-21 19:16:46 +08:00
self * p
}
#[inline]
fn inverse_transform_vector(&self, v: &CVectorN<N, 3>) -> CVectorN<N, 3> {
2020-03-21 19:16:46 +08:00
self.inverse_transform_vector(v)
}
#[inline]
fn inverse_transform_point(&self, p: &Point<N, 3>) -> Point<N, 3> {
2020-03-21 19:16:46 +08:00
self.inverse_transform_point(p)
}
}
impl<N: SimdRealField> AbstractRotation<N, 2> 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: &CVectorN<N, 2>) -> CVectorN<N, 2> {
2020-03-21 19:16:46 +08:00
self * v
}
#[inline]
fn transform_point(&self, p: &Point<N, 2>) -> Point<N, 2> {
2020-03-21 19:16:46 +08:00
self * p
}
#[inline]
fn inverse_transform_vector(&self, v: &CVectorN<N, 2>) -> CVectorN<N, 2> {
2020-03-21 19:16:46 +08:00
self.inverse_transform_vector(v)
}
#[inline]
fn inverse_transform_point(&self, p: &Point<N, 2>) -> Point<N, 2> {
2020-03-21 19:16:46 +08:00
self.inverse_transform_point(p)
}
}