Example #1
0
        private void Sort()
        {
            int anchorIndex = 0;

            for (int i = 0; i < inputPoints.Count; i++)
            {
                sorted.Add(new CartesianPointAngle(inputPoints[i]));

                //find lowest point
                if (sorted[anchorIndex].p.y >= sorted[i].p.y)
                {
                    anchorIndex = i;
                }
            }

            //move anchor to 0
            if (sorted.Count <= anchorIndex)
            {
                Debug.Log("wtf: " + anchorIndex.ToString() + ", " + sorted.Count.ToString());
            }

            CartesianPointAngle tmp = sorted[anchorIndex];

            sorted[anchorIndex] = sorted[0];
            sorted[0]           = tmp;

            for (int i = 1; i < sorted.Count; ++i)
            {
                sorted[i].a = Mathf.Atan2(sorted[i].p.y - sorted[0].p.y, sorted[i].p.x - sorted[0].p.x);
            }

            //sort that
            sorted.Sort(CompareCartesianPointAngle);
        }
Example #2
0
 static private int CompareCartesianPointAngle(CartesianPointAngle lhs, CartesianPointAngle rhs)
 {
     return(lhs.a < rhs.a ? -1 : (lhs.a > rhs.a ? 1 : 0));
 }