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

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

  public ASTEllipse(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 centerX, centerY, rX, rY;
  	
  	//Creates the center point and radii for an ellipse. Also calculates offsets 
  	//and scaling.
  	if (jjtGetNumChildren() == 4)
  	{
  		centerX = (((ASTInt) jjtGetChild(0)).val + ((ASTInt) jjtGetChild(2)).val)/2;
  		centerY = (((ASTInt) jjtGetChild(1)).val + ((ASTInt) jjtGetChild(3)).val)/2;
  		if(((ASTInt) jjtGetChild(2)).val > ((ASTInt) jjtGetChild(0)).val)
  		{
  			rX = (((ASTInt) jjtGetChild(2)).val - ((ASTInt) jjtGetChild(0)).val)/2;
  			rX *= scaleH;
  		}
  		else
  		{
  			rX = (((ASTInt) jjtGetChild(0)).val - ((ASTInt) jjtGetChild(2)).val)/2;
  			rX *= scaleH;
  		}  		
  		
  		if(((ASTInt) jjtGetChild(1)).val > ((ASTInt) jjtGetChild(3)).val)
  		{  		
  			rY = (((ASTInt) jjtGetChild(1)).val - ((ASTInt) jjtGetChild(3)).val)/2;
  			rY *= scaleV;
  		}
  		else
  		{
  			rY = (((ASTInt) jjtGetChild(3)).val - ((ASTInt) jjtGetChild(1)).val)/2;
  			rY *= scaleV;
  		}
  		centerX *= scaleH;
  		centerY *= scaleV;
  		centerX += offsetX;
  		centerY += offsetY;
  		
  		//Ensures inverted ellipses don't have negative radii.
  		if(rX < 0)
  		{
  			rX *= -1;
  		}
  		
  		if(rY < 0)
  		{
  			rY *= -1;
  		}
    }
    
    //Creates the center point and radii for a circle. Also calculates offsets 
  	//and scaling.
    else
    {
    	centerX = (((ASTInt) jjtGetChild(0)).val + ((ASTInt) jjtGetChild(2)).val)/2;
    	centerY = ((ASTInt) jjtGetChild(1)).val + ((((ASTInt) jjtGetChild(2)).val - ((ASTInt) jjtGetChild(0)).val)/2);
    	
    	if(((ASTInt) jjtGetChild(2)).val > ((ASTInt) jjtGetChild(0)).val)
  		{
  			rX = (((ASTInt) jjtGetChild(2)).val - ((ASTInt) jjtGetChild(0)).val)/2;
  			rY = rX;
  			rX *= scaleH;
  		}
  		else
  		{
  			rX = (((ASTInt) jjtGetChild(0)).val - ((ASTInt) jjtGetChild(2)).val)/2;
  			rY = rX;
  			rX *= scaleH;
  		}
    	
    	rY *= scaleV;
    	
    	centerX *= scaleH;
  		centerY *= scaleV;
    	centerX += offsetX;
  		centerY += offsetY;
  		
  		//Ensures inverted ellipses don't have negative radii.
  		if(rX < 0)
  		{
  			rX *= -1;
  		}
  		
  		if(rY < 0)
  		{
  			rY *= -1;
  		}
    }   	    
        
    //Returns the necessary SVG code.
    temp = ("<ellipse transform=\"translate(" + centerX + " " + centerY + ")\" rx=\"" + rX + "\" ry=\"" + rY + "\" fill=\"none\" stroke = \"" + colour + "\" stroke-width=\"" + brushSize +"\"  />");
	System.out.println(temp);
	return temp;
    
  }
  
  public String getName()
  {
     return name;
  }
}
