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

базовая реализация структуры, алгоритма распределения и визуализации #247

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions cs/TagsCloudVisualization/TagCloud/CircularCloudLayouter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Drawing;

namespace TagsCloudVisualization.TagCloud;

public class CircularCloudLayouter(Point center)
{
private readonly Point center = center;
private readonly IPositionCalculator calculator = new SpiralPositionCalculator(center);
m1nus0ne marked this conversation as resolved.
Show resolved Hide resolved

public List<Rectangle> Rectangles { get; private set; } = [];

public Rectangle PutNextRectangle(Size rectangleSize)
{
if (rectangleSize.Width <= 0)
throw new ArgumentException("Size width must be positive number");
if (rectangleSize.Height <= 0)
throw new ArgumentException("Size height must be positive number");

var temp = calculator.CalculateNextPosition(Rectangles, rectangleSize); //вывести на ленивую реализацию?
m1nus0ne marked this conversation as resolved.
Show resolved Hide resolved
Rectangles.Add(temp);
return temp;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Drawing;
using System.Globalization;

namespace TagsCloudVisualization.TagCloud;

public class BaseCloudDrawer : ICloudDrawer
{
public void DrawCloud(List<Rectangle> rectangles, string? fileName = null, string? path = null,
m1nus0ne marked this conversation as resolved.
Show resolved Hide resolved
int imageWidth = 500)
{
path ??= Environment.CurrentDirectory;
fileName ??= DateTime.Now.ToOADate().ToString(CultureInfo.InvariantCulture);
using var bitmap = new Bitmap(imageWidth, imageWidth);
using var graphics = Graphics.FromImage(bitmap);
graphics.Clear(Color.White);

foreach (var rectangle in rectangles)
{
graphics.DrawRectangle(new Pen(Color.Black), rectangle);
}

bitmap.Save(Path.Combine(path, fileName + ".png"));
m1nus0ne marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Drawing;

namespace TagsCloudVisualization.TagCloud;

public interface ICloudDrawer
{
public void DrawCloud(List<Rectangle> rectangles, string? fileName, string? path, int imageWidth);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Drawing;

namespace TagsCloudVisualization.TagCloud;

public interface IPositionCalculator
{
public Rectangle CalculateNextPosition(List<Rectangle> rectangles, Size nextRectangleSize);
public bool ValidateRectanglePosition(List<Rectangle> rectangles, Rectangle currentRectangle);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Drawing;

namespace TagsCloudVisualization.TagCloud;

public class SpiralPositionCalculator(Point center) : IPositionCalculator
m1nus0ne marked this conversation as resolved.
Show resolved Hide resolved
{
private double currentAngle = 0.0;
private double currentOffset = 0.0;
private const double offsetDelta = 2;
private const double angleDelta = 0.1;
m1nus0ne marked this conversation as resolved.
Show resolved Hide resolved

public Rectangle CalculateNextPosition(List<Rectangle> rectangles, Size nextRectangleSize)
{
while (true)
{
var newRectangle = RectangleFromParams(nextRectangleSize);
currentAngle += angleDelta;
if (currentAngle >= 2 * Math.PI)
m1nus0ne marked this conversation as resolved.
Show resolved Hide resolved
{
currentAngle = 0;
currentOffset += offsetDelta;
}

if (ValidateRectanglePosition(rectangles, newRectangle))
return newRectangle;
}
}

private Rectangle RectangleFromParams(Size nextRectangleSize)
m1nus0ne marked this conversation as resolved.
Show resolved Hide resolved
{
var x = (int)(center.X + currentOffset * Math.Cos(currentAngle)); //надо центровать?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

По желанию. Я бы центровал, так, на мой взгляд, "правильнее", но это не принципиально

var y = (int)(center.Y + currentOffset * Math.Sin(currentAngle));
var newRectangle = new Rectangle(new Point(x, y), nextRectangleSize);
return newRectangle;
}

public bool ValidateRectanglePosition(List<Rectangle> rectangles, Rectangle currentRectangle)
m1nus0ne marked this conversation as resolved.
Show resolved Hide resolved
m1nus0ne marked this conversation as resolved.
Show resolved Hide resolved
{
return !rectangles.Any(r => r.IntersectsWith(currentRectangle));
}
}
12 changes: 12 additions & 0 deletions cs/tdd.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BowlingGame", "BowlingGame\
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", "{D99B90EA-1C05-417E-80C6-B005531D0545}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TagsCloudVisualizationTest", "TagsCloudVisualizationTest\TagsCloudVisualizationTest.csproj", "{A1FACECA-57BA-4B8F-B804-DC54B8B167C8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +25,14 @@ Global
{B5108E20-2ACF-4ED9-84FE-2A718050FC94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5108E20-2ACF-4ED9-84FE-2A718050FC94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5108E20-2ACF-4ED9-84FE-2A718050FC94}.Release|Any CPU.Build.0 = Release|Any CPU
{D99B90EA-1C05-417E-80C6-B005531D0545}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D99B90EA-1C05-417E-80C6-B005531D0545}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D99B90EA-1C05-417E-80C6-B005531D0545}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D99B90EA-1C05-417E-80C6-B005531D0545}.Release|Any CPU.Build.0 = Release|Any CPU
{A1FACECA-57BA-4B8F-B804-DC54B8B167C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A1FACECA-57BA-4B8F-B804-DC54B8B167C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1FACECA-57BA-4B8F-B804-DC54B8B167C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1FACECA-57BA-4B8F-B804-DC54B8B167C8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions cs/tdd.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=4a98fdf6_002D7d98_002D4f5a_002Dafeb_002Dea44ad98c70c/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Instance" AccessRightKinds="Private" Description="Instance fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a0b4bc4d_002Dd13b_002D4a37_002Db37e_002Dc9c6864e4302/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Any" Description="Types and namespaces"&gt;&lt;ElementKinds&gt;&lt;Kind Name="NAMESPACE" /&gt;&lt;Kind Name="CLASS" /&gt;&lt;Kind Name="STRUCT" /&gt;&lt;Kind Name="ENUM" /&gt;&lt;Kind Name="DELEGATE" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=13FAEF5AD10371439A650EAFEB60E612/@KeyIndexDefined">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=13FAEF5AD10371439A650EAFEB60E612/Applicability/=Live/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=13FAEF5AD10371439A650EAFEB60E612/Categories/=Imported_002010_002E10_002E2016/@EntryIndexedValue">Imported 10.10.2016</s:String>
Expand Down