Implementations
sourceimpl<N: Number, U: Unit> Vec2D<N, U>
impl<N: Number, U: Unit> Vec2D<N, U>
sourcepub fn cast<NO: Number>(self) -> Vec2D<NO, U>
pub fn cast<NO: Number>(self) -> Vec2D<NO, U>
Tries to cast the values to different number type.
Examples
use mathie::Vec2D;
assert_eq!(Vec2D::<f32>::new_any(250.5, 250.5).cast(), Vec2D::<u32>::new_any(250, 250));
assert_eq!(Vec2D::<f32>::new_any(0.5, 0.5).cast(), Vec2D::<u32>::new_any(0, 0));
sourcepub fn try_cast<NO: Number>(self) -> Option<Vec2D<NO, U>>
pub fn try_cast<NO: Number>(self) -> Option<Vec2D<NO, U>>
Same as Self::cast but returns None if the cast failed.
sourcepub fn convert<UO: UnitCompatibility<N, U> + Default>(self) -> Vec2D<N, UO>
pub fn convert<UO: UnitCompatibility<N, U> + Default>(self) -> Vec2D<N, UO>
Same as Self::try_convert but panics if the conversion failed.
sourcepub fn try_convert<UO: UnitCompatibility<N, U> + Default>(
self
) -> Option<Vec2D<N, UO>>
pub fn try_convert<UO: UnitCompatibility<N, U> + Default>(
self
) -> Option<Vec2D<N, UO>>
Converts the value to a different unit type by using UnitCompatibility::convert_pos2. This is Self::convert_u but it uses the target unit default value for easier usage.
Arguments
returns: Option<Vec2D<N, UO>>
Examples
use mathie::unit::metric::Centimeter;
let v0 = mathie::Vec2D::<f32, Centimeter>::new(250.0, 250.0);
let v1 = v0.try_convert_u(()).unwrap();
assert_eq!(v1, mathie::Vec2D::new(2.5, 2.5));
See also
sourcepub fn convert_u<UO: UnitCompatibility<N, U>>(self, to: UO) -> Vec2D<N, UO>
pub fn convert_u<UO: UnitCompatibility<N, U>>(self, to: UO) -> Vec2D<N, UO>
Same as Self::try_convert_u but panics if the conversion failed.
sourcepub fn try_convert_u<UO: UnitCompatibility<N, U>>(
self,
to: UO
) -> Option<Vec2D<N, UO>>
pub fn try_convert_u<UO: UnitCompatibility<N, U>>(
self,
to: UO
) -> Option<Vec2D<N, UO>>
Converts the value to a different unit type by using UnitCompatibility::convert_pos2
Arguments
to
: The target unit to convert to.
returns: Option<Vec2D<N, UO>>
Examples
use mathie::unit::metric::Centimeter;
let v0 = mathie::Vec2D::<f32, Centimeter>::new(250.0, 250.0);
let v1 = v0.try_convert_u(()).unwrap();
assert_eq!(v1, mathie::Vec2D::new(2.5, 2.5));
See also
sourcepub fn any_unit(self) -> Vec2D<N, ()>
pub fn any_unit(self) -> Vec2D<N, ()>
Clears the unit value and converts this to an un-united vector.
sourcepub fn any(self, func: impl Fn(N) -> bool) -> bool
pub fn any(self, func: impl Fn(N) -> bool) -> bool
Checks if any of the values match a condition.
Examples
let v0 = mathie::Vec2D::new_any(2.0, 1.0);
assert!(v0.any(|v| v == 1.0))
sourcepub fn all(self, func: impl Fn(N) -> bool) -> bool
pub fn all(self, func: impl Fn(N) -> bool) -> bool
Checks if all of the values match a condition.
Examples
let v0 = mathie::Vec2D::new_any(2.0, 1.0);
assert!(!v0.all(|v| v == 1.0))
sourcepub fn map<NO: Number>(self, func: impl Fn(N) -> NO) -> Vec2D<NO, U>
pub fn map<NO: Number>(self, func: impl Fn(N) -> NO) -> Vec2D<NO, U>
Maps both of the values to the function result.
Examples
let v0 = mathie::Vec2D::new_any(1.0, 1.0);
assert_eq!(v0.map(|v| v + 2.0), mathie::Vec2D::new_any(1.0 + 2.0, 1.0 + 2.0))
sourcepub fn map_x(self, func: impl FnOnce(N) -> N) -> Vec2D<N, U>
pub fn map_x(self, func: impl FnOnce(N) -> N) -> Vec2D<N, U>
Maps the X value to the function result.
Examples
let v0 = mathie::Vec2D::new_any(1.0, 1.0);
assert_eq!(v0.map_x(|v| v + 2.0), mathie::Vec2D::new_any(1.0 + 2.0, 1.0))
sourcepub fn map_y(self, func: impl FnOnce(N) -> N) -> Vec2D<N, U>
pub fn map_y(self, func: impl FnOnce(N) -> N) -> Vec2D<N, U>
Maps the Y value to the function result.
Examples
let v0 = mathie::Vec2D::new_any(1.0, 1.0);
assert_eq!(v0.map_y(|v| v + 2.0), mathie::Vec2D::new_any(1.0, 1.0 + 2.0))
sourcepub fn add_vals(self) -> N
pub fn add_vals(self) -> N
Adds both of the values together.
Examples
let v0 = mathie::Vec2D::new_any(1.0, 1.0);
assert_eq!(v0.add_vals(), 2.0)
sourcepub fn sub_vals(self) -> N
pub fn sub_vals(self) -> N
Subtracts both of the values together.
Examples
let v0 = mathie::Vec2D::new_any(1.0, 2.0);
assert_eq!(v0.sub_vals(), -1.0)
sourcepub fn mul_vals(self) -> N
pub fn mul_vals(self) -> N
Multiplies both of the values together.
Examples
let v0 = mathie::Vec2D::new_any(2.0, 2.0);
assert_eq!(v0.mul_vals(), 4.0)
sourceimpl<N: Number + Float, U: Unit> Vec2D<N, U>
impl<N: Number + Float, U: Unit> Vec2D<N, U>
sourcepub fn lerp(self, other: Vec2D<N, U>, t: N) -> Vec2D<N, U>
pub fn lerp(self, other: Vec2D<N, U>, t: N) -> Vec2D<N, U>
Linearly interpolated the value of self
and other
by the value t
where 0 is self and 1 is other.
Arguments
other
: The target value.t
: A value which says where the value should be.
returns: Vec2D<N, U>
Examples
let v0 = mathie::Vec2D::new_any(1.0, 1.0);
let other = mathie::Vec2D::new_any(2.0, 2.0);
assert_eq!(v0.lerp(other, 0.0), v0);
assert_eq!(v0.lerp(other, 1.0), other);
assert_eq!(v0.lerp(other, 0.5), mathie::Vec2D::new_any(1.5, 1.5));
Trait Implementations
sourceimpl<T: Number + Add, U: Unit> AddAssign<T> for Vec2D<T, U>
impl<T: Number + Add, U: Unit> AddAssign<T> for Vec2D<T, U>
sourcefn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
Performs the +=
operation. Read more
sourceimpl<T: Number, U: Unit> AddAssign<Vec2D<T, U>> for Rect<T, U>
impl<T: Number, U: Unit> AddAssign<Vec2D<T, U>> for Rect<T, U>
sourcefn add_assign(&mut self, rhs: Vec2D<T, U>)
fn add_assign(&mut self, rhs: Vec2D<T, U>)
Performs the +=
operation. Read more
sourceimpl<T: Number + Add, U: Unit> AddAssign<Vec2D<T, U>> for Vec2D<T, U>
impl<T: Number + Add, U: Unit> AddAssign<Vec2D<T, U>> for Vec2D<T, U>
sourcefn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the +=
operation. Read more
sourceimpl<T: Number + Div, U: Unit> DivAssign<T> for Vec2D<T, U>
impl<T: Number + Div, U: Unit> DivAssign<T> for Vec2D<T, U>
sourcefn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
Performs the /=
operation. Read more
sourceimpl<T: Number, U: Unit> DivAssign<Vec2D<T, U>> for Rect<T, U>
impl<T: Number, U: Unit> DivAssign<Vec2D<T, U>> for Rect<T, U>
sourcefn div_assign(&mut self, rhs: Vec2D<T, U>)
fn div_assign(&mut self, rhs: Vec2D<T, U>)
Performs the /=
operation. Read more
sourceimpl<T: Number + Div, U: Unit> DivAssign<Vec2D<T, U>> for Vec2D<T, U>
impl<T: Number + Div, U: Unit> DivAssign<Vec2D<T, U>> for Vec2D<T, U>
sourcefn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
Performs the /=
operation. Read more
sourceimpl<T: Number + Mul, U: Unit> MulAssign<T> for Vec2D<T, U>
impl<T: Number + Mul, U: Unit> MulAssign<T> for Vec2D<T, U>
sourcefn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Performs the *=
operation. Read more
sourceimpl<T: Number, U: Unit> MulAssign<Vec2D<T, U>> for Rect<T, U>
impl<T: Number, U: Unit> MulAssign<Vec2D<T, U>> for Rect<T, U>
sourcefn mul_assign(&mut self, rhs: Vec2D<T, U>)
fn mul_assign(&mut self, rhs: Vec2D<T, U>)
Performs the *=
operation. Read more
sourceimpl<T: Number + Mul, U: Unit> MulAssign<Vec2D<T, U>> for Vec2D<T, U>
impl<T: Number + Mul, U: Unit> MulAssign<Vec2D<T, U>> for Vec2D<T, U>
sourcefn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the *=
operation. Read more
sourceimpl<N: Number + Ord, U: Unit> Ord for Vec2D<N, U>
impl<N: Number + Ord, U: Unit> Ord for Vec2D<N, U>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<N: Number, U: Unit> PartialOrd<Vec2D<N, U>> for Vec2D<N, U>
impl<N: Number, U: Unit> PartialOrd<Vec2D<N, U>> for Vec2D<N, U>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<T: Number + Rem, U: Unit> RemAssign<T> for Vec2D<T, U>
impl<T: Number + Rem, U: Unit> RemAssign<T> for Vec2D<T, U>
sourcefn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
Performs the %=
operation. Read more
sourceimpl<T: Number, U: Unit> RemAssign<Vec2D<T, U>> for Rect<T, U>
impl<T: Number, U: Unit> RemAssign<Vec2D<T, U>> for Rect<T, U>
sourcefn rem_assign(&mut self, rhs: Vec2D<T, U>)
fn rem_assign(&mut self, rhs: Vec2D<T, U>)
Performs the %=
operation. Read more
sourceimpl<T: Number + Rem, U: Unit> RemAssign<Vec2D<T, U>> for Vec2D<T, U>
impl<T: Number + Rem, U: Unit> RemAssign<Vec2D<T, U>> for Vec2D<T, U>
sourcefn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
Performs the %=
operation. Read more
sourceimpl<T: Number + Sub, U: Unit> SubAssign<T> for Vec2D<T, U>
impl<T: Number + Sub, U: Unit> SubAssign<T> for Vec2D<T, U>
sourcefn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
Performs the -=
operation. Read more
sourceimpl<T: Number, U: Unit> SubAssign<Vec2D<T, U>> for Rect<T, U>
impl<T: Number, U: Unit> SubAssign<Vec2D<T, U>> for Rect<T, U>
sourcefn sub_assign(&mut self, rhs: Vec2D<T, U>)
fn sub_assign(&mut self, rhs: Vec2D<T, U>)
Performs the -=
operation. Read more
sourceimpl<T: Number + Sub, U: Unit> SubAssign<Vec2D<T, U>> for Vec2D<T, U>
impl<T: Number + Sub, U: Unit> SubAssign<Vec2D<T, U>> for Vec2D<T, U>
sourcefn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the -=
operation. Read more
impl<T: Copy + Number, U: Copy + Unit> Copy for Vec2D<T, U>
impl<N: Number, U: Unit> Eq for Vec2D<N, U>
Auto Trait Implementations
impl<T, U> RefUnwindSafe for Vec2D<T, U> where
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<T, U> Send for Vec2D<T, U> where
T: Send,
U: Send,
impl<T, U> Sync for Vec2D<T, U> where
T: Sync,
U: Sync,
impl<T, U> Unpin for Vec2D<T, U> where
T: Unpin,
U: Unpin,
impl<T, U> UnwindSafe for Vec2D<T, U> where
T: UnwindSafe,
U: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more