#[repr(C)]pub struct Vec2 {
pub x: f32,
pub y: f32,
}Expand description
A 2D vector with FFI-safe memory layout.
This type is guaranteed to have the same memory layout as a C struct with two consecutive f32 fields. Use this type for any 2D positions, velocities, or texture coordinates that cross FFI boundaries.
Fields§
§x: f32The x-component of the vector.
y: f32The y-component of the vector.
Implementations§
Source§impl Vec2
impl Vec2
Sourcepub fn length_squared(self) -> f32
pub fn length_squared(self) -> f32
Returns the squared length of the vector.
This is more efficient than length() when you only need to compare lengths.
Sourcepub fn normalize(self) -> Vec2
pub fn normalize(self) -> Vec2
Returns a normalized (unit length) version of this vector.
If the vector has zero length, returns the zero vector.
Sourcepub fn lerp(self, other: Vec2, t: f32) -> Vec2
pub fn lerp(self, other: Vec2, t: f32) -> Vec2
Linearly interpolates between two vectors.
When t = 0.0, returns self. When t = 1.0, returns other.
Sourcepub fn perpendicular(self) -> Vec2
pub fn perpendicular(self) -> Vec2
Returns the perpendicular vector (rotated 90 degrees counter-clockwise).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Vec2
impl<'de> Deserialize<'de> for Vec2
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Vec2, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Vec2, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Vec2
impl Serialize for Vec2
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl 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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().