com.threerings.tudey.shape
Class Shape

java.lang.Object
  extended by com.threerings.tudey.shape.Shape
Direct Known Subclasses:
Capsule, Circle, Compound, Global, None, Point, Polygon, Segment

public abstract class Shape
extends Object

A Tudey shape.


Nested Class Summary
static class Shape.IntersectionType
          Intersection types indicating that the shape does not intersect, intersects, or fully contains, respectively, the parameter.
 
Field Summary
protected  Rect _bounds
          The bounds of the shape.
protected static float CIRCLE_INCREMENT
          The increment angle between circle segments.
protected static int CIRCLE_SEGMENTS
          The number of segments to use when we render circles.
 
Constructor Summary
Shape()
           
 
Method Summary
abstract  ShapeConfig createConfig()
          Creates a config corresponding to this shape.
abstract  void draw(boolean outline)
          Draws this shape in immediate mode.
 Shape expand(float amount)
          Expands this shape by the specified amount.
abstract  Shape expand(float amount, Shape result)
          Expands this shape, placing the result in the provided object if possible.
 Shape expandLocal(float amount)
          Expands this shape in-place by the specified amount.
 Rect getBounds()
          Returns a reference to the bounds of the shape.
 Vector2f getCenter()
          Retrieves the center of the shape.
abstract  Vector2f getCenter(Vector2f result)
          Retrieves the center of the shape and places it in the supplied vector.
abstract  boolean getIntersection(Ray2D ray, Vector2f result)
          Finds the intersection of a ray with this shape and places it in the supplied vector (if it exists).
abstract  Shape.IntersectionType getIntersectionType(Rect rect)
          Checks whether the intersector intersects the specified rect.
protected static Vector2f getMinMinkowskyDifference(Vector2f[] A, Vector2f[] B, float radius, Vector2f minDistance)
          Calculates the minimum distance to the origin for the A polygon edges in the convex hull of the Minkowski difference of the A and B polygons.
abstract  void getNearestPoint(Vector2f point, Vector2f result)
          Fins the nearest point of this element to the supplied point and places it in the supplied vector.
protected static void getOutsideLinePenetration(Vector2f start, Vector2f end, float radius, Vector2f point, Vector2f result)
           
abstract  Vector2f getPenetration(Capsule capsule, Vector2f result)
          Finds the penetration of the specified capsule into this shape.
abstract  Vector2f getPenetration(Circle circle, Vector2f result)
          Finds the penetration of the specified circle into this shape.
abstract  Vector2f getPenetration(Compound compound, Vector2f result)
          Finds the penetration of the specified compound into this shape.
 Vector2f getPenetration(None none, Vector2f result)
          Shapes never penetrate none.
abstract  Vector2f getPenetration(Point point, Vector2f result)
          Finds the penetration of the specified point into this shape.
abstract  Vector2f getPenetration(Polygon polygon, Vector2f result)
          Finds the penetration of the specified polygon into this shape.
abstract  Vector2f getPenetration(Segment segment, Vector2f result)
          Finds the penetration of the specified segment into this shape.
abstract  Vector2f getPenetration(Shape shape, Vector2f result)
          Finds the penetration of the specified shape into this one, assuming that they intersect.
 Vector2f[] getPerimeterPath()
          Returns a perimeter path for this shape.
abstract  boolean intersects(Capsule capsule)
          Checks for an intersection with this shape and the specified capsule.
abstract  boolean intersects(Circle circle)
          Checks for an intersection with this shape and the specified circle.
abstract  boolean intersects(Compound compound)
          Checks for an intersection with this shape and the specified compound.
 boolean intersects(None none)
          Shapes can never intserct none.
abstract  boolean intersects(Point point)
          Checks for an intersection with this shape and the specified point.
abstract  boolean intersects(Polygon polygon)
          Checks for an intersection with this shape and the specified polygon.
abstract  boolean intersects(Segment segment)
          Checks for an intersection with this shape and the specified segment.
abstract  boolean intersects(Shape shape)
          Determines whether this shape intersects the specified shape.
abstract  boolean intersects(SpaceElement element)
          Determines whether this shape intersects the specified element.
