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

Яценко Ирина #219

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
14 changes: 14 additions & 0 deletions cs/TagsCloudVisualization/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
50 changes: 50 additions & 0 deletions cs/TagsCloudVisualization/CircularCloudLayouter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;

namespace TagsCloudVisualization
{
public class CircularCloudLayouter : ICircularCloudLayouter
{
public Point Center { get; set; }
dmnovikova marked this conversation as resolved.
Show resolved Hide resolved
public List<Rectangle> Rectangles = new List<Rectangle>();
private double _angle;
dmnovikova marked this conversation as resolved.
Show resolved Hide resolved
private readonly int _step = 1;

public CircularCloudLayouter(Point center)
{
Center = center;
}

public Rectangle PutNextRectangle(Size rectangleSize)
{
if (rectangleSize.Width <= 0
dmnovikova marked this conversation as resolved.
Show resolved Hide resolved
|| rectangleSize.Height <= 0)
throw new ArgumentException();

var rectangle = new Rectangle(FindNewRectanglePosition(), rectangleSize);

while (HaveIntersection(rectangle)) rectangle.Location = FindNewRectanglePosition();
dmnovikova marked this conversation as resolved.
Show resolved Hide resolved

Rectangles.Add(rectangle);
return rectangle;
dmnovikova marked this conversation as resolved.
Show resolved Hide resolved
}

public Point FindNewRectanglePosition(double deltaAngle = 0.1)
dmnovikova marked this conversation as resolved.
Show resolved Hide resolved
{
dmnovikova marked this conversation as resolved.
Show resolved Hide resolved
_angle += deltaAngle;
var k = _step / (2 * Math.PI);
var radius = k * _angle;

var position = new Point(
Center.X + (int)(Math.Cos(_angle) * radius),
Center.Y + (int)(Math.Sin(_angle) * radius));

return position;
dmnovikova marked this conversation as resolved.
Show resolved Hide resolved
}

public bool HaveIntersection(Rectangle newRectangle) =>
Rectangles.Any(rectangle => rectangle.IntersectsWith(newRectangle));
}
}
10 changes: 10 additions & 0 deletions cs/TagsCloudVisualization/ICircularCloudLayouter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Drawing;

namespace TagsCloudVisualization
{
public interface ICircularCloudLayouter
{
Point Center { get; set; }
Rectangle PutNextRectangle(Size rectangleSize);
}
}
14 changes: 14 additions & 0 deletions cs/TagsCloudVisualization/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Drawing;

namespace TagsCloudVisualization
{
internal class Program
{
public const int ImageWidth = 800;
public const int ImageHeight = 800;
public static void Main(string[] args)
{
new CircularCloudLayouter(new Point(ImageWidth / 2, ImageHeight / 2));
}
}
}
36 changes: 36 additions & 0 deletions cs/TagsCloudVisualization/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Общие сведения об этой сборке предоставляются следующим набором
// набора атрибутов. Измените значения этих атрибутов для изменения сведений,
// связанные с этой сборкой.
[assembly: AssemblyTitle("TagsCloudVisualization")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TagsCloudVisualization")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
// из модели COM задайте для атрибута ComVisible этого типа значение true.
[assembly: ComVisible(false)]

// Следующий GUID представляет идентификатор typelib, если этот проект доступен из модели COM
[assembly: Guid("4f909c58-0835-4f9f-ba74-9530c220d676")]

// Сведения о версии сборки состоят из указанных ниже четырех значений:
//
// Основной номер версии
// Дополнительный номер версии
// Номер сборки
// Номер редакции
//
// Можно задать все значения или принять номера сборки и редакции по умолчанию
// используя "*", как показано ниже:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
85 changes: 85 additions & 0 deletions cs/TagsCloudVisualization/TagsCloudVisualization.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.4.5.0\build\net462\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.4.5.0\build\net462\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.4.0.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.4.0.0\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4F909C58-0835-4F9F-BA74-9530C220D676}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>TagsCloudVisualization</RootNamespace>
<AssemblyName>TagsCloudVisualization</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentAssertions, Version=6.12.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.6.12.0\lib\net47\FluentAssertions.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.4.0.0\lib\net462\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="nunit.framework.legacy, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.4.0.0\lib\net462\nunit.framework.legacy.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.0\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ICircularCloudLayouter.cs" />
<Compile Include="CircularCloudLayouter.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.4.0.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.4.0.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.4.5.0\build\net462\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.4.5.0\build\net462\NUnit3TestAdapter.props'))" />
</Target>
</Project>
8 changes: 8 additions & 0 deletions cs/TagsCloudVisualization/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FluentAssertions" version="6.12.0" targetFramework="net48" />
<package id="NUnit" version="4.0.0" targetFramework="net48" />
<package id="NUnit3TestAdapter" version="4.5.0" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net48" />
<package id="System.Threading.Tasks.Extensions" version="4.5.0" targetFramework="net48" />
</packages>
100 changes: 100 additions & 0 deletions cs/TagsCloudVizuaizationTest/CircularCloudLayouterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using System.CodeDom;
dmnovikova marked this conversation as resolved.
Show resolved Hide resolved
using System.Collections.Generic;
using System.Drawing;
using NUnit.Framework;
using TagsCloudVisualization;
using FluentAssertions;

