# Vec2

## \_\_call﻿ <a href="#call" id="call"></a>

[<kbd><mark style="background-color:purple;">**Constructor**<mark style="background-color:purple;"></kbd>](#user-content-fn-1)[^1]

Creates a new 2D vector instance.

**Arguments**

1\. Default vector (0, 0).

None.

2\. Single value.

| Name    | Type    | Description          |
| ------- | ------- | -------------------- |
| `value` | `float` | X and Y coordinates. |

3\. XY values.

| Name | Type    | Description   |
| ---- | ------- | ------------- |
| `x`  | `float` | X coordinate. |
| `y`  | `float` | Y coordinate. |

**Returns**

| Type   | Description |
| ------ | ----------- |
| `Vec2` | New vector. |

**Example**

```lua
local vec = draw.Vec2(5, 10);
```

***

## x﻿ <a href="#x" id="x"></a>

[<kbd><mark style="background-color:purple;">**Field**<mark style="background-color:purple;"></kbd>](#user-content-fn-2)[^2]

Type: `float`

X coordinate.

***

## y﻿ <a href="#y" id="y"></a>

[<kbd><mark style="background-color:purple;">**Field**<mark style="background-color:purple;"></kbd>](#user-content-fn-2)[^2]

Type: `float`

Y coordinate.

***

## Clone

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Returns a copy of this vector instance.

**Arguments**

None.

**Returns**

| Type   | Description       |
| ------ | ----------------- |
| `Vec2` | The copied vector |

**Example**

```lua
local copy = vec:Clone();
```

***

## Floor

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Returns floored variant of this vector.

**Arguments**

None.

**Returns**

| Type   | Description      |
| ------ | ---------------- |
| `Vec2` | Floored variant. |

**Example**

```lua
local fl = vec:Floor();
```

***

## Ceil

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Returns ceiled variant of this vector.

**Arguments**

None.

**Returns**

| Type   | Description     |
| ------ | --------------- |
| `Vec2` | Ceiled variant. |

**Example**

```lua
local ceiled = vec:Ceil();
```

***

## Round﻿ <a href="#round" id="round"></a>

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Returns rounded variant of this vector.

**Arguments**

None.

**Returns**

| Type   | Description      |
| ------ | ---------------- |
| `Vec2` | Rounded variant. |

**Example**

```lua
local rounded = vec:Round();
```

***

## Len <a href="#len" id="len"></a>

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Returns length of this vector.

**Arguments**

None.

**Returns**

| Type    | Description |
| ------- | ----------- |
| `float` | Length.     |

**Example**

```lua
local len = vec:Len();
```

***

## LenSqr

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Returns squared length of this vector.

{% hint style="info" %}
This method is de-facto faster than the non-squared variant. Use it, if you need extra performance.
{% endhint %}

**Arguments**

None.

**Returns**

| Type    | Description |
| ------- | ----------- |
| `float` | Length.     |

**Example**

```lua
local len = vec:LenSqr();
```

***

## Dist﻿ <a href="#dist" id="dist"></a>

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Returns distance to another vector.

**Arguments**

| Name    | Type   | Description   |
| ------- | ------ | ------------- |
| `other` | `Vec2` | Other vector. |

**Returns**

| Type    | Description |
| ------- | ----------- |
| `float` | Distance.   |

**Example**

```lua
local dist = vec1:Dist(vec2);
```

***

## DistSqr

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Returns squared distance to another vector.

{% hint style="info" %}
This method is de-facto faster than the non-squared variant. Use it, if you need extra performance.
{% endhint %}

**Arguments**

| Name    | Type   | Description   |
| ------- | ------ | ------------- |
| `other` | `Vec2` | Other vector. |

**Returns**

| Type    | Description |
| ------- | ----------- |
| `float` | Distance.   |

**Example**

```lua
local dist = vec1:DistSqr(vec2);
```

[^1]: This is a constructor definition for this type.

[^2]: This field is a regular field that must be accessed using a dot (.)

[^3]: This field is a method and must be invoked using a colon (:)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lua2.fatality.win/api/instances/draw/types/vec2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
