Struct AxisDiff

Source
pub struct AxisDiff<T: AxisDimension> { /* private fields */ }
Expand description

AxisDiff (the base for ColDiff or RowDiff) specifies a difference between two coordinate points on a terminal grid. (i.e., a coordinate of a vector on the terminal cell grid)

Implementations§

Source§

impl<T: AxisDimension> AxisDiff<T>

Source

pub fn new(v: i32) -> Self

Create a new AxisDiff from an i32. Any i32 value is valid.

Source

pub fn raw_value(self) -> i32

Unpack the AxisDiff to receive the raw i32 value.

Source

pub fn from_origin(self) -> AxisIndex<T>

Calculate the AxisIndex that has the specified AxisDiff to the origin (i.e., 0). Technically this just converts an AxisIndex into an AxisDiff, but is semantically more explicit.

§Examples:
use unsegen::base::{ColIndex, ColDiff};
assert_eq!(ColDiff::new(27).from_origin(), ColIndex::new(27));
Source

pub fn try_into_positive(self) -> Result<PositiveAxisDiff<T>, Self>

Try to convert the current value into a PositiveAxisDiff. If the conversion fails, the original value is returned.

§Examples:
use unsegen::base::{ColDiff, Width};
assert_eq!(ColDiff::new(27).try_into_positive(), Ok(Width::new(27).unwrap()));
assert_eq!(ColDiff::new(0).try_into_positive(), Ok(Width::new(0).unwrap()));
assert_eq!(ColDiff::new(-37).try_into_positive(), Err(ColDiff::new(-37)));
Source

pub fn abs(self) -> PositiveAxisDiff<T>

Convert the current value into a PositiveAxisDiff by taking the absolute value of the axis difference.

§Examples:
use unsegen::base::{ColDiff, Width};
assert_eq!(ColDiff::new(27).abs(), Width::new(27).unwrap());
assert_eq!(ColDiff::new(0).abs(), Width::new(0).unwrap());
assert_eq!(ColDiff::new(-37).abs(), Width::new(37).unwrap());
Source

pub fn positive_or_zero(self) -> PositiveAxisDiff<T>

Clamp the value into a positive or zero range

§Examples:
use unsegen::base::ColDiff;
assert_eq!(ColDiff::new(27).positive_or_zero(), ColDiff::new(27));
assert_eq!(ColDiff::new(0).positive_or_zero(), ColDiff::new(0));
assert_eq!(ColDiff::new(-37).positive_or_zero(), ColDiff::new(0));

Trait Implementations§

Source§

impl<T: AxisDimension, I: Into<AxisDiff<T>>> Add<I> for AxisDiff<T>

Source§

type Output = AxisDiff<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: AxisDimension, I: Into<AxisDiff<T>>> AddAssign<I> for AxisDiff<T>

Source§

fn add_assign(&mut self, rhs: I)

Performs the += operation. Read more
Source§

impl<T: Clone + AxisDimension> Clone for AxisDiff<T>

Source§

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

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

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + AxisDimension> Debug for AxisDiff<T>

Source§

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

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

impl<T: AxisDimension> Div<i32> for AxisDiff<T>

Source§

type Output = AxisDiff<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T: AxisDimension> From<i32> for AxisDiff<T>

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl<T: AxisDimension> Into<AxisDiff<T>> for PositiveAxisDiff<T>

Source§

fn into(self) -> AxisDiff<T>

Converts this type into the (usually inferred) input type.
Source§

impl<T: AxisDimension> Into<i32> for AxisDiff<T>

Source§

fn into(self) -> i32

Converts this type into the (usually inferred) input type.
Source§

impl<T: AxisDimension> Mul<i32> for AxisDiff<T>

Source§

type Output = AxisDiff<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: AxisDimension> Neg for AxisDiff<T>

Source§

type Output = AxisDiff<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: Ord + AxisDimension> Ord for AxisDiff<T>

Source§

fn cmp(&self, other: &AxisDiff<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: AxisDimension, I: Into<AxisDiff<T>> + Copy> PartialEq<I> for AxisDiff<T>

Source§

fn eq(&self, other: &I) -> bool

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

const 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: AxisDimension, I: Into<AxisDiff<T>> + Copy> PartialOrd<I> for AxisDiff<T>

Source§

fn partial_cmp(&self, other: &I) -> 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: AxisDimension, I: Into<AxisDiff<T>>> Rem<I> for AxisDiff<T>

Source§

type Output = AxisDiff<T>

The resulting type after applying the % operator.
Source§

fn rem(self, modulus: I) -> Self

Performs the % operation. Read more
Source§

impl<T: AxisDimension, I: Into<AxisDiff<T>>> Sub<I> for AxisDiff<T>

Source§

type Output = AxisDiff<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: AxisDimension, I: Into<AxisDiff<T>>> SubAssign<I> for AxisDiff<T>

Source§

fn sub_assign(&mut self, rhs: I)

Performs the -= operation. Read more
Source§

impl<'a, T: 'a + AxisDimension + PartialOrd + Ord> Sum<&'a AxisDiff<T>> for AxisDiff<T>

Source§

fn sum<I>(iter: I) -> Self
where I: Iterator<Item = &'a Self>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<T: AxisDimension + PartialOrd + Ord> Sum for AxisDiff<T>

Source§

fn sum<I>(iter: I) -> Self
where I: Iterator<Item = Self>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<T: Copy + AxisDimension> Copy for AxisDiff<T>

Source§

impl<T: Eq + AxisDimension> Eq for AxisDiff<T>

Auto Trait Implementations§

§

impl<T> Freeze for AxisDiff<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for AxisDiff<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, 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, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,