Struct Vec4

Source
pub struct Vec4 {
    pub x: f32,
    pub y: f32,
    pub z: f32,
    pub w: f32,
}

Fields§

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

Implementations§

Source§

impl Vec4

Source

pub fn new(x: f32, y: f32, z: f32, w: f32) -> Vec4

§Create a new instance of Vec4
use ck::Vec4;

let v = Vec4::new(1.0, 2.0, 3.0, 4.0);
assert_eq!(v.x, 1.0);
assert_eq!(v.y, 2.0);
assert_eq!(v.z, 3.0);
assert_eq!(v.w, 4.0);
Source

pub fn len(&self) -> f32

§Get the length of a Vec4
use ck::Vec4;

let v = Vec4::new(1.0, 2.0, 3.0, 5.0);
let a = v.len() * 1000.0;

// Rounding the result to account for f32 precision.
assert_eq!(a.round(), 6245.0);
Source

pub fn len_squared(&self) -> f32

§Get the squared length of a Vec4
use ck::Vec4;

let v = Vec4::new(1.0, 2.0, 3.0, 5.0);
assert_eq!(v.len_squared(), 39.0);
Source

pub fn normalize(&self) -> Vec4

§Get a new normalized version of a Vec4
use ck::Vec4;

let v = Vec4::new(1.0, 2.0, 3.0, 5.0);
let vn = v.normalize();

assert_eq!(vn.x, 1.0/v.len());
assert_eq!(vn.y, 2.0/v.len());
assert_eq!(vn.z, 3.0/v.len());
assert_eq!(vn.w, 5.0/v.len());
Source

pub fn raw(&self) -> [f32; 4]

§Get the raw data represented by a Vec4
use ck::Vec4;

let v = Vec4::new(1.0, 2.0, 3.0, 4.0);
let r: [f32; 4] = v.raw();
assert_eq!(v.x, r[0]);
assert_eq!(v.y, r[1]);
assert_eq!(v.z, r[2]);
assert_eq!(v.w, r[3]);
Source

pub fn dot(&self, other: &Vec4) -> f32

§Get the dot product of two Vec4
use ck::Vec4;

let v1 = Vec4::new(1.0, 2.0, 3.0, 4.0);
let v2 = Vec4::new(5.0, 6.0, 7.0, 8.0);
let res: f32 = v1.dot(&v2);
assert_eq!(res, 70.0);

Trait Implementations§

Source§

impl Add for Vec4

Source§

fn add(self, other: Vec4) -> Vec4

Overload the + operator for Vec4

§Examples
use ck::Vec4;

let v1 = Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 };
let v2 = Vec4 { x: 5.0, y: 6.0, z: 7.0, w: 8.0 };
let v = v1 + v2;

assert_eq!(v.x,  6.0);
assert_eq!(v.y,  8.0);
assert_eq!(v.z, 10.0);
assert_eq!(v.w, 12.0);
Source§

type Output = Vec4

The resulting type after applying the + operator.
Source§

impl Debug for Vec4

Source§

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

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

impl Index<usize> for Vec4

Source§

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

Indexing for Vec4 instead of field access by name

§Examples
use ck::Vec4;

let v = Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 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);
Source§

type Output = f32

The returned type after indexing.
Source§

impl IndexMut<usize> for Vec4

Source§

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

Mutable indexing for Vec4 instead of setting fields by name

§Examples
use ck::Vec4;

let mut v = Vec4 { x: 0.0, y: 0.0, z: 0.0, w: 0.0 };
v[0] = 1.0;
v[1] = 2.0;
v[2] = 3.0;
v[3] = 4.0;
assert_eq!(v.x, 1.0);
assert_eq!(v.y, 2.0);
assert_eq!(v.z, 3.0);
assert_eq!(v.w, 4.0);
Source§

impl Sub for Vec4

Source§

fn sub(self, other: Vec4) -> Vec4

Overload the - operator for Vec4

§Examples
use ck::Vec4;

let v1 = Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 };
let v2 = Vec4 { x: 8.0, y: 7.0, z: 6.0, w: 5.0 };
let v = v1 - v2;

assert_eq!(v.x, -7.0);
assert_eq!(v.y, -5.0);
assert_eq!(v.z, -3.0);
assert_eq!(v.w, -1.0);
Source§

type Output = Vec4

The resulting type after applying the - operator.

Auto Trait Implementations§

§

impl Freeze for Vec4

§

impl RefUnwindSafe for Vec4

§

impl Send for Vec4

§

impl Sync for Vec4

§

impl Unpin for Vec4

§

impl UnwindSafe for Vec4

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