nalgebra/src/geometry/abstract_rotation.rs

152 lines
3.8 KiB
Rust
Raw Normal View History

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