Struct Vector2

Source
pub struct Vector2<U> {
    pub x: U,
    pub y: U,
}

Fields§

§x: U§y: U

Implementations§

Source§

impl<U> Vector2<U>

Source

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

Source§

impl<U, W> Vector2<U>
where Vector2<U>: Clone + Copy + Mul<Vector2<U>, Output = W>,

Source

pub fn length_squared(self) -> W

Source§

impl Vector2<f32>

Source

pub fn from_angle(angle: f32, magnitude: f32) -> Self

Source

pub fn length(self) -> f32

Source

pub fn distance(self, other: Self) -> f32

Source

pub fn normalized(self) -> Self

Source

pub fn normalize(&mut self) -> &mut Self

Source

pub fn angle(self) -> f32

Source

pub fn angle_from(self, other: Self) -> f32

Source§

impl Vector2<f64>

Source

pub fn from_angle(angle: f64, magnitude: f64) -> Self

Source

pub fn length(&self) -> f64

Source

pub fn distance(self, other: Self) -> f64

Source

pub fn normalized(&self) -> Self

Source

pub fn normalize(&mut self) -> &mut Self

Source

pub fn angle(&self) -> f64

Source

pub fn angle_between(&self, other: &Self) -> f64

Source§

impl<U: Clone + Default> Vector2<U>

Source

pub fn horizontal(&self) -> Self

Source

pub fn vertical(&self) -> Self

Source§

impl<U: Clone + Copy + Neg<Output = U>> Vector2<U>

Source

pub fn normal(&self) -> Self

Trait Implementations§

Source§

impl<U: Add<Output = V>, V> Add for Vector2<U>

Source§

type Output = Vector2<V>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<U: AddAssign> AddAssign for Vector2<U>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<U: Clone> Clone for Vector2<U>

Source§

fn clone(&self) -> Vector2<U>

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<U: Debug> Debug for Vector2<U>

Source§

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

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

impl<U: Default> Default for Vector2<U>

Source§

fn default() -> Vector2<U>

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

impl<U, V> Div<U> for Vector2<U>
where U: Div<Output = V> + Clone,

Source§

type Output = Vector2<V>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<U: DivAssign + Clone> DivAssign<U> for Vector2<U>

Source§

fn div_assign(&mut self, rhs: U)

Performs the /= operation. Read more
Source§

impl<U: Clone + Copy> From<[U; 2]> for Vector2<U>

Source§

fn from(value: [U; 2]) -> Self

Converts to this type from the input type.
Source§

impl<U: Clone + Copy> From<(U, U)> for Vector2<U>

Source§

fn from(value: (U, U)) -> Self

Converts to this type from the input type.
Source§

impl<U, V> Mul<U> for Vector2<U>
where U: Clone + Copy + Mul<Output = V>,

Source§

type Output = Vector2<V>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<U> Mul for Vector2<U>
where U: Mul<Output = U> + Add<Output = U>,

Source§

type Output = U

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector2<U>) -> Self::Output

Performs the * operation. Read more
Source§

impl<U: Clone + Copy + MulAssign> MulAssign<U> for Vector2<U>

Source§

fn mul_assign(&mut self, rhs: U)

Performs the *= operation. Read more
Source§

impl<U: Neg<Output = V>, V> Neg for Vector2<U>

Source§

type Output = Vector2<V>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<U: PartialEq> PartialEq for Vector2<U>

Source§

fn eq(&self, other: &Vector2<U>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<U: Sub<Output = V>, V> Sub for Vector2<U>

Source§

type Output = Vector2<V>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<U: SubAssign> SubAssign for Vector2<U>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl Sum for Vector2<f32>

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Sum for Vector2<f64>

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<U: Zero + PartialEq> Zero for Vector2<U>

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<U: Copy> Copy for Vector2<U>

Source§

impl<U: Eq> Eq for Vector2<U>

Source§

impl<U> StructuralPartialEq for Vector2<U>

Auto Trait Implementations§

§

impl<U> Freeze for Vector2<U>
where U: Freeze,

§

impl<U> RefUnwindSafe for Vector2<U>
where U: RefUnwindSafe,

§

impl<U> Send for Vector2<U>
where U: Send,

§

impl<U> Sync for Vector2<U>
where U: Sync,

§

impl<U> Unpin for Vector2<U>
where U: Unpin,

§

impl<U> UnwindSafe for Vector2<U>
where U: 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.