Struct Vec2
pub struct Vec2<T>(pub T, pub T);
Simple two-dimensional vector of any numerical type. Supports only few mathematical operations as this is used mainly as data struct.
Fields
0: T1: T
Implementations
impl Vec2<i32>
fn to_usize(self, error_message: &'static str) -> Result<Vec2<usize>>Try to convert to [
Vec2<usize>], returning an error on negative numbers.
impl Vec2<usize>
fn to_i32(self) -> Vec2<i32>Panics for too large values
impl<T> Vec2<T>
fn max(self, other: Self) -> Self where T: Ord,Returns the vector with the maximum of either coordinates.
fn min(self, other: Self) -> Self where T: Ord,Returns the vector with the minimum of either coordinates.
fn try_from<S>(value: Vec2<S>) -> Result<Self, T::Error> where T: TryFrom<S>,Try to convert all components of this vector to a new type, yielding either a vector of that new type, or an error.
fn area(self) -> T where T: Mul<T, Output = T>,Seeing this vector as a dimension or size (width and height), this returns the area that this dimensions contains (
width * height).fn x(self) -> TThe first component of this 2D vector.
fn y(self) -> TThe second component of this 2D vector.
fn width(self) -> TThe first component of this 2D vector.
fn height(self) -> TThe second component of this 2D vector.
fn flat_index_for_size(self, resolution: Self) -> T where T: Copy + Debug + Ord + Mul<Output = T> + Add<Output = T>,Convert this two-dimensional coordinate to an index suited for one-dimensional flattened image arrays. Works for images that store the pixels row by row, one after another, in a single array. In debug mode, panics for an index out of bounds.
Trait Implementations
impl<T> From<(T, T)> for Vec2<T>
fn from((x, y): (T, T)) -> Self
impl<T> Neg for Vec2<T>
where
T: Neg<Output = T>,
type Output = Vec2<T>;fn neg(self) -> Self::Output
impl<T: Add<T>> Add for Vec2<T>
type Output = Vec2<<T as Add>::Output>;fn add(self, other: Self) -> Self::Output
impl<T: Clone> Clone for Vec2<T>
fn clone(&self) -> Self
impl<T: Copy> Copy for Vec2<T>
impl<T: Debug> Debug for Vec2<T>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<T: Default> Default for Vec2<T>
fn default() -> Self
impl<T: Div<T>> Div for Vec2<T>
type Output = Vec2<<T as Div>::Output>;fn div(self, other: Self) -> Self::Output
impl<T: Eq> Eq for Vec2<T>
impl<T: Hash> Hash for Vec2<T>
fn hash<__H: Hasher>(&self, state: &mut __H)
impl<T: Mul<T>> Mul for Vec2<T>
type Output = Vec2<<T as Mul>::Output>;fn mul(self, other: Self) -> Self::Output
impl<T: PartialEq> PartialEq for Vec2<T>
fn eq(&self, other: &Self) -> bool
impl<T: PartialEq> StructuralPartialEq for Vec2<T>
impl<T: Sub<T>> Sub for Vec2<T>
type Output = Vec2<<T as Sub>::Output>;fn sub(self, other: Self) -> Self::Output