[][src]Struct vex::Vector4

#[repr(C, packed)]pub struct Vector4 {
    pub x: f32,
    pub y: f32,
    pub z: f32,
    pub w: f32,
}

Fields

x: f32y: f32z: f32w: f32

Methods

impl Vector4[src]

pub fn new() -> Vector4[src]

Creates a vector <0.0, 0.0, 0.0, 0.0>

Examples

use vex::Vector4;
 
let actual = Vector4::new();
let expected = Vector4 { x: 0.0, y: 0.0, z: 0.0, w: 0.0 };
assert_eq!(actual, expected);

pub fn one() -> Vector4[src]

Creates a vector <0.0, 0.0, 0.0, 0.0>

Examples

use vex::Vector4;
 
let actual = Vector4::one();
let expected = Vector4 { x: 1.0, y: 1.0, z: 1.0, w: 1.0 };
assert_eq!(actual, expected);

pub fn make(x: f32, y: f32, z: f32, w: f32) -> Vector4[src]

Creates a vector from the provided values

Examples

use vex::Vector4;
 
let actual = Vector4::make(1.0, 2.0, 3.0, 4.0);
let expected = Vector4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 };
assert_eq!(actual, expected);

pub fn dot(a: &Vector4, b: &Vector4) -> f32[src]

Find the dot product between two vectors

Examples

use vex::Vector4;
 
let a = Vector4::make(1.0, 0.0, 0.0, 0.0);
let b = Vector4::make(0.0, 0.0, 1.0, 0.0);
let actual = Vector4::dot(&a, &b);
let expected = 0.0;
assert_eq!(actual, expected);

pub fn min(a: &Vector4, b: &Vector4) -> Vector4[src]

Find the minimum (component-wise) vector between two vectors

Examples

use vex::Vector4;
 
let a = Vector4::make(1.0, 4.0, 5.0, 7.0);
let b = Vector4::make(2.0, 3.0, 6.0, 8.0);
let actual = Vector4::min(&a, &b);
let expected = Vector4::make(1.0, 3.0, 5.0, 7.0);
assert_eq!(actual, expected);

pub fn max(a: &Vector4, b: &Vector4) -> Vector4[src]

Find the maximum (component-wise) vector between two vectors

Examples

use vex::Vector4;
 
let a = Vector4::make(1.0, 4.0, 5.0, 7.0);
let b = Vector4::make(2.0, 3.0, 6.0, 8.0);
let actual = Vector4::max(&a, &b);
let expected = Vector4::make(2.0, 4.0, 6.0, 8.0);
assert_eq!(actual, expected);

pub fn clamp(&mut self, a: &Vector4, b: &Vector4)[src]

Find the clamped (component-wise) vector between two vectors

Examples

use vex::Vector4;
 
let a = Vector4::make(1.0, 3.0, 5.0, 7.0);
let b = Vector4::make(2.0, 4.0, 6.0, 8.0);
let mut actual = Vector4::make(0.0, 5.0, 10.0, 20.0);
actual.clamp(&a, &b);
let expected = Vector4::make(1.0, 4.0, 6.0, 8.0);
assert_eq!(actual, expected);

pub fn set(&mut self, x: f32, y: f32, z: f32, w: f32)[src]

Set the components of a vector

Examples

use vex::Vector4;
 
let mut actual = Vector4::new();
actual.set(1.0, 2.0, 3.0, 4.0);
let expected = Vector4::make(1.0, 2.0, 3.0, 4.0);
assert_eq!(actual, expected);

pub fn mag(&self) -> f32[src]

Get the magnitude of the vector

Examples

use vex::Vector4;
 
let actual = Vector4::make(1.0, 2.0, 3.0, 4.0).mag();
let expected = 5.47722557505;
assert_eq!(actual, expected);

pub fn mag_sq(&self) -> f32[src]

Get the squared magnitude of the vector

Examples

use vex::Vector4;
 
