Package com.nr.cg

Examples of com.nr.cg.Box


    // Test setouterbox in 2D
    Point lo2=new Point(0.0,0.0),hi2=new Point(1.0,1.0);
    qotree2.setouterbox(lo2,hi2);

    // Test qobox in 2D
    Box b2=new Box(2);
    b2=qotree2.qobox(1);
//    System.out.printf(dist(b2.lo,lo2));
    localflag = dist(b2.lo,lo2) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,2D: Outer box lower corner improperly set");
     
    }

//    System.out.printf(dist(b2.hi,hi2));
    localflag = dist(b2.hi,hi2) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,2D: Outer box upper corner improperly set");
     
    }

    Point half=new Point(hi2.x[0]/2.0,hi2.x[1]/2.0);

    b2=qotree2.qobox(2);
//    System.out.printf(dist(b2.hi,half));
    localflag = dist(b2.hi,half) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,2D: Box 2 upper corner should be in center of outer box");
     
    }

    b2=qotree2.qobox(5);
//    System.out.printf(dist(b2.lo,half));
    localflag = dist(b2.lo,half) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      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) {
View Full Code Here


    // Test Box
    System.out.println("Testing Box");

    // Test constructor defaults for 1,2,3 dimensions
    Box b2 = new Box(2);
    Box b3 = new Box(3);

    localflag = false;
    localflag = !(b2.lo.equals(zero2)) || !(b2.hi.equals(zero2));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Box: Faulty default constructor for 2D");
     
    }

    localflag = false;
    localflag = !(b3.lo.equals(zero3)) || !(b3.hi.equals(zero3));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Box: Faulty default constructor for 3D");
     
    }

    // Test constructor with arguments
    Box c2=new Box(zero2,one2);
    Box c3=new Box(zero3,one3);

    localflag = false;
    localflag = !(c2.lo.equals(zero2)) || !(c2.hi.equals(one2));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Box: Faulty assignment of lo or hi for 2D constructor");
     
    }

    localflag = false;
    localflag = !(c3.lo.equals(zero3)) || !(c3.hi.equals(one3));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Box: Faulty assignment of lo or hi for 3D constructor");
     
    }

    // Test assignment operator
    b2= b2.copyAssign(c2);
    b3=b3.copyAssign(c3);

    localflag = false;
    localflag = !(b2.lo.equals(zero2)) || !(b2.hi.equals(one2));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Box: Failure of assignment operator for 2D");
     
    }

    localflag = false;
    localflag = !(b3.lo.equals(zero3)) || !(b3.hi.equals(one3));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Box: Failure of assignment operator for 3D");
     
    }

    // Test copy constructor

    Box d2 = new Box(c2);
    Box d3 = new Box(c3);

    localflag = false;
    localflag = !(d2.lo.equals(c2.lo)) || !(d2.hi.equals(c2.hi));
    globalflag = globalflag || localflag;
    if (localflag) {
View Full Code Here

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

TOP

Related Classes of com.nr.cg.Box

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.