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: f32
X coordinate of the vector.
y: f32
Y coordinate of the vector.
Methods
impl Vec2
[src]
fn new(x: f32, y: f32) -> Vec2
[src]
Creates a new vector from its coordinates.
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);
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());
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);
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);
const ZERO: Vec2
ZERO: Vec2 = Vec2{x: 0.0, y: 0.0,}
const UP: Vec2
UP: Vec2 = Vec2{x: 0.0, y: 1.0,}
const RIGHT: Vec2
RIGHT: Vec2 = Vec2{x: 1.0, y: 0.0,}
const DOWN: Vec2
DOWN: Vec2 = Vec2{x: 0.0, y: -1.0,}
const LEFT: Vec2
LEFT: Vec2 = Vec2{x: -1.0, y: 0.0,}
const ONE: Vec2
ONE: Vec2 = Vec2{x: 1.0, y: 1.0,}
Trait Implementations
impl PartialEq for Vec2
[src]
fn eq(&self, __arg_0: &Vec2) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Vec2) -> bool
[src]
This method tests for !=
.
impl Copy for Vec2
[src]
impl Clone for Vec2
[src]
fn clone(&self) -> Vec2
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Vec2
[src]
impl Cross for Vec2
[src]
type Output = f32
The type of the result of the cross product.
fn cross(self, other: Vec2) -> f32
[src]
Performs the cross product.
impl<'a> Cross<Vec2> for &'a Vec2
[src]
type Output = f32
The type of the result of the cross product.
fn cross(self, other: Vec2) -> f32
[src]
Performs the cross product.
impl<'b> Cross<&'b Vec2> for Vec2
[src]
type Output = f32
The type of the result of the cross product.
fn cross(self, other: &'b Vec2) -> f32
[src]
Performs 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.
fn cross(self, other: &'b Vec2) -> f32
[src]
Performs the cross product.
impl Cross<f32> for Vec2
[src]
type Output = Vec2
The type of the result of the cross product.
fn cross(self, s: f32) -> Vec2
[src]
Performs the cross product.
impl<'a> Cross<f32> for &'a Vec2
[src]
type Output = Vec2
The type of the result of the cross product.
fn cross(self, s: f32) -> Vec2
[src]
Performs the cross product.
impl<'b> Cross<&'b f32> for Vec2
[src]
type Output = Vec2
The type of the result of the cross product.
fn cross(self, s: &'b f32) -> Vec2
[src]
Performs 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.
fn cross(self, s: &'b f32) -> Vec2
[src]
Performs the cross product.
impl Neg for Vec2
[src]
type Output = Self
The resulting type after applying the -
operator.
fn neg(self) -> Self
[src]
Performs the unary -
operation.
impl<'a> Neg for &'a Vec2
[src]
type Output = Vec2
The resulting type after applying the -
operator.
fn neg(self) -> Vec2
[src]
Performs the unary -
operation.
impl Add for Vec2
[src]
type Output = Vec2
The resulting type after applying the +
operator.
fn add(self, other: Vec2) -> Vec2
[src]
Performs the +
operation.
impl<'a> Add<Vec2> for &'a Vec2
[src]
type Output = Vec2
The resulting type after applying the +
operator.
fn add(self, other: Vec2) -> Vec2
[src]
Performs the +
operation.
impl<'b> Add<&'b Vec2> for Vec2
[src]
type Output = Vec2
The resulting type after applying the +
operator.
fn add(self, other: &'b Vec2) -> Vec2
[src]
Performs the +
operation.
impl<'a, 'b> Add<&'b Vec2> for &'a Vec2
[src]
type Output = Vec2
The resulting type after applying the +
operator.
fn add(self, other: &'b Vec2) -> Vec2
[src]
Performs the +
operation.
impl AddAssign for Vec2
[src]
fn add_assign(&mut self, other: Vec2)
[src]
Performs the +=
operation.
impl<'b> AddAssign<&'b Vec2> for Vec2
[src]
fn add_assign(&mut self, other: &'b Vec2)
[src]
Performs the +=
operation.
impl Sub for Vec2
[src]
type Output = Vec2
The resulting type after applying the -
operator.
fn sub(self, other: Vec2) -> Vec2
[src]
Performs the -
operation.
impl<'a> Sub<Vec2> for &'a Vec2
[src]
type Output = Vec2
The resulting type after applying the -
operator.
fn sub(self, other: Vec2) -> Vec2
[src]
Performs the -
operation.
impl<'b> Sub<&'b Vec2> for Vec2
[src]
type Output = Vec2
The resulting type after applying the -
operator.
fn sub(self, other: &'b Vec2) -> Vec2
[src]
Performs the -
operation.
impl<'a, 'b> Sub<&'b Vec2> for &'a Vec2
[src]
type Output = Vec2
The resulting type after applying the -
operator.
fn sub(self, other: &'b Vec2) -> Vec2
[src]
Performs the -
operation.
impl SubAssign for Vec2
[src]
fn sub_assign(&mut self, other: Vec2)
[src]
Performs the -=
operation.
impl<'b> SubAssign<&'b Vec2> for Vec2
[src]
fn sub_assign(&mut self, other: &'b Vec2)
[src]
Performs the -=
operation.
impl Mul<f32> for Vec2
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, s: f32) -> Vec2
[src]
Performs the *
operation.
impl<'a> Mul<f32> for &'a Vec2
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, s: f32) -> Vec2
[src]
Performs the *
operation.
impl<'b> Mul<&'b f32> for Vec2
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, s: &'b f32) -> Vec2
[src]
Performs the *
operation.
impl<'a, 'b> Mul<&'b f32> for &'a Vec2
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, s: &'b f32) -> Vec2
[src]
Performs the *
operation.
impl MulAssign<f32> for Vec2
[src]
fn mul_assign(&mut self, s: f32)
[src]
Performs the *=
operation.
impl<'b> MulAssign<&'b f32> for Vec2
[src]
fn mul_assign(&mut self, s: &'b f32)
[src]
Performs the *=
operation.
impl Div<f32> for Vec2
[src]
type Output = Vec2
The resulting type after applying the /
operator.
fn div(self, s: f32) -> Vec2
[src]
Performs the /
operation.
impl<'a> Div<f32> for &'a Vec2
[src]
type Output = Vec2
The resulting type after applying the /
operator.
fn div(self, s: f32) -> Vec2
[src]
Performs the /
operation.
impl<'b> Div<&'b f32> for Vec2
[src]
type Output = Vec2
The resulting type after applying the /
operator.
fn div(self, s: &'b f32) -> Vec2
[src]
Performs the /
operation.
impl<'a, 'b> Div<&'b f32> for &'a Vec2
[src]
type Output = Vec2
The resulting type after applying the /
operator.
fn div(self, s: &'b f32) -> Vec2
[src]
Performs the /
operation.
impl DivAssign<f32> for Vec2
[src]
fn div_assign(&mut self, s: f32)
[src]
Performs the /=
operation.
impl<'b> DivAssign<&'b f32> for Vec2
[src]
fn div_assign(&mut self, s: &'b f32)
[src]
Performs the /=
operation.