[][src]Struct vek::vec::repr_c::vec4::Vec4

#[repr(C)]
pub struct Vec4<T> {
    pub x: T,
    pub y: T,
    pub z: T,
    pub w: T,
}

Vector type suited for homogeneous 3D spatial coordinates.

Fields

x: Ty: Tz: Tw: T

In homogeneous 3D-space coordinates, w is often set to 1 for points, and 0 for directions.

One reason behind this: with floating-point numbers, division by zero gives infinity (a direction is then a point stretching infinitely towards another).

Methods

impl<T> Vec4<T>[src]

pub const fn new(x: T, y: T, z: T, w: T) -> Self[src]

Creates a vector from elements.

impl<T> Vec4<T>[src]

pub fn broadcast(val: T) -> Self where
    T: Copy
[src]

Broadcasts a single value to all elements of a new vector.

This function is also named splat() in some libraries, or set1() in Intel intrinsics.

"Broadcast" was chosen as the name because it is explicit enough and is the same wording as the description in relevant Intel intrinsics.

assert_eq!(Vec4::broadcast(5), Vec4::new(5,5,5,5));
assert_eq!(Vec4::broadcast(5), Vec4::from(5));

pub fn zero() -> Self where
    T: Zero
[src]

Creates a new vector with all elements set to zero.

assert_eq!(Vec4::zero(), Vec4::new(0,0,0,0));
assert_eq!(Vec4::zero(), Vec4::broadcast(0));
assert_eq!(Vec4::zero(), Vec4::from(0));

pub fn one() -> Self where
    T: One
[src]

Creates a new vector with all elements set to one.

assert_eq!(Vec4::one(), Vec4::new(1,1,1,1));
assert_eq!(Vec4::one(), Vec4::broadcast(1));
assert_eq!(Vec4::one(), Vec4::from(1));

pub fn iota() -> Self where
    T: Zero + One + AddAssign + Copy
[src]

Produces a vector of the first n integers, starting from zero, where n is the number of elements for this vector type.

The iota (ι) function, originating from APL.

See this StackOverflow answer.

This is mostly useful for debugging purposes and tests.

assert_eq!(Vec4::iota(), Vec4::new(0, 1, 2, 3));

pub const fn elem_count(&self) -> usize[src]

Convenience method which returns the number of elements of this vector.

let v = Vec4::new(0,1,2,3);
assert_eq!(v.elem_count(), 4);

pub const ELEM_COUNT: usize[src]

Convenience constant representing the number of elements for this vector type.

pub fn into_tuple(self) -> (T, T, T, T)[src]

Converts this into a tuple with the same number of elements by consuming.

pub fn into_array(self) -> [T; 4][src]

Converts this vector into a fixed-size array.

pub fn as_slice(&self) -> &[T][src]

View this vector as an immutable slice.

pub fn as_mut_slice(&mut self) -> &mut [T][src]

View this vector as a mutable slice.

pub fn from_slice(slice: &[T]) -> Self where
    T: Default + Copy
[src]

Collects the content of a slice into a new vector. Elements are initialized to their default values.

pub fn map<D, F>(self, f: F) -> Vec4<D> where
    F: FnMut(T) -> D, 
[src]

Returns a memberwise-converted copy of this vector, using the given conversion closure.

let v = Vec4::new(0_f32, 1., 1.8, 3.14);
let i = v.map(|x| x.round() as i32);
assert_eq!(i, Vec4::new(0, 1, 2, 3));

Performing LERP on integer vectors by concisely converting them to floats:

let a = Vec4::new(0,1,2,3).map(|x| x as f32);
let b = Vec4::new(2,3,4,5).map(|x| x as f32);
let v = Vec4::lerp(a, b, 0.5_f32).map(|x| x.round() as i32);
assert_eq!(v, Vec4::new(1,2,3,4));

pub fn map2<D, F, S>(self, other: Vec4<S>, f: F) -> Vec4<D> where
    F: FnMut(T, S) -> D, 
[src]

Applies the function f to each element of two vectors, pairwise, and returns the result.

let a = Vec4::<u8>::new(255, 254, 253, 252);
let b = Vec4::<u8>::new(1, 2, 3, 4);
let v = a.map2(b, |a, b| a.wrapping_add(b));
assert_eq!(v, Vec4::zero());
let v = a.map2(b, u8::wrapping_add);
assert_eq!(v, Vec4::zero());

pub fn apply<F>(&mut self, f: F) where
    T: Copy,
    F: FnMut(T) -> T, 
[src]

Applies the function f to each element of this vector, in-place.

let mut v = Vec4::new(0_u32, 1, 2, 3);
v.apply(|x| x.count_ones());
assert_eq!(v, Vec4::new(0, 1, 1, 2));

pub fn apply2<F, S>(&mut self, other: Vec4<S>, f: F) where
    T: Copy,
    F: FnMut(T, S) -> T, 
[src]

Applies the function f to each element of two vectors, pairwise, in-place.

let mut a = Vec4::<u8>::new(255, 254, 253, 252);
let b = Vec4::<u8>::new(1, 2, 3, 4);
a.apply2(b, |a, b| a.wrapping_add(b));
assert_eq!(a, Vec4::zero());
a.apply2(b, u8::wrapping_add);
assert_eq!(a, b);

pub fn zip<S>(self, other: Vec4<S>) -> Vec4<(T, S)>[src]

"Zips" two vectors together into a vector of tuples.

let a = Vec4::<u8>::new(255, 254, 253, 252);
let b = Vec4::<u8>::new(1, 2, 3, 4);
assert_eq!(a.zip(b), Vec4::new((255, 1), (254, 2), (253, 3), (252, 4)));

pub fn numcast<D>(self) -> Option<Vec4<D>> where
    T: NumCast,
    D: NumCast
[src]

Returns a memberwise-converted copy of this vector, using NumCast.

let v = Vec4::new(0_f32, 1., 2., 3.);
let i: Vec4<i32> = v.numcast().unwrap();
assert_eq!(i, Vec4::new(0, 1, 2, 3));

pub fn mul_add<V: Into<Self>>(self, mul: V, add: V) -> Self where
    T: MulAdd<T, T, Output = T>, 
[src]

Fused multiply-add. Returns self * mul + add, and may be implemented efficiently by the hardware.

The compiler is often able to detect this kind of operation, so generally you don't need to use it. However, it can make your intent clear.

The name for this method is the one used by the same operation on primitive floating-point types.

let a = Vec4::new(0,1,2,3);
let b = Vec4::new(4,5,6,7);
let c = Vec4::new(8,9,0,1);
assert_eq!(a*b+c, a.mul_add(b, c));

pub fn is_any_negative(&self) -> bool where
    T: Signed
[src]

Is any of the elements negative ?

This was intended for checking the validity of extent vectors, but can make sense for other types too.

pub fn are_all_positive(&self) -> bool where
    T: Signed
[src]

Are all of the elements positive ?

pub fn min<V>(a: V, b: V) -> Self where
    V: Into<Self>,
    T: Ord
[src]

Compares elements of a and b, and returns the minimum values into a new vector, using total ordering.

let a = Vec4::new(0,1,2,3);
let b = Vec4::new(3,2,1,0);
let m = Vec4::new(0,1,1,0);
assert_eq!(m, Vec4::min(a, b));

pub fn max<V>(a: V, b: V) -> Self where
    V: Into<Self>,
    T: Ord
[src]

Compares elements of a and b, and returns the maximum values into a new vector, using total ordering.

let a = Vec4::new(0,1,2,3);
let b = Vec4::new(3,2,1,0);
let m = Vec4::new(3,2,2,3);
assert_eq!(m, Vec4::max(a, b));

pub fn partial_min<V>(a: V, b: V) -> Self where
    V: Into<Self>,
    T: PartialOrd
[src]

Compares elements of a and b, and returns the minimum values into a new vector, using partial ordering.

