#[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§impl AddAssign<Fvec4> for Fvec4
impl AddAssign<Fvec4> for Fvec4
source§fn add_assign(&mut self, rhs: Fvec4)
fn add_assign(&mut self, rhs: Fvec4)
Performs the
+=
operation. Read moresource§impl AddAssign<f32> for Fvec4
impl AddAssign<f32> for Fvec4
source§fn add_assign(&mut self, rhs: f32)
fn add_assign(&mut self, rhs: f32)
Performs the
+=
operation. Read moresource§impl DivAssign<Fvec4> for Fvec4
impl DivAssign<Fvec4> for Fvec4
source§fn div_assign(&mut self, rhs: Fvec4)
fn div_assign(&mut self, rhs: Fvec4)
Performs the
/=
operation. Read moresource§impl DivAssign<f32> for Fvec4
impl DivAssign<f32> for Fvec4
source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
Performs the
/=
operation. Read moresource§impl Mat4<f32, Fvec4> for Fmat4
impl Mat4<f32, Fvec4> for Fmat4
source§fn from_columns(x: Fvec4, y: Fvec4, z: Fvec4, w: Fvec4) -> Fmat4
fn from_columns(x: Fvec4, y: Fvec4, z: Fvec4, w: Fvec4) -> Fmat4
Create a new 4x4 matrix from its four columns.
source§fn as_mut_array(&mut self) -> &mut [Fvec4; 4]
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
fn mul_vector(&self, rhs: Fvec4) -> Fvec4
Multiply this matrix with a vector.
Can also use the
*
operator.source§fn from_rows(r0: [S; 4], r1: [S; 4], r2: [S; 4], r3: [S; 4]) -> Self
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§fn add_componentwise(&self, rhs: Self) -> Self
fn add_componentwise(&self, rhs: Self) -> Self
Add component by component.
Can also use the
+
operator.source§fn sub_componentwise(&self, rhs: Self) -> Self
fn sub_componentwise(&self, rhs: Self) -> Self
Subtract component by component.
Can also use the
-
operator.source§fn mul_matrix(&self, rhs: Self) -> Self
fn mul_matrix(&self, rhs: Self) -> Self
Multiply this matrix with another matrix.
Can also use the
*
operator.source§fn inverse_se3(&self) -> Self
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 MulAssign<Fvec4> for Fvec4
impl MulAssign<Fvec4> for Fvec4
source§fn mul_assign(&mut self, rhs: Fvec4)
fn mul_assign(&mut self, rhs: Fvec4)
Performs the
*=
operation. Read moresource§impl MulAssign<f32> for Fvec4
impl MulAssign<f32> for Fvec4
source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
Performs the
*=
operation. Read moresource§impl SubAssign<Fvec4> for Fvec4
impl SubAssign<Fvec4> for Fvec4
source§fn sub_assign(&mut self, rhs: Fvec4)
fn sub_assign(&mut self, rhs: Fvec4)
Performs the
-=
operation. Read moresource§impl SubAssign<f32> for Fvec4
impl SubAssign<f32> for Fvec4
source§fn sub_assign(&mut self, rhs: f32)
fn sub_assign(&mut self, rhs: f32)
Performs the
-=
operation. Read moresource§impl Vec4<f32> for Fvec4
impl Vec4<f32> for Fvec4
source§fn as_mut_array(&mut self) -> &mut [f32; 4]
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
fn add_componentwise(&self, rhs: Fvec4) -> Fvec4
Add component by component.
Can also use the
+
operator.source§fn sub_componentwise(&self, rhs: Fvec4) -> Fvec4
fn sub_componentwise(&self, rhs: Fvec4) -> Fvec4
Subtract component by component.
Can also use the
-
operator.source§fn mul_componentwise(&self, rhs: Fvec4) -> Fvec4
fn mul_componentwise(&self, rhs: Fvec4) -> Fvec4
Multiply component by component.
Can also use the
*
operator.source§fn div_componentwise(&self, rhs: Fvec4) -> Fvec4
fn div_componentwise(&self, rhs: Fvec4) -> Fvec4
Divide component by component.
Can also use the
/
operator.source§fn min_componentwise(&self, rhs: Fvec4) -> Fvec4
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
fn max_componentwise(&self, rhs: Fvec4) -> Fvec4
For each lane, select the largest component of the two.
source§fn min_reduce(&self) -> f32
fn min_reduce(&self) -> f32
Smallest of the four components.
source§fn max_reduce(&self) -> f32
fn max_reduce(&self) -> f32
Largest of the four components.
source§fn cross(&self, rhs: Fvec4) -> Self
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.
impl Copy for Fvec4
Auto Trait Implementations§
impl RefUnwindSafe for Fvec4
impl Send for Fvec4
impl Sync for Fvec4
impl Unpin for Fvec4
impl UnwindSafe for Fvec4
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more