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: T
1: 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) -> T

The first component of this 2D vector.

fn y(self) -> T

The second component of this 2D vector.

fn width(self) -> T

The first component of this 2D vector.

fn height(self) -> T

The 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

Auto Trait Implementations

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

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

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

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

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

impl<T> UnsafeUnpin for Vec2<T> where T: UnsafeUnpin + UnsafeUnpin,

impl<T> UnwindSafe for Vec2<T> where T: UnwindSafe + UnwindSafe,

Blanket Implementations

impl<R, P> ReadPrimitive<R> for Vec2<T> where R: Read + ReadEndian<P>, P: Default,

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for Vec2<T> where ST: ?Sized, DT: ?Sized,

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for Vec2<T> where ST: ?Sized, DT: ?Sized,

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

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

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

impl<T> From<T> for Vec2<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Pointable for Vec2<T>

const ALIGN: usize = _;
type Init = T;
unsafe fn init(init: <T as Pointable>::Init) -> usize
unsafe fn deref<'a>(ptr: usize) -> &'a T
unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
unsafe fn drop(ptr: usize)

impl<T> Read<Exclusive, BecauseExclusive> for Vec2<T> where T: ?Sized,

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

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

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

fn into(self) -> U

Calls U::from(self).

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

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

type Error = never;
fn try_from(value: U) -> Result<T, never>

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

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