pub struct Vector2 {
pub x: f64,
pub y: f64,
}
Fields§
§x: f64
X component of the vector.
y: f64
Y component of the vector.
Implementations§
source§impl Vector2
impl Vector2
sourcepub const NEGATIVE_INFINITY: Self = _
pub const NEGATIVE_INFINITY: Self = _
Shorthand for writing Vector2::new(f64::NEG_INFINITY, f64::NEG_INFINITY)
.
sourcepub const POSITIVE_INFINITY: Self = _
pub const POSITIVE_INFINITY: Self = _
Shorthand for writing Vector2::new(f64::INFINITY, f64::INFINITY)
.
sourcepub fn sqr_magnitude(&self) -> f64
pub fn sqr_magnitude(&self) -> f64
Returns the squared length of this vector.
sourcepub fn normalized(&self) -> Self
pub fn normalized(&self) -> Self
Returns this vector with a magnitude of 1.
sourcepub fn angle(from: Self, to: Self) -> f64
pub fn angle(from: Self, to: Self) -> f64
Gets the unsigned angle in degrees between from and to.
sourcepub fn clamp_magnitude(vector: Self, max_length: f64) -> Self
pub fn clamp_magnitude(vector: Self, max_length: f64) -> Self
Returns a copy of vector with its magnitude clamped to max_length.
sourcepub fn lerp(a: Self, b: Self, t: f64) -> Self
pub fn lerp(a: Self, b: Self, t: f64) -> Self
Linearly interpolates between vectors a and b by t.
sourcepub fn lerp_unclamped(a: Self, b: Self, t: f64) -> Self
pub fn lerp_unclamped(a: Self, b: Self, t: f64) -> Self
Linearly interpolates between vectors a and b by t.
sourcepub fn max(lhs: Self, rhs: Self) -> Self
pub fn max(lhs: Self, rhs: Self) -> Self
Returns a vector that is made from the largest components of two vectors.
sourcepub fn min(lhs: Self, rhs: Self) -> Self
pub fn min(lhs: Self, rhs: Self) -> Self
Returns a vector that is made from the smallest components of two vectors.
sourcepub fn move_towards(
current: Self,
target: Self,
max_distance_delta: f64
) -> Self
pub fn move_towards( current: Self, target: Self, max_distance_delta: f64 ) -> Self
Moves a point current towards target.
sourcepub fn perpendicular(in_direction: Self) -> Self
pub fn perpendicular(in_direction: Self) -> Self
Returns the 2D vector perpendicular to this 2D vector. The result is always rotated 90-degrees in a counter-clockwise direction for a 2D coordinate system where the positive Y axis goes up.
sourcepub fn reflect(in_direction: Self, in_normal: Self) -> Self
pub fn reflect(in_direction: Self, in_normal: Self) -> Self
Reflects a vector off the vector defined by a normal.
sourcepub fn signed_angle(from: Self, to: Self) -> f64
pub fn signed_angle(from: Self, to: Self) -> f64
Gets the signed angle in degrees between from and to.
Trait Implementations§
source§impl AddAssign<Vector2> for Vector2
impl AddAssign<Vector2> for Vector2
source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+=
operation. Read moresource§impl DivAssign<f64> for Vector2
impl DivAssign<f64> for Vector2
source§fn div_assign(&mut self, other: f64)
fn div_assign(&mut self, other: f64)
/=
operation. Read moresource§impl MulAssign<f64> for Vector2
impl MulAssign<f64> for Vector2
source§fn mul_assign(&mut self, other: f64)
fn mul_assign(&mut self, other: f64)
*=
operation. Read moresource§impl PartialEq<Vector2> for Vector2
impl PartialEq<Vector2> for Vector2
source§impl SubAssign<Vector2> for Vector2
impl SubAssign<Vector2> for Vector2
source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-=
operation. Read more