Rectangle

The Rectangle class represents an abstract rectangular area. It is different from a Rect.

Properties

propertyexplanationtypedefault value
bottom the y coordinate of the bottom of the rectangleNumber
center the x coordinate of the center of the rectangleNumber
heightthe height of the rectangleNumber
leftthe x coordinate of the left hand side of the rectangleNumber
middle the y coordinate of the center of the rectangleNumber
right the x coordinate of the right hand side of the rectangleNumber
topthe y coordinate of the top of the rectangleNumber
widththe width of the rectangleNumber
x the x coordinate of the center of the rectangle
same as “center”
Number
y the y coordinate of the center of the rectangle
same as “middle”
Number

Methods

methodexplanationreturn type
clone()returns a copy of this rectangleRectangle
contains(x, y)check if a point with the specified x and y coordinates (type Number) is inside this rectangleBoolean
intersects(r)returns true if this rectangle overlaps with rect (type Rectangle)Boolean
setHeight(v, ref)sets the height to v (type Number). Grows/shrinks from the bottom edge by default; pass BoundsAnchor.TOP as ref to anchor from the top edge, or BoundsAnchor.MIDDLE to grow/shrink symmetricallyvoid
setWidth(v, ref)sets the width to v (type Number). Grows/shrinks from the left edge by default; pass BoundsAnchor.RIGHT as ref to anchor from the right edge, or BoundsAnchor.CENTER to grow/shrink symmetricallyvoid
toJSON()returns an object with the rectangle’s center coordinates and dimensions: { x, y, width, height }Object
translate(dx, dy)shifts the rectangle by dx (type Number) horizontally and dy (type Number) verticallyvoid
union(rect)returns the union of this rectangle and the parameter rect (type Rectangle)Rectangle