int wildcardFind(const string& path, vector<Id>& ret) { ret.resize( 0 ); simpleWildcardFind( path, ret ); myUnique( ret ); return ret.size(); }
bool Server::pointInPolygon(Point p) { int polySides = this->cell.n; float x = p.x(); float y = p.y(); float polyYi, polyYj; float polyXi, polyXj; int i, j = polySides-1; bool oddNodes = false; std::vector<Point> verts; vertsToVector(&verts); verts = myUnique(verts); for (i=0; i<polySides; i++) { polyYi = verts[i].y(); polyXi = verts[i].x(); polyYj = verts[j].y(); polyXj = verts[j].x(); // if ((polyYi<y && polyYj>=y || polyYj< y && polyYi>=y) && (polyXi<=x || polyXj<=x)) { // if (polyXi+(y-polyYi)/(polyYj-polyYi)*(polyXj-polyXi)<=x) { // oddNodes=!oddNodes; // } // } if ((polyYi >= y) != (polyYj >= y)) { if (polyXi+(polyXj-polyXi)*(y-polyYi)/(polyYj-polyYi)>=x) { oddNodes=!oddNodes; } } /* *if( ( (points[i].y) >= point.y != (points[j].y >= point.y) ) && (point.x <= (points[j].x - points[i].x) * (point.y - points[i].y) / (points[j].y - points[i].y) + points[i].x) ) */ j=i; } return oddNodes; }
void Server::generateVoronoi() { clock_t start = clock(); for(unsigned long k=0;k<REPCOUNT;k++){ std::vector<Point> sPoints; std::vector<Point> vPoints; std::vector<Point> points; sPoints.clear(); vPoints.clear(); points.clear(); VoronoiDiagramGenerator vdg; set <Server*>::iterator it; float x1,y1,x2,y2; Point curPoint; double distTp, newDist; // Get all server locations points.push_back(this->loc); for(it = this->neighbours.begin(); it != this->neighbours.end(); it++) { points.push_back((*it)->loc); } int count = points.size(); float xValues[count]; float yValues[count]; vPoints.push_back(Point(0,0)); vPoints.push_back(Point(WIDTH,0)); vPoints.push_back(Point(WIDTH,WIDTH)); vPoints.push_back(Point(0,WIDTH)); for (int i=0;i<count;i++) { xValues[i] = points.at(i).x(); yValues[i] = points.at(i).y(); } vdg.generateVoronoi(xValues,yValues,count, 0,WIDTH,0,WIDTH); vdg.resetIterator(); // printf("\n-------------------------------\n"); while(vdg.getNext(x1,y1,x2,y2)) { // printf("GOT Line (%g,%g)->(%g,%g)\n",x1,y1,x2, y2); vPoints.push_back(Point(x1,y1)); vPoints.push_back(Point(x2,y2)); } vPoints = myUnique(vPoints); this->deleteCell(); bool mine; for (unsigned int i=0;i<vPoints.size();i++) { mine = true; curPoint = vPoints[i]; distTp = this->loc.dist(curPoint); for(it = this->neighbours.begin(); it != this->neighbours.end(); it++) { newDist = (*it)->loc.dist(curPoint); // if(distTp < newDist){ // mine = true; // }else if(abs(newDist - distTp) < EPS) { // mine = true; // }else if(newDist < distTp){ // mine = false; // } if (abs(newDist - distTp) > EPS) { if (newDist < distTp) { mine = false; } } } if (mine) { sPoints.push_back(curPoint); } } this->GrahamScan(sPoints); } clock_t end = clock(); double cpu_time = static_cast<double>( end - start )/REPCOUNT; printf("generateVoronoi() comp_time = %f \n",cpu_time); }