#[repr(C)]pub struct Rot2 {
pub re: f32,
pub im: f32,
}Expand description
A 2D rotation represented as a unit complex number (f32 precision).
The rotation is stored as re + im * i where re = cos(angle) and im = sin(angle).
Fields§
§re: f32Real part (cosine of the angle).
im: f32Imaginary part (sine of the angle).
Implementations§
Source§impl Rot2
impl Rot2
Sourcepub const fn from_cos_sin_unchecked(re: f32, im: f32) -> Rot2
pub const fn from_cos_sin_unchecked(re: f32, im: f32) -> Rot2
Creates a new unit complex from cosine and sine values.
The caller must ensure that re*re + im*im = 1.
Sourcepub fn from_matrix_unchecked(mat: Mat2) -> Rot2
pub fn from_matrix_unchecked(mat: Mat2) -> Rot2
Creates a rotation from a rotation matrix (without normalization).
Sourcepub fn from_angle(angle: f32) -> Rot2
pub fn from_angle(angle: f32) -> Rot2
Creates a rotation from an angle in radians.
Sourcepub fn length(&self) -> f32
pub fn length(&self) -> f32
Computes the length (magnitude) of self.
For a valid unit rotation, this should always be 1.0.
Sourcepub fn length_squared(&self) -> f32
pub fn length_squared(&self) -> f32
Computes the squared length of self.
This is faster than length() as it avoids a square root.
For a valid unit rotation, this should always be 1.0.
Sourcepub fn length_recip(&self) -> f32
pub fn length_recip(&self) -> f32
Computes 1.0 / length().
Sourcepub fn normalize(&self) -> Rot2
pub fn normalize(&self) -> Rot2
Returns self normalized to length 1.0.
For valid unit rotations this should be a no-op.
Sourcepub fn is_normalized(&self) -> bool
pub fn is_normalized(&self) -> bool
Returns whether self is of length 1.0 or not.
Uses a precision threshold of approximately 1e-4.
Sourcepub fn transform_vector(&self, v: Vec2) -> Vec2
pub fn transform_vector(&self, v: Vec2) -> Vec2
Rotates a 2D vector by this rotation.
Sourcepub fn inverse_transform_vector(&self, v: Vec2) -> Vec2
pub fn inverse_transform_vector(&self, v: Vec2) -> Vec2
Transforms a 2D vector by the inverse of this rotation.
Sourcepub fn from_mat(mat: Mat2) -> Rot2
pub fn from_mat(mat: Mat2) -> Rot2
Creates a rotation from a 2x2 rotation matrix.
The matrix should be a valid rotation matrix (orthogonal with determinant 1).
Sourcepub fn from_mat_unchecked(mat: Mat2) -> Rot2
pub fn from_mat_unchecked(mat: Mat2) -> Rot2
Creates a rotation from a 2x2 matrix without normalization.
Alias for from_matrix_unchecked.
Sourcepub fn from_rotation_arc(from: Vec2, to: Vec2) -> Rot2
pub fn from_rotation_arc(from: Vec2, to: Vec2) -> Rot2
Gets the minimal rotation for transforming from to to.
Both vectors must be normalized. The rotation is in the plane spanned by the two vectors.
Sourcepub fn slerp(&self, other: &Rot2, t: f32) -> Rot2
pub fn slerp(&self, other: &Rot2, t: f32) -> Rot2
Spherical linear interpolation between two rotations.
Sourcepub fn powf(&self, n: f32) -> Rot2
pub fn powf(&self, n: f32) -> Rot2
Raises this rotation to a power.
For example, powf(2.0) will return a rotation with double the angle.
Sourcepub fn rotate_towards(&self, rhs: &Rot2, max_angle: f32) -> Rot2
pub fn rotate_towards(&self, rhs: &Rot2, max_angle: f32) -> Rot2
Rotates self towards rhs up to max_angle (in radians).
When max_angle is 0.0, the result will be equal to self. When max_angle is
equal to self.angle_between(rhs), the result will be equal to rhs. If
max_angle is negative, rotates towards the exact opposite of rhs.
Will not go past the target.
Sourcepub fn angle_between(&self, rhs: &Rot2) -> f32
pub fn angle_between(&self, rhs: &Rot2) -> f32
Returns the angle (in radians) between self and rhs.
Sourcepub fn dot(&self, rhs: Rot2) -> f32
pub fn dot(&self, rhs: Rot2) -> f32
Computes the dot product of self and rhs.
The dot product is equal to the cosine of the angle between two rotations.
Sourcepub fn lerp(&self, rhs: Rot2, s: f32) -> Rot2
pub fn lerp(&self, rhs: Rot2, s: f32) -> Rot2
Performs a linear interpolation between self and rhs based on
the value s.
When s is 0.0, the result will be equal to self. When s is
1.0, the result will be equal to rhs. For rotations, slerp is
usually preferred over lerp.
Sourcepub fn normalize_mut(&mut self)
pub fn normalize_mut(&mut self)
Normalizes self in place.
Does nothing if self is already normalized or zero length.
Trait Implementations§
Source§impl AbsDiffEq for Rot2
impl AbsDiffEq for Rot2
Source§fn default_epsilon() -> <Rot2 as AbsDiffEq>::Epsilon
fn default_epsilon() -> <Rot2 as AbsDiffEq>::Epsilon
Source§fn abs_diff_eq(
&self,
other: &Rot2,
epsilon: <Rot2 as AbsDiffEq>::Epsilon,
) -> bool
fn abs_diff_eq( &self, other: &Rot2, epsilon: <Rot2 as AbsDiffEq>::Epsilon, ) -> bool
Source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq.Source§impl MulAssign<Rot2> for Pose2
impl MulAssign<Rot2> for Pose2
Source§fn mul_assign(&mut self, rhs: Rot2)
fn mul_assign(&mut self, rhs: Rot2)
*= operation. Read moreSource§impl MulAssign for Rot2
impl MulAssign for Rot2
Source§fn mul_assign(&mut self, rhs: Rot2)
fn mul_assign(&mut self, rhs: Rot2)
*= operation. Read moreSource§impl RelativeEq for Rot2
impl RelativeEq for Rot2
Source§fn default_max_relative() -> <Rot2 as AbsDiffEq>::Epsilon
fn default_max_relative() -> <Rot2 as AbsDiffEq>::Epsilon
Source§fn relative_eq(
&self,
other: &Rot2,
epsilon: <Rot2 as AbsDiffEq>::Epsilon,
max_relative: <Rot2 as AbsDiffEq>::Epsilon,
) -> bool
fn relative_eq( &self, other: &Rot2, epsilon: <Rot2 as AbsDiffEq>::Epsilon, max_relative: <Rot2 as AbsDiffEq>::Epsilon, ) -> bool
Source§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
RelativeEq::relative_eq.Source§impl UlpsEq for Rot2
impl UlpsEq for Rot2
Source§fn default_max_ulps() -> u32
fn default_max_ulps() -> u32
impl Copy for Rot2
impl StructuralPartialEq for Rot2
Auto Trait Implementations§
impl Freeze for Rot2
impl RefUnwindSafe for Rot2
impl Send for Rot2
impl Sync for Rot2
impl Unpin for Rot2
impl UnwindSafe for Rot2
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.