Rect

Represents a rectangle with a set origin (top-left corner) and size.

origin Point

The origin (top-left corner) of the rectangle.

size Size

The size of the rectangle.

Constructors

Rect (origin: Point | number[], size: Size | number[])

Creates a rectangle geometry with the specified parameters.

Parameters

origin Point | number[]

The origin (top-left corner) of the rectangle or an equivalent [x, y] array.

size Size | number[]

The size of the rectangle or an equivalent [width, height] array.

Methods

bbox

Returns the bounding box of this rectangle after applying the specified transformation matrix.

Parameters

matrix? Matrix

The transformation matrix to apply.

Returns

Rect - The bounding box after applying the transformation matrix.

bottomLeft

Gets the position of the bottom-left corner of the rectangle. This is also the rectangle origin.

Returns

Point - The position of the bottom-left corner.

bottomRight

Gets the position of the bottom-right corner of the rectangle.

Returns

Point - The position of the bottom-right corner.

center

Gets the position of the center of the rectangle.

Returns

Point - The position of the center.

clone

Creates a new instance with the same origin and size.

Returns

Rect - A new Rect instance with the same origin and size.

equals

Compares this rectangle with another instance.

Parameters

other Rect

The rectangle to compare with.

Returns

boolean true if the origin and size is the same for both rectangles. Otherwise, returns false.

getOrigin

Gets the origin (top-left point) of the rectangle.

Returns

Point - The origin (top-left point).

getSize

Gets the rectangle size.

Returns

Size - The current Size of the rectangle.

height

Gets the height of the rectangle.

Returns

number - The height of the rectangle.

setOrigin

Sets the origin (top-left point) of the rectangle.

Parameters

origin Point | number[]

The new origin Point or an equivalent [x, y] array.

Returns

Rect - The current Rect instance.

setSize

Sets the size of the rectangle.

Parameters

size Size | number[]

The new rectangle Size or an equivalent [width, height] array.

Returns

Rect - The current rectangle instance.

topLeft

Gets the position of the top-left corner of the rectangle. This is also the rectangle origin.

Returns

Point - The position of the top-left corner.

topRight

Gets the position of the top-right corner of the rectangle.

Returns

Point - The position of the top-right corner.

width

Gets the rectangle width.

Returns

number - The rectangle width.

fromPoints

Creates a Rect instance that contains the points given as arguments.

Parameters

a Point

The first point.

b Point

The second point.

Returns

Rect - The new Rect instance.

union

Creates a new Rect instance that encloses the two rectangles given as arguments.

Parameters

a Rect

The first rectangle.

b Rect

The second rectangle.

Returns

Rect - The new Rect instance.

 /