javalib.worldimages
Class PolygonImage

java.lang.Object
  extended by javalib.worldimages.AImage
      extended by javalib.worldimages.ColoredImage
          extended by javalib.worldimages.PolygonImage
All Implemented Interfaces:
Drawable, WorldImage, tester.ISame<WorldImage>

 class PolygonImage
extends ColoredImage

The class to represent filled Polygon images drawn by the world when drawing on its Canvas.

Since:
Dec 24 2012
Author:
adapted by Stephen Bloch from Viera Proulx's TriangleImage class

Field Summary
protected  Polygon poly
           
protected  int[] xcoord
           
protected  int[] ycoord
           
 
Fields inherited from class javalib.worldimages.ColoredImage
defaultColor
 
Fields inherited from interface javalib.worldimages.WorldImage
LOOKS_SAME
 
Constructor Summary
protected PolygonImage(Color color, Mode mode, int[] xcoord, int[] ycoord)
          A protected constructor that takes in arrays of coordinates.
protected PolygonImage(Color color, Mode mode, Posn... points)
          A full constructor for this Polygon image.
 
Method Summary
 void draw(Graphics2D g)
          Draw this image in the provided Graphics2D context.
 boolean equals(Object o)
          Is this PolygonImage same as the given object?
 int getBottom()
          Produce the bottom of the bounding box.
 int getLeft()
          Getter for the left edge of the bounding box.
 int getRight()
          Produce the bottom of the bounding box.
 int getTop()
          Getter for the top of the bounding box.
 int hashCode()
          The hashCode to match the equals method
(package private) static PolygonImage make(Color color, Mode mode, Posn... points)
           
(package private) static PolygonImage make(Color color, Posn... points)
           
(package private) static PolygonImage make(IColor color, Mode mode, Posn... points)
           
(package private) static PolygonImage make(IColor color, Posn... points)
           
(package private) static PolygonImage make(Mode mode, Posn... points)
           
(package private) static PolygonImage make(Posn... points)
           
 ColoredImage replaceColor(Color newColor)
          Functional setter for the color field Define this in all concrete subclasses.
 ColoredImage replaceMode(Mode newMode)
          Functional setter for the mode field Define this in all concrete subclasses.
 String toIndentedString(String indent)
          Produce a String that represents this image, indented by the given indent.
 
Methods inherited from class javalib.worldimages.ColoredImage
getColor, getMode, replaceColor
 
Methods inherited from class javalib.worldimages.AImage
above, aboveCentered, beside, besideCentered, build, build, centerMoved, centerMoved, cornerString, cropped, frozen, getCenter, getHeight, getPixelColor, getWidth, isApplet, makeCenteredCircle, makeCenteredCircle, makeCenteredCircle, makeCenteredCircle, makeCenteredCircle, makeCenteredCircle, makeCircle, makeCircle, makeCircle, makeCircle, makeCircle, makeCircle, makeEllipse, makeEllipse, makeEllipse, makeEllipse, makeEllipse, makeEllipse, makeFromFile, makeFromURL, makeImage, makeLine, makeLine, makeLine, makePolygon, makePolygon, makePolygon, makePolygon, makePolygon, makePolygon, makeRectangle, makeRectangle, makeRectangle, makeRectangle, makeRectangle, makeRectangle, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, map, map, moved, moved, normalized, overlay, overlayCentered, overlayImages, overlayXY, place, rotate, rotated, rotated, rotatedAround, rotatedAround, rotatedInPlace, rotatedInPlace, same, sameClass, save, scaled, scaled, show, toString, xReflected, yReflected
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

poly

protected Polygon poly

xcoord

protected int[] xcoord

ycoord

protected int[] ycoord
Constructor Detail

PolygonImage

protected PolygonImage(Color color,
                       Mode mode,
                       int[] xcoord,
                       int[] ycoord)
A protected constructor that takes in arrays of coordinates. Assumes both arrays are the same size, and that neither will be mutated after the call.

Parameters:
color -
xcoord - an array of the x coordinates of the vertices
ycoord - an array of the y coordinates of the vertices

PolygonImage

protected PolygonImage(Color color,
                       Mode mode,
                       Posn... points)
A full constructor for this Polygon image.

Parameters:
color - the color for this image
mode - either FILLED or OUTLINED
points - the vertices of this Polygon
Method Detail

draw

public void draw(Graphics2D g)
Description copied from interface: WorldImage
Draw this image in the provided Graphics2D context.

Parameters:
g - the provided Graphics2D context

equals

public boolean equals(Object o)
Is this PolygonImage same as the given object?

Specified by:
equals in interface WorldImage
Overrides:
equals in class ColoredImage
Parameters:
o - the object to compare with this
Returns:
true iff the images are isomorphic expression trees, with equal fields.

getBottom

public int getBottom()
Description copied from interface: WorldImage
Produce the bottom of the bounding box.

Returns:
the y coordinate of the bottom of the bounding box

getLeft

public int getLeft()
Description copied from class: AImage
Getter for the left edge of the bounding box.

Specified by:
getLeft in interface WorldImage
Overrides:
getLeft in class AImage
Returns:
the minimum x coordinate of the image

getRight

public int getRight()
Description copied from interface: WorldImage
Produce the bottom of the bounding box.

Returns:
the x coordinate of the right edge of the bounding box

getTop

public int getTop()
Description copied from class: AImage
Getter for the top of the bounding box.

Specified by:
getTop in interface WorldImage
Overrides:
getTop in class AImage
Returns:
the minimum y coordinate of the image

hashCode

public int hashCode()
The hashCode to match the equals method

Specified by:
hashCode in interface WorldImage
Overrides:
hashCode in class ColoredImage

make

static PolygonImage make(Color color,
                         Mode mode,
                         Posn... points)

make

static PolygonImage make(Color color,
                         Posn... points)

make

static PolygonImage make(IColor color,
                         Mode mode,
                         Posn... points)

make

static PolygonImage make(IColor color,
                         Posn... points)

make

static PolygonImage make(Mode mode,
                         Posn... points)

make

static PolygonImage make(Posn... points)

replaceColor

public ColoredImage replaceColor(Color newColor)
Description copied from class: ColoredImage
Functional setter for the color field Define this in all concrete subclasses. (I HATE this! Every one of these definitions will consist of calling the constructor with exactly the same fields but newColor plugged in as the color. Why do I have to write that over and over in every concrete subclass?)

Specified by:
replaceColor in class ColoredImage
Returns:
a new image just like this one but with a different color

replaceMode

public ColoredImage replaceMode(Mode newMode)
Description copied from class: ColoredImage
Functional setter for the mode field Define this in all concrete subclasses.

Specified by:
replaceMode in class ColoredImage
Returns:
a new image just like this one but with a different mode

toIndentedString

public String toIndentedString(String indent)
Description copied from interface: WorldImage
Produce a String that represents this image, indented by the given indent.

Define this in all concrete subclasses.

Convention: The result of toIndentedString() will neither begin nor end with a newline; the specified indent will immediately follow each internal newline.

Parameters:
indent - the given prefix representing the desired indentation
Returns:
the String representation of this image