Struct Vector3

Source
#[repr(C, packed(1))]
pub struct Vector3 { pub x: f32, pub y: f32, pub z: f32, }

Fields§

§x: f32§y: f32§z: f32

Implementations§

Source§

impl Vector3

Source

pub fn new() -> Vector3

Creates a vector <0.0, 0.0, 0.0>

§Examples
use vex::Vector3;
 
let actual = Vector3::new();
let expected = Vector3 { x: 0.0, y: 0.0, z: 0.0 };
assert_eq!(actual, expected);
Source

pub fn one() -> Vector3

Creates a vector <1.0, 1.0, 1.0>

§Examples
use vex::Vector3;
 
let actual = Vector3::one();
let expected = Vector3 { x: 1.0, y: 1.0, z: 1.0 };
assert_eq!(actual, expected);
Source

pub fn right() -> Vector3

Creates a right vector

§Examples
use vex::Vector3;
 
let actual = Vector3::right();
let expected = Vector3 { x: 1.0, y: 0.0, z: 0.0 };
assert_eq!(actual, expected);
Source

pub fn up() -> Vector3

Creates an up vector

§Examples
use vex::Vector3;
let actual = Vector3::up();
let expected = Vector3 { x: 0.0, y: 1.0, z: 0.0 };
assert_eq!(actual, expected);
Source

pub fn forward() -> Vector3

Creates a forward vector

§Examples
use vex::Vector3;
 
let actual = Vector3::forward();
let expected = Vector3 { x: 0.0, y: 0.0, z: -1.0 };
assert_eq!(actual, expected);
Source

pub fn make(x: f32, y: f32, z: f32) -> Vector3

Creates a vector from the provided values

§Examples
use vex::Vector3;
 
let actual = Vector3::make(1.0, 2.0, 3.0);
let expected = Vector3 { x: 1.0, y: 2.0, z: 3.0 };
assert_eq!(actual, expected);
Source

pub fn dot(a: &Vector3, b: &Vector3) -> f32

Find the dot product between two vectors

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

pub fn cross(a: &Vector3, b: &Vector3) -> Vector3

Find the cross product between two vectors

§Examples
use vex::Vector3;
 
let a = Vector3::make(0.0, 0.0, 1.0);
let b = Vector3::make(1.0, 0.0, 0.0);
let actual = Vector3::cross(&a, &b);
let expected = Vector3::make(0.0, 1.0, 0.0);
assert_eq!(actual, expected);
Source

pub fn min(a: &Vector3, b: &Vector3) -> Vector3

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

§Examples
use vex::Vector3;
 
let a = Vector3::make(1.0, 4.0, 5.0);
let b = Vector3::make(2.0, 3.0, 6.0);
let actual = Vector3::min(&a, &b);
let expected = Vector3::make(1.0, 3.0, 5.0);
assert_eq!(actual, expected);
Source

pub fn max(a: &Vector3, b: &Vector3) -> Vector3

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

§Examples
use vex::Vector3;
 
let a = Vector3::make(1.0, 4.0, 5.0);
let b = Vector3::make(2.0, 3.0, 6.0);
let actual = Vector3::max(&a, &b);
let expected = Vector3::make(2.0, 4.0, 6.0);
assert_eq!(actual, expected);
Source

pub fn clamp(&mut self, a: &Vector3, b: &Vector3)

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

§Examples
use vex::Vector3;
 
let a = Vector3::make(1.0, 3.0, 5.0);
let b = Vector3::make(2.0, 4.0, 6.0);
let mut actual = Vector3::make(0.0, 5.0, 10.0);
actual.clamp(&a, &b);
let expected = Vector3::make(1.0, 4.0, 6.0);
assert_eq!(actual, expected);
Source

pub fn set(&mut self, x: f32, y: f32, z: f32)

Set the components of a vector

§Examples
use vex::Vector3;
 
