Struct physics2d::Vec2 [] [src]

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 coordinate of the vector.

Y coordinate of the vector.

Methods

impl Vec2
[src]

[src]

Creates a new vector from its coordinates.

[src]

Returns the length (magnitude) of the vector.

Examples

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

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

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

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

ZERO: Vec2 = Vec2{x: 0.0, y: 0.0,}

UP: Vec2 = Vec2{x: 0.0, y: 1.0,}

RIGHT: Vec2 = Vec2{x: 1.0, y: 0.0,}

DOWN: Vec2 = Vec2{x: 0.0, y: -1.0,}

LEFT: Vec2 = Vec2{x: -1.0, y: 0.0,}

ONE: Vec2 = Vec2{x: 1.0, y: 1.0,}

Trait Implementations

impl PartialEq for Vec2
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Copy for Vec2
[src]

impl Clone for Vec2
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Vec2
[src]

[src]

Formats the value using the given formatter.

impl Cross for Vec2
[src]

The type of the result of the cross product.

[src]

Performs the cross product.

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

The type of the result of the cross product.

[src]

Performs the cross product.

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

The type of the result of the cross product.

[src]

Performs the cross product.

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

The type of the result of the cross product.

[src]

Performs the cross product.

impl Cross<f32> for Vec2
[src]

The type of the result of the cross product.

[src]

Performs the cross product.

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

The type of the result of the cross product.

[src]

Performs the cross product.

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

The type of the result of the cross product.

[src]

Performs the cross product.

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

The type of the result of the cross product.

[src]

Performs the cross product.

impl Neg for Vec2
[src]

The resulting type after applying the - operator.

[src]

Performs the unary - operation.

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

The resulting type after applying the - operator.

[src]

Performs the unary - operation.

impl Add for Vec2
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl AddAssign for Vec2
[src]

[src]

Performs the += operation.

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

[src]

Performs the += operation.

impl Sub for Vec2
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl SubAssign for Vec2
[src]

[src]

Performs the -= operation.

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

[src]

Performs the -= operation.

impl Mul<f32> for Vec2
[src]

The resulting type after applying the * operator.

[src]

Performs the * operation.

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

The resulting type after applying the * operator.

[src]

Performs the * operation.

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

The resulting type after applying the * operator.

[src]

Performs the * operation.

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

The resulting type after applying the * operator.

[src]

Performs the * operation.

impl MulAssign<f32> for Vec2
[src]

[src]

Performs the *= operation.

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

[src]

Performs the *= operation.

impl Div<f32> for Vec2
[src]

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

impl DivAssign<f32> for Vec2
[src]

[src]

Performs the /= operation.

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

[src]

Performs the /= operation.