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