let mut actual = Vector3::new();
actual.set(1.0, 2.0, 3.0);
let expected = Vector3::make(1.0, 2.0, 3.0);
assert_eq!(actual, expected);
Source

pub fn mag(&self) -> f32

Get the magnitude of the vector

§Examples
use vex::Vector3;
 
let actual = Vector3::make(1.0, 2.0, 3.0).mag();
let expected = 3.74165738677;
assert_eq!(actual, expected);
Source

pub fn mag_sq(&self) -> f32

Get the squared magnitude of the vector

§Examples
use vex::Vector3;
 
let actual = Vector3::make(1.0, 2.0, 3.0).mag_sq();
let expected = 14.0;
assert_eq!(actual, expected);
Source

pub fn norm(&mut self) -> f32

Normalize the vector

§Examples
use vex::Vector3;
 
let mut actual = Vector3::make(1.0, 2.0, 3.0);
actual.norm();
let expected = Vector3::make(0.26726124191, 0.53452248382, 0.8017837);
assert_eq!(actual, expected);
Source

pub fn abs(&mut self)

Set the components of a vector to their absolute values

§Examples
use vex::Vector3;
 
let mut actual = Vector3::make(-1.0, -2.0, -3.0);
actual.abs();
let expected = Vector3::make(1.0, 2.0, 3.0);
assert_eq!(actual, expected);
Source

pub fn is_valid(&self) -> bool

Determine whether or not all components of the vector are valid

§Examples
use vex::Vector3;
 
let actual = Vector3::make(1.0, 2.0, 3.0);
assert!(actual.is_valid());

Trait Implementations§

Source§

impl Add<f32> for Vector3

Source§

fn add(self, _rhs: f32) -> Vector3

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

§Examples
use vex::Vector3;
 
let actual = Vector3::make(1.0, 2.0, 3.0) + 1.0;
let expected = Vector3::make(2.0, 3.0, 4.0);
assert_eq!(actual, expected);
Source§

type Output = Vector3

The resulting type after applying the + operator.
Source§

impl Add for Vector3

Source§

fn add(self, _rhs: Vector3) -> Vector3

Add two vectors

§Examples
use vex::Vector3;
 
let a = Vector3::make(1.0, 2.0, 3.0);
let b = Vector3::make(4.0, 5.0, 6.0);
let actual = a + b;
let expected = Vector3::make(5.0, 7.0, 9.0);
assert_eq!(actual, expected);
Source§

type Output = Vector3

The resulting type after applying the + operator.
Source§

impl AddAssign<f32> for Vector3

Source§

fn add_assign(&mut self, _rhs: f32)

Increment a vector by a scalar

§Examples
use vex::Vector3;
 
let mut actual = Vector3::make(1.0, 2.0, 3.0);
actual += 10.0;
let expected = Vector3::make(11.0, 12.0, 13.0);
assert_eq!(actual, expected);
Source§

impl AddAssign for Vector3

Source§

fn add_assign(&mut self, _rhs: Vector3)

Increment a vector by another vector

§Examples
use vex::Vector3;
 
let mut actual = Vector3::make(1.0, 2.0, 3.0);
actual += Vector3::make(1.0, 2.0, 3.0);
let expected = Vector3::make(2.0, 4.0, 6.0);
assert_eq!(actual, expected);
Source§

impl Clone for Vector3

Source§

fn clone(&self) -> Vector3

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 Vector3

Source§

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

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

impl Display for Vector3

Source§

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

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

impl Div<f32> for Vector3

Source§

fn div(self, _rhs: f32) -> Vector3

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

§Examples
use vex::Vector3;
 
let actual = Vector3::make(1.0, 2.0, 3.0) / 2.0;
let expected = Vector3::make(0.5, 1.0, 1.5);
assert_eq!(actual, expected);
Source§

type Output = Vector3

The resulting type after applying the / operator.
Source§

impl Div for Vector3

Source§

