Пример #1
0
        public void LinearDistribution(int xmin, int xmax, int ymin, int ymax, int count, int mScale, int maskValue = 0, int[,] mask = null, Func <int, int, bool> op = null, Func <int, int, int> formula = null)
        {
            points = new List <VoronoiPoint>();

            if (mask != null)
            {
                int index = 0;
                for (int x = xmin + 2; x < xmax; x += 1)
                {
                    for (int y = ymin + 2; y < ymax; y += 1)
                    {
                        VoronoiPoint vp  = new VoronoiPoint(x, y);
                        bool         res = op(mask[x * mScale, y * mScale], maskValue);
                        if (res && ClosestDis(vp.GetXY) > 50 && mask.GetSurroundingPoints(new HashSet <int[]>(), vp.GetXY, xmax, ymax, op, 0).Count == 0)
                        {
                            points.Add(new VoronoiPoint(x, y));
                            index++;

                            if (index >= count)
                            {
                                return;
                            }
                        }
                    }
                }
            }

            return;
        }
Пример #2
0
 protected bool IsUnique(VoronoiPoint p)
 {
     if (!points.ContainsItem(p))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #3
0
        public static bool ContainsPoint(this List <VoronoiPoint> voronoiPoints, VoronoiPoint search)
        {
            int find = voronoiPoints.FindIndex(x => x.x == search.x && x.y == search.y);

            if (find == -1)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #4
0
        protected List <VoronoiPoint> TraceBoundaries(int xmin, int xmax, int ymin, int ymax, int[,] mask = null, int mScale = 1, int maskValue = 0, Func <int, int, bool> op = null)
        {
            List <VoronoiPoint> boundaries = new List <VoronoiPoint>();

            for (int x = xmin + 2; x < xmax; x += 1)
            {
                for (int y = ymin + 2; y < ymax; y += 1)
                {
                    VoronoiPoint vp  = new VoronoiPoint(x, y);
                    bool         res = op(mask[x * mScale, y * mScale], maskValue);
                    if (res && ClosestDis(vp.GetXY, boundaries) > 25 && mask.GetSurroundingPoints(new HashSet <int[]>(), vp.GetXY, xmax, ymax, op, 0).Count > 0)
                    {
                        boundaries.Add(new VoronoiPoint(x, y));
                    }
                }
            }
            return(boundaries);
        }
Пример #5
0
        public void GeneratePoints(int xmin, int xmax, int ymin, int ymax, int distanceBetween, int count, int[,] mask = null, int mScale = 1, int maskValue = 0, Func <int, int, bool> op = null, bool traceBounds = false)
        {
            if (traceBounds)
            {
                points = TraceBoundaries(xmin, xmax, ymin, ymax, mask, mScale, maskValue, (x, y) => x < y);
            }
            else
            {
                points = new List <VoronoiPoint>();
            }

            count = count - points.Count();

            if (mask != null)
            {
                for (int i = 0; i < count; i++)
                {
                    int rx = (int)(rnd.Next(xmin, xmax));
                    int ry = (int)(rnd.Next(ymin, ymax));

                    VoronoiPoint point         = new VoronoiPoint(rx, ry);
                    double       squeezeFactor = 0.1;

                    while (!op(mask[rx * mScale, ry * mScale], maskValue) || !IsUnique(point) || ClosestDis(point.GetXY) < distanceBetween - squeezeFactor)
                    {
                        rx             = (int)(rnd.Next(xmin, xmax));
                        ry             = (int)(rnd.Next(ymin, ymax));
                        point          = new VoronoiPoint(rx, ry);
                        squeezeFactor += 0.1;
                    }
                    points.Add(new VoronoiPoint(rx, ry));
                    squeezeFactor = 0.1;
                }
                return;
            }


            for (int i = 0; i < count; i++)
            {
                points.Add(new VoronoiPoint(rnd.Next(xmin, xmax), rnd.Next(ymin, ymax)));
            }
        }