package project2;

//import Drawable;
import java.awt.Color;

public class Vertex2D implements Drawable {
    public float x, y;              // coordinate of vertex
    public int argb;                // color of vertex

  /**
   * This constructor takes in the x,y and color
   * values for creating a point in 2-space with 
   * a specific color. 
   */
      
    public Vertex2D(float xval, float yval, int cval)
       // requires: float xval, float yval, int cval.
       // modifies: x, y, argb
       // effects: is Constructor for Vertex2D, sets pixel values 
       // and color of pixel in public class var.
    {
        x = xval;
        y = yval;
        argb = cval;
    }
    
  /**
   * This method returns the color of the 2D vertex.
   */

    public Color getColor()
    {
        return new Color(argb);
    }
  
  /**
   * This method Draws the vertex on the raster, if the vertex
   * is within the bounds of the raster.
   */
  
    public void Draw(Raster r)
    {
        int ix = (int) (x + 0.5f);
        int iy = (int) (y + 0.5f);
        if ((ix < 0) || (ix >= r.width)) return;
        if ((iy < 0) || (iy >= r.height)) return;
        r.setPixel(argb, ix, iy);
    }
    
  /**
   * This toString method returns the x,y coordinates of the 
   * vertex and its color.
   */

    public String toString()
    {
        return new String(Float.toString(x)+" "+Float.toString(y)+
			  " 0x"+Integer.toHexString(argb));
    }
}
