Package com.nr.cg

Examples of com.nr.cg.Point


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

    // Test constructor defaults for 1,2,3 dimensions
    Point x1= new Point(1);
    Point x2= new Point(2);
    Point x3= new Point(3);

    localflag = false;
    localflag = (x1.x[0] != 0.0);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Faulty default constructor for 1D");
     
    }

    localflag = false;
    localflag = (x2.x[0] != 0.0) || (x2.x[1] != 0.0);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Faulty default constructor for 2D");
     
    }

    localflag = false;
    localflag = (x3.x[0] != 0.0) || (x3.x[1] != 0.0) || (x3.x[2] != 0.0);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Faulty default constructor for 3D");
     
    }

    Point x11=new Point(1,1.0);
    Point x21=new Point(1.0,1.0);
    Point x31=new Point(1.0,1.0,1.0);

    localflag = false;
    localflag = (x11.x[0] != 1.0);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Faulty element assignments for 1D constructor");
     
    }

    localflag = false;
    localflag = (x21.x[0] != 1.0) || (x21.x[1] != 1.0);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Faulty element assignments for 2D constructor");
     
    }

    localflag = false;
    localflag = (x31.x[0] != 1.0) || (x31.x[1] != 1.0) || (x31.x[2] != 1.0);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Faulty element assignments for 3D constructor");
     
    }

    // Test assignment operator
    x1.copyAssign(x11);
    x2.copyAssign(x21);
    x3.copyAssign(x31);

    localflag = false;
    localflag = (x1.x[0] != 1.0);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Failure of assignment operator for 1D");
     
    }

    localflag = false;
    localflag = (x2.x[0] != 1.0) || (x2.x[1] != 1.0);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Failure of assignment operator for 2D");
     
    }

    localflag = false;
    localflag = (x3.x[0] != 1.0) || (x3.x[1] != 1.0) || (x3.x[2] != 1.0);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Failure of assignment operator for 3D");
     
    }

    // Test boolean equality operator
    localflag = false;
    localflag = !(x11.equals(x1));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Failure of boolean equality operator for 1D");
     
    }

    localflag = false;
    localflag = !(x21.equals(x2));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Failure of boolean equality operator for 2D");
     
    }

    localflag = false;
    localflag = !(x31.equals(x3));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Failure of boolean equality operator for 3D");
     
    }

    // Test copy constructor
    Point y1=new Point(x1);
    Point y2=new Point(x2);
    Point y3=new Point(x3);

    localflag = false;
    localflag = !(y1.equals(x1));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Failure of copy constructor for 1D");
     
    }

    localflag = false;
    localflag = !(y2.equals(x2));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Failure of copy constructor for 2D");
     
    }

    localflag = false;
    localflag = !(y3.equals(x3));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Point: Failure of copy constructor for 3D");
     
    }
