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

A discretized 2-dimensional rotation

Internally, these are stored in tenths 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

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

Measured clockwise from midnight.

Returns the exact internal mesaurement, stored in tenths of a degree

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

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

The direction that points straight up

The direction that points straight right

The direction that points straight down

The direction that points straight left

The direction that points halfway between up and right

The direction that points halfway between down and right

The direction that points halfway between down and left

The direction that points halfway between left and up

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));

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

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

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

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

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

Trait Implementations

The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
Returns the absolute distance between self and other as a Rotation Read more
Asserts that self is approximately equal to other Read more
Which RotationDirection is the shortest to rotate towards to reach target? Read more
Rotates self towards target_orientation by up to max_rotation Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Return the T [ShaderType] for self. When used in [AsBindGroup] derives, it is safe to assume that all images in self exist. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
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. Read more
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more
Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more
Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Creates Self using data from the given [World]
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more