pub struct Rotation { /* private fields */ }
Expand description

A discretized 2-dimensional rotation

Internally, these are stored in millionths of a degree, and so can be cleanly added and reversed without accumulating error.

Example

use leafwing_input_manager::orientation::{Rotation, Direction, Orientation};
use core::f32::consts::{FRAC_PI_2, PI, TAU};

let east = Rotation::from_radians(0.0);
let north = Rotation::from_radians(FRAC_PI_2);
let west = Rotation::from_radians(PI);

Rotation::default().assert_approx_eq(Rotation::from_radians(0.0));
Rotation::default().assert_approx_eq(Rotation::from_radians(TAU));
Rotation::default().assert_approx_eq(500.0 * Rotation::from_radians(TAU));

(north + north).assert_approx_eq(west);
(west - east).assert_approx_eq(west);
(2.0 * north).assert_approx_eq(west);
(west / 2.0).assert_approx_eq(north);

north.assert_approx_eq(Rotation::NORTH);

Direction::from(west).assert_approx_eq(Direction::WEST);

Implementations§

source§

impl Rotation

source

pub const fn new(micro_degrees: u32) -> Rotation

Creates a new Rotation from a whole number of millionths of a degree

Measured clockwise from midnight.

source

pub const fn micro_degrees(&self) -> u32

Returns the exact internal measurement, stored in millionths of a degree

Measured clockwise from midnight (x=0, y=1). 360_000_000 make up a full circle.

source§

impl Rotation

source

pub const DEGREE: u32 = 1_000_000u32

The number of micro-degrees in one degree

source

pub const HALF_CIRCLE: u32 = 180_000_000u32

The number of micro-degrees that make up a half circle

source

pub const FULL_CIRCLE: u32 = 360_000_000u32

The number of micro-degrees that make up a full circle

source

pub const NORTH: Rotation = _

The direction that points straight up

source

pub const EAST: Rotation = _

The direction that points straight right

source

pub const SOUTH: Rotation = _

The direction that points straight down

source

pub const WEST: Rotation = _

The direction that points straight left

source

pub const NORTHEAST: Rotation = _

The direction that points halfway between up and right

source

pub const SOUTHEAST: Rotation = _

The direction that points halfway between down and right

source

pub const SOUTHWEST: Rotation = _

The direction that points halfway between down and left

source

pub const NORTHWEST: Rotation = _

The direction that points halfway between left and up

source§

impl Rotation

source

pub fn from_xy(xy: Vec2) -> Result<Rotation, NearlySingularConversion>

Constructs a Rotation from an (x,y) Euclidean coordinate

If both x and y are nearly 0 (the magnitude is less than EPSILON), [Err(NearlySingularConversion)] will be returned instead.

Example
use bevy::math::Vec2;
use leafwing_input_manager::orientation::Rotation;

assert_eq!(Rotation::from_xy(Vec2::new(0.0, 1.0)), Ok(Rotation::NORTH));
source

pub fn into_xy(self) -> Vec2

Converts this direction into an (x, y) pair with magnitude 1

source

pub fn from_radians(radians: impl Into<f32>) -> Rotation

Construct a Direction from radians, measured counterclockwise from the positive x axis

source

pub fn into_radians(self) -> f32

Converts this direction into radians, measured counterclockwise from the positive x axis

source

pub fn from_degrees(degrees: impl Into<f32>) -> Rotation

Construct a Direction from degrees, measured counterclockwise from the positive x axis

source

pub const fn from_degrees_int(degrees: u32) -> Rotation

Construct a Direction from a whole number of degrees, measured counterclockwise from the positive x axis

source

pub fn into_degrees(self) -> f32

Converts this direction into degrees, measured counterclockwise from the positive x axis

Trait Implementations§

source§

impl Add for Rotation

§

type Output = Rotation

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Rotation

Performs the + operation. Read more
source§

impl AddAssign for Rotation

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl Clone for Rotation

source§

fn clone(&self) -> Rotation

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Component for Rotation
where Self: Send + Sync + 'static,

§

type Storage = TableStorage

A marker type indicating the storage type used for this component. This must be either [TableStorage] or [SparseStorage].
source§

impl Debug for Rotation

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Rotation

source§

fn default() -> Rotation

Returns the “default value” for a type. Read more
source§

impl Display for Rotation

source§

