Skip to main content

Vec2

Struct Vec2 

Source
#[repr(C)]
pub struct Vec2<F>
where F: Float,
{ pub x: F, pub y: F, }
Expand description

2D Euclidian vector with X and Y components.

Fields§

§x: F§y: F

Implementations§

Source§

impl<F> Vec2<F>
where F: Float,

Source

pub fn new(x: F, y: F) -> Self

Creates new vector.

Source

pub fn split(&self) -> (F, F)

Splits vector into X and Y components.

Source

pub fn combine(xy: (F, F)) -> Self

Combines tuple into vector.

Source

pub fn into_basis(self) -> (Self, Self)

Split vector into it’s basic vectors i, j.

Source

pub fn dot(&self, other: Self) -> F

Computes dot product between two vectors.

Source

pub fn dot_normalized(&self, other: Self) -> F

Computes dot product between two normalized copies of the vectors.

Source

pub fn scale(&mut self, factor: F)

Scales all of the components by factor.

Source

pub fn magnitude(&self) -> F

Computes the magnitude of the vector.

Source

pub fn sqrt_magnitude(&self) -> F

Computes the squared magnitude of the vector.

Source

pub fn distance_to(&self, other: Self) -> F

Computes the distance between two vectors.

Source

pub fn normalized(&self) -> Self

Returns the normalized version of the vector.

Source

pub fn normalize(&mut self)

Normalizes the vector, preserving direction but reducing its magnitude to 1.

Trait Implementations§

Source§

impl<F> Add for Vec2<F>
where F: Float,

Source§

type Output = Vec2<F>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<F> AddAssign for Vec2<F>
where F: Float,

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<F> Clone for Vec2<F>
where F: Float + Clone,

Source§

fn clone(&self) -> Vec2<F>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<F> Copy for Vec2<F>
where F: Float + Copy,

Source§

impl<F> Debug for Vec2<F>
where F: Float + Debug,

Source§

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

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

impl<F> Default for Vec2<F>
where F: Float + Default,

Source§

fn default() -> Vec2<F>

Returns the “default value” for a type. Read more
Source§

impl<F> Div<F> for Vec2<F>
where F: Float,

Source§

type Output = Vec2<F>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<F> DivAssign<F> for Vec2<F>
where F: Float,

Source§

fn div_assign(&mut self, rhs: F)

Performs the /= operation. Read more
Source§

impl<F> From<Complex<F>> for Vec2<F>
where F: Float,

Source§

fn from(z: Complex<F>) -> Self

Converts to this type from the input type.
Source§

impl<F> From<Vec2<F>> for Complex<F>
where F: Float,

Source§

fn from(v: Vec2<F>) -> Self

Converts to this type from the input type.
Source§

impl<F> Mul<F> for Vec2<F>
where F: Float,

Source§

type Output = Vec2<F>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<F> MulAssign<F> for Vec2<F>
where F: Float,

Source§

fn mul_assign(&mut self, rhs: F)

Performs the *= operation. Read more
Source§

impl<F> Neg for Vec2<F>
where F: Float,

Source§

type Output = Vec2<F>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<F> PartialEq for Vec2<F>
where F: Float + PartialEq,

Source§

fn eq(&self, other: &Vec2<F>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<F> PartialOrd for Vec2<F>
where F: Float + PartialOrd,

Source§

fn partial_cmp(&self, other: &Vec2<F>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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<F> StructuralPartialEq for Vec2<F>
where F: Float + PartialEq,

Source§

impl<F> Sub for Vec2<F>
where F: Float,

Source§

type Output = Vec2<F>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<F> SubAssign for Vec2<F>
where F: Float,

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<F> Vector<F> for Vec2<F>
where F: Float,

Source§

const SIZE: usize = 2

Source§

fn get(&self, i: usize) -> F

Source§

fn set(&mut self, i: usize, v: F)

Source§

impl<F> VectorConst<F> for Vec2<F>
where F: Float,

Source§

const SIZE: usize = 2

Source§

fn get<const I: usize>(&self) -> F

Source§

fn set<const I: usize>(&mut self, v: F)

Auto Trait Implementations§

§

impl<F> Freeze for Vec2<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for Vec2<F>
where F: RefUnwindSafe,

§

impl<F> Send for Vec2<F>
where F: Send,

§

impl<F> Sync for Vec2<F>
where F: Sync,

§

impl<F> Unpin for Vec2<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for Vec2<F>
where F: UnsafeUnpin,

§

impl<F> UnwindSafe for Vec2<F>
where F: 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.