let a = Vec4::new(0,1,2,3);
let b = Vec4::new(3,2,1,0);
let m = Vec4::new(0,1,1,0);
assert_eq!(m, Vec4::partial_min(a, b));

pub fn partial_max<V>(a: V, b: V) -> Self where
    V: Into<Self>,
    T: PartialOrd
[src]

Compares elements of a and b, and returns the minimum values into a new vector, using partial ordering.

let a = Vec4::new(0,1,2,3);
let b = Vec4::new(3,2,1,0);
let m = Vec4::new(3,2,2,3);
assert_eq!(m, Vec4::partial_max(a, b));

pub fn reduce_min(self) -> T where
    T: Ord
[src]

Returns the element which has the lowest value in this vector, using total ordering.

assert_eq!(-5, Vec4::new(0, 5, -5, 8).reduce_min());

pub fn reduce_max(self) -> T where
    T: Ord
[src]

Returns the element which has the highest value in this vector, using total ordering.

assert_eq!(8, Vec4::new(0, 5, -5, 8).reduce_max());

pub fn reduce_partial_min(self) -> T where
    T: PartialOrd
[src]

Returns the element which has the lowest value in this vector, using partial ordering.

assert_eq!(-5_f32, Vec4::new(0_f32, 5., -5., 8.).reduce_partial_min());

pub fn reduce_partial_max(self) -> T where
    T: PartialOrd
[src]

Returns the element which has the highest value in this vector, using partial ordering.

assert_eq!(8_f32, Vec4::new(0_f32, 5., -5., 8.).reduce_partial_max());

pub fn reduce_bitand(self) -> T where
    T: BitAnd<T, Output = T>, 
[src]

Returns the result of bitwise-AND (&) on all elements of this vector.

assert_eq!(true,  Vec4::new(true, true, true, true).reduce_bitand());
assert_eq!(false, Vec4::new(true, false, true, true).reduce_bitand());
assert_eq!(false, Vec4::new(true, true, true, false).reduce_bitand());

pub fn reduce_bitor(self) -> T where
    T: BitOr<T, Output = T>, 
[src]

Returns the result of bitwise-OR (|) on all elements of this vector.

assert_eq!(false, Vec4::new(false, false, false, false).reduce_bitor());
assert_eq!(true,  Vec4::new(false, false, true, false).reduce_bitor());

pub fn reduce_bitxor(self) -> T where
    T: BitXor<T, Output = T>, 
[src]

Returns the result of bitwise-XOR (^) on all elements of this vector.

assert_eq!(false, Vec4::new(true, true, true, true).reduce_bitxor());
assert_eq!(true,  Vec4::new(true, false, true, true).reduce_bitxor());

pub fn reduce<F>(self, f: F) -> T where
    F: FnMut(T, T) -> T, 
[src]

Reduces this vector with the given accumulator closure.

pub fn product(self) -> T where
    T: Product
[src]

Returns the product of each of this vector's elements.

assert_eq!(1*2*3*4, Vec4::new(1, 2, 3, 4).product());

pub fn sum(self) -> T where
    T: Sum
[src]

Returns the sum of each of this vector's elements.

assert_eq!(1+2+3+4, Vec4::new(1, 2, 3, 4).sum());

pub fn average(self) -> T where
    T: Sum + Div<T, Output = T> + From<u8>, 
[src]

Returns the average of this vector's elements.

assert_eq!(2.5_f32, Vec4::new(1_f32, 2., 3., 4.).average());

You should avoid using it on u8 vectors, not only because integer overflows cause panics in debug mode, but also because of integer division, the result may not be the one you expect.

// This causes a panic!
let red = Vec4::new(255u8, 1, 0, 0);
let grey_level = red.average();
assert_eq!(grey_level, 128);

You may want to convert the elements to bigger integers (or floating-point) instead:

let red = Vec4::new(255u8, 1, 128, 128);

let red = red.map(|c| c as u16);
let grey_level = red.average() as u8;
assert_eq!(grey_level, 128);

let red = red.map(|c| c as f32);
let grey_level = red.average().round() as u8;
assert_eq!(grey_level, 128);

pub fn sqrt(self) -> Self where
    T: Real
[src]

Returns a new vector which elements are the respective square roots of this vector's elements.

let v = Vec4::new(1f32, 2f32, 3f32, 4f32);
let s = Vec4::new(1f32, 4f32, 9f32, 16f32);
assert_eq!(v, s.sqrt());

pub fn rsqrt(self) -> Self where
    T: Real
[src]

Returns a new vector which elements are the respective reciprocal square roots of this vector's elements.

let v = Vec4::new(1f32, 0.5f32, 1f32/3f32, 0.25f32);
let s = Vec4::new(1f32, 4f32, 9f32, 16f32);
assert_eq!(v, s.rsqrt());

pub fn recip(self) -> Self where
    T: Real
[src]

Returns a new vector which elements are the respective reciprocal of this vector's elements.

let v = Vec4::new(1f32, 0.5f32, 0.25f32, 0.125f32);
let s = Vec4::new(1f32, 2f32, 4f32, 8f32);
assert_eq!(v, s.recip());
assert_eq!(s, v.recip());

pub fn ceil(self) -> Self where
    T: Real
[src]

Returns a new vector which elements are rounded to the nearest greater integer.

let v = Vec4::new(0_f32, 1., 1.8, 3.14);
assert_eq!(v.ceil(), Vec4::new(0f32, 1f32, 2f32, 4f32));

pub fn floor(self) -> Self where
    T: Real
[src]

Returns a new vector which elements are rounded down to the nearest lower integer.

let v = Vec4::new(0_f32, 1., 1.8, 3.14);
assert_eq!(v.floor(), Vec4::new(0f32, 1f32, 1f32, 3f32));

pub fn round(self) -> Self where
    T: Real
[src]

Returns a new vector which elements are rounded to the nearest integer.

let v = Vec4::new(0_f32, 1., 1.8, 3.14);
assert_eq!(v.round(), Vec4::new(0f32, 1f32, 2f32, 3f32));

pub fn hadd(self, rhs: Self) -> Self where
    T: Add<T, Output = T>, 
[src]

Horizontally adds adjacent pairs of elements in self and rhs into a new vector.

let a = Vec4::new(0, 1, 2, 3);
let b = Vec4::new(4, 5, 6, 7);
let h = Vec4::new(0+1, 2+3, 4+5, 6+7);
assert_eq!(h, a.hadd(b));

pub fn partial_cmpeq<Rhs: AsRef<Self>>(&self, rhs: &Rhs) -> Vec4<bool> where
    T: PartialEq
[src]

Compares each element of two vectors with the partial equality test, returning a boolean vector.

let u = Vec4::new(0,2,2,6);
let v = Vec4::new(0,1,2,3);
assert_eq!(u.partial_cmpeq(&v), Vec4::new(true, false, true, false));

pub fn partial_cmpne<Rhs: AsRef<Self>>(&self, rhs: &Rhs) -> Vec4<bool> where
    T: PartialEq
[src]

Compares each element of two vectors with the partial not-equal test, returning a boolean vector.

let u = Vec4::new(0,2,2,6);
let v = Vec4::new(0,1,2,3);
assert_eq!(u.partial_cmpne(&v), Vec4::new(false, true, false, true));

pub fn partial_cmpge<Rhs: AsRef<Self>>(&self, rhs: &Rhs) -> Vec4<bool> where
    T: PartialOrd
[src]

Compares each element of two vectors with the partial greater-or-equal test, returning a boolean vector.

let u = Vec4::new(0,2,2,2);
let v = Vec4::new(0,1,2,3);
assert_eq!(u.partial_cmpge(&v), Vec4::new(true, true, true, false));

pub fn partial_cmpgt<Rhs: AsRef<Self>>(&self, rhs: &Rhs) -> Vec4<bool> where
    T: PartialOrd
[src]

Compares each element of two vectors with the partial greater-than test, returning a boolean vector.

