Skip to content

Ситдиков Сергей#282

Open
s1lenter wants to merge 6 commits into
kontur-courses:masterfrom
s1lenter:master
Open

Ситдиков Сергей#282
s1lenter wants to merge 6 commits into
kontur-courses:masterfrom
s1lenter:master

Conversation

@s1lenter

Copy link
Copy Markdown

var newLocation = new Point(current.X + stepX, current.Y + stepY);
var newCandidate = new Rectangle(newLocation, current.Size);

if (!IntersectsWithAny(newCandidate) && !IsContainedInAny(newCandidate))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Точно нужна проверка на пересечение здесь? В PutNextRectangle и так ведь она есть


private bool IntersectsWithAny(Rectangle rectangle) => _rectangles.Any(r => r.IntersectsWith(rectangle));

private bool IsContainedInAny(Rectangle candidate)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не кажется что этот метод и IntersectsWithAny это одно и то же?


public CircularCloudLayouter(Point center)
{
_center = center;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Давай нейминг поправим. Пусть будет center, и так для других полей. Обычно принято просто с маленькой буквы приватные называть

private readonly List<Rectangle> _rectangles;
private readonly Spiral _spiral;

public CircularCloudLayouter(Point center)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Было бы удобно в этот класс настройки генерации передавать. Тот же шаг например

if (rectangleSize.Width <= 0 || rectangleSize.Height <= 0)
throw new ArgumentException("The size of the rectangle must be a positive number.");

if (_rectangles.Count == 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно использовать Any или if (_rectangles is [])

}
}

throw new InvalidOperationException("Can't place a rectangle.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Этот код вообще будет достигнут когда-то?

return newDistance < currentDistance;
}

private double DistanceToCenter(Rectangle rect)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Этот метод у тебя только для сравнения используется, реальное расстояние не нужно. Поэтому можно например корень не считать. А еще умножение быстрее Math.Pow будет работать

else
break;

if (Math.Abs(current.X - candidate.X) > 100 || Math.Abs(current.Y - candidate.Y) > 100)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

100 вынести в константу хотя бы? Или в какой-то общий класс с настройками генератора облака

public Spiral(Point center, double step)
{
this.center = center;
this.step = step;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Может ли сюда попасть step <= 0 ?

Comment thread cs/TagCloudVisualization/Spiral.cs Outdated
while (true)
{
var radius = step * angle;
var x = center.X + (int)(radius * Math.Cos(angle));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ожидаемое ли это поведение что тут каждый раз точность теряется при приведении к int?

var maxHeight = Math.Max(maxTop, maxBottom) * 2 + 2 * padding;

var maxSide = Math.Max(maxWidth, maxHeight);
maxSide = Math.Max(maxSide, 400);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

400 тоже какое-то магическое число, надо его куда-то вынести


private void DrawRectangles(Graphics graphics, List<Rectangle> rectangles, Point offset)
{
using var pen = new Pen(rectangleColor, 1.5f);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

снова магическое число

var rectangle = layouter.PutNextRectangle(rectangleSize);
placedRectangles.Add(rectangle);

var rectanglePoint = new Point(center.X - rectangleSize.Width / 2, center.Y - rectangleSize.Height / 2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Тут лишний пробел в строке. Отформатируй файлики плиз

placedRectangles.Add(secondRectangle);

rectangle.Should().NotBeNull();
secondRectangle.Should().NotBeNull();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Разве Rectangle может быть null?


for (int i = 1; i <= 10; i++)
{
var rect = layouter.PutNextRectangle(new Size(10 * i - i, 10 * i - i * 2));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не понятно откуда такая сложная формула взялась, и может ее упростить как-то?

}

foreach (var r1 in rectangles)
foreach (var r2 in rectangles.Where(r2 => r2 != r1))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

В общем-то пофиг, но ты каждую пару дважды проверяешь. Сначала r1 с r2, потом наоборот

var height = bounds.Height;

var aspectRatio = (double)Math.Max(width, height) / Math.Min(width, height);
aspectRatio.Should().BeLessThan(1.5);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

В тестах тоже магические числа

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