let actual = Vector4::make(1.0, 2.0, 3.0, 4.0).mag_sq();
let expected = 30.0;
assert_eq!(actual, expected);

pub fn norm(&mut self) -> f32[src]

Normalize the vector

Examples

use vex::Vector4;
 
let mut actual = Vector4::make(1.0, 2.0, 3.0, 4.0);
actual.norm();
let expected = Vector4::make(0.18257418, 0.36514837, 0.5477225, 0.73029673);
assert_eq!(actual, expected);

pub fn abs(&mut self)[src]

Set the components of a vector to their absolute values

Examples

use vex::Vector4;
 
let mut actual = Vector4::make(-1.0, -2.0, -3.0, -4.0);
actual.abs();
let expected = Vector4::make(1.0, 2.0, 3.0, 4.0);
assert_eq!(actual, expected);

pub fn is_valid(&self) -> bool[src]

Determine whether or not all components of the vector are valid

Examples

use vex::Vector4;
 
let actual = Vector4::make(1.0, 2.0, 3.0, 4.0);
assert!(actual.is_valid());

Trait Implementations

impl Add<Vector4> for Vector4[src]

type Output = Vector4

The resulting type after applying the + operator.

fn add(self, _rhs: Vector4) -> Vector4[src]

Add two vectors

Examples

use vex::Vector4;
 
let a = Vector4::make(1.0, 2.0, 3.0, 4.0);
let b = Vector4::make(5.0, 6.0, 7.0, 8.0);
let actual = a + b;
let expected = Vector4::make(6.0, 8.0, 10.0, 12.0);
assert_eq!(actual, expected);

impl Add<f32> for Vector4[src]

type Output = Vector4

The resulting type after applying the + operator.

fn add(self, _rhs: f32) -> Vector4[src]

Find the resulting vector by adding a scalar to a vector's components

Examples

use vex::Vector4;
 
let actual = Vector4::make(1.0, 2.0, 3.0, 4.0) + 1.0;
let expected = Vector4::make(2.0, 3.0, 4.0, 5.0);
assert_eq!(actual, expected);

impl AddAssign<Vector4> for Vector4[src]

fn add_assign(&mut self, _rhs: Vector4)[src]

Increment a vector by another vector

Examples

use vex::Vector4;
 
let mut actual = Vector4::make(1.0, 2.0, 3.0, 4.0);
actual += Vector4::make(1.0, 2.0, 3.0, 4.0);
let expected = Vector4::make(2.0, 4.0, 6.0, 8.0);
assert_eq!(actual, expected);

impl AddAssign<f32> for Vector4[src]

fn add_assign(&mut self, _rhs: f32)[src]

Increment a vector by a scalar

Examples

use vex::Vector4;
 
let mut actual = Vector4::make(1.0, 2.0, 3.0, 4.0);
actual += 10.0;
let expected = Vector4::make(11.0, 12.0, 13.0, 14.0);
assert_eq!(actual, expected);

impl Clone for Vector4[src]

impl Copy for Vector4[src]

impl Debug for Vector4[src]

impl Display for Vector4[src]

impl Div<Vector4> for Vector4[src]

type Output = Vector4

The resulting type after applying the / operator.

fn div(self, _rhs: Vector4) -> Vector4[src]

Divide two vectors

Examples

use vex::Vector4;
 
let a = Vector4::make(2.0, 4.0, 6.0, 8.0);
let b = Vector4::make(1.0, 4.0, 12.0, 32.0);
let actual = a / b;
let expected = Vector4::make(2.0, 1.0, 0.5, 0.25);
assert_eq!(actual, expected);

impl Div<f32> for Vector4[src]

type Output = Vector4

The resulting type after applying the / operator.

fn div(self, _rhs: f32) -> Vector4[src]

Find the resulting vector by dividing a scalar to a vector's components

Examples

use vex::Vector4;
 
let actual = Vector4::make(1.0, 2.0, 3.0, 4.0) / 2.0;
let expected = Vector4::make(0.5, 1.0, 1.5, 2.0);
assert_eq!(actual, expected);

