Struct mafs::Dvec4

source ·
#[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 Add<Dvec4> for Dvec4

§

type Output = Dvec4

The resulting type after applying the + operator.
source§

fn add(self, rhs: Dvec4) -> Dvec4

Performs the + operation. Read more
source§

impl Add<Dvec4> for f64

§

type Output = Dvec4

The resulting type after applying the + operator.
source§

fn add(self, rhs: Dvec4) -> Dvec4

Performs the + operation. Read more
source§

impl Add<f64> for Dvec4

§

type Output = Dvec4

The resulting type after applying the + operator.
source§

fn add(self, rhs: f64) -> Dvec4

Performs the + operation. Read more
source§

impl AddAssign<Dvec4> for Dvec4

source§

fn add_assign(&mut self, rhs: Dvec4)

Performs the += operation. Read more
source§

impl AddAssign<f64> for Dvec4

source§

fn add_assign(&mut self, rhs: f64)

Performs the += operation. Read more
source§

impl Clone for Dvec4

source§

fn clone(&self) -> Dvec4

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 Dvec4

source§

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

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

impl Default for Dvec4

source§

fn default() -> Dvec4

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

impl Div<Dvec4> for Dvec4

§

type Output = Dvec4

The resulting type after applying the / operator.
source§

fn div(self, rhs: Dvec4) -> Dvec4

Performs the / operation. Read more
source§

impl Div<Dvec4> for f64

§

type Output = Dvec4

The resulting type after applying the / operator.
source§

fn div(self, rhs: Dvec4) -> Dvec4

Performs the / operation. Read more
source§

impl Div<f64> for Dvec4

§

type Output = Dvec4

The resulting type after applying the / operator.
source§

fn div(self, rhs: f64) -> Dvec4

Performs the / operation. Read more
source§

impl DivAssign<Dvec4> for Dvec4

source§

fn div_assign(&mut self, rhs: Dvec4)

Performs the /= operation. Read more
source§

impl DivAssign<f64> for Dvec4

source§

fn div_assign(&mut self, rhs: f64)

Performs the /= operation. Read more
source§

impl Index<usize> for Dvec4

§

type Output = f64

The returned type after indexing.
source§

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

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

impl IndexMut<usize> for Dvec4

source§

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

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

impl Mat4<f64, Dvec4> for Dmat4

source§

fn from_columns(x: Dvec4, y: Dvec4, z: Dvec4, w: Dvec4) -> Dmat4

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

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

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

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

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

fn transpose(&self) -> Dmat4

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§

fn identity() -> Self

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<Dvec4> for Dmat4

§

type Output = Dvec4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Dvec4) -> Dvec4

Performs the * operation. Read more
source§

impl Mul<Dvec4> for Dvec4

§

type Output = Dvec4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Dvec4) -> Dvec4

Performs the * operation. Read more
source§

impl Mul<Dvec4> for f64

§

type Output = Dvec4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Dvec4) -> Dvec4

Performs the * operation. Read more
source§

impl Mul<f64> for Dvec4

§

type Output = Dvec4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: f64) -> Dvec4

Performs the * operation. Read more
source§

impl MulAssign<Dvec4> for Dvec4

source§

fn mul_assign(&mut self, rhs: Dvec4)

Performs the *= operation. Read more
source§

impl MulAssign<f64> for Dvec4

source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
source§

impl Neg for Dvec4

§

type Output = Dvec4

The resulting type after applying the - operator.
source§

fn neg(self) -> Dvec4

Performs the unary - operation. Read more
source§

impl PartialEq<Dvec4> for Dvec4

source§

fn eq(&self, rhs: &Dvec4) -> 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<Dvec4> for Dvec4

§

type Output = Dvec4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Dvec4) -> Dvec4

Performs the - operation. Read more
source§

impl Sub<Dvec4> for f64

§

type Output = Dvec4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Dvec4) -> Dvec4

Performs the - operation. Read more
source§

impl Sub<f64> for Dvec4

§

type Output = Dvec4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: f64) -> Dvec4

Performs the - operation. Read more
source§

impl SubAssign<Dvec4> for Dvec4

source§

fn sub_assign(&mut self, rhs: Dvec4)

Performs the -= operation. Read more
source§

impl SubAssign<f64> for Dvec4

source§

fn sub_assign(&mut self, rhs: f64)

Performs the -= operation. Read more
source§

impl Vec4<f64> for Dvec4

source§

fn new(x: f64, y: f64, z: f64, w: f64) -> Dvec4

Create a new two-dimensional vector.
source§

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

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

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

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

fn sub_componentwise(&self, rhs: Dvec4) -> Dvec4

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

fn mul_componentwise(&self, rhs: Dvec4) -> Dvec4

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

fn div_componentwise(&self, rhs: Dvec4) -> Dvec4

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

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

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

fn floor(&self) -> Dvec4

Round down all components to an integer value.
source§

fn min_reduce(&self) -> f64

Smallest of the four components.
source§

fn max_reduce(&self) -> f64

Largest of the four components.
source§

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

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

fn dot(&self, rhs: Dvec4) -> f64

Dot product.
source§

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

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