# Class goog.math.Rect

code »

Class for representing rectangular regions.

## Constructor

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

Parameters

x: `number`
  Left.
y: `number`
  Top.
w: `number`
  Width.
h: `number`
  Height.

Show:Public Protected Private

## Instance Methods

code »boundingRect ( rect )

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

Parameters

rect: `goog.math.Rect`
  The other rectangle.

code »ceil ( ) ⇒ `!goog.math.Rect`

Rounds the fields to the next larger integer values.

Returns

This rectangle with ceil'd fields.

code »clone ( ) ⇒ `!goog.math.Rect`

Returns

A new copy of this Rectangle.

code »contains ( another ) ⇒ `boolean`

Tests whether this rectangle entirely contains another rectangle or coordinate.

Parameters

another: `(goog.math.Rect|goog.math.Coordinate)`
  The rectangle or coordinate to test for containment.

Returns

Whether this rectangle contains given rectangle or coordinate.

code »difference ( rect ) ⇒ `!Array`

Computes the difference regions between this rectangle and `rect`. The return value is an array of 0 to 4 rectangles defining the remaining regions of this rectangle after the other has been subtracted.

Parameters

rect: `goog.math.Rect`
  A Rectangle.

Returns

An array with 0 to 4 rectangles which together define the difference area of rectangle a minus rectangle b.

code »distance ( point ) ⇒ `number`

Parameters

point: `!goog.math.Coordinate`
  A coordinate.

Returns

The distance between the point and the closest point inside the rectangle. Returns 0 if the point is inside the rectangle.

code »floor ( ) ⇒ `!goog.math.Rect`

Rounds the fields to the next smaller integer values.

Returns

This rectangle with floored fields.

code »getBottomRight ( ) ⇒ `!goog.math.Coordinate`

Returns

A new coordinate for the bottom-right corner of the rectangle.

code »getCenter ( ) ⇒ `!goog.math.Coordinate`

Returns

A new coordinate for the center of the rectangle.

code »getSize ( ) ⇒ `!goog.math.Size`

Returns

The size of this rectangle.

code »getTopLeft ( ) ⇒ `!goog.math.Coordinate`

Returns

A new coordinate for the top-left corner of the rectangle.

code »intersection ( rect ) ⇒ `boolean`

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

Parameters

rect: `goog.math.Rect`
  A Rectangle.

Returns

True iff this rectangle intersects with the parameter.

code »intersects ( rect ) ⇒ `boolean`

Returns whether a rectangle intersects this rectangle.

Parameters

rect: `goog.math.Rect`
  A rectangle.

Returns

Whether rect intersects this rectangle.

code »round ( ) ⇒ `!goog.math.Rect`

Rounds the fields to nearest integer values.

Returns

This rectangle with rounded fields.

code »scale ( sx, opt_sy ) ⇒ `!goog.math.Rect`

Scales this rectangle by the given scale factors. The left and width values are scaled by `sx` and the top and height values are scaled by `opt_sy`. If `opt_sy` is not given, then all fields are scaled by `sx`.

Parameters

sx: `number`
  The scale factor to use for the x dimension.
opt_sy: `number=`
  The scale factor to use for the y dimension.

Returns

This rectangle after scaling.

code »squaredDistance ( point ) ⇒ `number`

Parameters

point: `!goog.math.Coordinate`
  A coordinate.

Returns

The squared distance between the point and the closest point inside the rectangle. Returns 0 if the point is inside the rectangle.

code »toBox ( ) ⇒ `!goog.math.Box`

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

Returns

A new Box representation of this Rectangle.

code »toString ( ) ⇒ `string`

Returns a nice string representing size and dimensions of rectangle.

Returns

In the form (50, 73 - 75w x 25h).

code »translate ( tx, opt_ty ) ⇒ `!goog.math.Rect`

Translates this rectangle by the given offsets. If a `goog.math.Coordinate` is given, then the left and top values are translated by the coordinate's x and y values. Otherwise, top and left are translated by `tx` and `opt_ty` respectively.

Parameters

tx: `(number|goog.math.Coordinate)`
  The value to translate left by or the the coordinate to translate this rect by.
opt_ty: `number=`
  The value to translate top by.

Returns

This rectangle after translating.

## Instance Properties

code »height : `number`
code »left : `number`
code »top : `number`
code »width : `number`

## Static Functions

code »goog.math.Rect.boundingRect ( a, b ) ⇒ `goog.math.Rect`

Returns a new rectangle which completely contains both input rectangles.

Parameters

a: `goog.math.Rect`
  A rectangle.
b: `goog.math.Rect`
  A rectangle.

Returns

A new bounding rect, or null if either rect is null.

code »goog.math.Rect.createFromBox ( box ) ⇒ `!goog.math.Rect`

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.

Parameters

box: `goog.math.Box`
  A box.

Returns

A new Rect initialized with the box's position and size.

code »goog.math.Rect.difference ( a, b ) ⇒ `!Array`

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.

Parameters

a: `goog.math.Rect`
  A Rectangle.
b: `goog.math.Rect`
  A Rectangle.

Returns

An array with 0 to 4 rectangles which together define the difference area of rectangle a minus rectangle b.

code »goog.math.Rect.equals ( a, b ) ⇒ `boolean`

Compares rectangles for equality.

Parameters

a: `goog.math.Rect`
  A Rectangle.
b: `goog.math.Rect`
  A Rectangle.

Returns

True iff the rectangles have the same left, top, width, and height, or if both are null.

code »goog.math.Rect.intersection ( a, b ) ⇒ `goog.math.Rect`

Returns the intersection of two rectangles. 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.

Parameters

a: `goog.math.Rect`
  A Rectangle.
b: `goog.math.Rect`
  A Rectangle.

Returns

A new intersection rect (even if width and height are 0), or null if there is no intersection.

code »goog.math.Rect.intersects ( a, b ) ⇒ `boolean`

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.

Parameters

a: `goog.math.Rect`
  A Rectangle.
b: `goog.math.Rect`
  A Rectangle.

Returns

Whether a and b intersect.