Exemple #1
0
        public static void DrawToBmp(string path, CircularCloudLayouter cloud)
        {
            var pens = new List <Pen>
            {
                Pens.Red,
                Pens.Blue,
                Pens.Aqua,
                Pens.BlueViolet,
                Pens.Chartreuse,
                Pens.Brown,
                Pens.DarkGreen,
                Pens.DarkBlue,
                Pens.DarkGoldenrod,
                Pens.DeepPink,
                Pens.Orange
            };

            var bitmap   = new Bitmap(400, 400);
            var graphics = Graphics.FromImage(bitmap);

            for (var i = cloud.Rectangles.Count - 1; i >= 0; i--)
            {
                graphics.DrawRectangle(pens[i % pens.Count], cloud.Rectangles[i]);
            }
            bitmap.SetPixel(cloud.Center.X, cloud.Center.Y, Color.Black);
            bitmap.Save(path);
        }
        public void PutNextRectangle_ShouldReturnRectangle_WithSpecifiedSize()
        {
            var expectedSize = new Size(10, 10);
            var rectangle    = new CircularCloudLayouter(new Point()).PutNextRectangle(expectedSize);

            rectangle.Size.ShouldBeEquivalentTo(expectedSize);
        }
Exemple #3
0
        public void CircularCloudLayouter_AddCentre_Correctly(int x, int y)
        {
            var expectedCenter = new Point(x, y);
            var resultCenter   = new CircularCloudLayouter(expectedCenter).center;

            resultCenter.Should().Be(expectedCenter);
        }
        static void Main(string[] args)
        {
            var allSizes = new List <Size>();
            var rnd      = new Random();

            for (var i = 0; i < 100; i++)
            {
                var nextHeight = rnd.Next(20, 25);
                //var nextHeight = 40;
                var nextWidth = rnd.Next(nextHeight * 2, nextHeight * 6);
                //var nextWidth = 160;
                allSizes.Add(new Size(nextWidth, nextHeight));
            }

            var circularCloudLayouter = new CircularCloudLayouter(new Point(0, 5));

            foreach (var r in allSizes)
            {
                circularCloudLayouter.PutNextRectangle(r);
            }

            var render = new TagsCloudRenderer();

            render.RenderIntoFile("img.png", circularCloudLayouter.TagsCloud);
        }
Exemple #5
0
 private void CalculateImageBorders(CircularCloudLayouter layout)
 {
     foreach (var rectangle in layout.Rectangles)
     {
         if (rectangle.X <= _minX)
         {
             _minX = rectangle.X;
         }
         if (rectangle.X + rectangle.Width >= _maxX)
         {
             _maxX = rectangle.X + rectangle.Width;
         }
         if (rectangle.Y - rectangle.Height <= _minY)
         {
             _minY = rectangle.Y - rectangle.Height;
         }
         if (rectangle.Y >= _maxY)
         {
             _maxY = rectangle.Y;
         }
         if (rectangle.Y - rectangle.Height <= _yHeight)
         {
             _yHeight = rectangle.Y - rectangle.Height;
         }
     }
 }
Exemple #6
0
        public static IEnumerable <Rectangle> CreateRandomCircularLayout(Point center,
                                                                         float thickness, int minRectSize, int maxRectSize, int amountOfRectangles)
        {
            var layouter = new CircularCloudLayouter(center, new ArchimedesSpiral(center, thickness));

            return(CreateRandomLayout(layouter, minRectSize, maxRectSize, amountOfRectangles));
        }
        public void MustPositioningAsDenseCircle()
        {
            var origin = new Point(0, 0);

            currentCircularCloudLayouter = new CircularCloudLayouter(origin);
            var size       = new Size(3, 3);
            var rectangles = new List <Rectangle>();

            for (var i = 0; i < 360; i++)
            {
                var rectangle = currentCircularCloudLayouter.PutNextRectangle(size);
                rectangles.Add(rectangle);
            }

            var width        = rectangles.GetWidth();
            var height       = rectangles.GetHeight();
            var radius       = Math.Max(width, height);
            var circleSquare = Math.PI * Math.Pow(radius, 2);
            var rectsSquare  = rectangles.Select(r => r.Size.Square).Sum();

            var areRectsWithinCircle = rectangles
                                       .Select(r => r.Center)
                                       .Select(rectCenter => Vector.GetLength(origin, rectCenter))
                                       .All(radiusVector => radiusVector <= radius);
            var isCircleDense = circleSquare - rectsSquare < circleSquare * 0.5;
            var result        = areRectsWithinCircle && isCircleDense;

            result.Should().BeTrue();
        }
