Struct Vec2

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

Fields§

§x: f32§y: f32

Implementations§

Source§

impl Vec2

Source

pub fn new(x: f32, y: f32) -> Vec2

§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);
Source

pub fn len(&self) -> f32

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

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

pub fn len_squared(&self) -> f32

§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);
Source

pub fn normalize(&self) -> Vec2

§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);
Source

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

§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]);
Source

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

§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§

Source§

impl Add for Vec2

Source§

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

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);
Source§

type Output = Vec2

The resulting type after applying the + operator.
Source§

impl Debug for Vec2

Source§

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

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

impl Index<usize> for Vec2

Source§

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

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);
Source§

type Output = f32

The returned type after indexing.
Source§

impl IndexMut<usize> for Vec2

Source§

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

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);
Source§

impl Sub for Vec2

Source§

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

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);
Source§

type Output = Vec2

The resulting type after applying the - operator.

Auto Trait Implementations§

§

impl Freeze for Vec2

§

impl RefUnwindSafe for Vec2

§

impl Send for Vec2

§

impl Sync for Vec2

§

impl Unpin for Vec2

§

impl UnwindSafe for Vec2

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.