Class goog.math.Box

code »

Class for representing a box. A box is specified as a top, right, bottom, and left. A box is useful for representing margins and padding. This class assumes 'screen coordinates': larger Y coordinates are further from the top of the screen.

Constructor

goog.math.Box ( top, right, bottom, left )
Parameters
top: number
Top.
right: number
Right.
bottom: number
Bottom.
left: number
Left.
Show:

Instance Methods

Rounds the fields to the next larger integer values.

Returns
This box with ceil'd fields.

Creates a copy of the box with the same dimensions.

Returns
A clone of this Box.
code »contains ( other )boolean

Returns whether the box contains a coordinate or another box.

Parameters
other: (goog.math.Coordinate|goog.math.Box)
A Coordinate or a Box.
Returns
Whether the box contains the coordinate or other box.
code »expand ( top, opt_right, opt_bottom, opt_left )!goog.math.Box

Expands box with the given margins.

Parameters
top: (number|goog.math.Box)
Top margin or box with all margins.
opt_right: number=
Right margin.
opt_bottom: number=
Bottom margin.
opt_left: number=
Left margin.
Returns
A reference to this Box.

Expand this box to include another box. NOTE(user): This is used in code that needs to be very fast, please don't add functionality to this function at the expense of speed (variable arguments, accepting multiple argument types, etc).

Parameters
box: goog.math.Box
The box to include in this one.

Rounds the fields to the next smaller integer values.

Returns
This box with floored fields.
Returns
height The height of this Box.
Returns
width The width of this Box.

Rounds the fields to nearest integer values.

Returns
This box with rounded fields.
code »scale ( sx, opt_sy )!goog.math.Box

Scales this coordinate by the given scale factors. The x and y dimension values are scaled by sx and opt_sy respectively. If opt_sy is not given, then sx is used for both x and y.

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 box after scaling.

Returns a nice string representing the box.

Returns
In the form (50t, 73r, 24b, 13l).
code »translate ( tx, opt_ty )!goog.math.Box

Translates this box by the given offsets. If a goog.math.Coordinate is given, then the left and right values are translated by the coordinate's x value and the top and bottom values are translated by the coordinate's y value. Otherwise, tx and opt_ty are used to translate the x and y dimension values.

Parameters
tx: (number|goog.math.Coordinate)
The value to translate the x dimension values by or the the coordinate to translate this box by.
opt_ty: number=
The value to translate y dimension values by.
Returns
This box after translating.

Instance Properties

Static Functions

Creates a Box by bounding a collection of goog.math.Coordinate objects

Parameters
var_args: ...goog.math.Coordinate
Coordinates to be included inside the box.
Returns
A Box containing all the specified Coordinates.

Returns whether a box contains a coordinate or another box.

Parameters
box: goog.math.Box
A Box.
other: (goog.math.Coordinate|goog.math.Box)
A Coordinate or a Box.
Returns
Whether the box contains the coordinate or other box.

Returns the distance between a coordinate and the nearest corner/side of a box. Returns zero if the coordinate is inside the box.

Parameters
box: goog.math.Box
A Box.
coord: goog.math.Coordinate
A Coordinate.
Returns
The distance between coord and the nearest corner/side of box, or zero if coord is inside box.

Compares boxes for equality.

Parameters
a: goog.math.Box
A Box.
b: goog.math.Box
A Box.
Returns
True iff the boxes are equal, or if both are null.

Returns whether two boxes intersect.

Parameters
a: goog.math.Box
A Box.
b: goog.math.Box
A second Box.
Returns
Whether the boxes intersect.

Returns whether two boxes would intersect with additional padding.

Parameters
a: goog.math.Box
A Box.
b: goog.math.Box
A second Box.
padding: number
The additional padding.
Returns
Whether the boxes intersect.

Returns the relative x position of a coordinate compared to a box. Returns zero if the coordinate is inside the box.

Parameters
box: goog.math.Box
A Box.
coord: goog.math.Coordinate
A Coordinate.
Returns
The x position of coord relative to the nearest side of box, or zero if coord is inside box.

Returns the relative y position of a coordinate compared to a box. Returns zero if the coordinate is inside the box.

Parameters
box: goog.math.Box
A Box.
coord: goog.math.Coordinate
A Coordinate.
Returns
The y position of coord relative to the nearest side of box, or zero if coord is inside box.