Пример #1
0
        public void DrawImage_ShouldReturnImageWithCorrectSize()
        {
            var size           = new Size(100, 100);
            var wordRectangles = new List <WordRectangle>
            {
                new WordRectangle("земля", new Rectangle(3, 3, 10, 10)),
                new WordRectangle("привет", new Rectangle(15, 15, 20, 20))
            };

            var image = visualizer.DrawImage(wordRectangles, size);

            image.Size.Should().Be(size);
        }
Пример #2
0
        public Result <None> CreateImage(IInitialSettings settings)
        {
            var words = reader.ReadWords(settings.InputFilePath);

            return(wordProcessor.ProcessWords(words)
                   .Then(wordsWithCount => wordsWithCount.ToList())
                   .Then(wordsWithCount =>
            {
                words = wordsWithCount.Select(e => e.Word);
                var sizes = converter.ConvertToSizes(wordsWithCount);
                var rectangles = layouter.GetRectangles(sizes);
                return imageSizeCalculator.CalculateImageSize(rectangles)
                .Then(calculatedSize => HandleSize(settings, calculatedSize))
                .Then(imageSize => (rect: GetWordRectangles(words, rectangles, imageSize), imageSize));
            })
                   .Then(x => visualizer.DrawImage(x.rect, x.imageSize))
                   .Then(image => saver.SaveImage(image, settings.OutputFilePath)));
        }
Пример #3
0
        public void CreateImage(IInitialSettings settings)
        {
            var words          = reader.ReadWords(settings.InputFilePath);
            var wordsWithCount = wordProcessor.ProcessWords(words).ToList();
            var sizes          = converter.ConvertToSizes(wordsWithCount);
            var rectangles     = layouter.GetRectangles(sizes);
            var imageSize      = settings.ImageSize;

            if (imageSize == Size.Empty)
            {
                imageSize = imageSizeCalculator.CalculateImageSize(rectangles);
            }
            rectangles = rectanglesTransformer.TransformRectangles(rectangles, imageSize);
            words      = wordsWithCount.Select(e => e.Word);
            var wordRectangles = words.Zip(rectangles, (w, r) => new WordRectangle(w, r)).ToList();
            var image          = visualizer.DrawImage(wordRectangles, imageSize);

            saver.SaveImage(image, settings.OutputFilePath);
        }