Struct xyzvec::xy::XYVec

source ·
pub struct XYVec<T> { /* private fields */ }

Implementations§

source§

impl<T: VecInner> XYVec<T>

source

pub fn new(inner: [T; 2]) -> Self

source

pub fn x(&self) -> T

x component of XYVec

source

pub fn y(&self) -> T

y component of XYVec

source

pub fn scale_by(&self, d: T) -> Self

   use xyzvec::XYVec;
   use approx::assert_relative_eq;

   let v = XYVec::new([1.0f64, -0.5f64]);
   let scaled_v = v.scale_by(5.0);
   assert_relative_eq!(scaled_v.x(), 5.0);
   assert_relative_eq!(scaled_v.y(), -2.5);
source

pub fn div_by(&self, d: T) -> Self

   use xyzvec::XYVec;
   use approx::assert_relative_eq;

   let v = XYVec::new([1.0f64, -0.5f64]);
   let scaled_v = v.div_by(0.2);
   assert_relative_eq!(scaled_v.x(), 5.0);
   assert_relative_eq!(scaled_v.y(), -2.5);
source

pub fn l1_norm(&self) -> T

   use xyzvec::XYVec;
   use approx::assert_relative_eq;
source

pub fn l2_norm_sqd(&self) -> T

   use xyzvec::XYVec;
   use approx::assert_relative_eq;
source

pub fn cross_prod(&self, other: Self) -> T

   use xyzvec::XYVec;
   use approx::assert_relative_eq;

   let v = XYVec::new([1.0f64, -0.5f64]);
   let w = XYVec::new([-2.0f64, 0.0f64]);
   assert_relative_eq!(v.cross_prod(w), -1.0);
source

pub fn cross_prod_sqd(&self, other: Self) -> T

   use xyzvec::XYVec;
   use approx::assert_relative_eq;

   let v = XYVec::new([1.0f64, -0.5f64]);
   let w = XYVec::new([-2.0f64, 0.0f64]);
   assert_relative_eq!(v.cross_prod_sqd(w), 1.0);
source

pub fn dot_prod(&self, other: Self) -> T

   use xyzvec::XYVec;
   use approx::assert_relative_eq;

   let v = XYVec::new([1.0f64, -0.5f64]);
   let w = XYVec::new([-2.0f64, 0.0f64]);
   assert_relative_eq!(v.dot_prod(w), -2.0);
source

pub fn translate_by(&self, x: T, y: T) -> Self

   use xyzvec::XYVec;
   use approx::assert_relative_eq;

   let v = XYVec::new([1.0f64, -0.5f64]);
   let scaled_v = v.translate_by(1.0, 1.0);
   assert_relative_eq!(scaled_v.x(), 2.0);
   assert_relative_eq!(scaled_v.y(), 0.5);
source

pub fn sum(&self) -> T

    use xyzvec::XYVec;
    use approx::assert_relative_eq;    
source

pub fn iter(&self) -> Iter<'_, T>

    use xyzvec::XYVec;
    use approx::assert_relative_eq;    
     
    let v = XYVec::new([1.0f64, -0.5f64]);
    let v2: XYVec<f64> = v.iter().map(|a| a + 1.0).collect();
    assert_relative_eq!(v2.x(), 2.0);
    assert_relative_eq!(v2.y(), 0.5);
source§

impl XYVec<f32>

source

pub fn l2_norm(&self) -> f32

source

pub fn zeroes() -> Self

source

pub fn rotated_by(&self, theta: f32) -> Self

source§

impl XYVec<f64>

source

pub fn l2_norm(&self) -> f64

source

pub fn zeroes() -> Self

source

pub fn rotated_by(&self, theta: f64) -> Self

source§

impl<Frac> XYVec<FixedI64<Frac>>

source

pub fn zeroes() -> Self

Trait Implementations§

source§

impl<T: VecInner> Add for XYVec<T>

§

type Output = XYVec<T>

The resulting type after applying the + operator.
source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
source§

impl<T: VecInner> AddAssign for XYVec<T>

source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
source§

impl<T: Clone> Clone for XYVec<T>

source§

fn clone(&self) -> XYVec<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: VecInner> Debug for XYVec<T>

source§

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

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

impl<T: VecInner> Display for XYVec<T>

source§

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

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

impl<T: VecInner> FromIterator<T> for XYVec<T>

Build XYVec from iterator of size two. TODO: check for errors better

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T: VecInner> Neg for XYVec<T>

§

type Output = XYVec<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 for XYVec<T>

source§

fn eq(&self, other: &XYVec<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: VecInner> Sub for XYVec<T>

§

type Output = XYVec<T>

The resulting type after applying the - operator.
source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
source§

impl<T: VecInner> SubAssign for XYVec<T>

source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
source§

impl<T: Copy> Copy for XYVec<T>

source§

impl<T> StructuralPartialEq for XYVec<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for XYVec<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> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> ToOwned for T
where 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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.