let u = Vec4::new(0,2,2,6);
let v = Vec4::new(0,1,2,3);
assert_eq!(u.partial_cmpgt(&v), Vec4::new(false, true, false, true));

pub fn partial_cmple<Rhs: AsRef<Self>>(&self, rhs: &Rhs) -> Vec4<bool> where
    T: PartialOrd
[src]

Compares each element of two vectors with the partial less-or-equal test, returning a boolean vector.

let u = Vec4::new(0,2,2,2);
let v = Vec4::new(0,1,2,3);
assert_eq!(u.partial_cmple(&v), Vec4::new(true, false, true, true));

pub fn partial_cmplt<Rhs: AsRef<Self>>(&self, rhs: &Rhs) -> Vec4<bool> where
    T: PartialOrd
[src]

Compares each element of two vectors with the partial less-than test, returning a boolean vector.

let u = Vec4::new(0,2,2,2);
let v = Vec4::new(0,1,2,3);
assert_eq!(u.partial_cmplt(&v), Vec4::new(false, false, false, true));

pub fn cmpeq<Rhs: AsRef<Self>>(&self, rhs: &Rhs) -> Vec4<bool> where
    T: Eq
[src]

Compares each element of two vectors with the partial equality test, returning a boolean vector.

let u = Vec4::new(0,2,2,6);
let v = Vec4::new(0,1,2,3);
assert_eq!(u.cmpeq(&v), Vec4::new(true, false, true, false));

pub fn cmpne<Rhs: AsRef<Self>>(&self, rhs: &Rhs) -> Vec4<bool> where
    T: Eq
[src]

Compares each element of two vectors with the total not-equal test, returning a boolean vector.

let u = Vec4::new(0,2,2,6);
let v = Vec4::new(0,1,2,3);
assert_eq!(u.cmpne(&v), Vec4::new(false, true, false, true));

pub fn cmpge<Rhs: AsRef<Self>>(&self, rhs: &Rhs) -> Vec4<bool> where
    T: Ord
[src]

Compares each element of two vectors with the total greater-or-equal test, returning a boolean vector.

let u = Vec4::new(0,2,2,2);
let v = Vec4::new(0,1,2,3);
assert_eq!(u.cmpge(&v), Vec4::new(true, true, true, false));

pub fn cmpgt<Rhs: AsRef<Self>>(&self, rhs: &Rhs) -> Vec4<bool> where
    T: Ord
[src]

Compares each element of two vectors with the total greater-than test, returning a boolean vector.

let u = Vec4::new(0,2,2,6);
let v = Vec4::new(0,1,2,3);
assert_eq!(u.cmpgt(&v), Vec4::new(false, true, false, true));

pub fn cmple<Rhs: AsRef<Self>>(&self, rhs: &Rhs) -> Vec4<bool> where
    T: Ord
[src]

Compares each element of two vectors with the total less-or-equal test, returning a boolean vector.

let u = Vec4::new(0,2,2,2);
let v = Vec4::new(0,1,2,3);
assert_eq!(u.cmple(&v), Vec4::new(true, false, true, true));

pub fn cmplt<Rhs: AsRef<Self>>(&self, rhs: &Rhs) -> Vec4<bool> where
    T: Ord
[src]

Compares each element of two vectors with the total less-than test, returning a boolean vector.

let u = Vec4::new(0,2,2,2);
let v = Vec4::new(0,1,2,3);
assert_eq!(u.cmplt(&v), Vec4::new(false, false, false, true));

pub fn lerp_unclamped_precise<S: Into<Self>>(
    from: Self,
    to: Self,
    factor: S
) -> Self where
    T: Copy + One + Mul<Output = T> + Sub<Output = T> + MulAdd<T, T, Output = T>, 
[src]

Returns the linear interpolation of from to to with factor unconstrained. See the Lerp trait.

pub fn lerp_unclamped<S: Into<Self>>(from: Self, to: Self, factor: S) -> Self where
    T: Copy + Sub<Output = T> + MulAdd<T, T, Output = T>, 
[src]

Same as lerp_unclamped_precise, implemented as a possibly faster but less precise operation. See the Lerp trait.

pub fn lerp<S: Into<Self> + Clamp + Zero + One>(
    from: Self,
    to: Self,
    factor: S
) -> Self where
    T: Copy + Sub<Output = T> + MulAdd<T, T, Output = T>, 
[src]

Returns the linear interpolation of from to to with factor constrained to be between 0 and 1. See the Lerp trait.

pub fn lerp_precise<S: Into<Self> + Clamp + Zero + One>(
    from: Self,
    to: Self,
    factor: S
) -> Self where
    T: Copy + One + Mul<Output = T> + Sub<Output = T> + MulAdd<T, T, Output = T>, 
[src]

Returns the linear interpolation of from to to with factor constrained to be between 0 and 1. See the Lerp trait.

impl Vec4<bool>[src]

pub fn reduce_and(self) -> bool[src]

Returns the result of logical AND (&&) on all elements of this vector.

assert_eq!(true,  Vec4::new(true, true, true, true).reduce_and());
assert_eq!(false, Vec4::new(true, false, true, true).reduce_and());
assert_eq!(false, Vec4::new(true, true, true, false).reduce_and());

pub fn reduce_or(self) -> bool[src]

Returns the result of logical OR (||) on all elements of this vector.

assert_eq!(false, Vec4::new(false, false, false, false).reduce_or());
assert_eq!(true,  Vec4::new(false, false, true, false).reduce_or());

pub fn reduce_ne(self) -> bool[src]

Reduces this vector using total inequality.

assert_eq!(false, Vec4::new(true, true, true, true).reduce_ne());
assert_eq!(true,  Vec4::new(true, false, true, true).reduce_ne());

impl<T> Vec4<T>[src]

pub fn dot(self, v: Self) -> T where
    T: Sum + Mul<Output = T>, 
[src]

Dot product between this vector and another.

pub fn magnitude_squared(self) -> T where
    T: Copy + Sum + Mul<Output = T>, 
[src]

The squared magnitude of a vector is its spatial length, squared. It is slightly cheaper to compute than magnitude because it avoids a square root.

pub fn magnitude(self) -> T where
    T: Sum + Real
[src]

The magnitude of a vector is its spatial length.

pub fn distance_squared(self, v: Self) -> T where
    T: Copy + Sum + Sub<Output = T> + Mul<Output = T>, 
[src]

Squared distance between two point vectors. It is slightly cheaper to compute than distance because it avoids a square root.

pub fn distance(self, v: Self) -> T where
    T: Sum + Real
[src]

Distance between two point vectors.

pub fn normalized(self) -> Self where
    T: Sum + Real
[src]

Get a copy of this direction vector such that its length equals 1.

pub fn try_normalized(self) -> Option<Self> where
    T: ApproxEq + Sum + Real
[src]

Get a copy of this direction vector such that its length equals 1. If all components approximately zero, None is returned (uses ApproxEq).

pub fn normalize(&mut self) where
    T: Sum + Real
[src]

Divide this vector's components such that its length equals 1.

pub fn is_normalized(self) -> bool where
    T: ApproxEq + Sum + Real
[src]

Is this vector normalized ? (Uses ApproxEq)

pub fn is_approx_zero(self) -> bool where
    T: ApproxEq + Sum + Real
[src]

Is this vector approximately zero ? (Uses ApproxEq)

pub fn angle_between(self, v: Self) -> T where
    T: Sum + Real
[src]

Get the smallest angle, in radians, between two direction vectors.

pub fn angle_between_degrees(self, v: Self) -> T where
    T: Sum + Real
[src]

Deprecated:

Use to_degrees() on the value returned by angle_between() instead

Get the smallest angle, in degrees, between two direction vectors.

pub fn reflected(self, surface_normal: Self) -> Self where
    T: Copy + Sum + Mul<Output = T> + Sub<Output = T> + Add<Output = T>, 
[src]

The reflection direction for this vector on a surface which normal is given.

