#[repr(C)]pub struct Dvec4 { /* private fields */ }
Expand description
4D vector with double precision
The components are laid out in this order: [x, y, z, w]
. This struct is aligned to 32 bytes.
Examples
use mafs::{Vec4, Dvec4};
// Construction
let a = Dvec4::new(2.0, 3.0, 5.0, 6.0);
let b = Dvec4::new(6.0, 9.0, 2.5, 3.0);
let c = Dvec4::splat(0.0); // Set all four components to the same value
let p = Dvec4::point(1.0, 2.0, 3.0);
assert_eq!(p[3], 1.0); // Fourth component of a point is one
let d = Dvec4::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, Dvec4::new(8.0, 12.0, 7.5, 9.0));
assert_eq!(a - b, Dvec4::new(-4.0, -6.0, 2.5, 3.0));
assert_eq!(a * b, Dvec4::new(12.0, 27.0, 12.5, 18.0));
assert_eq!(b / a, Dvec4::new(3.0, 3.0, 0.5, 0.5));
// Euclidian norm
assert_eq!(a.norm(), 74.0f64.sqrt());
assert_eq!(a.normalize().norm(), 1.0); // hmmmm
// Specialized operations
assert_eq!(a.dot(b), 69.5);
assert_eq!(b.dot(a), a.dot(b));
assert_eq!(a.cross(b), Dvec4::new(-37.5, 25.0, 0.0, 0.0));
assert_eq!(b.cross(a), -a.cross(b));
assert_eq!(Dvec4::new(-0.5, 0.5, 2.9, 0.0).floor(), Dvec4::new(-1.0, 0.0, 2.0, 0.0));
// Comparisons
assert_eq!(a.min_componentwise(b), Dvec4::new(2.0, 3.0, 2.5, 3.0));
assert_eq!(a.max_componentwise(b), Dvec4::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<Dvec4> for Dvec4
impl AddAssign<Dvec4> for Dvec4
source§fn add_assign(&mut self, rhs: Dvec4)
fn add_assign(&mut self, rhs: Dvec4)
Performs the
+=
operation. Read moresource§impl AddAssign<f64> for Dvec4
impl AddAssign<f64> for Dvec4
source§fn add_assign(&mut self, rhs: f64)
fn add_assign(&mut self, rhs: f64)
Performs the
+=
operation. Read moresource§impl DivAssign<Dvec4> for Dvec4
impl DivAssign<Dvec4> for Dvec4
source§fn div_assign(&mut self, rhs: Dvec4)
fn div_assign(&mut self, rhs: Dvec4)
Performs the
/=
operation. Read moresource§impl DivAssign<f64> for Dvec4
impl DivAssign<f64> for Dvec4
source§fn div_assign(&mut self, rhs: f64)
fn div_assign(&mut self, rhs: f64)
Performs the
/=
operation. Read moresource§impl Mat4<f64, Dvec4> for Dmat4
impl Mat4<f64, Dvec4> for Dmat4
source§fn from_columns(x: Dvec4, y: Dvec4, z: Dvec4, w: Dvec4) -> Dmat4
fn from_columns(x: Dvec4, y: Dvec4, z: Dvec4, w: Dvec4) -> Dmat4
Create a new 4x4 matrix from its four columns.
source§fn as_mut_array(&mut self) -> &mut [Dvec4; 4]
fn as_mut_array(&mut self) -> &mut [Dvec4; 4]
Convert to a mutable array.
Can also use the indexing operator
[]
.source§fn mul_vector(&self, rhs: Dvec4) -> Dvec4
fn mul_vector(&self, rhs: Dvec4) -> Dvec4
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<Dvec4> for Dvec4
impl MulAssign<Dvec4> for Dvec4
source§fn mul_assign(&mut self, rhs: Dvec4)
fn mul_assign(&mut self, rhs: Dvec4)
Performs the
*=
operation. Read moresource§impl MulAssign<f64> for Dvec4
impl MulAssign<f64> for Dvec4
source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
Performs the
*=
operation. Read moresource§impl SubAssign<Dvec4> for Dvec4
impl SubAssign<Dvec4> for Dvec4
source§fn sub_assign(&mut self, rhs: Dvec4)
fn sub_assign(&mut self, rhs: Dvec4)
Performs the
-=
operation. Read moresource§impl SubAssign<f64> for Dvec4
impl SubAssign<f64> for Dvec4
source§fn sub_assign(&mut self, rhs: f64)
fn sub_assign(&mut self, rhs: f64)
Performs the
-=
operation. Read moresource§impl Vec4<f64> for Dvec4
impl Vec4<f64> for Dvec4
source§fn as_mut_array(&mut self) -> &mut [f64; 4]
fn as_mut_array(&mut self) -> &mut [f64; 4]
Convert to a mutable array.
Can also use the indexing operator
[]
.source§fn add_componentwise(&self, rhs: Dvec4) -> Dvec4
fn add_componentwise(&self, rhs: Dvec4) -> Dvec4
Add component by component.
Can also use the
+
operator.source§fn sub_componentwise(&self, rhs: Dvec4) -> Dvec4
fn sub_componentwise(&self, rhs: Dvec4) -> Dvec4
Subtract component by component.
Can also use the
-
operator.source§fn mul_componentwise(&self, rhs: Dvec4) -> Dvec4
fn mul_componentwise(&self, rhs: Dvec4) -> Dvec4
Multiply component by component.
Can also use the
*
operator.source§fn div_componentwise(&self, rhs: Dvec4) -> Dvec4
fn div_componentwise(&self, rhs: Dvec4) -> Dvec4
Divide component by component.
Can also use the
/
operator.source§fn min_componentwise(&self, rhs: Dvec4) -> Dvec4
fn min_componentwise(&self, rhs: Dvec4) -> Dvec4
For each lane, select the smallest component of the two.
source§fn max_componentwise(&self, rhs: Dvec4) -> Dvec4
fn max_componentwise(&self, rhs: Dvec4) -> Dvec4
For each lane, select the largest component of the two.
source§fn min_reduce(&self) -> f64
fn min_reduce(&self) -> f64
Smallest of the four components.
source§fn max_reduce(&self) -> f64
fn max_reduce(&self) -> f64
Largest of the four components.
source§fn cross(&self, rhs: Dvec4) -> Dvec4
fn cross(&self, rhs: Dvec4) -> Dvec4
Cross product.
The fourth component of the operands is ignored and the fourth component of the result will be zero.
impl Copy for Dvec4
Auto Trait Implementations§
impl RefUnwindSafe for Dvec4
impl Send for Dvec4
impl Sync for Dvec4
impl Unpin for Dvec4
impl UnwindSafe for Dvec4
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