Rect
Represents a rectangle with a set origin (top-left corner) and size(see example).
cornerRadius
number[]
The size of the rectangle.
origin
The origin (top-left corner) of the rectangle.
size
The size of the rectangle.
Constructors
Rect
(origin: Point | number[], size: Size | number[], cornerRadius?: number | 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.
cornerRadius?
number | number[]
The corner radius of the rectangle as a single number or an [rx, ry]
array.
Methods
bbox
Returns the bounding box of this rectangle after applying the specified transformation matrix.
Parameters
matrix?
The transformation matrix to apply.
Returns
- 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
- The position of the bottom-left corner.
bottomRight
Gets the position of the bottom-right corner of the rectangle.
Returns
- The position of the bottom-right corner.
center
Gets the position of the center of the rectangle.
Returns
- The position of the center.
clone
Creates a new instance with the same origin and size.
Returns
- A new Rect instance with the same origin and size.
equals
Compares this rectangle with another instance.
Parameters
other
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
- The origin (top-left point).
getSize
Gets the rectangle size.
Returns
- The current Size of the rectangle.
height
Gets the height of the rectangle.
Returns
number
- The height of the rectangle.
setCornerRadius
Sets the corner radius of the rectangle.
Parameters
cornerRadius
number | number[]
The new corner radius of the rectangle as a single number or an [rx, ry]
array.
Returns
- The current rectangle instance.
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
- 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
- The current rectangle instance.
topLeft
Gets the position of the top-left corner of the rectangle. This is also the rectangle origin.
Returns
- The position of the top-left corner.
topRight
Gets the position of the top-right corner of the rectangle.
Returns
- 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
The first point.
b
The second point.
Returns
- The new Rect instance.
union
Creates a new Rect instance that encloses the two rectangles given as arguments.
Parameters
a
The first rectangle.
b
The second rectangle.
Returns
- The new Rect instance.