Class PolyArea

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----PolyArea

class PolyArea
extends Canvas
implements Runnable
The PolyArea class defines an area that will hold our two polygons. It will first create them by catching mouse clicks events and adding the points to the polygons, and it will then run the algorithm on the polygons.


Variable Index

 o animator
The thread used to perform the animation
 o band
A boolean that indicates if the current yellow region is a band.
 o bestLength
The length of the longest distance so far.
 o bestV1
The point on the green polygon of the longest distance so far.
 o bestV2
The point on the red polygon of the longest distance so far.
 o comment
 o currentRegBase
The index on the red polygon of the current yellow region during the algorithm.
 o currentRegion
A Polygon used to draw the current yellow region
 o currentV1
An index that indicates the current point of the green polygon during the algorithm.
 o currentV2
The point on the red polygon of current distance in the algorithm.
 o nextStep
The step of the algorithm to execute at the next frame of animation or when the user clicks on the step button.
 o offDimension
 o offGraphics
 o offImage
 o poly1
 o poly2
Our two polygons.
 o trigo
A boolean that tell the algortihm in which direction the yellow band should move to find the next vertex of the green polygon.

Constructor Index

 o PolyArea(TextField)
This constructor creates the two polygons and resets the algorithm variables.

Method Index

 o handleEvent(Event)
This handles the mouse clicks, adds the points to the green then the red polygon and starts the algorithm when both are closed.
 o makeRegion()
This method is called in the algorithm to make the new yellow polygon that corresponds to the sweeping yellow region.
 o makeV2()
This method creates the new end of the current smallest distance that's on the red polygon.
 o paint(Graphics)
The paint method draws the current state of the algorithm in the given Graphics, including the two polygons, the yellow region and the important points.
 o run()
The run method is called by the virtual machine to perform the automated animation of the algorithm.
 o stepAlgo()
This method performs a step in the algorithm.
 o update(Graphics)
When called by the AWT, the update method clears its offscreen buffer, calls paint() to draw in it, and then copies the buffer to the screen.

Variables

 o offDimension
 Dimension offDimension
 o offImage
 Image offImage
 o offGraphics
 Graphics offGraphics
 o comment
 TextField comment
 o animator
 public Thread animator
The thread used to perform the animation

 o poly1
 FConvexPoly poly1
 o poly2
 FConvexPoly poly2
Our two polygons.

 o nextStep
 int nextStep
The step of the algorithm to execute at the next frame of animation or when the user clicks on the step button.

 o currentV1
 int currentV1
An index that indicates the current point of the green polygon during the algorithm.

 o bestV1
 FPoint bestV1
The point on the green polygon of the longest distance so far.

 o bestV2
 FPoint bestV2
The point on the red polygon of the longest distance so far.

 o currentV2
 FPoint currentV2
The point on the red polygon of current distance in the algorithm.

 o bestLength
 double bestLength
The length of the longest distance so far.

 o currentRegBase
 int currentRegBase
The index on the red polygon of the current yellow region during the algorithm.

 o band
 boolean band
A boolean that indicates if the current yellow region is a band. If it is a band, it is an infinite region perpendicular to an edge of the red polygon. If not, it is a sector between the two bands adjacent to the current vertex (currentRegBase).

 o currentRegion
 Polygon currentRegion
A Polygon used to draw the current yellow region

 o trigo
 boolean trigo
A boolean that tell the algortihm in which direction the yellow band should move to find the next vertex of the green polygon.

Constructors

 o PolyArea
 public PolyArea(TextField comment)
This constructor creates the two polygons and resets the algorithm variables.

Methods

 o handleEvent
 public boolean handleEvent(Event e)
This handles the mouse clicks, adds the points to the green then the red polygon and starts the algorithm when both are closed.

Overrides:
handleEvent in class Component
 o stepAlgo
 public void stepAlgo()
This method performs a step in the algorithm. It is called either by the applet when the "step" button is clicked, or by the animator thread if this one is running.

 o paint
 public void paint(Graphics g)
The paint method draws the current state of the algorithm in the given Graphics, including the two polygons, the yellow region and the important points.

Overrides:
paint in class Canvas
 o update
 public void update(Graphics g)
When called by the AWT, the update method clears its offscreen buffer, calls paint() to draw in it, and then copies the buffer to the screen.

Overrides:
update in class Component
 o makeRegion
 void makeRegion()
This method is called in the algorithm to make the new yellow polygon that corresponds to the sweeping yellow region.

 o makeV2
 void makeV2()
This method creates the new end of the current smallest distance that's on the red polygon. If the current vertex of the green polygon is in a yellow sector, it corresponds to the current vertex of the red polygon. If it is in a band, it is the foot of the perpendicular to the current edge of the red polygon that goes through the vertex.

 o run
 public void run()
The run method is called by the virtual machine to perform the automated animation of the algorithm. It calls the stepAlgo() method three times per second to animate the algorithme.