Package com.nr.cg

Examples of com.nr.cg.Sphcirc


    // Test method operator== in 2D
    Sphcirc[] circ=new Sphcirc[N];
   
    for (i=0;i<N;i++) {
      circ[i] = new Sphcirc(2);
      circ[i].center.x[0]=myran.doub();
      circ[i].center.x[1]=myran.doub();
      circ[i].radius=myran.doub();
    }
    // Make every fifth circle identical
    for (i=5;i<N;i+=5)
      circ[i]=circ[0];
    Sphcirc ctest=new Sphcirc(circ[0].center,circ[0].radius);
    for (i=0;i<N;i++) {
      j=myran.int32p() % N;
      test = (circ[j].equals(ctest));
      localflag = (test != (j % 5 == 0));
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,operator==(),2D: Incorrect signal of whether two circles are identical");
       
      }
    }

    // Test method isinbox() in 2D
    Point lo=new Point(2),hi=new Point(2);
    double boxsize=0.8,sphsize=0.25;
    for (i=0;i<N;i++) {
      p21.x[0]=myran.doub();
      p21.x[1]=myran.doub();

      lo.x[0]=p21.x[0]-boxsize;
      hi.x[0]=p21.x[0]+boxsize;
      lo.x[1]=p21.x[1]-boxsize;
      hi.x[1]=p21.x[1]+boxsize;
      Box box1=new Box(lo,hi);

      p22.x[0]=myran.doub();
      p22.x[1]=myran.doub();
      Sphcirc sph1=new Sphcirc(p22,sphsize);

//      System.out.printf(sph1.isinbox(box1));
      test=(sph1.isinbox(box1) != 0);

      localflag = (test != (
        (abs(p21.x[0]-p22.x[0]) <= (boxsize-sphsize))
        && (abs(p21.x[1]-p22.x[1]) <= (boxsize-sphsize))));
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,isinbox(),2D: Incorrect signal of whether the circle is inside the box");
       
      }
    }

    // Test method contains() in 2D
    for (i=0;i<N;i++) {
      p21.x[0]=myran.doub();
      p21.x[1]=myran.doub();
      radius1=myran.doub();
      Sphcirc sph1=new Sphcirc(p21,radius1);

      p22.x[0]=myran.doub();
      p22.x[1]=myran.doub();

//      System.out.printf(sph1.contains(p22));
      test=(sph1.contains(p22) != 0);
      localflag = (test != (dist(p21,p22) < radius1));
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,contains(),2D: Incorrect signal of whether point is in circle");
       
      }
    }

    // Test method collides() in 2D
    for (i=0;i<N;i++) {
      p21.x[0]=myran.doub();
      p21.x[1]=myran.doub();
      radius1=0.5*myran.doub();
      Sphcirc sph1=new Sphcirc(p21,radius1);

      p22.x[0]=myran.doub();
      p22.x[1]=myran.doub();
      radius2=0.5*myran.doub();
      Sphcirc sph2=new Sphcirc(p22,radius2);

//      System.out.printf(sph1.collides(sph2));
      test=(sph1.collides(sph2) != 0);
      localflag = (test != (dist(p21,p22) < (radius1+radius2)));
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,collides(),2D: Incorrect identification of colliding circles");
       
      }
    }

    // Test method operator== in 3D
    Sphcirc[] circ3=new Sphcirc[N];
    for (i=0;i<N;i++) {
      circ3[i] = new Sphcirc(3);
      circ3[i].center.x[0]=myran.doub();
      circ3[i].center.x[1]=myran.doub();
      circ3[i].center.x[2]=myran.doub();
      circ3[i].radius=myran.doub();
    }
    // Make every fifth circle identical
    for (i=5;i<N;i+=5)
      circ3[i]=circ3[0];
    Sphcirc ctest3=new Sphcirc(circ3[0].center,circ3[0].radius);
    for (i=0;i<N;i++) {
      j=myran.int32p() % N;
      test = (circ3[j].equals(ctest3));
      localflag = (test != (j % 5 == 0));
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,operator==(),3D: Incorrect signal of whether two circles are identical");
       
      }
    }

    // Test method isinbox() in 3D
    Point lo3=new Point(3),hi3=new Point(3);
    boxsize=0.8;sphsize=0.25;
    for (i=0;i<N;i++) {
      p31.x[0]=myran.doub();
      p31.x[1]=myran.doub();
      p31.x[2]=myran.doub();

      lo3.x[0]=p31.x[0]-boxsize;
      hi3.x[0]=p31.x[0]+boxsize;
      lo3.x[1]=p31.x[1]-boxsize;
      hi3.x[1]=p31.x[1]+boxsize;
      lo3.x[2]=p31.x[2]-boxsize;
      hi3.x[2]=p31.x[2]+boxsize;
      Box box1=new Box(lo3,hi3);

      p32.x[0]=myran.doub();
      p32.x[1]=myran.doub();
      p32.x[2]=myran.doub();
      Sphcirc sph1=new Sphcirc(p32,sphsize);

//      System.out.printf(sph1.isinbox(box1));
      test=(sph1.isinbox(box1) != 0);

      localflag = (test != (
        (abs(p31.x[0]-p32.x[0]) <= (boxsize-sphsize))
        && (abs(p31.x[1]-p32.x[1]) <= (boxsize-sphsize))
        && (abs(p31.x[2]-p32.x[2]) <= (boxsize-sphsize)))
      );
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,isinbox(),3D: Incorrect signal of whether the circle is inside the box");
       
      }
    }

    // Test method contains() in 3D
    for (i=0;i<N;i++) {
      p31.x[0]=myran.doub();
      p31.x[1]=myran.doub();
      p31.x[2]=myran.doub();
      radius1=myran.doub();
      Sphcirc sph1=new Sphcirc(p31,radius1);

      p32.x[0]=myran.doub();
      p32.x[1]=myran.doub();
      p32.x[2]=myran.doub();

//      System.out.printf(sph2.contains(p32));
      test=(sph1.contains(p32) != 0);
      localflag = (test != (dist(p31,p32) < radius1));
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,contains(),3D: Incorrect signal of whether point is in circle");
       
      }
    }

    // Test method collides() in 3D
    for (i=0;i<N;i++) {
      p31.x[0]=myran.doub();
      p31.x[1]=myran.doub();
      p31.x[2]=myran.doub();
      radius1=0.5*myran.doub();
      Sphcirc sph1=new Sphcirc(p31,radius1);

      p32.x[0]=myran.doub();
      p32.x[1]=myran.doub();
      p32.x[2]=myran.doub();
      radius2=0.5*myran.doub();
      Sphcirc sph2=new Sphcirc(p32,radius2);

//      System.out.printf(sph3.collides(sph4));
      test=(sph1.collides(sph2) != 0);
      localflag = (test != (dist(p31,p32) < (radius1+radius2)));
      globalflag = globalflag || localflag;
View Full Code Here


      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);
View Full Code Here

TOP

Related Classes of com.nr.cg.Sphcirc

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.