Skip to content

Копытов Михаил#266

Open
Mihail3141 wants to merge 13 commits into
kontur-courses:masterfrom
Mihail3141:master
Open

Копытов Михаил#266
Mihail3141 wants to merge 13 commits into
kontur-courses:masterfrom
Mihail3141:master

Conversation

@Mihail3141

Copy link
Copy Markdown


public class CircularCloudLayouter
{
private List<Rectangle> Rects { get; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rects -> Rectangles

Comment on lines +47 to +67
public IEnumerable<Rectangle> GetCircularCloudRectangles(int count, Size rectangleSize, double coefficient = 0)
{
if (count <= 0)
throw new ArgumentException("Count must be positive");
if (coefficient == 0)
{
for (var i = 0; i < count; i++)
yield return PutNextRectangle(rectangleSize);
yield break;
}

if (coefficient is < 0 or > 1)
throw new ArgumentException("Coefficient must be between 0 and 1");
for (var i = 0; i < count; i++)
{
var rnd = random.NextDouble() + coefficient;
var rndWidth = (int)Math.Round(rectangleSize.Width * rnd);
var rndHeight = (int)Math.Round(rectangleSize.Height * rnd);
yield return PutNextRectangle(new Size(rndWidth, rndHeight));
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Лучше вынести из лейаутера во внешний провайдер прямоугольников (или позиций прямоугольников)

Comment thread cs/TagsCloudVisualization/ImageSaver.cs Outdated

public static class ImageSaver
{
public static void ImageSave(Bitmap bitmap, string fileName)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ImageSave -> SaveImag


namespace TagsCloudVisualization;

public class PointGenerator

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Необходимо вынести интерфейс

Comment on lines +13 to +16
if (center.X < 0 || center.Y < 0)
throw new ArgumentException("Center coordinates must be non-negative");
if (imageSize.Width <= 0 || imageSize.Height <= 0)
throw new ArgumentException("Image size must be positive");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Эти проверки повторяются в двух местах, может их лучше оставить только там, где эти параметры используются?

yield break;
}

if (coefficient is < 0 or > 1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Что за коэффициент? Из названия не понятно?

Comment thread cs/TagsCloudVisualization/Render.cs Outdated

namespace TagsCloudVisualization;

public class Render(Size imageSize)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Render -> Renderer или TagCloudRenderer. Необходимо вынести интерфейс ICloudRenderer


act.Should().Throw<ArgumentException>()
.WithMessage("Center should be greater than 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.

Лишнее


act.Should().Throw<ArgumentException>()
.WithMessage("Center must be inside image bounds");
;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Лишнее

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 (center.X <= 0 || center.Y <= 0)
throw new ArgumentException("Center should be greater than 0");
Rectangles = new List<Rectangle>();
spiralPointGenerator = new SpiralPointGenerator(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.

Зависимости должны поставляться через конструктор. Работа должна проводиться через интерфейс, а не напрямую с классом

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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


private int maxPointCount = 10000;

public void SetMaxPointCount(int maxPointCount)

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 points = spiralPointGenerator
.GetPoints()
.Take(maxPointCount);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Кажется для maxPointCount стоит уточнить нейминг. По факту это точки, которые возьмём на один прямоугольник.

foreach (var point in points)
{
var rectangle = new Rectangle(point, rectangleSize);
if (Rectangles.Any(rectangle.IntersectsWith))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

На самом деле тут имеет смысл смотреть пересечения от последних раставленных прямоугольников, т.к. они ближе всего будут к потенциальному расположению прямоугольника. Так более часто будем проверять меньшее количество прямоугольников


public class CircularCloudLayouter
{
private List<Rectangle> Rectangles { get; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Почему через геттер получаем, а не сделать просто readonly поле?


public interface ICloudRenderer
{
public Bitmap CreateRectangleCloud(IEnumerable<Rectangle> rectangles);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Через интерфейс нужно работать

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Не совсем понял, что требуется

using System.Drawing;
using System.Drawing.Imaging;

namespace TagsCloudVisualization.Render;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Неймспейсы в папке поправить


namespace TagsCloudVisualization.Render;

public static class ImageSaver

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Тоже интерфейс нужен

{
public static void Save(Bitmap bitmap, string fileName)
{
var projectDir = Directory.GetParent(Environment.CurrentDirectory)!.Parent!.Parent!.FullName;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А если нет такой вложенности? Если я запущу это из коренной папки что будет?


public interface IPointGenerator
{
public IEnumerable<Point> GetPoints();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Интерфейс не используется


namespace TagsCloudVisualizationTest;

public class SpiralPointProviderTest

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Такие тесты должны быть на CircularCloudLayouter, а не на класс провайдера.

var circleRadius = Geometry.FindMinRadius(rectangles, validCenter);
var packingDensity = Geometry.GetRectanglesPackingDensity(rectangles, circleRadius);

packingDensity.Should().BeGreaterThan(0.4);

@tripples25 tripples25 Dec 5, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не маловато ли значение? По-хорошему должно быть больше 0.6-0.7. Попробуй тут большее количество прямоугольников расположить

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Если сделать 500 прямоугольников, то 0.6 достигает, но работает медленно. Для 150 достигает 0.5. Но вроде визуально прямоугольники расположены достаточно плотно.
cloud

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