Exemplo n.º 1
0
        public static BenTools.Data.HashSet <IntSite> GenerateInternalSites(int width, int height, int resolution, int internalSitesCount, Func <int, int, IntPoint> randomGenerator)
        {
            if (width < 1 || height < 1 || internalSitesCount < 1)
            {
                throw new ArgumentException("'width', 'height', 'internalSitesCount' should be greater than zero.");
            }
            if (resolution < 2)
            {
                throw new ArgumentException("'resolution' should be greater than one.");
            }

            int fullWidth, fullHeight, halfX, halfY, margin;

            CalculateGridParameters(width, height, resolution, out fullWidth, out fullHeight, out halfX, out halfY, out margin);

            int deviation = resolution / 2 - 1;

            var randomSites = new BenTools.Data.HashSet <IntSite>();

            for (int i = 0; i < internalSitesCount; i++)
            {
                var randomPoint = randomGenerator(-halfX + resolution + margin, halfX - resolution - margin);

                randomSites.Add(new IntSite
                {
                    IsBorder = false,
                    X        = randomPoint.X,
                    Y        = randomPoint.Y
                });
            }


            return(randomSites);
        }
Exemplo n.º 2
0
        public BenTools.Data.HashSet <Vector> GetSampledData()
        {
            BenTools.Data.HashSet <Vector> sampledData = new BenTools.Data.HashSet <Vector>();
            sampledData.Clear();

            if (sampledImage == null)
            {
                return(null);
            }

            for (int i = 0; i < sampledImage.GetLength(0); i++)
            {
                for (int j = 0; j < sampledImage.GetLength(1); j++)
                {
                    Color?c = sampledImage[i, j];

                    if (c != null)
                    {
                        sampledData.Add(new Vector(i, j));
                    }
                }
            }

            return(sampledData);
        }
Exemplo n.º 3
0
        public static BenTools.Data.HashSet<IntSite> GenerateInternalSites(int width, int height, int resolution, int internalSitesCount, Func<int, int, IntPoint> randomGenerator)
        {
            if (width < 1 || height < 1 || internalSitesCount < 1)
            {
                throw new ArgumentException("'width', 'height', 'internalSitesCount' should be greater than zero.");
            }
            if (resolution < 2)
            {
                throw new ArgumentException("'resolution' should be greater than one.");
            }

            int fullWidth, fullHeight, halfX, halfY, margin;
            CalculateGridParameters(width, height, resolution, out fullWidth, out fullHeight, out halfX, out halfY, out margin);

            int deviation = resolution / 2 - 1;

            var randomSites = new BenTools.Data.HashSet<IntSite>();

            for (int i = 0; i < internalSitesCount; i++)
            {
                var randomPoint = randomGenerator(-halfX + resolution + margin, halfX - resolution - margin);

                randomSites.Add(new IntSite
                {
                    IsBorder = false,
                    X = randomPoint.X,
                    Y = randomPoint.Y
                });
            }

            return randomSites;
        }
