pub struct Vector2D { /* private fields */ }Expand description
A 2D vector with x and y components represented as f64.
Implementations§
Source§impl Vector2D
Implements methods and operator overloading for Vector2D.
impl Vector2D
Implements methods and operator overloading for Vector2D.
Sourcepub fn up() -> Vector2D
pub fn up() -> Vector2D
Returns the unit vector pointing up (0.0, -1.0).
In screen coordinates where y increases downward.
§Returns
Vector2D- The up unit vector.
Sourcepub fn from_angle(radians: f64) -> Vector2D
pub fn from_angle(radians: f64) -> Vector2D
Sourcepub fn magnitude_squared(&self) -> f64
pub fn magnitude_squared(&self) -> f64
Returns the squared magnitude of the vector.
Avoids a square root, making it faster for comparison-only use cases.
§Returns
f64- The squared magnitude of the vector.
Sourcepub fn normalized(&self) -> Vector2D
pub fn normalized(&self) -> Vector2D
Returns a normalized (unit length) copy of this vector.
Returns the zero vector if the magnitude is zero.
§Returns
Vector2D- The normalized vector.
Sourcepub fn perp(&self) -> Vector2D
pub fn perp(&self) -> Vector2D
Returns the perpendicular vector (rotated 90 degrees counter-clockwise).
§Returns
Vector2D- The perpendicular vector.
Sourcepub fn distance_to(&self, other: Vector2D) -> f64
pub fn distance_to(&self, other: Vector2D) -> f64
Sourcepub fn distance_squared_to(&self, other: Vector2D) -> f64
pub fn distance_squared_to(&self, other: Vector2D) -> f64
Sourcepub fn direction_to(&self, other: Vector2D) -> Vector2D
pub fn direction_to(&self, other: Vector2D) -> Vector2D
Trait Implementations§
Source§impl AddAssign for Vector2D
Implements in-place vector addition.
impl AddAssign for Vector2D
Implements in-place vector addition.
Source§fn add_assign(&mut self, other: Vector2D)
fn add_assign(&mut self, other: Vector2D)
Performs the
+= operation. Read moreimpl Copy for Vector2D
Source§impl Interpolable for Vector2D
Implements Interpolable for Vector2D.
impl Interpolable for Vector2D
Implements Interpolable for Vector2D.
Source§impl MulAssign<f64> for Vector2D
Implements in-place scalar multiplication.
impl MulAssign<f64> for Vector2D
Implements in-place scalar multiplication.
Source§fn mul_assign(&mut self, scalar: f64)
fn mul_assign(&mut self, scalar: f64)
Performs the
*= operation. Read moreSource§impl PartialOrd for Vector2D
impl PartialOrd for Vector2D
impl StructuralPartialEq for Vector2D
Auto Trait Implementations§
impl Freeze for Vector2D
impl RefUnwindSafe for Vector2D
impl Send for Vector2D
impl Sync for Vector2D
impl Unpin for Vector2D
impl UnsafeUnpin for Vector2D
impl UnwindSafe for Vector2D
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