pub fn refracted(self, surface_normal: Self, eta: T) -> Self where
    T: Real + Sum + Mul<Output = T>, 
[src]

The refraction vector for this incident vector, a surface normal and a ratio of indices of refraction (eta).

pub fn face_forward(self, incident: Self, reference: Self) -> Self where
    T: Sum + Mul<Output = T> + Zero + PartialOrd + Neg<Output = T>, 
[src]

Orients a vector to point away from a surface as defined by its normal.

impl<T> Vec4<T>[src]

pub fn new_point(x: T, y: T, z: T) -> Self where
    T: One
[src]

Creates a point vector in homogeneous coordinates (sets the last coordinate to 1).

pub fn new_direction(x: T, y: T, z: T) -> Self where
    T: Zero
[src]

Creates a direction vector in homogeneous coordinates (sets the last coordinate to 0).

pub fn from_point<V: Into<Vec3<T>>>(v: V) -> Self where
    T: One
[src]

Turns a vector into a point vector in homogeneous coordinates (sets the last coordinate to 1).

pub fn from_direction<V: Into<Vec3<T>>>(v: V) -> Self where
    T: Zero
[src]

Turns a vector into a direction vector in homogeneous coordinates (sets the last coordinate to 0).

pub fn unit_x() -> Self where
    T: Zero + One
[src]

Get the unit direction vector which has x set to 1.

pub fn unit_y() -> Self where
    T: Zero + One
[src]

Get the unit direction vector which has y set to 1.

pub fn unit_z() -> Self where
    T: Zero + One
[src]

Get the unit direction vector which has z set to 1.

pub fn unit_w() -> Self where
    T: Zero + One
[src]

Get the vector which has w set to 1 and all other elements to zero.

pub fn left() -> Self where
    T: Zero + One + Neg<Output = T>, 
[src]

Get the unit direction vector which has x set to -1.

pub fn right() -> Self where
    T: Zero + One
[src]

Get the unit direction vector which has x set to 1.

pub fn up() -> Self where
    T: Zero + One
[src]

Get the unit direction vector which has y set to 1.

pub fn down() -> Self where
    T: Zero + One + Neg<Output = T>, 
[src]

Get the unit direction vector which has y set to -1.

pub fn forward_lh() -> Self where
    T: Zero + One
[src]

Get the unit direction vector which has z set to 1 ("forward" in a left-handed coordinate system).

pub fn forward_rh() -> Self where
    T: Zero + One + Neg<Output = T>, 
[src]

Get the unit direction vector which has z set to -1 ("forward" in a right-handed coordinate system).

pub fn back_lh() -> Self where
    T: Zero + One + Neg<Output = T>, 
[src]

Get the unit direction vector which has z set to -1 ("back" in a left-handed coordinate system).

pub fn back_rh() -> Self where
    T: Zero + One
[src]

Get the unit direction vector which has z set to 1 ("back" in a right-handed coordinate system).

pub fn unit_x_point() -> Self where
    T: Zero + One
[src]

Get the homogeneous point vector which has x set to 1.

pub fn unit_y_point() -> Self where
    T: Zero + One
[src]

Get the homogeneous point vector which has y set to 1.

pub fn unit_z_point() -> Self where
    T: Zero + One
[src]

Get the homogeneous point vector which has z set to 1.

pub fn left_point() -> Self where
    T: Zero + One + Neg<Output = T>, 
[src]

Get the homogeneous point vector which has x set to -1.

pub fn right_point() -> Self where
    T: Zero + One
[src]

Get the homogeneous point vector which has x set to 1.

pub fn up_point() -> Self where
    T: Zero + One
[src]

Get the homogeneous point vector which has y set to 1.

pub fn down_point() -> Self where
    T: Zero + One + Neg<Output = T>, 
[src]

Get the homogeneous point vector which has y set to -1.

pub fn forward_point_lh() -> Self where
    T: Zero + One
[src]

Get the homogeneous point vector which has z set to 1 ("forward" in a left-handed coordinate system).

pub fn forward_point_rh() -> Self where
    T: Zero + One + Neg<Output = T>, 
[src]

Get the homogeneous point vector which has z set to -1 ("forward" in a right-handed coordinate system).

pub fn back_point_lh() -> Self where
    T: Zero + One + Neg<Output = T>, 
[src]

Get the homogeneous point vector which has z set to -1 ("back" in a left-handed coordinate system).

pub fn back_point_rh() -> Self where
    T: Zero + One
[src]

Get the homogeneous point vector which has z set to 1 ("back" in a right-handed coordinate system).

pub fn homogenized(self) -> Self where
    T: Div<Output = T>,
    T: Copy
[src]

Get a copy of this vector where each component has been divided in order to make w = 1.

More info: A homogeneous point has w = 1. Some operations (e.g. projection) can cause this to no longer be the case. Homogenization is when you divide every component of the vector by w. This makes w = 1 and the remaining components are also appropriately scaled. This process is also called "normalization" in some textbooks, but that name is already taken by other methods of this struct.

If w = 0, this method will result in a division by zero. Be careful!

pub fn homogenize(&mut self) where
    T: Div<Output = T>,
    T: Copy
[src]

Divide the vector's components such that w = 1.

See the homogenized method for more information.

pub fn is_homogeneous(self) -> bool where
    T: ApproxEq + Zero + One + Copy
[src]

Returns true if this vector is homogeneous (w = 0 or w = 1).

Uses ApproxEq.

pub fn is_point(self) -> bool where
    T: ApproxEq + One
[src]

Returns true if this vector is a homogeneous point (w = 1).

Uses ApproxEq.

pub fn is_direction(self) -> bool where
    T: ApproxEq + Zero
[src]

Returns true if this vector is a homogeneous direction (w = 0).

Uses ApproxEq.

impl<T> Vec4<T>[src]

pub fn shuffled<M: Into<ShuffleMask4>>(self, mask: M) -> Self where
    T: Copy
[src]

Shuffle elements from this vector, using mask.

The relevant x86 intrinsic is _mm_shuffle_ps(v, v, mask).

let a = Vec4::<u32>::new(0,1,2,3);
assert_eq!(a.shuffled((0,1,2,3)), Vec4::new(0,1,2,3));
assert_eq!(a.shuffled((3,2,1,0)), Vec4::new(3,2,1,0));
assert_eq!(a.shuffled((2,3,4,5)), Vec4::new(2,3,0,1));
assert_eq!(a.shuffled(1), Vec4::new(1,1,1,1));
assert_eq!(a.shuffled(1), Vec4::broadcast(1));

pub fn shuffled_0101(self) -> Self where
    T: Copy
[src]

Moves the lower two elements of this vector to the upper two elements of the result. The lower two elements of this vector are passed through to the result.

The relevant x86 intrinsic is _mm_movelh_ps(v, v).

let a = Vec4::<u32>::new(0,1,2,3);
let b = Vec4::<u32>::new(0,1,0,1);
assert_eq!(a.shuffled_0101(), b);

pub fn shuffled_2323(self) -> Self where
    T: Copy
[src]

Moves the upper two elements of this vector to the lower two elements of the result. The upper two elements of this vector are passed through to the result.

The relevant x86 intrinsic is _mm_movehl_ps(v, v).

let a = Vec4::<u32>::new(0,1,2,3);
let b = Vec4::<u32>::new(2,3,2,3);
assert_eq!(a.shuffled_2323(), b);

pub fn shuffle_lo_hi<M: Into<ShuffleMask4>>(lo: Self, hi: Self, mask: M) -> Self where
    T: Copy
[src]

Shuffle elements from lo's low part and hi's high part using mask.

To shuffle a single vector, you may pass it as the first two arguments, or use the shuffled() method.

The relevant x86 intrinsic is _mm_shuffle_ps(lo, hi, mask).

