> For the complete documentation index, see [llms.txt](https://lua2.fatality.win/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lua2.fatality.win/api/instances/draw/types/rect.md).

# Rect

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

<mark style="color:yellow;">**`Constructor`**</mark>

Creates a new rectangle.

**Arguments**

1\. Default rectangle (0, 0 position; 0, 0 size).

None.

2\. Single value.

| Name    | Type    | Description             |
| ------- | ------- | ----------------------- |
| `value` | `float` | Mins XY, maxs XY value. |

3\. Single vector.

| Name    | Type                                        | Description               |
| ------- | ------------------------------------------- | ------------------------- |
| `value` | [`Vec2`](/api/instances/draw/types/vec2.md) | Mins vector, maxs vector. |

4\. Double value.

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

5\. Double vector.

| Name   | Type                                        | Description  |
| ------ | ------------------------------------------- | ------------ |
| `mins` | [`Vec2`](/api/instances/draw/types/vec2.md) | Mins vector. |
| `maxs` | [`Vec2`](/api/instances/draw/types/vec2.md) | Maxs vector. |

6\. Four values.

| Name | Type    | Description        |
| ---- | ------- | ------------------ |
| `x0` | `float` | Mins X coordinate. |
| `y0` | `float` | Mins Y coordinate. |
| `x1` | `float` | Maxs X coordinate. |
| `y1` | `float` | Maxs Y coordinate. |

**Returns**

| Type   | Description    |
| ------ | -------------- |
| `Rect` | New rectangle. |

**Example**

```lua
local my_rect = draw.Rect(50, 50, 150, 150);
```

***

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

<mark style="color:green;">**`Field`**</mark>

Type: [`Vec2`](/api/instances/draw/types/vec2.md)

Mins (top-left) vector.

***

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

<mark style="color:green;">**`Field`**</mark>

Type: [`Vec2`](/api/instances/draw/types/vec2.md)

Maxs (bottom-right) vector.

***

## Width

<mark style="color:purple;">**`Method`**</mark>&#x20;

Either returns rectangle's width, or sets a new width.

**Arguments**

1\. Get width.

None.

2\. Set width.

| Name    | Type    | Description |
| ------- | ------- | ----------- |
| `value` | `float` | New width.  |

**Returns**

1\. Get width.

| Type    | Description |
| ------- | ----------- |
| `float` | Width.      |

2\. Set width.

| Type   | Description                       |
| ------ | --------------------------------- |
| `Rect` | New rectangle with changed width. |

**Example**

```lua
local half_width = rect:Width(rect:Width() * 0.5);
```

***

## Height

<mark style="color:purple;">**`Method`**</mark>&#x20;

Either returns rectangle's height, or sets a new height.

**Arguments**

1\. Get height.

None.

2\. Set height.

| Name    | Type    | Description |
| ------- | ------- | ----------- |
| `value` | `float` | New height. |

**Returns**

1\. Get height.

| Type    | Description |
| ------- | ----------- |
| `float` | Height.     |

2\. Set height.

| Type   | Description                        |
| ------ | ---------------------------------- |
| `Rect` | New rectangle with changed height. |

**Example**

```lua
local half_height = rect:Height(rect:Height() * 0.5);
```

***

## Size

<mark style="color:purple;">**`Method`**</mark>&#x20;

Either returns rectangle's size, or sets a new size.

**Arguments**

1\. Get size.

None.

2\. Set size.

| Name    | Type                                        | Description |
| ------- | ------------------------------------------- | ----------- |
| `value` | [`Vec2`](/api/instances/draw/types/vec2.md) | New size.   |

**Returns**

1\. Get size.

| Type                                        | Description |
| ------------------------------------------- | ----------- |
| [`Vec2`](/api/instances/draw/types/vec2.md) | Size.       |

2\. Set size.

| Type   | Description                      |
| ------ | -------------------------------- |
| `Rect` | New rectangle with changed size. |

**Example**

```lua
local half_size = rect:Size(rect:Size() * draw.Vec2(0.5, 0.5));
```

***

## Explode

<mark style="color:purple;">**`Method`**</mark>&#x20;

Explodes the rectangle by given vector (increase size from center into all directions by coordinates in the vector).

**Arguments**

| Name    | Type                                        | Description   |
| ------- | ------------------------------------------- | ------------- |
| `value` | [`Vec2`](/api/instances/draw/types/vec2.md) | Explode size. |

**Returns**

| Type   | Description         |
| ------ | ------------------- |
| `Rect` | Exploded rectangle. |

**Example**

```lua
local exp = rect:Explode(draw.Vec2(6, 6)); -- will subtract -3,-3 from mins and add 3,3 to maxs
```

***

## HalfWidth

<mark style="color:purple;">**`Method`**</mark>&#x20;

Returns a rectangle with half of the width of this rectangle.

**Arguments**

None.

**Returns**

| Type   | Description                  |
| ------ | ---------------------------- |
| `Rect` | Rectangle with halved width. |

**Example**

```lua
local half = rect:HalfWidth();
```

***

## Translate

<mark style="color:purple;">**`Method`**</mark>&#x20;

Translates (moves) this rectangle by vector coordinates.

**Arguments**

| Name    | Type                                        | Description         |
| ------- | ------------------------------------------- | ------------------- |
| `value` | [`Vec2`](/api/instances/draw/types/vec2.md) | Translation amount. |

**Returns**

| Type   | Description           |
| ------ | --------------------- |
| `Rect` | Translated rectangle. |

**Example**

```lua
local rect = draw.Rect(50, 50, 150, 150);
local translated = rect:Translate(draw.Vec2(5, 5)); -- mins/maxs will be 55,55 and 155,155
```

***

## MarginLeft

<mark style="color:purple;">**`Method`**</mark>&#x20;

Move rectangle from the left by given amount.

**Arguments**

| Name    | Type    | Description    |
| ------- | ------- | -------------- |
| `value` | `float` | Margin amount. |

**Returns**

| Type   | Description      |
| ------ | ---------------- |
| `Rect` | Moved rectangle. |

**Example**

```lua
local new = rect:MarginLeft(5); -- moves to the right by 5px
```

***

## MarginRight

<mark style="color:purple;">**`Method`**</mark>&#x20;

Move rectangle from the right by given amount.

**Arguments**

| Name    | Type    | Description    |
| ------- | ------- | -------------- |
| `value` | `float` | Margin amount. |

**Returns**

| Type   | Description      |
| ------ | ---------------- |
| `Rect` | Moved rectangle. |

**Example**

```lua
local new = rect:MarginRight(5); -- moves to the left by 5px
```

***

## MarginTop

<mark style="color:purple;">**`Method`**</mark>&#x20;

Move rectangle from the top by given amount.

**Arguments**

| Name    | Type    | Description    |
| ------- | ------- | -------------- |
| `value` | `float` | Margin amount. |

**Returns**

| Type   | Description      |
| ------ | ---------------- |
| `Rect` | Moved rectangle. |

**Example**

```lua
local new = rect:MarginTop(5); -- moves to the bottom by 5px
```

***

## MarginBottom <a href="#margin-bottom" id="margin-bottom"></a>

<mark style="color:purple;">**`Method`**</mark>&#x20;

Move rectangle from the bottom by given amount.

**Arguments**

| Name    | Type    | Description    |
| ------- | ------- | -------------- |
| `value` | `float` | Margin amount. |

**Returns**

| Type   | Description      |
| ------ | ---------------- |
| `Rect` | Moved rectangle. |

**Example**

```lua
local new = rect:MarginBottom(5); -- moves to the top by 5px
```

***

## PaddingLeft

<mark style="color:purple;">**`Method`**</mark>&#x20;

Adds the value to the left side of the rectangle.

**Arguments**

| Name    | Type    | Description     |
| ------- | ------- | --------------- |
| `value` | `float` | Padding amount. |

**Returns**

| Type   | Description        |
| ------ | ------------------ |
| `Rect` | Resized rectangle. |

**Example**

```lua
local new = rect:PaddingLeft(5); -- adds 5 to mins x
```

***

## PaddingRight

<mark style="color:purple;">**`Method`**</mark>&#x20;

Adds the value to the right side of the rectangle.

**Arguments**

| Name    | Type    | Description     |
| ------- | ------- | --------------- |
| `value` | `float` | Padding amount. |

**Returns**

| Type   | Description        |
| ------ | ------------------ |
| `Rect` | Resized rectangle. |

**Example**

```lua
local new = rect:PaddingRight(5); -- adds 5 to maxs x
```

***

## PaddingTop

<mark style="color:purple;">**`Method`**</mark>&#x20;

Adds the value to the top side of the rectangle.

**Arguments**

| Name    | Type    | Description     |
| ------- | ------- | --------------- |
| `value` | `float` | Padding amount. |

**Returns**

| Type   | Description        |
| ------ | ------------------ |
| `Rect` | Resized rectangle. |

**Example**

```lua
local new = rect:PaddingTop(5); -- adds 5 to mins y
```

***

## PaddingBottom

<mark style="color:purple;">**`Method`**</mark>&#x20;

Adds the value to the bottom side of the rectangle.

**Arguments**

| Name    | Type    | Description     |
| ------- | ------- | --------------- |
| `value` | `float` | Padding amount. |

**Returns**

| Type   | Description        |
| ------ | ------------------ |
| `Rect` | Resized rectangle. |

**Example**

```lua
local new = rect:PaddingBottom(5); -- adds 5 to maxs y
```

***

## Shrink

<mark style="color:purple;">**`Method`**</mark>&#x20;

Shrinks (implodes) the rectangle by given amount.

**Arguments**

| Name    | Type    | Description   |
| ------- | ------- | ------------- |
| `value` | `float` | Shrink value. |

**Returns**

| Type   | Description        |
| ------ | ------------------ |
| `Rect` | Resized rectangle. |

**Example**

```lua
local shrinked = rect:Shrink(5); -- adds 5,5 to mins and subtracts 5,5 from maxs
```

***

## Expand

<mark style="color:purple;">**`Method`**</mark>&#x20;

Expands (explodes) the rectangle by given amount.

**Arguments**

| Name    | Type    | Description   |
| ------- | ------- | ------------- |
| `value` | `float` | Expand value. |

**Returns**

| Type   | Description        |
| ------ | ------------------ |
| `Rect` | Resized rectangle. |

**Example**

```lua
local expanded = rect:Expand(5); -- subtracts 5,5 from mins and adds 5,5 to maxs
```

***

## Contains﻿ <a href="#contains" id="contains"></a>

<mark style="color:purple;">**`Method`**</mark>&#x20;

Returns `true` if this rectangle contains either vector or another rectangle.

{% hint style="info" %}
Rectangle overload will return `true` ONLY of entire other rectangle is within the bounds of this one.
{% endhint %}

**Arguments**

1\. Vector variant.

| Name    | Type                                        | Description              |
| ------- | ------------------------------------------- | ------------------------ |
| `other` | [`Vec2`](/api/instances/draw/types/vec2.md) | Vector to check against. |

2\. Rectangle variant.

| Name    | Type   | Description                 |
| ------- | ------ | --------------------------- |
| `other` | `Rect` | Rectangle to check against. |

**Returns**

| Type   | Description                                            |
| ------ | ------------------------------------------------------ |
| `bool` | `true` if other object is in bounds of this rectangle. |

**Example**

```lua
if rect:Contains(cursor_pos) then
    -- ...
end
```

***

## Overlaps

<mark style="color:purple;">**`Method`**</mark>&#x20;

Returns `true` if the other rectangle overlaps with this rectangle.

**Arguments**

| Name    | Type   | Description                 |
| ------- | ------ | --------------------------- |
| `other` | `Rect` | Rectangle to check against. |

**Returns**

| Type   | Description                                             |
| ------ | ------------------------------------------------------- |
| `bool` | `true` if other rectangle overlaps with this rectangle. |

**Example**

```lua
if rect:Overlaps(another_rect) then
    -- ...
end
```

***

## Intersect

<mark style="color:purple;">**`Method`**</mark>&#x20;

Intersects this rectangle with another rectangle.

**Arguments**

| Name    | Type   | Description                  |
| ------- | ------ | ---------------------------- |
| `other` | `Rect` | Rectangle to intersect with. |

**Returns**

| Type   | Description            |
| ------ | ---------------------- |
| `Rect` | Intersected rectangle. |

**Example**

```lua
local intersected = rect:Intersect(another_rect);
```

***

## TL

<mark style="color:purple;">**`Method`**</mark>&#x20;

Returns top-left vector.

**Arguments**

None.

**Returns**

| Type                                        | Description      |
| ------------------------------------------- | ---------------- |
| [`Vec2`](/api/instances/draw/types/vec2.md) | Top-left vector. |

**Example**

```lua
local tl = rect:TL();
```

***

## TR <a href="#tr" id="tr"></a>

<mark style="color:purple;">**`Method`**</mark>&#x20;

Returns top-right vector.

**Arguments**

None.

**Returns**

| Type                                        | Description       |
| ------------------------------------------- | ----------------- |
| [`Vec2`](/api/instances/draw/types/vec2.md) | Top-right vector. |

**Example**

```lua
local tr = rect:TR();
```

***

## BR <a href="#br" id="br"></a>

<mark style="color:purple;">**`Method`**</mark>&#x20;

Returns bottom-right vector.

**Arguments**

None.

**Returns**

| Type                                        | Description          |
| ------------------------------------------- | -------------------- |
| [`Vec2`](/api/instances/draw/types/vec2.md) | Bottom-right vector. |

**Example**

```lua
local br = rect:BR();
```

***

## BL <a href="#bl" id="bl"></a>

<mark style="color:purple;">**`Method`**</mark>&#x20;

Returns bottom-left vector.

**Arguments**

None.

**Returns**

| Type                                        | Description         |
| ------------------------------------------- | ------------------- |
| [`Vec2`](/api/instances/draw/types/vec2.md) | Bottom-left vector. |

**Example**

```lua
local bl = rect:BL();
```

***

## Center﻿ <a href="#center" id="center"></a>

<mark style="color:purple;">**`Method`**</mark>&#x20;

Returns center point of this rectangle.

**Arguments**

None.

**Returns**

| Type                                        | Description   |
| ------------------------------------------- | ------------- |
| [`Vec2`](/api/instances/draw/types/vec2.md) | Center point. |

**Example**

```lua
local center = rect:Center();
```

***

## Circle﻿ <a href="#circle" id="circle"></a>

<mark style="color:purple;">**`Method`**</mark>&#x20;

Treats this rectangle as an ellipsis and returns point on it. Note, that this "ellipsis" will be perfect with no modified curvature (basically if this rectangle is a box - you will get a point on a perfect circle).

**Arguments**

| Name | Type    | Description    |
| ---- | ------- | -------------- |
| `r`  | `float` | Radians value. |

**Returns**

| Type                                        | Description            |
| ------------------------------------------- | ---------------------- |
| [`Vec2`](/api/instances/draw/types/vec2.md) | Point on the ellipsis. |

**Example**

```lua
local point = rect:Circle(rad(250)); -- returns point on the 250th degree
```

***

## Floor﻿ <a href="#floor" id="floor"></a>

<mark style="color:purple;">**`Method`**</mark>&#x20;

Returns floored rectangle.

**Arguments**

None.

**Returns**

| Type   | Description        |
| ------ | ------------------ |
| `Rect` | Floored rectangle. |

**Example**

```lua
local floored = rect:Floor();
```

***

## Ceil﻿ <a href="#ceil" id="ceil"></a>

<mark style="color:purple;">**`Method`**</mark>&#x20;

Returns ceiled rectangle.

**Arguments**

None.

**Returns**

| Type   | Description       |
| ------ | ----------------- |
| `Rect` | Ceiled rectangle. |

**Example**

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

***

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

<mark style="color:purple;">**`Method`**</mark>&#x20;

Returns rounded rectangle.

**Arguments**

None.

**Returns**

| Type   | Description        |
| ------ | ------------------ |
| `Rect` | Rounded rectangle. |

**Example**

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

***

## IsZero

<mark style="color:purple;">**`Method`**</mark>&#x20;

Returns `true` if both mins and maxs are equal to 0.

**Arguments**

None.

**Returns**

| Type   | Description                         |
| ------ | ----------------------------------- |
| `bool` | `true` if this is a zero rectangle. |

**Example**

```lua
if rect:IsZero() then
    -- ...
end
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
