import java.awt.*;

public class Plane3D {
  
  public final static int FRACBITS = 12 ;
  protected float c[];

  ///////////////////////// CONSTRUCTORS ///////////////////

  /**
   * 
   */
  public Plane3D( float aa, float bb, float cc, float dd ) {
    c = new float[4];
    c[0] = aa;     c[1] = bb;     c[2] = cc;     c[3] = dd; 
  }
  

  
  ////////////////////////// METHODS //////////////////// 

  public float dot( Vertex3D v ) {
    float sum = 0;
    if( isNotZero( v.getCoord(3) ) ) {
       for( int i=0; i<=3; i++ ) {
	sum += v.getCoord(i) * c[i] / v.getCoord(3);
      }
    } else { 
	//SINCE CLIPPING IS DONE IN VIEWING COORDS=>W=1, THESE FUNCTIONS UNNECESSARY. LET THEM BE HOWEVER.
	if( isPosZero( v.getCoord(3) ) ) {
	    for( int i=0; i<=3; i++ ) {
		sum += v.getCoord(i) * c[i];
	    }
	} 
	else {
	    if( isNegZero( v.getCoord(3) ) ) {
		for( int i=0; i<=3; i++ ) {
		    sum += (-v.getCoord(i)) * c[i];
		}
	    } 
	}
    }
    return sum;
  }

   
  public void print() {
      System.out.println(" A= " + c[0]+ " B= " + c[1] +  " C= " + c[2] +  " D= " + c[3] );  
  }

  protected boolean isNotZero( float f ) {
    if ( Math.abs(f) >= (1>>FRACBITS) ) return true; else return false;
  }
  protected boolean isPosZero( float f ) {
    if ( (f>0)&&( Math.abs(f) < (1>>FRACBITS)) ) return true;
    else return false;
  }
  protected boolean isNegZero( float f ) {
    if ( (f<0)&&( Math.abs(f) < (1>>FRACBITS)) ) return true;
    else return false;
  }

}//PLANE3D

