Request

Response

    Autodesk.Viewing.Math
    Version 8 preview
    This page documents a preview of the Viewer SDK v8. APIs and content can still change before the final release.

    Box2

    new Box2(min, max)

    Represents a 2D axis-aligned bounding box.

    Parameters

    minThe minimum (lower-left) corner. Defaults to (+Infinity, +Infinity).
    maxThe maximum (upper-right) corner. Defaults to (-Infinity, -Infinity).

    Properties

    minThe minimum (lower-left) corner of the box.
    maxThe maximum (upper-right) corner of the box.

    Methods

    set(min, max)

    Sets the min and max corners of this box.

    Parameters

    min*The minimum corner.
    max*The maximum corner.
    * Required

    Returns

    typedescription
    Box2 This box.

    setFromPoints(points)

    Sets this box to the minimum bounding box that contains all the given points.

    Parameters

    points*
    Array.<Vector2>
    Array of points to enclose.
    * Required

    Returns

    typedescription
    Box2 This box.

    setFromCenterAndSize(center, size)

    Sets this box from a center point and a size vector.

    Parameters

    center*The center point.
    size*The width and height.
    * Required

    Returns

    typedescription
    Box2 This box.

    copy(box)

    Copies the min and max from the given box into this box.

    Parameters

    box*The box to copy.
    * Required

    Returns

    typedescription
    Box2 This box.

    makeEmpty()

    Makes this box empty (min > max).

    Returns

    typedescription
    Box2 This box.

    isEmpty()

    Returns true if this box is empty (min > max in any axis).

    Returns

    typedescription
    boolean

    getCenter(optionalTarget)

    Returns the center point of this box.

    Parameters

    optionalTargetOptional vector to store the result.

    Returns

    typedescription
    Vector2 The center point.

    getSize(target)

    Returns the width and height of this box as a Vector2.

    Parameters

    target*Vector to store the result.
    * Required

    Returns

    typedescription
    Vector2 The size (width, height).

    expandByPoint(point)

    Expands this box to include the given point.

    Parameters

    point*The point to include.
    * Required

    Returns

    typedescription
    Box2 This box.

    expandByVector(vector)

    Expands each dimension of this box by the given vector.

    Parameters

    vector*The amount to expand in each dimension.
    * Required

    Returns

    typedescription
    Box2 This box.

    expandByScalar(scalar)

    Expands each dimension of this box by the given scalar.

    Parameters

    scalar*
    number
    The amount to expand.
    * Required

    Returns

    typedescription
    Box2 This box.

    containsPoint(point)

    Returns true if the given point lies within or on the boundary of this box.

    Parameters

    point*The point to test.
    * Required

    Returns

    typedescription
    boolean

    containsBox(box)

    Returns true if this box entirely contains the given box.

    Parameters

    box*The box to test.
    * Required

    Returns

    typedescription
    boolean

    getParameter(point, optionalTarget)

    Returns a point as a proportion of this box’s width and height (0–1 range).

    Parameters

    point*The point to parameterize.
    optionalTargetOptional vector to store the result.
    * Required

    Returns

    typedescription
    Vector2 The parameterized point.

    intersectsBox(box)

    Returns true if the given box intersects this box.

    Parameters

    box*The box to test.
    * Required

    Returns

    typedescription
    boolean

    clampPoint(point, optionalTarget)

    Clamps the given point to lie within this box.

    Parameters

    point*The point to clamp.
    optionalTargetOptional vector to store the result.
    * Required

    Returns

    typedescription
    Vector2 The clamped point.

    distanceToPoint(point)

    Returns the distance from the given point to the nearest edge of this box (0 if inside).

    Parameters

    point*The point to measure from.
    * Required

    Returns

    typedescription
    number The distance.

    intersect(box)

    Shrinks this box to the intersection of this box and the given box.

    Parameters

    box*The box to intersect with.
    * Required

    Returns

    typedescription
    Box2 This box.

    union(box)

    Expands this box to contain the union of this box and the given box.

    Parameters

    box*The box to union with.
    * Required

    Returns

    typedescription
    Box2 This box.

    translate(offset)

    Translates this box by the given offset.

    Parameters

    offset*The offset to apply.
    * Required

    Returns

    typedescription
    Box2 This box.

    equals(box)

    Returns true if the given box has the same min and max as this box.

    Parameters

    box*The box to compare.
    * Required

    Returns

    typedescription
    boolean

    clone()

    Returns a new Box2 with the same min and max as this box.

    Returns

    typedescription
    Box2 A new clone.