[−][src]Struct airmash_protocol::Vector2
A 2D Vector that works with unit conversions.
Note: Position
, Velocity
,
and Accel
are all instances of this struct
with different units.
Fields
x: T
y: T
Methods
impl<T> Vector2<T>
[src]
impl<T> Vector2<T>
pub fn new<X>(x: X, y: X) -> Self where | [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);
pub fn dot<U>(self, rhs: Vector2<U>) -> <<T as Mul<U>>::Output as Add>::Output where | [src] |
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);
pub fn length(self) -> <<<T as Mul>::Output as Add>::Output as Sqrt>::Output where | [src] |
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);
pub fn length2(self) -> <<T as Mul>::Output as Add>::Output where | [src] |
Calculate the length squared.
pub fn normalized( | [src] |
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: Copy> Copy for Vector2<T>
[src]
impl<T: Copy> Copy for Vector2<T>
impl<T: Default> Default for Vector2<T>
[src]
impl<T: Default> Default for Vector2<T>
impl<T: PartialEq> PartialEq<Vector2<T>> for Vector2<T>
[src]
impl<T: PartialEq> PartialEq<Vector2<T>> for Vector2<T>
impl<T: Clone> Clone for Vector2<T>
[src]
impl<T: Clone> Clone for Vector2<T>
fn clone(&self) -> Vector2<T> | [src] |
fn clone_from(&mut self, source: &Self) | 1.0.0 [src] |
Performs copy-assignment from source
. Read more
impl<T: Debug> Debug for Vector2<T>
[src]
impl<T: Debug> Debug for Vector2<T>
impl<T, U> Add<U> for Vector2<T> where
T: Add<U>,
U: Clone + NotVec,
[src]
impl<T, U> Add<U> for Vector2<T> where
T: Add<U>,
U: Clone + NotVec,
type Output = Vector2<T::Output>
The resulting type after applying the +
operator.
fn add(self, rhs: U) -> Self::Output | [src] |
impl<T, U> Add<Vector2<U>> for Vector2<T> where
T: Add<U>,
[src]
impl<T, U> Add<Vector2<U>> for Vector2<T> where
T: Add<U>,
type Output = Vector2<T::Output>
The resulting type after applying the +
operator.
fn add(self, rhs: Vector2<U>) -> Self::Output | [src] |
impl<T, U> Sub<U> for Vector2<T> where
T: Sub<U>,
U: Clone + NotVec,
[src]
impl<T, U> Sub<U> for Vector2<T> where
T: Sub<U>,
U: Clone + NotVec,
type Output = Vector2<T::Output>
The resulting type after applying the -
operator.
fn sub(self, rhs: U) -> Self::Output | [src] |
impl<T, U> Sub<Vector2<U>> for Vector2<T> where
T: Sub<U>,
[src]
impl<T, U> Sub<Vector2<U>> for Vector2<T> where
T: Sub<U>,
type Output = Vector2<T::Output>
The resulting type after applying the -
operator.
fn sub(self, rhs: Vector2<U>) -> Self::Output | [src] |
impl<T, U> Mul<U> for Vector2<T> where
T: Mul<U>,
U: Clone + NotVec,
[src]
impl<T, U> Mul<U> for Vector2<T> where
T: Mul<U>,
U: Clone + NotVec,
type Output = Vector2<T::Output>
The resulting type after applying the *
operator.
fn mul(self, rhs: U) -> Self::Output | [src] |
impl<T, U> Mul<Vector2<U>> for Vector2<T> where
T: Mul<U>,
[src]
impl<T, U> Mul<Vector2<U>> for Vector2<T> where
T: Mul<U>,
type Output = Vector2<T::Output>
The resulting type after applying the *
operator.
fn mul(self, rhs: Vector2<U>) -> Self::Output | [src] |
impl<T, U> Div<U> for Vector2<T> where
T: Div<U>,
U: Clone + NotVec,
[src]
impl<T, U> Div<U> for Vector2<T> where
T: Div<U>,
U: Clone + NotVec,
type Output = Vector2<T::Output>
The resulting type after applying the /
operator.
fn div(self, rhs: U) -> Self::Output | [src] |
impl<T, U> AddAssign<U> for Vector2<T> where
Self: Add<U, Output = Vector2<T>> + Clone,
[src]
impl<T, U> AddAssign<U> for Vector2<T> where
Self: Add<U, Output = Vector2<T>> + Clone,
fn add_assign(&mut self, rhs: U) | [src] |
impl<T, U> SubAssign<U> for Vector2<T> where
Self: Sub<U, Output = Vector2<T>> + Clone,
[src]
impl<T, U> SubAssign<U> for Vector2<T> where
Self: Sub<U, Output = Vector2<T>> + Clone,
fn sub_assign(&mut self, rhs: U) | [src] |
impl<T, U> MulAssign<U> for Vector2<T> where
Self: Mul<U, Output = Vector2<T>> + Clone,
[src]
impl<T, U> MulAssign<U> for Vector2<T> where
Self: Mul<U, Output = Vector2<T>> + Clone,
fn mul_assign(&mut self, rhs: U) | [src] |
impl<T, U> DivAssign<U> for Vector2<T> where
Self: Div<U, Output = Vector2<T>> + Clone,
[src]
impl<T, U> DivAssign<U> for Vector2<T> where
Self: Div<U, Output = Vector2<T>> + Clone,
fn div_assign(&mut self, rhs: U) | [src] |
impl<T> Serialize for Vector2<T> where
T: Serialize + Clone,
[src]
impl<T> Serialize for Vector2<T> where
T: Serialize + Clone,
impl<'de, T> Deserialize<'de> for Vector2<T> where
T: Deserialize<'de>,
[src]
impl<'de, T> Deserialize<'de> for Vector2<T> where
T: Deserialize<'de>,
fn deserialize<D>(de: D) -> Result<Self, D::Error> where | [src] |
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)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> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T | [src] |
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error> | [src] |
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId | [src] |
impl<T> Same for T
impl<T> Same for T
type Output = T
Should always be Self
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,