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)
+= 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)
*= operation. Read moreSource§impl PartialOrd for Vector2D
impl PartialOrd for Vector2D
impl StructuralPartialEq for Vector2D
Source§impl SubAssign for Vector2D
Implements in-place vector subtraction.
impl SubAssign for Vector2D
Implements in-place vector subtraction.
Source§fn sub_assign(&mut self, other: Vector2D)
fn sub_assign(&mut self, other: Vector2D)
-= operation. Read moreSource§impl Vector for Vector2D
Implements the Vector trait for Vector2D, forwarding every method to
the inherent implementation on the struct.
impl Vector for Vector2D
Implements the Vector trait for Vector2D, forwarding every method to
the inherent implementation on the struct.
Vector2D also offers 2D-specific operations that are not part of the
trait surface: perp, cross (returning f64), from_angle, angle,
angle_to, rotated, rotate, distance_to, distance_squared_to,
direction_to, scale, and normalize. These remain inherent.