BoundingBox

BoundingBox

A BoundingBox class.

Constructor

new BoundingBox(left, top, right, bottom)

Parameters:
Name Type Description
left Number

The left position of x-axis.

top Number

The top position of y-axis.

right Number

The right position of x-axis.

bottom Number

The bottom position of y-axis.

Methods

clone() → {BoundingBox}

Clone the current boundingbox to a new object.

Returns:

A clone of this instance

Type
BoundingBox

difference(other) → {Vector}

Returns this subtract other.

Parameters:
Name Type Description
other BoundingBox
Returns:

position

Type
Vector

getArea() → {Number}

Returns the area of this.

Returns:

area

Type
Number

getBoundingBox() → {BoundingBox}

Resolve this object down to a BoundingBox instance. Since this instance is already a boundingbox, it returns itself.

Returns:

self

Type
BoundingBox

getCenteredOnPosition(other) → {Vector}

Returns a position, which if this is set to, this will be centered on other.

Parameters:
Name Type Description
other BoundingBox
Returns:

position

Type
Vector

getCenterPosition() → {Vector}

Returns the center position of this.

Returns:

position

Type
Vector

getColliding(others) → {BoundingBox|undefined}

Returns which of other that this intersects an area of, not an edge.

Parameters:
Name Type Description
others Array.<BoundingBox>
Returns:
Type
BoundingBox | undefined

getCollisionMesh() → {CollisionMesh}

Returns a CollisionMesh instance version of this boundingbox similar to:

new CollisionMesh(BoundingBox)
Returns:
Type
CollisionMesh

getDistanceSquaredToPoint(other) → {Number}

Returns the squared distance between this and other.

Parameters:
Name Type Description
other Vector
Returns:

squared distance

Type
Number

getDistanceToPoint(other) → {Number}

Returns the distance between this and other.

Parameters:
Name Type Description
other Vector
Returns:

distance

Type
Number

getEdgeClosest(other) → {String}

Determines which this edge is closest to other.

Parameters:
Name Type Description
other BoundingBox
Returns:

edge name

Type
String

getEdgeClosestOrder(other) → {Array.<String>}

Determines which edges of this is closest to other, returns all edges in sorted order by distance.

Parameters:
Name Type Description
other BoundingBox
Returns:

edge names sorted from closest to furthest

Type
Array.<String>

getEdgeTouching(others) → {String|undefined}

If this touches one of others, but does not intersect area, then this returns the this edge name.

Parameters:
Name Type Description
others Array.<BoundingBox>
Returns:

edge name

Type
String | undefined

getHeight() → {Number}

Returns the height of this.

Returns:

height

Type
Number

getIntersection(other) → {Vector|BoundingBox|undefined}

Returns the intersection between this and other. This will return a Vector if they only intersect at a point. This will return a BoundingBox if they intersect over an area or line. This will return a undefined if they do not intersect.

Parameters:
Name Type Description
other BoundingBox
Returns:

intersection object

Type
Vector | BoundingBox | undefined

getOtherEdgeTouching(others) → {String|undefined}

If this touches one of others, but does not intersect area, then this returns the other edge name.

Parameters:
Name Type Description
others Array.<BoundingBox>
Returns:

edge name

Type
String | undefined

getPosition() → {Vector}

Returns the position of this.

Returns:

position

Type
Vector

getSize() → {Vector}

Returns the size of this.

Returns:

size

Type
Vector

getSnapDelta(other, snapDistanceopt) → {Vector}

Returns a vector representing the delta position to add to this to snap to other.
Note: snapDelta may contain NaN for left or right

Parameters:
Name Type Attributes Default Description
other BoundingBox
snapDistance Number <optional>
5

max distance to move this

Returns:

snapDelta

Type
Vector

getWidth() → {Number}

Returns the width of this.

Returns:

width

Type
Number

isColliding(other) → {Boolean}

Determines if this intersects an area of others, not an edge.

Parameters:
Name Type Description
other BoundingBox
Returns:
Type
Boolean

isContains(other) → {Boolean}

Determines if this encapsulates other.

Parameters:
Name Type Description
other BoundingBox
Returns:
Type
Boolean

isNaN() → {Boolean}

Checks if any property on this is NaN.

Returns:
Type
Boolean

isTouching(other) → {Boolean}

Determines if this touches an edge of other, but does not intersect area.

Parameters:
Name Type Description
other BoundingBox
Returns:
Type
Boolean

moveBy(deltaLeftopt, deltaTopopt) → {BoundingBox}

Move this relatively to position by deltaLeft and/or deltaTop.

Parameters:
Name Type Attributes Default Description
deltaLeft Number <optional>
null
deltaTop Number <optional>
null
Returns:

self

Type
BoundingBox

moveTo(leftopt, topopt) → {BoundingBox}

Move this to position at left and/or top.

Parameters:
Name Type Attributes Default Description
left Number <optional>
null
top Number <optional>
null
Returns:

self

Type
BoundingBox

resizeTo(widthopt, heightopt, anchoropt) → {BoundingBox}

Resize this to size width and/or height, anchored at anchor.

Parameters:
Name Type Attributes Default Description
width Number <optional>
null
height Number <optional>
null
anchor String <optional>
'top-left'

supports "top-left", "top-right", "bottom-left", or "bottom-right"

Returns:

self

Type
BoundingBox

set(other) → {BoundingBox}

Sets this's properties to other's properties.

Parameters:
Name Type Description
other BoundingBox
Returns:

self

Type
BoundingBox

someColliding(others) → {Boolean}

Determines if this intersects an area of one of others, not an edge.

Parameters:
Name Type Description
others Array.<BoundingBox>
Returns:
Type
Boolean

someContains(others) → {Boolean}

Determines if this encapsulates at least one of others.

Parameters:
Name Type Description
others Array.<BoundingBox>
Returns:
Type
Boolean

someTouching(others) → {Boolean}

Determines if this touches an edge of one of others, but does not intersect area.

Parameters:
Name Type Description
others Array.<BoundingBox>
Returns:
Type
Boolean