# Vector

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

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

```rust
struct Vector
```

Defines a vector.

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

## 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)
- [`parse`](#function-parse)
- [`length`](#function-length)
- [`squared_length`](#function-squared_length)
- [`equals`](#function-equals)
- [`nearly_equals`](#function-nearly_equals)
- [`with_x`](#function-with_x)
- [`with_y`](#function-with_y)
- [`normalize`](#function-normalize)
- [`negate`](#function-negate)
- [`dot`](#function-dot)
- [`cross`](#function-cross)
- [`normalize_vector`](#function-normalize_vector)
- [`divide`](#function-divide)
- [`divide_scalar`](#function-divide_scalar)
- [`multiply`](#function-multiply)
- [`multiply_scalar`](#function-multiply_scalar)
- [`add`](#function-add)
- [`subtract`](#function-subtract)
- [`negate_vector`](#function-negate_vector)
- [`deconstruct`](#function-deconstruct)
- [`abs`](#function-abs)
- [`clamp`](#function-clamp)
- [`max`](#function-max)
- [`min`](#function-min)
- [`distance`](#function-distance)
- [`distance_squared`](#function-distance_squared)

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

### x

```rust
x: f64
```

The X component.

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

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

### y

```rust
y: f64
```

The Y component.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L18)

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

### ZERO

```rust
const ZERO: Vector
```

The zero vector.

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

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

### ONE

```rust
const ONE: Vector
```

The one vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L26)

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

### UNIT_X

```rust
const UNIT_X: Vector
```

The X unit vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L29)

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

### UNIT_Y

```rust
const UNIT_Y: Vector
```

The Y unit vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L32)

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

### new

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

Initializes a new instance of the `Vector` structure.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L36)

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

### parse

```rust
fn parse(s: &str) -> Result<Self, FormatError>
```

Parses a `Vector` string (`"x, y"` or `"x y"`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L41)

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

### length

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

Length of the vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L48)

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

### squared_length

```rust
fn squared_length(self: &Self) -> f64
```

Squared length of the vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L54)

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

### equals

```rust
fn equals(self: &Self, other: Vector) -> bool
```

Check if two vectors are equal (exact comparison of the components).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L60)

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

### nearly_equals

```rust
fn nearly_equals(self: &Self, other: Vector) -> bool
```

Check if two vectors are nearly equal (numerically).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L66)

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

### with_x

```rust
const fn with_x(self: &Self, x: f64) -> Vector
```

Returns a new vector with the specified X component.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L72)

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

### with_y

```rust
const fn with_y(self: &Self, y: f64) -> Vector
```

Returns a new vector with the specified Y component.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L78)

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

### normalize

```rust
fn normalize(self: &Self) -> Vector
```

Returns a normalized version of this vector. A zero-length vector yields NaN components.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L84)

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

### negate

```rust
fn negate(self: &Self) -> Vector
```

Returns a negated version of this vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L90)

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

### dot

```rust
fn dot(a: Vector, b: Vector) -> f64
```

Returns the dot product of two vectors.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L96)

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

### cross

```rust
fn cross(a: Vector, b: Vector) -> f64
```

Returns the cross product of two vectors.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L102)

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

### normalize_vector

```rust
fn normalize_vector(vector: Vector) -> Vector
```

Normalizes the given vector (static form of `normalize`).

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

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

### divide

```rust
fn divide(a: Vector, b: Vector) -> Vector
```

Divides the first vector by the second, component-wise.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L114)

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

### divide_scalar

```rust
fn divide_scalar(vector: Vector, scalar: f64) -> Vector
```

Divides the vector by the given scalar.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L120)

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

### multiply

```rust
fn multiply(a: Vector, b: Vector) -> Vector
```

Multiplies the first vector by the second, component-wise.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L126)

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

### multiply_scalar

```rust
fn multiply_scalar(vector: Vector, scalar: f64) -> Vector
```

Multiplies the vector by the given scalar.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L132)

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

### add

```rust
fn add(a: Vector, b: Vector) -> Vector
```

Adds the second to the first vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L139)

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

### subtract

```rust
fn subtract(a: Vector, b: Vector) -> Vector
```

Subtracts the second from the first vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L145)

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

### negate_vector

```rust
fn negate_vector(vector: Vector) -> Vector
```

Negates the vector (static form of `negate`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L151)

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

### deconstruct

```rust
const fn deconstruct(self: &Self) -> (f64, f64)
```

Deconstructs the vector into its X and Y components.

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

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

### abs

```rust
fn abs(self: &Self) -> Vector
```

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/vector.rs#L164)

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

### clamp

```rust
fn clamp(value: Vector, min: Vector, max: Vector) -> Vector
```

Restricts a vector between a minimum and a maximum value.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L170)

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

### max

```rust
fn max(left: Vector, right: Vector) -> Vector
```

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/vector.rs#L177)

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

### min

```rust
fn min(left: Vector, right: Vector) -> Vector
```

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/vector.rs#L187)

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

### distance

```rust
fn distance(value1: Vector, value2: Vector) -> f64
```

Computes the Euclidean distance between the two given points.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L196)

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

### distance_squared

```rust
fn distance_squared(value1: Vector, value2: Vector) -> f64
```

Returns the Euclidean distance squared between two specified points.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/vector.rs#L202)

## 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`
- [`Transition<Vector>`](/docs/0.5.0/api/ferroui-base/animation/trait-transition/)
- `From<Vector>`
- `From<Vector2>`
- `IInterpolator<Vector>`
- `ExpressionVariantValue`
- `ServerPropertyValue`
- `BatchValue`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- [`ValueTypeRegistration`](/docs/0.5.0/api/ferroui-base/data/core/trait-valuetyperegistration/)
- `From<Point>`
- `Add<Vector>`
- `Sub<Vector>`
- `AddAssign<Vector>`
- `SubAssign<Vector>`
- `Mul<Vector>`
- `Div<Vector>`
- `MulAssign<Vector>`
- `DivAssign<Vector>`
- `Clone`
- `Copy`
- `Debug`
- `StructuralPartialEq`
- `PartialEq`
- `Default`
- `Mul`
- `Mul<f64>`
- `Div<f64>`
- `Neg`
- `Add`
- `Sub`
- `AddAssign`
- `SubAssign`
- `MulAssign<f64>`
- `DivAssign<f64>`
- `FromStr`
- `Display`

## Availability

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