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

A 2D unit vector that represents a direction

Its magnitude is always 1.0.

Example

use leafwing_input_manager::orientation::Direction;
use bevy::math::Vec2;

assert_eq!(Direction::NORTH.unit_vector(), Vec2::new(0.0, 1.0));
assert_eq!(Direction::try_from(Vec2::ONE), Ok(Direction::NORTHEAST));

assert_eq!(Direction::SOUTH * 3.0, Vec2::new(0.0, -3.0));
assert_eq!(Direction::EAST / 2.0, Vec2::new(0.5, 0.0));

Implementations§

source§

impl Direction

source

pub fn new(vec2: Vec2) -> Self

Creates a new Direction from a Vec2

The Vec2 stored internally will be normalized to have a magnitude of 1.0.

Panics

Panics if the length of the supplied vector has length zero or cannot be determined. Use try_from to get a Result instead.

source

pub const fn unit_vector(&self) -> Vec2

Returns the raw underlying Vec2 unit vector of this direction

This will always have a length of 1.0

source§

impl Direction

source

pub const NORTH: Direction = _

The direction that points straight up

source

pub const EAST: Direction = _

The direction that points straight right

source

pub const SOUTH: Direction = _

The direction that points straight down

source

pub const WEST: Direction = _

The direction that points straight left

source

pub const NORTHEAST: Direction = _

The direction that points halfway between up and right

source

pub const SOUTHEAST: Direction = _

The direction that points halfway between down and right

source

pub const SOUTHWEST: Direction = _

The direction that points halfway between down and left

source

pub const NORTHWEST: Direction = _

The direction that points halfway between left and up

Trait Implementations§

source§

impl Add for Direction

§

type Output = Vec2

The resulting type after applying the + operator.
source§

fn add(self, other: Direction) -> Vec2

Performs the + operation. Read more
source§

impl Clone for Direction

source§

fn clone(&self) -> Direction

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 Direction
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 Direction

source§

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

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

impl Default for Direction

source§

fn default() -> Direction

Direction::EAST is the default direction, as it is consistent with the default Rotation

source§

impl Display for Direction

source§

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

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

impl Div<Direction> for f32

§

type Output = Vec2

The resulting type after applying the / operator.
source§

fn div(self, rhs: Direction) -> Vec2

Performs the / operation. Read more
source§

impl Div<f32> for Direction

§

type Output = Vec2

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl From<Direction> for GlobalTransform

source§

fn from(direction: Direction) -> Self

Converts to this type from the input type.
source§

impl From<Direction> for Quat

source§

fn from(direction: Direction) -> Quat

Converts to this type from the input type.
source§

impl From<Direction> for Rotation

source§

fn from(direction: Direction) -> Rotation

Converts to this type from the input type.
source§

impl From<Direction> for Transform

source§

fn from(direction: Direction) -> Self

Converts to this type from the input type.
source§

impl From<Direction> for Vec2

source§

fn from(direction: Direction) -> Vec2

Converts to this type from the input type.
source§

impl From<Direction> for Vec3

source§

fn from(direction: Direction) -> Vec3

Converts to this type from the input type.
source§

impl From<GlobalTransform> for Direction

source§

fn from(transform: GlobalTransform) -> Self

Converts to this type from the input type.
source§

impl From<Quat> for Direction

source§

fn from(quaternion: Quat) -> Self

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<Transform> for Direction

source§

fn from(transform: Transform) -> Self

Converts to this type from the input type.
source§

impl Mul<Direction> for f32

§

type Output = Vec2

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Direction) -> Vec2

Performs the * operation. Read more
source§

impl Mul<f32> for Direction

§

type Output = Vec2

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Neg for Direction

§

type Output = Direction

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl Orientation for Direction

source§

fn distance(&self, other: Direction) -> 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 Direction

source§

fn eq(&self, other: &Direction) -> 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 Sub for Direction

§

type Output = Vec2

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Direction) -> Vec2

Performs the - operation. Read more
source§

impl TryFrom<Vec2> for Direction

§

type Error = NearlySingularConversion

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

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

Performs the conversion.
source§

impl Copy for Direction

source§

impl StructuralPartialEq for Direction

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> 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<C> DynamicBundle for C
where C: Component,

§

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

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
§

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,