public ConvexHull FindHull()
{
if (this.points.Count <= 3)
{
return new ConvexHull(this.points);
}
var pointsSortedByAngle = this.SortPointsByAngle();
int index = 1;
while (index + 1 < pointsSortedByAngle.Count)
{
var value = PointAngleComparer2D.Compare(pointsSortedByAngle[index - 1], pointsSortedByAngle[index + 1], pointsSortedByAngle[index]);
if (value < 0)
{
index++;
}
else //Also removes points that are on a line when value == 0
{
pointsSortedByAngle.RemoveAt(index);
if (index > 1)
{
index--;
}
}
}
pointsSortedByAngle.Add(pointsSortedByAngle.First());
return new ConvexHull(pointsSortedByAngle);
}