Expand description
A 2-dimensional vector.
Fields
x: f32
y: f32
Implementations
sourceimpl Vec2
impl Vec2
sourcepub fn is_nan(self) -> Vec2Mask
pub fn is_nan(self) -> Vec2Mask
Performs is_nan
on each element of self, returning a Vec2Mask
of the results.
In other words, this computes [x.is_nan(), y.is_nan()]
.
sourcepub fn signum(self) -> Vec2
pub fn signum(self) -> Vec2
Returns a Vec2
with elements representing the sign of self
.
1.0
if the number is positive,+0.0
orINFINITY
-1.0
if the number is negative,-0.0
orNEG_INFINITY
NAN
if the number isNAN
sourcepub fn recip(self) -> Vec2
pub fn recip(self) -> Vec2
Returns a Vec2
containing the reciprocal 1.0/n
of each element of self
.
sourcepub fn lerp(self, other: Vec2, s: f32) -> Vec2
pub fn lerp(self, other: Vec2, s: f32) -> Vec2
Performs a linear interpolation between self
and other
based on
the value s
.
When s
is 0.0
, the result will be equal to self
. When s
is 1.0
, the result will be equal to other
.
sourcepub fn is_normalized(self) -> bool
pub fn is_normalized(self) -> bool
Returns whether self
is length 1.0
or not.
Uses a precision threshold of 1e-6
.
sourcepub fn abs_diff_eq(self, other: Vec2, max_abs_diff: f32) -> bool
pub fn abs_diff_eq(self, other: Vec2, max_abs_diff: f32) -> bool
Returns true if the absolute difference of all elements between self
and other
is less than or equal to max_abs_diff
.
This can be used to compare if two Vec2
’s contain similar elements. It
works best when comparing with a known value. The max_abs_diff
that
should be used used depends on the values being compared against.
For more on floating point comparisons see https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
pub fn x(self) -> f32
please use .x
instead
pub fn y(self) -> f32
please use .y
instead
pub fn x_mut(&mut self) -> &mut f32
please use .x
instead
pub fn y_mut(&mut self) -> &mut f32
please use .y
instead
pub fn set_x(&mut self, x: f32)
please use .x
instead
pub fn set_y(&mut self, y: f32)
please use .y
instead
sourcepub fn length_squared(self) -> f32
pub fn length_squared(self) -> f32
Computes the squared length of self
.
This is generally faster than Vec2::length()
as it avoids a square
root operation.
sourcepub fn length_recip(self) -> f32
pub fn length_recip(self) -> f32
Computes 1.0 / Vec2::length()
.
For valid results, self
must not be of length zero.
sourcepub fn distance_squared(self, other: Vec2) -> f32
pub fn distance_squared(self, other: Vec2) -> f32
Compute the squared Euclidean distance between two points.
sourcepub fn normalize(self) -> Vec2
pub fn normalize(self) -> Vec2
Returns self
normalized to length 1.0.
For valid results, self
must not be of length zero.
sourcepub fn min(self, other: Vec2) -> Vec2
pub fn min(self, other: Vec2) -> Vec2
Returns the vertical minimum of self
and other
.
In other words, this computes
[x: min(x1, x2), y: min(y1, y2)]
,
taking the minimum of each element individually.
sourcepub fn max(self, other: Vec2) -> Vec2
pub fn max(self, other: Vec2) -> Vec2
Returns the vertical maximum of self
and other
.
In other words, this computes
[x: max(x1, x2), y: max(y1, y2)]
,
taking the maximum of each element individually.
sourcepub fn min_element(self) -> f32
pub fn min_element(self) -> f32
Returns the horizontal minimum of self
’s elements.
In other words, this computes min(x, y)
.
sourcepub fn max_element(self) -> f32
pub fn max_element(self) -> f32
Returns the horizontal maximum of self
’s elements.
In other words, this computes max(x, y)
.
sourcepub fn cmpeq(self, other: Vec2) -> Vec2Mask
pub fn cmpeq(self, other: Vec2) -> Vec2Mask
Performs a vertical ==
comparison between self
and other
,
returning a Vec2Mask
of the results.
In other words, this computes [x1 == x2, y1 == y2]
.
sourcepub fn cmpne(self, other: Vec2) -> Vec2Mask
pub fn cmpne(self, other: Vec2) -> Vec2Mask
Performs a vertical !=
comparison between self
and other
,
returning a Vec2Mask
of the results.
In other words, this computes [x1 != x2, y1 != y2]
.
sourcepub fn cmpge(self, other: Vec2) -> Vec2Mask
pub fn cmpge(self, other: Vec2) -> Vec2Mask
Performs a vertical >=
comparison between self
and other
,
returning a Vec2Mask
of the results.
In other words, this computes [x1 >= x2, y1 >= y2]
.
sourcepub fn cmpgt(self, other: Vec2) -> Vec2Mask
pub fn cmpgt(self, other: Vec2) -> Vec2Mask
Performs a vertical >
comparison between self
and other
,
returning a Vec2Mask
of the results.
In other words, this computes [x1 > x2, y1 > y2]
.
sourcepub fn cmple(self, other: Vec2) -> Vec2Mask
pub fn cmple(self, other: Vec2) -> Vec2Mask
Performs a vertical <=
comparison between self
and other
,
returning a Vec2Mask
of the results.
In other words, this computes [x1 <= x2, y1 <= y2]
.
sourcepub fn cmplt(self, other: Vec2) -> Vec2Mask
pub fn cmplt(self, other: Vec2) -> Vec2Mask
Performs a vertical <
comparison between self
and other
,
returning a Vec2Mask
of the results.
In other words, this computes [x1 < x2, y1 < y2]
.
sourcepub fn from_slice_unaligned(slice: &[f32]) -> Vec2
pub fn from_slice_unaligned(slice: &[f32]) -> Vec2
Creates a Vec2
from the first two values in slice
.
Panics
Panics if slice
is less than two elements long.
sourcepub fn write_to_slice_unaligned(self, slice: &mut [f32])
pub fn write_to_slice_unaligned(self, slice: &mut [f32])
Writes the elements of self
to the first two elements in slice
.
Panics
Panics if slice
is less than two elements long.
sourcepub fn round(self) -> Vec2
pub fn round(self) -> Vec2
Returns a Vec2
containing the nearest integer to a number for each element of self
.
Round half-way cases away from 0.0.
sourcepub fn floor(self) -> Vec2
pub fn floor(self) -> Vec2
Returns a Vec2
containing the largest integer less than or equal to a number for each
element of self
.
sourcepub fn ceil(self) -> Vec2
pub fn ceil(self) -> Vec2
Returns a Vec2
containing the smallest integer greater than or equal to a number for each
element of self
.
sourcepub fn perp_dot(self, other: Vec2) -> f32
pub fn perp_dot(self, other: Vec2) -> f32
The perpendicular dot product of the vector and other
.
sourcepub fn angle_between(self, other: Vec2) -> f32
pub fn angle_between(self, other: Vec2) -> f32
Returns the angle between two vectors, in radians.
The vectors do not need to be unit length, but this function does
perform a sqrt
.
Trait Implementations
sourceimpl AddAssign<Vec2> for Vec2
impl AddAssign<Vec2> for Vec2
sourcefn add_assign(&mut self, other: Vec2)
fn add_assign(&mut self, other: Vec2)
Performs the +=
operation. Read more
sourceimpl DivAssign<Vec2> for Vec2
impl DivAssign<Vec2> for Vec2
sourcefn div_assign(&mut self, other: Vec2)
fn div_assign(&mut self, other: Vec2)
Performs the /=
operation. Read more
sourceimpl DivAssign<f32> for Vec2
impl DivAssign<f32> for Vec2
sourcefn div_assign(&mut self, other: f32)
fn div_assign(&mut self, other: f32)
Performs the /=
operation. Read more
sourceimpl MulAssign<Vec2> for Vec2
impl MulAssign<Vec2> for Vec2
sourcefn mul_assign(&mut self, other: Vec2)
fn mul_assign(&mut self, other: Vec2)
Performs the *=
operation. Read more
sourceimpl MulAssign<f32> for Vec2
impl MulAssign<f32> for Vec2
sourcefn mul_assign(&mut self, other: f32)
fn mul_assign(&mut self, other: f32)
Performs the *=
operation. Read more
sourceimpl PartialEq<Vec2> for Vec2
impl PartialEq<Vec2> for Vec2
sourceimpl PartialOrd<Vec2> for Vec2
impl PartialOrd<Vec2> for Vec2
sourcefn partial_cmp(&self, other: &Vec2) -> Option<Ordering>
fn partial_cmp(&self, other: &Vec2) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl SubAssign<Vec2> for Vec2
impl SubAssign<Vec2> for Vec2
sourcefn sub_assign(&mut self, other: Vec2)
fn sub_assign(&mut self, other: Vec2)
Performs the -=
operation. Read more
sourceimpl Vec2Swizzles for Vec2
impl Vec2Swizzles for Vec2
fn xxxx(self) -> Vec4
fn xxxy(self) -> Vec4
fn xxyx(self) -> Vec4
fn xxyy(self) -> Vec4
fn xyxx(self) -> Vec4
fn xyxy(self) -> Vec4
fn xyyx(self) -> Vec4
fn xyyy(self) -> Vec4
fn yxxx(self) -> Vec4
fn yxxy(self) -> Vec4
fn yxyx(self) -> Vec4
fn yxyy(self) -> Vec4
fn yyxx(self) -> Vec4
fn yyxy(self) -> Vec4
fn yyyx(self) -> Vec4
fn yyyy(self) -> Vec4
fn xxx(self) -> Vec3
fn xxy(self) -> Vec3
fn xyx(self) -> Vec3
fn xyy(self) -> Vec3
fn yxx(self) -> Vec3
fn yxy(self) -> Vec3
fn yyx(self) -> Vec3
fn yyy(self) -> Vec3
fn xx(self) -> Vec2
fn yx(self) -> Vec2
fn yy(self) -> Vec2
impl Copy for Vec2
impl StructuralPartialEq for Vec2
Auto Trait Implementations
impl RefUnwindSafe for Vec2
impl Send for Vec2
impl Sync for Vec2
impl Unpin for Vec2
impl UnwindSafe for Vec2
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more