Exemplo n.º 4
0
        public static BenTools.Data.HashSet <IntSite> GenerateTileBorder(int width, int height, int resolution, Func <int, int, IntPoint> randomGenerator)
        {
            if (width < 1 || height < 1)
            {
                throw new ArgumentException("'width', 'height' should be greater than zero.");
            }
            if (resolution < 2)
            {
                throw new ArgumentException("'resolution' should be greater than one.");
            }

            int fullWidth, fullHeight, halfX, halfY, margin;

            CalculateGridParameters(width, height, resolution, out fullWidth, out fullHeight, out halfX, out halfY, out margin);

            int deviation = resolution / 2 - 1;

            var vBorderSites = new BenTools.Data.HashSet <IntSite>();

            for (int i = margin, j = resolution; i < height - margin; i++, j += resolution)
            {
                vBorderSites.Add(new IntSite {
                    IsBorder = true, X = 0, Y = j
                });
                vBorderSites.Add(new IntSite {
                    IsBorder = false, X = resolution, Y = j
                });
            }

            var vBorderShifted = Shift(vBorderSites, -halfX, -halfY);
            var randomVBorder  = new BenTools.Data.HashSet <IntSite>();

            vBorderShifted.ForEach(s => {
                var randomShift = randomGenerator(-deviation, deviation);
                s.X            += randomShift.X;
                s.Y            += randomShift.Y;

                randomVBorder.Add(s);
            });

            var vBorderRepeated = RepeatHorizontally(randomVBorder, fullWidth - resolution);

            var hBorderSites = new BenTools.Data.HashSet <IntSite>();

            for (int i = margin, j = resolution; i < width - margin; i++, j += resolution)
            {
                hBorderSites.Add(new IntSite {
                    IsBorder = true, X = j, Y = 0
                });
                hBorderSites.Add(new IntSite {
                    IsBorder = false, X = j, Y = resolution
                });
            }

            var hBorderShifted = Shift(hBorderSites, -halfX, -halfY);
            var randomHBorder  = new BenTools.Data.HashSet <IntSite>();

            hBorderShifted.ForEach(s =>
            {
                var randomShift = randomGenerator(-deviation, deviation);
                s.X            += randomShift.X;
                s.Y            += randomShift.Y;

                randomHBorder.Add(s);
            });

            var hBorderRepeated = RepeatVertically(randomHBorder, fullHeight - resolution);

            var resultingBorder = new BenTools.Data.HashSet <IntSite>();

            resultingBorder.AddRange(vBorderRepeated);
            resultingBorder.AddRange(hBorderRepeated);

            resultingBorder.AddRange(new[]
            {
                new IntSite {
                    IsBorder = true, X = -halfX, Y = -halfY
                },
                new IntSite {
                    IsBorder = true, X = -halfX, Y = halfY
                },
                new IntSite {
                    IsBorder = true, X = halfX, Y = -halfY
                },
                new IntSite {
                    IsBorder = true, X = halfX, Y = halfY
                },
            });

            return(resultingBorder);
        }
Exemplo n.º 5
0
        public static BenTools.Data.HashSet<IntSite> GenerateTileBorder(int width, int height, int resolution, Func<int,int,IntPoint> randomGenerator)
        {
            if (width < 1 || height < 1)
            {
                throw new ArgumentException("'width', 'height' should be greater than zero.");
            }
            if (resolution < 2)
            {
                throw new ArgumentException("'resolution' should be greater than one.");
            }

            int fullWidth, fullHeight, halfX, halfY, margin;
            CalculateGridParameters(width, height, resolution, out fullWidth, out fullHeight, out halfX, out halfY, out margin);

            int deviation = resolution / 2 - 1;

            var vBorderSites = new BenTools.Data.HashSet<IntSite>();
            for (int i = margin, j = resolution; i < height - margin; i++, j += resolution)
            {
                vBorderSites.Add(new IntSite { IsBorder = true, X = 0, Y = j });
                vBorderSites.Add(new IntSite { IsBorder = false, X = resolution, Y = j });
            }

            var vBorderShifted = Shift(vBorderSites, -halfX, -halfY);
            var randomVBorder = new BenTools.Data.HashSet<IntSite>();

            vBorderShifted.ForEach(s => {
                var randomShift = randomGenerator(-deviation, deviation);
                s.X += randomShift.X;
                s.Y += randomShift.Y;

                randomVBorder.Add(s);
            });

            var vBorderRepeated = RepeatHorizontally(randomVBorder, fullWidth - resolution);

            var hBorderSites = new BenTools.Data.HashSet<IntSite>();
            for (int i = margin, j = resolution; i < width - margin; i++, j += resolution)
            {
                hBorderSites.Add(new IntSite { IsBorder = true, X = j, Y = 0 });
                hBorderSites.Add(new IntSite { IsBorder = false, X = j, Y = resolution });
            }

            var hBorderShifted = Shift(hBorderSites, -halfX, -halfY);
            var randomHBorder = new BenTools.Data.HashSet<IntSite>();
            hBorderShifted.ForEach(s =>
            {
                var randomShift = randomGenerator(-deviation, deviation);
                s.X += randomShift.X;
                s.Y += randomShift.Y;

                randomHBorder.Add(s);
            });

            var hBorderRepeated = RepeatVertically(randomHBorder, fullHeight - resolution);

            var resultingBorder = new BenTools.Data.HashSet<IntSite>();
            resultingBorder.AddRange(vBorderRepeated);
            resultingBorder.AddRange(hBorderRepeated);

            resultingBorder.AddRange(new[]
            {
                new IntSite{ IsBorder = true, X = -halfX, Y = -halfY},
                new IntSite{ IsBorder = true, X = -halfX, Y = halfY},
                new IntSite{ IsBorder = true, X = halfX, Y = -halfY},
                    new IntSite{ IsBorder = true, X = halfX, Y = halfY},
            });

            return resultingBorder;
        }