fn div(self, _rhs: Vector3) -> Vector3

Divide two vectors

§Examples
use vex::Vector3;
 
let a = Vector3::make(1.0, 2.0, 4.0);
let b = Vector3::make(2.0, 8.0, 32.0);
let actual = a / b;
let expected = Vector3::make(0.5, 0.25, 0.125);
assert_eq!(actual, expected);
Source§

type Output = Vector3

The resulting type after applying the / operator.
Source§

impl DivAssign<f32> for Vector3

Source§

fn div_assign(&mut self, _rhs: f32)

Divide a vector by a scalar

§Examples
use vex::Vector3;
 
let mut actual = Vector3::make(1.0, 2.0, 3.0);
actual /= 2.0;
let expected = Vector3::make(0.5, 1.0, 1.5);
assert_eq!(actual, expected);
Source§

impl DivAssign for Vector3

Source§

fn div_assign(&mut self, _rhs: Vector3)

Divide a vector by another vector

§Examples
use vex::Vector3;
 
let mut actual = Vector3::make(1.0, 2.0, 4.0);
actual /= Vector3::make(2.0, 8.0, 32.0);
let expected = Vector3::make(0.5, 0.25, 0.125);
assert_eq!(actual, expected);
Source§

impl From<Vector2> for Vector3

Source§

fn from(item: Vector2) -> Vector3

Creates a Vector3 from the components of a Vector2

§Examples
use vex::Vector2;
use vex::Vector3;
 
let input = Vector2::make(1.0, 2.0);
let actual = Vector3::from(input);
let expected = Vector3 { x: 1.0, y: 2.0, z: 0.0 };
assert_eq!(actual, expected);
Source§

impl From<Vector3> for Vector2

Source§

fn from(item: Vector3) -> Self

Creates a Vector2 from the components of a Vector3

§Examples
use vex::Vector2;
use vex::Vector3;
 
let input = Vector3::make(1.0, 2.0, 3.0);
let actual = Vector2::from(input);
let expected = Vector2 { x: 1.0, y: 2.0 };
assert_eq!(actual, expected);
Source§

impl From<Vector3> for Vector4

Source§

fn from(item: Vector3) -> Vector4

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);
Source§

impl From<Vector4> for Vector3

Source§

fn from(item: Vector4) -> Vector3

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);
Source§

impl Index<u32> for Vector3

Source§

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

Looks up a component by index

§Examples
use vex::Vector3;
 
let mut v = Vector3::make(1.0, 2.0, 3.0);
assert_eq!(v[0], 1.0);
assert_eq!(v[1], 2.0);
assert_eq!(v[2], 3.0);
Source§

type Output = f32

The returned type after indexing.
Source§

impl IndexMut<u32> for Vector3

Source§

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

Mutate a component by index

§Examples
use vex::Vector3;
 
let mut v = Vector3::new();
v[0] = 4.0;
v[1] = 5.0;
v[2] = 6.0;
assert_eq!(v[0], 4.0);
assert_eq!(v[1], 5.0);
assert_eq!(v[2], 6.0);
Source§

impl Matrix<Vector3> for Matrix3

Source§

fn transform_point(&self, point: &Vector3) -> Vector3

Find the resulting vector given a vector and matrix

§Examples
use vex::Matrix;
use vex::Matrix3;
use vex::Vector3;
 
let m = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
let v = Vector3::make(1.0, 2.0, 3.0);
let actual = m.transform_point(&v);
let expected = Vector3::make(30.0, 36.0, 42.0);
assert_eq!(actual, expected);
Source§

impl Matrix<Vector3> for Matrix4

Source§

fn transform_point(&self, point: &Vector3) -> Vector3

Find the resulting vector given a vector and matrix

§Examples
use vex::Matrix;
use vex::Matrix4;
use vex::Vector3;
 
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 = Vector3::make(1.0, 2.0, 3.0);
let actual = m.transform_point(&v);
let expected = Vector3::make(51.0, 58.0, 65.0);
assert_eq!(actual, expected);
Source§

