Repository: Mawak0/OOAiP
Pull request #34: Алгоритм для подготовки данных о коллизии
Author: login: ShelDenis
Created: 2025-05-18T12:16:07Z | Merged: 2025-05-22T12:31:23Z



Diff:
diff --git a/SpaceBattle.Lib.Tests/CollisionDataGeneratorTests.cs b/SpaceBattle.Lib.Tests/CollisionDataGeneratorTests.cs
new file mode 100644
index 0000000..e2a3e0e
--- /dev/null
+++ b/SpaceBattle.Lib.Tests/CollisionDataGeneratorTests.cs
@@ -0,0 +1,168 @@
+﻿using App;
+using App.Scopes;
+using Xunit;
+
+namespace SpaceBattle.Lib.Tests;
+
+public class CollisionDataGeneratorTests
+{
+    public CollisionDataGeneratorTests()
+    {
+        new InitCommand().Execute();
+        var iocScope = Ioc.Resolve<object>("IoC.Scope.Create");
+        Ioc.Resolve<App.ICommand>("IoC.Scope.Current.Set", iocScope).Execute();
+    }
+
+    [Fact]
+    public void CorrectIoCRegistrationTest()
+    {
+        var key1 = "shape1";
+        var key2 = "shape2";
+
+        var polygon1 = new Polygon(new List<Point>() { new Point(1, 1), new Point(2, 2), new Point(1, 3) });
+        var polygon2 = new Polygon(new List<Point>() { new Point(1, 2), new Point(2, 3), new Point(1, 4) });
+
+        var polygonDict = new Dictionary<string, Polygon> {
+                            { key1, polygon1 },
+                            { key2, polygon2 }
+                        };
+        Ioc.Resolve<App.ICommand>(
+            "IoC.Register",
+            "Collision.GetPolygonDict",
+            (object[] args) => polygonDict
+        ).Execute();
+
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Collision.Dataset.Length", (object[] args) => (object)100).Execute();
+
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Field.Quadrant.Size", (object[] args) => (object)10).Execute();
+
+        var registerIoCDependencyCollisionGenerator = new RegisterIoCDependencyCollisionGenerator();
+        registerIoCDependencyCollisionGenerator.Execute();
+
+        var dataGenerator = Ioc.Resolve<CollisionDataGenerator>("Collision.DataGenerator", key1, key2);
+
+        Assert.IsType<CollisionDataGenerator>(dataGenerator);
+    }
+
+    [Fact]
+    public void GenerateCollisionsTest()
+    {
+        var key1 = "shape1";
+        var key2 = "shape2";
+
+        var polygon1 = new Polygon(new List<Point>() { new Point(1, 1), new Point(2, 2), new Point(1, 3) });
+        var polygon2 = new Polygon(new List<Point>() { new Point(1, 2), new Point(2, 3), new Point(1, 4) });
+
+        var polygonDict = new Dictionary<string, Polygon> {
+                            { key1, polygon1 },
+                            { key2, polygon2 }
+                        };
+        Ioc.Resolve<App.ICommand>(
+            "IoC.Register",
+            "Collision.GetPolygonDict",
+            (object[] args) => polygonDict
+        ).Execute();
+
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Collision.Dataset.Length", (object[] args) => (object)100).Execute();
+
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Field.Quadrant.Size", (object[] args) => (object)10).Execute();
+
+        var collisionDataGenerator = new CollisionDataGenerator(key1, key2);
+
+        List<int[]> collisionData = (List<int[]>)collisionDataGenerator.GenerateCollisionData();
+
+        Assert.True(collisionData.Count > 0);
+    }
+
+    [Fact]
+    public void CreatePointReturnsValidRandomPointTest()
+    {
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Field.Quadrant.Size", (object[] args) => (object)10).Execute();
+
+        var generator = new CollisionDataGenerator("shape1", "shape2");
+        var point = generator.CreatePoint();
+
+        Assert.InRange(point.X, 0, 10);
+        Assert.InRange(point.Y, 0, 10);
+    }
+
+    [Fact]
+    public void HandleEmptyPolygonsTest()
+    {
+        var key1 = "empty_shape1";
+        var key2 = "empty_shape2";
+
+        var emptyPolygon = new Polygon(new List<Point>());
+
+        var polygonDict = new Dictionary<string, Polygon> {
+                            { key1, emptyPolygon },
+                            { key2, emptyPolygon }
+                        };
+        Ioc.Resolve<App.ICommand>(
+            "IoC.Register",
+            "Collision.GetPolygonDict",
+            (object[] args) => polygonDict
+        ).Execute();
+
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Collision.Dataset.Length", (object[] args) => (object)100).Execute();
+
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Field.Quadrant.Size", (object[] args) => (object)10).Execute();
+
+        var collisionDataGenerator = new CollisionDataGenerator(key1, key2);
+
+        List<int[]> collisionData = (List<int[]>)collisionDataGenerator.GenerateCollisionData();
+
+        Assert.Empty(collisionData);
+    }
+
+    [Fact]
+    public void HandleOnePointPolygonsTest()
+    {
+        var key1 = "degenerate_shape1";
+        var key2 = "degenerate_shape2";
+
+        var degeneratePolygon = new Polygon(new List<Point>() { new Point(1, 1) });
+
+        var polygonDict = new Dictionary<string, Polygon> {
+                            { key1, degeneratePolygon },
+                            { key2, degeneratePolygon }
+                        };
+        Ioc.Resolve<App.ICommand>(
+            "IoC.Register",
+            "Collision.GetPolygonDict",
+            (object[] args) => polygonDict
+        ).Execute();
+
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Collision.Dataset.Length", (object[] args) => (object)100).Execute();
+
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Field.Quadrant.Size", (object[] args) => (object)10).Execute();
+
+        var collisionDataGenerator = new CollisionDataGenerator(key1, key2);
+
+        List<int[]> collisionData = (List<int[]>)collisionDataGenerator.GenerateCollisionData();
+
+        Assert.Empty(collisionData);
+    }
+
+    [Fact]
+    public void FirstShape_ReturnsCorrectValue()
+    {
+        var key1 = "shape1";
+        var key2 = "shape2";
+
+        var collisionDataGenerator = new CollisionDataGenerator(key1, key2);
+
+        Assert.Equal(key1, collisionDataGenerator.firstShape);
+    }
+
+    [Fact]
+    public void SecondShape_ReturnsCorrectValue()
+    {
+        var key1 = "shape1";
+        var key2 = "shape2";
+
+        var collisionDataGenerator = new CollisionDataGenerator(key1, key2);
+
+        Assert.Equal(key2, collisionDataGenerator.secondShape);
+    }
+}
diff --git a/SpaceBattle.Lib.Tests/PointTests.cs b/SpaceBattle.Lib.Tests/PointTests.cs
new file mode 100644
index 0000000..02c9a54
--- /dev/null
+++ b/SpaceBattle.Lib.Tests/PointTests.cs
@@ -0,0 +1,72 @@
+﻿using Xunit;
+
+namespace SpaceBattle.Lib.Tests;
+
+public class PointTests
+{
+    [Fact]
+    public void CreatePointTest()
+    {
+        var point = new Point(1, 5);
+
+        Assert.Equal(1, point.X);
+        Assert.Equal(5, point.Y);
+    }
+
+    [Fact]
+    public void AdditionPointsTest()
+    {
+        var p1 = new Point(1, 2);
+        var p2 = new Point(3, 4);
+
+        var result = p1 + p2;
+
+        Assert.Equal(4.0, result.X);
+        Assert.Equal(6.0, result.Y);
+    }
+
+    [Fact]
+    public void SubtractionPointsTest()
+    {
+        var p1 = new Point(5, 8);
+        var p2 = new Point(2, 3);
+
+        var result = p1 - p2;
+
+        Assert.Equal(3, result.X);
+        Assert.Equal(5, result.Y);
+    }
+
+    [Fact]
+    public void ScalarMultiplicationTest()
+    {
+        var point = new Point(2, 3);
+        const double scalar = 3;
+
+        var result = scalar * point;
+
+        Assert.Equal(6, result.X);
+        Assert.Equal(9, result.Y);
+    }
+
+    [Fact]
+    public void NormalizationTest()
+    {
+        var point = new Point(3, 4);
+
+        var normalized = point.Normalize();
+
+        Assert.True(Math.Abs(normalized.X * normalized.X + normalized.Y * normalized.Y - 1.0) < 1E-10);
+    }
+
+    [Fact]
+    public void CrossPointsTest()
+    {
+        var p1 = new Point(1, 2);
+        var p2 = new Point(3, 4);
+
+        var crossProduct = Point.Cross(p1, p2);
+
+        Assert.Equal(-2, crossProduct);
+    }
+}
diff --git a/SpaceBattle.Lib.Tests/PolygonCollisionTests.cs b/SpaceBattle.Lib.Tests/PolygonCollisionTests.cs
new file mode 100644
index 0000000..38c3ebc
--- /dev/null
+++ b/SpaceBattle.Lib.Tests/PolygonCollisionTests.cs
@@ -0,0 +1,33 @@
+﻿using Xunit;
+namespace SpaceBattle.Lib.Tests;
+
+public class PolygonCollisionTests
+{
+    [Fact]
+    public void HasCollisionTest()
+    {
+        var firstPolygonPoints = new List<Point> { new Point(3, 5), new Point(6, 7), new Point(8, 3), new Point(6, 2) };
+        var secondPolygonPoints = new List<Point> { new Point(3, 3), new Point(6, 5), new Point(5, 2) };
+        var firstPolygon = new Polygon(firstPolygonPoints);
+        var secondPolygon = new Polygon(secondPolygonPoints);
+        var v = new Point(0, 1);
+
+        var collision = CollisionDetector.FindIntersections(firstPolygon, secondPolygon, v);
+
+        Assert.True(collision.Count > 0);
+    }
+
+    [Fact]
+    public void HasNotCollisionTest()
+    {
+        var firstPolygonPoints = new List<Point> { new Point(3, 5), new Point(6, 7), new Point(8, 3), new Point(6, 2) };
+        var secondPolygonPoints = new List<Point> { new Point(3, 3), new Point(6, 5), new Point(5, 2) };
+        var firstPolygon = new Polygon(firstPolygonPoints);
+        var secondPolygon = new Polygon(secondPolygonPoints);
+        var v = new Point(1, 1);
+
+        var collision = CollisionDetector.FindIntersections(firstPolygon, secondPolygon, v);
+
+        Assert.False(collision.Count > 0);
+    }
+}
diff --git a/SpaceBattle.Lib.Tests/PolygonTests.cs b/SpaceBattle.Lib.Tests/PolygonTests.cs
new file mode 100644
index 0000000..3905558
--- /dev/null
+++ b/SpaceBattle.Lib.Tests/PolygonTests.cs
@@ -0,0 +1,64 @@
+﻿using Xunit;
+
+namespace SpaceBattle.Lib.Tests;
+
+public class PolygonTests
+{
+    [Fact]
+    public void CorrectInitTest()
+    {
+        var points = new List<Point>
+        {
+            new Point(0, 0),
+            new Point(1, 0),
+            new Point(1, 1),
+            new Point(0, 1)
+        };
+
+        var polygon = new Polygon(points);
+
+        Assert.Equal(points, polygon.Points);
+    }
+
+    [Fact]
+    public void ReturnsCorrectEdgesTest()
+    {
+        var points = new List<Point>
+        {
+            new Point(0, 0),
+            new Point(1, 0),
+            new Point(1, 1),
+            new Point(0, 1)
+        };
+        var expectedEdges = new List<(Point start, Point end)>
+        {
+            (points[0], points[1]),
+            (points[1], points[2]),
+            (points[2], points[3]),
+            (points[3], points[0])
+        };
+
+        var polygon = new Polygon(points);
+        var edges = polygon.Edges().ToList();
+
+        Assert.Equal(expectedEdges, edges);
+    }
+
+    [Fact]
+    public void LastEdgeConnectsLastAndFirstVertexTest()
+    {
+        var points = new List<Point>
+        {
+            new Point(0, 0),
+            new Point(1, 0),
+            new Point(1, 1),
+            new Point(0, 1)
+        };
+
+        var polygon = new Polygon(points);
+        var lastEdge = polygon.Edges().Last();
+
+        Assert.Equal(points.Last(), lastEdge.start);
+        Assert.Equal(points.First(), lastEdge.end);
+    }
+}
diff --git a/SpaceBattle.Lib.Tests/RayTests.cs b/SpaceBattle.Lib.Tests/RayTests.cs
new file mode 100644
index 0000000..3461afc
--- /dev/null
+++ b/SpaceBattle.Lib.Tests/RayTests.cs
@@ -0,0 +1,40 @@
+﻿using Xunit;
+
+namespace SpaceBattle.Lib.Tests;
+
+public class RayTests
+{
+    [Fact]
+    public void ConstructorNormalizesDirectionVectorTest()
+    {
+        var origin = new Point(0, 0);
+        var direction = new Point(3, 4);
+
+        var ray = new Ray(origin, direction);
+
+        Assert.Equal(1, Math.Sqrt(ray.Direction.X * ray.Direction.X + ray.Direction.Y * ray.Direction.Y));
+    }
+
+    [Fact]
+    public void PropertiesSetCorrectlyTest()
+    {
+        var origin = new Point(1, 2);
+        var direction = new Point(3, 4);
+
+        var ray = new Ray(origin, direction);
+
+        Assert.Equal(origin, ray.Origin);
+        Assert.NotEqual(direction, ray.Direction);
+    }
+
+    [Fact]
+    public void DirectionHasUnitLengthTest()
+    {
+        var origin = new Point(0, 0);
+        var direction = new Point(10, 0);
+
+        var ray = new Ray(origin, direction);
+
+        Assert.Equal(1.0, Math.Sqrt(ray.Direction.X * ray.Direction.X + ray.Direction.Y * ray.Direction.Y));
+    }
+}
diff --git a/SpaceBattle.Lib/CollisionDataGenerator.cs b/SpaceBattle.Lib/CollisionDataGenerator.cs
new file mode 100644
index 0000000..89badd3
--- /dev/null
+++ b/SpaceBattle.Lib/CollisionDataGenerator.cs
@@ -0,0 +1,74 @@
+﻿using App;
+
+namespace SpaceBattle.Lib;
+
+public class CollisionDataGenerator : ICollisionDataGenerator
+{
+    private readonly string shape1;
+    private readonly string shape2;
+    private readonly Random rnd;
+
+    public string firstShape => shape1;
+
+    public string secondShape => shape2;
+
+    public CollisionDataGenerator(string shape1, string shape2)
+    {
+        this.shape1 = shape1;
+        this.shape2 = shape2;
+        rnd = new Random();
+    }
+
+    public IList<int[]> GenerateCollisionData()
+    {
+        var shapesDict = (IDictionary<string, Polygon>)Ioc.Resolve<object>("Collision.GetPolygonDict");
+        var datasetLength = Ioc.Resolve<int>("Collision.Dataset.Length");
+        var rawPolygon1 = shapesDict[shape1];
+        var polygon2 = shapesDict[shape2];
+
+        return Enumerable.Range(0, datasetLength)
+                        .Select(i =>
+                        {
+                            var point0 = CreatePoint();
+                            var velocity = CreatePoint();
+
+                            List<Point> points = rawPolygon1.Edges()
+                                                        .SelectMany(edge => new[] { edge.start, edge.end })
+                                                        .Distinct()
+                                                        .ToList();
+
+                            for (int j = 0; j < points.Count; j++)
+                            {
+                                points[j] += point0;
+                            }
+
+                            var polygon1 = new Polygon(points);
+
+                            var collisions = CollisionDetector.FindIntersections(polygon1, polygon2, velocity);
+                            if (collisions.Capacity > 0)
+                            {
+                                var collisionLine = new List<int>();
+
+                                collisionLine.AddRange(
+                                    new[] { polygon1, polygon2 }.SelectMany(p => p.Points).SelectMany(p => new int[] { (int)p.X, (int)p.Y }));
+
+                                collisionLine.Add((int)velocity.X);
+                                collisionLine.Add((int)velocity.Y);
+
+                                return collisionLine.ToArray();
+                            }
+
+                            return null;
+                        })
+                        .Where(line => line != null)
+                        .Cast<int[]>()
+                        .ToList();
+    }
+
+    public Point CreatePoint()
+    {
+        var quadrantSize = Ioc.Resolve<int>("Field.Quadrant.Size");
+        return new Point(rnd.Next(0, quadrantSize), rnd.Next(0, quadrantSize));
+    }
+}
+
diff --git a/SpaceBattle.Lib/CollisionDetector.cs b/SpaceBattle.Lib/CollisionDetector.cs
new file mode 100644
index 0000000..5177fe5
--- /dev/null
+++ b/SpaceBattle.Lib/CollisionDetector.cs
@@ -0,0 +1,43 @@
+﻿namespace SpaceBattle.Lib;
+
+using System.Collections.Generic;
+using Microsoft.CodeAnalysis;
+
+public class CollisionDetector
+{
+    public static List<Point> FindIntersections(Polygon poly1, Polygon poly2, Point velocity)
+    {
+        var intersections =
+            from vertex in poly1.Points
+            from edge in poly2.Edges()
+            let ray = new Ray(vertex, velocity)
+            let intersection = RayIntersectsEdge(ray, edge.start, edge.end)
+            where intersection.HasValue
+            select intersection.Value;
+
+        return intersections.Distinct().ToList();
+    }
+
+    private static Optional<Point> RayIntersectsEdge(Ray ray, Point start, Point end)
+    {
+        var dir = ray.Direction;
+        var diff = start - ray.Origin;
+        var edgeDir = end - start;
+
+        double det = Point.Cross(dir, edgeDir);
+        if (Math.Abs(det) < 1e-7)
+        {
+            return default(Optional<Point>);
+        }
+
+        double t = Point.Cross(diff, edgeDir) / det;
+        double u = Point.Cross(diff, dir) / det;
+
+        if (t >= 0 && u >= 0 && u <= 1)
+        {
+            return new Optional<Point>(ray.Origin + t * dir);
+        }
+
+        return default(Optional<Point>);
+    }
+}
diff --git a/SpaceBattle.Lib/Point.cs b/SpaceBattle.Lib/Point.cs
new file mode 100644
index 0000000..3e6ce38
--- /dev/null
+++ b/SpaceBattle.Lib/Point.cs
@@ -0,0 +1,39 @@
+﻿namespace SpaceBattle.Lib;
+
+public class Point
+{
+    public double X { get; }
+    public double Y { get; }
+
+    public Point(double x, double y)
+    {
+        X = x;
+        Y = y;
+    }
+
+    public static double Cross(Point p1, Point p2)
+    {
+        return p1.X * p2.Y - p1.Y * p2.X;
+    }
+
+    public static Point operator -(Point p1, Point p2)
+    {
+        return new Point(p1.X - p2.X, p1.Y - p2.Y);
+    }
+
+    public static Point operator +(Point p1, Point p2)
+    {
+        return new Point(p1.X + p2.X, p1.Y + p2.Y);
+    }
+
+    public static Point operator *(double scalar, Point p)
+    {
+        return new Point(p.X * scalar, p.Y * scalar);
+    }
+
+    public Point Normalize()
+    {
+        double len = Math.Sqrt(X * X + Y * Y);
+        return new Point(X / len, Y / len);
+    }
+}
diff --git a/SpaceBattle.Lib/Polygon.cs b/SpaceBattle.Lib/Polygon.cs
new file mode 100644
index 0000000..7aa13ea
--- /dev/null
+++ b/SpaceBattle.Lib/Polygon.cs
@@ -0,0 +1,18 @@
+﻿namespace SpaceBattle.Lib;
+
+public class Polygon
+{
+    public List<Point> Points { get; }
+
+    public Polygon(IEnumerable<Point> points)
+    {
+        Points = points.ToList();
+    }
+
+    public IEnumerable<(Point start, Point end)> Edges()
+    {
+        var result = Points.Select((point, i) => (point, Points[(i + 1) % Points.Count]));
+        return result;
+
+    }
+}
diff --git a/SpaceBattle.Lib/Ray.cs b/SpaceBattle.Lib/Ray.cs
new file mode 100644
index 0000000..81499b0
--- /dev/null
+++ b/SpaceBattle.Lib/Ray.cs
@@ -0,0 +1,13 @@
+﻿namespace SpaceBattle.Lib;
+
+public class Ray
+{
+    public Point Origin { get; }
+    public Point Direction { get; }
+
+    public Ray(Point origin, Point direction)
+    {
+        Origin = origin;
+        Direction = direction.Normalize();
+    }
+}
diff --git a/SpaceBattle.Lib/RegisterIoCCollisionDataGenerator.cs b/SpaceBattle.Lib/RegisterIoCCollisionDataGenerator.cs
new file mode 100644
index 0000000..659adcd
--- /dev/null
+++ b/SpaceBattle.Lib/RegisterIoCCollisionDataGenerator.cs
@@ -0,0 +1,15 @@
+﻿using App;
+
+namespace SpaceBattle.Lib;
+
+public class RegisterIoCDependencyCollisionGenerator : ICommand
+{
+    public void Execute()
+    {
+        Ioc.Resolve<App.ICommand>(
+            "IoC.Register",
+            "Collision.DataGenerator",
+            (object[] args) => new CollisionDataGenerator((string)args[0], (string)args[1])
+        ).Execute();
+    }
+}
diff --git a/SpaceBattle.Lib/SpaceBattle.Lib.csproj b/SpaceBattle.Lib/SpaceBattle.Lib.csproj
index 92c1573..1cc79da 100644
--- a/SpaceBattle.Lib/SpaceBattle.Lib.csproj
+++ b/SpaceBattle.Lib/SpaceBattle.Lib.csproj
@@ -7,6 +7,7 @@
   </PropertyGroup>
 
     <ItemGroup>
