Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AABB

Axis aligned bounding box class

example
var aabb = new AABB({
upperBound: [1, 1],
lowerBound: [-1, -1]
});

Hierarchy

  • AABB

Index

Constructors

  • Parameters

    Returns AABB

Properties

lowerBound: Vec2

The lower bound of the bounding box.

upperBound: Vec2

The upper bound of the bounding box.

Methods

  • containsPoint(point: Vec2): boolean
  • Whether the AABB contains a given point

    Parameters

    Returns boolean

  • copy(aabb: AABB): void
  • Copy bounds from an AABB to this AABB

    Parameters

    Returns void

  • extend(aabb: AABB): void
  • Extend this AABB so that it covers the given AABB too.

    Parameters

    Returns void

  • overlaps(aabb: AABB): boolean
  • Returns true if the given AABB overlaps this AABB.

    Parameters

    Returns boolean

  • overlapsRay(ray: Ray): number
  • Check if the AABB is hit by a ray.

    example
    var aabb = new AABB({
    upperBound: [1, 1],
    lowerBound: [-1, -1]
    });
    var ray = new Ray({
    from: [-2, 0],
    to: [0, 0]
    });
    var fraction = aabb.overlapsRay(ray); // fraction == 0.5

    Parameters

    Returns number

    -1 if no hit, a number between 0 and 1 if hit, indicating the position between the "from" and "to" points.

  • setFromPoints(points: Vec2[], position: Vec2, angle?: number, skinSize?: number): void
  • Set the AABB bounds from a set of points, transformed by the given position and angle.

    Parameters

    • points: Vec2[]

      An array of vec2's.

    • position: Vec2
    • angle: number = 0
    • skinSize: number = 0

      Some margin to be added to the AABB.

    Returns void