The goog.math.Box Class

goog.math.Box(top, right, bottom, left)

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.

top {number}
Top.
right {number}
Right.
bottom {number}
Bottom.
left {number}
Left.

.bottom {number}

Bottom

.boundingBox(var_args)

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

var_args {...goog.math.Coordinate}
Coordinates to be included inside the box.
returns {!goog.math.Box}
A Box containing all the specified Coordinates.

.clone()

Creates a copy of the box with the same dimensions.

returns {!goog.math.Box}
A clone of this Box.

.contains(other)

Returns whether the box contains a coordinate or another box.

other {goog.math.Coordinate|goog.math.Box}
A Coordinate or a Box.
returns {boolean}
Whether the box contains the coordinate or other box.

.distance(box, coord)

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

box {goog.math.Box}
A Box.
coord {goog.math.Coordinate}
A Coordinate.
returns {number}
The distance between {@code coord} and the nearest corner/side of {@code box}, or zero if {@code coord} is inside {@code box}.

.equals(a, b)

Compares boxes for equality.

a {goog.math.Box}
A Box.
b {goog.math.Box}
A Box.
returns {boolean}
True iff the boxes are equal, or if both are null.

.expand(top, opt_right, opt_bottom, opt_left)

Expands box with the given margins.

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 {!goog.math.Box}
A reference to this Box.

.expandToInclude(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).

box {goog.math.Box}
The box to include in this one.

.intersects(a, b)

Returns whether two boxes intersect.

a {goog.math.Box}
A Box.
b {goog.math.Box}
A second Box.
returns {boolean}
Whether the boxes intersect.

.intersectsWithPadding(a, b, padding)

Returns whether two boxes would intersect with additional padding.

a {goog.math.Box}
A Box.
b {goog.math.Box}
A second Box.
padding {number}
The additional padding.
returns {boolean}
Whether the boxes intersect.

.left {number}

Left

.relativePositionX(box, coord)

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

box {goog.math.Box}
A Box.
coord {goog.math.Coordinate}
A Coordinate.
returns {number}
The x position of {@code coord} relative to the nearest side of {@code box}, or zero if {@code coord} is inside {@code box}.

.relativePositionY(box, coord)

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

box {goog.math.Box}
A Box.
coord {goog.math.Coordinate}
A Coordinate.
returns {number}
The y position of {@code coord} relative to the nearest side of {@code box}, or zero if {@code coord} is inside {@code box}.

Right

.toString()

Returns a nice string representing the box.

returns {string}
In the form (50t, 73r, 24b, 13l).

.top {number}

Top