Skip to main content

Vector2

Struct Vector2 

Source
pub struct Vector2 {
    pub x: f64,
    pub y: f64,
}
Expand description

A displacement or direction, distinct from a Point position.

Fields§

§x: f64

Horizontal displacement.

§y: f64

Vertical displacement.

Implementations§

Source§

impl Vector2

Source

pub const ZERO: Self

A displacement with no movement.

Source

pub const fn new(horizontal: f64, vertical: f64) -> Self

Preserves the supplied components; validation belongs to the consumer.

Source

pub fn from_angle(radians: f64) -> Self

Returns a unit vector at clockwise radians from the positive horizontal axis. Principal quarter-turn angles preserve exact axis alignment.

Source

pub fn length(self) -> f64

Returns Euclidean length without squaring unscaled components.

Source

pub fn normalize(self) -> Self

Returns a unit direction, or zero for a zero vector. Finite very large or very small components are scaled before normalization. Nonfinite input does not become a finite zero vector.

Source

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

Returns the scalar dot product.

Source

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

Returns the signed two-dimensional cross product.

Source

pub fn rotate(self, radians: f64) -> Self

Rotates clockwise in the downward-positive coordinate system.

Source

pub fn interpolate(&self, target: &Self, progress: f64) -> Self

Linearly interpolates or extrapolates with double-precision progress.

Trait Implementations§

Source§

impl Add for Vector2

Source§

type Output = Vector2

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<Vector2> for Point

Source§

type Output = Point

The resulting type after applying the + operator.
Source§

fn add(self, displacement: Vector2) -> Self

Performs the + operation. Read more
Source§

impl Clone for Vector2

Source§

fn clone(&self) -> Self

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 Copy for Vector2

Source§

impl Debug for Vector2

Source§

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

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

impl Default for Vector2

Source§

fn default() -> Self

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

impl Div<f64> for Vector2

Source§

type Output = Vector2

The resulting type after applying the / operator.
Source§

fn div(self, divisor: f64) -> Self

Performs the / operation. Read more
Source§

impl Interpolate for Vector2

Source§

fn interpolate(&self, target: &Self, progress: f64) -> Self

Blends toward target with nominal progress zero at self and one at target. Read more
Source§

impl Mul<Vector2> for f64

Source§

type Output = Vector2

The resulting type after applying the * operator.
Source§

fn mul(self, vector: Vector2) -> Vector2

Performs the * operation. Read more
Source§

impl Mul<f64> for Vector2

Source§

type Output = Vector2

The resulting type after applying the * operator.
Source§

fn mul(self, factor: f64) -> Self

Performs the * operation. Read more
Source§

impl Neg for Vector2

Source§

type Output = Vector2

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Vector2

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Vector2

Source§

impl Sub for Vector2

Source§

type Output = Vector2

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<Vector2> for Point

Source§

type Output = Point

The resulting type after applying the - operator.
Source§

fn sub(self, displacement: Vector2) -> Self

Performs the - operation. Read more

Auto Trait Implementations§

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.