Exemple #8
0
        public static IEnumerable <Rectangle> CreateRandomCircularLayout(Point center, ISpiral spiral, int minRectSize,
                                                                         int maxRectSize, int amountOfRectangles)
        {
            var layouter = new CircularCloudLayouter(center, spiral);

            return(CreateRandomLayout(layouter, minRectSize, maxRectSize, amountOfRectangles));
        }
Exemple #9
0
        public static void Draw(string fileName, CircularCloudLayouter layouter)
        {
            var pens = new List <Pen>
            {
                new Pen(new SolidBrush(Color.Blue)),
                new Pen(new SolidBrush(Color.Green)),
                new Pen(new SolidBrush(Color.Black)),
                new Pen(new SolidBrush(Color.Red)),
                new Pen(new SolidBrush(Color.Yellow)),
                new Pen(new SolidBrush(Color.Magenta))
            };
            const int border   = 10;
            var       width    = layouter.SizeOfCloud.Width + border;
            var       height   = layouter.SizeOfCloud.Height + border;
            var       bitmap   = new Bitmap(width, height);
            var       graphics = Graphics.FromImage(bitmap);

            graphics.Clear(Color.White);
            graphics.TranslateTransform(border / 2 - layouter.LeftDownPointOfCloud.X,
                                        border / 2 - layouter.LeftDownPointOfCloud.Y);

            var colorIndex = 0;

            layouter.Rectangles.ForEach(rect =>
            {
                colorIndex = (colorIndex + 1) % pens.Count;
                graphics.DrawRectangle(pens[colorIndex], rect);
            });

            bitmap.Save(fileName);
        }
Exemple #10
0
        private static void SaveRectangles(CircularCloudLayouter layouter, string fileName)
        {
            var image    = Visualizer.VisualizeLayout(layouter);
            var fullPath = Directory.GetCurrentDirectory() + ExamplesDirectory + fileName;

            image.Save(fullPath, ImageFormat.Png);
        }
Exemple #11
0
            public void Initialize_WithGivenCenter(int x, int y)
            {
                var expectedCenter = new Point(x, y);

                _layouter = new CircularCloudLayouter(new Point(x, y));
                _layouter.Center.Should().Be(expectedCenter);
            }
Exemple #12
0
 public void ThrowsArgumentException_IfNotPositiveSizeOfRectangle(int width, int height)
 {
     cloudCenter           = new Point(50, 50);
     circularCloudLayouter = new CircularCloudLayouter(cloudCenter);
     rectangleSizes.Add(new Size(width, height));
     Assert.Throws <ArgumentException>(() => circularCloudLayouter.PutNextRectangle(rectangleSizes[0]));
 }
Exemple #13
0
        public void PutNextRectangle_ThrowArgumentException_WhenIncorrectDirectionsOfRectangle(int width, int height)
        {
            cloudLayouter = new CircularCloudLayouter(new Point(0, 0));
            Action action = () => cloudLayouter.PutNextRectangle(new Size(width, height));

            action.Should().Throw <ArgumentException>();
        }
Exemple #14
0
        public static Bitmap CreateBitmap(Point center, Size pictureSize, IEnumerable <Size> sizes)
        {
            var rectangles = new CircularCloudLayouter(center, pictureSize).PutMultipleRectangles(sizes);
            var visualizer = new Visualizer(pictureSize);

            return(visualizer.GetRectangleLayoutBitmap(rectangles));
        }
