fail("*** Qotree,2D: Box 5 lower corner should be in center of outer box");
}
// Test qowhichbox in 2D
Sphcirc s2 = new Sphcirc(2);
s2.center=new Point(5.5/16.0,10.5/16.0);
int ans[]={1,4,15,239};
for (i=0;i<4;i++) {
s2.radius=0.25/pow(2.0,i);
nbox=qotree2.qowhichbox(s2);
// System.out.printf(s2.radius << " %f\n", nbox);
localflag = (nbox != ans[i]);
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,2D: Method qowhichbox() identified wrong box for specified circle");
}
}
// Test qostore in 2D
s2.center=new Point(5.5/16.0,10.5/16.0);
for (i=0;i<4;i++) {
s2.radius=0.25/pow(2.0,i);
nbox=qotree2.qostore(s2);
// System.out.println("box: %f\n", nbox);
localflag = (nbox != ans[i]);
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,2D: Method qostore() stored specified circle in wrong box");
}
}
// Test qoerase in 2D
s2.center=new Point(5.5/16.0,10.5/16.0);
for (i=0;i<4;i++) {
s2.radius=0.25/pow(2.0,i);
nbox=qotree2.qoerase(s2);
// System.out.printf(nbox);
localflag = (nbox != ans[i]);
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,2D: Method qoerase() removed circle from wrong box");
}
}
// Store 16 circles in the tree
s2.center=new Point(5.5/16.0,10.5/16.0);
for (i=0;i<4;i++) {
s2.radius=0.25/pow(2.0,i);
qotree2.qostore(s2);
}
s2.center=new Point(10.5/16.0,10.5/16.0);
for (i=0;i<4;i++) {
s2.radius=0.25/pow(2.0,i);
qotree2.qostore(s2);
}
s2.center=new Point(10.5/16.0,5.5/16.0);
for (i=0;i<4;i++) {
s2.radius=0.25/pow(2.0,i);
qotree2.qostore(s2);
}
s2.center=new Point(5.5/16.0,5.5/16.0);
for (i=0;i<4;i++) {
s2.radius=0.25/pow(2.0,i);
qotree2.qostore(s2);
}
// Test qoget in 2D
Sphcirc[]list2=new Sphcirc[N];
nlist=qotree2.qoget(1,list2,N);
System.out.println(nlist);
for (i=0;i<nlist;i++)
System.out.printf( "%f %f %f\n", list2[i].center.x[0], list2[i].center.x[1] , list2[i].radius);
localflag = (nlist != 4);
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,2D: Method qoget() found the wrong number of circles in Box 1");
}
localflag=false;
for (i=0;i<nlist;i++) {
nbox=qotree2.qowhichbox(list2[i]);
localflag = localflag || (nbox != 1);
}
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,2D: Method qoget() returned a circle that is not in Box 1");
}
// Test qodump in 2D
int[] klist2=new int[N];
nlist=qotree2.qodump(klist2,list2,N);
// System.out.printf(nlist);
localflag = (nlist != 16);
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,2D: Method qodump() did not find all 16 circles in the tree");
}
// Test qocontainspt in 2D
Point p2=new Point(5.5/16.0,10.5/16.0);
nlist=qotree2.qocontainspt(p2,list2,N);
// System.out.printf(nlist);
localflag = (nlist != 4);
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,2D: Method qodump() did not find all 4 circles with the given point");
}
for (i=0;i<nlist;i++) {
localflag = dist(p2,list2[i].center) > list2[i].radius;
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,2D: Method qodump() returned a circle that does not contain the given point");
}
}
// Test qocollides in 2D
s2.center=new Point(0.75,0.75);
s2.radius=0.10;
nlist=qotree2.qocollides(s2,list2,N);
// System.out.printf(nlist);
localflag = (nlist != 3);
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,2D: Method qocollides() did not find 3 circles that collide with target");
}
for (i=0;i<nlist;i++) {
localflag = (dist(list2[i].center,s2.center) > list2[i].radius+s2.radius);
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,2D: Incorrect collision detection by method qocollides()");
}
}
// Test Qotree in 3D
Qotree qotree3=new Qotree(3,N,N,5);
// Test setouterbox in 3D
Point lo3=new Point(0.0,0.0,0.0),hi3=new Point(1.0,1.0,1.0);
qotree3.setouterbox(lo3,hi3);
// Test qobox in 3D
Box b3=new Box(3);
b3=qotree3.qobox(1);
// System.out.printf(dist(b3.lo,lo3));
localflag = dist(b3.lo,lo3) > sbeps;
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,3D: Outer box lower corner improperly set");
}
// System.out.printf(dist(b3.hi,hi3));
localflag = dist(b3.hi,hi3) > sbeps;
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,3D: Outer box upper corner improperly set");
}
Point half3=new Point(hi3.x[0]/2.0,hi3.x[1]/2.0,hi3.x[2]/2.0);
b3=qotree3.qobox(2);
// System.out.printf(dist(b3.hi,half3));
localflag = dist(b3.hi,half3) > sbeps;
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,3D: Box 2 upper corner should be in center of outer box");
}
b3=qotree3.qobox(9);
// System.out.printf(dist(b3.lo,half3));
localflag = dist(b3.lo,half3) > sbeps;
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Qotree,3D: Box 9 lower corner should be in center of outer box");
}
// Test qowhichbox in 3D
Sphcirc s3=new Sphcirc(3);
int ans3[]={1,8,59,3771};
s3.center=new Point(5.5/16.0,10.5/16.0,10.5/16.0);
for (i=0;i<4;i++) {
s3.radius=0.25/pow(2.0,i);
nbox=qotree3.qowhichbox(s3);