c++ - Using my own sort to sort 2D vertices clockwise -
so have vector of vertices i'm trying sort , i'm new using predicates. current sort vertices.
void triangulate::ordervertices() { std::sort(mvertices.begin(), mvertices.end(), triangulate::clockwise()); }
and sorting predicate
bool triangulate::clockwise::operator()(const cvertex2& pointa, const cvertex2& pointb) { if(pointa.mpoint.x >= 0 && pointb.mpoint.x < 0) { return true; } if(pointa.mpoint.x == 0 && pointb.mpoint.x == 0) { return true; } // gets center of current viewport cvertex2 centercoordinate(cclipper::instance()->getmidx(), cclipper::instance()->getmidy()); // compute cross product of vectors int det = (int)((pointa.mpoint.x - centercoordinate.mpoint.x) * (pointb.mpoint.y - centercoordinate.mpoint.y) - (pointb.mpoint.x - centercoordinate.mpoint.x) * (pointa.mpoint.y - centercoordinate.mpoint.y)); if(det < 0) { return true; } if(det > 0) { return false; } int det1 = (int)((pointa.mpoint.x - centercoordinate.mpoint.x) * (pointa.mpoint.x - centercoordinate.mpoint.x) + (pointa.mpoint.y - centercoordinate.mpoint.y) * (pointa.mpoint.y - centercoordinate.mpoint.y)); int det2 = (int)((pointb.mpoint.x - centercoordinate.mpoint.x) * (pointb.mpoint.x - centercoordinate.mpoint.x) + (pointb.mpoint.y - centercoordinate.mpoint.y) * (pointb.mpoint.y - centercoordinate.mpoint.y)); return det1 > det2; }
i have predicate set within triangulate class so.
class triangulate { friend class clockwise; public: triangulate(std::vector<cvertex2>& vertices) :mvertices(vertices) {} ~triangulate(void); class clockwise { public: bool operator()(const cvertex2& pointa, const cvertex2& pointb); }; private: };
when error , i'm pretty sure because didn't set right. can help?
Comments
Post a Comment