Struct airmash_protocol::Vector2[][src]

pub struct Vector2<T> {
    pub x: T,
    pub y: T,
}

A 2D Vector that works with unit conversions.

Note: Position, Velocity, and Accel are all instances of this struct with different units.

Fields

Methods

impl<T> Vector2<T>
[src]

Create a new vector with components that convert into the vectors types.

This is easier to use when creating a vector from components, but it may prevent type inference when the vector type is not specified.

Example

// Note that this is the same as Position
let vec: Vector2<Distance> = Vector2::new(0.0, 0.0);

Take the dot product of two vectors.

The dot product for a 2D vector is defined (given two vectors a and b) as: a.x * b.x + a.y * b.x.

Example

let a: Vector2<i32> = Vector2::new(1, 2);
let b: Vector2<i32> = Vector2::new(3, 4);
 
let c = Vector2::dot(a, b);
 
assert_eq!(c, 11);

Calculate the magnitude of the vector.

Examples

Calculate the distance between two points.

let a: Vector2<f32> = Vector2::new(4.0, 0.0);
let b: Vector2<f32> = Vector2::new(-4.0, 0.0);
 
// The distance is length of the vector going
// from b to a
let dist = (a - b).length();
 
assert_eq!(dist, 8.0);

Calculate the length squared.

Return a vector pointing in the same direction as this one but with a magniture of 1.

Note

When used with units this will always return a dimensionless vector.

Trait Implementations

impl<T: Default> Default for Vector2<T>
[src]

Returns the "default value" for a type. Read more

impl<T: Clone> Clone for Vector2<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Copy> Copy for Vector2<T>
[src]

impl<T: PartialEq> PartialEq for Vector2<T>
[src]

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

This method tests for !=.

impl<T: Debug> Debug for Vector2<T>
[src]

Formats the value using the given formatter. Read more

impl<T, U> Add<U> for Vector2<T> where
    T: Add<U>,
    U: Clone + NotVec, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, U> Sub<U> for Vector2<T> where
    T: Sub<U>,
    U: Clone + NotVec, 
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<T, U> Mul<U> for Vector2<T> where
    T: Mul<U>,
    U: Clone + NotVec, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, U> Div<U> for Vector2<T> where
    T: Div<U>,
    U: Clone + NotVec, 
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<T, U> Add<Vector2<U>> for Vector2<T> where
    T: Add<U>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, U> Sub<Vector2<U>> for Vector2<T> where
    T: Sub<U>, 
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<T, U> Mul<Vector2<U>> for Vector2<T> where
    T: Mul<U>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, U> AddAssign<U> for Vector2<T> where
    Self: Add<U, Output = Vector2<T>> + Clone
[src]

Performs the += operation.

impl<T, U> SubAssign<U> for Vector2<T> where
    Self: Sub<U, Output = Vector2<T>> + Clone
[src]

Performs the -= operation.

impl<T, U> MulAssign<U> for Vector2<T> where
    Self: Mul<U, Output = Vector2<T>> + Clone
[src]

Performs the *= operation.

impl<T, U> DivAssign<U> for Vector2<T> where
    Self: Div<U, Output = Vector2<T>> + Clone
[src]

Performs the /= operation.

impl<T> Serialize for Vector2<T> where
    T: Serialize + Clone
[src]

Serialize this value into the given Serde serializer. Read more

impl<'de, T> Deserialize<'de> for Vector2<T> where
    T: Deserialize<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations

impl<T> Send for Vector2<T> where
    T: Send

impl<T> Sync for Vector2<T> where
    T: Sync