Struct exr::math::Vec2

source ·
pub struct Vec2<T>(pub T, pub T);
Expand description

Simple two-dimensional vector of any numerical type. Supports only few mathematical operations as this is used mainly as data struct.

Tuple Fields§

§0: T§1: T

Implementations§

source§

impl<T> Vec2<T>

source

pub fn max(self, other: Self) -> Selfwhere T: Ord,

Returns the vector with the maximum of either coordinates.

source

pub fn min(self, other: Self) -> Selfwhere T: Ord,

Returns the vector with the minimum of either coordinates.

source

pub 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.

source

pub fn area(self) -> Twhere 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).

source

pub fn x(self) -> T

The first component of this 2D vector.

source

pub fn y(self) -> T

The second component of this 2D vector.

source

pub fn width(self) -> T

The first component of this 2D vector.

source

pub fn height(self) -> T

The second component of this 2D vector.

source

pub fn flat_index_for_size(self, resolution: Vec2<T>) -> Twhere 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.

source§

impl Vec2<i32>

source

pub fn to_usize(self, error_message: &'static str) -> Result<Vec2<usize>>

Try to convert to Vec2<usize>, returning an error on negative numbers.

source§

impl Vec2<usize>

source

pub fn to_i32(self) -> Vec2<i32>

Panics for too large values

Trait Implementations§

source§

impl<T: Add<T>> Add<Vec2<T>> for Vec2<T>

§

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

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

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

source§

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

Returns a copy 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> 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> Default for Vec2<T>

source§

fn default() -> Vec2<T>

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

impl<T: Div<T>> Div<Vec2<T>> for Vec2<T>

§

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

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

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

source§

fn from((x, y): (T, T)) -> Self

Converts to this type from the input type.
source§

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

source§

fn from(vec2: Vec2<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Hash> 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>> Mul<Vec2<T>> for Vec2<T>

§

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

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T> Neg for Vec2<T>where T: Neg<Output = T>,

§

type Output = Vec2<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Sub<T>> Sub<Vec2<T>> for Vec2<T>

§

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

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

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

source§

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

source§

impl<T> StructuralEq for Vec2<T>

source§

impl<T> StructuralPartialEq for Vec2<T>

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for Pwhere R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T> ToOwned for Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.