Class: Rect

Core.Math. Rect

Represents a utility class used to manipulate rectangle objects.

new Rect(x1, y1, x2, y2)

Create a new Rect with the x and y coordinates of the upper-left and lower right points.
Parameters:
Name Type Description
x1 number the x coordinate of the upper-left point
y1 number the y coordinate of the upper-left point
x2 number the x coordinate of the lower-right point
y2 number the y coordinate of the lower-right point
Properties:
Name Type Description
x1 number the x coordinate of the upper-left point
y1 number the y coordinate of the upper-left point
x2 number the x coordinate of the lower-right point
y2 number the y coordinate of the lower-right point
Example
(x1,y1)------|
    |         |
    |-------(x2,y2)

Methods


<static> contains(rect, container)

A static method that determines whether the first rect is contains the second rect.
Parameters:
Name Type Description
rect Core.Math.Rect The first rect (container)
container Core.Math.Rect The second rect
Returns:
True if the first rect contains the second rect. Otherwise false
Type
boolean

<static> createFromDimensions(x, y, width, height)

Creates a Rect using position and dimensions.
Parameters:
Name Type Description
x number The X coordinate
y number The Y coordinate
width number The width of the rect
height number The height of the rect
Returns:
A rect at the designated position of the defined size
Type
Core.Math.Rect

<static> intersects(rect1, rect2)

A static method that determines whether the two rects provided intersect each other.
Parameters:
Name Type Description
rect1 Core.Math.Rect The first rect
rect2 Core.Math.Rect The second rect
Returns:
True if the rects intersect. Otherwise, false.
Type
boolean

contains(otherRect)

A method to determine whether this rect contains another rect. It is not considered as containment if another rect intersects this one.
Parameters:
Name Type Description
otherRect Rect The other rect
Returns:
True if this rect contains 'otherRect'. Otherwise, false.
Type
boolean

exportNormalize()

Normalizes the rect to ensure point (x1, y1) is the bottom left point as expected by xfdf output

fitTo(rect)

Best fit this rect into another larger rect
Parameters:
Name Type Description
rect Core.Math.Rect

getBottom()

Returns the most bottom Y value.
Returns:
Type
number

getBottomLeft()

Gets a Point that is at the bottom-left of the rect.
Returns:
A point at the bottom-left of the rect
Type
Core.Math.Point

getBottomRight()

Gets a Point that is at the top-right of the rect.
Returns:
A point at the top-right of the rect
Type
Core.Math.Point

getCenter()

Gets a Point that is at the center of the rect.
Returns:
A point at the center of the rect
Type
Core.Math.Point

getHeight()

Gets the height of the rect
Returns:
The height of the rect
Type
number

getLeft()

Returns the most left X value.
Returns:
Type
number

getRight()

Returns the most right X value.
Returns:
Type
number

getTop()

Returns the most top Y value.
Returns:
Type
number

getTopLeft()

Gets a Point that is at the top-left of the rect.
Returns:
A point at the top-left of the rect
Type
Core.Math.Point

getTopRight()

Gets a Point that is at the top-right of the rect.
Returns:
A point at the top-right of the rect
Type
Core.Math.Point

getWidth()

Gets the width of the rect
Returns:
The width of the rect
Type
number

intersects(otherRect)

A method to determine whether this rect overlaps with another. If this rect contains another, this is still considered true.
Parameters:
Name Type Description
otherRect Rect The other rect
Returns:
True if the rects intersect. Otherwise, false.
Type
boolean

normalize()

Normalizes the rect to ensure point (x1, y1) is the upper left point and width and height are non-negative.

toQuad()

Returns a Quad that represents this rect.
Returns:
A quad that represents this rect
Type
Core.Math.Quad

transform(transform)

Applies a transformation matrix to the rect which will adjust the points.
Parameters:
Name Type Description
transform Core.Math.Matrix The transformation matrix to apply

translate(x, y)

Translates the rect
Parameters:
Name Type Description
x number The amount to translate in the x direction
y number The amount to translate in the y direction