vooga.physicsEngine.geometry.shapes
Class ShapeFactory

java.lang.Object
  extended by vooga.physicsEngine.geometry.shapes.ShapeFactory

public class ShapeFactory
extends java.lang.Object

Factory class that creates new instances of various kinds of shapes. Although one can create the shapes directly using Shape constructors, this can facilitate the creation of simple shapes such as squares, rectangles. Furthermore, one can use this to generate a bounding approximation for a complex shape (for example, one may take an image of a car and use this to generate a simpler Polygon that contains the car).

Author:
Peng Shi

Constructor Summary
ShapeFactory()
           
 
Method Summary
static java.awt.Shape getJavaShapeFromShape(Shape shape)
          Create a JavaShape object from a Shape object.
static java.awt.Shape getShapeFromImage(java.awt.image.BufferedImage image, int offsetx, int offsety)
          Creates a polygonal approximation of a shape from an image.
static JavaShape JavaCircle(double radius)
          Create a circle with given radius, implemented using Java.awt.Shape.
static JavaShape JavaRectangle(double width, double height)
          Create a rectangle of given width and height, using the java.awt.Shape framework for the backend.
static Shape makeRectangle(double width, double height)
          Creates a rectangle (Polygon) of given width and height.
static Shape makeRectangleWithCentroid(double width, double height, double xOffset, double yOffset)
          Create a rectangle (Polygon) of given width and height and coordinate of top left corner.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShapeFactory

public ShapeFactory()
Method Detail

makeRectangle

public static Shape makeRectangle(double width,
                                  double height)
Creates a rectangle (Polygon) of given width and height.

Parameters:
width -
height -
Returns:

makeRectangleWithCentroid

public static Shape makeRectangleWithCentroid(double width,
                                              double height,
                                              double xOffset,
                                              double yOffset)
Create a rectangle (Polygon) of given width and height and coordinate of top left corner. This allows one to specify the centroid of the rectangle.

Parameters:
width -
height -
xOffset -
yOffset -
Returns:

JavaCircle

public static JavaShape JavaCircle(double radius)
Create a circle with given radius, implemented using Java.awt.Shape.

Parameters:
radius -
Returns:

JavaRectangle

public static JavaShape JavaRectangle(double width,
                                      double height)
Create a rectangle of given width and height, using the java.awt.Shape framework for the backend.

Parameters:
width -
height -
Returns:

getJavaShapeFromShape

public static java.awt.Shape getJavaShapeFromShape(Shape shape)
Create a JavaShape object from a Shape object. This involves rendering the Shape and obtaining the java.awt.Shape information from the image.

Parameters:
shape -
Returns:

getShapeFromImage

public static java.awt.Shape getShapeFromImage(java.awt.image.BufferedImage image,
                                               int offsetx,
                                               int offsety)
Creates a polygonal approximation of a shape from an image. This is used to initialize the Shape of a PhysicalParameters or GeometricParameters object. Create a convex outline around the given image. If given image defines transparent region, then the outline will trace a convex polygon around that edge. Otherwise, it will simply create a rectangular region around the image. Created by R. Duvall

Parameters:
image -
Returns: