import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.awt.geom.*; import java.math.*; public class SanityChecks implements Runnable { int halt; Manager M; public SanityChecks() { } public SanityChecks(Manager MM) { this.M=MM; sendMessage(0,0); halt=0; } public void run() { double E=M.C.ENERGY.getParameter(); //power law exponent halt=1; int mode=M.C.SCC.ACTION.mode; System.out.println("mode "+mode); if(mode==0) testDelta(); if(mode==1) testSeparationUpperBound0(); if(mode==2) testSeparationLowerBound0(); if(mode==3) testXtraVector0(); if(mode==4) testEnergyTheorem0(E); if(mode==5) testInterval(); if(mode==6) testIntervalComplex(); if(mode==7) testIntervalVector(); if(mode==8) testStereo(); if(mode==9) testBoxRoutines(); if(mode==10) testSeparation(); if(mode==11) testEnergy(); if(mode==12) testBinary(); halt=0; } public void sendMessage(int i, double min) { M.C.SCC.d[0]=i; M.C.SCC.d[1]=min; M.C.repaint(); } /**Checks that the function delta from the paper really does give a bound to the radius of a spherical patch. the output (min) should exceed 1.*/ public void testDelta() { double min=100000000; Box b1=new Box(new Complex(0,0),-2,0,1); int t=M.C.SCC.SI[2].val; Box[] LIST=SanityCheckSupport.getBoxList(b1,t); for(int i=0;itest) min=test; sendMessage(i,min); } halt=0; } /**Checks that the separation upper bound works. Min should exceed 1*/ public void testSeparationUpperBound0() { double min=10000000; Box b1=new Box(new Complex(0,0),-2,0,1); int t=M.C.SCC.SI[2].val; Box[] LIST1=SanityCheckSupport.getBoxList(b1,t); Box[] LIST2=SanityCheckSupport.getBoxList(b1,t); int i=0; while((halt==1)&&(itest) min=test; } sendMessage(i,min); ++i; } halt=0; } public double testSeparationUpperBound1(Box B1,Box B2) { int N=M.C.SCC.SI[4].val; //number of sample points in box N=(int)(Math.pow(2,N)); double max=0; for(int i1=0;i10) { double test=crude/estimate; if(min>test) min=test; } } sendMessage(i,min); ++i; } halt=0; } public double testSeparationLowerBound1(Box B1,Box B2) { int N=M.C.SCC.SI[4].val; //number of sample points in box N=(int)(Math.pow(2,N)); double min=2; for(int i1=0;i1d) min=d; } } } } return(min); } /**Checks that some of our routines for spherical geometry are working.**/ public void testXtraVector0() { double min=1; Box b1=new Box(new Complex(0,0),-2,0,1); int t=M.C.SCC.SI[2].val; Box[] LIST=SanityCheckSupport.getBoxList(b1,t); for(int i=0;itest) min=test; sendMessage(i,min); } halt=0; } public double testXtraVector1(Box B) { Vector[] V=B.toVectors(); Vector X=XtraVector.center(V[0],V[1]); double d1=Vector.dist(X,new Vector(0,0,1)); double d2=Vector.dist(X,V[0]); double d3=Vector.dist(X,V[1]); if(Math.abs(d1-d2)>.0000001) return(0); if(Math.abs(d1-d3)>.0000001) return(0); if(Math.abs(d2-d3)>.0000001) return(0); Vector Y=XtraVector.farPoint(V[0],V[1]); double d4=Vector.dist(Y,X); double d5=Vector.dist(Y,V[0]); double d6=Vector.dist(Y,V[1]); double d7=XtraVector.norm(Y); if(Math.abs(1-d7)>.0000001) return(0); if(Math.abs(d1-d4)>.0000001) return(0); if(Math.abs(d5-d6)>.0000001) return(0); for(int i=0;i<=10;++i) { Vector H=XtraVector.interpolate(V[0],V[1],1.0*i/10); double d8=XtraVector.norm(H); if(Math.abs(1-d8)>.0000001) return(0); double d9=Vector.dist(H,X); if(Math.abs(d9-d4)>.0000001) return(0); } return(1); } /**Energy Theorem **/ public void testEnergyTheorem0(double E) { double min=10000000; Box b1=new Box(new Complex(0,0),-2,0,1); int t1=M.C.SCC.SI[2].val; int t2=M.C.SCC.SI[3].val; Box[] LIST1=SanityCheckSupport.getBoxList(b1,t1); Box[] LIST2=SanityCheckSupport.getBoxList(b1,t2); int i=0; while((halt==1)&&(itest) min=test; } sendMessage(i,min); ++i; } halt=0; } public double testEnergyTheorem1(double E,Box B1,Box B2) { int N=M.C.SCC.SI[4].val; //number of sample points in box N=(int)(Math.pow(2,N)); double num=0; for(int i=0;i<=N;++i) { for(int j=0;j<=N;++j) { double a=1.0*i/N; double b=1.0*j/N; double test=XtraEnergy.discrepancy0(E,B1,B2,a,b); if(num