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:
Type:
BoundingBox

A clone of this instance

difference(other) → {Vector}

Returns this subtract other.

Parameters:
Name Type Description
other BoundingBox
Returns:
Type:
Vector

position

getArea() → {Number}

Returns the area of this.

Returns:
Type:
Number

area

getBoundingBox() → {BoundingBox}

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

Returns:
Type:
BoundingBox

self

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:
Type:
Vector

position

getCenterPosition() → {Vector}

Returns the center position of this.

Returns:
Type:
Vector

position

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:
Type:
Number

squared distance

getDistanceToPoint(other) → {Number}

Returns the distance between this and other.

Parameters:
Name Type Description
other Vector
Returns:
Type:
Number

distance

getEdgeClosest(other) → {String}

Determines which this edge is closest to other.

Parameters:
Name Type Description
other BoundingBox
Returns:
Type:
String

edge name

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:
Type:
Array.<String>

edge names sorted from closest to furthest

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:
Type:
String | undefined

edge name

getHeight() → {Number}

Returns the height of this.

Returns:
Type:
Number

height

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:
Type:
Vector | BoundingBox | undefined

intersection object

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:
Type:
String | undefined

edge name

getPosition() → {Vector}

Returns the position of this.

Returns:
Type:
Vector

position

getSize() → {Vector}

Returns the size of this.

Returns:
Type:
Vector

size

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:
Type:
Vector

snapDelta

getWidth() → {Number}

Returns the width of this.

Returns:
Type:
Number

width

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:
Type:
BoundingBox

self

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:
Type:
BoundingBox

self

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:
Type:
BoundingBox

self

set(other) → {BoundingBox}

Sets this's properties to other's properties.

Parameters:
Name Type Description
other BoundingBox
Returns:
Type:
BoundingBox

self

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