Bounds

Basic bounding box.

Constructor

new Bounds(from, to)

Create a new bounding box (parameters do not have to necessarily be min and max).
Parameters:
NameTypeDescription
fromVec2First corner
toVec2Second corner

Members

bottom

Get the y value of the bottom side of the bounds.

bottomLeft

Get the bottom-left corner of the bounding box.

height

Get the height of the bounding box.

left

Get the x value of the left side of the bounds.

max

Maximum (bottom-right) point

min

Minimum (top-left) point
Get the x value of the right side of the bounds.

top

Get the y value of the top side of the bounds.

topRight

Get the top-right corner of the bounding box.

width

Get the width of the bounding box.

Methods

add(offset) → {Bounds}

Offset the bounding box.
Parameters:
NameTypeDescription
offsetVec2Vector to offset by
Returns:
Offset bounding box
Type: 
Bounds

copy() → {Bounds}

Get a copy of the bounding box.
Returns:
Copied bounding box
Type: 
Bounds

merge(other) → {Bounds}

Merge the bounds with another.
Parameters:
NameTypeDescription
otherBoundsOther bounding box to merge with
Returns:
Merged/combined bounding box
Type: 
Bounds

overlaps(other) → {boolean}

Check if the bounding box overlaps another.
Parameters:
NameTypeDescription
otherBoundsOther bounding box to check with
Returns:
Whether bounding boxes overlap
Type: 
boolean

scale(val) → {Bounds}

Scale the bounding box.
Parameters:
NameTypeDescription
valnumber | Vec2Value to scale bounds by
Returns:
Scaled bounding box
Type: 
Bounds

within(pos) → {boolean}

Check if a point is within the bounding box.
Parameters:
NameTypeDescription
posVec2Point to check for
Returns:
Whether point is within bounds
Type: 
boolean

(static) fromWidthAndHeight(width, height) → {Bounds}

Create a bounding box from width and height (centered)
Parameters:
NameTypeDescription
widthnumberWidth of bounding box
heightnumberHeight of bounding box
Returns:
Resulting bounding box
Type: 
Bounds