Exemple #15
0
        public void PlaceRectanglesNotFarFromEachOtherThan10Px()
        {
            var center = new Point(200, 200);
            var size   = new Size(10, 10);

            cloudLayouter = new CircularCloudLayouter(center);
            var centerRectangle = cloudLayouter.PutNextRectangle(size);
            var rectangles      = new List <Rectangle>();

            for (int i = 0; i < 490; i += 1)
            {
                rectangles.Add(cloudLayouter.PutNextRectangle(size));
            }
            cloudLayouter.GetVisualization();
            var orderedRectangles = rectangles
                                    .OrderBy(r => r.X)
                                    .ToArray();

            orderedRectangles
            .Where((r, i) => i < orderedRectangles.Length - 1)
            .Select((r, i) => new { First = r, Second = orderedRectangles[i + 1] })
            .All(rp => Math.Abs(rp.First.X - rp.Second.X) < 10)
            .Should()
            .BeTrue();
            orderedRectangles = rectangles
                                .OrderBy(r => r.Y)
                                .ToArray();
            orderedRectangles
            .Where((r, i) => i < orderedRectangles.Length - 1)
            .Select((r, i) => new { First = r, Second = orderedRectangles[i + 1] })
            .All(rp => Math.Abs(rp.First.Y - rp.Second.Y) < 10)
            .Should()
            .BeTrue();
        }
Exemple #16
0
        private static void Main(string[] args)
        {
            var commandLineParser = PrepareCommandLineParser();

            if (commandLineParser.Parse(args).HelpCalled)
            {
                return;
            }

            var task = commandLineParser.Object;
            var data = Statistic.FromTask(task);

            if (task.XmlSource == null)
            {
                data.ToXml(new StreamWriter(File.OpenWrite("stat.xml")));
            }

            var layoter = new CircularCloudLayouter(Vector.Zero, new Vector((int)(task.Ratio * 10), (int)(10 / task.Ratio)));
            var max     = data.Count != 0 ? data.Max(p => p.Value) : 1;
            var min     = data.Count != 0 ? data.Min(p => p.Value) : 0;

            if (data.Count == 0)
            {
                Console.WriteLine("Data is not founded");
            }
            var tags     = TagCloud.FromLimits(layoter, task.MinWordHeight, task.MaxWordWidth, max, min);
            var renderer = new TagCloudRenderer(task.RenderBackgroundRectangles);

            renderer.AddManyColors(Color.DarkBlue, Color.OrangeRed, Color.DarkGreen);
            tags.PutManyTags(data);
            renderer.RenderToBitmap(tags).Save(task.OutFileName, ImageFormat.Png);
            Process.Start(task.OutFileName);
        }
 public void SetUp()
 {
     center   = new Point(300, 300);
     layouter = new CircularCloudLayouter(center);
     layouter.PutNextRectangle(new Size(20, 10));
     layouter.PutNextRectangle(new Size(20, 10));
 }
Exemple #18
0
        public void CircularCloudLayouter_ShouldHave(int count)
        {
            cloud = new CircularCloudLayouter(new Point(200, 200));

            FillCloudWithRandomRectangles(count);

            cloud.Rectangles.Count.Should().Be(count);
        }
Exemple #19
0
            public void PlaceTwoRects_WithoutIntersections(int centerX, int centerY, int w1, int h1, int w2, int h2)
            {
                _layouter = new CircularCloudLayouter(new Point(centerX, centerY));
                var firstRectangle  = _layouter.PutNextRectangle(new Size(w1, h1));
                var secondRectangle = _layouter.PutNextRectangle(new Size(w2, h2));

                firstRectangle.IntersectsWith(secondRectangle).Should().BeFalse();
            }
