Exemple #1
0
        private scg.List <WPointF> SortRegion(scg.KeyValuePair <Vector, scg.List <PointF> > region)
        {
            scg.List <WPointF> sort = new scg.List <WPointF>();
            scg.List <PointF>  lp   = region.Value;

            float x = (float)region.Key[0];
            float y = (float)region.Key[1];

            for (int k = 0; k < region.Value.Count; k++)
            {
                PointF originalPoint = lp[k];

                PointF dir = new PointF(x, y);
                dir.X -= originalPoint.X;
                dir.Y -= originalPoint.Y;
                dir.X *= (float)(1.0 / Math.Sqrt(dir.X * dir.X + dir.Y * dir.Y));

                double alfa = Math.Acos(dir.X);

                if (dir.Y < 0)
                {
                    alfa *= -1;
                }

                WPointF p = new WPointF()
                {
                    point = originalPoint, weight = alfa
                };
                sort.Add(p);
            }

            sort.Sort(new Comparison <WPointF>(PointComparer));
            return(sort);
        }
Exemple #2
0
        private int PointComparer(WPointF obj1, WPointF obj2)
        {
            if (obj1.weight > obj2.weight)
            {
                return(1);
            }
            else if (obj1.weight < obj2.weight)
            {
                return(-1);
            }

            return(0);
        }