View Full Code Here


  @Test
  public void test() {
    boolean test;
    int i,j,N=1000;
    double radius1,radius2;
    Point p21=new Point(2),p22=new Point(2);
    Point p31=new Point(3),p32=new Point(3);
    boolean localflag, globalflag=false;

   

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

    Ran myran=new Ran(17);

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

    // Polygon 4, complex
    double x6[]={-1.0,-0.5,0.0,0.5,1.0,0.5,0.0,-0.5};
    double x7[]={0.0,1.0,-0.1,1.0,0.0,-1.0,0.1,-1.0};
    Point[] poly1=new Point[N1],poly2=new Point[N2],poly3=new Point[N3],poly4=new Point[N4];
    for(i=0;i<N1;i++)
      poly1[i]= new Point(2);
    for(i=0;i<N2;i++)
      poly2[i]= new Point(2);
    for(i=0;i<N3;i++)
      poly3[i]= new Point(2);
    for(i=0;i<N4;i++)
      poly4[i]= new Point(2);
   

    boolean localflag, globalflag=false;

   
View Full Code Here

  @Test
  public void test() {
    int i,j,nkd,nqo,N=1000,M=100;
    double r,d,min,sbeps;
    Point testpt = new  Point(2);
    Point[] pvec=new Point[N];
    boolean localflag, globalflag=false;

   

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

    Ran myran=new Ran(17);

    // Create KDtree and Qotree of same Points<2> in 2D
    for (i=0;i<N;i++) {
      pvec[i] = new Point(2);
      pvec[i].x[0]=myran.doub();
      pvec[i].x[1]=myran.doub();
    }

    Nearpoints qo = new Nearpoints(2,pvec);
    KDtree kd = new KDtree(2,pvec);

    int[] kdlist=new int[M];
    Point[] qolist=new Point[M];

    testpt.x[0]=0.6;
    testpt.x[1]=0.7;
    r=0.1;
    nkd=kd.locatenear(testpt,r,kdlist,M);
    nqo=qo.locatenear(testpt,r,qolist,M);

    // See if KDtree and Nearpoints found the same number of
    // neighbors withing radius r
    localflag = (nkd != nqo);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Nearpoints,2D: KDtree found a different number of neighbors inside radius r");
     
    }

    // See if each point from kdlist can be found in qolist
    sbeps=1.e-16;
    if (nkd == nqo) {
      for (i=0;i<nkd;i++) {
        min=1.e99;
        for (j=0;j<nqo;j++) {
          d=dist(kd.ptss[kdlist[i]],qolist[j]);
          if (d < min) min=d;
        }
//        System.out.printf(min);
        localflag = min > sbeps;
        globalflag = globalflag || localflag;
        if (localflag) {
          fail("*** Nearpoints,2D: A point identified by KDtree was not found by Nearpoints");
         
        }
      }
    }

    // Create KDtree and Qotree of same Points<3> in 3D
    Point test3pt=new Point(3);
    Point[] p3vec=new Point[N]
    for (i=0;i<N;i++) {
      p3vec[i] = new Point(3);
      p3vec[i].x[0]=myran.doub();
      p3vec[i].x[1]=myran.doub();
      p3vec[i].x[2]=myran.doub();
    }

View Full Code Here

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

    // Distance between two points in 2D
    Ran myran=new Ran(17);
    Point x=new Point(2),y=new Point(2);
    for (i=0;i<N;i++) {
      x.x[0]=myran.doub();
      x.x[1]=myran.doub();
      y.x[0]=myran.doub();
      y.x[1]=myran.doub();
      dexp[i]=sqrt(SQR(y.x[0]-x.x[0])+SQR(y.x[1]-x.x[1]));
      d[i]=dist(x,y);
    }

    sbeps=1.0e-15;
    localflag = maxel(vecsub(d,dexp)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** dist: Error in distance between two Points in 2D");
     
    }

    // Distance between two points in 3D
    Point xx=new Point(3),yy=new Point(3);
    for (i=0;i<N;i++) {
      xx.x[0]=myran.doub();
      xx.x[1]=myran.doub();
      xx.x[2]=myran.doub();
      yy.x[0]=myran.doub();
View Full Code Here

  }

  @Test
  public void test() {
    int i,j,nwind,N=10000;
    Point p=new Point(2);
    Point[] pvec = new Point[N];
    for(i=0;i<N;i++)
      pvec[i]= new Point(2);
    boolean localflag, globalflag=false;

   

    // Test Convexhull
View Full Code Here

    Ran myran=new Ran(17);

    // Test KDtree in 2D
    for (i=0;i<N;i++) {
      kd2[i] = new Point(2);
      kd2[i].x[0]=myran.doub();
      kd2[i].x[1]=myran.doub();
    }
    KDtree tree2=new KDtree(2,kd2);
   
    // Test locate(Point) method
    Point y=new Point(2);
    int nb;       // number of box containing y
    localflag=false;
    for (i=0;i<M;i++) {
      y.x[0]=myran.doub();
      y.x[1]=myran.doub();
      nb=tree2.locate(y);
//      System.out.printf(nb);
//      System.out.printf(tree2.boxes[nb].lo.x[0] << " %f\n", tree2.boxes[nb].lo.x[1]);
//      System.out.printf(tree2.boxes[nb].hi.x[0] << " %f\n", tree2.boxes[nb].hi.x[1]);
      localflag = localflag || (y.x[0] < tree2.boxes[nb].lo.x[0]);
      localflag = localflag || (y.x[0] > tree2.boxes[nb].hi.x[0]);
      localflag = localflag || (y.x[1] < tree2.boxes[nb].lo.x[1]);
      localflag = localflag || (y.x[1] > tree2.boxes[nb].hi.x[1]);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** KDtree<2>,locate(Point): The located box does not contain selected point");
       
      }
    }

    // Test locate(int) method
    int n0;
    localflag=false;
    for (i=0;i<M;i++) {
      n0=myran.int32p() % N;
      nb=tree2.locate(n0);
//      System.out.printf(nb);
//      System.out.printf(tree2.boxes[nb].lo.x[0] << " %f\n", tree2.boxes[nb].lo.x[1]);
//      System.out.printf(tree2.boxes[nb].hi.x[0] << " %f\n", tree2.boxes[nb].hi.x[1]);
      localflag = localflag || (kd2[n0].x[0] < tree2.boxes[nb].lo.x[0]);
      localflag = localflag || (kd2[n0].x[0] > tree2.boxes[nb].hi.x[0]);
      localflag = localflag || (kd2[n0].x[1] < tree2.boxes[nb].lo.x[1]);
      localflag = localflag || (kd2[n0].x[1] > tree2.boxes[nb].hi.x[1]);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** KDtree<2>,locate(int): The located box does not contain selected point");
       
      }
    }

    // Test disti() method
    int n1,n2;
    sbeps=1.e-15;
    localflag=false;
    for (i=0;i<M;i++) {
      n1=myran.int32p() % N;
      n2=myran.int32p() % N;
      double dis=tree2.disti(n1,n2);
//      System.out.printf(dis << " %f\n", sqrt(SQR(kd2[n1].x[0]-kd2[n2].x[0])
//        + SQR(kd2[n1].x[1]-kd2[n2].x[1])));
      if (n1 == n2)
        localflag = localflag || dis < 1.e99;
      else
        localflag = localflag || (dis-sqrt(SQR(kd2[n1].x[0]-kd2[n2].x[0])
          + SQR(kd2[n1].x[1]-kd2[n2].x[1]))) > sbeps;
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** KDtree<2>,disti(): The disti() method gave an incorrect result");
       
      }
    }

    // Test nearest() method
    int j,n3;
    double dis2sq;
    localflag=false;
    for (i=0;i<M;i++) {
      y.x[0]=myran.doub();
      y.x[1]=myran.doub();
      n3=tree2.nearest(y);
      dis2sq=SQR(kd2[n3].x[0]-y.x[0])+SQR(kd2[n3].x[1]-y.x[1]);
      for (j=0;j<N;j++) {
        if (j != n3) localflag = localflag ||
          (SQR(kd2[j].x[0]-y.x[0])+ SQR(kd2[j].x[1]-y.x[1])) < dis2sq;
      }
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** KDtree<2>,nearest(): Exhaustive search found closer point");
       
      }
    }

    // Test nnearest() method
    int n4,n,nfar,K=5;
    boolean test;
    double far;
    int[]nn=new int[K];
    double[] dn=new double[K];
    localflag=false;
    for (i=0;i<M;i++) {
      n4=myran.int32p()%N;
      tree2.nnearest(n4,nn,dn,K);   // Find K nearest Points
      // See if there is anything closer than the furthest
      // of these points, other than the other points in the list nn[]
      far=0.0;
      nfar=0;
      for (j=0;j<K;j++)
        if (dn[j] > far) {
          far=dn[j];
          nfar=nn[j];
        }
      test=false;
      for (j=0;j<N;j++) {
        for (n=0;n<K;n++)
          test = test || (nn[n] == j);
        if (!test)
          localflag = localflag || (tree2.disti(j,n4) < far);
        globalflag = globalflag || localflag;
        if (localflag) {
          fail("*** KDtree<2>,nnearest(): Found a nearer point than the supposed n nearest");
         
        }
      }
    }

    // Test locatenear() method
    int nmax=N/10;
    int[] list=new int[nmax];
    double r=0.1;
    y.x[0]=0.5;
    y.x[1]=0.5;
    int nret=tree2.locatenear(y,r,list,nmax);
    // Check the result by brute force
    int[] list2=new int[nmax];
    int nret2=0;
    for (i=0;i<N;i++) {
      if ((dist(y,kd2[i]) < r) && (nret2 < nmax)) {
        list2[nret2]=i;
        nret2++;
      }
    }