let a = Vec4::<u32>::new(0,1,2,3);
let b = Vec4::<u32>::new(4,5,6,7);
assert_eq!(Vec4::shuffle_lo_hi(a, b, (0,1,2,3)), Vec4::new(0,1,6,7));
assert_eq!(Vec4::shuffle_lo_hi(a, b, (3,2,1,0)), Vec4::new(3,2,5,4));

pub fn interleave_0011(a: Self, b: Self) -> Self[src]

Interleaves the lower two elements from a and b.

The relevant x86 intrinsic is _mm_unpacklo_ps(a, b).

let a = Vec4::<u32>::new(0,1,2,3);
let b = Vec4::<u32>::new(4,5,6,7);
let c = Vec4::<u32>::new(0,4,1,5);
assert_eq!(Vec4::interleave_0011(a, b), c);

pub fn interleave_2233(a: Self, b: Self) -> Self[src]

Interleaves the upper two elements from a and b.

The relevant x86 intrinsic is _mm_unpackhi_ps(a, b).

let a = Vec4::<u32>::new(0,1,2,3);
let b = Vec4::<u32>::new(4,5,6,7);
let c = Vec4::<u32>::new(2,6,3,7);
assert_eq!(Vec4::interleave_2233(a, b), c);

pub fn shuffle_lo_hi_0101(a: Self, b: Self) -> Self[src]

Moves the lower two elements of b to the upper two elements of the result. The lower two elements of a are passed through to the result.

The relevant x86 intrinsic is _mm_movelh_ps(a, b).

let a = Vec4::<u32>::new(0,1,2,3);
let b = Vec4::<u32>::new(4,5,6,7);
let c = Vec4::<u32>::new(0,1,4,5);
assert_eq!(Vec4::shuffle_lo_hi_0101(a, b), c);

pub fn shuffle_hi_lo_2323(a: Self, b: Self) -> Self[src]

Moves the upper two elements of b to the lower two elements of the result. The upper two elements of a are passed through to the result.

The relevant x86 intrinsic is _mm_movehl_ps(a, b).

let a = Vec4::<u32>::new(0,1,2,3);
let b = Vec4::<u32>::new(4,5,6,7);
let c = Vec4::<u32>::new(6,7,2,3);
assert_eq!(Vec4::shuffle_hi_lo_2323(a, b), c);

pub fn shuffled_0022(self) -> Self where
    T: Copy
[src]

Returns a copy of this vector with v[1] set to v[0] and v[3] set to v[2].

The relevant x86 intrinsic is _mm_moveldup_ps(v).

let a = Vec4::<u32>::new(0,1,2,3);
let b = Vec4::<u32>::new(0,0,2,2);
assert_eq!(a.shuffled_0022(), b);

pub fn shuffled_1133(self) -> Self where
    T: Copy
[src]

Returns a copy of this vector with v[0] set to v[1] and v[2] set to v[3].

The relevant x86 intrinsic is _mm_movehdup_ps(v).

let a = Vec4::<u32>::new(0,1,2,3);
let b = Vec4::<u32>::new(1,1,3,3);
assert_eq!(a.shuffled_1133(), b);

impl<T: Copy + Add<T, Output = T> + Mul<T, Output = T> + Sub<T, Output = T>> Vec4<T>[src]

pub fn mat2_rows_mul(self, rhs: Self) -> Self[src]

Performs 2x2 matrix multiplication, treating each Vec4 as a row-major 2x2 matrix.

let a = Vec4::new(
    0,1,
    2,3
);
let b = Vec4::new(
    2,3,
    6,11
);
assert_eq!(a.mat2_rows_mul(a), b)

pub fn mat2_rows_adj_mul(self, rhs: Self) -> Self[src]

