Struct vect::vector2::Vector2

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

Fields

x: f64y: f64

Implementations

Creates a new Vector2

Shorthand for Vector2 { x: 0.0, y: 1.0 }

Shorthand for Vector2 { x: 0.0, y: -1.0 }

Shorthand for Vector2 { x: -1.0, y: 0.0 }

Shorthand for Vector2 { x: 1.0, y: 0.0 }

Trait Implementations

Adds two vectors together.

Example:

let a = Vector2::new(1.0, 2.0);
let b = Vector2::new(3.0, 4.0);
let res = a + b;
let expected = Vector2::new(4.0, 6.0);
 
assert_eq!(res, expected);
The resulting type after applying the + operator.

Adds two vectors together and assigns the result back to the first.

Example:

let mut a = Vector2::new(1.0, 2.0);
let b = Vector2::new(3.0, 4.0);
a += b;
let expected = Vector2::new(4.0, 6.0);
 
assert_eq!(a, expected);
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Divides a scalar with some vector

The resulting type after applying the / operator.

Divides the vector with some scalar

The resulting type after applying the / operator.

Divides the vector with some scalar and assigns the result back into the vector

Creates a Vector3 from a Vector2, adding a z component of 0

Turns a Vector3 into a Vector2, discarding the z component.

Multiplies a scalar with some vector

Example:

let a = Vector2::new(2.5, 5.0);
let res = 2.0 * a;
let expected = Vector2::new(5.0, 10.0);
 
assert_eq!(res, expected);
The resulting type after applying the * operator.

Multiplies the vector with some scalar

Example:

let a = Vector2::new(3.0, 4.0);
let res = a * 3.0;
let expected = Vector2::new(9.0, 12.0);
 
assert_eq!(res, expected);
The resulting type after applying the * operator.

Multiplies the vector with some scalar and assigns the result back onto the vector

Example:

let mut a = Vector2::new(3.0, 4.0);
a *= 3.0;
let expected = Vector2::new(9.0, 12.0);
 
assert_eq!(a, expected);
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Subtracts two vectors from each other.

Example:

let a = Vector2::new(5.0, 8.0);
let b = Vector2::new(6.0, 4.0);
let res = a - b;
let expected = Vector2::new(-1.0, 4.0);
 
assert_eq!(res, expected);
The resulting type after applying the - operator.

Subtracts two vectors from each other and assigns the result back to the first.

Example:

let mut a = Vector2::new(5.0, 8.0);
let b = Vector2::new(6.0, 4.0);
a -= b;
let expected = Vector2::new(-1.0, 4.0);
 
assert_eq!(a, expected);

Reflects the vector along the normal vector.

Example:

let a = Vector2::new(1.0, 2.0);
let n = Vector2::up();
let r = a.reflect(n);
 
assert_eq!(r, Vector2::new(1.0, -2.0));
The Zero vector
Gets the magnitude (length) of the vector
Returns a vector with the same angle, but with a magnitude of 1
Mutates the vector such that it gains a magnitude of 1
Returns the magnitude squared
Returns the angle between two vectors
Returns a new vector with a magnitude clamped to max_len.
Returns the dot product between two vectors
Performs a linear interpolation between self and other over t. Read more
Performs a linear interpolation, where t isn’t clamped between 0 and 1. Read more
Returns the largest of the two vectors
Returns the smallest of the two vectors

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.