Struct collider::geom::Vec2
[−]
[src]
pub struct Vec2 { pub x: f64, pub y: f64, }
A 2-D Cartesian vector using finite f64
values.
Fields
x: f64
The x-coordinate.
y: f64
The y-coordinate.
Methods
impl Vec2
[src]
pub fn new(x: f64, y: f64) -> Vec2
[src]
Constructs a vector with the given x
and y
coordinates.
pub fn zero() -> Vec2
[src]
Constructs a (0, 0) vector.
pub fn len_sq(&self) -> f64
[src]
Computes the square of the Euclidean length of the vector.
Due to underflow, this might be 0.0
even if x
and y
are non-zero but very small.
pub fn len(&self) -> f64
[src]
Computes the the Euclidean length of the vector.
Due to underflow, this might be 0.0
even if x
and y
are non-zero but very small.
pub fn normalize(&self) -> Option<Vec2>
[src]
Returns a vector in the same direction as self
but with length (approximately) 1.0
,
or None
if self.len() == 0.0
.
pub fn dist_sq(&self, other: &Vec2) -> f64
[src]
Computes the square of the Euclidean distance between two vectors.
pub fn dist(&self, other: &Vec2) -> f64
[src]
Computes the Euclidean distance between two vectors.
pub fn lerp(&self, other: Vec2, ratio: f64) -> Vec2
[src]
Linearly interpolates between self
and other
.
Using ratio = 0.0
will return self
, and using ratio = 1.0
will return other
.
Can also extrapolate using ratio > 1.0
or ratio < 0.0
.
pub fn rotate(&self, angle: f64) -> Vec2
[src]
Rotates the vector by angle
radians counter-clockwise (assuming +x is right and +y is up).
Trait Implementations
impl PartialEq for Vec2
[src]
fn eq(&self, __arg_0: &Vec2) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Vec2) -> bool
[src]
This method tests for !=
.
impl Copy for Vec2
[src]
impl Clone for Vec2
[src]
fn clone(&self) -> Vec2
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Vec2
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Default for Vec2
[src]
impl Mul<Vec2> for f64
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, rhs: Vec2) -> Vec2
[src]
Performs the *
operation.
impl Mul<f64> for Vec2
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, rhs: f64) -> Vec2
[src]
Performs the *
operation.
impl MulAssign<f64> for Vec2
[src]
fn mul_assign(&mut self, rhs: f64)
[src]
Performs the *=
operation.
impl Mul<Vec2> for Vec2
[src]
type Output = f64
The resulting type after applying the *
operator.
fn mul(self, rhs: Vec2) -> f64
[src]
Performs the *
operation.
impl Add for Vec2
[src]
type Output = Vec2
The resulting type after applying the +
operator.
fn add(self, rhs: Vec2) -> Vec2
[src]
Performs the +
operation.
impl AddAssign for Vec2
[src]
fn add_assign(&mut self, rhs: Vec2)
[src]
Performs the +=
operation.
impl Sub for Vec2
[src]
type Output = Vec2
The resulting type after applying the -
operator.
fn sub(self, rhs: Vec2) -> Vec2
[src]
Performs the -
operation.
impl SubAssign for Vec2
[src]
fn sub_assign(&mut self, rhs: Vec2)
[src]
Performs the -=
operation.
impl Neg for Vec2
[src]
type Output = Vec2
The resulting type after applying the -
operator.
fn neg(self) -> Vec2
[src]
Performs the unary -
operation.