Represents an axis-aligned bounding box (AABB) in 2D space.

Hierarchy

  • Base
    • Box2

Constructors

  • Creates a Box2 bounded by min and max.

    Parameters

    • min: Vector2 = ...

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

    • max: Vector2 = ...

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

    Returns Box2

Properties

max: Vector2

The lower upper (x, y) boundary of the box. Default is ( - Infinity, - Infinity ).

min: Vector2

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

Accessors

  • get isBox2(): boolean
  • Returns boolean

  • get isBox3(): boolean
  • Returns boolean

  • get isColor(): boolean
  • Returns boolean

  • get isCylindrical(): boolean
  • Returns boolean

  • get isEuler(): boolean
  • Returns boolean

  • get isLine3(): boolean
  • Returns boolean

  • get isMatrix3(): boolean
  • Returns boolean

  • get isMatrix4(): boolean
  • Returns boolean

  • get isPlane(): boolean
  • Returns boolean

  • get isQuaternion(): boolean
  • Returns boolean

  • get isRay(): boolean
  • Returns boolean

  • get isSphere(): boolean
  • Returns boolean

  • get isSpherical(): boolean
  • Returns boolean

  • get isTriangle(): boolean
  • Returns boolean

  • get isVector2(): boolean
  • Returns boolean

  • get isVector3(): boolean
  • Returns boolean

  • get isVector4(): boolean
  • Returns boolean

Methods

  • Clamps the point within the bounds of this box.

    Returns

    The target Vector updated with clamped dimensions.

    Parameters

    • point: Vector2

      Vector2 to clamp.

    • target: Vector2 = ...

      the result will be copied into this Vector2.

    Returns Vector2

  • Creates a new Box2 with the same min and max as this one.

    Returns

    The new instance.

    Returns Box2

  • containsBox(box: Box2): boolean
  • Test if this box includes the entirety of box. If this and box are identical,this function also returns true.

    Returns

    True if this box includes the entirety of box.

    Parameters

    • box: Box2

      Box2 to test for inclusion.

    Returns boolean

  • containsPoint(point: Vector2): boolean
  • Test if the specified point lies within or on the boundaries of this box.

    Returns

    True if point lies within or on the boundary of this box.

    Parameters

    • point: Vector2

      Vector2 to check for inclusion.

    Returns boolean

  • Copies the min and max from box to this box

    Returns

    This instance.

    Parameters

    • box: Box2

      The box to copy.

    Returns Box2

  • distanceToPoint(point: Vector2): number
  • Compute 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.

    Returns

    The distance to point.

    Parameters

    • point: Vector2

      Vector2 to measure distance to.

    Returns number

  • equals(box: Box2): boolean
  • Test the dimensions of this box with another box for equality.

    Returns

    True if this box and box share the same lower and upper bounds.

    Parameters

    • box: Box2

      Box to compare with this one.

    Returns boolean

  • Expands the boundaries of this box to include point.

    Returns

    This instance.

    Parameters

    • point: Vector2

      Vector2 that should be included in the box.

    Returns Box2

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

    Returns

    This instance.

    Parameters

    • scalar: number

      Distance to expand the box by.

    Returns Box2

  • 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.

    Returns

    This instance.

    Parameters

    • vector: Vector2

      Vector2 to expand the box by.

    Returns Box2

  • Compute the center point of the box as a Vector2.

    Returns

    The center point.

    Parameters

    • target: Vector2 = ...

      � the result will be copied into this Vector2.

    Returns Vector2

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

    Returns

    The target vector

    Parameters

    • point: Vector2
    • target: Vector2 = ...

      the result will be copied into this Vector2.

    Returns Vector2

  • The width and height of this box.

    Returns

    The width and height of this box.

    Parameters

    • target: Vector2 = ...

      � the result will be copied into this Vector2.

    Returns Vector2

  • Compute 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.

    Returns

    This instance.

    Parameters

    • box: Box2

      Box to intersect with.

    Returns Box2

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

    Returns

    True if this and another box2 overlap.

    Parameters

    • box: Box2

      Box to check for intersection against.

    Returns boolean

  • isEmpty(): boolean
  • Determine if there is no overlap between this box and another. Note that a box with equal lower and upper bounds still includes one point, the one both bounds share.

    Returns

    True if this box includes zero points within its bounds.

    Returns boolean

  • Makes this box empty.

    Returns

    This instance.

    Returns Box2

  • Sets the lower and upper (x, y) boundaries of this box. Please note that this method only copies the values from the given objects.

    Returns

    This instance.

    Parameters

    • min: Vector2

      Vector2 representing the lower (x, y) boundary of the box.

    • max: Vector2

      Vector2 representing the upper (x, y) boundary of the box.

    Returns Box2

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

    Returns

    This instance.

    Parameters

    • center: Vector2

      Desired center position of the box

    • size: Vector2

      Desired x and y dimensions of the box

    Returns Box2

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

    Returns

    This instance.

    Parameters

    • points: Vector2[]

      Array of Vector2s that the resulting box will contain.

    Returns Box2

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

    Returns

    This instance.

    Parameters

    • offset: Vector2

      Direction and distance of offset.

    Returns Box2

  • 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