com.threerings.math
Class Rect

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

public final class Rect
extends Object
implements Exportable

An axis-aligned rectangle.


Field Summary
static Rect EMPTY
          The empty rect.
static Rect MAX_VALUE
          A rect that's as large as rects can get.
static Rect ZERO
          The zero rect.
 
Constructor Summary
Rect()
          Creates an empty rectangle.
Rect(Rect other)
          Copy constructor.
Rect(Vector2f minExtent, Vector2f maxExtent)
          Creates a rectangle with the values contained in the supplied minimum and maximum extents.
 
Method Summary
 Rect add(Rect other)
          Expands this rectangle to include the bounds of another rectangle.
 Rect add(Rect other, Rect result)
          Expands this rectangle to include the bounds of another rectangle, placing the result in the object provided.
 Rect add(Vector2f point)
          Expands this rectangle to include the specified point.
 Rect add(Vector2f point, Rect result)
          Expands this rectangle to include the specified point, placing the result in the object provided.
 Rect addLocal(Rect other)
          Expands this rectangle to include the bounds of another rectangle.
 Rect addLocal(Vector2f point)
          Expands this rectangle in-place to include the specified point.
 boolean contains(float x, float y)
          Determines whether this rectangle contains the specified point.
 boolean contains(Rect other)
          Determines whether this rectangle completely contains the specified rectangle.
 boolean contains(Vector2f point)
          Determines whether this rectangle contains the specified point.
 boolean equals(Object other)
           
 Rect expand(float x, float y)
          Expands the rectangle by the specified amounts.
 Rect expand(float x, float y, Rect result)
          Expands the rectangle by the specified amounts, placing the result in the object provided.
 Rect expandLocal(float x, float y)
          Expands the rectangle in-place by the specified amounts.
 Rect fromPoints(Vector2f... points)
          Initializes this rectangle with the extents of an array of points.
 Vector2f getCenter()
          Returns the center of the rectangle as a new vector.
 Vector2f getCenter(Vector2f result)
          Places the location of the center of the rectangle into the given result vector.
 float getHeight()
          Returns the height of the rectangle.
 boolean getIntersection(Ray2D ray, Vector2f result)
          Finds the location of the (first) intersection between the specified ray and this rectangle.
 float getLongestEdge()
          Returns the length of the rectangle's longest edge.
 Vector2f getMaximumExtent()
          Returns a reference to the rectangle's maximum extent.
 Vector2f getMinimumExtent()
          Returns a reference to the rectangle's minimum extent.
 Vector2f[] getPerimeterPath()
          Returns a path that goes counter-clockwise around the rectangle, starting and ending at the minimum extent.
 float getShortestEdge()
          Returns the length of the rectangle's shortest edge.
 Vector2f getVertex(int code)
          Retrieves one of the four vertices of the rectangle.
 Vector2f getVertex(int code, Vector2f result)
          Retrieves one of the four vertices of the rectangle.
 float getWidth()
          Returns the width of the rectangle.
 int hashCode()
           
 Rect intersect(Rect other)
          Finds the intersection between this rectangle and another rectangle.
 Rect intersect(Rect other, Rect result)
          Finds the intersection between this rectangle and another rectangle and places the result in the provided object.
 Rect intersectLocal(Rect other)
          Finds the intersection between this rectangle and another rectangle and places the result in this rectangle.
 boolean intersects(Ray2D ray)
          Determines whether the specified ray intersects this rectangle.
 boolean intersects(Rect other)
          Determines whether this rectangle intersects the specified other rectangle.
 boolean isEmpty()
          Determines whether the rect is empty (whether any of its minima are greater than their corresponding maxima).
 Rect set(Rect other)
          Copies the parameters of another rectangle.
 Rect set(Vector2f minExtent, Vector2f maxExtent)
          Sets the rectangle parameters to the values contained in the supplied vectors.
 Rect setToEmpty()
          Sets the parameters of the rectangle to the empty values (Vector2f.MAX_VALUE and Vector2f.MIN_VALUE for the minimum and maximum, respectively).
 String toString()
           
 Rect transform(Transform2D transform)
          Transforms this rectangle.
 Rect transform(Transform2D transform, Rect result)
          Transforms this rectangle, placing the result in the provided object.
 Rect transformLocal(Transform2D transform)
          Transforms this rectangle in-place.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Rect ZERO
The zero rect.


EMPTY

public static final Rect EMPTY
The empty rect.


MAX_VALUE

public static final Rect MAX_VALUE
A rect that's as large as rects can get.

Constructor Detail

Rect

public Rect(Vector2f minExtent,
            Vector2f maxExtent)
