org.newdawn.slick.geom
Class Shape

java.lang.Object
  extended by org.newdawn.slick.geom.Shape
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Curve, Ellipse, Line, MorphShape, Path, Point, Polygon, Rectangle

public abstract class Shape
extends java.lang.Object
implements java.io.Serializable

The description of any 2D shape that can be transformed. The points provided approximate the intent of the shape.

Author:
Mark
See Also:
Serialized Form

Field Summary
protected  float boundingCircleRadius
          Radius of a circle that can completely enclose this shape.
protected  float[] center
          Center point of the polygon.
protected  float maxX
          The right most point of this shape
protected  float maxY
          The bottom most point of this shape
protected  float minX
          The left most point of this shape.
protected  float minY
          The top most point of this shape.
protected  float[] points
          The points representing this polygon.
protected  boolean pointsDirty
          Flag to tell whether points need to be generated
protected  boolean trianglesDirty
          True if the triangles need updating
protected  Triangulator tris
          The triangles that define the shape
protected  float x
          The left most point of this shape.
protected  float y
          The top most point of this shape.
 
Constructor Summary
Shape()
          Shape constructor.
 
Method Summary
protected  void calculateRadius()
          Calculate the radius of a circle that can completely enclose this shape.
protected  void calculateTriangles()
          Calculate the triangles that can fill this shape
protected  void checkPoints()
          Check the dirty flag and create points as necessary.
 boolean closed()
          True if this is a closed shape
 boolean contains(float x, float y)
          Check if this polygon contains the given point
 boolean contains(Shape other)
          Check if the shape passed is entirely contained within this shape.
protected abstract  void createPoints()
          Subclasses implement this to create the points of the shape.
protected  void findCenter()
          Get the center of this polygon.
 float getBoundingCircleRadius()
          Get the radius of a circle that can completely enclose this shape.
 float[] getCenter()
          Get the point closet to the center of all the points in this Shape
 float getCenterX()
          Get the x center of this shape.
 float getCenterY()
          Get the y center of this shape.
 float getHeight()
          Get the height of the shape
 Vector2f getLocation()
          Get the top-left location of this shape.
 float getMaxX()
          Get the right most point of this shape.
 float getMaxY()
          Get the bottom most point of this shape.
 float getMinX()
          Get the left most point of this shape.
 float getMinY()
          Get the top most point of this shape.
 float[] getNormal(int index)
          Get the combine normal of a given point
 float[] getPoint(int index)
          Get a single point in this polygon
 int getPointCount()
          Get the number of points in this polygon
 float[] getPoints()
          Get the points that outline this shape.
 Triangulator getTriangles()
          The triangles that define the filled version of this shape
 float getWidth()
          Get the width of the shape
 float getX()
          Get the x location of the left side of this shape.
 float getY()
          Get the y position of the top of this shape.
 boolean hasVertex(float x, float y)
          Check if a particular location is a vertex of this polygon
 boolean includes(float x, float y)
          Check if the given point is part of the path that forms this shape
 void increaseTriangulation()
          Increase triangulation
 int indexOf(float x, float y)
          Get the index of a given point
 boolean intersects(Shape shape)
          Check if this shape intersects with the shape provided.
 void preCache()
          Cause all internal state to be generated and cached
 Shape prune()
          Prune any required points in this shape
 void setCenterX(float centerX)
          Set the x center of this shape.
 void setCenterY(float centerY)
          Set the y center of this shape.
 void setLocation(float x, float y)
          Set the top-left location of this shape
 void setLocation(Vector2f loc)
          Set the top-left location of this shape
 void setX(float x)
          Set the x position of the left side this shape.
 void setY(float y)
          Set the y position of the top of this shape.
 Shape[] subtract(Shape other)
          Subtract the given shape from this one.
abstract  Shape transform(Transform transform)
          Apply a transformation and return a new shape.
 Shape[] union(Shape other)
          Join this shape with another.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

points

protected float[] points
The points representing this polygon.


center

protected float[] center
Center point of the polygon.


x

protected float x
The left most point of this shape.


y

protected float y
The top most point of this shape.


maxX

protected float maxX
The right most point of this shape


maxY

protected float maxY
The bottom most point of this shape


minX

protected float minX
The left most point of this shape.


minY

protected float minY
The top most point of this shape.


boundingCircleRadius

protected float boundingCircleRadius
Radius of a circle that can completely enclose this shape.


pointsDirty

protected boolean pointsDirty
Flag to tell whether points need to be generated


tris

protected transient Triangulator tris
The triangles that define the shape


trianglesDirty

protected boolean trianglesDirty
True if the triangles need updating

Constructor Detail

Shape

public Shape()
Shape constructor.

Method Detail

setLocation

public void setLocation(float x,
                        float y)
Set the top-left location of this shape

Parameters:
x - The x coordinate of the new location of the shape
y - The y coordinate of the new location of the shape

transform

public abstract Shape transform(Transform transform)
Apply a transformation and return a new shape. This will not alter the current shape but will return the transformed shape.

Parameters:
transform - The transform to be applied
Returns:
The transformed shape.

createPoints

protected abstract void createPoints()
Subclasses implement this to create the points of the shape.


