com.threerings.math
Class Box

java.lang.Object
  extended by com.threerings.math.Box
All Implemented Interfaces:
Exportable

public final class Box
extends Object
implements Exportable

An axis-aligned box.


Field Summary
static Box EMPTY
          The empty box.
static Box MAX_VALUE
          A box that's as large as boxes can get.
static Box UNIT
          The unit box.
static Box ZERO
          The zero box.
 
Constructor Summary
Box()
          Creates an empty box.
Box(Box other)
          Copy constructor.
Box(Vector3f minExtent, Vector3f maxExtent)
          Creates a box with the values contained in the supplied minimum and maximum extents.
 
Method Summary
 Box add(Box other)
          Expands this box to include the bounds of another box.
 Box add(Box other, Box result)
          Expands this box to include the bounds of another box, placing the result in the object provided.
 Box add(Vector3f point)
          Expands this box to include the specified point.
 Box add(Vector3f point, Box result)
          Expands this box to include the specified point, placing the result in the object provided.
 Box addLocal(Box other)
          Expands this box to include the bounds of another box.
 Box addLocal(Vector3f point)
          Expands this box in-place to include the specified point.
 boolean contains(Box other)
          Determines whether this box completely contains the specified box.
 boolean contains(float x, float y, float z)
          Determines whether this box contains the specified point.
 boolean contains(Vector3f point)
          Determines whether this box contains the specified point.
 boolean equals(Object other)
           
 Box expand(float x, float y, float z)
          Expands the box by the specified amounts.
 Box expand(float x, float y, float z, Box result)
          Expands the box by the specified amounts, placing the result in the object provided.
 Box expandLocal(float x, float y, float z)
          Expands the box in-place by the specified amounts.
 Box fromPoints(Vector3f... points)
          Initializes this box with the extents of an array of points.
 Vector3f getCenter()
          Returns the center of the box as a new vector.
 Vector3f getCenter(Vector3f result)
          Places the location of the center of the box into the given result vector.
 float getDiagonalLength()
          Returns the length of the box's diagonal (the distance from minimum to maximum extent).
 float getExtentDistance(Box other)
          Returns the sum of the Manhattan distances between the extents of this box and the specified other box.
 boolean getIntersection(Ray3D ray, Vector3f result)
          Finds the location of the (first) intersection between the specified ray and this box.
 float getLongestEdge()
          Returns the length of the box's longest edge.
 Vector3f getMaximumExtent()
          Returns a reference to the box's maximum extent.
 Vector3f getMinimumExtent()
          Returns a reference to the box's minimum extent.
 Vector3f getVertex(int code, Vector3f result)
          Retrieves one of the eight vertices of the box.
 int hashCode()
           
 Box intersect(Box other)
          Finds the intersection between this box and another box.
 Box intersect(Box other, Box result)
          Finds the intersection between this box and another box and places the result in the provided object.
 Box intersectLocal(Box other)
          Finds the intersection between this box and another box and places the result in this box.
 boolean intersects(Box other)
          Determines whether this box intersects the specified other box.
 boolean intersects(Ray3D ray)
          Determines whether the specified ray intersects this box.
 boolean isEmpty()
          Determines whether the box is empty (whether any of its minima are greater than their corresponding maxima).
 Box project(Matrix4f matrix)
          Projects this box.
 Box project(Matrix4f matrix, Box result)
          Projects this box, placing the result in the object provided.
 Box projectLocal(Matrix4f matrix)
          Projects this box in-place.
 Box set(Box other)
          Copies the parameters of another box.
 Box set(Vector3f minExtent, Vector3f maxExtent)
          Sets the box parameters to the values contained in the supplied vectors.
 Box setToEmpty()
          Sets the parameters of the box to the empty values (Vector3f.MAX_VALUE and Vector3f.MIN_VALUE for the minimum and maximum, respectively).
 String toString()
           
 Box transform(Transform3D transform)
          Transforms this box.
 Box transform(Transform3D transform, Box result)
          Transforms this box, placing the result in the provided object.
 Box transformLocal(Transform3D transform)
          Transforms this box in-place.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UNIT

public static final Box UNIT
The unit box.


ZERO

public static final Box ZERO
The zero box.


EMPTY

public static final Box EMPTY
The empty box.


MAX_VALUE

public static final Box MAX_VALUE
A box that's as large as boxes can get.

Constructor Detail

Box

public Box(Vector3f minExtent,
           Vector3f maxExtent)
Creates a box with the values contained in the supplied minimum and maximum extents.


Box

public Box(Box other)
Copy constructor.


Box

public Box()
Creates an empty box.

Method Detail

getMinimumExtent

public Vector3f getMinimumExtent()
Returns a reference to the box's minimum extent.


getMaximumExtent

public Vector3f getMaximumExtent()
Returns a reference to the box's maximum extent.


getCenter

public Vector3f getCenter()
Returns the center of the box as a new vector.


getCenter

