void Voronoi::insertParabola(VPoint *p) { if (!root) { root = new VParabola(p); return; } // TRANSLATEME degenerovaný pøípad - obì spodní místa ve stejné výšce if (root->isLeaf && root->site->y - p->y < 0.1) { VPoint *fp = root->site; root->isLeaf = false; root->setLeft(new VParabola(fp)); root->setRight(new VParabola(p)); VPoint *s = new VPoint((p->x + fp->x) / 2, height); // TRANSLATEME zaèátek hrany uprostøed míst points.push_back(s); if (p->x > fp->x) root->edge = new VEdge(s, fp, p); // TRANSLATEME 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; } VPoint *start = new VPoint(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); // TRANSLATEME 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); }
// get an field index and edit the new value from the user void CourseEditingState::edit(int index) { string new_svalue; int choise = 0; bool circle = false;; cout << "You have choosen to edit the field: \n"; switch (index) { case 0: cout << "Name " << this->course.name.get() << endl << endl; cout << "Please enter new value \n\n"; cin.ignore(); getline(cin, new_svalue); course.name.set(new_svalue); break; case 1: cout << "Description " << this->course.description.get() << endl << endl; cout << "Please enter new value \n\n"; cin.ignore(); getline(cin, new_svalue); course.description.set(new_svalue); break; case 2: cout << "Max Number of students " << this->course.maxNumberOfStudents.get() << endl << endl; cout << "Please enter new value \n\n"; course.maxNumberOfStudents.set(insertValue()); break; case 3: cout << "Teaching Hours " << this->course.teachingHours.get() << endl << endl; cout << "Please enter new value \n\n"; course.teachingHours.set(insertValue()); break; case 4: system("cls"); while (choise != 3) { cout << getCaption(4) << " : " << getValue(4) << endl << endl; cout << "1.adding pre course\n2.remove\n3.exit\n\n"; choise = insertValue(); switch (choise) { case 1: if (displayAllAvailableCourses(seasonConfig, course) != 0) { cout << "enter course index: "; course.pre.add(seasonConfig.courses.get(insertValue())); circle = checkCircle(this->seasonConfig); if (circle == true) { cout << "Cannot add course because circle was found \n\n"; course.pre.remove(course.pre.count() - 1); } } else { cout << "No available courses to add" << endl << endl; } _sleep(3000); break; case 2: if (course.pre.count() != 0) { cout << "enter course index: "; course.pre.remove(insertValue()); } else { cout << "No pre courses to remove" << endl << endl; _sleep(3000); } break; case 3: choise = 3; default: cout << "Wrong key \n"; break; } } break; } }
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 << "TRANSLATEME 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; } VPoint *p = new VPoint(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); }