I am already implemented Graham scan, but i see that the bottleneck of my program is the sorting (80% of the time). I want to improve in it, now I am doing the following:
std::sort(intersections.begin() + 1, intersections.end(), [&minElement](Point const& a, Point const& b)
{return angle (minElement - a, XAxis) < angle (minElement - b,XAxis);});
Which gives me the exact angle, but it's not cheap because my angle function looks like the following:
float angle (const Point& v1, const Point& v2) {
return dot (v1, v2) / (v1.Length () * v2.Length ());
}
In the Length function I have to do a square root, which is one of the most expensive operations. But this way I get a good ordering.
I tried ordering the array by Slope, dot, ccw, and even only removing sqrt from my compare, but none of that provides me the same ordering. Can you give me any advice?