コード例 #1
0
ファイル: CloudDrawer.cs プロジェクト: Dagepok/tdd
        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);
        }
コード例 #2
0
        public void PutNextRectangle_ShouldReturnRectangle_WithSpecifiedSize()
        {
            var expectedSize = new Size(10, 10);
            var rectangle    = new CircularCloudLayouter(new Point()).PutNextRectangle(expectedSize);

            rectangle.Size.ShouldBeEquivalentTo(expectedSize);
        }
コード例 #3
0
ファイル: CircularCloudLayouter.cs プロジェクト: g0djan/tdd
        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);
        }
コード例 #4
0
        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);
        }
コード例 #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;
         }
     }
 }
コード例 #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));
        }
コード例 #7
0
        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();
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: DvnKor/tdd
        private static void SaveRectangles(CircularCloudLayouter layouter, string fileName)
        {
            var image    = Visualizer.VisualizeLayout(layouter);
            var fullPath = Directory.GetCurrentDirectory() + ExamplesDirectory + fileName;

            image.Save(fullPath, ImageFormat.Png);
        }
コード例 #11
0
ファイル: LayouterShould.cs プロジェクト: shurik236/tdd
            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);
            }
コード例 #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]));
 }
コード例 #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>();
        }
コード例 #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));
        }
コード例 #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();
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: anaym/tddp
        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);
        }
コード例 #17
0
 public void SetUp()
 {
     center   = new Point(300, 300);
     layouter = new CircularCloudLayouter(center);
     layouter.PutNextRectangle(new Size(20, 10));
     layouter.PutNextRectangle(new Size(20, 10));
 }
コード例 #18
0
        public void CircularCloudLayouter_ShouldHave(int count)
        {
            cloud = new CircularCloudLayouter(new Point(200, 200));

            FillCloudWithRandomRectangles(count);

            cloud.Rectangles.Count.Should().Be(count);
        }
コード例 #19
0
ファイル: LayouterShould.cs プロジェクト: shurik236/tdd
            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();
            }
コード例 #20
0
ファイル: LayouterShould.cs プロジェクト: shurik236/tdd
            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);
            }
コード例 #21
0
 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));
     }
 }
コード例 #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));
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: dragrayraptor/tdd
        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");
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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);
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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);
     }
 }
コード例 #30
0
ファイル: Visualizer.cs プロジェクト: Partyinlab/tdd
        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)));
        }