Class: Rectangle<T>
Represents a rectangle in a two-dimensional coordinate system.
Type Parameters
T
T extends Point
Implements
Cloneable<Rectangle<T>>
Constructors
Constructor
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
The size of the rectangle.
Returns
Rectangle<T>
Constructor
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
height
Get Signature
get height():
number
The height of the rectangle.
Returns
number
Set Signature
set height(
height):void
Parameters
height
number
Returns
void
width
Get Signature
get width():
number
The width of the rectangle.
Returns
number
Set Signature
set width(
width):void
Parameters
width
number
Returns
void
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
calculateBoundingBox()
staticcalculateBoundingBox(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.