import java.awt.event.*;
import java.awt.*;

public class QuadMap {

    /**This class does the symmetries of the tiling*/


    public static PolygonWrapper doMap(PolygonWrapper QUAD,int q,PolygonWrapper K0) {
	int q1=q/9;
	int q2=q-9*q1;
	
	if(q1==0) return doMap1(QUAD,q2,K0);

	if(q1==1) {
	    PolygonWrapper K1=doMap1(QUAD,q2,K0);
	    K1=doMap0(QUAD,5,K1);
	    return K1;
	}
	
	if(q1==2) {
	    PolygonWrapper K1=doMap1(QUAD,q2,K0);
	    K1=doMap0(QUAD,6,K1);
	    return K1;
	}
	return null;
    }

    
    public static PolygonWrapper doMap1(PolygonWrapper QUAD,int q,PolygonWrapper K0) {
	if(q<5) return doMap0(QUAD,q,K0);
	
	if(q==5) {
	    PolygonWrapper K1=doMap0(QUAD,1,K0);
	    K1=doMap0(QUAD,3,K1);
	    return K1;
	}
	if(q==6) {
	    PolygonWrapper K1=doMap0(QUAD,2,K0);
	    K1=doMap0(QUAD,3,K1);
	    return K1;
	}
	
	if(q==7) {
	    PolygonWrapper K1=doMap0(QUAD,1,K0);
	    K1=doMap0(QUAD,4,K1);
	    return K1;
	}
	if(q==8) {
	    PolygonWrapper K1=doMap0(QUAD,2,K0);
	    K1=doMap0(QUAD,4,K1);
	    return K1;
	}
	return null;
    }
    
    public static PolygonWrapper doMap0(PolygonWrapper QUAD, int q,PolygonWrapper K0) {
	if(q==0) return K0;
	PolygonWrapper K1=new PolygonWrapper(K0);

	if(q==1) {
	   for(int i=0;i<K0.count;++i) {
	       K1.z[i]=Complex.minus(QUAD.z[1].scale(2),K0.z[i]);
	   }
	   return K1;
	}
	
	if(q==2) {
	   for(int i=0;i<K0.count;++i) {
	       K1.z[i]=Complex.minus(QUAD.z[2].scale(2),K0.z[i]);
	   }
	   return K1;
	}

	if(q==3) {
	   for(int i=0;i<K0.count;++i) {
	       K1.z[i]=Complex.plus(QUAD.z[1].scale(2),K0.z[i]);
	   }
	   return K1;
	}


	if(q==4) {
	   for(int i=0;i<K0.count;++i) {
	       K1.z[i]=Complex.minus(K0.z[i],QUAD.z[1].scale(2));
	   }
	   return K1;
	}
	
	if(q==5) {
	   for(int i=0;i<K0.count;++i) {
	       K1.z[i]=Complex.plus(K0.z[i],QUAD.z[3].scale(2));
	   }
	   return K1;
	}

	if(q==6) {
	   for(int i=0;i<K0.count;++i) {
	       K1.z[i]=Complex.minus(K0.z[i],QUAD.z[3].scale(2));
	   }
	   return K1;
	}
	return null;
    }
    


}


