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
impl Vec4
Sourcepub fn new(x: f32, y: f32, z: f32, w: f32) -> Vec4
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);
Sourcepub fn len(&self) -> f32
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);
Sourcepub fn len_squared(&self) -> f32
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);
Sourcepub fn normalize(&self) -> Vec4
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());
Trait Implementations§
Source§impl Add for Vec4
impl Add for Vec4
Source§fn add(self, other: Vec4) -> Vec4
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§impl Index<usize> for Vec4
impl Index<usize> for Vec4
Source§impl IndexMut<usize> for Vec4
impl IndexMut<usize> for Vec4
Source§fn index_mut(&mut self, idx: usize) -> &mut f32
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
impl Sub for Vec4
Source§fn sub(self, other: Vec4) -> Vec4
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);
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more