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 scg.Dictionary <Vector, scg.List <PointF> > GetRegions(VoronoiGraph graph)
        {
            scg.Dictionary <Vector, scg.List <PointF> > output = new scg.Dictionary <Vector, scg.List <PointF> >();

            int i = 0;

            foreach (Vector v in this.points)
            {
                if (!output.ContainsKey(v))
                {
                    output.Add(v, new scg.List <PointF>());

                    foreach (VoronoiEdge edge in graph.Edges)
                    {
                        AddEdgeForVectorRegion(output, edge, v);
                    }
                }

                this.progress = 30 + (int)(((float)i / (float)this.points.Count) * 55f);

                i++;
            }

            scg.Dictionary <Vector, scg.List <PointF> > newOutput = new scg.Dictionary <Vector, scg.List <PointF> >();

            foreach (scg.KeyValuePair <Vector, scg.List <PointF> > region in output)
            {
                scg.List <WPointF> sort = SortRegion(region);

                newOutput.Add(region.Key, new scg.List <PointF>());

                foreach (WPointF pointf in sort)
                {
                    newOutput[region.Key].Add(pointf.point);
                }
            }

            output = newOutput;

            return(output);
        }