-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ватлин Алексей #242
base: master
Are you sure you want to change the base?
Ватлин Алексей #242
Conversation
var layouter = new CircularCloudLayouter(new(0, 0), 0.1, 0.1); | ||
var size = new Size(width, height); | ||
|
||
Action action = () => layouter.PutNextRectangle(size); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
cs/TagsCloudVisualization/PointsGenerators/SpiralPointsGenerator.cs
Outdated
Show resolved
Hide resolved
|
||
public class CircularCloudLayouter : ICircularCloudLayouter | ||
{ | ||
private Point center; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
if (rectangleSize.Width <= 0 || rectangleSize.Height <= 0) | ||
throw new ArgumentException($"{nameof(rectangleSize)} height and width must be greater than zero"); | ||
var rectangle = GetNextRectangle(rectangleSize); | ||
while (rectangles.Any(rectangle.IntersectsWith)) //����� ������������ do while |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
public class CircularCloudLayouter : ICircularCloudLayouter | ||
{ | ||
private Point center; | ||
private List<Rectangle> rectangles = []; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
return centerOfRectangle; | ||
} | ||
|
||
private Rectangle CreateRectangleWithCenter(Point center, Size rectangleSize) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
private Rectangle GetNextRectangle(Size rectagleSize) | ||
{ | ||
var rectanglePosition = spiral.GetNextPointPosition(); | ||
var centerOfRectangle = CreateRectangleWithCenter(rectanglePosition, rectagleSize); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
return rectangle; | ||
} | ||
|
||
private Rectangle GetNextRectangle(Size rectagleSize) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
[TestCase(1, 0, TestName = "WhenHeightIsZero")] | ||
[TestCase(-1, 1, TestName = "WhenWidthIsNegative")] | ||
[TestCase(1, -1, TestName = "WhenHeightIsNegative")] | ||
public void LayouterPutNextRectangle_ShouldThrowArgumentException(int width, int height) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
} | ||
|
||
[Test] | ||
public void FirstRectang_ShouldBeInCenter() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
var rectangleSize = new Size(10, 10); | ||
|
||
var actualRectangle = layouter.PutNextRectangle(rectangleSize); | ||
var expectedRectangle = new Rectangle( |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
||
[Test] | ||
[Repeat(10)] | ||
public void AllRectanglesCenter_ShoulBeLikeInitCenter() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
||
[Test] | ||
[Repeat(10)] | ||
public void Rectangles_ShouldNotHaveIntersects() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тест-метод должен говорить, какой метод мы тестируем
|
||
[Test] | ||
[Repeat(10)] | ||
public void RectanglesDensity_ShouldBeMax() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
var layouter = CloudGenerator.GenerateCloud(100); | ||
rectanglesInTest = layouter.GetRectangles(); | ||
|
||
var actualCenter = GetCenterOfAllRectangles(rectanglesInTest); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
var layouter = CloudGenerator.GenerateCloud(100); | ||
rectanglesInTest = layouter.GetRectangles(); | ||
|
||
var rectanglesArea = rectanglesInTest.Sum(rect => rect.Width * rect.Height); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
||
private double GetDistanceBetweenPoints(Point point1, Point point2) | ||
=> Math.Sqrt(Math.Pow(point1.X - point2.X, 2) + Math.Pow(point1.Y - point2.Y, 2)); | ||
} |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
public const double LayoutStep = 0.1; | ||
public const double LayoutAngleOffset = 0.1; | ||
public const string ImagesDirectory = "images"; | ||
} |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
||
public static class CloudGenerator | ||
{ | ||
public static CircularCloudLayouter GenerateCloud(int rectanglesNumber = Constans.RectanglesNumber) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
{ | ||
public static CircularCloudLayouter GenerateCloud(int rectanglesNumber = Constans.RectanglesNumber) | ||
{ | ||
var center = new Point(Constans.ImageWidth / 2, Constans.ImageHeight / 2); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
var cloudLayouter = new CircularCloudLayouter(center); | ||
var random = new Random(); | ||
var rectangles = new Rectangle[rectanglesNumber]; | ||
rectangles = rectangles |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
random.Next(Constans.MinRectangleSize, Constans.MaxRectangleSize)))) | ||
.ToArray(); | ||
return cloudLayouter; | ||
} |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
IEnumerable<Rectangle> rectangles, | ||
Size bitmapSize, | ||
string directory = Constans.ImagesDirectory, | ||
string currentPath = null |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
bitmap.Save(path, ImageFormat.Jpeg); | ||
} | ||
|
||
private Color GetRandomColor() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
) | ||
{ | ||
var bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height); | ||
var graphics = Graphics.FromImage(bitmap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не диспоузим этот объект - потеря памяти
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using graphics = ...
…енератор точек, создал readme, перенес тесты из отдельного проекта в основной
{ | ||
public Point Center { get; } | ||
public List<Rectangle> GeneratedRectangles { get; } | ||
private IPointsGenerator spiral { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вижу тебе понравились свойства)
Для spiral логичнее использовать поле с пометкой readonly
- таким образом зафиксируем, что оно инициализируется в конструкторе, и больше в логике этого класса не меняется.
А сейчас это private
свойство до которого никто не может достучаться)
|
||
public static class ICircularCloudLayouterExtensions | ||
{ | ||
public static void GenerateCloud(this ICircularCloudLayouter cloudLayouter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По код-стайлу, если в одну строку сигнатура метода не вмещается, то лучше все параметры с новой строки.
private readonly double step = 0.1; | ||
private readonly double angleOffset = 0.1; | ||
private readonly Point center; | ||
private double angle = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше переименовать на currentAngle
private readonly Point center; | ||
private double angle = 0; | ||
|
||
public SpiralPointsGenerator(Point center) => this.center = center; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В этом случае как-то теряются "дефолтные значения", давай сделаем один конструктор, но с опциональными параметрами:
public SpiralPointsGenerator(Point center, double step = 0.1, double angleOffset = 0.1)
{ ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
соответственно инициализацию у полей можно будет убрать
private readonly double step;
private readonly double angleOffset;
private readonly Point center;
private double angle;
|
||
namespace TagsCloudVisualization.Tests.CircularCloudLayouterTests; | ||
|
||
[TestFixture, Parallelizable] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Для Parallelizable
нужно указать, что "не параллельно"
|
||
public CircularCloudLayouter(Point center, int step, int angleOffset) | ||
{ | ||
GeneratedRectangles = new List<Rectangle>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
центр забыл проинициализировать
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно наследоваться от других конструкторов и писать только различающуюся логику
public CircularCloudLayouter(Point center, int step, int angleOffset) : this(center)
{
spiral = new SpiralPointsGenerator(center, step, angleOffset);
}
@SlavikGh0st
Решенные 3 задания с примерами работы программы (вид количество фигур/шаг/угол). Также при запуске и провале теста создаются соответствующие изображения в bin\Debug\net8.0+нужная директория внутри папок самих проектов