-
Notifications
You must be signed in to change notification settings - Fork 31
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
Черных Илья #17
base: master
Are you sure you want to change the base?
Черных Илья #17
Changes from 19 commits
0a6e494
0638e5f
551a45a
734981b
10b0ed0
318ea03
35a611a
b550659
02c81bd
040f8ad
6c4c791
dfc0b82
f532610
ffee430
b9e717c
6f74ab0
d61fc93
fd9b4ec
b538562
74730db
80cf168
6f47276
320960a
1d93229
f3e92f8
e90d4b5
08dc670
c09d029
2af1197
2f7958e
687f1bf
77d21b4
ea7d0df
f9958fe
0297174
b4fc174
ff41811
f5136ac
24be459
45c7767
2b8d684
5e0eab5
4644e0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Здесь будут скучные слова |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Drawing; | ||
using TagsCloudVisualization.LayoutAlgorithms; | ||
|
||
namespace TagsCloudVisualization.CircularCloudLayouters; | ||
|
||
public class CircularCloudLayouter : ICircularCloudLayouter | ||
{ | ||
private readonly ILayoutAlgorithm layoutAlgorithm; | ||
private readonly List<Rectangle> addedRectangles = []; | ||
|
||
public CircularCloudLayouter(ILayoutAlgorithm layoutAlgorithm) | ||
{ | ||
this.layoutAlgorithm = layoutAlgorithm; | ||
} | ||
|
||
public Rectangle PutNextRectangle(Size rectangleSize) | ||
{ | ||
Rectangle rectangle; | ||
|
||
do | ||
{ | ||
var nextPoint = layoutAlgorithm.CalculateNextPoint(); | ||
|
||
var rectangleLocation = nextPoint - rectangleSize / 2; | ||
|
||
rectangle = new Rectangle(rectangleLocation, rectangleSize); | ||
|
||
} while (IntersectWithAddedRectangles(rectangle)); | ||
|
||
addedRectangles.Add(rectangle); | ||
|
||
return rectangle; | ||
} | ||
|
||
private bool IntersectWithAddedRectangles(Rectangle rectangle) | ||
{ | ||
return addedRectangles.Any(addedRectangle => addedRectangle.IntersectsWith(rectangle)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Drawing; | ||
|
||
namespace TagsCloudVisualization.CircularCloudLayouters; | ||
|
||
public interface ICircularCloudLayouter | ||
{ | ||
Rectangle PutNextRectangle(Size rectangleSize); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace TagsCloudVisualization; | ||
|
||
public class CommandLineOptions | ||
{ | ||
// Здесь будут описаны возможности командной строки | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Autofac; | ||
|
||
namespace TagsCloudVisualization.Di; | ||
|
||
public class DiContainer | ||
{ | ||
public static IContainer Configure() | ||
{ | ||
var builder = new ContainerBuilder(); | ||
|
||
// Здесь будут зарегистрированы все зависимости | ||
|
||
return builder.Build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace TagsCloudVisualization.FileReaders; | ||
|
||
public interface IFileReader | ||
{ | ||
bool CanRead(string pathToFile); | ||
|
||
string Read(string pathToFile); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace TagsCloudVisualization.FileReaders; | ||
|
||
public class TxtFileReader : IFileReader | ||
{ | ||
public bool CanRead(string pathToFile) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public string Read(string pathToFile) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Drawing; | ||
|
||
namespace TagsCloudVisualization.LayoutAlgorithms; | ||
|
||
public class CircularLayoutAlgorithm : ILayoutAlgorithm | ||
{ | ||
private readonly Point center; | ||
private readonly double stepIncreasingAngle; | ||
private readonly int stepIncreasingRadius; | ||
private double currentAngleOfCircle; | ||
private double currentRadiusOfCircle; | ||
private const double OneDegree = Math.PI / 180; | ||
private const double FullCircleRotation = 2 * Math.PI; | ||
|
||
public CircularLayoutAlgorithm(Point center, double stepIncreasingAngle = OneDegree, int stepIncreasingRadius = 1) | ||
{ | ||
if (stepIncreasingRadius <= 0) | ||
throw new ArgumentException("The parameter 'stepIncreasingRadius' is less than or equal to zero"); | ||
if (stepIncreasingAngle == 0) | ||
throw new ArgumentException("The parameter 'stepIncreasingAngle' is zero"); | ||
|
||
this.center = center; | ||
this.stepIncreasingAngle = stepIncreasingAngle; | ||
this.stepIncreasingRadius = stepIncreasingRadius; | ||
} | ||
|
||
public Point CalculateNextPoint() | ||
{ | ||
var x = center.X + (int)(currentRadiusOfCircle * Math.Cos(currentAngleOfCircle)); | ||
var y = center.Y + (int)(currentRadiusOfCircle * Math.Sin(currentAngleOfCircle)); | ||
|
||
currentAngleOfCircle += stepIncreasingAngle; | ||
|
||
// проверяем не прошли ли целый круг или равен ли текущий радиус нулю | ||
if (currentAngleOfCircle > FullCircleRotation || currentRadiusOfCircle == 0) | ||
{ | ||
currentAngleOfCircle = 0; | ||
currentRadiusOfCircle += stepIncreasingRadius; | ||
} | ||
|
||
return new Point(x, y); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Drawing; | ||
|
||
namespace TagsCloudVisualization.LayoutAlgorithms; | ||
|
||
public interface ILayoutAlgorithm | ||
{ | ||
Point CalculateNextPoint(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Drawing.Imaging; | ||
using Autofac; | ||
using TagsCloudVisualization; | ||
using TagsCloudVisualization.Di; | ||
using TagsCloudVisualization.Visualization; | ||
|
||
var container = DiContainer.Configure(); | ||
var cloudCreator = container.Resolve<TagCloudCreator>(); | ||
|
||
var image = cloudCreator.CreateImage(); | ||
|
||
ImageSaver.Save(image, "", "", ImageFormat.Png); | ||
|
||
Console.WriteLine("Hello, World!"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Drawing; | ||
|
||
namespace TagsCloudVisualization.Settings; | ||
|
||
public class ImageSettings | ||
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. Настройки цветов стоит либо расширить, либо сократить |
||
{ | ||
public ImageSettings(int width, int height, Color backgroundColor) | ||
{ | ||
Width = width; | ||
Height = height; | ||
BackgroundColor = backgroundColor; | ||
} | ||
|
||
public int Width { get; } | ||
|
||
public int Height { get; } | ||
|
||
public Color BackgroundColor { get; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Drawing; | ||
using TagsCloudVisualization.TagLayouters; | ||
using TagsCloudVisualization.Visualization; | ||
|
||
namespace TagsCloudVisualization; | ||
|
||
public class TagCloudCreator | ||
{ | ||
private readonly ITagLayouter tagLayouter; | ||
private readonly IImageDrawer imageDrawer; | ||
|
||
public TagCloudCreator(ITagLayouter tagLayouter, IImageDrawer imageDrawer) | ||
{ | ||
this.tagLayouter = tagLayouter; | ||
this.imageDrawer = imageDrawer; | ||
} | ||
|
||
public Bitmap CreateImage() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using TagsCloudVisualization.Tags; | ||
|
||
namespace TagsCloudVisualization.TagLayouters; | ||
|
||
public interface ITagLayouter | ||
{ | ||
IEnumerable<Tag> GetTags(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using TagsCloudVisualization.CircularCloudLayouters; | ||
using TagsCloudVisualization.Tags; | ||
using TagsCloudVisualization.TextHandlers; | ||
|
||
namespace TagsCloudVisualization.TagLayouters; | ||
|
||
public class TagLayouter : ITagLayouter | ||
{ | ||
private readonly ICircularCloudLayouter circularCloudLayouter; | ||
private readonly ITextHandler textHandler; | ||
|
||
public TagLayouter(ICircularCloudLayouter circularCloudLayouter, ITextHandler textHandler) | ||
{ | ||
this.textHandler = textHandler; | ||
this.circularCloudLayouter = circularCloudLayouter; | ||
} | ||
|
||
public IEnumerable<Tag> GetTags() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Drawing; | ||
|
||
namespace TagsCloudVisualization.Tags; | ||
|
||
public interface ITag | ||
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. Не стоит делать лишние интерфейсы. Для класса просто содержащего данные нет смысла создавать интерфейс |
||
{ | ||
string Content { get; } | ||
|
||
int Size { get; } | ||
|
||
Rectangle Rectangle { get; } | ||
|
||
FontFamily Font { get; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Drawing; | ||
|
||
namespace TagsCloudVisualization.Tags; | ||
|
||
public class Tag : ITag | ||
{ | ||
public Tag(string content, int size, Rectangle rectangle, FontFamily font) | ||
{ | ||
Content = content; | ||
Size = size; | ||
Rectangle = rectangle; | ||
Font = font; | ||
} | ||
|
||
public string Content { get; } | ||
|
||
public int Size { get; } | ||
|
||
public Rectangle Rectangle { get; } | ||
|
||
public FontFamily Font { get; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Autofac" Version="8.2.0" /> | ||
<PackageReference Include="System.Drawing.Common" Version="9.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace TagsCloudVisualization.TextHandlers; | ||
|
||
public interface ITextHandler | ||
{ | ||
/// <summary> | ||
/// Метод-обработчик исходного текста | ||
/// </summary> | ||
/// <returns> Словарь: слово - количество </returns> | ||
Dictionary<string, int> HandleText(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using TagsCloudVisualization.FileReaders; | ||
|
||
namespace TagsCloudVisualization.TextHandlers; | ||
|
||
public class TextHandler : ITextHandler | ||
{ | ||
private readonly IFileReader fileReader; | ||
|
||
public TextHandler(IFileReader fileReader) | ||
{ | ||
this.fileReader = fileReader; | ||
} | ||
|
||
public Dictionary<string, int> HandleText() | ||
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. Название GetWordsCount будет более точно отображать суть метода, даже если он будет содержать в себе дополнительную предобработку текста |
||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Drawing; | ||
using TagsCloudVisualization.Tags; | ||
|
||
namespace TagsCloudVisualization.Visualization; | ||
|
||
public interface IImageDrawer | ||
{ | ||
Bitmap Draw(IEnumerable<Tag> tags); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Drawing; | ||
using TagsCloudVisualization.Settings; | ||
using TagsCloudVisualization.Tags; | ||
|
||
namespace TagsCloudVisualization.Visualization; | ||
|
||
public class ImageDrawer : IImageDrawer | ||
{ | ||
private readonly ImageSettings imageSettings; | ||
|
||
public ImageDrawer(ImageSettings imageSettings) | ||
{ | ||
this.imageSettings = imageSettings; | ||
} | ||
|
||
public Bitmap Draw(IEnumerable<Tag> tags) | ||
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. Не всегда стоит упарываться с абстракциями над типами, в большинстве случаев будет лучше указывать в аргументах конкретный тип с которым будешь работать, например список или массив. Если хочется обеспечить неизменность коллекции, то есть readonly типы колекций |
||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Drawing; | ||
using System.Drawing.Imaging; | ||
|
||
namespace TagsCloudVisualization.Visualization; | ||
|
||
public class ImageSaver | ||
{ | ||
public static void Save(Bitmap bitmap, string filePath, string fileName, ImageFormat imageFormat) | ||
{ | ||
bitmap.Save(Path.Combine(filePath, fileName), imageFormat); | ||
} | ||
} |
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.
Лучше сразу сделать IWordsReader, пускай возвращает коллекицю строк, по слову в строке