Class AABB

Axis aligned bounding box class

Example

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

Hierarchy

  • AABB

Constructors

  • Parameters

    Returns AABB

Properties

lowerBound: Vec2

The lower bound of the bounding box.

upperBound: Vec2

The upper bound of the bounding box.

Methods

  • Whether the AABB contains a given point

    Parameters

    Returns boolean

  • Copy bounds from an AABB to this AABB

    Parameters

    Returns void

  • Extend this AABB so that it covers the given AABB too.

    Parameters

    Returns void

  • Returns true if the given AABB overlaps this AABB.

    Parameters

    Returns boolean

  • Check if the AABB is hit by a ray.

    Parameters

    Returns number

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

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