[−][src]Struct physics2d::Vec2
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.
fn cross(self, other: Vec2) -> f32
[src]
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]
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]
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]
impl Cross<f32> for Vec2
[src]
impl<'a> Cross<f32> for &'a Vec2
[src]
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]
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]
impl Cross<Vec2> for f32
[src]
type Output = Vec2
The type of the result of the cross product.
fn cross(self, other: Vec2) -> Vec2
[src]
impl<'a> Cross<Vec2> for &'a f32
[src]
type Output = Vec2
The type of the result of the cross product.
fn cross(self, other: Vec2) -> Vec2
[src]
impl<'b> Cross<&'b Vec2> for f32
[src]
type Output = Vec2
The type of the result of the cross product.
fn cross(self, other: &'b Vec2) -> Vec2
[src]
impl<'a, 'b> Cross<&'b Vec2> for &'a f32
[src]
type Output = Vec2
The type of the result of the cross product.
fn cross(self, other: &'b Vec2) -> Vec2
[src]
impl Clone for Vec2
[src]
fn clone(&self) -> 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.
fn div(self, s: f32) -> Vec2
[src]
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]
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]
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]
impl Add<Vec2> for Vec2
[src]
type Output = Vec2
The resulting type after applying the +
operator.
fn add(self, other: Vec2) -> Vec2
[src]
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]
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]
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]
impl Sub<Vec2> for Vec2
[src]
type Output = Vec2
The resulting type after applying the -
operator.
fn sub(self, other: Vec2) -> Vec2
[src]
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]
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]
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]
impl Mul<f32> for Vec2
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, s: f32) -> Vec2
[src]
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]
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]
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]
impl Mul<Vec2> for f32
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, v: Vec2) -> Vec2
[src]
impl<'a> Mul<Vec2> for &'a f32
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, v: Vec2) -> Vec2
[src]
impl<'b> Mul<&'b Vec2> for f32
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, v: &'b Vec2) -> Vec2
[src]
impl<'a, 'b> Mul<&'b Vec2> for &'a f32
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, v: &'b Vec2) -> Vec2
[src]
impl Mul<Vec2> for Mat2
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, other: Vec2) -> Vec2
[src]
impl<'a> Mul<Vec2> for &'a Mat2
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, other: Vec2) -> Vec2
[src]
impl<'b> Mul<&'b Vec2> for Mat2
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, other: &'b Vec2) -> Vec2
[src]
impl<'a, 'b> Mul<&'b Vec2> for &'a Mat2
[src]
type Output = Vec2
The resulting type after applying the *
operator.
fn mul(self, other: &'b Vec2) -> Vec2
[src]
impl Neg for Vec2
[src]
impl<'a> Neg for &'a Vec2
[src]
impl AddAssign<Vec2> for Vec2
[src]
fn add_assign(&mut self, other: Vec2)
[src]
impl<'b> AddAssign<&'b Vec2> for Vec2
[src]
fn add_assign(&mut self, other: &'b Vec2)
[src]
impl SubAssign<Vec2> for Vec2
[src]
fn sub_assign(&mut self, other: Vec2)
[src]
impl<'b> SubAssign<&'b Vec2> for Vec2
[src]
fn sub_assign(&mut self, other: &'b Vec2)
[src]
impl MulAssign<f32> for Vec2
[src]
fn mul_assign(&mut self, s: f32)
[src]
impl<'b> MulAssign<&'b f32> for Vec2
[src]
fn mul_assign(&mut self, s: &'b f32)
[src]
impl DivAssign<f32> for Vec2
[src]
fn div_assign(&mut self, s: f32)
[src]
impl<'b> DivAssign<&'b f32> for Vec2
[src]
fn div_assign(&mut self, s: &'b f32)
[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]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,