Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Twinki14 committed Jan 4, 2024
1 parent d3093a3 commit 9848586
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 57 deletions.
4 changes: 4 additions & 0 deletions src/PolyZone.Debug/PolyZone.Debug.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
<Folder Include="Drawing\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CitizenFX.Core.Client" Version="1.0.7277" />
</ItemGroup>

</Project>
8 changes: 5 additions & 3 deletions src/PolyZone.Debug/Script.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace PolyZone.Debug;
using CitizenFX.Core;

public class Script
namespace PolyZone.Debug;

public class Script : BaseScript
{

}
}
6 changes: 0 additions & 6 deletions src/PolyZone.Tests/AssertionExtensions.cs

This file was deleted.

9 changes: 4 additions & 5 deletions src/PolyZone.Tests/Internal/Vector2Assertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using FluentAssertions;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;
using PolyZone.Shapes;
using PolyZone.Shapes.Interfaces;

namespace PolyZone.Tests.Internal;

Expand All @@ -16,15 +16,14 @@ public static Vector2Assertions Should(this Vector2 instance)

public class Vector2Assertions(Vector2 instance) : ReferenceTypeAssertions<Vector2, Vector2Assertions>(instance)

Check warning on line 17 in src/PolyZone.Tests/Internal/Vector2Assertions.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'Vector2 instance' is captured into the state of the enclosing type and its value is also passed to the base constructor. The value might be captured by the base class as well.

Check warning on line 17 in src/PolyZone.Tests/Internal/Vector2Assertions.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'Vector2 instance' is captured into the state of the enclosing type and its value is also passed to the base constructor. The value might be captured by the base class as well.
{
private readonly Vector2 _instance = instance;
protected override string Identifier => "directory";

public AndConstraint<Vector2Assertions> BeInside(Polygon polygon, string because = "", params object[] becauseArgs)
public AndConstraint<Vector2Assertions> BeInside(ISpatial2dShape shape, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.ForCondition(polygon.Contains(_instance))
.FailWith($"Expected point to be inside polygon, point was { _instance.X }, { _instance.Y }");
.ForCondition(shape.Contains(instance))
.FailWith($"Expected point to be inside polygon, point was { instance.X }, { instance.Y }");

return new AndConstraint<Vector2Assertions>(this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PolyZone.Tests/PolyZone.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<LangVersion>default</LangVersion>
<LangVersion>12</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
39 changes: 13 additions & 26 deletions src/PolyZone.Tests/Shapes/PolygonTests.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
using System.Collections.Generic;
using CitizenFX.Core;
using CitizenFX.Core;
using FluentAssertions;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;
using PolyZone.Shapes;
using PolyZone.Tests.Internal;
using Xunit.Abstractions;

// ReSharper disable ArrangeObjectCreationWhenTypeNotEvident

namespace PolyZone.Tests.Shapes;

public class PolygonTests
{
private readonly ITestOutputHelper _testOutputHelper;

public PolygonTests(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}

[Fact]
public void Polygon_A_IsInside_ShouldPassTest()
{
Expand All @@ -35,17 +22,17 @@ public void Polygon_A_IsInside_ShouldPassTest()
new Vector2 { X = -2f, Y = -8f }, // O (-3,-8)
new Vector2 { X = 2.26106f, Y = -9.30121f }, // P (2.26106,-9.30121)
};
List<Vector2> points =
[
new() { X = 9.12f, Y = 4.2f }, // A (9.12,4.2)
new() { X = -3.98f, Y = 3.32f }, // B (-3.98,3.32)
new() { X = -4.56966f, Y = -3.5142f }, // C (-4.56966,-3.5142)
new() { X = -3.56008f, Y = -9.12483f }, // D (-3.56008,-9.12483)
new() { X = 3.75525f, Y = -9.88615f }, // E (3.75525,-9.88615)
new() { X = -2.36844f, Y = -2.83563f }, // F (-2.36844,-2.83563)
new() { X = -0.5f, Y = 2.06f } // G (-0.5,2.06)
];

var points = new[]
{
new Vector2 { X = 9.12f, Y = 4.2f }, // A (9.12,4.2)
new Vector2 { X = -3.98f, Y = 3.32f }, // B (-3.98,3.32)
new Vector2 { X = -4.56966f, Y = -3.5142f }, // C (-4.56966,-3.5142)
new Vector2 { X = -3.56008f, Y = -9.12483f }, // D (-3.56008,-9.12483)
new Vector2 { X = 3.75525f, Y = -9.88615f }, // E (3.75525,-9.88615)
new Vector2 { X = -2.36844f, Y = -2.83563f }, // F (-2.36844,-2.83563)
new Vector2 { X = -0.5f, Y = 2.06f } // G (-0.5,2.06)
};

var polygon = new Polygon(points);

Expand All @@ -54,7 +41,7 @@ public void Polygon_A_IsInside_ShouldPassTest()
point.Should().BeInside(polygon);
}

var distance = polygon.DistanceFrom(new() { X = -1f, Y = 3.6f });
var distance = polygon.DistanceFrom(new Vector2 { X = -1f, Y = 3.6f });

distance.Should().BeGreaterThan(0);
}
Expand Down
8 changes: 3 additions & 5 deletions src/PolyZone/Extensions/Vector2Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using CitizenFX.Core;
using PolyZone.Shapes;
using PolyZone.Shapes.Interfaces;

namespace PolyZone.Extensions;

public static class Vector2Extensions
{
/*public static float DistanceFrom(this Vector2 vector2, in Polygon polygon)
{
return vector2;
}*/
public static bool IsInside(this Vector2 vector2, in ISpatial2dShape shape) => shape.Contains(vector2);
public static float DistanceTo(this Vector2 vector2, in ISpatial2dShape shape) => shape.DistanceFrom(vector2);
}
3 changes: 0 additions & 3 deletions src/PolyZone/Properties/AssemblyInfo.cs

This file was deleted.

10 changes: 2 additions & 8 deletions src/PolyZone/Shapes/Interfaces/IPolygon.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using CitizenFX.Core;
namespace PolyZone.Shapes.Interfaces;

namespace PolyZone.Shapes.Interfaces;

public interface IPolygon
{
bool Contains(Vector2 point);
float DistanceFrom(in Vector2 point);
}
public interface IPolygon : ISpatial2dShape;
9 changes: 9 additions & 0 deletions src/PolyZone/Shapes/Interfaces/ISpatial2dShape.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using CitizenFX.Core;

namespace PolyZone.Shapes.Interfaces;

public interface ISpatial2dShape
{
bool Contains(Vector2 point);
float DistanceFrom(in Vector2 point);
}

0 comments on commit 9848586

Please sign in to comment.