Expand description
A 4-dimensional vector.
This type is 16 byte aligned unless the scalar-math
feature is enabed.
Fields
x: f32
y: f32
z: f32
w: f32
Implementations
sourceimpl Vec4
impl Vec4
sourcepub fn truncate(self) -> Vec3
pub fn truncate(self) -> Vec3
Creates a Vec3
from the x
, y
and z
elements of self
, discarding w
.
Truncation to Vec3
may also be performed by using self.xyz()
or Vec3::from()
.
To truncate to Vec3A
use Vec3A::from()
.
pub fn x(self) -> f32
please use .x
instead
pub fn y(self) -> f32
please use .y
instead
pub fn z(self) -> f32
please use .z
instead
pub fn w(self) -> f32
please use .w
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 z_mut(&mut self) -> &mut f32
please use .z
instead
pub fn w_mut(&mut self) -> &mut f32
please use .w
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
pub fn set_z(&mut self, z: f32)
please use .z
instead
pub fn set_w(&mut self, w: f32)
please use .w
instead
sourcepub fn length_squared(self) -> f32
pub fn length_squared(self) -> f32
Computes the squared 4D length of self
.
This is generally faster than Vec4::length()
as it avoids a square
root operation.
sourcepub fn length_recip(self) -> f32
pub fn length_recip(self) -> f32
Computes 1.0 / Vec4::length()
.
For valid results, self
must not be of length zero.
sourcepub fn distance(self, other: Vec4) -> f32
pub fn distance(self, other: Vec4) -> f32
Computes the Euclidean distance between two points in space.
sourcepub fn distance_squared(self, other: Vec4) -> f32
pub fn distance_squared(self, other: Vec4) -> f32
Compute the squared euclidean distance between two points in space.
sourcepub fn normalize(self) -> Vec4
pub fn normalize(self) -> Vec4
Returns self
normalized to length 1.0.
For valid results, self
must not be of length zero.
sourcepub fn min(self, other: Vec4) -> Vec4
pub fn min(self, other: Vec4) -> Vec4
Returns the vertical minimum of self
and other
.
In other words, this computes
[x: min(x1, x2), y: min(y1, y2), z: min(z1, z2), w: min(w1, w2)]
,
taking the minimum of each element individually.
sourcepub fn max(self, other: Vec4) -> Vec4
pub fn max(self, other: Vec4) -> Vec4
Returns the vertical maximum of self
and other
.
In other words, this computes
[x: max(x1, x2), y: max(y1, y2), z: max(z1, z2), w: max(w1, w2)]
,
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, z, w)
.
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, z, w)
.
sourcepub fn cmpeq(self, other: Vec4) -> Vec4Mask
pub fn cmpeq(self, other: Vec4) -> Vec4Mask
Performs a vertical ==
comparison between self
and other
,
returning a Vec4Mask
of the results.
In other words, this computes [x1 == x2, y1 == y2, z1 == z2, w1 == w2]
.
sourcepub fn cmpne(self, other: Vec4) -> Vec4Mask
pub fn cmpne(self, other: Vec4) -> Vec4Mask
Performs a vertical !=
comparison between self
and other
,
returning a Vec4Mask
of the results.
In other words, this computes [x1 != x2, y1 != y2, z1 != z2, w1 != w2]
.
sourcepub fn cmpge(self, other: Vec4) -> Vec4Mask
pub fn cmpge(self, other: Vec4) -> Vec4Mask
Performs a vertical >=
comparison between self
and other
,
returning a Vec4Mask
of the results.
In other words, this computes [x1 >= x2, y1 >= y2, z1 >= z2, w1 >= w2]
.
sourcepub fn cmpgt(self, other: Vec4) -> Vec4Mask
pub fn cmpgt(self, other: Vec4) -> Vec4Mask
Performs a vertical >
comparison between self
and other
,
returning a Vec4Mask
of the results.
In other words, this computes [x1 > x2, y1 > y2, z1 > z2, w1 > w2]
.
sourcepub fn cmple(self, other: Vec4) -> Vec4Mask
pub fn cmple(self, other: Vec4) -> Vec4Mask
Performs a vertical <=
comparison between self
and other
,
returning a Vec4Mask
of the results.
In other words, this computes [x1 <= x2, y1 <= y2, z1 <= z2, w1 <= w2]
.
sourcepub fn cmplt(self, other: Vec4) -> Vec4Mask
pub fn cmplt(self, other: Vec4) -> Vec4Mask
Performs a vertical <
comparison between self
and other
,
returning a Vec4Mask
of the results.
In other words, this computes [x1 < x2, y1 < y2, z1 < z2, w1 < w2]
.
sourcepub fn from_slice_unaligned(slice: &[f32]) -> Vec4
pub fn from_slice_unaligned(slice: &[f32]) -> Vec4
Creates a Vec4
from the first four values in slice
.
Panics
Panics if slice
is less than four 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 four elements in slice
.
Panics
Panics if slice
is less than four elements long.
sourcepub fn round(self) -> Vec4
pub fn round(self) -> Vec4
Returns a Vec4
containing the nearest integer to a number for each element of self
.
Round half-way cases away from 0.0.
sourcepub fn floor(self) -> Vec4
pub fn floor(self) -> Vec4
Returns a Vec4
containing the largest integer less than or equal to a number for each
element of self
.
sourcepub fn ceil(self) -> Vec4
pub fn ceil(self) -> Vec4
Returns a Vec4
containing the smallest integer greater than or equal to a number for each
element of self
.
sourcepub fn is_nan(self) -> Vec4Mask
pub fn is_nan(self) -> Vec4Mask
Performs is_nan
on each element of self, returning a Vec4Mask
of the results.
In other words, this computes [x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]
.
sourcepub fn signum(self) -> Vec4
pub fn signum(self) -> Vec4
Returns a Vec4
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) -> Vec4
pub fn recip(self) -> Vec4
Returns a Vec4
containing the reciprocal 1.0/n
of each element of self
.
sourcepub fn lerp(self, other: Vec4, s: f32) -> Vec4
pub fn lerp(self, other: Vec4, s: f32) -> Vec4
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: Vec4, max_abs_diff: f32) -> bool
pub fn abs_diff_eq(self, other: Vec4, 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 Vec4
’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/
Trait Implementations
sourceimpl AddAssign<Vec4> for Vec4
impl AddAssign<Vec4> for Vec4
sourcefn add_assign(&mut self, other: Vec4)
fn add_assign(&mut self, other: Vec4)
Performs the +=
operation. Read more
sourceimpl DivAssign<Vec4> for Vec4
impl DivAssign<Vec4> for Vec4
sourcefn div_assign(&mut self, other: Vec4)
fn div_assign(&mut self, other: Vec4)
Performs the /=
operation. Read more
sourceimpl DivAssign<f32> for Vec4
impl DivAssign<f32> for Vec4
sourcefn div_assign(&mut self, other: f32)
fn div_assign(&mut self, other: f32)
Performs the /=
operation. Read more
sourceimpl MulAssign<Vec4> for Vec4
impl MulAssign<Vec4> for Vec4
sourcefn mul_assign(&mut self, other: Vec4)
fn mul_assign(&mut self, other: Vec4)
Performs the *=
operation. Read more
sourceimpl MulAssign<f32> for Vec4
impl MulAssign<f32> for Vec4
sourcefn mul_assign(&mut self, other: f32)
fn mul_assign(&mut self, other: f32)
Performs the *=
operation. Read more
sourceimpl PartialEq<Vec4> for Vec4
impl PartialEq<Vec4> for Vec4
sourceimpl PartialOrd<Vec4> for Vec4
impl PartialOrd<Vec4> for Vec4
sourcefn partial_cmp(&self, other: &Vec4) -> Option<Ordering>
fn partial_cmp(&self, other: &Vec4) -> 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<Vec4> for Vec4
impl SubAssign<Vec4> for Vec4
sourcefn sub_assign(&mut self, other: Vec4)
fn sub_assign(&mut self, other: Vec4)
Performs the -=
operation. Read more
sourceimpl Vec4Swizzles for Vec4
impl Vec4Swizzles for Vec4
fn xxxx(self) -> Vec4
fn xxxy(self) -> Vec4
fn xxxz(self) -> Vec4
fn xxxw(self) -> Vec4
fn xxyx(self) -> Vec4
fn xxyy(self) -> Vec4
fn xxyz(self) -> Vec4
fn xxyw(self) -> Vec4
fn xxzx(self) -> Vec4
fn xxzy(self) -> Vec4
fn xxzz(self) -> Vec4
fn xxzw(self) -> Vec4
fn xxwx(self) -> Vec4
fn xxwy(self) -> Vec4
fn xxwz(self) -> Vec4
fn xxww(self) -> Vec4
fn xyxx(self) -> Vec4
fn xyxy(self) -> Vec4
fn xyxz(self) -> Vec4
fn xyxw(self) -> Vec4
fn xyyx(self) -> Vec4
fn xyyy(self) -> Vec4
fn xyyz(self) -> Vec4
fn xyyw(self) -> Vec4
fn xyzx(self) -> Vec4
fn xyzy(self) -> Vec4
fn xyzz(self) -> Vec4
fn xywx(self) -> Vec4
fn xywy(self) -> Vec4
fn xywz(self) -> Vec4
fn xyww(self) -> Vec4
fn xzxx(self) -> Vec4
fn xzxy(self) -> Vec4
fn xzxz(self) -> Vec4
fn xzxw(self) -> Vec4
fn xzyx(self) -> Vec4
fn xzyy(self) -> Vec4
fn xzyz(self) -> Vec4
fn xzyw(self) -> Vec4
fn xzzx(self) -> Vec4
fn xzzy(self) -> Vec4
fn xzzz(self) -> Vec4
fn xzzw(self) -> Vec4
fn xzwx(self) -> Vec4
fn xzwy(self) -> Vec4
fn xzwz(self) -> Vec4
fn xzww(self) -> Vec4
fn xwxx(self) -> Vec4
fn xwxy(self) -> Vec4
fn xwxz(self) -> Vec4
fn xwxw(self) -> Vec4
fn xwyx(self) -> Vec4
fn xwyy(self) -> Vec4
fn xwyz(self) -> Vec4
fn xwyw(self) -> Vec4
fn xwzx(self) -> Vec4
fn xwzy(self) -> Vec4
fn xwzz(self) -> Vec4
fn xwzw(self) -> Vec4
fn xwwx(self) -> Vec4
fn xwwy(self) -> Vec4
fn xwwz(self) -> Vec4
fn xwww(self) -> Vec4
fn yxxx(self) -> Vec4
fn yxxy(self) -> Vec4
fn yxxz(self) -> Vec4
fn yxxw(self) -> Vec4
fn yxyx(self) -> Vec4
fn yxyy(self) -> Vec4
fn yxyz(self) -> Vec4
fn yxyw(self) -> Vec4
fn yxzx(self) -> Vec4
fn yxzy(self) -> Vec4
fn yxzz(self) -> Vec4
fn yxzw(self) -> Vec4
fn yxwx(self) -> Vec4
fn yxwy(self) -> Vec4
fn yxwz(self) -> Vec4
fn yxww(self) -> Vec4
fn yyxx(self) -> Vec4
fn yyxy(self) -> Vec4
fn yyxz(self) -> Vec4
fn yyxw(self) -> Vec4
fn yyyx(self) -> Vec4
fn yyyy(self) -> Vec4
fn yyyz(self) -> Vec4
fn yyyw(self) -> Vec4
fn yyzx(self) -> Vec4
fn yyzy(self) -> Vec4
fn yyzz(self) -> Vec4
fn yyzw(self) -> Vec4
fn yywx(self) -> Vec4
fn yywy(self) -> Vec4
fn yywz(self) -> Vec4
fn yyww(self) -> Vec4
fn yzxx(self) -> Vec4
fn yzxy(self) -> Vec4
fn yzxz(self) -> Vec4
fn yzxw(self) -> Vec4
fn yzyx(self) -> Vec4
fn yzyy(self) -> Vec4
fn yzyz(self) -> Vec4
fn yzyw(self) -> Vec4
fn yzzx(self) -> Vec4
fn yzzy(self) -> Vec4
fn yzzz(self) -> Vec4
fn yzzw(self) -> Vec4
fn yzwx(self) -> Vec4
fn yzwy(self) -> Vec4
fn yzwz(self) -> Vec4
fn yzww(self) -> Vec4
fn ywxx(self) -> Vec4
fn ywxy(self) -> Vec4
fn ywxz(self) -> Vec4
fn ywxw(self) -> Vec4
fn ywyx(self) -> Vec4
fn ywyy(self) -> Vec4
fn ywyz(self) -> Vec4
fn ywyw(self) -> Vec4
fn ywzx(self) -> Vec4
fn ywzy(self) -> Vec4
fn ywzz(self) -> Vec4
fn ywzw(self) -> Vec4
fn ywwx(self) -> Vec4
fn ywwy(self) -> Vec4
fn ywwz(self) -> Vec4
fn ywww(self) -> Vec4
fn zxxx(self) -> Vec4
fn zxxy(self) -> Vec4
fn zxxz(self) -> Vec4
fn zxxw(self) -> Vec4
fn zxyx(self) -> Vec4
fn zxyy(self) -> Vec4
fn zxyz(self) -> Vec4
fn zxyw(self) -> Vec4
fn zxzx(self) -> Vec4
fn zxzy(self) -> Vec4
fn zxzz(self) -> Vec4
fn zxzw(self) -> Vec4
fn zxwx(self) -> Vec4
fn zxwy(self) -> Vec4
fn zxwz(self) -> Vec4
fn zxww(self) -> Vec4
fn zyxx(self) -> Vec4
fn zyxy(self) -> Vec4
fn zyxz(self) -> Vec4
fn zyxw(self) -> Vec4
fn zyyx(self) -> Vec4
fn zyyy(self) -> Vec4
fn zyyz(self) -> Vec4
fn zyyw(self) -> Vec4
fn zyzx(self) -> Vec4
fn zyzy(self) -> Vec4
fn zyzz(self) -> Vec4
fn zyzw(self) -> Vec4
fn zywx(self) -> Vec4
fn zywy(self) -> Vec4
fn zywz(self) -> Vec4
fn zyww(self) -> Vec4
fn zzxx(self) -> Vec4
fn zzxy(self) -> Vec4
fn zzxz(self) -> Vec4
fn zzxw(self) -> Vec4
fn zzyx(self) -> Vec4
fn zzyy(self) -> Vec4
fn zzyz(self) -> Vec4
fn zzyw(self) -> Vec4
fn zzzx(self) -> Vec4
fn zzzy(self) -> Vec4
fn zzzz(self) -> Vec4
fn zzzw(self) -> Vec4
fn zzwx(self) -> Vec4
fn zzwy(self) -> Vec4
fn zzwz(self) -> Vec4
fn zzww(self) -> Vec4
fn zwxx(self) -> Vec4
fn zwxy(self) -> Vec4
fn zwxz(self) -> Vec4
fn zwxw(self) -> Vec4
fn zwyx(self) -> Vec4
fn zwyy(self) -> Vec4
fn zwyz(self) -> Vec4
fn zwyw(self) -> Vec4
fn zwzx(self) -> Vec4
fn zwzy(self) -> Vec4
fn zwzz(self) -> Vec4
fn zwzw(self) -> Vec4
fn zwwx(self) -> Vec4
fn zwwy(self) -> Vec4
fn zwwz(self) -> Vec4
fn zwww(self) -> Vec4
fn wxxx(self) -> Vec4
fn wxxy(self) -> Vec4
fn wxxz(self) -> Vec4
fn wxxw(self) -> Vec4
fn wxyx(self) -> Vec4
fn wxyy(self) -> Vec4
fn wxyz(self) -> Vec4
fn wxyw(self) -> Vec4
fn wxzx(self) -> Vec4
fn wxzy(self) -> Vec4
fn wxzz(self) -> Vec4
fn wxzw(self) -> Vec4
fn wxwx(self) -> Vec4
fn wxwy(self) -> Vec4
fn wxwz(self) -> Vec4
fn wxww(self) -> Vec4
fn wyxx(self) -> Vec4
fn wyxy(self) -> Vec4
fn wyxz(self) -> Vec4
fn wyxw(self) -> Vec4
fn wyyx(self) -> Vec4
fn wyyy(self) -> Vec4
fn wyyz(self) -> Vec4
fn wyyw(self) -> Vec4
fn wyzx(self) -> Vec4
fn wyzy(self) -> Vec4
fn wyzz(self) -> Vec4
fn wyzw(self) -> Vec4
fn wywx(self) -> Vec4
fn wywy(self) -> Vec4
fn wywz(self) -> Vec4
fn wyww(self) -> Vec4
fn wzxx(self) -> Vec4
fn wzxy(self) -> Vec4
fn wzxz(self) -> Vec4
fn wzxw(self) -> Vec4
fn wzyx(self) -> Vec4
fn wzyy(self) -> Vec4
fn wzyz(self) -> Vec4
fn wzyw(self) -> Vec4
fn wzzx(self) -> Vec4
fn wzzy(self) -> Vec4
fn wzzz(self) -> Vec4
fn wzzw(self) -> Vec4
fn wzwx(self) -> Vec4
fn wzwy(self) -> Vec4
fn wzwz(self) -> Vec4
fn wzww(self) -> Vec4
fn wwxx(self) -> Vec4
fn wwxy(self) -> Vec4
fn wwxz(self) -> Vec4
fn wwxw(self) -> Vec4
fn wwyx(self) -> Vec4
fn wwyy(self) -> Vec4
fn wwyz(self) -> Vec4
fn wwyw(self) -> Vec4
fn wwzx(self) -> Vec4
fn wwzy(self) -> Vec4
fn wwzz(self) -> Vec4
fn wwzw(self) -> Vec4
fn wwwx(self) -> Vec4
fn wwwy(self) -> Vec4
fn wwwz(self) -> Vec4
fn wwww(self) -> Vec4
fn xxx(self) -> Vec3
fn xxy(self) -> Vec3
fn xxz(self) -> Vec3
fn xxw(self) -> Vec3
fn xyx(self) -> Vec3
fn xyy(self) -> Vec3
fn xyz(self) -> Vec3
fn xyw(self) -> Vec3
fn xzx(self) -> Vec3
fn xzy(self) -> Vec3
fn xzz(self) -> Vec3
fn xzw(self) -> Vec3
fn xwx(self) -> Vec3
fn xwy(self) -> Vec3
fn xwz(self) -> Vec3
fn xww(self) -> Vec3
fn yxx(self) -> Vec3
fn yxy(self) -> Vec3
fn yxz(self) -> Vec3
fn yxw(self) -> Vec3
fn yyx(self) -> Vec3
fn yyy(self) -> Vec3
fn yyz(self) -> Vec3
fn yyw(self) -> Vec3
fn yzx(self) -> Vec3
fn yzy(self) -> Vec3
fn yzz(self) -> Vec3
fn yzw(self) -> Vec3
fn ywx(self) -> Vec3
fn ywy(self) -> Vec3
fn ywz(self) -> Vec3
fn yww(self) -> Vec3
fn zxx(self) -> Vec3
fn zxy(self) -> Vec3
fn zxz(self) -> Vec3
fn zxw(self) -> Vec3
fn zyx(self) -> Vec3
fn zyy(self) -> Vec3
fn zyz(self) -> Vec3
fn zyw(self) -> Vec3
fn zzx(self) -> Vec3
fn zzy(self) -> Vec3
fn zzz(self) -> Vec3
fn zzw(self) -> Vec3
fn zwx(self) -> Vec3
fn zwy(self) -> Vec3
fn zwz(self) -> Vec3
fn zww(self) -> Vec3
fn wxx(self) -> Vec3
fn wxy(self) -> Vec3
fn wxz(self) -> Vec3
fn wxw(self) -> Vec3
fn wyx(self) -> Vec3
fn wyy(self) -> Vec3
fn wyz(self) -> Vec3
fn wyw(self) -> Vec3
fn wzx(self) -> Vec3
fn wzy(self) -> Vec3
fn wzz(self) -> Vec3
fn wzw(self) -> Vec3
fn wwx(self) -> Vec3
fn wwy(self) -> Vec3
fn wwz(self) -> Vec3
fn www(self) -> Vec3
fn xx(self) -> Vec2
fn xy(self) -> Vec2
fn xz(self) -> Vec2
fn xw(self) -> Vec2
fn yx(self) -> Vec2
fn yy(self) -> Vec2
fn yz(self) -> Vec2
fn yw(self) -> Vec2
fn zx(self) -> Vec2
fn zy(self) -> Vec2
fn zz(self) -> Vec2
fn zw(self) -> Vec2
fn wx(self) -> Vec2
fn wy(self) -> Vec2
fn wz(self) -> Vec2
fn ww(self) -> Vec2
impl Copy for Vec4
impl StructuralPartialEq for Vec4
Auto Trait Implementations
impl RefUnwindSafe for Vec4
impl Send for Vec4
impl Sync for Vec4
impl Unpin for Vec4
impl UnwindSafe for Vec4
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