Class: Box2

Box2(min, max)

new Box2(min, max)

Box is described by a minimum and maximum points. Can be used for collision detection with points and other boxes.
Parameters:
Name Type Description
min Vector2 Minimum point of the box.
max Vector2 Maximum point of the box.
Source:

Members

max :Vector2

Maximum point of the box.
Type:
Source:

min :Vector2

Minimum point of the box.
Type:
Source:

Methods

clone() → {Box2}

Clone the box into a new object. Should be used when it it necessary to make operations to this box.
Source:
Returns:
New box object with the copy of this object.
Type
Box2

containsBox(box) → {boolean}

Check if the box fully contains another box inside (different from intersects box). Only returns true if the box is fully contained.
Parameters:
Name Type Description
box Box2
Source:
Returns:
True if the box contains box.
Type
boolean

containsPoint(point) → {boolean}

Check if the box contains a point inside.
Parameters:
Name Type Description
point Vector2
Source:
Returns:
True if the box contains point.
Type
boolean

copy(point)

Copy the box value from another box.
Parameters:
Name Type Description
point Box2
Source:

distanceToPoint(point) → {number}

Calculate the distance to a point.
Parameters:
Name Type Description
point Vector2
Source:
Returns:
Distance to point calculated.
Type
number

equals(box) → {boolean}

Checks if two boxes are equal.
Parameters:
Name Type Description
box Box2
Source:
Returns:
True if the two boxes are equal.
Type
boolean

expandByPoint(point)

Expand the box to contain a new point.
Parameters:
Name Type Description
point Vector2
Source:

expandByScalar(scalar)

Expand the box by adding a border with the scalar value.
Parameters:
Name Type Description
scalar number
Source:

expandByVector(vector)

Expand the box by adding a border with the vector size. Vector is subtracted from min and added to the max points.
Parameters:
Name Type Description
vector Vector2
Source:

fromArray(array)

Set box data min and max from numeric array.
Parameters:
Name Type Description
array Array.<number> Numeric array with box data min and max.
Source:

getCenter(targetopt) → {Vector2}

Calculate the center point of the box.
Parameters:
Name Type Attributes Description
target Vector2 <optional>
Vector to store the result.
Source:
Returns:
Central point of the box.
Type
Vector2

getSize(targetopt) → {Vector2}

Get the size of the box from its min and max points.
Parameters:
Name Type Attributes Description
target Vector2 <optional>
Vector to store the result.
Source:
Returns:
Vector with the calculated size.
Type
Vector2

intersect(box)

Make a intersection between this box and another box. Store the result in this object.
Parameters:
Name Type Description
box Box2
Source:

intersectsBox(box) → {boolean}

Check if two boxes intersect each other, using 4 splitting planes to rule out intersections.
Parameters:
Name Type Description
box Box2
Source:
Returns:
True if the boxes intersect each other.
Type
boolean

isEmpty() → {boolean}

Check if the box is empty (size equals zero or is negative). The box size is condireded valid on two negative axis.
Source:
Returns:
True if the box is empty.
Type
boolean

set(min, max)

Set the box values.
Parameters:
Name Type Description
min Vector2 Minimum point of the box.
max Vector2 Maximum point of the box.
Source:

setFromCenterAndSize(center, size)

Set the box minimum and maximum from center point and size.
Parameters:
Name Type Description
center Vector2
size Vector2
Source:

setFromPoints(points)

Set the box from a list of Vector2 points.
Parameters:
Name Type Description
points Array
Source:

toArray() → {Array.<number>}

Store the box data into a numeric array.
Source:
Returns:
Numeric array with box data min and max.
Type
Array.<number>

translate(offset)

Translate the box by a offset value, adds the offset to booth min and max.
Parameters:
Name Type Description
offset Vector2
Source:

union(box)

Make a union between this box and another box. Store the result in this object.
Parameters:
Name Type Description
box Box2
Source: