#[repr(C)]pub struct Vector2 {
pub x: f32,
pub y: f32,
}Expand description
An owning representation of a 2-component Euclidean vector.
Like Vec2, the Vector2 object represents a Euclidean vector in
2D. Unlike the Vec2, this is an owning representation that stores the
actual content of the vector.
Fields§
§x: f32The X-component of the vector.
y: f32The Y-component of the vector.
Implementations§
source§impl Vector2
impl Vector2
sourcepub const ZERO: Vector2 = _
pub const ZERO: Vector2 = _
A constant for a Null vector, which has magnitude 0 and exists at the origin.
sourcepub const UNIT_X: Vector2 = _
pub const UNIT_X: Vector2 = _
A constant for a unit vector in the positive X-direction.
sourcepub const UNIT_Y: Vector2 = _
pub const UNIT_Y: Vector2 = _
A constant for a unit vector in the positive Y-direction.
sourcepub const NEG_UNIT_X: Vector2 = _
pub const NEG_UNIT_X: Vector2 = _
A constant for a unit vector in the negative X-direction.
sourcepub const NEG_UNIT_Y: Vector2 = _
pub const NEG_UNIT_Y: Vector2 = _
A constant for a unit vector in the negative Y-direction.
sourcepub const fn new(x: f32, y: f32) -> Self
pub const fn new(x: f32, y: f32) -> Self
Constructs this vector from an x and y coordinate.
§Parameters
x- the x-componenty- the y-component
sourcepub const fn from_array(array: &[f32; 2]) -> Self
pub const fn from_array(array: &[f32; 2]) -> Self
sourcepub const fn from_slice(slice: &[f32]) -> Result<Self, VecError>
pub const fn from_slice(slice: &[f32]) -> Result<Self, VecError>
sourcepub const unsafe fn from_slice_unchecked(slice: &[f32]) -> Self
pub const unsafe fn from_slice_unchecked(slice: &[f32]) -> Self
sourcepub fn from_vec2i(other: &Vec2i) -> Self
pub fn from_vec2i(other: &Vec2i) -> Self
sourcepub fn from_vec2u(other: &Vec2u) -> Self
pub fn from_vec2u(other: &Vec2u) -> Self
sourcepub fn as_mut_vec2(&mut self) -> &mut Vec2
pub fn as_mut_vec2(&mut self) -> &mut Vec2
Returns this vector as a mutable Vec2.
sourcepub fn as_mut_slice(&mut self) -> &mut [f32]
pub fn as_mut_slice(&mut self) -> &mut [f32]
Returns this vector as a mutable slice of f32.
Methods from Deref<Target = Vec2>§
sourcepub fn as_mut_slice(&mut self) -> &mut [f32]
pub fn as_mut_slice(&mut self) -> &mut [f32]
sourcepub fn as_mut_ptr(&mut self) -> *mut f32
pub fn as_mut_ptr(&mut self) -> *mut f32
Returns a raw pointer to f32 of the vector’s buffer.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut f32>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut f32>
Returns a mutable iterator over the vector.
sourcepub fn x_mut(&mut self) -> &mut f32
pub fn x_mut(&mut self) -> &mut f32
Returns a mutable reference to the X-coordinate of this 2-component vector.
sourcepub fn y_mut(&mut self) -> &mut f32
pub fn y_mut(&mut self) -> &mut f32
Returns a mutable reference to the Y-coordinate of this 2-component vector.
sourcepub fn square_magnitude(&self) -> f32
pub fn square_magnitude(&self) -> f32
Computes the square magnitude of this two-component vector.
sourcepub fn magnitude(&self) -> f32
pub fn magnitude(&self) -> f32
Computes the magnitude of this vector.
Where possible, consider using Vec2::square_magnitude as this will
avoid the need to compute the square-root.
sourcepub fn is_normalized(&self) -> bool
pub fn is_normalized(&self) -> bool
Queries whether this vector is normalized (e.g. has a magnitude of 1).
sourcepub fn normalized(&self) -> Vector2
pub fn normalized(&self) -> Vector2
Returns a normalized version of this vector.
sourcepub fn is_finite(&self) -> bool
pub fn is_finite(&self) -> bool
Returns whether all components of this Vec are finite.
§Example
Basic use:
let finite = Vector2::UNIT_X;
let not_finite = Vector2::new(f32::INFINITY, 3.0);
assert!(finite.is_finite());
assert!(!not_finite.is_finite());sourcepub fn is_infinite(&self) -> bool
pub fn is_infinite(&self) -> bool
sourcepub fn is_nan(&self) -> bool
pub fn is_nan(&self) -> bool
Returns whether any component of this vec are nan.
§Example
Basic use:
let not_nan = Vector2::UNIT_X;
let nan = Vector2::new(f32::NAN, 3.0);
assert!(!not_nan.is_nan());
assert!(nan.is_nan());sourcepub fn abs(&self) -> Vector2
pub fn abs(&self) -> Vector2
Computes the absolute value of self
§Example
Basic use:
let vec = Vector2::new(-3.0, 4.0);
let abs = vec.abs();
assert_eq!(abs, Vector2::new(3.0, 4.0));Trait Implementations§
source§impl AddAssign<&Vec2> for Vector2
impl AddAssign<&Vec2> for Vector2
source§fn add_assign(&mut self, rhs: &Vec2)
fn add_assign(&mut self, rhs: &Vec2)
+= operation. Read moresource§impl AddAssign<&Vector2> for Vector2
impl AddAssign<&Vector2> for Vector2
source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
+= operation. Read moresource§impl AddAssign for Vector2
impl AddAssign for Vector2
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moresource§impl BorrowMut<Vec2> for Vector2
impl BorrowMut<Vec2> for Vector2
source§fn borrow_mut(&mut self) -> &mut Vec2
fn borrow_mut(&mut self) -> &mut Vec2
source§impl DivAssign<f32> for Vector2
impl DivAssign<f32> for Vector2
source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moresource§impl From<Vector2> for Horizontal
impl From<Vector2> for Horizontal
source§impl MulAssign<f32> for Vector2
impl MulAssign<f32> for Vector2
source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moresource§impl PartialOrd for Vector2
impl PartialOrd for Vector2
source§impl RemAssign<f32> for Vector2
impl RemAssign<f32> for Vector2
source§fn rem_assign(&mut self, rhs: f32)
fn rem_assign(&mut self, rhs: f32)
%= operation. Read moresource§impl SubAssign<&Vec2> for Vector2
impl SubAssign<&Vec2> for Vector2
source§fn sub_assign(&mut self, rhs: &Vec2)
fn sub_assign(&mut self, rhs: &Vec2)
-= operation. Read moresource§impl SubAssign<&Vector2> for Vector2
impl SubAssign<&Vector2> for Vector2
source§fn sub_assign(&mut self, rhs: &Self)
fn sub_assign(&mut self, rhs: &Self)
-= operation. Read moresource§impl SubAssign for Vector2
impl SubAssign for Vector2
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreimpl Copy for Vector2
impl StructuralPartialEq for Vector2
Auto Trait Implementations§
impl Freeze for Vector2
impl RefUnwindSafe for Vector2
impl Send for Vector2
impl Sync for Vector2
impl Unpin for Vector2
impl UnwindSafe for Vector2
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)