diff --git a/cs/TagsCloudVisualization/PointsOnSpiral.cs b/cs/TagsCloudVisualization/PointsOnSpiral.cs new file mode 100644 index 000000000..0cd40a9a1 --- /dev/null +++ b/cs/TagsCloudVisualization/PointsOnSpiral.cs @@ -0,0 +1,28 @@ +using System.Drawing; + +namespace TagsCloudVisualization; + +public class PointsOnSpiral +{ + private Point center; + + public PointsOnSpiral(Point center) + { + this.center = center; + } + + public IEnumerable GetPointsOnSpiral() + { + var radius = 0; + while (true) + { + for (var i = 0; i < 360; i++) + { + yield return new Point((int)(Math.Cos(2 * Math.PI * i / 360) * radius) + center.X, + (int)(Math.Sin(2 * Math.PI * i / 360) * radius) + center.Y); + } + + radius++; + } + } +} \ No newline at end of file diff --git a/cs/TagsCloudVisualization/Program.cs b/cs/TagsCloudVisualization/Program.cs new file mode 100644 index 000000000..b68515782 --- /dev/null +++ b/cs/TagsCloudVisualization/Program.cs @@ -0,0 +1,29 @@ +using System.Drawing; +using TagsCloudVisualization; + +class CircularCloudLayouter +{ + private Point cloudCenter; + private List rectangels = new List(); + private PointsOnSpiral points; + + public CircularCloudLayouter(Point cloudCenter) + { + this.cloudCenter = cloudCenter; + points = new PointsOnSpiral(cloudCenter); + } + + public Rectangle PutNextRectangle(Size rectangleSize) + { + foreach (var point in points.GetPointsOnSpiral()) + { + var rectangle = new Rectangle(point, rectangleSize); + if (rectangels.Any(x => x.IntersectsWith(rectangle))) + continue; + rectangels.Add(rectangle); + return rectangle; + } + + return new Rectangle(cloudCenter, rectangleSize); + } +} \ No newline at end of file diff --git a/cs/TagsCloudVisualization/TagsCloudVisualization.csproj b/cs/TagsCloudVisualization/TagsCloudVisualization.csproj new file mode 100644 index 000000000..9c9ef272f --- /dev/null +++ b/cs/TagsCloudVisualization/TagsCloudVisualization.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/cs/global.json b/cs/global.json new file mode 100644 index 000000000..dad2db5ef --- /dev/null +++ b/cs/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "8.0.0", + "rollForward": "latestMajor", + "allowPrerelease": true + } +} \ No newline at end of file diff --git a/cs/tdd.sln b/cs/tdd.sln index c8f523d63..a5ce745e8 100644 --- a/cs/tdd.sln +++ b/cs/tdd.sln @@ -7,6 +7,8 @@ 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", "{21297E12-D769-413A-BDBE-7A1D2022B650}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ 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 + {21297E12-D769-413A-BDBE-7A1D2022B650}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {21297E12-D769-413A-BDBE-7A1D2022B650}.Debug|Any CPU.Build.0 = Debug|Any CPU + {21297E12-D769-413A-BDBE-7A1D2022B650}.Release|Any CPU.ActiveCfg = Release|Any CPU + {21297E12-D769-413A-BDBE-7A1D2022B650}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE