Skip to content

Bounds

The Bounds class represents a bounding box of an object.

Usage

To use this class, add the following require at the top of your script:

local Bounds = require 'engine/math/bounds'

Reference

new

static new(center, size)

Creates a new Bounds instance.

Parameters

  • center (Vector3): The center of the bounds.
  • size (Vector3): The total size of the bounds.

Returns

  • Bounds: new Bounds object.

get

get()

Gets the center and size of the bounds as separate values.

Returns

  • number: The X component of the center
  • number: The Y component of the center
  • number: The Z component of the center
  • number: The X component of the size
  • number: The Y component of the size
  • number: The Z component of the size

getSize

getSize()

Gets the size (full extents * 2) of the bounds.

Returns

  • Vector3: full size of the bounds.

setSize

setSize(value)

Sets the size of the bounds.

Parameters

  • value (Vector3): The new size of the bounds.

getMin

getMin()

Gets the minimum corner of the bounds.

Returns

  • Vector3: minimum corner position.

setMin

setMin(value)

Sets the minimum corner, adjusting the bounds accordingly.

Parameters

  • value (Vector3): The new minimum corner.

getMax

getMax()

Gets the maximum corner of the bounds.

Returns

  • Vector3: maximum corner position.

setMax

setMax(value)

Sets the maximum corner, adjusting the bounds accordingly.

Parameters

  • value (Vector3): The new maximum corner.

setMinMax

setMinMax(min, max)

Sets both the minimum and maximum corners, recalculating center and extents.

Parameters

  • min (Vector3): The new minimum corner.
  • max (Vector3): The new maximum corner.

encapsulate

encapsulate(point)

Expands the bounds to encapsulate a given point.

Parameters

  • point (Vector3): The point to include within the bounds.

expand

expand(amount)

Expands the bounds by a given amount.

Parameters

  • amount (number|Vector3): The amount to expand by (uniformly if number, per axis if Vector3).

intersects

intersects(bounds)

Checks if this bounds intersects with another.

Parameters

  • bounds (Bounds): The other bounds to check against.

Returns

  • boolean: if the bounds intersect.

contains

contains(p)

Checks if a point is contained within the bounds.

Parameters

  • p (Vector3): The point to check.

Returns

  • boolean: if the point is inside the bounds.