Skip to content
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

TO_PR #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion FractalPainter/App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Windows.Forms;
using Ninject;

namespace FractalPainting.App
{
Expand Down
6 changes: 6 additions & 0 deletions FractalPainter/fractalPainter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@
<StartupObject>FractalPainting.App.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=4.2.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da">
<HintPath>..\packages\Autofac.4.2.1\lib\net45\Autofac.dll</HintPath>
</Reference>
<Reference Include="Castle.Core, Version=3.2.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.3.2.0\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FakeItEasy, Version=3.0.0.0, Culture=neutral, PublicKeyToken=eff28e2146d5fd2c">
<HintPath>..\packages\FakeItEasy.3.0.0-beta002-build000066\lib\net40\FakeItEasy.dll</HintPath>
</Reference>
<Reference Include="FluentAssertions, Version=4.15.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.4.15.0\lib\net45\FluentAssertions.dll</HintPath>
<Private>True</Private>
Expand Down
2 changes: 2 additions & 0 deletions FractalPainter/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="4.2.1" targetFramework="net452" />
<package id="Castle.Core" version="3.2.0" targetFramework="net452" />
<package id="FakeItEasy" version="3.0.0-beta002-build000066" targetFramework="net452" />
<package id="FluentAssertions" version="4.15.0" targetFramework="net452" />
<package id="JetBrains.Annotations" version="10.2.1" targetFramework="net452" />
<package id="Ninject" version="3.2.2.0" targetFramework="net452" />
Expand Down
31 changes: 31 additions & 0 deletions TagsCloudApp/TagsCloudApp/Core/CloudCreator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Drawing;
using TagsCloudApp.Core.Interfaces;

namespace TagsCloudApp.Core
{
public class CloudCreator
{
private readonly ICloudBuilder cloudBuilder;
private readonly IFileReader reader;
private readonly IPrioritySetter prioritySetter;
private readonly ITextPreprocessor textPreprocessor;

public CloudCreator(ICloudBuilder cloudBuilder, IFileReader reader, IPrioritySetter prioritySetter,
ITextPreprocessor textPreprocessor)
{
this.cloudBuilder = cloudBuilder;
this.reader = reader;
this.prioritySetter = prioritySetter;
this.textPreprocessor = textPreprocessor;
}

public TagCloud Create(TagCloudSettings settings)
{
var words = reader.GetFileContetByWords(settings.PathToWords);
var processedWords = textPreprocessor.ProcessWords(words);
var priorities = prioritySetter.SetPriorities(processedWords, settings);
var size = settings.Size;
return new TagCloud(cloudBuilder.BuildCloud(priorities, new Point(size.Width / 2, size.Height / 2)), size);
}
}
}
18 changes: 18 additions & 0 deletions TagsCloudApp/TagsCloudApp/Core/Extensions/PointExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Drawing;

namespace TagsCloudApp.Core.Extensions
{
public static class PointExtensions
{
public static Point SnapByX(this Point p)
{
return new Point(p.X / (p.X != 0 ? Math.Abs(p.X) : 1), 0);
}

public static Point SnapByY(this Point p)
{
return new Point(0, p.Y / (p.Y != 0 ? Math.Abs(p.Y) : 1));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Drawing;

namespace TagsCloudApp.Core.Extensions
{
public static class RectangleExtension
{
public static Point GetCenter(this Rectangle rect) => rect.Location + new Size(rect.Width / 2, rect.Height / 2);
}
}
10 changes: 10 additions & 0 deletions TagsCloudApp/TagsCloudApp/Core/Interfaces/ICloudBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;
using System.Drawing;

namespace TagsCloudApp.Core.Interfaces
{
public interface ICloudBuilder
{
List<TagCloudItem> BuildCloud(List<TagCloudItem> cloudItems, Point newCenter);
}
}
9 changes: 9 additions & 0 deletions TagsCloudApp/TagsCloudApp/Core/Interfaces/IFileReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace TagsCloudApp.Core.Interfaces
{
public interface IFileReader
{
IEnumerable<string> GetFileContetByWords(string path);
}
}
9 changes: 9 additions & 0 deletions TagsCloudApp/TagsCloudApp/Core/Interfaces/IPrioritySetter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace TagsCloudApp.Core.Interfaces
{
public interface IPrioritySetter
{
List<TagCloudItem> SetPriorities(IEnumerable<WordInfo> words, TagCloudSettings settings);
}
}
10 changes: 10 additions & 0 deletions TagsCloudApp/TagsCloudApp/Core/Interfaces/IRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Drawing;

namespace TagsCloudApp.Core.Interfaces
{
public interface IRenderer
{
Image RenderImage(TagCloud cloud);
void SaveImageTo(string path, Image image);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace TagsCloudApp.Core.Interfaces
{
public interface ITextPreprocessor
{
List<WordInfo> ProcessWords(IEnumerable<string> words);
}
}
7 changes: 7 additions & 0 deletions TagsCloudApp/TagsCloudApp/Core/Interfaces/IVizualizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TagsCloudApp.Core.Interfaces
{
public interface IVizualizer
{
void RunVizualizer();
}
}
18 changes: 18 additions & 0 deletions TagsCloudApp/TagsCloudApp/Core/TagCloud.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;
using System.Drawing;

namespace TagsCloudApp.Core
{
public class TagCloud
{
private readonly List<TagCloudItem> items;
public Size Size { get; }
public IEnumerable<TagCloudItem> Items => items.AsReadOnly();

public TagCloud(List<TagCloudItem> items, Size size)
{
this.items = items;
Size = size;
}
}
}
29 changes: 29 additions & 0 deletions TagsCloudApp/TagsCloudApp/Core/TagCloudItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Drawing;

namespace TagsCloudApp.Core
{
public class TagCloudItem
{
public readonly WordInfo WordInfo;
public readonly Color Color;
public readonly Font Font;
public readonly Rectangle Rectangle;

public TagCloudItem(Color color, WordInfo wordInfo, Font font, Rectangle rectangle)
{
Color = color;
WordInfo = wordInfo;
Font = font;
Rectangle = rectangle;
}

public TagCloudItem SetRectangle(Rectangle newRectangle) => new TagCloudItem(Color, WordInfo, Font, newRectangle);

public static TagCloudItem GetRandomFontSize(Random rnd)
{
return new TagCloudItem(Color.AliceBlue, new WordInfo("", 100), new Font("Menlo", rnd.Next(int.MaxValue)),
default(Rectangle));
}
}
}
25 changes: 25 additions & 0 deletions TagsCloudApp/TagsCloudApp/Core/TagCloudSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Drawing;

namespace TagsCloudApp.Core
{
public class TagCloudSettings
{
public static readonly TagCloudSettings DefaultSettings =
new TagCloudSettings(new Font("Meslo", 10), Color.GreenYellow, "test.txt", "test", new Size(500, 500));

public Font Font { get; set; }
public Color Color { get; set; }
public string PathToWords { get; set; }
public string PathToSave { get; set; }
public Size Size { get; set; }

public TagCloudSettings(Font font, Color color, string pathToWords, string pathToSave, Size size)
{
Font = font;
Color = color;
PathToWords = pathToWords;
PathToSave = pathToSave;
Size = size;
}
}
}
41 changes: 41 additions & 0 deletions TagsCloudApp/TagsCloudApp/Core/WordInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace TagsCloudApp.Core
{
public class WordInfo
{
public readonly string Word;
public readonly double Frequency;

public WordInfo(string word, double frequency)
{
Word = word;
Frequency = frequency;
}

private bool Equals(WordInfo other)
{
return string.Equals(Word, other.Word);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((WordInfo) obj);
}

public override int GetHashCode()
{
return Word?.GetHashCode() ?? 0;
}

public static bool operator ==(WordInfo left, WordInfo right)
{
return Equals(left, right);
}

public static bool operator !=(WordInfo left, WordInfo right)
{
return !Equals(left, right);
}
}
}
Loading