Skip to main content
Version: Version 5 beta

Class: Rectangle<T>

Represents a rectangle in a two-dimensional coordinate system.

Type Parameters

T extends Point

Implements

Constructors

new Rectangle()

new Rectangle<T>(topLeft, size): Rectangle<T>

Creates a new Rectangle instance with the specified top-left corner and size.

Parameters

topLeft: T

The top-left corner of the rectangle.

size: Size

The size of the rectangle.

Returns

Rectangle<T>

new Rectangle()

new Rectangle<T>(x, y, width, height): Rectangle<T>

Creates a new Rectangle instance with the specified coordinates and dimensions.

Parameters

x: number

The X coordinate of the top-left corner.

y: number

The Y coordinate of the top-left corner.

width: number

The width of the rectangle.

height: number

The height of the rectangle.

Returns

Rectangle<T>

Properties

size

size: Size

The size of the rectangle.


topLeft

topLeft: T

The top-left corner of the rectangle.

Accessors

bottomLeft

get bottomLeft(): T

Gets the bottom-left corner of the rectangle.

Returns

T


bottomRight

get bottomRight(): T

Gets the bottom-right corner of the rectangle.

Returns

T


height

get height(): number

The height of the rectangle.

set height(height): void

Parameters

height: number

Returns

number


topRight

get topRight(): T

Gets the top-right corner of the rectangle.

Returns

T


width

get width(): number

The width of the rectangle.

set width(width): void

Parameters

width: number

Returns

number

Methods

clone()

clone(): Rectangle<T>

Creates a deep copy of the object.

Returns

Rectangle<T>

A new instance that is a deep copy of the original object.

Implementation of

Cloneable.clone


calculateBoundingBox()

static calculateBoundingBox(points): Rectangle<Point>

Calculates the bounding box that encompasses a given set of points.

Parameters

points: Point[]

An array of Point objects representing the points to enclose.

Returns

Rectangle<Point>

A Rectangle representing the bounding box of the points, or null if the input array is empty.

Remarks

This method determines the smallest rectangular area that fully contains all the provided points. It iterates through the points to find the minimum and maximum x and y coordinates, then constructs a Rectangle using those boundaries.

If the input array is empty, the function returns null.