import Drawable;
import java.awt.Color;

// Edge represents two vertices connected by a line. (xLower, yLower) is the vertex
// with the smaller y, and (xUpper, yUpper) is the vertex with the larger y.
// dxPerScan = 1/slope.

public class Edge {

  
  public float yLower, yUpper, xLower, xUpper;
  public float dxPerScan, xIntersect;


  public Edge() {
  }


  public Edge(float y0, float y1, float x0, float x1) {

    if (y0<y1) {
      yLower = y0;
      xLower = x0;
      yUpper = y1;
      xUpper = x1;
    }
    else {
      yLower = y1;
      xLower = x1;
      yUpper = y0;
      xUpper = x0;
    }

    // safe to divide because horizontal edges are never used
    dxPerScan = (xUpper - xLower) / (yUpper - yLower);
    // account for the fact that we start at the ceiling of yLower
    xIntersect = xLower + dxPerScan*((int)(Math.ceil(yLower))-yLower);

  }


  public void updateX() {

    // xnew = xold + 1/slope since y changed by 1
    xIntersect = xIntersect + dxPerScan;
    
  }


  // for debugging purposes

  public void print() {
    
    System.out.println("edge from (" + xLower + ", " + yLower + ") to (" +
		       xUpper + ", " + yUpper + ")");
    System.out.println("     with slope " + (1/dxPerScan));
  }

  
}