namespace TagsCloudVizualizationTest
dmnovikova marked this conversation as resolved.
Show resolved Hide resolved
{
[TestFixture]
public class CircularCloudLayouterTests
{
private CircularCloudLayouter layouter;

[SetUp]
public void Initial() =>
layouter = new CircularCloudLayouter(new Point(400, 400));

[Test]
public static void CircularCloudLayouterCtor_WhenPassValidArguments_DoesNotThrowException() =>
Assert.DoesNotThrow(() => new CircularCloudLayouter(new Point(200, 200)));

public static TestCaseData[] InvalidArguments =
{
new TestCaseData(-200, 200).SetName("PassNegativeWidth"),
new TestCaseData(200, -200).SetName("PassNegativeHeight"),
new TestCaseData(-200, -200).SetName("PassNegativeArguments"),
new TestCaseData(0, 0).SetName("PassOnlyZero")
};

[TestOf(nameof(CircularCloudLayouter.HaveIntersection))]
[TestCaseSource(nameof(InvalidArguments))]
public void WhenPassInvalidArguments_ShouldThrowArgumentException(int width, int height) =>
Assert.Throws<ArgumentException>(() => layouter.PutNextRectangle(new Size(width, height)));

[Test]
public void WhenPutNewRectangle_ShouldBeAddedToList()
{
layouter.PutNextRectangle(new Size(4, 2));

layouter.Rectangles.Count.Should().Be(1);
}

private static readonly List<Rectangle> Rectangles = new List<Rectangle>
{
new Rectangle(new Point(400, 400), new Size(4, 2))
};

public static TestCaseData[] RectanglesPosition =
{
new TestCaseData(new Rectangle(new Point(400, 402), new Size(4, 2)))
.Returns(false).SetName("NotIntersectedRectangles2"),
new TestCaseData(new Rectangle(new Point(400, 402), new Size(6, 2)))
.Returns(false).SetName("NotIntersectedRectanglesOfDifferentSizes"),

new TestCaseData(new Rectangle(new Point(400, 400), new Size(4, 2)))
.Returns(true).SetName("IntersectedRectanglesInOnePoint"),
new TestCaseData(new Rectangle(new Point(402, 400), new Size(4, 2)))
.Returns(true).SetName("IntersectedRectangles")
};

[TestOf(nameof(CircularCloudLayouter.HaveIntersection))]
[TestCaseSource(nameof(RectanglesPosition))]
public bool WhenPassSeveralRectangles_ShouldReturnCorrectIntersectionResult(Rectangle newRectangle)
{
layouter.Rectangles = Rectangles;

return layouter.HaveIntersection(newRectangle);
}

[Test]
public void WhenPutNewRectangles_TheyShouldBeTightlyPositioned()
{
for (var i = 0; i < 15; i++)
layouter.PutNextRectangle(new Size(4, 2));

var rectanglesSquare = 0;
var radius = 0.0;

foreach (var rectangle in layouter.Rectangles)
{
var center = layouter.Center;

rectanglesSquare += rectangle.Size.Height * rectangle.Size.Width;

var biggestDistance= Math.Abs(Math.Sqrt(Math.Pow(rectangle.X - center.X, 2)
+ Math.Pow(rectangle.Y - center.Y, 2)));
if (biggestDistance > radius)
radius = biggestDistance;
}

var circleSquare = Math.PI * radius * radius;

var percentOfRatio = (rectanglesSquare / circleSquare) * 100;

percentOfRatio.Should().BeGreaterThan(80);
}
}
}
20 changes: 20 additions & 0 deletions cs/TagsCloudVizuaizationTest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("TagsCloudVizuaizationTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TagsCloudVizuaizationTest")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("09f90167-009f-4e35-94dd-dbd7a4b6a814")]

// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading