Example #1
0
        public void QuickHull()
        {
            var            ltl         = CGUtils.LowestThenLeftmost(points);
            var            htr         = CGUtils.HighestThenRightmost(points);
            List <CGPoint> leftPoints  = new List <CGPoint>();
            List <CGPoint> rightPoints = new List <CGPoint>();

            leftPoints.Add(ltl);
            rightPoints.Add(htr);
            for (int i = 0; i < points.Count; i++)
            {
                if (points[i] != ltl && points[i] != htr)
                {
                    if (CGUtils.ToLeft(ltl, htr, points[i]))
                    {
                        leftPoints.Add(points[i]);
                    }
                    else
                    {
                        rightPoints.Add(points[i]);
                    }
                }
            }
            leftPoints.Add(htr);
            rightPoints.Add(ltl);
            QuickHull(leftPoints, 0, leftPoints.Count - 1);
            QuickHull(rightPoints, 0, rightPoints.Count - 1);
        }
Example #2
0
        void InitLeftRightChain()
        {
            var htr      = CGUtils.HighestThenRightmost(p.vertices);
            var ltl      = CGUtils.LowestThenLeftmost(p.vertices);
            int index    = 0;
            var leftCurr = htr;

            while (leftCurr != ltl)
            {
                leftChain.Add(index++, leftCurr);
                leftCurr = leftCurr.succ;
            }
            leftChain.Add(index++, ltl);
            var rightCurr = htr.pred;

            while (rightCurr != ltl)
            {
                rightChain.Add(index++, rightCurr);
                rightCurr = rightCurr.pred;
            }
        }