Struct bevy_math::primitives::Direction2d
source · pub struct Direction2d(/* private fields */);
Expand description
A normalized vector pointing in a direction in 2D space
Implementations§
source§impl Direction2d
impl Direction2d
sourcepub fn new(value: Vec2) -> Result<Self, InvalidDirectionError>
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
.
sourcepub fn new_unchecked(value: Vec2) -> Self
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
.
sourcepub fn new_and_length(value: Vec2) -> Result<(Self, f32), InvalidDirectionError>
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
.
sourcepub fn from_xy(x: f32, y: f32) -> Result<Self, InvalidDirectionError>
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>§
pub const ZERO: Vec2 = _
pub const ONE: Vec2 = _
pub const NEG_ONE: Vec2 = _
pub const MIN: Vec2 = _
pub const MAX: Vec2 = _
pub const NAN: Vec2 = _
pub const INFINITY: Vec2 = _
pub const NEG_INFINITY: Vec2 = _
pub const X: Vec2 = _
pub const Y: Vec2 = _
pub const NEG_X: Vec2 = _
pub const NEG_Y: Vec2 = _
pub const AXES: [Vec2; 2] = _
sourcepub fn as_i16vec2(&self) -> I16Vec2
pub fn as_i16vec2(&self) -> I16Vec2
Casts all elements of self
to i16
.
sourcepub fn as_u16vec2(&self) -> U16Vec2
pub fn as_u16vec2(&self) -> U16Vec2
Casts all elements of self
to u16
.
sourcepub fn as_i64vec2(&self) -> I64Vec2
pub fn as_i64vec2(&self) -> I64Vec2
Casts all elements of self
to i64
.
sourcepub fn as_u64vec2(&self) -> U64Vec2
pub fn as_u64vec2(&self) -> U64Vec2
Casts all elements of self
to u64
.
Trait Implementations§
source§impl Clone for Direction2d
impl Clone for Direction2d
source§fn clone(&self) -> Direction2d
fn clone(&self) -> Direction2d
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Direction2d
impl Debug for Direction2d
source§impl Deref for Direction2d
impl Deref for Direction2d
source§impl<'de> Deserialize<'de> for Direction2d
impl<'de> Deserialize<'de> for Direction2d
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Neg for Direction2d
impl Neg for Direction2d
source§impl PartialEq for Direction2d
impl PartialEq for Direction2d
source§fn eq(&self, other: &Direction2d) -> bool
fn eq(&self, other: &Direction2d) -> bool
self
and other
values to be equal, and is used
by ==
.