getX

public float getX()
Get the x location of the left side of this shape.

Returns:
The x location of the left side of this shape.

setX

public void setX(float x)
Set the x position of the left side this shape.

Parameters:
x - The new x position of the left side this shape.

setY

public void setY(float y)
Set the y position of the top of this shape.

Parameters:
y - The new y position of the top of this shape.

getY

public float getY()
Get the y position of the top of this shape.

Returns:
The y position of the top of this shape.

getLocation

public Vector2f getLocation()
Get the top-left location of this shape.

Returns:
The coordinate of the top-left of this shape

setLocation

public void setLocation(Vector2f loc)
Set the top-left location of this shape

Parameters:
loc - The new coordinate of the top-left of this shape

getCenterX

public float getCenterX()
Get the x center of this shape.

Returns:
The x center of this shape.

setCenterX

public void setCenterX(float centerX)
Set the x center of this shape.

Parameters:
centerX - The center point to set.

getCenterY

public float getCenterY()
Get the y center of this shape.

Returns:
The y center of this shape.

setCenterY

public void setCenterY(float centerY)
Set the y center of this shape.

Parameters:
centerY - The center point to set.

getMaxX

public float getMaxX()
Get the right most point of this shape.

Returns:
The right most point of this shape.

getMaxY

public float getMaxY()
Get the bottom most point of this shape.

Returns:
The bottom most point of this shape.

getMinX

public float getMinX()
Get the left most point of this shape.

Returns:
The left most point of this shape.

getMinY

public float getMinY()
Get the top most point of this shape.

Returns:
The top most point of this shape.

getBoundingCircleRadius

public float getBoundingCircleRadius()
Get the radius of a circle that can completely enclose this shape.

Returns:
The radius of the circle.

getCenter

public float[] getCenter()
Get the point closet to the center of all the points in this Shape

Returns:
The x,y coordinates of the center.

getPoints

public float[] getPoints()
Get the points that outline this shape. Use CW winding rule

Returns:
an array of x,y points

getPointCount

public int getPointCount()
Get the number of points in this polygon

Returns:
The number of points in this polygon

getPoint

public float[] getPoint(int index)
Get a single point in this polygon

Parameters:
index - The index of the point to retrieve
Returns:
The point's coordinates

getNormal

public float[] getNormal(int index)
Get the combine normal of a given point

Parameters:
index - The index of the point whose normal should be retrieved
Returns:
The combined normal of a given point

contains

public boolean contains(Shape other)
Check if the shape passed is entirely contained within this shape.

Parameters:
other - The other shape to test against this one
Returns:
True if the other shape supplied is entirely contained within this one.

includes

public boolean includes(float x,
                        float y)
Check if the given point is part of the path that forms this shape

Parameters:
x - The x position of the point to check
y - The y position of the point to check
Returns:
True if the point is includes in the path of the polygon

indexOf

public int indexOf(float x,
                   float y)
Get the index of a given point

Parameters:
x - The x coordinate of the point
y - The y coordinate of the point
Returns:
The index of the point or -1 if the point is not part of this shape path

contains

public boolean contains(float x,
                        float y)
Check if this polygon contains the given point

Parameters:
x - The x position of the point to check
y - The y position of the point to check
Returns:
True if the point is contained in the polygon

intersects

public boolean intersects(Shape shape)
Check if this shape intersects with the shape provided.

Parameters:
shape - The shape to check if it intersects with this one.
Returns:
True if the shapes do intersect, false otherwise.

hasVertex

public boolean hasVertex(float x,
                         float y)
Check if a particular location is a vertex of this polygon

Parameters:
x - The x coordinate to check
y - The y coordinate to check
Returns:
True if the cordinates supplied are a vertex of this polygon

findCenter

protected void findCenter()
Get the center of this polygon.


calculateRadius

protected void calculateRadius()
Calculate the radius of a circle that can completely enclose this shape.


calculateTriangles

protected void calculateTriangles()
Calculate the triangles that can fill this shape


increaseTriangulation

public void increaseTriangulation()
Increase triangulation


getTriangles

public Triangulator getTriangles()
The triangles that define the filled version of this shape

Returns:
The triangles that define the

checkPoints

protected final void checkPoints()
Check the dirty flag and create points as necessary.


preCache

public void preCache()
Cause all internal state to be generated and cached


closed

public boolean closed()
True if this is a closed shape

Returns:
True if this is a closed shape

prune

public Shape prune()
Prune any required points in this shape

Returns:
The new shape with points pruned

subtract

public Shape[] subtract(Shape other)
Subtract the given shape from this one. Note that this method only deals with edges, it will not create holes in polygons.

Parameters:
other - The other shape to subtract from this one
Returns:
The newly created set of shapes resulting from the operation

union

public Shape[] union(Shape other)
Join this shape with another.

Parameters:
other - The other shape to join with this one
Returns:
The newly created set of shapes resulting from the operation

getWidth

public float getWidth()
Get the width of the shape

Returns:
The width of the shape

getHeight

public float getHeight()
Get the height of the shape

Returns:
The height of the shape


Copyright © 2006 New Dawn Software. All Rights Reserved.