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.
-
animator
- The thread used to perform the animation
-
band
- A boolean that indicates if the current yellow region is a band.
-
bestLength
- The length of the longest distance so far.
-
bestV1
- The point on the green polygon of the longest distance so far.
-
bestV2
- The point on the red polygon of the longest distance so far.
-
comment
-
-
currentRegBase
- The index on the red polygon of the current yellow region during the
algorithm.
-
currentRegion
- A Polygon used to draw the current yellow region
-
currentV1
- An index that indicates the current point of the green polygon during
the algorithm.
-
currentV2
- The point on the red polygon of current distance in the algorithm.
-
nextStep
- The step of the algorithm to execute at the next frame of animation
or when the user clicks on the step button.
-
offDimension
-
-
offGraphics
-
-
offImage
-
-
poly1
-
-
poly2
- Our two polygons.
-
trigo
- A boolean that tell the algortihm in which direction the yellow
band should move to find the next vertex of the green polygon.
-
PolyArea(TextField)
- This constructor creates the two polygons and resets the algorithm
variables.
-
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.
-
makeRegion()
- This method is called in the algorithm to make the new
yellow polygon that corresponds to the sweeping yellow
region.
-
makeV2()
- This method creates the new end of the current smallest distance
that's on the red polygon.
-
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.
-
run()
- The run method is called by the virtual machine to perform the
automated animation of the algorithm.
-
stepAlgo()
- This method performs a step in the algorithm.
-
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.
offDimension
Dimension offDimension
offImage
Image offImage
offGraphics
Graphics offGraphics
comment
TextField comment
animator
public Thread animator
- The thread used to perform the animation
poly1
FConvexPoly poly1
poly2
FConvexPoly poly2
- Our two polygons.
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.
currentV1
int currentV1
- An index that indicates the current point of the green polygon during
the algorithm.
bestV1
FPoint bestV1
- The point on the green polygon of the longest distance so far.
bestV2
FPoint bestV2
- The point on the red polygon of the longest distance so far.
currentV2
FPoint currentV2
- The point on the red polygon of current distance in the algorithm.
bestLength
double bestLength
- The length of the longest distance so far.
currentRegBase
int currentRegBase
- The index on the red polygon of the current yellow region during the
algorithm.
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).
currentRegion
Polygon currentRegion
- A Polygon used to draw the current yellow region
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.
PolyArea
public PolyArea(TextField comment)
- This constructor creates the two polygons and resets the algorithm
variables.
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
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.
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
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
makeRegion
void makeRegion()
- This method is called in the algorithm to make the new
yellow polygon that corresponds to the sweeping yellow
region.
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.
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.