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>
impl<T: AxisDimension> AxisDiff<T>
Sourcepub fn from_origin(self) -> AxisIndex<T>
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));
Sourcepub fn try_into_positive(self) -> Result<PositiveAxisDiff<T>, Self>
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)));
Sourcepub fn abs(self) -> PositiveAxisDiff<T>
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());
Sourcepub fn positive_or_zero(self) -> PositiveAxisDiff<T>
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>>> AddAssign<I> for AxisDiff<T>
impl<T: AxisDimension, I: Into<AxisDiff<T>>> AddAssign<I> for AxisDiff<T>
Source§fn add_assign(&mut self, rhs: I)
fn add_assign(&mut self, rhs: I)
Performs the
+=
operation. Read moreSource§impl<T: AxisDimension> Into<AxisDiff<T>> for PositiveAxisDiff<T>
impl<T: AxisDimension> Into<AxisDiff<T>> for PositiveAxisDiff<T>
Source§impl<T: AxisDimension> Neg for AxisDiff<T>
impl<T: AxisDimension> Neg for AxisDiff<T>
Source§impl<T: Ord + AxisDimension> Ord for AxisDiff<T>
impl<T: Ord + AxisDimension> Ord for AxisDiff<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: AxisDimension, I: Into<AxisDiff<T>> + Copy> PartialOrd<I> for AxisDiff<T>
impl<T: AxisDimension, I: Into<AxisDiff<T>> + Copy> PartialOrd<I> for AxisDiff<T>
Source§impl<T: AxisDimension, I: Into<AxisDiff<T>>> SubAssign<I> for AxisDiff<T>
impl<T: AxisDimension, I: Into<AxisDiff<T>>> SubAssign<I> for AxisDiff<T>
Source§fn sub_assign(&mut self, rhs: I)
fn sub_assign(&mut self, rhs: I)
Performs the
-=
operation. Read moreSource§impl<'a, T: 'a + AxisDimension + PartialOrd + Ord> Sum<&'a AxisDiff<T>> for AxisDiff<T>
impl<'a, T: 'a + AxisDimension + PartialOrd + Ord> Sum<&'a AxisDiff<T>> for AxisDiff<T>
Source§impl<T: AxisDimension + PartialOrd + Ord> Sum for AxisDiff<T>
impl<T: AxisDimension + PartialOrd + Ord> Sum for AxisDiff<T>
impl<T: Copy + AxisDimension> Copy for AxisDiff<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more