[][src]Struct physics2d::Vec2

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

A 2-dimensional vector.

The Vec2 type can be used to represent anything that has two dimensions: a size, a point, a velocity, etc.

Fields

x: f32

X coordinate of the vector.

y: f32

Y coordinate of the vector.

Methods

impl Vec2[src]

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

Creates a new vector from its coordinates.

pub fn len(&self) -> f32[src]

Returns the length (magnitude) of the vector.

Examples

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

pub fn sqr_len(&self) -> f32[src]

Returns the square of the length (magnitude) of the vector.

Examples

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

pub fn dot(&self, b: &Vec2) -> f32[src]

Returns the dot product of this vector with another vector.

Examples

let a = Vec2::new(3.0, 4.0);
let b = Vec2::new(4.0, 5.0);

assert_eq!(a.dot(&b), 32.0);

pub fn normalized(self) -> Vec2[src]

Returns the normalized (unit) vector for the given vector.

Examples

let v = Vec2::new(3.0, 4.0);
let l = v.len();
let n = v.normalized();

assert_eq!(n, v / l);
assert_eq!(n.len(), 1.0);

pub fn min(&self, other: &Vec2) -> Vec2[src]

Returns a vector whose components are the minimum of the corresponding components of the two vectors.

Examples

let a = Vec2::new(3.0, 40.0);
let b = Vec2::new(40.0, 3.0);

assert_eq!(a.min(&b), Vec2::new(3.0, 3.0));

pub fn max(&self, other: &Vec2) -> Vec2[src]

Returns a vector whose components are the maximum of the corresponding components of the two vectors.

Examples

let a = Vec2::new(3.0, 40.0);
let b = Vec2::new(40.0, 3.0);

assert_eq!(a.max(&b), Vec2::new(40.0, 40.0));

pub const ZERO: Vec2[src]

pub const UP: Vec2[src]

pub const RIGHT: Vec2[src]

pub const DOWN: Vec2[src]

pub const LEFT: Vec2[src]

pub const ONE: Vec2[src]

Trait Implementations

impl Cross<Vec2> for Vec2[src]

type Output = f32

The type of the result of the cross product.

impl<'a> Cross<Vec2> for &'a Vec2[src]

type Output = f32

The type of the result of the cross product.

impl<'b> Cross<&'b Vec2> for Vec2[src]

type Output = f32

The type of the result of the cross product.

impl<'a, 'b> Cross<&'b Vec2> for &'a Vec2[src]

type Output = f32

The type of the result of the cross product.

impl Cross<f32> for Vec2[src]

type Output = Vec2

The type of the result of the cross product.

impl<'a> Cross<f32> for &'a Vec2[src]

type Output = Vec2

The type of the result of the cross product.

impl<'b> Cross<&'b f32> for Vec2[src]

type Output = Vec2

The type of the result of the cross product.

impl<'a, 'b> Cross<&'b f32> for &'a Vec2[src]

type Output = Vec2

The type of the result of the cross product.

impl Cross<Vec2> for f32[src]

type Output = Vec2

The type of the result of the cross product.

impl<'a> Cross<Vec2> for &'a f32[src]

type Output = Vec2

The type of the result of the cross product.

impl<'b> Cross<&'b Vec2> for f32[src]

type Output = Vec2

The type of the result of the cross product.

impl<'a, 'b> Cross<&'b Vec2> for &'a f32[src]

type Output = Vec2

The type of the result of the cross product.

impl Clone for Vec2[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl PartialEq<Vec2> for Vec2[src]

impl Copy for Vec2[src]

impl Debug for Vec2[src]

impl Div<f32> for Vec2[src]

type Output = Vec2

The resulting type after applying the / operator.

impl<'a> Div<f32> for &'a Vec2[src]

type Output = Vec2

The resulting type after applying the / operator.

impl<'b> Div<&'b f32> for Vec2[src]

type Output = Vec2

The resulting type after applying the / operator.

impl<'a, 'b> Div<&'b f32> for &'a Vec2[src]

type Output = Vec2

The resulting type after applying the / operator.

impl Add<Vec2> for Vec2[src]

type Output = Vec2

The resulting type after applying the + operator.

impl<'a> Add<Vec2> for &'a Vec2[src]

type Output = Vec2

The resulting type after applying the + operator.

impl<'b> Add<&'b Vec2> for Vec2[src]

type Output = Vec2

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'b Vec2> for &'a Vec2[src]

type Output = Vec2

The resulting type after applying the + operator.

impl Sub<Vec2> for Vec2[src]

type Output = Vec2

The resulting type after applying the - operator.

impl<'a> Sub<Vec2> for &'a Vec2[src]

type Output = Vec2

The resulting type after applying the - operator.

impl<'b> Sub<&'b Vec2> for Vec2[src]

type Output = Vec2

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'b Vec2> for &'a Vec2[src]

type Output = Vec2

The resulting type after applying the - operator.

impl Mul<f32> for Vec2[src]

type Output = Vec2

The resulting type after applying the * operator.

impl<'a> Mul<f32> for &'a Vec2[src]

type Output = Vec2

The resulting type after applying the * operator.

impl<'b> Mul<&'b f32> for Vec2[src]

type Output = Vec2

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'b f32> for &'a Vec2[src]

type Output = Vec2

The resulting type after applying the * operator.

impl Mul<Vec2> for f32[src]

type Output = Vec2

The resulting type after applying the * operator.

impl<'a> Mul<Vec2> for &'a f32[src]

type Output = Vec2

The resulting type after applying the * operator.

impl<'b> Mul<&'b Vec2> for f32[src]

type Output = Vec2

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'b Vec2> for &'a f32[src]

type Output = Vec2

The resulting type after applying the * operator.

impl Mul<Vec2> for Mat2[src]

type Output = Vec2

The resulting type after applying the * operator.

impl<'a> Mul<Vec2> for &'a Mat2[src]

type Output = Vec2

The resulting type after applying the * operator.

impl<'b> Mul<&'b Vec2> for Mat2[src]

type Output = Vec2

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'b Vec2> for &'a Mat2[src]

type Output = Vec2

The resulting type after applying the * operator.

impl Neg for Vec2[src]

type Output = Self

The resulting type after applying the - operator.

impl<'a> Neg for &'a Vec2[src]

type Output = Vec2

The resulting type after applying the - operator.

impl AddAssign<Vec2> for Vec2[src]

impl<'b> AddAssign<&'b Vec2> for Vec2[src]

impl SubAssign<Vec2> for Vec2[src]

impl<'b> SubAssign<&'b Vec2> for Vec2[src]

impl MulAssign<f32> for Vec2[src]

impl<'b> MulAssign<&'b f32> for Vec2[src]

impl DivAssign<f32> for Vec2[src]

impl<'b> DivAssign<&'b f32> for Vec2[src]

Auto Trait Implementations

impl Sync for Vec2

impl Send for Vec2

impl Unpin for Vec2

impl RefUnwindSafe for Vec2

impl UnwindSafe for Vec2

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]