protected static boolean intersects(Vector2f center, float radius, Vector2f start, Vector2f end)
          Determines whether the line segment from start to end intersects the circle with the given center and radius.
protected static boolean intersects(Vector2f start, Vector2f end, float radius, Vector2f origin, Vector2f terminus)
          Determines whether the capsule from start to end with the specified radius intersects the line segment with the supplied origin and terminus.
protected static void nearestPointOnSegment(Vector2f start, Vector2f end, Vector2f point, Vector2f result)
          Finds the nearest point on the line segment from start to end to a point point and stores it in result.
 Shape sweep(Vector2f translation)
          Computes the shape created by sweeping this shape along the specified translation vector.
abstract  Shape sweep(Vector2f translation, Shape result)
          Computes the shape created by sweeping this shape along the specified translation vector, placing the result in the provided object if possible.
 Shape transform(Transform2D transform)
          Transforms this shape.
abstract  Shape transform(Transform2D transform, Shape result)
          Transforms this shape, placing the result in the provided object if possible.
 Shape transformLocal(Transform2D transform)
          Transforms this shape in-place.
abstract  void updateBounds()
          Updates the bounds of the shape.
protected static Vector2f updateClosest(Vector2f origin, Vector2f result, Vector2f closest)
          Updates the value of the closest point and returns a new result vector reference.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_bounds

protected Rect _bounds
The bounds of the shape.


CIRCLE_SEGMENTS

protected static final int CIRCLE_SEGMENTS
The number of segments to use when we render circles.

See Also:
Constant Field Values

CIRCLE_INCREMENT

protected static final float CIRCLE_INCREMENT
The increment angle between circle segments.

See Also:
Constant Field Values
Constructor Detail

Shape

public Shape()
Method Detail

getBounds

public Rect getBounds()
Returns a reference to the bounds of the shape.


updateBounds

public abstract void updateBounds()
Updates the bounds of the shape.


getCenter

public Vector2f getCenter()
Retrieves the center of the shape.

Returns:
a new vector containing the result.

getCenter

public abstract Vector2f getCenter(Vector2f result)
Retrieves the center of the shape and places it in the supplied vector.

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

transformLocal

public Shape transformLocal(Transform2D transform)
Transforms this shape in-place.

Returns:
a reference to this shape, for chaining.

transform

public Shape transform(Transform2D transform)
Transforms this shape.

Returns:
a new shape containing the result.

transform

public abstract Shape transform(Transform2D transform,
                                Shape result)
Transforms this shape, placing the result in the provided object if possible.

Returns:
a reference to the result object, if it was reused; otherwise, a new object containing the result.

expandLocal

public Shape expandLocal(float amount)
Expands this shape in-place by the specified amount.

Returns:
a reference to this shape, for chaining.

expand

public Shape expand(float amount)
Expands this shape by the specified amount.

Returns:
a new shape containing the result.

expand

public abstract Shape expand(float amount,
                             Shape result)
Expands this shape, placing the result in the provided object if possible.

Returns:
a reference to the result object, if it was reused; otherwise, a new object containing the result.

sweep

public Shape sweep(Vector2f translation)
Computes the shape created by sweeping this shape along the specified translation vector.

Returns:
a new shape containing the result.

sweep

public abstract Shape sweep(Vector2f translation,
                            Shape result)
Computes the shape created by sweeping this shape along the specified translation vector, placing the result in the provided object if possible.

Returns:
a reference to the result object, if it was reused; otherwise, a new object containing the result.

getPerimeterPath

public Vector2f[] getPerimeterPath()
Returns a perimeter path for this shape.


getIntersection

public abstract boolean getIntersection(Ray2D ray,
                                        Vector2f result)
Finds the intersection of a ray with this shape and places it in the supplied vector (if it exists).

Returns:
true if the ray intersected the shape (in which case the result will contain the point of intersection), false otherwise.

getNearestPoint

public abstract void getNearestPoint(Vector2f point,
                                     Vector2f result)
Fins the nearest point of this element to the supplied point and places it in the supplied vector.


getIntersectionType

