-
Notifications
You must be signed in to change notification settings - Fork 306
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
Брайденбихер Виктор Николаевич #238
Open
viteokB
wants to merge
9
commits into
kontur-courses:master
Choose a base branch
from
viteokB:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b0f93d6
Выполненное домашнее задание
viteokB 45ebd90
Исправление недоработок
viteokB e3b1cfb
Откат обновления пакета Newtonsoft.Json
viteokB 7380895
Исправление недочетов CloudClasses.
viteokB 9d0430e
Рефакторинг тестов
viteokB 8500201
Изменение интерефейса ICloudLayouter и его реализация CircularCloudLa…
viteokB 0432d5d
Добавил возможность использовать состояние, для созд. изображения
viteokB c235046
Доработал CircularCloudLayouter
viteokB ee289c4
Поправил тестирование
viteokB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,4 +197,5 @@ FakesAssemblies/ | |
|
||
*Solved.cs | ||
|
||
.idea/ | ||
.idea/ | ||
/cs/tdd.sln.DotSettings |
51 changes: 51 additions & 0 deletions
51
cs/TagsCloudVisualization/CloudClasses/CircularCloudLayouter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Drawing; | ||
using System.Runtime.CompilerServices; | ||
using TagsCloudVisualization.CloudClasses.Interfaces; | ||
|
||
namespace TagsCloudVisualization.CloudClasses | ||
{ | ||
public class CircularCloudLayouter : ICloudLayouter | ||
{ | ||
private readonly List<Rectangle> rectangles = new List<Rectangle>(); | ||
|
||
public readonly ISpiralRayMover RayMover; | ||
|
||
public List<Rectangle> Rectangles => rectangles; | ||
|
||
public CircularCloudLayouter(ISpiralRayMover rayMover) | ||
{ | ||
if (rayMover.Center.X <= 0 || rayMover.Center.Y <= 0) | ||
throw new ArgumentException("IRayMover center Point should have positive X and Y"); | ||
|
||
if (rayMover.RadiusStep <= 0 || rayMover.AngleStep <= 0) | ||
throw new ArgumentException("radiusStep and angleStep should be positive"); | ||
|
||
RayMover = rayMover; | ||
} | ||
|
||
public Rectangle PutNextRectangle(Size rectangleSize) | ||
{ | ||
if (rectangleSize.Width <= 0 || rectangleSize.Height <= 0) | ||
throw new ArgumentException("The height and width of the Rectangle must be greater than 0"); | ||
|
||
var rectangle = Rectangle.Empty; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. можно убрать и создавать внутри цикла |
||
|
||
foreach (var point in RayMover.MoveRay()) | ||
{ | ||
var location = new Point(point.X - rectangleSize.Width / 2, | ||
point.Y - rectangleSize.Height / 2); | ||
|
||
rectangle = new Rectangle(location, rectangleSize); | ||
|
||
// Проверяем, пересекается ли новый прямоугольник с уже существующими | ||
if (!rectangles.Any(r => r.IntersectsWith(rectangle))) | ||
{ | ||
rectangles.Add(rectangle); | ||
return rectangle; | ||
} | ||
} | ||
|
||
throw new InvalidOperationException("No suitable location found for the rectangle."); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
cs/TagsCloudVisualization/CloudClasses/Interfaces/ICloudLayouter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Drawing; | ||
|
||
namespace TagsCloudVisualization.CloudClasses.Interfaces | ||
{ | ||
public interface ICloudLayouter | ||
{ | ||
public Rectangle PutNextRectangle(Size rectangleSize); | ||
|
||
public List<Rectangle> Rectangles { get; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
cs/TagsCloudVisualization/CloudClasses/Interfaces/ISpiralRayMover.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Drawing; | ||
|
||
namespace TagsCloudVisualization.CloudClasses.Interfaces | ||
{ | ||
// Интерфейс для класса, который перемещает луч по спирали, генерируя последовательность точек. | ||
public interface ISpiralRayMover | ||
{ | ||
IEnumerable<Point> MoveRay(); | ||
|
||
public Point Center { get; } | ||
|
||
public double RadiusStep { get; } | ||
|
||
public double AngleStep { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Drawing; | ||
|
||
namespace TagsCloudVisualization.CloudClasses | ||
{ | ||
public class Ray | ||
{ | ||
public double Radius { get; private set; } | ||
|
||
//В радианах | ||
public double Angle { get; private set; } | ||
|
||
public readonly Point StartPoint; | ||
|
||
public Ray(Point startPoint, int radius, int angle) | ||
{ | ||
StartPoint = startPoint; | ||
|
||
Radius = radius; | ||
|
||
Angle = angle; | ||
} | ||
|
||
public void Update(double deltaRadius, double deltaAngle) | ||
{ | ||
Radius += deltaRadius; | ||
Angle += deltaAngle; | ||
} | ||
|
||
public Point EndPoint => new Point | ||
{ | ||
X = StartPoint.X + (int)(Radius * Math.Cos(Angle)), | ||
Y = StartPoint.Y + (int)(Radius * Math.Sin(Angle)) | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Drawing; | ||
using TagsCloudVisualization.CloudClasses.Interfaces; | ||
|
||
namespace TagsCloudVisualization.CloudClasses | ||
{ | ||
public class SpiralRayMover : ISpiralRayMover | ||
{ | ||
private readonly Ray spiralRay; | ||
|
||
private readonly double radiusStep; | ||
|
||
//В радианах | ||
private readonly double angleStep; | ||
|
||
private const double OneRound = Math.PI * 2; | ||
|
||
public SpiralRayMover(Point center, double radiusStep = 1, double angleStep = 5, | ||
int startRadius = 0, int startAngle = 0) | ||
{ | ||
spiralRay = new Ray(center, startRadius, startAngle); | ||
this.radiusStep = radiusStep; | ||
|
||
//Преобразование из градусов в радианы | ||
this.angleStep = angleStep * Math.PI / 180; | ||
} | ||
|
||
public Point Center => spiralRay.StartPoint; | ||
|
||
public double RadiusStep => radiusStep; | ||
|
||
public double AngleStep => angleStep; | ||
|
||
public IEnumerable<Point> MoveRay() | ||
{ | ||
while (true) | ||
{ | ||
yield return spiralRay.EndPoint; | ||
|
||
//Радиус увеличивается на 1 только после полного прохождения круга | ||
spiralRay.Update(radiusStep / OneRound * angleStep, angleStep); | ||
} | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.23 KB
...ctangleNotIntersectsWithOtherRectangles63e7c14d-22d8-4823-8263-c51bf0ef4d6b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13 KB
...ctangleNotIntersectsWithOtherRectanglesb77a115f-bdc6-4b16-b196-1049273d785e.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.Drawing; | ||
using TagsCloudVisualization.CloudClasses; | ||
using TagsCloudVisualization.CloudClasses.Interfaces; | ||
|
||
namespace TagsCloudVisualization.Visualisation | ||
{ | ||
internal class Program | ||
{ | ||
private static void Main(string[] args) | ||
{ | ||
using var tagCloudGenerator = new TagCloudImageGenerator(new Visualiser(Color.Black, 1)); | ||
|
||
var center = new Point(500, 500); | ||
var bitmapSize = new Size(1000, 1000); | ||
|
||
var firstSizes = GenerateRectangleSizes(40, 60, 80, 60, 80); | ||
var secondSizes = GenerateRectangleSizes(100, 10, 40, 20, 30); | ||
var thirdSizes = GenerateRectangleSizes(30, 80, 130, 80, 130); | ||
|
||
var firstLayouter = SetupCloudLayout(center, firstSizes); | ||
var secondLayouter = SetupCloudLayout(center, secondSizes); | ||
var thirdLayouter = SetupCloudLayout(center, thirdSizes); | ||
|
||
using var bitmap1 = tagCloudGenerator.CreateNewBitmap(bitmapSize, firstLayouter.Rectangles); | ||
using var bitmap2 = tagCloudGenerator.CreateNewBitmap(bitmapSize, secondLayouter.Rectangles); | ||
using var bitmap3 = tagCloudGenerator.CreateNewBitmap(bitmapSize, thirdLayouter.Rectangles); | ||
|
||
BitmapSaver.SaveToCorrect(bitmap1, "bitmap_1.png"); | ||
BitmapSaver.SaveToCorrect(bitmap2, "bitmap_2.png"); | ||
BitmapSaver.SaveToCorrect(bitmap3, "bitmap_3.png"); | ||
} | ||
|
||
private static IEnumerable<Size> GenerateRectangleSizes(int count, int minWidth, int maxWidth, int minHeight, int maxHeight) | ||
{ | ||
var sizeBuilder = SizeBuilder.Configure() | ||
.SetCount(count) | ||
.SetWidth(minWidth, maxWidth) | ||
.SetHeight(minHeight, maxHeight) | ||
.Generate(); | ||
|
||
return sizeBuilder; | ||
} | ||
|
||
private static CircularCloudLayouter SetupCloudLayout(Point center, IEnumerable<Size> sizes) | ||
{ | ||
var layouter = new CircularCloudLayouter(new SpiralRayMover(center)); | ||
|
||
sizes.ToList() | ||
.ForEach(size => layouter.PutNextRectangle(size)); | ||
|
||
return layouter; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
<StartupObject>TagsCloudVisualization.Visualisation.Program</StartupObject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="FluentAssertions" Version="6.12.2" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="NUnit" Version="3.14.0" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" /> | ||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="NUnit.Framework" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="CorrectImages\" /> | ||
<Folder Include="FailImages\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Можно сделать интерфейс IRayMover и наследовать от него будущие RayMover'ы, как SpiralRayMover. И сюда передавать IRayMover, чтобы в случае изменения логики распределения прямоугольников просто подменить реализацию RayMover'a