Struct ck::Vec4
[−]
[src]
pub struct Vec4 { pub x: f32, pub y: f32, pub z: f32, pub w: f32, }
Fields
x: f32
y: f32
z: f32
w: f32
Methods
impl Vec4
[src]
fn new(x: f32, y: f32, z: f32, w: f32) -> Vec4
[src]
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);
fn len(&self) -> f32
[src]
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);
fn len_squared(&self) -> f32
[src]
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);
fn normalize(&self) -> Vec4
[src]
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());
fn raw(&self) -> [f32; 4]
[src]
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]);
fn dot(&self, other: &Vec4) -> f32
[src]
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
impl Debug for Vec4
[src]
impl Index<usize> for Vec4
[src]
type Output = f32
The returned type after indexing.
fn index(&self, idx: usize) -> &f32
[src]
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);
impl IndexMut<usize> for Vec4
[src]
fn index_mut(&mut self, idx: usize) -> &mut f32
[src]
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);
impl Add<Vec4> for Vec4
[src]
type Output = Vec4
The resulting type after applying the +
operator.
fn add(self, other: Vec4) -> Vec4
[src]
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);
impl Sub<Vec4> for Vec4
[src]
type Output = Vec4
The resulting type after applying the -
operator.
fn sub(self, other: Vec4) -> Vec4
[src]
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);