ewe.fx
Class Polygon

java.lang.Object
  extended byewe.fx.Polygon
All Implemented Interfaces:
Area

public class Polygon
extends Object
implements Area


Field Summary
protected  Rect bounds
           
 int numPoints
           
 int[] xPoints
           
 int[] yPoints
           
 
Constructor Summary
Polygon(int[] xPoints, int[] yPoints, int numPoints)
           
Polygon(Polygon other, int dx, int dy)
          Create a new Polygon which is a (possibly) translated version of the original.
 
Method Summary
 void draw(Graphics g, int x, int y, boolean fill)
          Draw the polygon onto a Graphics object.
 Polygon getCopy()
           
 Rect getRect(Rect dest)
          Get the bounding rectangle of the area.
 boolean intersects(Area other)
          See if this Area intersects another.
 boolean isIn(int x, int y)
          Check if the point is in the area.
 Image toImage()
          Convert this Polygon to a black and white Image which fits exactly around the bounding Rect for the polygon.
 Mask toMask()
          Convert this Polygon to a Mask which fits exactly around the bounding Rect for the polygon.
 Polygon translate(Polygon other, int dx, int dy)
          Turn this polygon into a translation of the other polygon, by the specified dx and dy values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

xPoints

public int[] xPoints

yPoints

public int[] yPoints

numPoints

public int numPoints

bounds

protected Rect bounds
Constructor Detail

Polygon

public Polygon(int[] xPoints,
               int[] yPoints,
               int numPoints)

Polygon

public Polygon(Polygon other,
               int dx,
               int dy)
Create a new Polygon which is a (possibly) translated version of the original. Note that this keeps a reference to the original polygon.

Method Detail

getCopy

public Polygon getCopy()

getRect

public Rect getRect(Rect dest)
Description copied from interface: Area
Get the bounding rectangle of the area.

Specified by:
getRect in interface Area
Parameters:
dest - an optional destination Rect.
Returns:
The dest Rect or a newly created Rect if dest is null.

isIn

public boolean isIn(int x,
                    int y)
Description copied from interface: Area
Check if the point is in the area.

Specified by:
isIn in interface Area

intersects

public boolean intersects(Area other)
Description copied from interface: Area
See if this Area intersects another. This intersection is not necessarily an intersection of the bounding rectangles.

Specified by:
intersects in interface Area

translate

public Polygon translate(Polygon other,
                         int dx,
                         int dy)
Turn this polygon into a translation of the other polygon, by the specified dx and dy values. This is efficient to call multiple times - if the polygon is the same as the last one AND dx and dy are the same as the last translation, this polygon is unchanged.

Parameters:
other - The other polygon.
dx - The x translation.
dy - The y translation.
Returns:
this polygon after translation.

draw

public void draw(Graphics g,
                 int x,
                 int y,
                 boolean fill)
Draw the polygon onto a Graphics object. You should set the pen and brush first.


toImage

public Image toImage()
Convert this Polygon to a black and white Image which fits exactly around the bounding Rect for the polygon.


toMask

public Mask toMask()
Convert this Polygon to a Mask which fits exactly around the bounding Rect for the polygon.