# Struct cgmath::Vector2 [−] [src]

```pub struct Vector2<S> {
pub x: S,
pub y: S,
}```

A 2-dimensional vector.

This type is marked as `#[repr(C, packed)]`.

## Fields

`x: S`

The x component of the vector.

`y: S`

The y component of the vector.

## Methods

### `impl<S> Vector2<S>`[src]

#### `fn new(x: S, y: S) -> Vector2<S>`

Construct a new vector, using the provided values.

### `impl<S: NumCast + Copy> Vector2<S>`[src]

#### `fn cast<T: NumCast>(&self) -> Vector2<T>`

Component-wise casting to another type

### `impl<S: BaseNum> Vector2<S>`[src]

#### `fn unit_x() -> Vector2<S>`

A unit vector in the `x` direction.

#### `fn unit_y() -> Vector2<S>`

A unit vector in the `y` direction.

#### `fn perp_dot(self, other: Vector2<S>) -> S`

The perpendicular dot product of the vector and `other`.

#### `fn extend(self, z: S) -> Vector3<S>`

Create a `Vector3`, using the `x` and `y` values from this vector, and the provided `z`.

## Trait Implementations

### `impl<S: Hash> Hash for Vector2<S>`[src]

#### `fn hash<__HS: Hasher>(&self, __arg_0: &mut __HS)`

Feeds this value into the state given, updating the hasher as necessary.

#### `fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher`1.3.0

Feeds a slice of this type into the state provided.

### `impl<S: Clone> Clone for Vector2<S>`[src]

#### `fn clone(&self) -> Vector2<S>`

Returns a copy of the value. Read more

#### `fn clone_from(&mut self, source: &Self)`1.0.0

Performs copy-assignment from `source`. Read more

### `impl<S: PartialEq> PartialEq for Vector2<S>`[src]

#### `fn eq(&self, __arg_0: &Vector2<S>) -> bool`

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `fn ne(&self, __arg_0: &Vector2<S>) -> bool`

This method tests for `!=`.

### `impl<S: BaseFloat> MetricSpace for Vector2<S>`[src]

#### `type Metric = S`

The metric to be returned by the `distance` function.

#### `fn distance2(self, other: Self) -> S`

Returns the squared distance. Read more

#### `fn distance(self, other: Self) -> Self::Metric`

The distance between two values.

### `impl<S: Copy> Array for Vector2<S>`[src]

#### `fn from_value(scalar: S) -> Vector2<S>`

Construct a vector from a single value, replicating it. Read more

#### `fn sum(self) -> S where S: Add<Output=S>`

The sum of the elements of the array.

#### `fn product(self) -> S where S: Mul<Output=S>`

The product of the elements of the array.

#### `fn min(self) -> S where S: PartialOrd`

The minimum element of the array.

#### `fn max(self) -> S where S: PartialOrd`

The maximum element of the array.

#### `fn as_ptr(&self) -> *const Self::Element`

Get the pointer to the first element of the array.

#### `fn as_mut_ptr(&mut self) -> *mut Self::Element`

Get a mutable pointer to the first element of the array.

#### `fn swap_elements(&mut self, i: usize, j: usize)`

Swap the elements at indices `i` and `j` in-place.

### `impl<S: BaseNum> Zero for Vector2<S>`[src]

#### `fn zero() -> Vector2<S>`

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

#### `fn is_zero(&self) -> bool`

Returns `true` if `self` is equal to the additive identity.

### `impl<S: BaseNum> VectorSpace for Vector2<S>`[src]

#### `type Scalar = S`

The associated scalar.

### `impl<S: Neg<Output=S>> Neg for Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `-` operator

#### `fn neg(self) -> Vector2<S>`

The method for the unary `-` operator

### `impl<S: BaseFloat + Rand> Rand for Vector2<S>`[src]

#### `fn rand<R: Rng>(rng: &mut R) -> Vector2<S>`

Generates a random instance of this type using the specified source of randomness. Read more

### `impl<S: BaseNum> Add<Vector2<S>> for Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `+` operator

#### `fn add(self, other: Vector2<S>) -> Vector2<S>`

The method for the `+` operator

### `impl<'a, S: BaseNum> Add<&'a Vector2<S>> for Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `+` operator

#### `fn add(self, other: &'a Vector2<S>) -> Vector2<S>`

The method for the `+` operator

### `impl<'a, S: BaseNum> Add<Vector2<S>> for &'a Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `+` operator

#### `fn add(self, other: Vector2<S>) -> Vector2<S>`

