int main(int argc, char* argv[]){
  int numErrors = 0;
  numErrors += swapTest();
  numErrors += rotateTest();
  numErrors += pointerToMaxTest();
  printf("Number of errors: %d\n", numErrors);
}
Exemple #2
0
void Voronoi :: swapTest(Line &e,Point &p) {

    qDebug() << "Edge: "<<e.toString() << " P:"<<p.x() << " " << p.y();

    if ( (e.equals(ext1)) || (e.equals(ext2)) || (e.equals(ext3)) )   {
        return;
    }
    else {

        bool exists = false;
        Point d = findVertexOnTheRight(e,p,exists);
        if (exists)  {

            qDebug() << "Vertex on the right" <<  d.x() << " " << d.y();
            Point eA = e.getA();
            Point eB = e.getB();
            if ( inCircle(p, eA, eB, d) ) {

                qDebug() << "Is in circle, flipping";
                flip(e,p,d);
                Line l1,l2;
                l1.setA(eA);
                l1.setB(d);

                l2.setA(d);
                l2.setB(eB);

                swapTest(l1, p);
                swapTest(l2, p);

            }

        }
        else {
            qDebug() << "No vertex on the right";
        }

    }
}
Exemple #3
0
void Voronoi :: insert(Point& p) {

    //Find the triangle cotaining the point
    int parentIndex = -1;
    int i=0;
    foreach(Triangle t,triangles) {
        if(t.contains(p)) {
            parentIndex = i;
        }
        i++;
    }

    if(parentIndex!=-1) {
        //Remove the triangle, split and insert 3 triangles

        Triangle parent = triangles[parentIndex];
        qDebug() << "Parent triangle is:";
        parent.print();

        triangles.removeAt(parentIndex);

        /* Point temp;

           Line pa,pb,pc;
           pa.setA(p);
           temp = parent.ab.getA();
           pa.setB(temp);

           pb.setA(p);
           temp = parent.bc.getA();
           pb.setB(temp);

           pc.setA(p);
           temp = parent.ca.getA();
           pc.setB(temp);

           Line ap,bp,cp;
           temp = parent.ab.getA();
           ap.setA(temp);
           ap.setB(p);

           temp = parent.bc.getA();
           bp.setA(temp);
           bp.setB(p);

           temp = parent.ca.getA();
           cp.setA(temp);
           cp.setB(p);*/


        Point temp1=parent.ab.getA();
        Point temp2=parent.ab.getB();

        Triangle t1 = Triangle :: makeTriangle(temp1,temp2,p);

        temp1 = parent.ab.getB();
        temp2 = parent.ca.getA();
        Triangle t2 = Triangle :: makeTriangle(temp1,temp2,p);

        temp1 = parent.ab.getA();
        temp2 = parent.ca.getA();
        Triangle t3 = Triangle :: makeTriangle(temp1,p,temp2);


        triangles.append(t1);
        triangles.append(t2);
        triangles.append(t3);

        swapTest(parent.ab,p);
        swapTest(parent.bc,p);
        swapTest(parent.ca,p);


    }
    else {
        qDebug() << "No triangle found for point: " << p.x() << " " << p.y();
    }
}