Vec2

Struct Vec2 

Source
pub struct Vec2<T: VecItem> {
    pub x: T,
    pub y: T,
}

Fields§

§x: T§y: T

Implementations§

Source§

impl<T: VecItem> Vec2<T>

Source

pub fn new(x: T, y: T) -> Self

Creates a new Vec2 from multiple components

Source

pub fn elements(&self) -> [T; 2]

Returns the elements of the vector as an array

Source

pub fn map<U: VecItem, F: Fn(T) -> U>(&self, f: F) -> Vec2<U>

Apply an operation to all elements of this vector, returning the result

Source

pub fn convert_to<U: VecItem + From<T>>(&self) -> Vec2<U>

Trait Implementations§

Source§

impl<T> Add<T> for Vec2<T>
where T: VecItem + Add, T::Output: VecItem + Add,

Source§

type Output = Vec2<<T as Add>::Output>

The resulting type after applying the + operator.
Source§

fn add(self, other: T) -> Vec2<T::Output>

Performs the + operation. Read more
Source§

impl<T> Add for Vec2<T>
where T: VecItem + Add, T::Output: VecItem + Add,

Source§

type Output = Vec2<<T as Add>::Output>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Vec2<T::Output>

Performs the + operation. Read more
Source§

impl<T> AddAssign<T> for Vec2<T>
where T: VecItem + Add<Output = T>,

Source§

fn add_assign(&mut self, other: T)

Performs the += operation. Read more
Source§

impl<T> AddAssign for Vec2<T>
where T: VecItem + Add<Output = T>,

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl<T: Clone + VecItem> Clone for Vec2<T>

Source§

fn clone(&self) -> Vec2<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: VecItem + Debug> Debug for Vec2<T>

Source§

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

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

impl<T: Default + VecItem> Default for Vec2<T>

Source§

fn default() -> Vec2<T>

Returns the “default value” for a type. Read more
Source§

impl<T: VecItem + Display> Display for Vec2<T>

Source§

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

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

impl<T> Div<T> for Vec2<T>
where T: VecItem + Div, T::Output: VecItem + Div,

Source§

type Output = Vec2<<T as Div>::Output>

The resulting type after applying the / operator.
Source§

fn div(self, other: T) -> Vec2<T::Output>

Performs the / operation. Read more
Source§

impl<T> Div for Vec2<T>
where T: VecItem + Div, T::Output: VecItem + Div,

Source§

type Output = Vec2<<T as Div>::Output>

The resulting type after applying the / operator.
Source§

fn div(self, other: Self) -> Vec2<T::Output>

Performs the / operation. Read more
Source§

impl<T> DivAssign<T> for Vec2<T>
where T: VecItem + Div<Output = T>,

Source§

fn div_assign(&mut self, other: T)

Performs the /= operation. Read more
Source§

impl<T> DivAssign for Vec2<T>
where T: VecItem + Div<Output = T>,

Source§

fn div_assign(&mut self, other: Self)

Performs the /= operation. Read more
Source§

impl<T: VecItem> From<[T; 2]> for Vec2<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T: VecItem> From<(T, T)> for Vec2<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T: Hash + VecItem> Hash for Vec2<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> Mul<T> for Vec2<T>
where T: VecItem + Mul, T::Output: VecItem + Mul,

Source§

type Output = Vec2<<T as Mul>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, other: T) -> Vec2<T::Output>

Performs the * operation. Read more
Source§

impl<T> Mul for Vec2<T>
where T: VecItem + Mul, T::Output: VecItem + Mul,

Source§

type Output = Vec2<<T as Mul>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Vec2<T::Output>

Performs the * operation. Read more
Source§

impl<T> MulAssign<T> for Vec2<T>
where T: VecItem + Mul<Output = T>,

Source§

fn mul_assign(&mut self, other: T)

Performs the *= operation. Read more
Source§

impl<T> MulAssign for Vec2<T>
where T: VecItem + Mul<Output = T>,

Source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
Source§

impl<T: PartialEq + VecItem> PartialEq for Vec2<T>

Source§

fn eq(&self, other: &Vec2<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> Sub<T> for Vec2<T>
where T: VecItem + Sub, T::Output: VecItem + Sub,

Source§

type Output = Vec2<<T as Sub>::Output>

The resulting type after applying the - operator.
Source§

fn sub(self, other: T) -> Vec2<T::Output>

Performs the - operation. Read more
Source§

impl<T> Sub for Vec2<T>
where T: VecItem + Sub, T::Output: VecItem + Sub,

Source§

type Output = Vec2<<T as Sub>::Output>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Vec2<T::Output>

Performs the - operation. Read more
Source§

impl<T> SubAssign<T> for Vec2<T>
where T: VecItem + Sub<Output = T>,

Source§

fn sub_assign(&mut self, other: T)

Performs the -= operation. Read more
Source§

impl<T> SubAssign for Vec2<T>
where T: VecItem + Sub<Output = T>,

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl<T> VecFloat for Vec2<T>
where T: VecItem + Float,

Source§

fn length(&self) -> Self::Item

Calculates the magnitude of the vector
Source§

fn norm(&self) -> Self

Calculates the normalized form of the vector (i.e: a vector with identical direction but a magnitude of 1)
Source§

fn floor(&self) -> Self

Rounds each element of the vector down to the nearest whole number
Source§

fn ceil(&self) -> Self

Rounds each element of the vector up to the nearest whole number
Source§

fn round(&self) -> Self

Rounds each element of the vector to the nearest whole number
Source§

impl<T> VecInt for Vec2<T>
where T: VecItem + Integer,

Source§

fn div_euc(&self, other: Self) -> Self

Performs a Eucledian division (i.e: rounds towards negative infinity) operation upon the vector
Source§

impl<T> VecNum for Vec2<T>
where T: VecItem + Num,

Source§

fn sum(&self) -> Self::Item

Calculates the sum of all components of the vector
Source§

fn product(&self) -> Self::Item

Calculates the product of all components of the vector
Source§

impl<T> VecSigned for Vec2<T>
where T: VecItem + Signed,

Source§

fn snake_length(&self) -> Self::Item

Calculates the snake length (also known as ‘manhattan distance’) of the vector Read more
Source§

impl<T: VecItem> Vector for Vec2<T>

Source§

type Item = T

Source§

impl<T: Copy + VecItem> Copy for Vec2<T>

Source§

impl<T: Eq + VecItem> Eq for Vec2<T>

Source§

impl<T: VecItem> StructuralPartialEq for Vec2<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Vec2<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.