Creates a rectangle with the values contained in the supplied minimum and maximum extents.


Rect

public Rect(Rect other)
Copy constructor.


Rect

public Rect()
Creates an empty rectangle.

Method Detail

getMinimumExtent

public Vector2f getMinimumExtent()
Returns a reference to the rectangle's minimum extent.


getMaximumExtent

public Vector2f getMaximumExtent()
Returns a reference to the rectangle's maximum extent.


getCenter

public Vector2f getCenter()
Returns the center of the rectangle as a new vector.


getCenter

public Vector2f getCenter(Vector2f result)
Places the location of the center of the rectangle into the given result vector.

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

getLongestEdge

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


getShortestEdge

public float getShortestEdge()
Returns the length of the rectangle's shortest edge.


getWidth

public float getWidth()
Returns the width of the rectangle.


getHeight

public float getHeight()
Returns the height of the rectangle.


isEmpty

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


fromPoints

public Rect fromPoints(Vector2f... points)
Initializes this rectangle with the extents of an array of points.

Returns:
a reference to this rectangle, for chaining.

addLocal

public Rect addLocal(Vector2f point)
Expands this rectangle in-place to include the specified point.

Returns:
a reference to this rectangle, for chaining.

add

public Rect add(Vector2f point)
Expands this rectangle to include the specified point.

Returns:
a new rectangle containing the result.

add

public Rect add(Vector2f point,
                Rect result)
Expands this rectangle to include the specified point, placing the result in the object provided.

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

addLocal

public Rect addLocal(Rect other)
Expands this rectangle to include the bounds of another rectangle.

Returns:
a reference to this rectangle, for chaining.

add

public Rect add(Rect other)
Expands this rectangle to include the bounds of another rectangle.

Returns:
a new rectangle containing the result.

add

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

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

intersectLocal

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

Returns:
a reference to this rectangle, for chaining.

intersect

public Rect intersect(Rect other)
Finds the intersection between this rectangle and another rectangle.

Returns:
a new rectangle containing the result.

intersect

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

Returns:
a reference to this rectangle, for chaining.

transformLocal

public Rect transformLocal(Transform2D transform)
Transforms this rectangle in-place.

Returns:
a reference to this rectangle, for chaining.

transform

public Rect transform(Transform2D transform)
Transforms this rectangle.

Returns:
a new rectangle containing the result.

transform

public Rect transform(Transform2D transform,
                      Rect result)
Transforms this rectangle, placing the result in the provided object.

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

expandLocal

public Rect expandLocal(float x,
                        float y)
Expands the rectangle in-place by the specified amounts.

Returns:
a reference to this rectangle, for chaining.

expand

public Rect expand(float x,
                   float y)
Expands the rectangle by the specified amounts.

Returns:
a new rectangle containing the result.

expand

public Rect expand(float x,
                   float y,
                   Rect result)
Expands the rectangle by the specified amounts, placing the result in the object provided.

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

setToEmpty

public Rect setToEmpty()
Sets the parameters of the rectangle to the empty values (Vector2f.MAX_VALUE and Vector2f.MIN_VALUE for the minimum and maximum, respectively).

Returns:
a reference to this rectangle, for chaining.

set

public Rect set(Rect other)
Copies the parameters of another rectangle.

Returns:
a reference to this rectangle, for chaining.

set

public Rect set(Vector2f minExtent,
                Vector2f maxExtent)
Sets the rectangle parameters to the values contained in the supplied vectors.

Returns:
a reference to this rectangle, for chaining.

getPerimeterPath

public Vector2f[] getPerimeterPath()
Returns a path that goes counter-clockwise around the rectangle, starting and ending at the minimum extent.


getVertex

public Vector2f getVertex(int code)
Retrieves one of the four vertices of the rectangle. 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 01b selects the vertex with the minimum x and maximum y.

Returns:
a new vector containing the result.

getVertex

public Vector2f getVertex(int code,
                          Vector2f result)
Retrieves one of the four vertices of the rectangle. 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 01b selects the vertex with the minimum x and maximum y.

Returns:
a reference to the result, for chaining.

contains

public boolean contains(Vector2f point)
Determines whether this rectangle contains the specified point.


contains

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


contains

public boolean contains(Rect other)
Determines whether this rectangle completely contains the specified rectangle.


intersects

public boolean intersects(Rect other)
Determines whether this rectangle intersects the specified other rectangle.


intersects

public boolean intersects(Ray2D ray)
Determines whether the specified ray intersects this rectangle.


getIntersection

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

Parameters:
result - a vector to hold the location of the intersection.
Returns:
true if the ray intersects the rectangle (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.