Struct ck::Vec2
[−]
[src]
pub struct Vec2 { pub x: f32, pub y: f32, }
Fields
x: f32
y: f32
Methods
impl Vec2
[src]
fn new(x: f32, y: f32) -> Vec2
[src]
Create a new instance of Vec2
use ck::Vec2; let v = Vec2::new(1.0, 2.0); assert_eq!(v.x, 1.0); assert_eq!(v.y, 2.0);
fn len(&self) -> f32
[src]
Get the length of a Vec2
use ck::Vec2; let v = Vec2::new(3.0, 4.0); assert_eq!(v.len(), 5.0);
fn len_squared(&self) -> f32
[src]
Get the squared length of a Vec2
use ck::Vec2; let v = Vec2::new(3.0, 4.0); assert_eq!(v.len_squared(), 25.0);
fn normalize(&self) -> Vec2
[src]
Get a new normalized version of a Vec2
use ck::Vec2; let v = Vec2::new(3.0, 4.0); let vn = v.normalize(); assert_eq!(vn.x, 3.0/5.0); assert_eq!(vn.y, 4.0/5.0);
fn raw(&self) -> [f32; 2]
[src]
Get the raw data represented by a Vec2
use ck::Vec2; let v = Vec2::new(1.0, 2.0); let r: [f32; 2] = v.raw(); assert_eq!(v.x, r[0]); assert_eq!(v.y, r[1]);
fn dot(&self, other: &Vec2) -> f32
[src]
Get the dot product of two Vec2
use ck::Vec2; let v1 = Vec2::new(1.0, 2.0); let v2 = Vec2::new(3.0, 4.0); let res: f32 = v1.dot(&v2); assert_eq!(res, 11.0);
Trait Implementations
impl Debug for Vec2
[src]
impl Index<usize> for Vec2
[src]
type Output = f32
The returned type after indexing.
fn index(&self, idx: usize) -> &f32
[src]
Indexing for Vec2 instead of field access by name
Examples
use ck::Vec2; let v = Vec2 { x: 1.0, y: 2.0 }; assert_eq!(v[0], 1.0); assert_eq!(v[1], 2.0);
impl IndexMut<usize> for Vec2
[src]
fn index_mut(&mut self, idx: usize) -> &mut f32
[src]
Mutable indexing for Vec2 instead of setting fields by name
Examples
use ck::Vec2; let mut v = Vec2 { x: 0.0, y: 0.0 }; v[0] = 1.0; v[1] = 2.0; assert_eq!(v.x, 1.0); assert_eq!(v.y, 2.0);
impl Add<Vec2> for Vec2
[src]
type Output = Vec2
The resulting type after applying the +
operator.
fn add(self, other: Vec2) -> Vec2
[src]
Overload the + operator for Vec2
Examples
use ck::Vec2; let v1 = Vec2 { x: 1.0, y: 2.0 }; let v2 = Vec2 { x: 3.0, y: 4.0 }; let v = v1 + v2; assert_eq!(v.x, 4.0); assert_eq!(v.y, 6.0);