pub struct Vector2<T = f64> {
    pub x: T,
    pub y: T,
}

Fields§

§x: T§y: T

Implementations§

source§

impl<T> Vector2<T>
where T: Real,

source

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

Create a new vector with x and y components.

source

pub fn zero() -> Self

Create a zero vector (x = 0, y = 0).

source

pub fn scale(&self, scale_factor: T) -> Self

Uniformly scale the vector by scale_factor.

source

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

Dot product.

source

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

Compute the perpendicular dot product (self.x * other.y - self.y * other.x).

source

pub fn length_squared(&self) -> T

Squared length of the vector.

source

pub fn length(&self) -> T

Length of the vector.

source

pub fn normalize(&self) -> Self

Normalize the vector (length = 1).

source

pub fn fuzzy_eq_eps(&self, other: Self, fuzzy_epsilon: T) -> bool

Fuzzy equal comparison with another vector using fuzzy_epsilon given.

source

pub fn fuzzy_eq(&self, other: Self) -> bool

Fuzzy equal comparison with another vector using T::fuzzy_epsilon().

source

pub fn perp(&self) -> Self

Create perpendicular vector.

source

pub fn unit_perp(&self) -> Self

Create perpendicular unit vector (length = 1).

source

pub fn rotate_about(&self, origin: Self, angle: T) -> Self

Rotate this point around an origin point by some angle in radians.

Trait Implementations§

source§

impl<'a, 'b, T: Real> Add<&'b Vector2<T>> for &'a Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the + operator.
source§

fn add(self, _rhs: &'b Vector2<T>) -> Self::Output

Performs the + operation. Read more
source§

impl<T: Real> Add<&Vector2<T>> for Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Vector2<T>) -> Self::Output

Performs the + operation. Read more
source§

impl<T: Real> Add<Vector2<T>> for &Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T: Real> Add for Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T: Clone> Clone for Vector2<T>

source§

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

source§

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

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

impl<T: Default> Default for Vector2<T>

source§

fn default() -> Vector2<T>

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

impl<T> Display for Vector2<T>
where T: Display,

source§

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

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

impl<T: Real> Neg for &Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<T: Real> Neg for Vector2<T>

§

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

source§

fn eq(&self, other: &Vector2<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<'a, 'b, T: Real> Sub<&'b Vector2<T>> for &'a Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the - operator.
source§

fn sub(self, _rhs: &'b Vector2<T>) -> Self::Output

Performs the - operation. Read more
source§

impl<T: Real> Sub<&Vector2<T>> for Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Vector2<T>) -> Self::Output

Performs the - operation. Read more
source§

impl<T: Real> Sub<Vector2<T>> for &Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T: Real> Sub for Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T: Copy> Copy for Vector2<T>

source§

impl<T: Eq> Eq for Vector2<T>

source§

impl<T> StructuralPartialEq for Vector2<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Vector2<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> 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> 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,

§

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.