# Struct mafs::Fvec4

``#[repr(C)]pub struct Fvec4 { /* private fields */ }``
Expand description

4D vector with single precision

The components are laid out in this order: `[x, y, z, w]`. This struct is aligned to 16 bytes.

### Examples

``````use mafs::{Vec4, Fvec4};

// Construction
let a = Fvec4::new(2.0, 3.0, 5.0, 6.0);
let b = Fvec4::new(6.0, 9.0, 2.5, 3.0);
let c = Fvec4::splat(0.0); // Set all four components to the same value

let p = Fvec4::point(1.0, 2.0, 3.0);
assert_eq!(p[3], 1.0); // Fourth component of a point is one

let d = Fvec4::direction(1.0, 2.0, 3.0);
assert_eq!(d[3], 0.0); // Fourth component of a direction is zero

// Arithmetics
assert_eq!(a + b, Fvec4::new(8.0, 12.0, 7.5, 9.0));
assert_eq!(a - b, Fvec4::new(-4.0, -6.0, 2.5, 3.0));
assert_eq!(a * b, Fvec4::new(12.0, 27.0, 12.5, 18.0));
assert_eq!(b / a, Fvec4::new(3.0, 3.0, 0.5, 0.5));

// Euclidian norm
assert_eq!(a.norm(), 74.0f32.sqrt());
assert_eq!(a.normalize().norm(), 0.99999994); // hmmmm

// Specialized operations
assert_eq!(a.dot(b), 69.5);
assert_eq!(b.dot(a), a.dot(b));
assert_eq!(a.cross(b), Fvec4::new(-37.5, 25.0, 0.0, 0.0));
assert_eq!(b.cross(a), -a.cross(b));
assert_eq!(Fvec4::new(-0.5, 0.5, 2.9, 0.0).floor(), Fvec4::new(-1.0, 0.0, 2.0, 0.0));

// Comparisons
assert_eq!(a.min_componentwise(b), Fvec4::new(2.0, 3.0, 2.5, 3.0));
assert_eq!(a.max_componentwise(b), Fvec4::new(6.0, 9.0, 5.0, 6.0));

// Reduction
assert_eq!(a.min_reduce(), 2.0);
assert_eq!(b.max_reduce(), 9.0);``````

## Trait Implementations§

source§

§

#### type Output = Fvec4

The resulting type after applying the `+` operator.
source§

#### fn add(self, rhs: Fvec4) -> Fvec4

Performs the `+` operation. Read more
source§

§

#### type Output = Fvec4

The resulting type after applying the `+` operator.
source§

#### fn add(self, rhs: f32) -> Fvec4

Performs the `+` operation. Read more
source§

source§

#### fn add_assign(&mut self, rhs: Fvec4)

Performs the `+=` operation. Read more
source§

source§

#### fn add_assign(&mut self, rhs: f32)

Performs the `+=` operation. Read more
source§

### impl Clone for Fvec4

source§

#### fn clone(&self) -> Fvec4

Returns a copy of the value. Read more
1.0.0 · source§

#### fn clone_from(&mut self, source: &Self)

Performs copy-assignment from `source`. Read more
source§

### impl Debug for Fvec4

source§

#### fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

### impl Default for Fvec4

source§

#### fn default() -> Fvec4

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

### impl Div<Fvec4> for Fvec4

§

#### type Output = Fvec4

The resulting type after applying the `/` operator.
source§

#### fn div(self, rhs: Fvec4) -> Fvec4

Performs the `/` operation. Read more
source§

### impl Div<f32> for Fvec4

§

#### type Output = Fvec4

The resulting type after applying the `/` operator.
source§

#### fn div(self, rhs: f32) -> Fvec4

Performs the `/` operation. Read more
source§

### impl DivAssign<Fvec4> for Fvec4

source§

#### fn div_assign(&mut self, rhs: Fvec4)

Performs the `/=` operation. Read more
source§

### impl DivAssign<f32> for Fvec4

source§

#### fn div_assign(&mut self, rhs: f32)

Performs the `/=` operation. Read more
source§

### impl Index<usize> for Fvec4

§

#### type Output = f32

The returned type after indexing.
source§

#### fn index(&self, idx: usize) -> &f32

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

### impl IndexMut<usize> for Fvec4

source§

#### fn index_mut(&mut self, idx: usize) -> &mut f32

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

### impl Mat4<f32, Fvec4> for Fmat4

source§

#### fn from_columns(x: Fvec4, y: Fvec4, z: Fvec4, w: Fvec4) -> Fmat4

Create a new 4x4 matrix from its four columns.
source§

#### fn as_array(&self) -> &[Fvec4; 4]

Convert to an array. Can also use the indexing operator `[]`.
source§

#### fn as_mut_array(&mut self) -> &mut [Fvec4; 4]

Convert to a mutable array. Can also use the indexing operator `[]`.
source§

#### fn mul_vector(&self, rhs: Fvec4) -> Fvec4

Multiply this matrix with a vector. Can also use the `*` operator.
source§

Transpose.
source§

#### fn splat(value: S) -> Self

Create a new 4x4 matrix with all equal components.
source§

#### fn from_rows(r0: [S; 4], r1: [S; 4], r2: [S; 4], r3: [S; 4]) -> Self

Create a new 4x4 matrix from its four rows
source§

Identity matrix.
source§

#### fn add_componentwise(&self, rhs: Self) -> Self

Add component by component. Can also use the `+` operator.
source§

#### fn sub_componentwise(&self, rhs: Self) -> Self

Subtract component by component. Can also use the `-` operator.
source§

#### fn mul_matrix(&self, rhs: Self) -> Self

Multiply this matrix with another matrix. Can also use the `*` operator.
source§

