pub struct Vec2 {
pub x: f32,
pub y: f32,
}Expand description
A set of 2 f32s representing a location or direction in the 2d plane.
Fields§
§x: f32The x component of the vector.
y: f32The y component of the vector.
Implementations§
Source§impl Vec2
impl Vec2
Sourcepub const fn new(x: f32, y: f32) -> Vec2
pub const fn new(x: f32, y: f32) -> Vec2
Creates a new Vec2 with the given x- and y-values.
It is often simpler, and preferred, to just write (x, y).into().
Sourcepub fn sq_magnitude(self) -> f32
pub fn sq_magnitude(self) -> f32
Gets the squared magnitude of the vector.
Useful for comparisons as it is faster to calculate than magnitude.
Sourcepub fn sq_dist(self, rhs: Self) -> f32
pub fn sq_dist(self, rhs: Self) -> f32
Gets the squared distance from this vector to rhs.
Useful for comparisons as it is faster to calculate than dist.
Sourcepub fn normalized(self) -> Self
pub fn normalized(self) -> Self
Normalizes the vector, making its magnitude 1.
Trait Implementations§
Source§impl<T> AddAssign<T> for Vec2
impl<T> AddAssign<T> for Vec2
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
Performs the
+= operation. Read moreSource§impl DivAssign<f32> for Vec2
impl DivAssign<f32> for Vec2
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
Performs the
/= operation. Read moreSource§impl MulAssign<f32> for Vec2
impl MulAssign<f32> for Vec2
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
Performs the
*= operation. Read moreSource§impl<T> SubAssign<T> for Vec2
impl<T> SubAssign<T> for Vec2
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
Performs the
-= operation. Read moreimpl Copy for Vec2
impl StructuralPartialEq for Vec2
Auto Trait Implementations§
impl Freeze for Vec2
impl RefUnwindSafe for Vec2
impl Send for Vec2
impl Sync for Vec2
impl Unpin for Vec2
impl UnwindSafe for Vec2
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more