pub struct DRot2 {
pub cos: f64,
pub sin: f64,
}Expand description
A double-precision version of Rot2.
Fields§
§cos: f64The cosine of the rotation angle.
This is the real part of the unit complex number representing the rotation.
sin: f64The sine of the rotation angle.
This is the imaginary part of the unit complex number representing the rotation.
Implementations§
Source§impl DRot2
impl DRot2
Sourcepub const FRAC_PI_2: Self
pub const FRAC_PI_2: Self
A counterclockwise rotation of π/2 radians. Corresponds to a counterclockwise quarter-turn.
Sourcepub const FRAC_PI_3: Self
pub const FRAC_PI_3: Self
A counterclockwise rotation of π/3 radians. Corresponds to a counterclockwise turn by 60°.
Sourcepub const FRAC_PI_4: Self
pub const FRAC_PI_4: Self
A counterclockwise rotation of π/4 radians. Corresponds to a counterclockwise turn by 45°.
Sourcepub const FRAC_PI_6: Self
pub const FRAC_PI_6: Self
A counterclockwise rotation of π/6 radians. Corresponds to a counterclockwise turn by 30°.
Sourcepub const FRAC_PI_8: Self
pub const FRAC_PI_8: Self
A counterclockwise rotation of π/8 radians. Corresponds to a counterclockwise turn by 22.5°.
Sourcepub fn turn_fraction(fraction: f64) -> Self
pub fn turn_fraction(fraction: f64) -> Self
Creates a DRot2 from a counterclockwise fraction of a full turn of 360 degrees.
A negative argument corresponds to a clockwise rotation.
§Note
Angles larger than or equal to 1 turn (in either direction) loop around to smaller rotations, since a full rotation returns an object to its starting orientation.
Sourcepub fn from_sin_cos(sin: f64, cos: f64) -> Self
pub fn from_sin_cos(sin: f64, cos: f64) -> Self
Sourcepub fn as_radians(self) -> f64
pub fn as_radians(self) -> f64
Returns a corresponding rotation angle in radians in the (-pi, pi] range.
Sourcepub fn as_degrees(self) -> f64
pub fn as_degrees(self) -> f64
Returns a corresponding rotation angle in degrees in the (-180, 180] range.
Sourcepub fn as_turn_fraction(self) -> f64
pub fn as_turn_fraction(self) -> f64
Returns a corresponding rotation angle as a fraction of a full 360 degree turn in the (-0.5, 0.5] range.
Sourcepub fn length(self) -> f64
pub fn length(self) -> f64
Computes the length or norm of the complex number used to represent the rotation.
The length is typically expected to be 1.0. Unexpectedly denormalized rotations
can be a result of incorrect construction or floating point error caused by
successive operations.
Sourcepub fn length_squared(self) -> f64
pub fn length_squared(self) -> f64
Computes the squared length or norm of the complex number used to represent the rotation.
This is generally faster than DRot2::length(), as it avoids a square
root operation.
The length is typically expected to be 1.0. Unexpectedly denormalized rotations
can be a result of incorrect construction or floating point error caused by
successive operations.
Sourcepub fn length_recip(self) -> f64
pub fn length_recip(self) -> f64
Computes 1.0 / self.length().
For valid results, self must not have a length of zero.
Sourcepub fn try_normalize(self) -> Option<Self>
pub fn try_normalize(self) -> Option<Self>
Returns self with a length of 1.0 if possible, and None otherwise.
None will be returned if the sine and cosine of self are both zero (or very close to zero),
or if either of them is NaN or infinite.
Note that DRot2 should typically already be normalized by design.
Manual normalization is only needed when successive operations result in
accumulated floating point error, or if the rotation was constructed
with invalid values.
Sourcepub fn normalize(self) -> Self
pub fn normalize(self) -> Self
Returns self with a length of 1.0.
Note that DRot2 should typically already be normalized by design.
Manual normalization is only needed when successive operations result in
accumulated floating point error, or if the rotation was constructed
with invalid values.
§Panics
Panics if self has a length of zero, NaN, or infinity when debug assertions are enabled.
Sourcepub fn fast_renormalize(self) -> Self
pub fn fast_renormalize(self) -> Self
Returns self after an approximate normalization, assuming the value is already nearly normalized.
Useful for preventing numerical error accumulation.
Sourcepub fn is_normalized(self) -> bool
pub fn is_normalized(self) -> bool
Returns whether self has a length of 1.0 or not.
Uses a precision threshold of approximately 1e-4.
Sourcepub fn is_near_identity(self) -> bool
pub fn is_near_identity(self) -> bool
Returns true if the rotation is near DRot2::IDENTITY.
Sourcepub fn angle_to(self, other: Self) -> f64
pub fn angle_to(self, other: Self) -> f64
Returns the angle in radians needed to make self and other coincide.
Sourcepub const fn inverse(self) -> Self
pub const fn inverse(self) -> Self
Returns the inverse of the rotation. This is also the conjugate of the unit complex number representing the rotation.
Sourcepub fn nlerp(self, end: Self, s: f64) -> Self
pub fn nlerp(self, end: Self, s: f64) -> Self
Performs a linear interpolation between self and end based on
the value s, and normalizes the rotation afterwards.
When s == 0.0, the result will be equal to self.
When s == 1.0, the result will be equal to end.
This is slightly more efficient than slerp, and produces a similar result
when the difference between the two rotations is small. At larger differences,
the result resembles a kind of ease-in-out effect.
If you would like the angular velocity to remain constant, consider using slerp instead.
§Details
nlerp corresponds to computing an angle for a point at position s on a line drawn
between the endpoints of the arc formed by self and end on a unit circle,
and normalizing the result afterwards.
Note that if the angles are opposite like 0 and π, the line will pass through the origin,
and the resulting angle will always be either self or end depending on s.
If s happens to be 0.5 in this case, a valid rotation cannot be computed, and self
will be returned as a fallback.
Sourcepub fn slerp(self, end: Self, s: f64) -> Self
pub fn slerp(self, end: Self, s: f64) -> Self
Performs a spherical linear interpolation between self and end
based on the value s.
This corresponds to interpolating between the two angles at a constant angular velocity.
When s == 0.0, the result will be equal to self.
When s == 1.0, the result will be equal to end.
If you would like the rotation to have a kind of ease-in-out effect, consider
using the slightly more efficient nlerp instead.
Trait Implementations§
impl Copy for DRot2
Source§impl FromReflect for DRot2
impl FromReflect for DRot2
Source§fn from_reflect(reflect: &dyn PartialReflect) -> Option<Self>
fn from_reflect(reflect: &dyn PartialReflect) -> Option<Self>
Self from a reflected value.Source§fn take_from_reflect(
reflect: Box<dyn PartialReflect>,
) -> Result<Self, Box<dyn PartialReflect>>
fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>
Self using,
constructing the value using from_reflect if that fails. Read moreSource§impl GetTypeRegistration for DRot2
impl GetTypeRegistration for DRot2
Source§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
TypeRegistration for this type.Source§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
Source§impl MulAssign for DRot2
impl MulAssign for DRot2
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl PartialReflect for DRot2
impl PartialReflect for DRot2
Source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
Source§fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError>
fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError>
Source§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
Source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
Source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
Source§fn reflect_owned(self: Box<Self>) -> ReflectOwned
fn reflect_owned(self: Box<Self>) -> ReflectOwned
Source§fn try_into_reflect(
self: Box<Self>,
) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
fn try_into_reflect( self: Box<Self>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
Source§fn try_as_reflect(&self) -> Option<&dyn Reflect>
fn try_as_reflect(&self) -> Option<&dyn Reflect>
Source§fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
Source§fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect>
fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect>
Source§fn as_partial_reflect(&self) -> &dyn PartialReflect
fn as_partial_reflect(&self) -> &dyn PartialReflect
Source§fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect
fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect
Source§fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option<bool>
fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option<bool>
Source§fn reflect_partial_cmp(&self, value: &dyn PartialReflect) -> Option<Ordering>
fn reflect_partial_cmp(&self, value: &dyn PartialReflect) -> Option<Ordering>
Source§fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
Self using reflection. Read moreSource§fn apply(&mut self, value: &(dyn PartialReflect + 'static))
fn apply(&mut self, value: &(dyn PartialReflect + 'static))
Source§fn to_dynamic(&self) -> Result<Box<dyn PartialReflect>, ReflectCloneError>
fn to_dynamic(&self) -> Result<Box<dyn PartialReflect>, ReflectCloneError>
Source§fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
PartialReflect, combines reflect_clone and
take in a useful fashion, automatically constructing an appropriate
ReflectCloneError if the downcast fails.Source§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Source§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
Source§impl Reflect for DRot2
impl Reflect for DRot2
Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
&mut dyn Any. Read moreSource§fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
Source§fn as_reflect(&self) -> &dyn Reflect
fn as_reflect(&self) -> &dyn Reflect
Source§fn as_reflect_mut(&mut self) -> &mut dyn Reflect
fn as_reflect_mut(&mut self) -> &mut dyn Reflect
Source§impl Struct for DRot2
impl Struct for DRot2
Source§fn field(&self, name: &str) -> Option<&dyn PartialReflect>
fn field(&self, name: &str) -> Option<&dyn PartialReflect>
name as a &dyn PartialReflect.Source§fn field_mut(&mut self, name: &str) -> Option<&mut dyn PartialReflect>
fn field_mut(&mut self, name: &str) -> Option<&mut dyn PartialReflect>
name as a
&mut dyn PartialReflect.Source§fn field_at(&self, index: usize) -> Option<&dyn PartialReflect>
fn field_at(&self, index: usize) -> Option<&dyn PartialReflect>
index as a
&dyn PartialReflect.Source§fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>
fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>
index
as a &mut dyn PartialReflect.Source§fn index_of_name(&self, name: &str) -> Option<usize>
fn index_of_name(&self, name: &str) -> Option<usize>
Source§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
Source§fn to_dynamic_struct(&self) -> Result<DynamicStruct, ReflectCloneError>
fn to_dynamic_struct(&self) -> Result<DynamicStruct, ReflectCloneError>
DynamicStruct from this struct. Read moreSource§fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
None if TypeInfo is not available.impl StructuralPartialEq for DRot2
Source§impl ToF32Precision for DRot2
impl ToF32Precision for DRot2
Source§impl ToRealPrecision for DRot2
impl ToRealPrecision for DRot2
Source§impl TypePath for DRot2
impl TypePath for DRot2
Source§fn type_path() -> &'static str
fn type_path() -> &'static str
Source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
Source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
Source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
Auto Trait Implementations§
impl Freeze for DRot2
impl RefUnwindSafe for DRot2
impl Send for DRot2
impl Sync for DRot2
impl Unpin for DRot2
impl UnsafeUnpin for DRot2
impl UnwindSafe for DRot2
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T, Right> ClosedMul<Right> for T
impl<T, Right> ClosedMulAssign<Right> for T
impl<T> ConditionalSend for Twhere
T: Send,
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> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
Source§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path.Source§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
Source§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident.Source§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name.Source§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
Source§impl<T> DynamicTyped for Twhere
T: Typed,
impl<T> DynamicTyped for Twhere
T: Typed,
Source§fn reflect_type_info(&self) -> &'static TypeInfo
fn reflect_type_info(&self) -> &'static TypeInfo
Typed::type_info.Source§impl<T> FromTemplate for T
impl<T> FromTemplate for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
Source§impl<T> GetPath for T
impl<T> GetPath for T
Source§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
path. Read moreSource§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
path. Read moreSource§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
path. Read moreSource§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
path. Read moreSource§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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Reflectable for T
impl<T> Scalar for T
impl<T> Settings for T
Source§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.Source§impl<T> Template for T
impl<T> Template for T
Source§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
entity context to produce a Template::Output.Source§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clone.Source§impl<T> TypeData for T
impl<T> TypeData for T
Source§fn clone_type_data(&self) -> Box<dyn TypeData>
fn clone_type_data(&self) -> Box<dyn TypeData>
self.