Struct ck::Vec2 [] [src]

pub struct Vec2 {
    pub x: f32,
    pub y: f32,
}

Fields

Methods

impl Vec2
[src]

[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);

[src]

Get the length of a Vec2

use ck::Vec2;

let v = Vec2::new(3.0, 4.0);
assert_eq!(v.len(), 5.0);

[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);

[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);

[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]);

[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]

[src]

Formats the value using the given formatter.

impl Index<usize> for Vec2
[src]

The returned type after indexing.

[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]

[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]

The resulting type after applying the + operator.

[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);

impl Sub<Vec2> for Vec2
[src]

The resulting type after applying the - operator.

[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: 5.0 };
let v = v1 - v2;

assert_eq!(v.x, -2.0);
assert_eq!(v.y, -3.0);