//    System.out.printf(nret << " %f\n", nret2);
    localflag = (nret != nret2);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** KDtree<2>,locatenear(): Found different number of points closer than radius r");
     
    }

    // Make sure list[] and list2[] are the same
    int[] llist=buildVector(list),llist2=buildVector(list2);
    Arrays.sort(llist);
    Arrays.sort(llist2);
    localflag=false;
    for (i=0;i<nret;i++) {
//      System.out.printf(llist[i] << " %f\n", llist2[i]);
      localflag=localflag || (llist[i] != llist2[i]);
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** KDtree<2>,locatenear(): The list of nearby points is not correct");
     
    }

    // Repeat all the tests in 3D
    // Test KDtree in 3D
    for (i=0;i<N;i++) {
      kd3[i] = new Point(3);
      kd3[i].x[0]=myran.doub();
      kd3[i].x[1]=myran.doub();
      kd3[i].x[2]=myran.doub();
    }
    KDtree tree3 = new KDtree(3,kd3);

    // Test locate(Point) method in 3D
    Point yy=new Point(3);
    localflag=false;
    for (i=0;i<M;i++) {
      yy.x[0]=myran.doub();
      yy.x[1]=myran.doub();
      yy.x[2]=myran.doub();
View Full Code Here

  @Test
  public void test() {
    int i,min,N=1000;
    Point[] pvec=new Point[N],qvec=new Point[N];
    for(i=0;i<N;i++){
      pvec[i]= new Point(2);
      qvec[i]= new Point(2);
    }
    boolean localflag=false, globalflag=false;

   
View Full Code Here

TOP

Related Classes of com.nr.cg.Point

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.