The goog.math.Rect Class

goog.math.Rect(x, y, w, h)

Class for representing rectangular regions.

x {number}
Left.
y {number}
Top.
w {number}
Width.
h {number}
Height.

.boundingRect(rect)

Expand this rectangle to also include the area of the given rectangle.

rect {goog.math.Rect}
The other rectangle.

.clone()

Returns a new copy of the rectangle.

returns {!goog.math.Rect}
A clone of this Rectangle.

.contains(another)

Tests whether this rectangle entirely contains another rectangle or coordinate.

another {goog.math.Rect|goog.math.Coordinate}
The rectangle or coordinate to test for containment.
returns {boolean}
Whether this rectangle contains given rectangle or coordinate.

.createFromBox(box)

Creates a new Rect object with the same position and dimensions as a given Box. Note that this is only the inverse of toBox if left/top are defined.

box {goog.math.Box}
A box.
returns {!goog.math.Rect}
A new Rect initialized with the box's position and size.

.difference(a, b)

Computes the difference regions between two rectangles. The return value is an array of 0 to 4 rectangles defining the remaining regions of the first rectangle after the second has been subtracted.

a {goog.math.Rect}
A Rectangle.
b {goog.math.Rect}
A Rectangle.
returns {!Array.<!goog.math.Rect>}
An array with 0 to 4 rectangles which together define the difference area of rectangle a minus rectangle b.

.equals(a, b)

Compares rectangles for equality.

a {goog.math.Rect}
A Rectangle.
b {goog.math.Rect}
A Rectangle.
returns {boolean}
True iff the rectangles have the same left, top, width, and height, or if both are null.

.getSize()

Returns the size of this rectangle.

returns {!goog.math.Size}
The size of this rectangle.

.height {number}

Height

.intersection(rect)

Computes the intersection of this rectangle and the rectangle parameter. If there is no intersection, returns false and leaves this rectangle as is.

rect {goog.math.Rect}
A Rectangle.
returns {boolean}
True iff this rectangle intersects with the parameter.

.intersects(a, b)

Returns whether two rectangles intersect. Two rectangles intersect if they touch at all, for example, two zero width and height rectangles would intersect if they had the same top and left.

a {goog.math.Rect}
A Rectangle.
b {goog.math.Rect}
A Rectangle.
returns {boolean}
Whether a and b intersect.

.left {number}

Left

.toBox()

Returns a new Box object with the same position and dimensions as this rectangle.

returns {!goog.math.Box}
A new Box representation of this Rectangle.

.toString()

Returns a nice string representing size and dimensions of rectangle.

returns {string}
In the form (50, 73 - 75w x 25h).

.top {number}

Top

.width {number}

Width