Skip to content

Class Rectangle

A rectangle with a position and size.

Fields

x

x: number

The x-position of the top-left corner

y

y: number

The y-position of the top-left corner

width

width: number

The width of the rectangle

height

height: number

The height of the rectangle

Functions

method split_at

function Rectangle:split_at(axis: "horizontal" | "vertical", at: number, thickness?: number)
    -> rect1: Rectangle, rect2: Rectangle | nil

Split this rectangle along axis at at.

If thickness is specified, the split will chop off a section of this rectangle from at to at + thickness.

at is relative to the space this rectangle is in, not this rectangle's origin.

Parameters

axis: "horizontal" | "vertical"
at: number
thickness?: number

Returns

  1. rect1: Rectangle - The first rectangle.
  2. rect2: Rectangle | nil - The second rectangle, if there is one.