PlacedWordRectangle PlaceFirstWord(WordRectangle rectangle)
 {
     var position = new Point(
         (Size.Width - rectangle.Size.Width) / 2,
         (Size.Height - rectangle.Size.Height) / 2
     );
     return new PlacedWordRectangle(rectangle, position);
 }
        PlacedWordRectangle PlaceNextWord(WordRectangle rectangle,
            IReadOnlyList<PlacedWordRectangle> alreadyPlacedWords)
        {
            if (rectangle.Size.Width > Size.Width || rectangle.Size.Height > Size.Height)
                return null;

            var triesCount = Math.Max(50, alreadyPlacedWords.Count * 2);
            for (var i = 0; i < triesCount; i++)
            {
                var curPosition = new Point(
                    random.Next(0, Size.Width - rectangle.Size.Width),
                    random.Next(0, Size.Height - rectangle.Size.Height)
                );
                var curRect = new Rectangle(curPosition, rectangle.Size);

                var hasIntersection = alreadyPlacedWords
                    .Select(placedWord => new Rectangle(placedWord.Position, placedWord.Size))
                    .Any(curRect.IntersectsWith);
                if (!hasIntersection)
                    return new PlacedWordRectangle(rectangle, curPosition);
            }
            return null;
        }
 public PlacedWordRectangle(WordRectangle rectangle, Point position)
     : base(rectangle)
 {
     Position = position;
 }
 static PlacedWordRectangle SwapViewCoordinates(PlacedWordRectangle rectangle)
 {
     var newRectangle = new WordRectangle(rectangle.Word, rectangle.Font, SwapSizeElements(rectangle.Size));
     return new PlacedWordRectangle(newRectangle, SwapPointCoordinates(rectangle.Position));
 }
        PlacedWordRectangle PlaceNextWord(WordRectangle rectangle,
            IReadOnlyList<PlacedWordRectangle> alreadyPlacedWords)
        {
            if (rectangle.Size.Width > Size.Width || rectangle.Size.Height > Size.Height)
                return null;

            var triesCount = Math.Max(50, alreadyPlacedWords.Count * 2);
            PlacedWordRectangle bestRectangle = null;
            double? bestRate = null;
            for (var i = 0; i < triesCount; i++)
            {
                var placeMethod = placeMethods[random.Next(placeMethods.Length)];
                var position = placeMethod(rectangle.Size, alreadyPlacedWords);
                if (position == null)
                    continue;
                var view = new PlacedWordRectangle(rectangle, position.Value);

                var rate = DistanceSquareBetween(GetViewCenter(view), imageCenter);
                if (bestRate == null || rate < bestRate)
                {
                    bestRectangle = view;
                    bestRate = rate;
                }
            }
            return bestRectangle;
        }
 public WordRectangle(WordRectangle rectangle)
 {
     Word = rectangle.Word;
     Font = rectangle.Font;
     Size = rectangle.Size;
 }