impl Mul<f32> for Vector3

Source§

fn mul(self, _rhs: f32) -> Vector3

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

§Examples
use vex::Vector3;
 
let actual = Vector3::make(1.0, 2.0, 3.0) * 2.0;
let expected = Vector3::make(2.0, 4.0, 6.0);
assert_eq!(actual, expected);
Source§

type Output = Vector3

The resulting type after applying the * operator.
Source§

impl Mul for Vector3

Source§

fn mul(self, _rhs: Vector3) -> Vector3

Multiply two vectors

§Examples
use vex::Vector3;
 
let a = Vector3::make(1.0, 2.0, 3.0);
let b = Vector3::make(3.0, 4.0, 5.0);
let actual = a * b;
let expected = Vector3::make(3.0, 8.0, 15.0);
assert_eq!(actual, expected);
Source§

type Output = Vector3

The resulting type after applying the * operator.
Source§

impl MulAssign<f32> for Vector3

Source§

fn mul_assign(&mut self, _rhs: f32)

Multiply a vector by a scalar

§Examples
use vex::Vector3;
 
let mut actual = Vector3::make(1.0, 2.0, 3.0);
actual *= 2.0;
let expected = Vector3::make(2.0, 4.0, 6.0);
assert_eq!(actual, expected);
Source§

impl MulAssign for Vector3

Source§

fn mul_assign(&mut self, _rhs: Vector3)

Multiply a vector by another vector

§Examples
use vex::Vector3;
 
let mut actual = Vector3::make(1.0, 2.0, 3.0);
actual *= Vector3::make(2.0, 3.0, 6.0);
let expected = Vector3::make(2.0, 6.0, 18.0);
assert_eq!(actual, expected);
Source§

impl Neg for Vector3

Source§

fn neg(self) -> Vector3

Negates all components in a vector

§Examples
use vex::Vector3;
 
let actual = -Vector3::make(1.0, 2.0, 3.0);
let expected = Vector3::make(-1.0, -2.0, -3.0);
assert_eq!(actual, expected);
Source§

type Output = Vector3

The resulting type after applying the - operator.
Source§

impl PartialEq for Vector3

Source§

fn eq(&self, _rhs: &Vector3) -> bool

Determines if two vectors’ components are equivalent

§Examples
use vex::Vector3;
 
assert!(Vector3::new() == Vector3::new());
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<f32> for Vector3

Source§

fn sub(self, _rhs: f32) -> Vector3

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

§Examples
use vex::Vector3;
 
let actual = Vector3::make(1.0, 2.0, 3.0) - 10.0;
let expected = Vector3::make(-9.0, -8.0, -7.0);
assert_eq!(actual, expected);
Source§

type Output = Vector3

The resulting type after applying the - operator.
Source§

impl Sub for Vector3

Source§

fn sub(self, _rhs: Vector3) -> Vector3

Subtract two vectors

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

type Output = Vector3

The resulting type after applying the - operator.
Source§

impl SubAssign<f32> for Vector3

Source§

fn sub_assign(&mut self, _rhs: f32)

Decrement a vector by a scalar

§Examples
use vex::Vector3;
 
let mut actual = Vector3::make(1.0, 2.0, 3.0);
actual -= 1.0;
let expected = Vector3::make(0.0, 1.0, 2.0);
assert_eq!(actual, expected);
Source§

impl SubAssign for Vector3

Source§

fn sub_assign(&mut self, _rhs: Vector3)

Decrement a vector by another vector

§Examples
use vex::Vector3;
 
let mut actual = Vector3::make(1.0, 2.0, 3.0);
actual -= Vector3::make(1.0, 2.0, 3.0);
assert_eq!(actual, Vector3::new());
Source§

impl Copy for Vector3

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.