impl DivAssign<Vector4> for Vector4[src]

fn div_assign(&mut self, _rhs: Vector4)[src]

Divide a vector by another vector

Examples

use vex::Vector4;
 
let mut actual = Vector4::make(2.0, 4.0, 6.0, 8.0);
actual /= Vector4::make(1.0, 4.0, 12.0, 32.0);
let expected = Vector4::make(2.0, 1.0, 0.5, 0.25);
assert_eq!(actual, expected);

impl DivAssign<f32> for Vector4[src]

fn div_assign(&mut self, _rhs: f32)[src]

Divide a vector by a scalar

Examples

use vex::Vector4;
 
let mut actual = Vector4::make(1.0, 2.0, 3.0, 4.0);
actual /= 2.0;
let expected = Vector4::make(0.5, 1.0, 1.5, 2.0);
assert_eq!(actual, expected);

impl From<Vector3> for Vector4[src]

fn from(item: Vector3) -> Vector4[src]

Creates a Vector4 from the components of a Vector3

Examples

use vex::Vector3;
use vex::Vector4;
 
let input = Vector3::make(1.0, 2.0, 3.0);
let actual = Vector4::from(input);
let expected = Vector4 { x: 1.0, y: 2.0, z: 3.0, w: 0.0 };
assert_eq!(actual, expected);

impl From<Vector4> for Vector3[src]

fn from(item: Vector4) -> Vector3[src]

Creates a Vector3 from the components of a Vector4

Examples

use vex::Vector3;
use vex::Vector4;
 
let input = Vector4::make(1.0, 2.0, 3.0, 4.0);
let actual = Vector3::from(input);
let expected = Vector3 { x: 1.0, y: 2.0, z: 3.0 };
assert_eq!(actual, expected);

impl Index<u32> for Vector4[src]

type Output = f32

The returned type after indexing.

fn index(&self, index: u32) -> &f32[src]

Looks up a component by index

Examples

use vex::Vector4;
 
let mut v = Vector4::make(1.0, 2.0, 3.0, 4.0);
assert_eq!(v[0], 1.0);
assert_eq!(v[1], 2.0);
assert_eq!(v[2], 3.0);
assert_eq!(v[3], 4.0);

impl IndexMut<u32> for Vector4[src]

fn index_mut<'a>(&'a mut self, index: u32) -> &'a mut f32[src]

Mutate a component by index

Examples

use vex::Vector4;
 
let mut v = Vector4::new();
v[0] = 4.0;
v[1] = 5.0;
v[2] = 6.0;
v[3] = 7.0;
assert_eq!(v[0], 4.0);
assert_eq!(v[1], 5.0);
assert_eq!(v[2], 6.0);
assert_eq!(v[3], 7.0);

impl Matrix<Vector4> for Matrix4[src]

fn transform_point(&self, point: &Vector4) -> Vector4[src]

Find the resulting vector given a vector and matrix

Examples

use vex::Matrix;
use vex::Matrix4;
use vex::Vector4;
 
let m = Matrix4::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0);
let v = Vector4::make(1.0, 2.0, 3.0, 4.0);
let actual = m.transform_point(&v);
let expected = Vector4::make(90.0, 100.0, 110.0, 120.0);
assert_eq!(actual, expected);

impl Mul<Vector4> for Vector4[src]

type Output = Vector4

The resulting type after applying the * operator.

fn mul(self, _rhs: Vector4) -> Vector4[src]

Multiply two vectors

Examples

use vex::Vector4;
 
let a = Vector4::make(1.0, 2.0, 3.0, 4.0);
let b = Vector4::make(5.0, 6.0, 7.0, 8.0);
let actual = a * b;
let expected = Vector4::make(5.0, 12.0, 21.0, 32.0);
assert_eq!(actual, expected);

impl Mul<f32> for Vector4[src]

type Output = Vector4

The resulting type after applying the * operator.

