1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
use crate::allocator::Allocator;
use crate::geometry::{Rotation, UnitComplex, UnitQuaternion};
use crate::{DefaultAllocator, DimName, Point, Scalar, SimdRealField, Unit, VectorN, U2, U3};

use simba::scalar::ClosedMul;

/// Trait implemented by rotations that can be used inside of an `Isometry` or `Similarity`.
pub trait AbstractRotation<N: Scalar, D: DimName>: PartialEq + ClosedMul + Clone {
    /// The rotation identity.
    fn identity() -> Self;
    /// The rotation inverse.
    fn inverse(&self) -> Self;
    /// Change `self` to its inverse.
    fn inverse_mut(&mut self);
    /// Apply the rotation to the given vector.
    fn transform_vector(&self, v: &VectorN<N, D>) -> VectorN<N, D>
    where
        DefaultAllocator: Allocator<N, D>;
    /// Apply the rotation to the given point.
    fn transform_point(&self, p: &Point<N, D>) -> Point<N, D>
    where
        DefaultAllocator: Allocator<N, D>;
    /// Apply the inverse rotation to the given vector.
    fn inverse_transform_vector(&self, v: &VectorN<N, D>) -> VectorN<N, D>
    where
        DefaultAllocator: Allocator<N, D>;
    /// Apply the inverse rotation to the given unit vector.
    fn inverse_transform_unit_vector(&self, v: &Unit<VectorN<N, D>>) -> Unit<VectorN<N, D>>
    where
        DefaultAllocator: Allocator<N, D>,
    {
        Unit::new_unchecked(self.inverse_transform_vector(&**v))
    }
    /// 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>;
}

impl<N: SimdRealField, D: DimName> AbstractRotation<N, D> for Rotation<N, D>
where
    N::Element: SimdRealField,
    DefaultAllocator: Allocator<N, D, D>,
{
    #[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_unit_vector(&self, v: &Unit<VectorN<N, D>>) -> Unit<VectorN<N, D>>
    where
        DefaultAllocator: Allocator<N, D>,
    {
        self.inverse_transform_unit_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)
    }
}

impl<N: SimdRealField> AbstractRotation<N, U3> for UnitQuaternion<N>
where
    N::Element: SimdRealField,
{
    #[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>
where
    N::Element: SimdRealField,
{
    #[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)
    }
}