[−][src]Struct glam::f32::Vec2
A 2-dimensional vector.
Implementations
impl Vec2
[src]
pub fn new(x: f32, y: f32) -> Vec2
[src]
Creates a new vector.
pub const fn unit_x() -> Vec2
[src]
Creates a vector with values [x: 1.0, y: 0.0]
.
pub const fn unit_y() -> Vec2
[src]
Creates a vector with values [x: 0.0, y: 1.0]
.
pub fn extend(self, z: f32) -> Vec3
[src]
Creates a 3D vector from self
and the given z
value.
pub const fn zero() -> Self
[src]
Creates a vector with all elements set to 0.0
.
pub const fn one() -> Self
[src]
Creates a vector with all elements set to 1.0
.
pub fn splat(v: f32) -> Self
[src]
Creates a vector with all elements set to v
.
pub fn select(mask: BVec2, if_true: Vec2, if_false: Vec2) -> Vec2
[src]
Creates a vector from the elements in if_true
and if_false
, selecting which to use
for each element of self
.
A true element in the mask uses the corresponding element from if_true
, and false
uses the element from if_false
.
pub fn dot(self, other: Self) -> f32
[src]
Computes the dot product of self
and other
.
pub fn min(self, other: Self) -> Self
[src]
Returns a vector containing the mininum values for each element of self
and other
.
In other words this computes [self.x.max(other.x), self.y.max(other.y), ..]
.
pub fn max(self, other: Self) -> Self
[src]
Returns a vector containing the maximum values for each element of self
and other
.
In other words this computes [self.x.max(other.x), self.y.max(other.y), ..]
.
pub fn min_element(self) -> f32
[src]
Returns the horizontal minimum of self
.
In other words this computes min(x, y, ..)
.
pub fn max_element(self) -> f32
[src]
Returns the horizontal maximum of self
.
In other words this computes max(x, y, ..)
.
pub fn cmpeq(self, other: Self) -> BVec2
[src]
Returns a vector mask containing the result of a ==
comparison for each element of
self
and other
.
In other words, this computes [self.x == other.x, self.y == other.y, ..]
for all
elements.
pub fn cmpne(self, other: Self) -> BVec2
[src]
Returns a vector mask containing the result of a !=
comparison for each element of
self
and other
.
In other words this computes [self.x != other.x, self.y != other.y, ..]
for all
elements.
pub fn cmpge(self, other: Self) -> BVec2
[src]
Returns a vector mask containing the result of a >=
comparison for each element of
self
and other
.
In other words this computes [self.x >= other.x, self.y >= other.y, ..]
for all
elements.
pub fn cmpgt(self, other: Self) -> BVec2
[src]
Returns a vector mask containing the result of a >
comparison for each element of
self
and other
.
In other words this computes [self.x > other.x, self.y > other.y, ..]
for all
elements.
pub fn cmple(self, other: Self) -> BVec2
[src]
Returns a vector mask containing the result of a <=
comparison for each element of
self
and other
.
In other words this computes [self.x <= other.x, self.y <= other.y, ..]
for all
elements.
pub fn cmplt(self, other: Self) -> BVec2
[src]
Returns a vector mask containing the result of a <
comparison for each element of
self
and other
.
In other words this computes [self.x < other.x, self.y < other.y, ..]
for all
elements.
pub fn from_slice_unaligned(slice: &[f32]) -> Self
[src]
Creates a vector from the first N values in slice
.
Panics
Panics if slice
is less than N elements long.
pub fn write_to_slice_unaligned(self, slice: &mut [f32])
[src]
Writes the elements of self
to the first N elements in slice
.
Panics
Panics if slice
is less than N elements long.
pub fn abs(self) -> Self
[src]
Returns a vector containing the absolute value of each element of self
.
pub fn signum(self) -> Self
[src]
Returns a vector 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
pub fn perp(self) -> Self
[src]
Returns a vector that is equal to self
rotated by 90 degrees.
pub fn perp_dot(self, other: Vec2) -> f32
[src]
The perpendicular dot product of self
and other
.
pub fn is_finite(self) -> bool
[src]
Returns true
if, and only if, all elements are finite. If any element is either
NaN
, positive or negative infinity, this will return false
.
pub fn is_nan(self) -> bool
[src]
Returns true
if any elements are NaN
.
pub fn is_nan_mask(self) -> BVec2
[src]
Performs is_nan
on each element of self, returning a vector mask of the results.
In other words, this computes [x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]
.
pub fn length(self) -> f32
[src]
Computes the length of self
.
pub fn length_squared(self) -> f32
[src]
Computes the squared length of self
.
This is faster than length()
as it avoids a square root operation.
pub fn length_recip(self) -> f32
[src]
Computes 1.0 / length()
.
For valid results, self
must not be of length zero.
pub fn distance(self, other: Self) -> f32
[src]
Computes the Euclidean distance between two points in space.
pub fn distance_squared(self, other: Self) -> f32
[src]
Compute the squared euclidean distance between two points in space.
pub fn normalize(self) -> Self
[src]
Returns self
normalized to length 1.0.
For valid results, self
must not be of length zero.
pub fn is_normalized(self) -> bool
[src]
Returns whether self
is length 1.0
or not.
Uses a precision threshold of 1e-6
.
pub fn round(self) -> Self
[src]
Returns a vector containing the nearest integer to a number for each element of self
.
Round half-way cases away from 0.0.
pub fn floor(self) -> Self
[src]
Returns a vector containing the largest integer less than or equal to a number for each
element of self
.
pub fn ceil(self) -> Self
[src]
Returns a vector containing the smallest integer greater than or equal to a number for
each element of self
.
pub fn exp(self) -> Self
[src]
Returns a vector containing e^self
(the exponential function) for each element of
self
.
pub fn powf(self, n: f32) -> Self
[src]
Returns a vector containing each element of self
raised to the power of n
.
pub fn recip(self) -> Self
[src]
Returns a vector containing the reciprocal 1.0/n
of each element of self
.
pub fn lerp(self, other: Self, s: f32) -> Self
[src]
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
.
pub fn abs_diff_eq(self, other: Self, max_abs_diff: f32) -> bool
[src]
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 vectors 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 see comparing floating point numbers.
pub fn angle_between(self, other: Self) -> f32
[src]
Returns the angle between self
and other
in radians.
The vectors do not need to be unit length, but this function does
perform a sqrt
.
pub fn as_f64(&self) -> DVec2
[src]
Casts all elements of self
to f64
.
pub fn as_i32(&self) -> IVec2
[src]
Casts all elements of self
to i32
.
pub fn as_u32(&self) -> UVec2
[src]
Casts all elements of self
to u32
.
Trait Implementations
impl Add<Vec2> for Vec2
[src]
type Output = Self
The resulting type after applying the +
operator.
pub fn add(self, other: Self) -> Self
[src]
impl AddAssign<Vec2> for Vec2
[src]
pub fn add_assign(&mut self, other: Self)
[src]
impl AsMut<[f32; 2]> for Vec2
[src]
impl AsRef<[f32; 2]> for Vec2
[src]
impl Clone for Vec2
[src]
impl Copy for Vec2
[src]
impl Debug for Vec2
[src]
impl Default for Vec2
[src]
impl Deref for Vec2
[src]
type Target = XY<f32>
The resulting type after dereferencing.
pub fn deref(&self) -> &Self::Target
[src]
impl DerefMut for Vec2
[src]
impl Display for Vec2
[src]
impl Div<Vec2> for Vec2
[src]
type Output = Self
The resulting type after applying the /
operator.
pub fn div(self, other: Vec2) -> Self
[src]
impl Div<f32> for Vec2
[src]
type Output = Self
The resulting type after applying the /
operator.
pub fn div(self, other: f32) -> Self
[src]
impl DivAssign<Vec2> for Vec2
[src]
pub fn div_assign(&mut self, other: Vec2)
[src]
impl DivAssign<f32> for Vec2
[src]
pub fn div_assign(&mut self, other: f32)
[src]
impl From<[f32; 2]> for Vec2
[src]
impl From<(f32, f32)> for Vec2
[src]
impl From<Vec3> for Vec2
[src]
impl From<Vec3A> for Vec2
[src]
impl From<Vec4> for Vec2
[src]
pub fn from(v: Vec4) -> Self
[src]
Creates a 2D vector from the x
and y
elements of self
, discarding z
and
w
.
impl Index<usize> for Vec2
[src]
type Output = f32
The returned type after indexing.
pub fn index(&self, index: usize) -> &Self::Output
[src]
impl IndexMut<usize> for Vec2
[src]
impl Mul<Vec2> for Mat2
[src]
type Output = Vec2
The resulting type after applying the *
operator.
pub fn mul(self, other: Vec2) -> Vec2
[src]
impl Mul<Vec2> for Vec2
[src]
type Output = Self
The resulting type after applying the *
operator.
pub fn mul(self, other: Vec2) -> Self
[src]
impl Mul<f32> for Vec2
[src]
type Output = Self
The resulting type after applying the *
operator.
pub fn mul(self, other: f32) -> Self
[src]
impl MulAssign<Vec2> for Vec2
[src]
pub fn mul_assign(&mut self, other: Vec2)
[src]
impl MulAssign<f32> for Vec2
[src]
pub fn mul_assign(&mut self, other: f32)
[src]
impl Neg for Vec2
[src]
impl PartialEq<Vec2> for Vec2
[src]
pub fn eq(&self, other: &Self) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Vec2> for Vec2
[src]
pub fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> Product<&'a Vec2> for Vec2
[src]
impl Sub<Vec2> for Vec2
[src]
type Output = Self
The resulting type after applying the -
operator.
pub fn sub(self, other: Vec2) -> Self
[src]
impl SubAssign<Vec2> for Vec2
[src]
pub fn sub_assign(&mut self, other: Vec2)
[src]
impl<'a> Sum<&'a Vec2> for Vec2
[src]
impl Vec2Swizzles for Vec2
[src]
type Vec3 = Vec3
type Vec4 = Vec4
pub fn xxxx(self) -> Vec4
[src]
pub fn xxxy(self) -> Vec4
[src]
pub fn xxyx(self) -> Vec4
[src]
pub fn xxyy(self) -> Vec4
[src]
pub fn xyxx(self) -> Vec4
[src]
pub fn xyxy(self) -> Vec4
[src]
pub fn xyyx(self) -> Vec4
[src]
pub fn xyyy(self) -> Vec4
[src]
pub fn yxxx(self) -> Vec4
[src]
pub fn yxxy(self) -> Vec4
[src]
pub fn yxyx(self) -> Vec4
[src]
pub fn yxyy(self) -> Vec4
[src]
pub fn yyxx(self) -> Vec4
[src]
pub fn yyxy(self) -> Vec4
[src]
pub fn yyyx(self) -> Vec4
[src]
pub fn yyyy(self) -> Vec4
[src]
pub fn xxx(self) -> Vec3
[src]
pub fn xxy(self) -> Vec3
[src]
pub fn xyx(self) -> Vec3
[src]
pub fn xyy(self) -> Vec3
[src]
pub fn yxx(self) -> Vec3
[src]
pub fn yxy(self) -> Vec3
[src]
pub fn yyx(self) -> Vec3
[src]
pub fn yyy(self) -> Vec3
[src]
pub fn xx(self) -> Self
[src]
pub fn yx(self) -> Self
[src]
pub fn yy(self) -> Self
[src]
Auto Trait Implementations
impl RefUnwindSafe for Vec2
[src]
impl Send for Vec2
[src]
impl Sync for Vec2
[src]
impl Unpin for Vec2
[src]
impl UnwindSafe for Vec2
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,