Exemple #20
0
            public void PlaceFirstRect_InCenter(int centerX, int centerY, int width, int height)
            {
                _layouter = new CircularCloudLayouter(new Point(centerX, centerY));
                var nextRectangle     = _layouter.PutNextRectangle(new Size(width, height));
                var expectedRectangle = new Rectangle(centerX - width / 2, centerY - height / 2, width, height);

                nextRectangle.Should().Be(expectedRectangle);
            }
 private void PrepareTestLayout(Point center, Size minRectangleSize, Size maxRectangleSize, int sampleCount)
 {
     layouter = new CircularCloudLayouter(center);
     for (int i = 0; i < sampleCount; i++)
     {
         layouter.PutNextRectangle(GetRandomRectangle(minRectangleSize, maxRectangleSize));
     }
 }
Exemple #22
0
        public void OneTimeSetUp()
        {
            var rnd    = new Random();
            var center = rnd.NextPoint(-100, 100, -100, 100);

            layouter = new CircularCloudLayouter(center);
            layouter.PutRectangles(rnd.NextSizes(10, 30, 2, 5, 10, 50));
        }
Exemple #23
0
        public static void Main(string[] args)
        {
            var sizes      = Generator.GetRandomSizesList(20, 20, 20, 20, 100, new Random());
            var layouter   = new CircularCloudLayouter(new Point(0, 0));
            var rectangles = layouter.PutNextRectangles(sizes);

            RectanglesVisualizer.SaveNewRectanglesLayout(rectangles, "Images", "Image.png");
        }
        public void PutNextRectangle_PutOneRectangle_NeedBeOnCenterPoint(int centerX, int centerY)
        {
            var newCloutLayouter = new CircularCloudLayouter(new Point(centerX, centerY));

            var rectangle = newCloutLayouter.PutNextRectangle(new Size(213, 313));

            rectangle.Location.Should().Be(newCloutLayouter.Center);
        }
        public static IEnumerable <Rectangle> GenerateRectangles(int rectanglesCount, Size maxSize, Size minSize)
        {
            var sizes      = GenerateSizes(rectanglesCount, maxSize, minSize);
            var layouter   = new CircularCloudLayouter();
            var rectangles = sizes.Select(layouter.PutNextRectangle);

            return(rectangles);
        }
Exemple #26
0
        public void CircularCloudLayouter_FirstRectangle_HaveRightPosition()
        {
            cloud = new CircularCloudLayouter(new Point(200, 200));

            FillCloudWithRandomRectangles(1);

            cloud.Rectangles.First().Location.Should().Be(new Point(200, 200));
        }
Exemple #27
0
        private static Bitmap CreateBitmap(int count, Func <int, Tag> fabric)
        {
            var layouter   = new CircularCloudLayouter(Center);
            var tags       = Enumerable.Range(0, count).Select(fabric).ToArray();
            var visualizer = new CircularCloudVisualizer();

            return(visualizer.Visualize(layouter, tags));
        }
Exemple #28
0
        public void PutNextRectangle_ShouldThrowArgumentException_WhenGetsIncorrectSize(int width, int height)
        {
            var generatorCirclePoints = new EternityGeneratorCirclePoints(0, 0);
            var cloudLayouter         = new CircularCloudLayouter(generatorCirclePoints);
            var size = new Size(width, height);

            Assert.Throws <ArgumentException>(() => cloudLayouter.PutNextRectangle(size));
        }
Exemple #29
0
 static void Main(string[] args)
 {
     for (int i = 0; i < 3; i++)
     {
         var layouter   = new CircularCloudLayouter(new Point(1000, 1000));
         var rectangles = CircularCloudLayouterGenerator.GenerateRectanglesSet(layouter, 50, 100, 150, 50, 75);
         CircularCloudLayouterDrawer.DrawRectanglesSet(layouter.Size, $"tag-cloud-{i + 1}.png", rectangles);
     }
 }
Exemple #30
0
        private static Rectangle GetImageRectangle(CircularCloudLayouter cloud)
        {
            var minX = cloud.Rectangles.Min(rect => rect.Left);
            var minY = cloud.Rectangles.Min(rect => rect.Top);
            var maxX = cloud.Rectangles.Max(rect => rect.Right);
            var maxY = cloud.Rectangles.Max(rect => rect.Bottom);

            return(new Rectangle(new Point(minX, minY), new Size(maxX - minX, maxY - minY)));
        }