
/**
 * This entire class is borrowed from McMillan's lecture notes, with
 * some changes from integers to floating point.
 */
public class EdgeEqn {

    public final static int FRACBITS = 12;
    public double A, B, C;
    public int flag;            // used to compute bounding box
    
    public EdgeEqn(Vertex2D v0, Vertex2D v1) {
	double a = v0.y - v1.y;
	double b = v1.x - v0.x;
	double c = -0.5f*(a*(v0.x + v1.x) + b*(v0.y + v1.y));
	A = (a * (1<<FRACBITS));
	B = (b * (1<<FRACBITS));
	C = (c * (1<<FRACBITS));
	flag = 0;
	if (A >= 0) flag += 8;
	if (B >= 0) flag += 1;
    }
    
    public void flip() {
	A = -A;
	B = -B;
	C = -C;
    }
    
    public int evaluate(int x, int y) {
	return (int)(A*x + B*y + C);
    }
}
