#[repr(C)]
pub struct Vec4 { pub x: f32, pub y: f32, pub z: f32, pub w: f32, }
Expand description

A 4-dimensional vector.

This type is 16 byte aligned unless the scalar-math feature is enabed.

Fields

x: f32y: f32z: f32w: f32

Implementations

Creates a new Vec4.

Creates a Vec4 with all elements set to 0.0.

Creates a Vec4 with all elements set to 1.0.

Creates a Vec4 with values [x: 1.0, y: 0.0, z: 0.0, w: 0.0].

Creates a Vec4 with values [x: 0.0, y: 1.0, z: 0.0, w: 0.0].

Creates a Vec4 with values [x: 0.0, y: 0.0, z: 1.0, w: 0.0].

Creates a Vec4 with values [x: 0.0, y: 0.0, z: 0.0, w: 1.0].

Creates a Vec4 with all elements set to v.

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().

👎Deprecated since 0.10.0:

please use .x instead

👎Deprecated since 0.10.0:

please use .y instead

👎Deprecated since 0.10.0:

please use .z instead

👎Deprecated since 0.10.0:

please use .w instead

👎Deprecated since 0.10.0:

please use .x instead

👎Deprecated since 0.10.0:

please use .y instead

👎Deprecated since 0.10.0:

please use .z instead

👎Deprecated since 0.10.0:

please use .w instead

👎Deprecated since 0.10.0:

please use .x instead

👎Deprecated since 0.10.0:

please use .y instead

👎Deprecated since 0.10.0:

please use .z instead

👎Deprecated since 0.10.0:

please use .w instead

Computes the 4D dot product of self and other.

Computes the 4D length of self.

Computes the squared 4D length of self.

This is generally faster than Vec4::length() as it avoids a square root operation.

Computes 1.0 / Vec4::length().

For valid results, self must not be of length zero.

Computes the Euclidean distance between two points in space.

Compute the squared euclidean distance between two points in space.

Returns self normalized to length 1.0.

For valid results, self must not be of length zero.

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.

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.

Returns the horizontal minimum of self’s elements.

In other words, this computes min(x, y, z, w).

Returns the horizontal maximum of self’s elements.

In other words, this computes max(x, y, z, w).

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].

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].

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].

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].

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].

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].

Creates a Vec4 from the first four values in slice.

Panics

Panics if slice is less than four elements long.

Writes the elements of self to the first four elements in slice.

Panics

Panics if slice is less than four elements long.

Returns a Vec4 containing the absolute value of each element of self.

Returns a Vec4 containing the nearest integer to a number for each element of self. Round half-way cases away from 0.0.

Returns a Vec4 containing the largest integer less than or equal to a number for each element of self.

Returns a Vec4 containing the smallest integer greater than or equal to a number for each element of self.

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()].

Returns a Vec4 with elements representing the sign of self.

  • 1.0 if the number is positive, +0.0 or INFINITY
  • -1.0 if the number is negative, -0.0 or NEG_INFINITY
  • NAN if the number is NAN

Returns a Vec4 containing the reciprocal 1.0/n of each element of self.

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.

Returns whether self is length 1.0 or not.

Uses a precision threshold of 1e-6.

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

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Converts this type into a mutable reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Creates a Vec2 from the x and y elements of the Vec4, discarding z.

Creates a Vec3 from the x, y and z elements of the Vec4, discarding z.

Creates a Vec3 from the x, y and z elements of the Vec4, discarding z.

On architectures where SIMD is supported such as SSE2 on x86_64 this conversion is a noop.

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.