The method for the `+` operator

### `impl<'a, 'b, S: BaseNum> Add<&'a Vector2<S>> for &'b Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `+` operator

#### `fn add(self, other: &'a Vector2<S>) -> Vector2<S>`

The method for the `+` operator

### `impl<S: BaseNum + AddAssign<S>> AddAssign<Vector2<S>> for Vector2<S>`[src]

#### `fn add_assign(&mut self, other: Vector2<S>)`

The method for the `+=` operator

### `impl<S: BaseNum> Sub<Vector2<S>> for Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `-` operator

#### `fn sub(self, other: Vector2<S>) -> Vector2<S>`

The method for the `-` operator

### `impl<'a, S: BaseNum> Sub<&'a Vector2<S>> for Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `-` operator

#### `fn sub(self, other: &'a Vector2<S>) -> Vector2<S>`

The method for the `-` operator

### `impl<'a, S: BaseNum> Sub<Vector2<S>> for &'a Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `-` operator

#### `fn sub(self, other: Vector2<S>) -> Vector2<S>`

The method for the `-` operator

### `impl<'a, 'b, S: BaseNum> Sub<&'a Vector2<S>> for &'b Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `-` operator

#### `fn sub(self, other: &'a Vector2<S>) -> Vector2<S>`

The method for the `-` operator

### `impl<S: BaseNum + SubAssign<S>> SubAssign<Vector2<S>> for Vector2<S>`[src]

#### `fn sub_assign(&mut self, other: Vector2<S>)`

The method for the `-=` operator

### `impl<S: BaseNum> Mul<S> for Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `*` operator

#### `fn mul(self, other: S) -> Vector2<S>`

The method for the `*` operator

### `impl<'a, S: BaseNum> Mul<S> for &'a Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `*` operator

#### `fn mul(self, other: S) -> Vector2<S>`

The method for the `*` operator

### `impl<S: BaseNum + MulAssign<S>> MulAssign<S> for Vector2<S>`[src]

#### `fn mul_assign(&mut self, scalar: S)`

The method for the `*=` operator

### `impl<S: BaseNum> Div<S> for Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `/` operator

#### `fn div(self, other: S) -> Vector2<S>`

The method for the `/` operator

### `impl<'a, S: BaseNum> Div<S> for &'a Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `/` operator

#### `fn div(self, other: S) -> Vector2<S>`

The method for the `/` operator

### `impl<S: BaseNum + DivAssign<S>> DivAssign<S> for Vector2<S>`[src]

#### `fn div_assign(&mut self, scalar: S)`

The method for the `/=` operator

### `impl<S: BaseNum> Rem<S> for Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `%` operator

#### `fn rem(self, other: S) -> Vector2<S>`

The method for the `%` operator

### `impl<'a, S: BaseNum> Rem<S> for &'a Vector2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `%` operator

#### `fn rem(self, other: S) -> Vector2<S>`

The method for the `%` operator

### `impl<S: BaseNum + RemAssign<S>> RemAssign<S> for Vector2<S>`[src]

#### `fn rem_assign(&mut self, scalar: S)`

The method for the `%=` operator

### `impl<S> Index<usize> for Vector2<S>`[src]

#### `type Output = S`

The returned type after indexing

#### `fn index<'a>(&'a self, i: usize) -> &'a S`

The method for the indexing (`Foo[Bar]`) operation

### `impl<S> IndexMut<usize> for Vector2<S>`[src]

#### `fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut S`

The method for the indexing (`Foo[Bar]`) operation

### `impl<S> Index<Range<usize>> for Vector2<S>`[src]

#### `type Output = [S]`

The returned type after indexing

#### `fn index<'a>(&'a self, i: Range<usize>) -> &'a [S]`

The method for the indexing (`Foo[Bar]`) operation

### `impl<S> IndexMut<Range<usize>> for Vector2<S>`[src]

#### `fn index_mut<'a>(&'a mut self, i: Range<usize>) -> &'a mut [S]`

The method for the indexing (`Foo[Bar]`) operation

### `impl<S> Index<RangeTo<usize>> for Vector2<S>`[src]

#### `type Output = [S]`

The returned type after indexing

#### `fn index<'a>(&'a self, i: RangeTo<usize>) -> &'a [S]`

The method for the indexing (`Foo[Bar]`) operation

### `impl<S> IndexMut<RangeTo<usize>> for Vector2<S>`[src]

#### `fn index_mut<'a>(&'a mut self, i: RangeTo<usize>) -> &'a mut [S]`