2x2 row-major Matrix adjugate multiply (A#)*B

pub fn mat2_rows_mul_adj(self, rhs: Self) -> Self[src]

2x2 row-major Matrix multiply adjugate A*(B#)

pub fn mat2_cols_mul(self, rhs: Self) -> Self[src]

Performs 2x2 matrix multiplication, treating each Vec4 as a column-major 2x2 matrix.

let a = Vec4::new(
    0,2,
    1,3
);
let b = Vec4::new(
    2,6,
    3,11
);
assert_eq!(a.mat2_cols_mul(a), b)

pub fn mat2_cols_adj_mul(self, rhs: Self) -> Self[src]

2x2 column-major Matrix adjugate multiply (A#)*B

pub fn mat2_cols_mul_adj(self, rhs: Self) -> Self[src]

2x2 column-major Matrix multiply adjugate A*(B#)

impl<T> Vec4<T>[src]

pub fn wzyx(self) -> Self[src]

Returns a copy of this vector, with elements reversed.

pub fn zyxw(self) -> Self[src]

Returns a copy of this vector, with X and Z swapped.

pub fn xyz(self) -> Vec3<T>[src]

Same as Vec3::from(self), but shorter.

pub fn xy(self) -> Vec2<T>[src]

Same as Vec2::from(self), but shorter.

impl<T> CVec<T>[src]

pub fn into_repr_simd(self) -> Vec4<T>[src]

Converts this vector into its #[repr(simd)] counterpart.

Trait Implementations

impl<T: IsBetween<Output = bool> + Copy> IsBetween<T> for Vec4<T>[src]

type Output = Vec4<bool>

bool for scalars, or vector of bools for vectors.

impl<T: IsBetween<Output = bool>> IsBetween<Vec4<T>> for Vec4<T>[src]

type Output = Vec4<bool>

bool for scalars, or vector of bools for vectors.

impl<T: Clamp + Copy> Clamp<T> for Vec4<T>[src]

impl<T: Clamp> Clamp<Vec4<T>> for Vec4<T>[src]

impl<T> MulAdd<Vec4<T>, Vec4<T>> for Vec4<T> where
    T: MulAdd<T, T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the fused multiply-add operation.

impl<'c, T> MulAdd<Vec4<T>, Vec4<T>> for &'c Vec4<T> where
    &'c T: MulAdd<T, T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the fused multiply-add operation.

impl<'b, T> MulAdd<Vec4<T>, &'b Vec4<T>> for Vec4<T> where
    T: MulAdd<T, &'b T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the fused multiply-add operation.

impl<'b, 'c, T> MulAdd<Vec4<T>, &'b Vec4<T>> for &'c Vec4<T> where
    &'c T: MulAdd<T, &'b T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the fused multiply-add operation.

impl<'a, T> MulAdd<&'a Vec4<T>, Vec4<T>> for Vec4<T> where
    T: MulAdd<&'a T, T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the fused multiply-add operation.

impl<'a, 'c, T> MulAdd<&'a Vec4<T>, Vec4<T>> for &'c Vec4<T> where
    &'c T: MulAdd<&'a T, T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the fused multiply-add operation.

impl<'a, 'b, T> MulAdd<&'a Vec4<T>, &'b Vec4<T>> for Vec4<T> where
    T: MulAdd<&'a T, &'b T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the fused multiply-add operation.

impl<'a, 'b, 'c, T> MulAdd<&'a Vec4<T>, &'b Vec4<T>> for &'c Vec4<T> where
    &'c T: MulAdd<&'a T, &'b T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the fused multiply-add operation.

impl<T, Factor> Lerp<Factor> for Vec4<T> where
    T: Lerp<Factor, Output = T>,
    Factor: Copy
[src]

type Output = Self

The resulting type after performing the LERP operation.

impl<'a, T, Factor> Lerp<Factor> for &'a Vec4<T> where
    &'a T: Lerp<Factor, Output = T>,
    Factor: Copy
[src]

type Output = Vec4<T>

The resulting type after performing the LERP operation.

impl<T: Wrap + Copy> Wrap<T> for Vec4<T>[src]

impl<T: Wrap> Wrap<Vec4<T>> for Vec4<T>[src]

impl<T> From<Vec4<T>> for Vec2<T>[src]

impl<T> From<Vec4<T>> for Vec3<T>[src]

impl<T> From<(T, T, T, T)> for Vec4<T>[src]

impl<T> From<[T; 4]> for Vec4<T>[src]

impl<T: Copy> From<T> for Vec4<T>[src]

A vector can be obtained from a single scalar by broadcasting it.

This conversion is important because it allows scalars to be smoothly accepted as operands in most vector operations.

For instance :

assert_eq!(Vec4::min(4, 5), Vec4::broadcast(4));
assert_eq!(Vec4::max(4, 5), Vec4::broadcast(5));
assert_eq!(Vec4::from(4), Vec4::broadcast(4));
assert_eq!(Vec4::from(4).mul_add(4, 5), Vec4::broadcast(21));

// scaling_3d() logically accepts a Vec3...
let _ = Mat4::<f32>::scaling_3d(Vec3::broadcast(5.0));
// ... but there you go; quick uniform scale, thanks to Into !
let _ = Mat4::scaling_3d(5_f32);

On the other hand, it also allows writing nonsense. To minimize surprises, the names of operations try to be as explicit as possible.

// This creates a matrix that translates to (5,5,5), but it's probably not what you meant.
// Hopefully the `_3d` suffix would help you catch this.
let _ = Mat4::translation_3d(5_f32);
// translation_3d() takes V: Into<Vec3> because it allows it to accept
// Vec2, Vec3 and Vec4, and also with both repr(C) and repr(simd) layouts.

impl<T: Zero> From<Vec3<T>> for Vec4<T>[src]

impl<T: Zero> From<Vec2<T>> for Vec4<T>[src]

impl<T> From<Rgba<T>> for Vec4<T>[src]

impl<T> From<Vec4<T>> for Rgba<T>[src]

impl<T> From<Vec4<T>> for Vec4<T>[src]

impl<T> From<Vec4<T>> for CVec<T>[src]

impl<T> From<Vec4<T>> for Quaternion<T>[src]

A quaternion can be created directly from a Vec4's x, y, z and w elements. You are responsible for ensuring that the resulting quaternion is normalized.

impl<T> From<Quaternion<T>> for CVec4<T>[src]

A Vec4 can be created directly from a quaternion's x, y, z and w elements.

impl<T> From<Vec4<T>> for Quaternion<T>[src]

A quaternion can be created directly from a Vec4's x, y, z and w elements. You are responsible for ensuring that the resulting quaternion is normalized.

impl<T> From<Quaternion<T>> for Vec4<T>[src]

A Vec4 can be created directly from a quaternion's x, y, z and w elements.

impl<T> From<Vec4<Vec2<T>>> for CubicBezier2<T>[src]

impl<T> From<CubicBezier2<T>> for Vec4<Vec2<T>>[src]

impl<T> From<Vec4<Vec3<T>>> for CubicBezier3<T>[src]

impl<T> From<CubicBezier3<T>> for Vec4<Vec3<T>>[src]

impl<T: Display> Display for Vec4<T>[src]

Displays the vector, formatted as ({}, {}, {}, {}).

impl<T: Debug> Debug for Vec4<T>[src]

impl<V, T> Div<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: Div<T, Output = T>, 
[src]

type Output = Self

The resulting type after applying the / operator.

impl<'a, T> Div<&'a Vec4<T>> for Vec4<T> where
    T: Div<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the / operator.

impl<'a, T> Div<Vec4<T>> for &'a Vec4<T> where
    &'a T: Div<T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the / operator.

impl<'a, 'b, T> Div<&'a Vec4<T>> for &'b Vec4<T> where
    &'b T: Div<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the / operator.

impl<'a, T> Div<T> for &'a Vec4<T> where
    &'a T: Div<T, Output = T>,
    T: Copy
[src]

type Output = Vec4<T>

The resulting type after applying the / operator.

impl<'a, 'b, T> Div<&'a T> for &'b Vec4<T> where
    &'b T: Div<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the / operator.

impl<V, T> Rem<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: Rem<T, Output = T>, 
[src]

type Output = Self

The resulting type after applying the % operator.

impl<'a, T> Rem<&'a Vec4<T>> for Vec4<T> where
    T: Rem<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the % operator.

impl<'a, T> Rem<Vec4<T>> for &'a Vec4<T> where
    &'a T: Rem<T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the % operator.

impl<'a, 'b, T> Rem<&'a Vec4<T>> for &'b Vec4<T> where
    &'b T: Rem<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the % operator.

impl<'a, T> Rem<T> for &'a Vec4<T> where
    &'a T: Rem<T, Output = T>,
    T: Copy
[src]

type Output = Vec4<T>

The resulting type after applying the % operator.

impl<'a, 'b, T> Rem<&'a T> for &'b Vec4<T> where
    &'b T: Rem<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the % operator.

impl<V, T> Sub<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: Sub<T, Output = T>, 
[src]

type Output = Self

The resulting type after applying the - operator.

impl<'a, T> Sub<&'a Vec4<T>> for Vec4<T> where
    T: Sub<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the - operator.

impl<'a, T> Sub<Vec4<T>> for &'a Vec4<T> where
    &'a T: Sub<T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the - operator.

impl<'a, 'b, T> Sub<&'a Vec4<T>> for &'b Vec4<T> where
    &'b T: Sub<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the - operator.

impl<'a, T> Sub<T> for &'a Vec4<T> where
    &'a T: Sub<T, Output = T>,
    T: Copy
[src]

type Output = Vec4<T>

The resulting type after applying the - operator.

impl<'a, 'b, T> Sub<&'a T> for &'b Vec4<T> where
    &'b T: Sub<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the - operator.

impl<T: PartialEq> PartialEq<Vec4<T>> for Vec4<T>[src]

impl<T: Eq> Eq for Vec4<T>[src]

impl<V, T> Add<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: Add<T, Output = T>, 
[src]

type Output = Self

The resulting type after applying the + operator.

impl<'a, T> Add<&'a Vec4<T>> for Vec4<T> where
    T: Add<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the + operator.

impl<'a, T> Add<Vec4<T>> for &'a Vec4<T> where
    &'a T: Add<T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the + operator.

impl<'a, 'b, T> Add<&'a Vec4<T>> for &'b Vec4<T> where
    &'b T: Add<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the + operator.

impl<'a, T> Add<T> for &'a Vec4<T> where
    &'a T: Add<T, Output = T>,
    T: Copy
[src]

type Output = Vec4<T>

The resulting type after applying the + operator.

impl<'a, 'b, T> Add<&'a T> for &'b Vec4<T> where
    &'b T: Add<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the + operator.

impl Add<Vec4<i8>> for i8[src]

type Output = Vec4<i8>

The resulting type after applying the + operator.

impl Add<Vec4<u8>> for u8[src]

type Output = Vec4<u8>

The resulting type after applying the + operator.

impl Add<Vec4<i16>> for i16[src]

type Output = Vec4<i16>

The resulting type after applying the + operator.

impl Add<Vec4<u16>> for u16[src]

type Output = Vec4<u16>

The resulting type after applying the + operator.

impl Add<Vec4<i32>> for i32[src]

type Output = Vec4<i32>

The resulting type after applying the + operator.

impl Add<Vec4<u32>> for u32[src]

type Output = Vec4<u32>

The resulting type after applying the + operator.

impl Add<Vec4<i64>> for i64[src]

type Output = Vec4<i64>

The resulting type after applying the + operator.

impl Add<Vec4<u64>> for u64[src]

type Output = Vec4<u64>

The resulting type after applying the + operator.

impl Add<Vec4<f32>> for f32[src]

type Output = Vec4<f32>

The resulting type after applying the + operator.

impl Add<Vec4<f64>> for f64[src]

type Output = Vec4<f64>

The resulting type after applying the + operator.

impl<V, T> Mul<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: Mul<T, Output = T>, 
[src]

type Output = Self

The resulting type after applying the * operator.

impl<'a, T> Mul<&'a Vec4<T>> for Vec4<T> where
    T: Mul<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the * operator.

impl<'a, T> Mul<Vec4<T>> for &'a Vec4<T> where
    &'a T: Mul<T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the * operator.

impl<'a, 'b, T> Mul<&'a Vec4<T>> for &'b Vec4<T> where
    &'b T: Mul<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the * operator.

impl<'a, T> Mul<T> for &'a Vec4<T> where
    &'a T: Mul<T, Output = T>,
    T: Copy
[src]

type Output = Vec4<T>

The resulting type after applying the * operator.

impl<'a, 'b, T> Mul<&'a T> for &'b Vec4<T> where
    &'b T: Mul<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the * operator.

impl Mul<Vec4<i8>> for i8[src]

type Output = Vec4<i8>

The resulting type after applying the * operator.

impl Mul<Vec4<u8>> for u8[src]

type Output = Vec4<u8>

The resulting type after applying the * operator.

impl Mul<Vec4<i16>> for i16[src]

type Output = Vec4<i16>

The resulting type after applying the * operator.

impl Mul<Vec4<u16>> for u16[src]

type Output = Vec4<u16>

The resulting type after applying the * operator.

impl Mul<Vec4<i32>> for i32[src]

type Output = Vec4<i32>

The resulting type after applying the * operator.

impl Mul<Vec4<u32>> for u32[src]

type Output = Vec4<u32>

The resulting type after applying the * operator.

impl Mul<Vec4<i64>> for i64[src]

type Output = Vec4<i64>

The resulting type after applying the * operator.

impl Mul<Vec4<u64>> for u64[src]

type Output = Vec4<u64>

The resulting type after applying the * operator.

impl Mul<Vec4<f32>> for f32[src]

type Output = Vec4<f32>

The resulting type after applying the * operator.

impl Mul<Vec4<f64>> for f64[src]

type Output = Vec4<f64>

The resulting type after applying the * operator.

impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Mat4<T>> for Vec4<T>[src]

Multiplies a row vector with a column-major matrix, giving a row vector.

use vek::mat::column_major::Mat4;
use vek::vec::Vec4;

let m = Mat4::new(
    0, 1, 2, 3,
    4, 5, 6, 7,
    8, 9, 0, 1,
    2, 3, 4, 5
);
let v = Vec4::new(0, 1, 2, 3);
let r = Vec4::new(26, 32, 18, 24);
assert_eq!(v * m, r);

type Output = Self

The resulting type after applying the * operator.

impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Vec4<T>> for Mat4<T>[src]

Multiplies a column-major matrix with a column vector, giving a column vector.

With SIMD vectors, this is the most efficient way.

use vek::mat::column_major::Mat4;
use vek::vec::Vec4;

let m = Mat4::new(
    0, 1, 2, 3,
    4, 5, 6, 7,
    8, 9, 0, 1,
    2, 3, 4, 5
);
let v = Vec4::new(0, 1, 2, 3);
let r = Vec4::new(14, 38, 12, 26);
assert_eq!(m * v, r);

type Output = Vec4<T>

The resulting type after applying the * operator.

impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Mat4<T>> for Vec4<T>[src]

Multiplies a row vector with a row-major matrix, giving a row vector.

With SIMD vectors, this is the most efficient way.

use vek::mat::row_major::Mat4;
use vek::vec::Vec4;

let m = Mat4::new(
    0, 1, 2, 3,
    4, 5, 6, 7,
    8, 9, 0, 1,
    2, 3, 4, 5
);
let v = Vec4::new(0, 1, 2, 3);
let r = Vec4::new(26, 32, 18, 24);
assert_eq!(v * m, r);

type Output = Self

The resulting type after applying the * operator.

impl<T: MulAdd<T, T, Output = T> + Mul<Output = T> + Copy> Mul<Vec4<T>> for Mat4<T>[src]

Multiplies a row-major matrix with a column vector, giving a column vector.

use vek::mat::row_major::Mat4;
use vek::vec::Vec4;

let m = Mat4::new(
    0, 1, 2, 3,
    4, 5, 6, 7,
    8, 9, 0, 1,
    2, 3, 4, 5
);
let v = Vec4::new(0, 1, 2, 3);
let r = Vec4::new(14, 38, 12, 26);
assert_eq!(m * v, r);

type Output = Vec4<T>

The resulting type after applying the * operator.

impl<T: Real + Sum> Mul<Vec4<T>> for Quaternion<T>[src]

3D vectors can be rotated by being premultiplied by a quaternion, assuming the quaternion is normalized. On Vec4s, the w element is preserved, so you can safely rotate points and directions.

use std::f32::consts::PI;

let v = Vec4::unit_x();

let q = Quaternion::<f32>::identity();
assert_relative_eq!(q * v, v);

let q = Quaternion::rotation_z(PI);
assert_relative_eq!(q * v, -v);

let q = Quaternion::rotation_z(PI * 0.5);
assert_relative_eq!(q * v, Vec4::unit_y());

let q = Quaternion::rotation_z(PI * 1.5);
assert_relative_eq!(q * v, -Vec4::unit_y());

let angles = 32;
for i in 0..angles {
    let theta = PI * 2. * (i as f32) / (angles as f32);

    // See what rotating unit vectors do for most angles between 0 and 2*PI.
    // It's helpful to picture this as a right-handed coordinate system.

    let v = Vec4::unit_y();
    let q = Quaternion::rotation_x(theta);
    assert_relative_eq!(q * v, Vec4::new(0., theta.cos(), theta.sin(), 0.));

    let v = Vec4::unit_z();
    let q = Quaternion::rotation_y(theta);
    assert_relative_eq!(q * v, Vec4::new(theta.sin(), 0., theta.cos(), 0.));

    let v = Vec4::unit_x();
    let q = Quaternion::rotation_z(theta);
    assert_relative_eq!(q * v, Vec4::new(theta.cos(), theta.sin(), 0., 0.));
}

type Output = CVec4<T>

The resulting type after applying the * operator.

impl<T: Real + Sum> Mul<Vec4<T>> for Quaternion<T>[src]

3D vectors can be rotated by being premultiplied by a quaternion, assuming the quaternion is normalized. On Vec4s, the w element is preserved, so you can safely rotate points and directions.

use std::f32::consts::PI;

let v = Vec4::unit_x();

let q = Quaternion::<f32>::identity();
assert_relative_eq!(q * v, v);

let q = Quaternion::rotation_z(PI);
assert_relative_eq!(q * v, -v);

let q = Quaternion::rotation_z(PI * 0.5);
assert_relative_eq!(q * v, Vec4::unit_y());

let q = Quaternion::rotation_z(PI * 1.5);
assert_relative_eq!(q * v, -Vec4::unit_y());

let angles = 32;
for i in 0..angles {
    let theta = PI * 2. * (i as f32) / (angles as f32);

    // See what rotating unit vectors do for most angles between 0 and 2*PI.
    // It's helpful to picture this as a right-handed coordinate system.

    let v = Vec4::unit_y();
    let q = Quaternion::rotation_x(theta);
    assert_relative_eq!(q * v, Vec4::new(0., theta.cos(), theta.sin(), 0.));

    let v = Vec4::unit_z();
    let q = Quaternion::rotation_y(theta);
    assert_relative_eq!(q * v, Vec4::new(theta.sin(), 0., theta.cos(), 0.));

    let v = Vec4::unit_x();
    let q = Quaternion::rotation_z(theta);
    assert_relative_eq!(q * v, Vec4::new(theta.cos(), theta.sin(), 0., 0.));
}

type Output = Vec4<T>

The resulting type after applying the * operator.

impl<T> Neg for Vec4<T> where
    T: Neg<Output = T>, 
[src]

type Output = Self

The resulting type after applying the - operator.

impl<V, T> AddAssign<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: AddAssign<T>, 
[src]

impl<V, T> SubAssign<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: SubAssign<T>, 
[src]

impl<V, T> MulAssign<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: MulAssign<T>, 
[src]

impl<V, T> DivAssign<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: DivAssign<T>, 
[src]

impl<V, T> RemAssign<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: RemAssign<T>, 
[src]

impl<T> Not for Vec4<T> where
    T: Not<Output = T>, 
[src]

type Output = Self

The resulting type after applying the ! operator.

impl<V, T> BitAnd<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: BitAnd<T, Output = T>, 
[src]

type Output = Self

The resulting type after applying the & operator.

impl<'a, T> BitAnd<&'a Vec4<T>> for Vec4<T> where
    T: BitAnd<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the & operator.

impl<'a, T> BitAnd<Vec4<T>> for &'a Vec4<T> where
    &'a T: BitAnd<T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the & operator.

impl<'a, 'b, T> BitAnd<&'a Vec4<T>> for &'b Vec4<T> where
    &'b T: BitAnd<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the & operator.

impl<'a, T> BitAnd<T> for &'a Vec4<T> where
    &'a T: BitAnd<T, Output = T>,
    T: Copy
[src]

type Output = Vec4<T>

The resulting type after applying the & operator.

impl<'a, 'b, T> BitAnd<&'a T> for &'b Vec4<T> where
    &'b T: BitAnd<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the & operator.

impl<V, T> BitOr<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: BitOr<T, Output = T>, 
[src]

type Output = Self

The resulting type after applying the | operator.

impl<'a, T> BitOr<&'a Vec4<T>> for Vec4<T> where
    T: BitOr<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the | operator.

impl<'a, T> BitOr<Vec4<T>> for &'a Vec4<T> where
    &'a T: BitOr<T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the | operator.

impl<'a, 'b, T> BitOr<&'a Vec4<T>> for &'b Vec4<T> where
    &'b T: BitOr<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the | operator.

impl<'a, T> BitOr<T> for &'a Vec4<T> where
    &'a T: BitOr<T, Output = T>,
    T: Copy
[src]

type Output = Vec4<T>

The resulting type after applying the | operator.

impl<'a, 'b, T> BitOr<&'a T> for &'b Vec4<T> where
    &'b T: BitOr<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the | operator.

impl<V, T> BitXor<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: BitXor<T, Output = T>, 
[src]

type Output = Self

The resulting type after applying the ^ operator.

impl<'a, T> BitXor<&'a Vec4<T>> for Vec4<T> where
    T: BitXor<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the ^ operator.

impl<'a, T> BitXor<Vec4<T>> for &'a Vec4<T> where
    &'a T: BitXor<T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the ^ operator.

impl<'a, 'b, T> BitXor<&'a Vec4<T>> for &'b Vec4<T> where
    &'b T: BitXor<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the ^ operator.

impl<'a, T> BitXor<T> for &'a Vec4<T> where
    &'a T: BitXor<T, Output = T>,
    T: Copy
[src]

type Output = Vec4<T>

The resulting type after applying the ^ operator.

impl<'a, 'b, T> BitXor<&'a T> for &'b Vec4<T> where
    &'b T: BitXor<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the ^ operator.

impl<V, T> Shl<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: Shl<T, Output = T>, 
[src]

type Output = Self

The resulting type after applying the << operator.

impl<'a, T> Shl<&'a Vec4<T>> for Vec4<T> where
    T: Shl<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the << operator.

impl<'a, T> Shl<Vec4<T>> for &'a Vec4<T> where
    &'a T: Shl<T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the << operator.

impl<'a, 'b, T> Shl<&'a Vec4<T>> for &'b Vec4<T> where
    &'b T: Shl<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the << operator.

impl<'a, T> Shl<T> for &'a Vec4<T> where
    &'a T: Shl<T, Output = T>,
    T: Copy
[src]

type Output = Vec4<T>

The resulting type after applying the << operator.

impl<'a, 'b, T> Shl<&'a T> for &'b Vec4<T> where
    &'b T: Shl<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the << operator.

impl<V, T> Shr<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: Shr<T, Output = T>, 
[src]

type Output = Self

The resulting type after applying the >> operator.

impl<'a, T> Shr<&'a Vec4<T>> for Vec4<T> where
    T: Shr<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the >> operator.

impl<'a, T> Shr<Vec4<T>> for &'a Vec4<T> where
    &'a T: Shr<T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the >> operator.

impl<'a, 'b, T> Shr<&'a Vec4<T>> for &'b Vec4<T> where
    &'b T: Shr<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the >> operator.

impl<'a, T> Shr<T> for &'a Vec4<T> where
    &'a T: Shr<T, Output = T>,
    T: Copy
[src]

type Output = Vec4<T>

The resulting type after applying the >> operator.

impl<'a, 'b, T> Shr<&'a T> for &'b Vec4<T> where
    &'b T: Shr<&'a T, Output = T>, 
[src]

type Output = Vec4<T>

The resulting type after applying the >> operator.

impl<V, T> BitAndAssign<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: BitAndAssign<T>, 
[src]

impl<V, T> BitOrAssign<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: BitOrAssign<T>, 
[src]

impl<V, T> BitXorAssign<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: BitXorAssign<T>, 
[src]

impl<V, T> ShlAssign<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: ShlAssign<T>, 
[src]

impl<V, T> ShrAssign<V> for Vec4<T> where
    V: Into<Vec4<T>>,
    T: ShrAssign<T>, 
[src]

impl<T> Deref for Vec4<T>[src]

type Target = [T]

The resulting type after dereferencing.

impl<T> DerefMut for Vec4<T>[src]

impl<T: Hash> Hash for Vec4<T>[src]

impl<T: Copy> Copy for Vec4<T>[src]

impl<T> StructuralPartialEq for Vec4<T>[src]

impl<T> StructuralEq for Vec4<T>[src]

impl<T: Default> FromIterator<T> for Vec4<T>[src]

impl<'a, T> IntoIterator for &'a Vec4<T>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<'a, T> IntoIterator for &'a mut Vec4<T>[src]

type Item = &'a mut T

The type of the elements being iterated over.

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?

impl<T> IntoIterator for Vec4<T>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

impl<T> Sum<Vec4<T>> for Vec4<T> where
    T: Add<T, Output = T> + Zero
[src]

impl<T> Product<Vec4<T>> for Vec4<T> where
    T: Mul<T, Output = T> + One
[src]

impl<T> AsRef<[T]> for Vec4<T>[src]

impl<T> AsRef<Vec4<T>> for Vec4<T>[src]

impl<T> AsMut<[T]> for Vec4<T>[src]

impl<T> AsMut<Vec4<T>> for Vec4<T>[src]

impl<T: Clone> Clone for Vec4<T>[src]

impl<T: Default> Default for Vec4<T>[src]

impl<T> Borrow<[T]> for Vec4<T>[src]

impl<T> BorrowMut<[T]> for Vec4<T>[src]

impl<T: Zero + PartialEq> Zero for Vec4<T>[src]

impl<T: One> One for Vec4<T>[src]

impl<T: ApproxEq> ApproxEq for Vec4<T> where
    T::Epsilon: Copy
[src]

type Epsilon = T::Epsilon

Used for specifying relative comparisons.

Auto Trait Implementations

impl<T> Unpin for Vec4<T> where
    T: Unpin

impl<T> Send for Vec4<T> where
    T: Send

impl<T> Sync for Vec4<T> where
    T: Sync

impl<T> UnwindSafe for Vec4<T> where
    T: UnwindSafe

impl<T> RefUnwindSafe for Vec4<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> IsBetween01 for T where
    T: IsBetween<T> + Zero + One
[src]

impl<T> Clamp01 for T where
    T: Clamp<T> + Zero + One
[src]

impl<T> From<T> for T[src]

impl<T> From<!> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, Rhs, Output> NumOps<Rhs, Output> for T where
    T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>, 
[src]

impl<T, Base> RefNum<Base> for T where
    T: NumOps<Base, Base> + NumOps<&'r Base, Base>, 
[src]

impl<T, Rhs> NumAssignOps<Rhs> for T where
    T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>, 
[src]