#### fn inverse_se3(&self) -> Self

Assume that this matrix is a rotation+translation matrix and computes its inverse. If this matrix is not a rotation+translation, the result will be nonsense.
source§

### impl Mul<Fvec4> for Fmat4

§

#### type Output = Fvec4

The resulting type after applying the `*` operator.
source§

#### fn mul(self, rhs: Fvec4) -> Fvec4

Performs the `*` operation. Read more
source§

### impl Mul<Fvec4> for Fvec4

§

#### type Output = Fvec4

The resulting type after applying the `*` operator.
source§

#### fn mul(self, rhs: Fvec4) -> Fvec4

Performs the `*` operation. Read more
source§

### impl Mul<f32> for Fvec4

§

#### type Output = Fvec4

The resulting type after applying the `*` operator.
source§

#### fn mul(self, rhs: f32) -> Fvec4

Performs the `*` operation. Read more
source§

### impl MulAssign<Fvec4> for Fvec4

source§

#### fn mul_assign(&mut self, rhs: Fvec4)

Performs the `*=` operation. Read more
source§

### impl MulAssign<f32> for Fvec4

source§

#### fn mul_assign(&mut self, rhs: f32)

Performs the `*=` operation. Read more
source§

### impl Neg for Fvec4

§

#### type Output = Fvec4

The resulting type after applying the `-` operator.
source§

#### fn neg(self) -> Fvec4

Performs the unary `-` operation. Read more
source§

### impl PartialEq<Fvec4> for Fvec4

source§

#### fn eq(&self, rhs: &Fvec4) -> bool

This method tests for `self` and `other` values to be equal, and is used by `==`.
1.0.0 · source§

#### fn ne(&self, other: &Rhs) -> bool

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

### impl Sub<Fvec4> for Fvec4

§

#### type Output = Fvec4

The resulting type after applying the `-` operator.
source§

#### fn sub(self, rhs: Fvec4) -> Fvec4

Performs the `-` operation. Read more
source§

### impl Sub<f32> for Fvec4

§

#### type Output = Fvec4

The resulting type after applying the `-` operator.
source§

#### fn sub(self, rhs: f32) -> Fvec4

Performs the `-` operation. Read more
source§

### impl SubAssign<Fvec4> for Fvec4

source§

#### fn sub_assign(&mut self, rhs: Fvec4)

Performs the `-=` operation. Read more
source§

### impl SubAssign<f32> for Fvec4

source§

#### fn sub_assign(&mut self, rhs: f32)

Performs the `-=` operation. Read more
source§

### impl Vec4<f32> for Fvec4

source§

#### fn new(x: f32, y: f32, z: f32, w: f32) -> Fvec4

Create a new two-dimensional vector.
source§

#### fn as_array(&self) -> &[f32; 4]

Convert to an array. Can also use the indexing operator `[]`.
source§

#### fn as_mut_array(&mut self) -> &mut [f32; 4]

Convert to a mutable array. Can also use the indexing operator`[]`.
source§

#### fn add_componentwise(&self, rhs: Fvec4) -> Fvec4

Add component by component. Can also use the `+` operator.
source§

#### fn sub_componentwise(&self, rhs: Fvec4) -> Fvec4

Subtract component by component. Can also use the `-` operator.
source§

#### fn mul_componentwise(&self, rhs: Fvec4) -> Fvec4

Multiply component by component. Can also use the `*` operator.
source§

#### fn div_componentwise(&self, rhs: Fvec4) -> Fvec4

Divide component by component. Can also use the `/` operator.
source§

#### fn min_componentwise(&self, rhs: Fvec4) -> Fvec4

For each lane, select the smallest component of the two.
source§

#### fn max_componentwise(&self, rhs: Fvec4) -> Fvec4

For each lane, select the largest component of the two.
source§

#### fn floor(&self) -> Fvec4

Round down all components to an integer value.
source§

#### fn min_reduce(&self) -> f32

Smallest of the four components.
source§

#### fn max_reduce(&self) -> f32

Largest of the four components.
source§

#### fn eq_reduce(&self, rhs: Fvec4) -> bool

Equality of a vector to another on all components.
source§

Dot product.
source§

#### fn cross(&self, rhs: Fvec4) -> Self

Cross product. The fourth component of the operands is ignored and the fourth component of the result will be zero.
source§

#### fn splat(value: S) -> Self

Create a two-dimensional vector with all equal components.
source§

#### fn norm(&self) -> S

Norm of this vector.
source§

#### fn normalize(&self) -> Self

Divide by the norm to obain a normalized vector.
source§

#### fn point(x: S, y: S, z: S) -> Self

Create a point in 3D space, i.e. the fourth component is 1.
source§

#### fn direction(x: S, y: S, z: S) -> Self

Create a direction in 3D space, i.e. the fourth component is 0.
source§

§

§

§

§

§

## Blanket Implementations§

source§

### impl<T> Any for Twhere T: 'static + ?Sized,

source§

#### fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more
source§

### impl<T> Borrow<T> for Twhere T: ?Sized,

source§

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

### impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

#### fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

### impl<T> From<T> for T

source§

#### fn from(t: T) -> T

Returns the argument unchanged.

source§

### impl<T, U> Into<U> for Twhere U: From<T>,

source§

#### fn into(self) -> U

Calls `U::from(self)`.

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

source§

### impl<T> ToOwned for Twhere T: Clone,

§

#### type Owned = T

The resulting type after obtaining ownership.
source§

#### fn to_owned(&self) -> T

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

#### fn clone_into(&self, target: &mut T)

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

### impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

#### type Error = Infallible

The type returned in the event of a conversion error.
source§

#### fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

### impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

#### type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

#### fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.