CCT.NUI.Core.Shape.GrahamScan.FindHull C# (CSharp) Method

FindHull() public method

public FindHull ( ) : ConvexHull
return ConvexHull
        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);
        }