+    <PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.14.0" />
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
     <PackageReference Include="Moq" Version="4.20.72" />
     <PackageReference Include="xunit" Version="2.4.2" />


Reviews:
user: login: zaryanezrya
state: CHANGES_REQUESTED
author_association: NONE
submitted_at: 2025-05-20T07:40:05Z
user: login: zaryanezrya
state: APPROVED
author_association: NONE
submitted_at: 2025-05-22T10:00:31Z

Review comments:
path: SpaceBattle.Lib/Point.cs
user: login: zaryanezrya
body: !
created_at: 2025-05-20T07:29:23Z
author_association: NONE
path: SpaceBattle.Lib/Point.cs
user: login: zaryanezrya
body: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods
created_at: 2025-05-20T07:29:32Z
author_association: NONE
diff_hunk: @@ -0,0 +1,41 @@
+﻿namespace SpaceBattle.Lib;
+using System.Collections.Generic;
+
+public class CollisionDetector
+{
+    public static List<Point> FindIntersections(Polygon poly1, Polygon poly2, Point velocity)
+    {
+        var intersections =
+            from vertex in poly1.Points
+            from edge in poly2.Edges()
+            let ray = new Ray(vertex, velocity)
+            let intersection = RayIntersectsEdge(ray, edge.start, edge.end)
+            where intersection != null
+            select intersection;
+
+        return intersections.Distinct().ToList();
+    }
+
+    private static Point? RayIntersectsEdge(Ray ray, Point start, Point end)
path: SpaceBattle.Lib/CollisionDetector.cs
user: login: zaryanezrya
body: https://learn.microsoft.com/ru-ru/dotnet/api/microsoft.codeanalysis.optional-1?view=roslyn-dotnet-4.13.0
created_at: 2025-05-20T07:33:37Z
author_association: NONE
diff_hunk: @@ -0,0 +1,33 @@
+﻿using Xunit;
+namespace SpaceBattle.Lib.Tests;
+
+public class PolygonCollisionTests
+{
+    [Fact]
+    public void HasCollisionTest()
+    {
+        var firstPolygonPoints = new List<Point> { new Point(3, 5), new Point(6, 7), new Point(8, 3), new Point(6, 2) };
+        var secondPolygonPoints = new List<Point> { new Point(3, 3), new Point(6, 5), new Point(5, 2) };
+        var firstPolygon = new Polygon(firstPolygonPoints);
+        var secondPolygon = new Polygon(secondPolygonPoints);
+        var v = new Point(0, 1);
+
+        var collision = CollisionDetector.FindIntersections(firstPolygon, secondPolygon, v);
+
+        Assert.True(collision.Capacity > 0);
+    }
+
+    [Fact]
+    public void HasNotCollisionTest()
+    {
+        var firstPolygonPoints = new List<Point> { new Point(3, 5), new Point(6, 7), new Point(8, 3), new Point(6, 2) };
+        var secondPolygonPoints = new List<Point> { new Point(3, 3), new Point(6, 5), new Point(5, 2) };
+        var firstPolygon = new Polygon(firstPolygonPoints);
+        var secondPolygon = new Polygon(secondPolygonPoints);
+        var v = new Point(1, 1);
+
+        var collision = CollisionDetector.FindIntersections(firstPolygon, secondPolygon, v);
+
+        Assert.False(collision.Capacity > 0);
path: SpaceBattle.Lib.Tests/PolygonCollisionTests.cs
user: login: zaryanezrya
body: ?
created_at: 2025-05-20T07:39:08Z
author_association: NONE
diff_hunk: @@ -0,0 +1,168 @@
+﻿using App;
+using App.Scopes;
+using Xunit;
+
+namespace SpaceBattle.Lib.Tests;
+
+public class CollisionDataGeneratorTests
+{
+    public CollisionDataGeneratorTests()
+    {
+        new InitCommand().Execute();
+        var iocScope = Ioc.Resolve<object>("IoC.Scope.Create");
+        Ioc.Resolve<App.ICommand>("IoC.Scope.Current.Set", iocScope).Execute();
+    }
+
+    [Fact]
+    public void CorrectIoCRegistrationTest()
+    {
+        var key1 = "shape1";
+        var key2 = "shape2";
+
+        var polygon1 = new Polygon(new List<Point>() { new Point(1, 1), new Point(2, 2), new Point(1, 3) });
+        var polygon2 = new Polygon(new List<Point>() { new Point(1, 2), new Point(2, 3), new Point(1, 4) });
+
+        var polygonDict = new Dictionary<string, Polygon> {
+                            { key1, polygon1 },
+                            { key2, polygon2 }
+                        };
+        Ioc.Resolve<App.ICommand>(
+            "IoC.Register",
+            "Collision.GetPolygonDict",
+            (object[] args) => polygonDict
+        ).Execute();
+
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Collision.Dataset.Length", (object[] args) => (object)100).Execute();
+
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Field.Quadrant.Size", (object[] args) => (object)10).Execute();
+
+        var registerIoCDependencyCollisionGenerator = new RegisterIoCDependencyCollisionGenerator();
+        registerIoCDependencyCollisionGenerator.Execute();
+
+        var dataGenerator = Ioc.Resolve<CollisionDataGenerator>("Collision.DataGenerator", key1, key2);
+
+        Assert.IsType<CollisionDataGenerator>(dataGenerator);
+    }
+
+    [Fact]
+    public void GenerateCollisionsTest()
+    {
+        var key1 = "shape1";
+        var key2 = "shape2";
+
+        var polygon1 = new Polygon(new List<Point>() { new Point(1, 1), new Point(2, 2), new Point(1, 3) });
+        var polygon2 = new Polygon(new List<Point>() { new Point(1, 2), new Point(2, 3), new Point(1, 4) });
+
+        var polygonDict = new Dictionary<string, Polygon> {
+                            { key1, polygon1 },
+                            { key2, polygon2 }
+                        };
+        Ioc.Resolve<App.ICommand>(
+            "IoC.Register",
+            "Collision.GetPolygonDict",
+            (object[] args) => polygonDict
+        ).Execute();
+
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Collision.Dataset.Length", (object[] args) => (object)100).Execute();
+
+        Ioc.Resolve<App.ICommand>("IoC.Register", "Field.Quadrant.Size", (object[] args) => (object)10).Execute();
+
+        var collisionDataGenerator = new CollisionDataGenerator(key1, key2);
+
+        List<int[]> collisionData = (List<int[]>)collisionDataGenerator.GenerateCollisionData();
+
+        Assert.True(collisionData.Capacity > 0);
path: SpaceBattle.Lib.Tests/CollisionDataGeneratorTests.cs
user: login: zaryanezrya
body: ?
created_at: 2025-05-20T07:39:53Z
author_association: NONE

PR comments:
user: login: github-actions[bot]
created_at: 2025-05-21T13:35:22Z
body: ![Code Coverage](https://img.shields.io/badge/Code%20Coverage-100%25-success?style=flat)

Package | Line Rate | Branch Rate | Complexity | Health
-------- | --------- | ----------- | ---------- | ------
SpaceBattle.Lib | 100% | 100% | 119 | ✔
**Summary** | **100%** (499 / 499) | **100%** (24 / 24) | **119** | ✔

<!-- Sticky Pull Request Comment -->
author_association: NONE