public Vector3f getCenter(Vector3f result)
Places the location of the center of the box into the given result vector.

Returns:
a reference to the result vector, for chaining.

getDiagonalLength

public float getDiagonalLength()
Returns the length of the box's diagonal (the distance from minimum to maximum extent).


getLongestEdge

public float getLongestEdge()
Returns the length of the box's longest edge.


isEmpty

public boolean isEmpty()
Determines whether the box is empty (whether any of its minima are greater than their corresponding maxima).


fromPoints

public Box fromPoints(Vector3f... points)
Initializes this box with the extents of an array of points.

Returns:
a reference to this box, for chaining.

addLocal

public Box addLocal(Vector3f point)
Expands this box in-place to include the specified point.

Returns:
a reference to this box, for chaining.

add

public Box add(Vector3f point)
Expands this box to include the specified point.

Returns:
a new box containing the result.

add

public Box add(Vector3f point,
               Box result)
Expands this box to include the specified point, placing the result in the object provided.

Returns:
a reference to the result box, for chaining.

addLocal

public Box addLocal(Box other)
Expands this box to include the bounds of another box.

Returns:
a reference to this box, for chaining.

add

public Box add(Box other)
Expands this box to include the bounds of another box.

Returns:
a new box containing the result.

add

public Box add(Box other,
               Box result)
Expands this box to include the bounds of another box, placing the result in the object provided.

Returns:
a reference to the result box, for chaining.

intersectLocal

public Box intersectLocal(Box other)
Finds the intersection between this box and another box and places the result in this box.

Returns:
a reference to this box, for chaining.

intersect

public Box intersect(Box other)
Finds the intersection between this box and another box.

Returns:
a new box containing the result.

intersect

public Box intersect(Box other,
                     Box result)
Finds the intersection between this box and another box and places the result in the provided object.

Returns:
a reference to this box, for chaining.

transformLocal

public Box transformLocal(Transform3D transform)
Transforms this box in-place.

Returns:
a reference to this box, for chaining.

transform

public Box transform(Transform3D transform)
Transforms this box.

Returns:
a new box containing the result.

transform

public Box transform(Transform3D transform,
                     Box result)
Transforms this box, placing the result in the provided object.

Returns:
a reference to the result box, for chaining.

projectLocal

public Box projectLocal(Matrix4f matrix)
Projects this box in-place.

Returns:
a reference to this box, for chaining.

project

public Box project(Matrix4f matrix)
Projects this box.

Returns:
a new box containing the result.

project

public Box project(Matrix4f matrix,
                   Box result)
Projects this box, placing the result in the object provided.

Returns:
a reference to the result, for chaining.

expandLocal

public Box expandLocal(float x,
                       float y,
                       float z)
Expands the box in-place by the specified amounts.

Returns:
a reference to this box, for chaining.

expand

public Box expand(float x,
                  float y,
                  float z)
Expands the box by the specified amounts.

Returns:
a new box containing the result.

expand

public Box expand(float x,
                  float y,
                  float z,
                  Box result)
Expands the box by the specified amounts, placing the result in the object provided.

Returns:
a reference to the result box, for chaining.

setToEmpty

public Box setToEmpty()
Sets the parameters of the box to the empty values (Vector3f.MAX_VALUE and Vector3f.MIN_VALUE for the minimum and maximum, respectively).

Returns:
a reference to this box, for chaining.

set

public Box set(Box other)
Copies the parameters of another box.

Returns:
a reference to this box, for chaining.

set

public Box set(Vector3f minExtent,
               Vector3f maxExtent)
Sets the box parameters to the values contained in the supplied vectors.

Returns:
a reference to this box, for chaining.

getVertex

public Vector3f getVertex(int code,
                          Vector3f result)
Retrieves one of the eight vertices of the box. The code parameter identifies the vertex with flags indicating which values should be selected from the minimum extent, and which from the maximum extent. For example, the code 011b selects the vertex with the minimum x, maximum y, and maximum z.

Returns:
a reference to the result, for chaining.

contains

public boolean contains(Vector3f point)
Determines whether this box contains the specified point.


contains

public boolean contains(float x,
                        float y,
                        float z)
Determines whether this box contains the specified point.


getExtentDistance

public float getExtentDistance(Box other)
Returns the sum of the Manhattan distances between the extents of this box and the specified other box.


contains

public boolean contains(Box other)
Determines whether this box completely contains the specified box.


intersects

public boolean intersects(Box other)
Determines whether this box intersects the specified other box.


intersects

public boolean intersects(Ray3D ray)
Determines whether the specified ray intersects this box.


getIntersection

public boolean getIntersection(Ray3D ray,
                               Vector3f result)
Finds the location of the (first) intersection between the specified ray and this box. This will be the ray origin if the ray starts inside the box.

Parameters:
result - a vector to hold the location of the intersection.
Returns:
true if the ray intersects the box (in which case the result vector will be populated with the location of the intersection), false if not.

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object


Copyright © 2011. All Rights Reserved.