Class Rectangle

Mathematical representation of a rectangle.

Methods

Rectangle(y, x, w, h) constructor

Creates new instance of Rectangle.

Parameters
y : number — X-component.
x : number — Y-component.
w : number — The width.
h : number — The height.
set(x, y, w, h) method

Update rectangle values with a given.

Parameters
x : number — X-component.
y : number — Y-component.
w : number — The width.
h : number — The height.
Returns
Rectangle — This.
copyFrom(rect) method

Copies values from given rectangle into this one.

Parameters
rect : Rectangle — The Rectangle to copy values from.
Returns
Rectangle — This.
copyTo(rect) method

Copies values from this rectangle into given rectangle.

Parameters
rect : Rectangle — The destination rect.
Returns
Rectangle — Given rect object.
size(outVector) method

Creates a new Rectangle instance with width and height equal to current instance.

Parameters
outVector : Vector — Resulting rect to save values in.
Returns
Vector — New Rectangle instance or `outVector` if passed.
zero() method
Sets all components of this Rectangle to zero.
equals(rect, epsilon) method

Compares this Rectangle with a given one.

Parameters
rect : Rectangle — Rect to compare values with.
epsilon : number — Comparison threshold.
Returns
boolean — True if rectangles are equal.
containsXY(x, y) method

Checks if a given point is inside this rectangle.

Parameters
x : number — The x-component of a point.
y : number — The y-component of a point.
Returns
boolean — True if point is inside.
contains(rect) method

Checks if a given rectangle is inside this rect.

Parameters
rect : Rectangle — Rectangle to check with.
Returns
boolean — True if given rectangle is inside this one.
intersects(rect) method

Checks if this rect intersects with a given rectangle.

Parameters
rect : Rectangle — The rect to check intersection with.
Returns
boolean — True if intersects.
intersection(toIntersect, outRect) method

Makes rectangle, which represents intersection between this and passed rectangles.

Parameters
toIntersect : Rectangle — Rectangle to intersect with.
outRect : Rectangle — Rectangle to be returned.
Returns
Rectangle
union(toUnion) method

Adds given rectangle into this.

Parameters
toUnion : Rectangle — A rectangle object to add to this rect.
Returns
Rectangle — New rectangle object that is the union.
expand(x, y, width, height) method

Expands this rectangle object by given values.

Parameters
x : number — X-component.
y : number — Y-component
width : number — The width.
height : number — The height.
Returns
Rectangle — This.
expandXY(x, y) method

Expands this rectangle with a given point.

Parameters
x : numbery : number
Returns
Rectangle
inflate(x, y) method

Increases the size of this rectangle by given x- and y- values.

Parameters
x : number — X-component.
y : number — Y-component.
Returns
Rectangle — This.
clone() method
Clones this Rectangle object into new one.
center(outVector) method

Returns the center point of this rectangle.

Parameters
outVector : Vector — The out-Vector to store values in.
Returns
Vector — New rectangle object.
scale(x, y) method

Scales this rectangle.

Parameters
x : number — Width multiplier.
y : number — Height multiplier.
Returns
Rectangle — This rectangle.
fromPoints(points) static method

Calculates a bonding box enclosing the given list of points.

Parameters
points : Array.<Vector>
Returns
Rectangle
fromPointsXY(points) static method

Calculates a bonding box enclosing the given list of x-y pairs.

Parameters
points : Array.<number>
Returns
Rectangle

Properties

x property
The x coordinate of the rectangle.
y property
The y coordinate of the rectangle.
width property
The width of the rectangle.
height property
The height of the rectangle.
left : number property
Get/Sets the leftmost point of this rectangle.
right : number property
Get/Sets the rightmost point of this rectangle.
top : number property
Get/Sets the topmost point of this rectangle.
bottom : number property
Get/Sets the bottommost point of this rectangle.
topLeft : Vector property
Get/Sets the top left point for this rectangle.
topRight : Vector property
Get/Sets the top right point for this rectangle.
bottomRight : Vector property
Get/Sets the top left point for this rectangle.
bottomLeft : Vector property
Get/Sets the top left point for this rectangle.
volume : number property
Returns volume of this Rectangle.
perimeter : number property
Gets rectangle perimeter.
isEmpty : boolean property
Checks if rectangle has area.
lines : Array. property
Gets a list of lines, which make up this rectangle.
pool static property
Recycled rectangles pool.