#[repr(C)]pub struct Vector {
pub x: f32,
pub y: f32,
}
Expand description
A 2D vector.
Fields§
§x: f32
The x coordinate.
y: f32
The y coordinate.
Implementations§
Source§impl Vector
impl Vector
Sourcepub fn from_angle(angle: f32) -> Self
pub fn from_angle(angle: f32) -> Self
Create a new vector from an angle.
let x = std::f32::consts::FRAC_PI_3;
let v = Vector::from_angle(x);
assert_eq!(v.x, x.cos());
assert_eq!(v.y, x.sin());
Sourcepub fn clamp(self, min: Self, max: Self) -> Self
pub fn clamp(self, min: Self, max: Self) -> Self
Clamp self to the range [min, max] by element.
Sourcepub fn length_squared(self) -> f32
pub fn length_squared(self) -> f32
Get the length of the vector squared.
Sourcepub fn normalize(self) -> Self
pub fn normalize(self) -> Self
Normalize the vector.
If the length of the vector is zero, the zero vector is returned.
Sourcepub fn angle_between(self, other: Self) -> f32
pub fn angle_between(self, other: Self) -> f32
Get the angle between self and other.
Trait Implementations§
Source§impl AddAssign<Vector> for Point
impl AddAssign<Vector> for Point
Source§fn add_assign(&mut self, rhs: Vector)
fn add_assign(&mut self, rhs: Vector)
Performs the
+=
operation. Read moreSource§impl AddAssign<Vector> for Rect
impl AddAssign<Vector> for Rect
Source§fn add_assign(&mut self, rhs: Vector)
fn add_assign(&mut self, rhs: Vector)
Performs the
+=
operation. Read moreSource§impl AddAssign<Vector> for Size
impl AddAssign<Vector> for Size
Source§fn add_assign(&mut self, rhs: Vector)
fn add_assign(&mut self, rhs: Vector)
Performs the
+=
operation. Read moreSource§impl AddAssign<f32> for Vector
impl AddAssign<f32> for Vector
Source§fn add_assign(&mut self, rhs: f32)
fn add_assign(&mut self, rhs: f32)
Performs the
+=
operation. Read moreSource§impl AddAssign for Vector
impl AddAssign for Vector
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+=
operation. Read moreSource§impl DivAssign<Vector> for Point
impl DivAssign<Vector> for Point
Source§fn div_assign(&mut self, rhs: Vector)
fn div_assign(&mut self, rhs: Vector)
Performs the
/=
operation. Read moreSource§impl DivAssign<Vector> for Size
impl DivAssign<Vector> for Size
Source§fn div_assign(&mut self, rhs: Vector)
fn div_assign(&mut self, rhs: Vector)
Performs the
/=
operation. Read moreSource§impl DivAssign<f32> for Vector
impl DivAssign<f32> for Vector
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
Performs the
/=
operation. Read moreSource§impl DivAssign for Vector
impl DivAssign for Vector
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
Performs the
/=
operation. Read moreSource§impl MulAssign<Vector> for Point
impl MulAssign<Vector> for Point
Source§fn mul_assign(&mut self, rhs: Vector)
fn mul_assign(&mut self, rhs: Vector)
Performs the
*=
operation. Read moreSource§impl MulAssign<Vector> for Size
impl MulAssign<Vector> for Size
Source§fn mul_assign(&mut self, rhs: Vector)
fn mul_assign(&mut self, rhs: Vector)
Performs the
*=
operation. Read moreSource§impl MulAssign<f32> for Vector
impl MulAssign<f32> for Vector
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
Performs the
*=
operation. Read moreSource§impl MulAssign for Vector
impl MulAssign for Vector
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*=
operation. Read moreSource§impl RemAssign<Vector> for Point
impl RemAssign<Vector> for Point
Source§fn rem_assign(&mut self, rhs: Vector)
fn rem_assign(&mut self, rhs: Vector)
Performs the
%=
operation. Read moreSource§impl RemAssign<Vector> for Size
impl RemAssign<Vector> for Size
Source§fn rem_assign(&mut self, rhs: Vector)
fn rem_assign(&mut self, rhs: Vector)
Performs the
%=
operation. Read moreSource§impl RemAssign<f32> for Vector
impl RemAssign<f32> for Vector
Source§fn rem_assign(&mut self, rhs: f32)
fn rem_assign(&mut self, rhs: f32)
Performs the
%=
operation. Read moreSource§impl RemAssign for Vector
impl RemAssign for Vector
Source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
Performs the
%=
operation. Read moreSource§impl SubAssign<Vector> for Point
impl SubAssign<Vector> for Point
Source§fn sub_assign(&mut self, rhs: Vector)
fn sub_assign(&mut self, rhs: Vector)
Performs the
-=
operation. Read moreSource§impl SubAssign<Vector> for Rect
impl SubAssign<Vector> for Rect
Source§fn sub_assign(&mut self, rhs: Vector)
fn sub_assign(&mut self, rhs: Vector)
Performs the
-=
operation. Read moreSource§impl SubAssign<Vector> for Size
impl SubAssign<Vector> for Size
Source§fn sub_assign(&mut self, rhs: Vector)
fn sub_assign(&mut self, rhs: Vector)
Performs the
-=
operation. Read moreSource§impl SubAssign<f32> for Vector
impl SubAssign<f32> for Vector
Source§fn sub_assign(&mut self, rhs: f32)
fn sub_assign(&mut self, rhs: f32)
Performs the
-=
operation. Read moreSource§impl SubAssign for Vector
impl SubAssign for Vector
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-=
operation. Read moreimpl Copy for Vector
impl StructuralPartialEq for Vector
Auto Trait Implementations§
impl Freeze for Vector
impl RefUnwindSafe for Vector
impl Send for Vector
impl Sync for Vector
impl Unpin for Vector
impl UnwindSafe for Vector
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