3 min read

Source: Roblox Creator Hub · CC BY 4.0 · View source · Code samples: MIT Imported 2026-10-03. Formatting adapted for this site.

Rect

Rect describes a rectangle on a 2D plane. It is constructed using two corners, either two Vector2 positions or four numbers:

local rect1 = Rect.new(Vector2.new(10, 10), Vector2.new(80, 80))
local rect2 = Rect.new(10, 10, 80, 80)

This data type is used in the ImageLabel.SliceCenter property which determines the center area of a scaled image.

Constructors

NameType / ReturnsDescription
Rect.newReturns a new Rect with zero Vector2 positions.
Rect.newReturns a new Rect from the given Vector2 positions.
Rect.newReturns a new Rect using the first and last two arguments as coordinates for corners.

Rect.new

Constructs a new Rect with two zero Vector2 positions.

Rect.new

Constructs a new Rect given two Vector2 positions: min as the top-left corner and max as the bottom-right corner.

Parameters

NameTypeDefaultDescription
minVector2One corner of the rectangle as a Vector2. The constructor computes the component-wise minimum of min and max to determine the top-left corner.
maxVector2The other corner of the rectangle as a Vector2. The constructor computes the component-wise maximum of min and max to determine the bottom-right corner.

Rect.new

Constructs a new Rect using minX and minY as coordinates for the top-left corner, and maxX and maxY as coordinates for the bottom-right corner.

Parameters

NameTypeDefaultDescription
minXnumberThe X coordinate of the top-left corner of the rectangle.
minYnumberThe Y coordinate of the top-left corner of the rectangle.
maxXnumberThe X coordinate of the bottom-right corner of the rectangle.
maxYnumberThe Y coordinate of the bottom-right corner of the rectangle.

Properties

NameType / ReturnsDescription
Rect.WidthnumberThe width of the Rect.
Rect.HeightnumberThe height of the Rect.
Rect.MinVector2The coordinates of the top-left corner.
Rect.MaxVector2The coordinates of the bottom-right corner.

Rect.Width

The horizontal span of the rectangle, equal to Max.X - Min.X. This value is always non-negative because the constructor normalizes the input coordinates so that Min is component-wise less than or equal to Max. Defaults to 0 for a Rect created with no arguments.

FieldValue
typenumber

Rect.Height

The vertical span of the rectangle, equal to Max.Y - Min.Y. This value is always non-negative because the constructor normalizes the input coordinates so that Min is component-wise less than or equal to Max. Defaults to 0 for a Rect created with no arguments.

FieldValue
typenumber

Rect.Min

The top-left corner of the rectangle as a Vector2. When you construct a Rect with two positions, this property returns the component-wise minimum of those positions regardless of the order they were passed in. Defaults to (0, 0) for a Rect created with no arguments.

FieldValue
typeVector2

Rect.Max

The bottom-right corner of the rectangle as a Vector2. When you construct a Rect with two positions, this property returns the component-wise maximum of those positions regardless of the order they were passed in. Defaults to (0, 0) for a Rect created with no arguments.

FieldValue
typeVector2