#[repr(C)]pub struct Vec2<T: Number>(_);
Implementations
sourceimpl<N: Number> Vec2<N>
impl<N: Number> Vec2<N>
pub const fn split(v: N) -> Vec2<N>
pub fn zero() -> Vec2<N>
pub fn one() -> Vec2<N>
sourcepub fn cast<NO: Number>(self) -> Vec2<NO>
pub fn cast<NO: Number>(self) -> Vec2<NO>
Tries to cast the values to different number type.
Examples
use mathie::Vec2;
assert_eq!(Vec2::<f32>::new(250.5, 250.5).cast(), Vec2::<u32>::new(250, 250));
assert_eq!(Vec2::<f32>::new(0.5, 0.5).cast(), Vec2::<u32>::new(0, 0));
sourcepub fn try_cast<NO: Number>(self) -> Option<Vec2<NO>>
pub fn try_cast<NO: Number>(self) -> Option<Vec2<NO>>
Same as Self::cast but returns None if the cast failed.
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::Vec2::new(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::Vec2::new(2.0, 1.0);
assert!(!v0.all(|v| v == 1.0))
sourcepub fn map<NO: Number>(self, func: impl Fn(N) -> NO) -> Vec2<NO>
pub fn map<NO: Number>(self, func: impl Fn(N) -> NO) -> Vec2<NO>
Maps both of the values to the function result.
Examples
let v0 = mathie::Vec2::new(1.0, 1.0);
assert_eq!(v0.map(|v| v + 2.0), mathie::Vec2::new(1.0 + 2.0, 1.0 + 2.0))
sourcepub fn map_x(self, func: impl FnOnce(N) -> N) -> Vec2<N>
pub fn map_x(self, func: impl FnOnce(N) -> N) -> Vec2<N>
Maps the X value to the function result.
Examples
let v0 = mathie::Vec2::new(1.0, 1.0);
assert_eq!(v0.map_x(|v| v + 2.0), mathie::Vec2::new(1.0 + 2.0, 1.0))
sourcepub fn map_y(self, func: impl FnOnce(N) -> N) -> Vec2<N>
pub fn map_y(self, func: impl FnOnce(N) -> N) -> Vec2<N>
Maps the Y value to the function result.
Examples
let v0 = mathie::Vec2::new(1.0, 1.0);
assert_eq!(v0.map_y(|v| v + 2.0), mathie::Vec2::new(1.0, 1.0 + 2.0))
sourcepub fn add_xy(self) -> N
pub fn add_xy(self) -> N
Adds both of the values together.
Examples
let v0 = mathie::Vec2::new(1.0, 1.0);
assert_eq!(v0.add_xy(), 2.0)
sourcepub fn sub_xy(self) -> N
pub fn sub_xy(self) -> N
Subtracts both of the values together.
Examples
let v0 = mathie::Vec2::new(1.0, 2.0);
assert_eq!(v0.sub_xy(), -1.0)
sourcepub fn mul_xy(self) -> N
pub fn mul_xy(self) -> N
Multiplies both of the values together.
Examples
let v0 = mathie::Vec2::new(2.0, 2.0);
assert_eq!(v0.mul_xy(), 4.0)
sourcepub fn div_xy(self) -> N
pub fn div_xy(self) -> N
Divides x/y of the values together.
Examples
let v0 = mathie::Vec2::new(2.0, 4.0);
assert_eq!(v0.div_xy(), 0.5)
sourceimpl<N: Number + Ord> Vec2<N>
impl<N: Number + Ord> Vec2<N>
sourcepub fn min_val(self) -> N
pub fn min_val(self) -> N
Gets the smallest coordinate of the Vector.
Examples
let v0 = mathie::Vec2::new(1, 2);
assert_eq!(v0.min_val(), 1)
sourcepub fn max_val(self) -> N
pub fn max_val(self) -> N
Gets the biggest coordinate of the Vector.
Examples
let v0 = mathie::Vec2::new(1, 2);
assert_eq!(v0.max_val(), 2)
sourceimpl<F: Number + Float> Vec2<F>
impl<F: Number + Float> Vec2<F>
sourcepub fn norm(self) -> Vec2<F>
pub fn norm(self) -> Vec2<F>
Gets the normalized vector from this vector. Meaning a vector the length of 1
Examples
use mathie::Vec2;
let value = Vec2::new(4.0, 3.0);
assert_eq!(value.norm(), Vec2::new(4.0 / 5.0, 3.0 / 5.0));
assert_eq!(value.norm().hypot(), 1.0);
let value = Vec2::new(69.0, 420.0);
assert_eq!(value.norm().hypot(), 1.0);
sourcepub fn lerp(self, other: Vec2<F>, t: F) -> Vec2<F>
pub fn lerp(self, other: Vec2<F>, t: F) -> Vec2<F>
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::Vec2::new(1.0, 1.0);
let other = mathie::Vec2::new(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::Vec2::new(1.5, 1.5));
sourcepub fn minf_val(self) -> F
pub fn minf_val(self) -> F
The same as Self::min_val but for floating-point numbers.
sourcepub fn maxf_val(self) -> F
pub fn maxf_val(self) -> F
The same as Self::max_val but for floating-point numbers.
sourcepub fn minf(self, other: Vec2<F>) -> Vec2<F>
pub fn minf(self, other: Vec2<F>) -> Vec2<F>
The same as Self::min but for floating-point numbers.
Trait Implementations
sourceimpl<T: Number + Add> AddAssign<T> for Vec2<T>
impl<T: Number + Add> AddAssign<T> for Vec2<T>
sourcefn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+=
operation. Read moresourceimpl<T: Number> AddAssign<Vec2<T>> for Rect<T>
impl<T: Number> AddAssign<Vec2<T>> for Rect<T>
sourcefn add_assign(&mut self, rhs: Vec2<T>)
fn add_assign(&mut self, rhs: Vec2<T>)
+=
operation. Read moresourceimpl<T: Number + Add> AddAssign<Vec2<T>> for Vec2<T>
impl<T: Number + Add> AddAssign<Vec2<T>> for Vec2<T>
sourcefn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresourceimpl<T: Number + Div> DivAssign<T> for Vec2<T>
impl<T: Number + Div> DivAssign<T> for Vec2<T>
sourcefn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/=
operation. Read moresourceimpl<T: Number> DivAssign<Vec2<T>> for Rect<T>
impl<T: Number> DivAssign<Vec2<T>> for Rect<T>
sourcefn div_assign(&mut self, rhs: Vec2<T>)
fn div_assign(&mut self, rhs: Vec2<T>)
/=
operation. Read moresourceimpl<T: Number + Div> DivAssign<Vec2<T>> for Vec2<T>
impl<T: Number + Div> DivAssign<Vec2<T>> for Vec2<T>
sourcefn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moresourceimpl<T: Number + Mul> MulAssign<T> for Vec2<T>
impl<T: Number + Mul> MulAssign<T> for Vec2<T>
sourcefn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*=
operation. Read moresourceimpl<T: Number> MulAssign<Vec2<T>> for Rect<T>
impl<T: Number> MulAssign<Vec2<T>> for Rect<T>
sourcefn mul_assign(&mut self, rhs: Vec2<T>)
fn mul_assign(&mut self, rhs: Vec2<T>)
*=
operation. Read moresourceimpl<T: Number + Mul> MulAssign<Vec2<T>> for Vec2<T>
impl<T: Number + Mul> MulAssign<Vec2<T>> for Vec2<T>
sourcefn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moresourceimpl<N: Number + Ord> Ord for Vec2<N>
impl<N: Number + Ord> Ord for Vec2<N>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl<N: Number> PartialOrd<Vec2<N>> for Vec2<N>
impl<N: Number> PartialOrd<Vec2<N>> for Vec2<N>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl<T: Number + Rem> RemAssign<T> for Vec2<T>
impl<T: Number + Rem> RemAssign<T> for Vec2<T>
sourcefn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
%=
operation. Read moresourceimpl<T: Number> RemAssign<Vec2<T>> for Rect<T>
impl<T: Number> RemAssign<Vec2<T>> for Rect<T>
sourcefn rem_assign(&mut self, rhs: Vec2<T>)
fn rem_assign(&mut self, rhs: Vec2<T>)
%=
operation. Read moresourceimpl<T: Number + Rem> RemAssign<Vec2<T>> for Vec2<T>
impl<T: Number + Rem> RemAssign<Vec2<T>> for Vec2<T>
sourcefn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%=
operation. Read moresourceimpl<T: Number + Sub> SubAssign<T> for Vec2<T>
impl<T: Number + Sub> SubAssign<T> for Vec2<T>
sourcefn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-=
operation. Read moresourceimpl<T: Number> SubAssign<Vec2<T>> for Rect<T>
impl<T: Number> SubAssign<Vec2<T>> for Rect<T>
sourcefn sub_assign(&mut self, rhs: Vec2<T>)
fn sub_assign(&mut self, rhs: Vec2<T>)
-=
operation. Read moresourceimpl<T: Number + Sub> SubAssign<Vec2<T>> for Vec2<T>
impl<T: Number + Sub> SubAssign<Vec2<T>> for Vec2<T>
sourcefn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read more