Methods
set(min, max)
Sets the min and max corners of this box.
Parameters
| min* | The minimum corner. |
| max* | The maximum corner. |
* Required
Returns
| type | description |
| Box2 |
This box. |
setFromPoints(points)
Sets this box to the minimum bounding box that contains all the given points.
Parameters
| points* Array.<Vector2> | Array of points to enclose. |
* Required
Returns
| type | description |
| Box2 |
This box. |
setFromCenterAndSize(center, size)
Sets this box from a center point and a size vector.
Parameters
| center* | The center point. |
| size* | The width and height. |
* Required
Returns
| type | description |
| Box2 |
This box. |
copy(box)
Copies the min and max from the given box into this box.
Returns
| type | description |
| Box2 |
This box. |
makeEmpty()
Makes this box empty (min > max).
Returns
| type | description |
| Box2 |
This box. |
isEmpty()
Returns true if this box is empty (min > max in any axis).
getCenter(optionalTarget)
Returns the center point of this box.
Parameters
| optionalTarget | Optional vector to store the result. |
Returns
| type | description |
| Vector2 |
The center point. |
getSize(target)
Returns the width and height of this box as a Vector2.
Parameters
| target* | Vector to store the result. |
* Required
Returns
| type | description |
| Vector2 |
The size (width, height). |
expandByPoint(point)
Expands this box to include the given point.
Parameters
| point* | The point to include. |
* Required
Returns
| type | description |
| Box2 |
This box. |
expandByVector(vector)
Expands each dimension of this box by the given vector.
Parameters
| vector* | The amount to expand in each dimension. |
* Required
Returns
| type | description |
| Box2 |
This box. |
expandByScalar(scalar)
Expands each dimension of this box by the given scalar.
Parameters
| scalar* number | The amount to expand. |
* Required
Returns
| type | description |
| Box2 |
This box. |
getParameter(point, optionalTarget)
Returns a point as a proportion of this box’s width and height (0–1 range).
Parameters
| point* | The point to parameterize. |
| optionalTarget | Optional vector to store the result. |
* Required
Returns
| type | description |
| Vector2 |
The parameterized point. |
clampPoint(point, optionalTarget)
Clamps the given point to lie within this box.
Parameters
| point* | The point to clamp. |
| optionalTarget | Optional vector to store the result. |
* Required
Returns
| type | description |
| Vector2 |
The clamped point. |
distanceToPoint(point)
Returns the distance from the given point to the nearest edge of this box (0 if inside).
Parameters
| point* | The point to measure from. |
* Required
Returns
| type | description |
| number |
The distance. |
intersect(box)
Shrinks this box to the intersection of this box and the given box.
Parameters
| box* | The box to intersect with. |
* Required
Returns
| type | description |
| Box2 |
This box. |
union(box)
Expands this box to contain the union of this box and the given box.
Parameters
| box* | The box to union with. |
* Required
Returns
| type | description |
| Box2 |
This box. |
translate(offset)
Translates this box by the given offset.
Parameters
| offset* | The offset to apply. |
* Required
Returns
| type | description |
| Box2 |
This box. |
equals(box)
Returns true if the given box has the same min and max as this box.
clone()
Returns a new Box2 with the same min and max as this box.
Returns
| type | description |
| Box2 |
A new clone. |