The method for the indexing (`Foo[Bar]`) operation

### `impl<S> Index<RangeFrom<usize>> for Vector2<S>`[src]

#### `type Output = [S]`

The returned type after indexing

#### `fn index<'a>(&'a self, i: RangeFrom<usize>) -> &'a [S]`

The method for the indexing (`Foo[Bar]`) operation

### `impl<S> IndexMut<RangeFrom<usize>> for Vector2<S>`[src]

#### `fn index_mut<'a>(&'a mut self, i: RangeFrom<usize>) -> &'a mut [S]`

The method for the indexing (`Foo[Bar]`) operation

### `impl<S> Index<RangeFull> for Vector2<S>`[src]

#### `type Output = [S]`

The returned type after indexing

#### `fn index<'a>(&'a self, i: RangeFull) -> &'a [S]`

The method for the indexing (`Foo[Bar]`) operation

### `impl<S> IndexMut<RangeFull> for Vector2<S>`[src]

#### `fn index_mut<'a>(&'a mut self, i: RangeFull) -> &'a mut [S]`

The method for the indexing (`Foo[Bar]`) operation

### `impl<S> Into<[S; 2]> for Vector2<S>`[src]

#### `fn into(self) -> [S; 2]`

Performs the conversion.

### `impl<S> AsRef<[S; 2]> for Vector2<S>`[src]

#### `fn as_ref(&self) -> &[S; 2]`

Performs the conversion.

### `impl<S> AsMut<[S; 2]> for Vector2<S>`[src]

#### `fn as_mut(&mut self) -> &mut [S; 2]`

Performs the conversion.

### `impl<S: Clone> From<[S; 2]> for Vector2<S>`[src]

#### `fn from(v: [S; 2]) -> Vector2<S>`

Performs the conversion.

### `impl<'a, S> From<&'a [S; 2]> for &'a Vector2<S>`[src]

#### `fn from(v: &'a [S; 2]) -> &'a Vector2<S>`

Performs the conversion.

### `impl<'a, S> From<&'a mut [S; 2]> for &'a mut Vector2<S>`[src]

#### `fn from(v: &'a mut [S; 2]) -> &'a mut Vector2<S>`

Performs the conversion.

### `impl<S> Into<(S, S)> for Vector2<S>`[src]

#### `fn into(self) -> (S, S)`

Performs the conversion.

### `impl<S> AsRef<(S, S)> for Vector2<S>`[src]

#### `fn as_ref(&self) -> &(S, S)`

Performs the conversion.

### `impl<S> AsMut<(S, S)> for Vector2<S>`[src]

#### `fn as_mut(&mut self) -> &mut (S, S)`

Performs the conversion.

### `impl<S> From<(S, S)> for Vector2<S>`[src]

#### `fn from(v: (S, S)) -> Vector2<S>`

Performs the conversion.

### `impl<'a, S> From<&'a (S, S)> for &'a Vector2<S>`[src]

#### `fn from(v: &'a (S, S)) -> &'a Vector2<S>`

Performs the conversion.

### `impl<'a, S> From<&'a mut (S, S)> for &'a mut Vector2<S>`[src]

#### `fn from(v: &'a mut (S, S)) -> &'a mut Vector2<S>`

Performs the conversion.

### `impl<S: BaseFloat> InnerSpace for Vector2<S>`[src]

#### `fn dot(self, other: Vector2<S>) -> S`

Vector dot (or inner) product.

#### `fn angle(self, other: Vector2<S>) -> Rad<S>`

Returns the angle between two vectors in radians.

#### `fn is_perpendicular(self, other: Self) -> bool`

Returns `true` if the vector is perpendicular (at right angles) to the other vector. Read more

#### `fn magnitude2(self) -> Self::Scalar`

Returns the squared magnitude. Read more

#### `fn magnitude(self) -> Self::Scalar`

The distance from the tail to the tip of the vector.

#### `fn normalize(self) -> Self`

Returns a vector with the same direction, but with a magnitude of `1`.

#### `fn normalize_to(self, magnitude: Self::Scalar) -> Self`

Returns a vector with the same direction and a given magnitude.

#### `fn lerp(self, other: Self, amount: Self::Scalar) -> Self`

Returns the result of linearly interpolating the magnitude of the vector towards the magnitude of `other` by the specified amount. Read more

### `impl<S: Debug> Debug for Vector2<S>`[src]

#### `fn fmt(&self, f: &mut Formatter) -> Result`

Formats the value using the given formatter.