/* Generated By:JJTree: Do not edit this line. ASTPolygon.java */

public class ASTPolygon extends SimpleNode {
  String name = "polygon";
  public ASTPolygon(int id) {
    super(id);
  }

  public ASTPolygon(drawphase3 p, int id) {
    super(p, id);
  }
  
  public String generate(String colour, int brushSize, int offsetX, int offsetY, int scaleH, int scaleV)
  {
  	String temp = "";
  	int[] coords = new int[10];
  	int coordNumber = 0;
  	
  	//Generates the coodrinates for a rectangle and puts them into an array.
  	if (jjtGetNumChildren() == 4)
  	{
  		coords[0] = ((ASTInt) jjtGetChild(0)).val;
  		coords[1] = ((ASTInt) jjtGetChild(3)).val;
  		coords[2] = ((ASTInt) jjtGetChild(0)).val;
  		coords[3] = ((ASTInt) jjtGetChild(1)).val;
  		coords[4] = ((ASTInt) jjtGetChild(2)).val;
  		coords[5] = ((ASTInt) jjtGetChild(1)).val;
  		coords[6] = ((ASTInt) jjtGetChild(2)).val;
  	    coords[7] = ((ASTInt) jjtGetChild(3)).val;
  	    coords[8] = ((ASTInt) jjtGetChild(0)).val;
  	    coords[9] = ((ASTInt) jjtGetChild(3)).val;  	    
  	}
  	
  	//Generates the coodrinates for a square and puts them into an array.
  	else if (jjtGetNumChildren() == 3)
  	{  	      	   
  	    int	lastPoint = ((ASTInt) jjtGetChild(1)).val + (((ASTInt) jjtGetChild(2)).val - ((ASTInt) jjtGetChild(0)).val);
  	   
  	    coords[0] = ((ASTInt) jjtGetChild(0)).val;
  		coords[1] = lastPoint;
  		coords[2] = ((ASTInt) jjtGetChild(0)).val;
  		coords[3] = ((ASTInt) jjtGetChild(1)).val;
  		coords[4] = ((ASTInt) jjtGetChild(2)).val;
  		coords[5] = ((ASTInt) jjtGetChild(1)).val;
  		coords[6] = ((ASTInt) jjtGetChild(2)).val;
  	    coords[7] = lastPoint;
  	    coords[8] = ((ASTInt) jjtGetChild(0)).val;
  	    coords[9] = lastPoint;  	    
  	}
  	
  	//Sets the number of coords for a triangle.  	
  	else if (jjtGetNumChildren() == 6)
  	{
  	   coordNumber = 6;
  	}
  	
  	//sets the number of coords for a polygon.
  	else
  	{
  	   coordNumber = jjtGetNumChildren();
  	}
  	
  	//creates out the SVG code for rectangles and squares.
    if(jjtGetNumChildren() == 3 || jjtGetNumChildren() == 4)
    {  	  
  	  //Makes each line in the polygon.
  	  for (int i = 0; i < 8; i = i+2)
   	  {   	    
        temp += ASTLine.makeLine(coords[i], coords[i+1], coords[i+2], coords[i+3], colour, brushSize, offsetX, offsetY, scaleH, scaleV);
   	  }     
 	}
 	
 	//Creates the SVG code for triangles and polygons.
 	else if(jjtGetNumChildren() > 5)
 	{ 	  
 	   //Makes each line in the polygon.
 	   for (int i = 0; i < coordNumber; i = i+2)
   	   {
   	    int last = i+2;
   	    if(last >= jjtGetNumChildren())
   	    {
   	       last = 0;
   	    }
   	       	    
        temp += ASTLine.makeLine(((ASTInt) jjtGetChild(i)).val, ((ASTInt) jjtGetChild(i+1)).val, ((ASTInt) jjtGetChild(last)).val, ((ASTInt) jjtGetChild(last+1)).val, colour, brushSize, offsetX, offsetY, scaleH, scaleV);
   	  }
 	} 
 	//returns the code.	
 	return temp;
  }
  
  public String getName()
  {
     return name;
  }

}