fn mul(self, _rhs: f32) -> Vector4[src]

Find the resulting vector by multiplying a scalar to a vector's components

Examples

use vex::Vector4;
 
let actual = Vector4::make(1.0, 2.0, 3.0, 4.0) * 2.0;
let expected = Vector4::make(2.0, 4.0, 6.0, 8.0);
assert_eq!(actual, expected);

impl MulAssign<Vector4> for Vector4[src]

fn mul_assign(&mut self, _rhs: Vector4)[src]

Multiply a vector by another vector

Examples

use vex::Vector4;
 
let mut actual = Vector4::make(1.0, 2.0, 3.0, 4.0);
actual *= Vector4::make(2.0, 3.0, 6.0, 8.0);
let expected = Vector4::make(2.0, 6.0, 18.0, 32.0);
assert_eq!(actual, expected);

impl MulAssign<f32> for Vector4[src]

fn mul_assign(&mut self, _rhs: f32)[src]

Multiply a vector by a scalar

Examples

use vex::Vector4;
 
let mut actual = Vector4::make(1.0, 2.0, 3.0, 4.0);
actual *= 2.0;
let expected = Vector4::make(2.0, 4.0, 6.0, 8.0);
assert_eq!(actual, expected);

impl Neg for Vector4[src]

type Output = Vector4

The resulting type after applying the - operator.

fn neg(self) -> Vector4[src]

Negates all components in a vector

Examples

use vex::Vector4;
 
let actual = -Vector4::make(1.0, 2.0, 3.0, 4.0);
let expected = Vector4::make(-1.0, -2.0, -3.0, -4.0);
assert_eq!(actual, expected);

impl PartialEq<Vector4> for Vector4[src]

fn eq(&self, _rhs: &Vector4) -> bool[src]

Determines if two vectors' components are equivalent

Examples

use vex::Vector4;
 
assert!(Vector4::new() == Vector4::new());

impl Sub<Vector4> for Vector4[src]

type Output = Vector4

The resulting type after applying the - operator.

fn sub(self, _rhs: Vector4) -> Vector4[src]

Subtract two vectors

Examples

use vex::Vector4;
 
let a = Vector4::make(1.0, 2.0, 3.0, 4.0);
let b = Vector4::make(5.0, 4.0, 3.0, 2.0);
let actual = a - b;
let expected = Vector4::make(-4.0, -2.0, 0.0, 2.0);
assert_eq!(actual, expected);

impl Sub<f32> for Vector4[src]

type Output = Vector4

The resulting type after applying the - operator.

fn sub(self, _rhs: f32) -> Vector4[src]

Find the resulting vector by subtracting a scalar from a vector's components

Examples

use vex::Vector4;
 
let actual = Vector4::make(1.0, 2.0, 3.0, 4.0) - 10.0;
let expected = Vector4::make(-9.0, -8.0, -7.0, -6.0);
assert_eq!(actual, expected);

impl SubAssign<Vector4> for Vector4[src]

fn sub_assign(&mut self, _rhs: Vector4)[src]

Decrement a vector by another vector

Examples

use vex::Vector4;
 
let mut actual = Vector4::make(1.0, 2.0, 3.0, 4.0);
actual -= Vector4::make(1.0, 2.0, 3.0, 4.0);
assert_eq!(actual, Vector4::new());

impl SubAssign<f32> for Vector4[src]

fn sub_assign(&mut self, _rhs: f32)[src]

Decrement a vector by a scalar

Examples

use vex::Vector4;
 
let mut actual = Vector4::make(1.0, 2.0, 3.0, 4.0);
actual -= 1.0;
let expected = Vector4::make(0.0, 1.0, 2.0, 3.0);
assert_eq!(actual, expected);

Auto Trait Implementations

impl RefUnwindSafe for Vector4

impl Send for Vector4

impl Sync for Vector4

impl Unpin for Vector4

impl UnwindSafe for Vector4

Blanket Implementations

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

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

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

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[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, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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.