Struct vector2::Vector2

source ·
pub struct Vector2 {
    pub x: f64,
    pub y: f64,
}

Fields§

§x: f64

X component of the vector.

§y: f64

Y component of the vector.

Implementations§

source§

impl Vector2

source

pub const DOWN: Self = _

Shorthand for writing Vector2::new(0.0, -1.0).

source

pub const LEFT: Self = _

Shorthand for writing Vector2::new(-1.0, 0.0).

source

pub const NEGATIVE_INFINITY: Self = _

Shorthand for writing Vector2::new(f64::NEG_INFINITY, f64::NEG_INFINITY).

source

pub const ONE: Self = _

Shorthand for writing Vector2::new(1.0, 1.0).

source

pub const POSITIVE_INFINITY: Self = _

Shorthand for writing Vector2::new(f64::INFINITY, f64::INFINITY).

source

pub const RIGHT: Self = _

Shorthand for writing Vector2::new(1.0, 0.0).

source

pub const UP: Self = _

Shorthand for writing Vector2::new(0.0, 1.0).

source

pub const ZERO: Self = _

Shorthand for writing Vector2::new(0.0, 0.0).

source

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

Constructs a new vector with given x, y components.

source

pub fn magnitude(&self) -> f64

Returns the length of this vector.

source

pub fn sqr_magnitude(&self) -> f64

Returns the squared length of this vector.

source

pub fn normalized(&self) -> Self

Returns this vector with a magnitude of 1.

source

pub fn normalize(&mut self)

Makes this vector have a magnitude of 1.

source

pub fn set(&mut self, new_x: f64, new_y: f64)

Set x and y components of an existing Vector2.

source

pub fn angle(from: Self, to: Self) -> f64

Gets the unsigned angle in degrees between from and to.

source

pub fn clamp_magnitude(vector: Self, max_length: f64) -> Self

Returns a copy of vector with its magnitude clamped to max_length.

source

pub fn distance(a: Self, b: Self) -> f64

Returns the distance between a and b.

source

pub fn dot(lhs: Self, rhs: Self) -> f64

Dot product of two vectors.

source

pub fn lerp(a: Self, b: Self, t: f64) -> Self

Linearly interpolates between vectors a and b by t.

source

pub fn lerp_unclamped(a: Self, b: Self, t: f64) -> Self

Linearly interpolates between vectors a and b by t.

source

pub fn max(lhs: Self, rhs: Self) -> Self

Returns a vector that is made from the largest components of two vectors.

source

pub fn min(lhs: Self, rhs: Self) -> Self

Returns a vector that is made from the smallest components of two vectors.

source

pub fn move_towards( current: Self, target: Self, max_distance_delta: f64 ) -> Self

Moves a point current towards target.

source

pub fn perpendicular(in_direction: Self) -> Self

Returns the 2D vector perpendicular to this 2D vector. The result is always rotated 90-degrees in a counter-clockwise direction for a 2D coordinate system where the positive Y axis goes up.

source

pub fn reflect(in_direction: Self, in_normal: Self) -> Self

Reflects a vector off the vector defined by a normal.

source

pub fn scale(a: Self, b: Self) -> Self

Multiplies two vectors component-wise.

source

pub fn signed_angle(from: Self, to: Self) -> f64

Gets the signed angle in degrees between from and to.

Trait Implementations§

source§

impl Add<Vector2> for Vector2

§

type Output = Vector2

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl AddAssign<Vector2> for Vector2

source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
source§

impl Clone for Vector2

source§

fn clone(&self) -> Vector2

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 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() -> Vector2

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

impl Display for Vector2

source§

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

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

impl Div<f64> for Vector2

§

type Output = Vector2

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl DivAssign<f64> for Vector2

source§

fn div_assign(&mut self, other: f64)

Performs the /= operation. Read more
source§

impl From<(f64, f64)> for Vector2

source§

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

Converts to this type from the input type.
source§

impl From<Vector2> for (f64, f64)

source§

fn from(value: Vector2) -> (f64, f64)

Converts to this type from the input type.
source§

impl Mul<Vector2> for f64

§

type Output = Vector2

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<f64> for Vector2

§

type Output = Vector2

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl MulAssign<f64> for Vector2

source§

fn mul_assign(&mut self, other: f64)

Performs the *= operation. Read more
source§

impl Neg for Vector2

§

type Output = Vector2

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl PartialEq<Vector2> for Vector2

source§

fn eq(&self, other: &Vector2) -> 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 Sub<Vector2> for Vector2

§

type Output = Vector2

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl SubAssign<Vector2> for Vector2

source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
source§

impl Copy for Vector2

source§

impl StructuralPartialEq for Vector2

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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.