#[repr(C)]pub struct Vec2 {
pub x: Float,
pub y: Float,
}Expand description
A 2D vector.
Fields§
§x: FloatX component.
y: FloatY component.
Implementations§
Source§impl Vec2
impl Vec2
Sourcepub const fn splat(value: Float) -> Self
pub const fn splat(value: Float) -> Self
Creates a vector with all components set to the same value.
Sourcepub const fn from_array(arr: [Float; 2]) -> Self
pub const fn from_array(arr: [Float; 2]) -> Self
Creates a vector from an array.
Sourcepub fn length_squared(self) -> Float
pub fn length_squared(self) -> Float
Computes the squared length (magnitude squared).
Sourcepub fn normalize(self) -> Self
pub fn normalize(self) -> Self
Returns a normalized vector (unit length).
Returns zero vector if the length is near zero.
Sourcepub fn try_normalize(self) -> Option<Self>
pub fn try_normalize(self) -> Option<Self>
Returns a normalized vector, or None if length is near zero.
Sourcepub fn distance_squared(self, other: Self) -> Float
pub fn distance_squared(self, other: Self) -> Float
Computes the squared distance to another vector.
Sourcepub fn perpendicular(self) -> Self
pub fn perpendicular(self) -> Self
Returns a vector perpendicular to this one.
Sourcepub fn cross(self, other: Self) -> Float
pub fn cross(self, other: Self) -> Float
Computes the 2D cross product (the z-component of the 3D cross product).
Sourcepub fn angle_between(self, other: Self) -> Float
pub fn angle_between(self, other: Self) -> Float
Computes the angle in radians between two vectors.
Trait Implementations§
Source§impl AddAssign for Vec2
impl AddAssign for Vec2
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+= operation. Read moreSource§impl DivAssign<f32> for Vec2
impl DivAssign<f32> for Vec2
Source§fn div_assign(&mut self, scalar: Float)
fn div_assign(&mut self, scalar: Float)
Performs the
/= operation. Read moreSource§impl MulAssign<f32> for Vec2
impl MulAssign<f32> for Vec2
Source§fn mul_assign(&mut self, scalar: Float)
fn mul_assign(&mut self, scalar: Float)
Performs the
*= operation. Read moreSource§impl SubAssign for Vec2
impl SubAssign for Vec2
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
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§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more