javalib.worldimages
Class LinearImage

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

public class LinearImage
extends AImage

An image which is a translation of another existing image.

Version:
Dec 23, 2012
Author:
Stephen Bloch

Field Summary
 
Fields inherited from interface javalib.worldimages.WorldImage
LOOKS_SAME
 
Constructor Summary
LinearImage(AffineTransform transform, WorldImage base)
          Constructor for objects of class LinearImage
 
Method Summary
 void draw(Graphics2D g)
          Draw this image in the provided Graphics2D context.
 boolean equals(Object other)
          Is this the same as another WorldImage, as expression trees? Define this at every level that has instance variables.
 int getBottom()
          Produce the bottom of the bounding box.
 int getHeight()
          Retrieve the height of the image, in pixels.
 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.
 Posn getTranslation()
          Getter for the translation field.
 int getWidth()
          Retrieve the width of the image, in pixels.
 int getX()
          Getter for the x coordinate of the translation field (just for brevity).
 int getY()
          Getter for the y coordinate of the translation field (just for brevity).
(package private) static WorldImage make(AffineTransform transform, WorldImage base)
          Pseudo-constructor for objects of class LinearImage.
 String toIndentedString(String indent)
          Produce a String that represents this image, indented by the given indent.
 
Methods inherited from class javalib.worldimages.AImage
above, aboveCentered, beside, besideCentered, build, build, centerMoved, centerMoved, cornerString, cropped, frozen, getCenter, getPixelColor, 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, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javalib.worldimages.WorldImage
hashCode
 

Constructor Detail

LinearImage

LinearImage(AffineTransform transform,
            WorldImage base)
Constructor for objects of class LinearImage

Parameters:
base - the image to transform
transform - what to do to it
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 other)
Description copied from interface: WorldImage
Is this the same as another WorldImage, as expression trees? Define this at every level that has instance variables.

Specified by:
equals in interface WorldImage
Overrides:
equals in class AImage
Parameters:
other - 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

getHeight

public int getHeight()
Description copied from class: AImage
Retrieve the height of the image, in pixels.

Specified by:
getHeight in interface WorldImage
Overrides:
getHeight in class AImage
Returns:
an int

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

getTranslation

public Posn getTranslation()
Getter for the translation field.

Returns:
the translation of the given object

getWidth

public int getWidth()
Description copied from class: AImage
Retrieve the width of the image, in pixels.

Specified by:
getWidth in interface WorldImage
Overrides:
getWidth in class AImage
Returns:
an int

getX

public int getX()
Getter for the x coordinate of the translation field (just for brevity).

Returns:
this.translation.getX()

getY

public int getY()
Getter for the y coordinate of the translation field (just for brevity).

Returns:
this.translation.getY()

make

static WorldImage make(AffineTransform transform,
                       WorldImage base)
Pseudo-constructor for objects of class LinearImage.

The main purpose of the pseudo-constructor is to collapse multiple successive linear transforms into one, so we don't get a bunch of deeply-nested LinearImages.

This isn't just an optimization: it affects the calculation of the bounding box. If two or more LinearImages are nested, the bounding box of the outer one is calculated from the four corners of the bounding box of the inner one, which are in turn calculated from the four corners of the bounding box of the inner one's base. The visible effect of this is that when you repeatedly rotate a single image, the accumulated errors cause it to spiral out of control. With LinearImages collapsed, the same could still happen (e.g. if there were a Crop or an Overlay between each pair of LinearImages), but it's much less likely.

Parameters:
base - the image to transform
transform - what to do to it

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