/*
 * PolyGen.java
 *
 * Created on April 15, 2003, 9:58 PM
 */
import java.awt.Polygon;
/**
 * This class generates polygons used to denote radars
 * and targets
 * @author  Nick Cole
 */
public class PolyGen {
    
    /** Creates a new instance of PolyGen */
    public PolyGen() {
    }
    
    /* Generates a polygon representation of a target 
     * @param thisSL a ScreenLoc of the target
     * @param height an int of the height
     * @param width an int of the width
     */
    public Polygon makeTargetPoly( ScreenLoc thisSL, int height, int width ){
        Polygon tempPoly;
        int[] xPoints = new int[3];         //polys are created from pairs
        int[] yPoints = new int[3];         //of x/y coordinates
        
        //create the individual vertices
        xPoints[0] = thisSL.GetX();
        yPoints[0] = thisSL.GetY() - height/2;
        xPoints[1] = thisSL.GetX() + width;
        yPoints[1] = yPoints[2] = thisSL.GetY()+ height/2;;
        xPoints[2] = thisSL.GetX() - width;
        
        //now build the poly and return it
        tempPoly = new Polygon( xPoints, yPoints, 3 );
               
        return tempPoly;
    }
    
    /* Generates an  inversepolygon representation of a target 
     * @param thisSL a ScreenLoc of the target
     * @param height an int of the height
     * @param width an int of the width
     */
    public Polygon makeTargetInvPoly( ScreenLoc thisSL, int height,
        int width, int offSet ){
        Polygon tempPoly;
        int[] xPoints = new int[3];         //polys are created from pairs
        int[] yPoints = new int[3];         //of x/y coordinates
        
        //create the individual vertices
        xPoints[0] = thisSL.GetX();
        yPoints[0] = thisSL.GetY()+ height - offSet;
        xPoints[1] = thisSL.GetX() + width;
        yPoints[1] = yPoints[2] = thisSL.GetY() - height - offSet;
        xPoints[2] = thisSL.GetX() - width;
        
        //now build the poly and return it
        tempPoly = new Polygon( xPoints, yPoints, 3 );
               
        return tempPoly;
    }
    
    /* Generates a polygon representation of a radar 
     * @param thisSL a ScreenLoc of the radar
     * @param height an int of the height
     * @param width an int of the width
     */
    public Polygon makeRadarPoly( ScreenLoc thisSL, int height, int width ){
        Polygon tempPoly;
        int[] xPoints = new int[9];         //polys are created from pairs
        int[] yPoints = new int[9];         //of x/y coordinates
        int innerSqr = (int)(height * 0.5 );
        int innerWdth = (int)(width * 0.75);
        
        //get the left half's verts
        xPoints[0] = thisSL.GetX();
        yPoints[0] = thisSL.GetY() - height;
        xPoints[1] = thisSL.GetX() - innerWdth;
        yPoints[1] = thisSL.GetY() - innerSqr;
        xPoints[2] = thisSL.GetX() - innerWdth;
        yPoints[2] = thisSL.GetY() + innerSqr;
        xPoints[3] = thisSL.GetX() - width;
        yPoints[3] = thisSL.GetY() + innerSqr;
        xPoints[4] = thisSL.GetX() - width;
        yPoints[4] = thisSL.GetY() + height;

        //now, do the right half
        xPoints[5] = thisSL.GetX() + width;
        yPoints[5] = thisSL.GetY() + height;
        xPoints[6] = thisSL.GetX() + width;
        yPoints[6] = thisSL.GetY() + innerSqr;
        xPoints[7] = thisSL.GetX() + innerWdth;
        yPoints[7] = thisSL.GetY() + innerSqr;
        xPoints[8] = thisSL.GetX() + innerWdth;
        yPoints[8] = thisSL.GetY() - innerSqr;

        //create the poly and return
        tempPoly = new Polygon( xPoints, yPoints, 9 );        
        
        return tempPoly;
    }
    
    /* Makes a carrier polygon (which is just a rectangle )
     * @param thisSL ScreenLoc where the carrier will be drawn
     * @param width an int which determines width of block
     * @param height an in which determines height of block
     */
    public Polygon makeCarrierPoly( ScreenLoc thisSL, int width, int height ){
        Polygon tempPoly;
        int[] xPoints = new int[4];         //polys are created from pairs
        int[] yPoints = new int[4];         //of x/y coordinates
        
        //get the left half's verts
        xPoints[0] = thisSL.GetX() + width;
        yPoints[0] = thisSL.GetY() + height;
        xPoints[1] = thisSL.GetX() + width;
        yPoints[1] = thisSL.GetY() - height;
        xPoints[2] = thisSL.GetX() - width;
        yPoints[2] = thisSL.GetY() - height;
        xPoints[3] = thisSL.GetX() - width;
        yPoints[3] = thisSL.GetY() + height;
        
        //create the poly and return
        tempPoly = new Polygon( xPoints, yPoints, 4 );       
        return tempPoly;
    }
    
}
