int main(int argc, const char *argv[]) { Node* head = CreateList(); int v = 5; InsertList(head, v); InsertList(head, v); InsertList(head, v); v = 10; int i = InsertList(head, v, 4); v = 20; i = InsertList(head, v, 4); v = 1; i = InsertList(head, v); printf("i:%d\n", i); PList(head); printf("\n\n"); PListRecurse(head->next); printf("\nreserve list:\n"); ReserveList(head); PList(head); printf("\n---- reserve list\n"); Node* p = GetNode(head, 1); if( NULL != p ) { printf("\n0 node d:%d p:%016lX\n", p->d, reinterpret_cast<uint64_t>(p)); } Node* head2 = CreateList(); head2->next = p; printf("\nlist2\n"); PList(head2); printf("\n"); int retInterSection = CheckUnion(head, head2); printf("checkunion ret:%d\n", retInterSection); int ret = CheckCircle(head); printf("check circle:%d\n", ret); printf("makecircle \n"); MakeCircle(head); //PList(head); retInterSection = CheckUnion(head, head2); printf("checkunion2 ret:%d\n", retInterSection); ret = CheckCircle(head); printf("check circle:%d\n", ret); i = FindInList(head, 20); printf("\nfind i:%d\n", i); return 0; }
void Voronoi::InsertParabola(Vec2d * p){ if(!root){root = new VParabola(p); return;} if(root->isLeaf && root->site->y - p->y < 1){ // degenerovaný pripad - obì spodní místa ve stejné výce Vec2d * fp = root->site; root->isLeaf = false; root->SetLeft( new VParabola(fp) ); root->SetRight(new VParabola(p) ); //Vec2d * s = new Vec2d( (p->x + fp->x)/2, height ); // zaèátek hrany uprostøed míst Vec2d * s = new Vec2d(); s->set( (p->x + fp->x)/2, height ); // zaèátek hrany uprostøed míst points.push_back(s); if(p->x > fp->x) root->edge = new VEdge(s, fp, p); // rozhodnu, který vlevo, který vpravo else root->edge = new VEdge(s, p, fp); edges->push_back(root->edge); return; } VParabola * par = GetParabolaByX(p->x); if(par->cEvent) { deleted.insert(par->cEvent); par->cEvent = 0; } //Vec2d * start = new Vec2d(p->x, GetY(par->site, p->x)); Vec2d * start = new Vec2d(); start->set( p->x, GetY(par->site, p->x) ); points.push_back(start); VEdge * el = new VEdge(start, par->site, p); VEdge * er = new VEdge(start, p, par->site); el->neighbour = er; edges->push_back(el); // pøestavuju strom .. vkládám novou parabolu par->edge = er; par->isLeaf = false; VParabola * p0 = new VParabola(par->site); VParabola * p1 = new VParabola(p); VParabola * p2 = new VParabola(par->site); par->SetRight(p2); par->SetLeft(new VParabola()); par->Left()->edge = el; par->Left()->SetLeft(p0); par->Left()->SetRight(p1); CheckCircle(p0); CheckCircle(p2); }
int CheckArgs(int type, int color, int arg0, int arg1, int arg2, int numArgs) { if (numArgs < MIN_ARGS) { printf("Bad formatting in first %d args.\n", MIN_ARGS); return 0; } if (!IsGoodColor(color)) { printf("Bad color.\n"); return 0; } if (type == 'R') return CheckRectangle(arg0, arg1, numArgs); else if (type == 'E') return CheckEllipse(arg2, numArgs); else if (type == 'C') return CheckCircle(arg0, numArgs); else if (type == '!') return CheckExclaim(arg0, arg1, numArgs); else if (type == 'H' || type == 'L') return CheckLetter(type, arg0, arg1, arg2, numArgs); else { printf("Bad shape %c.\n", type); return 0; } return 1; }
void Voronoi::RemoveParabola(VEvent * e){ VParabola * p1 = e->arch; VParabola * xl = VParabola::GetLeftParent(p1); VParabola * xr = VParabola::GetRightParent(p1); VParabola * p0 = VParabola::GetLeftChild(xl); VParabola * p2 = VParabola::GetRightChild(xr); if(p0 == p2) std::cout << "chyba - pravá a levá parabola má stejné ohnisko!\n"; if(p0->cEvent){ deleted.insert(p0->cEvent); p0->cEvent = 0; } if(p2->cEvent){ deleted.insert(p2->cEvent); p2->cEvent = 0; } //Vec2d * p = new Vec2d(e->point->x, GetY(p1->site, e->point->x)); Vec2d * p = new Vec2d(); p->set( e->point->x, GetY(p1->site, e->point->x) ); points.push_back(p); xl->edge->end = p; xr->edge->end = p; VParabola * higher; VParabola * par = p1; while(par != root) { par = par->parent; if(par == xl) higher = xl; if(par == xr) higher = xr; } higher->edge = new VEdge(p, p0->site, p2->site); edges->push_back(higher->edge); VParabola * gparent = p1->parent->parent; if(p1->parent->Left() == p1) { if(gparent->Left() == p1->parent) gparent->SetLeft ( p1->parent->Right() ); if(gparent->Right() == p1->parent) gparent->SetRight( p1->parent->Right() ); }else{ if(gparent->Left() == p1->parent) gparent->SetLeft ( p1->parent->Left() ); if(gparent->Right() == p1->parent) gparent->SetRight( p1->parent->Left() ); } delete p1->parent; delete p1; CheckCircle(p0); CheckCircle(p2); }