dot big bang

Developer API
Menu

Class Box2

All
  • Public
  • Public/Protected
  • All

Hierarchy

  • Box2

Index

Constructors

constructor

  • Creates a box bounded by min and max.

    Parameters

    • Optional min: Vector2

      Lower (x, y) boundary of the box. Default is (+Infinity, +Infinity).

    • Optional max: Vector2

      Upper (x, y) boundary of the box. Default is (-Infinity, -Infinity).

    Returns Box2

Properties

max

max: Vector2

The upper (x, y) boundary of this box.

min

min: Vector2

The lower (x, y) boundary of this box.

Methods

center

  • Returns the center point of this box.

    Parameters

    • Optional optionalTarget: Vector2

      If specified, the result will be copied here.

    Returns Vector2

clampPoint

  • Clamps point within the bounds of this box.

    Parameters

    • point: Vector2

      Position to clamp.

    • Optional optionalTarget: Vector2

      If specified, the clamped result will be copied here.

    Returns Vector2

clone

  • Returns a copy of this box.

    Returns Box2

containsBox

  • containsBox(box: Box2): boolean
  • Returns true if this box includes the entirety of box. If this and box overlap exactly, this function also returns true.

    Parameters

    • box: Box2

      Box to test for inclusion.

    Returns boolean

containsPoint

  • containsPoint(point: Vector2): boolean
  • Returns true if the specified point lies within the boundaries of this box.

    Parameters

    • point: Vector2

      Point to check for inclusion.

    Returns boolean

copy

  • Copies the values of box into this box.

    Parameters

    • box: Box2

      Box to copy.

    Returns Box2

distanceToPoint

  • distanceToPoint(point: Vector2): number
  • Returns the distance from any edge of this box to the specified point. If the point lies inside of this box, the distance will be 0.

    Parameters

    • point: Vector2

      Point to measure distance to.

    Returns number

equals

  • Returns true if this box and box share the same lower and upper bounds.

    Parameters

    • box: Box2

      Box to compare.

    Returns Box2

expandByPoint

  • Expands the boundaries of this box to include the provided point.

    Parameters

    • point: Vector2

      Point that should be included in the box.

    Returns Box2

expandByScalar

  • expandByScalar(scalar: number): Box2
  • Expands each dimension of the box by scalar. If negative, the dimensions of the box will be contracted

    Parameters

    • scalar: number

      Distance to expand.

    Returns Box2

expandByVector

  • Expands this box equilaterally by vector. The width of this box will be expanded by the x component of vector in both directions. The height of this box will be expanded by the y component of vector in both directions.

    Parameters

    • vector: Vector2

      Amount to expand this box in each dimension.

    Returns Box2

getParameter

  • Returns a point as a proportion of this box's width and height.

    Parameters

    • point: Vector2

      Point to parametrize.

    • Optional optionalTarget: Vector2

      If specified, the result will be copied here.

    Returns Vector2

intersect

  • Returns the intersection of this and box, setting the upper bound of this box to the lesser of the two boxes' upper bounds and the lower bound of this box to the greater of the two boxes' lower bounds.

    Parameters

    • box: Box2

      Box to intersect with.

    Returns Box2

intersectsBox

  • intersectsBox(box: Box2): boolean
  • Determines whether or not this box intersects box.

    Parameters

    • box: Box2

      Box to check for intersection against.

    Returns boolean

isEmpty

  • isEmpty(): boolean
  • Returns true if this box includes zero points within its bounds. Note that a box with equal lower and upper bounds still includes one point, the one both bounds share.

    Returns boolean

makeEmpty

  • Makes this box empty.

    Returns Box2

set

  • Sets the lower and upper (x, y) boundaries of this box.

    Parameters

    • min: Vector2

      Lower (x, y) boundary of the box.

    • max: Vector2

      Upper (x, y) boundary of the box.

    Returns Box2

setFromCenterAndSize

  • Centers this box on center and sets this box's width and height to the values specified in size.

    Parameters

    • center: Vector2

      Desired center position of the box.

    • size: Vector2

      Desired x and y dimensions of the box.

    Returns Box2

setFromPoints

  • Sets the upper and lower bounds of this box to include all of the points in points.

    Parameters

    • points: Vector2[]

      Set of points that the resulting box will envelop.

    Returns Box2

size

  • Returns the width and height of this box.

    Parameters

    • Optional optionalTarget: Vector2

      If specified, the result will be copied here.

    Returns Vector2

translate

  • Adds offset to both the upper and lower bounds of this box, effectively moving this box offset units in 2D space.

    Parameters

    • offset: Vector2

      Direction and distance of offset.

    Returns Box2

union

  • Unions this box with box setting the upper bound of this box to the greater of the two boxes' upper bounds and the lower bound of this box to the lesser of the two boxes' lower bounds.

    Parameters

    • box: Box2

      Box that will be unioned with this box.

    Returns Box2