Skip to content

Балашов#262

Open
Balashov2004 wants to merge 18 commits intokontur-courses:masterfrom
Balashov2004:HomeWork
Open

Балашов#262
Balashov2004 wants to merge 18 commits intokontur-courses:masterfrom
Balashov2004:HomeWork

Conversation

@Balashov2004
Copy link

No description provided.

@@ -0,0 +1,3 @@
![img.png](img.png)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А чего у тебя csproj нет у проекта? Или в гит просто не залился? Тяжело из-за этого смотреть код

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Залил


namespace TagsCloudVisualization;

public class WorkWithWorkWithFile : IWorkWithFile

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Странное название класса. Зачем он вообще нужен в проекте?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Убрал, согласен ток усложняет

var stepX = currentRect.X + currentRect.Width / 2 < Center.X ? 1 : -1;
var stepY = currentRect.Y + currentRect.Height / 2 < Center.Y ? 1 : -1;

while ((currentRect.X + currentRect.Width / 2).CompareTo(Center.X) != stepX)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Какое-то немного странное условие. Что если мы шаг поменяем с 1 на 2? У нас вечный цикл будет? Можно как-то его поменять, чтоб таких приколов не было?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил условия на пересечение

private readonly TextProcessor TextProcessor;
private readonly List<WordData> WordDataList;

public CloudRunner(Size imageSize, string outputPath, string wordsFilePath)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут не хотим установить максимум/минимум изображения, которое твоя программа сможет валидно обрабатывать?
Можно аналогичные проверки сделать на число слов/прямоугольников

using var graphics = Graphics.FromImage(bitmap);
graphics.Clear(Color.White);

for (int i = 0; i < Rectangles.Count; i++)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нигде не увидел, может быть такое что текст не поместится в квадратик?

var fontSize = random.Next(MinSize, MaxSize);
using var wordFont = new Font(DefaultFont, fontSize);
var size = MeasureWordSize(word, wordFont);
var storedFont = (Font)wordFont.Clone();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем этот каст?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Убрал, он бы нужен потому что я прописал что
wordFont using сейчас он не using и я убрал
var storedFont = (Font)wordFont.Clone();

throw new InvalidOperationException("Не удалось найти место для прямоугольника.");
}

private bool IsIntersection(Rectangle newRectangle)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно ли как-то быстрее чем за O(n) проверить что все прямоугольники не пересекаются?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вроде получилось сделать быстрее, сейчас проверяем только ячейки, свободны они или нет и если нет, то уже ток эти прямоугольники проверяем на пересечение

private readonly Point Center;
private readonly List<Rectangle> PlacedRectangles = new();
private readonly SpiralPointGenerator SpiralGenerator;
private const int Padding = 2;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Думаю что такие константы, и как например 0.1 ниже в коде можно явно у пользователя спрашивать.
Или например завести единый файл с конфигурацией твоего алгоритма, и брать их оттуда.
Чтобы можно было поигратся с параметрами если надо будет

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил AppSettings где есть дефолтные значения и можно их менять

@@ -0,0 +1,3 @@
![img.png](img.png)
![img_1.png](img_1.png)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему-то картинки не грузятся

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пофиксил

gridSize = appSettings.MaxFontSize;
}

public Rectangle GetNextRectangle(Size rectangleSize)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мелочь конечно, но переименуй в PutNextRectangle (по спецификации задачки)

private readonly Dictionary<Point, List<Rectangle>> grid = new Dictionary<Point, List<Rectangle>>();
private readonly int gridSize;

public CircularCloudLayouter(Point Center, AppSettings appSettings)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Center -> center


namespace TagsCloudVisualization;

public class SpiralPointGenerator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что если я захочу переделать алгоритм генерации точек на какой-то другой. Легко ли его будет прокинуть в CircularCloudLayouter?
Может этот класс должен передаваться в него в конструкторе или еще как-то, и реализовывать общий интерфейс?

{
var rect = rectangles[i];
var data = wordDataList[i];
using var brush = new SolidBrush(appSettings.WordColor);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Точно в цикле наддо создавать?

if (PlacedRectangles.Count == 0)
{
var topLeft = CalculateTopLeft(Center, rectangleSize);
var CenterRect = new Rectangle(topLeft.X, topLeft.Y, rectangleSize.Width, rectangleSize.Height);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

centerRect

public CircularCloudLayouter(Point Center, AppSettings appSettings)
{
this.Center = Center;
this.appSettings = appSettings;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А если AppSettings null?

namespace TagsCloudVisualizationTests;

[TestFixture]
public class CircularCloudLayouterTests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не хватает тестов:
Тест на максимальное количество прямоугольников
Тесты на различные размеры и соотношения сторон
Тесты на edge cases (размер 0, очень большие размеры)
Тесты на то, что действительно получается спираль
Тесты на плотность, что прямоугольники действительно близко стоят а не на рандом разбросаны

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants