Vector2

Struct Vector2 

Source
pub struct Vector2<T: Num> {
    pub x: T,
    pub y: T,
}
Expand description

Point in cartesian space on a 2D plane

§Examples

let origin = Vector2 {
    x: 0.0,
    y: 0.0,
};

Fields§

§x: T

Distance along the x axis

§y: T

Distance along the y axis

Trait Implementations§

Source§

impl<T: Num + Add> Add for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Num + CheckedAdd> CheckedAdd for Vector2<T>

Source§

fn checked_add(&self, rhs: &Self) -> Option<Self>

Adds two numbers, checking for overflow. If overflow happens, None is returned.
Source§

impl<T: Num + CheckedSub> CheckedSub for Vector2<T>

Source§

fn checked_sub(&self, rhs: &Self) -> Option<Self>

Subtracts two numbers, checking for underflow. If underflow happens, None is returned.
Source§

impl<T: Clone + Num> Clone for Vector2<T>

Source§

fn clone(&self) -> Vector2<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Num> Debug for Vector2<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Num + Display> Display for Vector2<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Float> Div<T> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: Float> Dot<T> for Vector2<T>

Source§

fn dot(&self, rhs: &Self) -> T

Source§

impl<T: Float> From<&Polar<T>> for Vector2<T>

Source§

fn from(polar: &Polar<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Float> From<&Vector2<T>> for Polar<T>

Source§

fn from(cart: &Vector2<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Num + Clone> From<[T; 2]> for Vector2<T>

Source§

fn from(a: [T; 2]) -> Self

Converts to this type from the input type.
Source§

impl<T: Num> From<(T, T)> for Vector2<T>

Source§

fn from(tuple: (T, T)) -> Self

Converts to this type from the input type.
Source§

impl<T: Float> From<Polar<T>> for Vector2<T>

Source§

fn from(polar: Polar<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Num> From<Vector2<T>> for [T; 2]

Source§

fn from(v: Vector2<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Num> From<Vector2<T>> for (T, T)

Source§

fn from(v: Vector2<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Float> From<Vector2<T>> for Polar<T>

Source§

fn from(cart: Vector2<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash + Num> Hash for Vector2<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Float> Magnitude<T> for Vector2<T>

Source§

fn magnitude(&self) -> T

Returns the exact magnitude of the vector Read more
Source§

fn quick_magnitude(&self) -> T

Returns the magnitude of a vector in as few operations as possible Read more
Source§

fn normalize(self) -> Self

Source§

impl<T: Num + Mul + Copy> Mul<T> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Neg<Output = T> + Num> Neg for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: PartialEq + Num> PartialEq for Vector2<T>

Source§

fn eq(&self, other: &Vector2<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd + Num> PartialOrd for Vector2<T>

Source§

fn partial_cmp(&self, other: &Vector2<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Float> Positional<T> for Vector2<T>

Source§

fn angle_to(&self, other: &Self) -> T

Angle between two points in space. Read more
Source§

impl<T: Num + Sub> Sub for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: Float + TrigConsts> TwoDimensionalConsts<T> for Vector2<T>

Source§

const ORIGIN: Self

Center of the coordinate space
Source§

const UP: Self

Unit vector pointing in the positive y direction
Source§

const DOWN: Self

Unit vector pointing in the negative y direction
Source§

const LEFT: Self

Unit vector pointing in the positive x direction
Source§

const RIGHT: Self

Unit vector pointing in the negative x direction
Source§

impl<T: Copy + Num> Copy for Vector2<T>

Source§

impl<T: Eq + Num> Eq for Vector2<T>

Source§

impl<T: Num> StructuralPartialEq for Vector2<T>

Auto Trait Implementations§

§

impl<T> Freeze for Vector2<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Vector2<T>
where T: RefUnwindSafe,

§

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

§

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

§

impl<T> Unpin for Vector2<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vector2<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> FullTwoDimensional<U> for T
where U: Float, T: Positional<U> + TwoDimensionalConsts<U> + Add + Sub + Neg,