pub struct Direction2d(/* private fields */);
Expand description

A normalized vector pointing in a direction in 2D space

Implementations§

source§

impl Direction2d

source

pub const X: Self = _

A unit vector pointing along the positive X axis.

source

pub const Y: Self = _

A unit vector pointing along the positive Y axis.

source

pub const NEG_X: Self = _

A unit vector pointing along the negative X axis.

source

pub const NEG_Y: Self = _

A unit vector pointing along the negative Y axis.

source

pub fn new(value: Vec2) -> Result<Self, InvalidDirectionError>

Create a direction from a finite, nonzero Vec2.

Returns Err(InvalidDirectionError) if the length of the given vector is zero (or very close to zero), infinite, or NaN.

source

pub fn new_unchecked(value: Vec2) -> Self

Create a Direction2d from a Vec2 that is already normalized.

§Warning

value must be normalized, i.e it’s length must be 1.0.

source

pub fn new_and_length(value: Vec2) -> Result<(Self, f32), InvalidDirectionError>

Create a direction from a finite, nonzero Vec2, also returning its original length.

Returns Err(InvalidDirectionError) if the length of the given vector is zero (or very close to zero), infinite, or NaN.

source

pub fn from_xy(x: f32, y: f32) -> Result<Self, InvalidDirectionError>

Create a direction from its x and y components.

Returns Err(InvalidDirectionError) if the length of the vector formed by the components is zero (or very close to zero), infinite, or NaN.

Methods from Deref<Target = Vec2>§

source

pub const ZERO: Vec2 = _

source

pub const ONE: Vec2 = _

source

pub const NEG_ONE: Vec2 = _

source

pub const MIN: Vec2 = _

source

pub const MAX: Vec2 = _

source

pub const NAN: Vec2 = _

source

pub const INFINITY: Vec2 = _

source

pub const NEG_INFINITY: Vec2 = _

source

pub const X: Vec2 = _

source

pub const Y: Vec2 = _

source

pub const NEG_X: Vec2 = _

source

pub const NEG_Y: Vec2 = _

source

pub const AXES: [Vec2; 2] = _

source

pub fn to_array(&self) -> [f32; 2]

[x, y]

source

pub fn as_dvec2(&self) -> DVec2

Casts all elements of self to f64.

source

pub fn as_i16vec2(&self) -> I16Vec2

Casts all elements of self to i16.

source

pub fn as_u16vec2(&self) -> U16Vec2

Casts all elements of self to u16.

source

pub fn as_ivec2(&self) -> IVec2

Casts all elements of self to i32.

source

pub fn as_uvec2(&self) -> UVec2

Casts all elements of self to u32.

source

pub fn as_i64vec2(&self) -> I64Vec2

Casts all elements of self to i64.

source

pub fn as_u64vec2(&self) -> U64Vec2

Casts all elements of self to u64.

Trait Implementations§

source§

impl Clone for Direction2d

source§

fn clone(&self) -> Direction2d

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 Debug for Direction2d

source§

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

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

impl Deref for Direction2d

§

type Target = Vec2

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl Neg for Direction2d

§

type Output = Direction2d

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl PartialEq for Direction2d

source§

fn eq(&self, other: &Direction2d) -> 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 TryFrom<Vec2> for Direction2d

§

type Error = InvalidDirectionError

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

fn try_from(value: Vec2) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for Direction2d

source§

impl Primitive2d for Direction2d

source§

impl StructuralPartialEq for Direction2d

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
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
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.