fn fmt(&self, _derive_more_display_formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Div<Rotation> for f32

§

type Output = Rotation

The resulting type after applying the / operator.
source§

fn div(self, rhs: Rotation) -> Rotation

Performs the / operation. Read more
source§

impl Div<f32> for Rotation

§

type Output = Rotation

The resulting type after applying the / operator.
source§

fn div(self, rhs: f32) -> Rotation

Performs the / operation. Read more
source§

impl From<Direction> for Rotation

source§

fn from(direction: Direction) -> Rotation

Converts to this type from the input type.
source§

impl From<GlobalTransform> for Rotation

source§

fn from(transform: GlobalTransform) -> Self

Converts to this type from the input type.
source§

impl From<Quat> for Rotation

source§

fn from(quaternion: Quat) -> Rotation

Converts to this type from the input type.
source§

impl From<Rotation> for Direction

source§

fn from(rotation: Rotation) -> Direction

Converts to this type from the input type.
source§

impl From<Rotation> for GlobalTransform

source§

fn from(rotation: Rotation) -> Self

Converts to this type from the input type.
source§

impl From<Rotation> for Quat

source§

fn from(rotation: Rotation) -> Self

Converts to this type from the input type.
source§

impl From<Rotation> for Transform

source§

fn from(rotation: Rotation) -> Self

Converts to this type from the input type.
source§

impl From<Rotation> for Vec2

source§

fn from(rotation: Rotation) -> Vec2

Converts to this type from the input type.
source§

impl From<Transform> for Rotation

source§

fn from(transform: Transform) -> Self

Converts to this type from the input type.
source§

impl Hash for Rotation

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Mul<Rotation> for f32

§

type Output = Rotation

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Rotation) -> Rotation

Performs the * operation. Read more
source§

impl Mul<f32> for Rotation

§

type Output = Rotation

The resulting type after applying the * operator.
source§

fn mul(self, rhs: f32) -> Rotation

Performs the * operation. Read more
source§

impl Neg for Rotation

§

type Output = Rotation

The resulting type after applying the - operator.
source§

fn neg(self) -> Rotation

Performs the unary - operation. Read more
source§

impl Orientation for Rotation

source§

fn distance(&self, other: Rotation) -> Rotation

Returns the absolute distance between self and other as a Rotation Read more
source§

fn assert_approx_eq(self, other: impl Orientation)

Asserts that self is approximately equal to other Read more
source§

fn rotation_direction(&self, target: Self) -> RotationDirection

Which RotationDirection is the shortest to rotate towards to reach target? Read more
source§

fn rotate_towards( &mut self, target_orientation: Self, max_rotation: Option<Rotation> )

Rotates self towards target_orientation by up to max_rotation Read more
source§

impl PartialEq for Rotation

source§

fn eq(&self, other: &Rotation) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Rotation

source§

fn partial_cmp(&self, other: &Rotation) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub for Rotation

§

type Output = Rotation

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Rotation

Performs the - operation. Read more
source§

impl SubAssign for Rotation

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl TryFrom<Vec2> for Rotation

§

type Error = NearlySingularConversion

The type returned in the event of a conversion error.
source§

fn try_from(vec2: Vec2) -> Result<Rotation, NearlySingularConversion>

Performs the conversion.
source§

impl Copy for Rotation

source§

impl Eq for Rotation

source§

impl StructuralEq for Rotation

source§

impl StructuralPartialEq for Rotation

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U

Return the T [ShaderType] for self. When used in [AsBindGroup] derives, it is safe to assume that all images in self exist.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<C> Bundle for C
where C: Component,

§

fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId) )

§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

§

impl<T> CallHasher for T
where T: Hash + ?Sized,

§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DynEq for T
where T: Any + Eq,

§

fn as_any(&self) -> &(dyn Any + 'static)

Casts the type to dyn Any.
§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
§

impl<T> DynHash for T
where T: DynEq + Hash,

§

fn as_dyn_eq(&self) -> &(dyn DynEq + 'static)

Casts the type to dyn Any.
§

fn dyn_hash(&self, state: &mut dyn Hasher)

Feeds this value into the given Hasher.
§

impl<C> DynamicBundle for C
where C: Component,

§

fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromWorld for T
where T: Default,

§

fn from_world(_world: &mut World) -> T

Creates Self using data from the given [World].
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData>

§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<M> Measure for M
where M: Debug + PartialOrd + Add<Output = M> + Default + Clone,

§

impl<T> Settings for T
where T: 'static + Send + Sync,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSync for T
where T: Sync,