Conversation
- написал основную структуру логику CircularCloudLayouter и Spiral
cs/TagsCloudVisualization/Spiral.cs
Outdated
| const double radiusStep = 1.0; | ||
|
|
||
| angle += angleStep; | ||
| var radius = radiusStep * angle; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
cs/TagsCloudVisualization/Spiral.cs
Outdated
| } | ||
|
|
||
| private bool IntersectsWithAny(Rectangle rect) => | ||
| Rectangles.Any(r => r.IntersectsWith(rect)); |
There was a problem hiding this comment.
Будет очень дорого, если будет, например, много мелких квадратов. Попробуй эвристику похитрее придумать. Или посмотри в сторону геометрических алгоритмов.
cs/TagsCloudVisualization/Spiral.cs
Outdated
|
|
||
| namespace TagCloud; | ||
|
|
||
| public class Spiral(Point center) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
cs/TagsCloudVisualization/Spiral.cs
Outdated
| private bool IntersectsWithAny(Rectangle rect) => | ||
| Rectangles.Any(r => r.IntersectsWith(rect)); | ||
|
|
||
| private Rectangle MoveToCenter(Rectangle rect) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| public Rectangle PutNextRectangle(Size rectangleSize) | ||
| { | ||
| if (rectangleSize.Width <= 0 || rectangleSize.Height <= 0) | ||
| throw new ArgumentException("Размер прямоугольника должен быть положительным"); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
|
||
| namespace TagCloud; | ||
|
|
||
| public class CircularCloudLayouter(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("Размер прямоугольника должен быть положительным"); | ||
|
|
||
| return RectangleSpiral.TryAddRectangleInCenter(rectangleSize, out var rectangle) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
cs/TagsCloudVisualization/Spiral.cs
Outdated
|
|
||
| public Rectangle AddRectangle(Size rectangleSize) | ||
| { | ||
| while (true) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
cs/TagsCloudVisualization/Spiral.cs
Outdated
| return false; | ||
| } | ||
|
|
||
| #region Helpers |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples", "Samples\Samples.csproj", "{B5108E20-2ACF-4ED9-84FE-2A718050FC94}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TagsCloudVisualization", "TagsCloudVisualization\TagsCloudVisualization.csproj", "{6580A616-7832-45F4-8A9A-E9A5D4FE64A8}" |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
- доп. проект с примерами использования библиотеки - визуализация упавших тестов - переделал логику
| @@ -0,0 +1,129 @@ | |||
| using System.Drawing; | |||
| using ArgumentOutOfRangeException = System.ArgumentOutOfRangeException; | |||
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| private readonly List<Rectangle> rectangles = []; | ||
| public IReadOnlyCollection<Rectangle> Rectangles => rectangles.AsReadOnly(); | ||
|
|
||
| private int failureStreak; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| private int failureStreak; | ||
| private int currentStep = DefaultStep; | ||
|
|
||
| private const int DefaultStep = 1; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| public IReadOnlyCollection<Rectangle> Rectangles => rectangles.AsReadOnly(); | ||
|
|
||
| private int failureStreak; | ||
| private int currentStep = DefaultStep; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| } | ||
| } | ||
|
|
||
| private Rectangle MoveAtTheWay(Rectangle rectangle, int dx, int dy, bool toCenter, int maxStep) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
|
||
| var boundingWidth = maxX - minX; | ||
| var boundingHeight = maxY - minY; | ||
| var boundingArea = (double)boundingWidth * boundingHeight; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| [SetUp] | ||
| public void Setup() | ||
| { | ||
| center = new Point(0, 0); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| namespace TagCloudTests; | ||
|
|
||
| [TestFixture] | ||
| public class CloudVisualizationConfigBuilderTests |
There was a problem hiding this comment.
Хвалю за попытку хорошо сделать, но кажется, что тесты на билдер излишни - как-будто присваивание в этих тестах проверяешь, не? :)
| } | ||
|
|
||
| [Test] | ||
| public void ConfigIsNull_ShouldThrowArgumentNullException() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| } | ||
|
|
||
| [Test] | ||
| public void GetNextPoint_ShouldReturnDifferentPoints() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| return Math.Sqrt(halfW * halfW + halfH * halfH); | ||
| } | ||
|
|
||
| private static bool CirclesIntersect(Point c1, double r1, Point c2, double r2) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| var distX = Math.Abs(center.X - shiftedCenter.X); | ||
| var distY = Math.Abs(center.Y - shiftedCenter.Y); | ||
|
|
||
| if (dx != 0 && distX >= bestDistX || |
| }; | ||
|
|
||
| var shiftedCenter = GetCenter(shifted); | ||
| var distX = Math.Abs(center.X - shiftedCenter.X); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| private Rectangle FindBestPositionWithExponentialStep(Rectangle rectangle, int dx, int dy) | ||
| { | ||
| var best = rectangle; | ||
| var bestCenter = GetCenter(best); |
There was a problem hiding this comment.
Хороший кандидат на метод-расширение для Rectangle.
There was a problem hiding this comment.
не очень удобно его выносить, т.к. завязан на внутренних методах и некоторых полях
| private void AddRectangle(Rectangle rect) | ||
| { | ||
| rectangles.Add(rect); | ||
| var c = GetCenter(rect); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
cs/TagsCloudVisualization/Spiral.cs
Outdated
| { | ||
| placementFailureStreak++; | ||
|
|
||
| currentAngleStepMultiplier = |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| [Repeat(100)] | ||
| public void PutNextRectangle_CloudForManyRectangles_ShouldBeDense() | ||
| { | ||
| var random = new Random(42); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| return this; | ||
| } | ||
|
|
||
| public CloudVisualizationConfigBuilder WithBackground(Rgba32 color) |
There was a problem hiding this comment.
Никогда, никогда, никогда, НИКОГДА в публичных методах своих интерфейсов НЕ ИСПОЛЬЗУЙ ТИПЫ ИЗ БИБЛИОТЕК-ЗАВИСИМОСТЕЙ! Во-первых, если пользователь на них завяжется, то ты не сможешь сменить библиотеку для отрисовки под капотом у конфиг-билдера без поломки обратной совместимости с кодом пользователя, а во-вторых если он тоже использует ту же зависимость, но другой версии, могут быть очень дурацкие конфликты с зависимостями. В целом нюгет неплохо их разрешает, но всё-равно от пользователя надо стараться прятать транзитивные зависимости, для этого есть специальные инструкции в *.csproj файлах - если интересно, гугли про PrivateAssets и другие похожие инструкции.


No description provided.