# Vector2

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/numerics/struct-vector2/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct Vector2
```

A vector with two single-precision components.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L12)

## Members

- [`x`](#struct_field-x)
- [`y`](#struct_field-y)
- [`ZERO`](#assoc_const-zero)
- [`ONE`](#assoc_const-one)
- [`UNIT_X`](#assoc_const-unit_x)
- [`UNIT_Y`](#assoc_const-unit_y)
- [`new`](#function-new)
- [`from_value`](#function-from_value)
- [`abs`](#function-abs)
- [`clamp`](#function-clamp)
- [`distance`](#function-distance)
- [`distance_squared`](#function-distance_squared)
- [`dot`](#function-dot)
- [`length`](#function-length)
- [`length_squared`](#function-length_squared)
- [`lerp`](#function-lerp)
- [`max`](#function-max)
- [`min`](#function-min)
- [`normalize`](#function-normalize)
- [`square_root`](#function-square_root)
- [`transform`](#function-transform)
- [`transform_matrix4x4`](#function-transform_matrix4x4)
- [`transform_quaternion`](#function-transform_quaternion)
- [`transform_normal`](#function-transform_normal)

<a id="struct_field-x"></a>

### x

```rust
x: f32
```

The X component of the vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L14)

<a id="struct_field-y"></a>

### y

```rust
y: f32
```

The Y component of the vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L16)

<a id="assoc_const-zero"></a>

### ZERO

```rust
const ZERO: Vector2
```

The vector `(0, 0)`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L21)

<a id="assoc_const-one"></a>

### ONE

```rust
const ONE: Vector2
```

The vector `(1, 1)`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L23)

<a id="assoc_const-unit_x"></a>

### UNIT_X

```rust
const UNIT_X: Vector2
```

The vector `(1, 0)`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L25)

<a id="assoc_const-unit_y"></a>

### UNIT_Y

```rust
const UNIT_Y: Vector2
```

The vector `(0, 1)`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L27)

<a id="function-new"></a>

### new

```rust
const fn new(x: f32, y: f32) -> Self
```

Creates a vector from its components.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L31)

<a id="function-from_value"></a>

### from_value

```rust
const fn from_value(value: f32) -> Self
```

Creates a vector whose components all have the same value.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L37)

<a id="function-abs"></a>

### abs

```rust
fn abs(value: Vector2) -> Vector2
```

Returns a vector whose elements are the absolute values of each of the
specified vector's elements.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L44)

<a id="function-clamp"></a>

### clamp

```rust
fn clamp(value1: Vector2, min: Vector2, max: Vector2) -> Vector2
```

Restricts a vector between a minimum and a maximum value
(`min(max(value, min), max)`, so `max` wins when the bounds are inverted).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L51)

<a id="function-distance"></a>

### distance

```rust
fn distance(value1: Vector2, value2: Vector2) -> f32
```

Computes the Euclidean distance between the two given points.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L57)

<a id="function-distance_squared"></a>

### distance_squared

```rust
fn distance_squared(value1: Vector2, value2: Vector2) -> f32
```

Returns the Euclidean distance squared between two specified points.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L63)

<a id="function-dot"></a>

### dot

```rust
fn dot(value1: Vector2, value2: Vector2) -> f32
```

Returns the dot product of two vectors.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L69)

<a id="function-length"></a>

### length

```rust
fn length(self: &Self) -> f32
```

Returns the length of the vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L75)

<a id="function-length_squared"></a>

### length_squared

```rust
fn length_squared(self: &Self) -> f32
```

Returns the length of the vector squared.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L81)

<a id="function-lerp"></a>

### lerp

```rust
fn lerp(value1: Vector2, value2: Vector2, amount: f32) -> Vector2
```

Performs a linear interpolation between two vectors based on the given weighting.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L87)

<a id="function-max"></a>

### max

```rust
fn max(value1: Vector2, value2: Vector2) -> Vector2
```

Returns a vector whose elements are the maximum of each of the pairs of
elements in two specified vectors.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L94)

<a id="function-min"></a>

### min

```rust
fn min(value1: Vector2, value2: Vector2) -> Vector2
```

Returns a vector whose elements are the minimum of each of the pairs of
elements in two specified vectors.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L101)

<a id="function-normalize"></a>

### normalize

```rust
fn normalize(value: Vector2) -> Vector2
```

Returns a vector with the same direction as the specified vector, but
with a length of one (NaN components for a zero-length vector).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L108)

<a id="function-square_root"></a>

### square_root

```rust
fn square_root(value: Vector2) -> Vector2
```

Returns a vector whose elements are the square root of each of a
specified vector's elements.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L115)

<a id="function-transform"></a>

### transform

```rust
fn transform(position: Vector2, matrix: Matrix3x2) -> Vector2
```

Transforms a vector by a specified 3x2 matrix.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L121)

<a id="function-transform_matrix4x4"></a>

### transform_matrix4x4

```rust
fn transform_matrix4x4(position: Vector2, matrix: Matrix4x4) -> Vector2
```

Transforms a vector by a specified 4x4 matrix.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L130)

<a id="function-transform_quaternion"></a>

### transform_quaternion

```rust
fn transform_quaternion(value: Vector2, rotation: Quaternion) -> Vector2
```

Transforms a vector by the specified rotation.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L138)

<a id="function-transform_normal"></a>

### transform_normal

```rust
fn transform_normal(normal: Vector2, matrix: Matrix3x2) -> Vector2
```

Transforms a vector normal by the given 3x2 matrix.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/numerics/vector2.rs#L157)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ToString`
- `ErasedDestructor`
- `IntoEither`
- `Clone`
- `Copy`
- `Debug`
- `StructuralPartialEq`
- `PartialEq`
- `Default`
- `From<Vector>`
- `From<Vector2>`
- `Add`
- `Sub`
- `Mul`
- `Mul<f32>`
- `Mul<Vector2>`
- `Div`
- `Div<f32>`
- `Neg`
- `AddAssign`
- `SubAssign`
- `MulAssign`
- `MulAssign<f32>`
- `DivAssign`
- `DivAssign<f32>`
- `Display`
- `IInterpolator<Vector2>`
- `SpringValue`
- `ExpressionVariantValue`
- `BatchValue`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