public abstract Shape.IntersectionType getIntersectionType(Rect rect)
Checks whether the intersector intersects the specified rect.


intersects

public abstract boolean intersects(SpaceElement element)
Determines whether this shape intersects the specified element. Uses double-dispatch to invoke the appropriate specialization of SpaceElement.intersects(com.threerings.tudey.shape.Point).


intersects

public abstract boolean intersects(Shape shape)
Determines whether this shape intersects the specified shape. Uses double-dispatch to invoke the appropriate method specialization.


intersects

public abstract boolean intersects(Point point)
Checks for an intersection with this shape and the specified point.


intersects

public abstract boolean intersects(Segment segment)
Checks for an intersection with this shape and the specified segment.


intersects

public abstract boolean intersects(Circle circle)
Checks for an intersection with this shape and the specified circle.


intersects

public abstract boolean intersects(Capsule capsule)
Checks for an intersection with this shape and the specified capsule.


intersects

public abstract boolean intersects(Polygon polygon)
Checks for an intersection with this shape and the specified polygon.


intersects

public abstract boolean intersects(Compound compound)
Checks for an intersection with this shape and the specified compound.


intersects

public boolean intersects(None none)
Shapes can never intserct none.


getPenetration

public abstract Vector2f getPenetration(Shape shape,
                                        Vector2f result)
Finds the penetration of the specified shape into this one, assuming that they intersect. The penetration vector represents the minimum translation required to separate the two shapes. Uses double-dispatch to invoke the appropriate method specialization.

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

getPenetration

public abstract Vector2f getPenetration(Point point,
                                        Vector2f result)
Finds the penetration of the specified point into this shape.


getPenetration

public abstract Vector2f getPenetration(Segment segment,
                                        Vector2f result)
Finds the penetration of the specified segment into this shape.


getPenetration

public abstract Vector2f getPenetration(Circle circle,
                                        Vector2f result)
Finds the penetration of the specified circle into this shape.


getPenetration

public abstract Vector2f getPenetration(Capsule capsule,
                                        Vector2f result)
Finds the penetration of the specified capsule into this shape.


getPenetration

public abstract Vector2f getPenetration(Polygon polygon,
                                        Vector2f result)
Finds the penetration of the specified polygon into this shape.


getPenetration

public abstract Vector2f getPenetration(Compound compound,
                                        Vector2f result)
Finds the penetration of the specified compound into this shape.


getPenetration

public Vector2f getPenetration(None none,
                               Vector2f result)
Shapes never penetrate none.


draw

public abstract void draw(boolean outline)
Draws this shape in immediate mode.

Parameters:
outline - if true, draw the outline of the shape; otherwise, the solid form.

createConfig

public abstract ShapeConfig createConfig()
Creates a config corresponding to this shape.


updateClosest

protected static Vector2f updateClosest(Vector2f origin,
                                        Vector2f result,
                                        Vector2f closest)
Updates the value of the closest point and returns a new result vector reference.


intersects

protected static boolean intersects(Vector2f start,
                                    Vector2f end,
                                    float radius,
                                    Vector2f origin,
                                    Vector2f terminus)
Determines whether the capsule from start to end with the specified radius intersects the line segment with the supplied origin and terminus.


intersects

protected static boolean intersects(Vector2f center,
                                    float radius,
                                    Vector2f start,
                                    Vector2f end)
Determines whether the line segment from start to end intersects the circle with the given center and radius.


nearestPointOnSegment

protected static void nearestPointOnSegment(Vector2f start,
                                            Vector2f end,
                                            Vector2f point,
                                            Vector2f result)
Finds the nearest point on the line segment from start to end to a point point and stores it in result.


getOutsideLinePenetration

protected static void getOutsideLinePenetration(Vector2f start,
                                                Vector2f end,
                                                float radius,
                                                Vector2f point,
                                                Vector2f result)

getMinMinkowskyDifference

protected static Vector2f getMinMinkowskyDifference(Vector2f[] A,
                                                    Vector2f[] B,
                                                    float radius,
                                                    Vector2f minDistance)
Calculates the minimum distance to the origin for the A polygon edges in the convex hull of the Minkowski difference of the A and B polygons.