/* 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(drawphase2 p, int id) {
    super(p, id);
  }
  
  public String generate(String colour, int brushSize, int offsetX, int offsetY)
  {
  	String temp;
  	int centerX, centerY, rX, rY;
  	//Works out the center point and Radii for an ellpise and then calculates offsets.
  	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;
  		}
  		else
  		{
  			rX = (((ASTInt) jjtGetChild(0)).val - ((ASTInt) jjtGetChild(2)).val)/2;
  		}
  		
  		if(((ASTInt) jjtGetChild(1)).val > ((ASTInt) jjtGetChild(3)).val)
  		{  		
  			rY = (((ASTInt) jjtGetChild(1)).val - ((ASTInt) jjtGetChild(3)).val)/2;
  		}
  		else
  		{
  			rY = (((ASTInt) jjtGetChild(3)).val - ((ASTInt) jjtGetChild(1)).val)/2;
  		}
  		centerX += offsetX;
  		centerY = centerY - offsetY;
    }
    //Works out the center point and radii of a circle and then calculates offsets.
    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;
  		}
  		else
  		{
  			rX = (((ASTInt) jjtGetChild(0)).val - ((ASTInt) jjtGetChild(2)).val)/2;
  		}
    	rY = rX;
    	
    	centerX += offsetX;
  		centerY = centerY + offsetY;
    }        
    
    //returns the 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;
  }
}
